-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for the format parameter #1299
base: develop
Are you sure you want to change the base?
Changes from 1 commit
873b29e
7863668
98144cc
98e6891
06b7ec4
e89b116
7e46c4e
a9fe227
e4d3857
29fb4b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,39 +43,22 @@ fun composeTemporalEntitiesQueryFromGet( | |
requestParams, | ||
contexts | ||
).bind() | ||
var withTemporalValues = false | ||
var withAggregatedValues = false | ||
if (inQueryEntities) { | ||
entitiesQueryFromGet.validateMinimalQueryEntitiesParameters().bind() | ||
} | ||
val optionsParam = Optional.ofNullable(requestParams.getFirst(QueryParameter.OPTIONS.key)) | ||
val formatParam = requestParams.getFirst(QueryParameter.FORMAT.key) | ||
when (formatParam) { | ||
FormatValue.TEMPORAL_VALUES.value -> withTemporalValues = true | ||
FormatValue.AGGREGATED_VALUES.value -> withAggregatedValues = true | ||
else -> { | ||
val hasTemporal = hasValueInQueryParam(optionsParam, QueryParamValue.TEMPORAL_VALUES) | ||
val hasAggregated = hasValueInQueryParam(optionsParam, QueryParamValue.AGGREGATED_VALUES) | ||
if (hasTemporal && hasAggregated) { | ||
return BadRequestDataException("Only one temporal representation can be present").left() | ||
} | ||
withTemporalValues = hasTemporal | ||
withAggregatedValues = hasAggregated | ||
} | ||
} | ||
val temporalRepresentation = extractTemporalRepresentation(requestParams).bind() | ||
val withAudit = hasValueInQueryParam( | ||
Optional.ofNullable(requestParams.getFirst(QueryParameter.OPTIONS.key)), | ||
QueryParamValue.AUDIT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should use |
||
) | ||
val temporalQuery = | ||
buildTemporalQuery(requestParams, defaultPagination, inQueryEntities, withAggregatedValues).bind() | ||
buildTemporalQuery(requestParams, defaultPagination, inQueryEntities, temporalRepresentation).bind() | ||
|
||
TemporalEntitiesQueryFromGet( | ||
entitiesQuery = entitiesQueryFromGet, | ||
temporalQuery = temporalQuery, | ||
withTemporalValues = withTemporalValues, | ||
withAudit = withAudit, | ||
withAggregatedValues = withAggregatedValues | ||
temporalRepresentation = temporalRepresentation, | ||
withAudit = withAudit | ||
) | ||
} | ||
|
||
|
@@ -91,20 +74,12 @@ fun composeTemporalEntitiesQueryFromPost( | |
requestParams, | ||
contexts | ||
).bind() | ||
val temporalRepresentation = extractTemporalRepresentation(requestParams).bind() | ||
|
||
val withTemporalValues = hasValueInQueryParam( | ||
Optional.ofNullable(requestParams.getFirst(QueryParameter.OPTIONS.key)), | ||
QueryParamValue.TEMPORAL_VALUES | ||
) | ||
val withAudit = hasValueInQueryParam( | ||
Optional.ofNullable(requestParams.getFirst(QueryParameter.OPTIONS.key)), | ||
QueryParamValue.AUDIT | ||
) | ||
val withAggregatedValues = hasValueInQueryParam( | ||
Optional.ofNullable(requestParams.getFirst(QueryParameter.OPTIONS.key)), | ||
QueryParamValue.AGGREGATED_VALUES | ||
) | ||
|
||
val temporalParams = mapOf( | ||
QueryParameter.TIMEREL.key to listOf(query.temporalQ?.timerel), | ||
QueryParameter.TIMEAT.key to listOf(query.temporalQ?.timeAt), | ||
|
@@ -118,15 +93,14 @@ fun composeTemporalEntitiesQueryFromPost( | |
MultiValueMapAdapter(temporalParams), | ||
defaultPagination, | ||
true, | ||
withAggregatedValues | ||
temporalRepresentation | ||
).bind() | ||
|
||
TemporalEntitiesQueryFromPost( | ||
entitiesQuery = entitiesQueryFromPost, | ||
temporalQuery = temporalQuery, | ||
withTemporalValues = withTemporalValues, | ||
withAudit = withAudit, | ||
withAggregatedValues = withAggregatedValues | ||
temporalRepresentation = temporalRepresentation, | ||
withAudit = withAudit | ||
) | ||
} | ||
|
||
|
@@ -135,11 +109,12 @@ fun buildTemporalQuery( | |
params: MultiValueMap<String, String>, | ||
pagination: ApplicationProperties.Pagination, | ||
inQueryEntities: Boolean = false, | ||
withAggregatedValues: Boolean = false, | ||
temporalRepresentation: TemporalRepresentation, | ||
): Either<APIException, TemporalQuery> { | ||
val timerelParam = params.getFirst(QueryParameter.TIMEREL.key) | ||
val timeAtParam = params.getFirst(QueryParameter.TIMEAT.key) | ||
val endTimeAtParam = params.getFirst(QueryParameter.ENDTIMEAT.key) | ||
val withAggregatedValues = temporalRepresentation == TemporalRepresentation.AGGREGATED_VALUES | ||
val aggrPeriodDurationParam = | ||
if (withAggregatedValues) | ||
params.getFirst(QueryParameter.AGGRPERIODDURATION.key) ?: WHOLE_TIME_RANGE_DURATION | ||
|
@@ -215,3 +190,30 @@ fun buildTimerelAndTime( | |
} else { | ||
"'timerel' and 'time' must be used in conjunction".left() | ||
} | ||
|
||
fun extractTemporalRepresentation(requestParams: MultiValueMap<String, String>): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it can be a private function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we now call it |
||
Either<APIException, TemporalRepresentation> = either { | ||
ranim-n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val optionsParam = Optional.ofNullable(requestParams.getFirst(QueryParameter.OPTIONS.key)) | ||
val formatParam = requestParams.getFirst(QueryParameter.FORMAT.key) | ||
return when (formatParam) { | ||
FormatValue.TEMPORAL_VALUES.value -> TemporalRepresentation.TEMPORAL_VALUES.right() | ||
FormatValue.AGGREGATED_VALUES.value -> TemporalRepresentation.AGGREGATED_VALUES.right() | ||
else -> { | ||
val hasTemporal = hasValueInQueryParam(optionsParam, QueryParamValue.TEMPORAL_VALUES) | ||
val hasAggregated = hasValueInQueryParam(optionsParam, QueryParamValue.AGGREGATED_VALUES) | ||
when { | ||
hasTemporal && hasAggregated -> | ||
return BadRequestDataException("Only one temporal representation can be present").left() | ||
hasTemporal -> TemporalRepresentation.TEMPORAL_VALUES.right() | ||
hasAggregated -> TemporalRepresentation.AGGREGATED_VALUES.right() | ||
else -> TemporalRepresentation.NONE.right() | ||
} | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be simplified. By adding a fromString function to the TemporalRepresentation enum. |
||
|
||
enum class TemporalRepresentation { | ||
TEMPORAL_VALUES, | ||
AGGREGATED_VALUES, | ||
NONE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you add enclosing
{
for this one-line expression?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
detekt automatic fix