-
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?
Conversation
Test Results 71 files + 1 71 suites +1 1m 25s ⏱️ -2s Results for commit 1de5901. ± Comparison against base commit b9bca70. This pull request removes 190 and adds 50 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
shared/src/main/kotlin/com/egm/stellio/shared/model/NgsiLdDataRepresentation.kt
Show resolved
Hide resolved
shared/src/main/kotlin/com/egm/stellio/shared/queryparameter/FormatValue.kt
Show resolved
Hide resolved
shared/src/main/kotlin/com/egm/stellio/shared/queryparameter/FormatValue.kt
Outdated
Show resolved
Hide resolved
search-service/src/test/kotlin/com/egm/stellio/search/entity/web/EntityHandlerTests.kt
Show resolved
Hide resolved
@@ -45,18 +45,22 @@ fun composeTemporalEntitiesQueryFromGet( | |||
|
|||
if (inQueryEntities) | |||
entitiesQueryFromGet.validateMinimalQueryEntitiesParameters().bind() | |||
val optionsParam = Optional.ofNullable(requestParams.getFirst(QueryParameter.OPTIONS.key)) | |||
val formatParam = Optional.ofNullable(requestParams.getFirst(QueryParameter.FORMAT.key)) | |||
val withTemporalValues = when { |
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.
you could take this opportunity to return an APIException
if both temporalValues
and aggregatedValues
are provided
search-service/src/main/kotlin/com/egm/stellio/search/temporal/util/TemporalQueryUtils.kt
Outdated
Show resolved
Hide resolved
search-service/src/main/kotlin/com/egm/stellio/search/temporal/util/TemporalQueryUtils.kt
Outdated
Show resolved
Hide resolved
…/util/TemporalQueryUtils.kt Co-authored-by: Thomas Bousselin <[email protected]>
…/util/TemporalQueryUtils.kt Co-authored-by: Thomas Bousselin <[email protected]>
...ch-service/src/test/kotlin/com/egm/stellio/search/temporal/web/TemporalEntityHandlerTests.kt
Outdated
Show resolved
Hide resolved
search-service/src/main/kotlin/com/egm/stellio/search/temporal/util/TemporalQueryUtils.kt
Outdated
Show resolved
Hide resolved
…/web/TemporalEntityHandlerTests.kt Co-authored-by: Benoit Orihuela <[email protected]>
search-service/src/main/kotlin/com/egm/stellio/search/temporal/util/TemporalQueryUtils.kt
Outdated
Show resolved
Hide resolved
search-service/src/main/kotlin/com/egm/stellio/search/temporal/util/TemporalQueryUtils.kt
Outdated
Show resolved
Hide resolved
search-service/src/test/kotlin/com/egm/stellio/search/support/BusinessObjectsFactory.kt
Outdated
Show resolved
Hide resolved
search-service/src/main/kotlin/com/egm/stellio/search/temporal/util/TemporalQueryUtils.kt
Outdated
Show resolved
Hide resolved
search-service/src/main/kotlin/com/egm/stellio/search/temporal/util/TemporalQueryUtils.kt
Outdated
Show resolved
Hide resolved
@@ -206,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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
we now call it queryParams
, and no longer requestParams
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.
still the 1st point
search-service/src/main/kotlin/com/egm/stellio/search/temporal/util/TemporalQueryUtils.kt
Outdated
Show resolved
Hide resolved
…/util/TemporalQueryUtils.kt Co-authored-by: Benoit Orihuela <[email protected]>
don't know why you merged develop in your branch (we never do that, we rebase on develop), but it is a bit a mess. there is at least one commit from develop which is included in the branch... |
@@ -199,7 +200,8 @@ class AttributeInstanceServiceTests : WithTimescaleContainer, WithKafkaContainer | |||
buildDefaultTestTemporalQuery( | |||
timerel = Timerel.AFTER, | |||
timeAt = now.minusHours(1) | |||
) | |||
), | |||
TemporalRepresentation.NORMALIZED |
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.
this parameter is useless if equals to NORMALIZED
(it is the default in gimmeTemporalEntitiesQuery
). here and in every other calls below.
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.
This was fixed but the merge must've removed it (same thing for the private function)
companion object { | ||
fun fromString(key: String): Either<APIException, OptionsValue> = either { | ||
OptionsValue.entries.find { it.value == key } | ||
?: return InvalidRequestException("'$key' is not a valid options value").left() |
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.
?: return InvalidRequestException("'$key' is not a valid options value").left() | |
?: return InvalidRequestException("'$key' is not a valid value for the options query parameter").left() |
shared/src/test/kotlin/com/egm/stellio/shared/model/NgsiLdDataRepresentationTests.kt
Outdated
Show resolved
Hide resolved
|
||
fun hasValueInOptionsParam(options: Optional<String>, optionValue: OptionsParamValue): Boolean = | ||
options | ||
fun hasValueInOptionsParam( |
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.
fun hasValueInOptionsParam(
optionsParam: Optional<String>,
optionsValue: OptionsValue
): Either<APIException, Boolean> = either {
optionsParam
.map { it.split(",") }
.orElse(emptyList())
.map { OptionsValue.fromString(it).bind() }
.any { it == optionsValue }
}
@@ -206,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 comment
The reason will be displayed to describe this comment to others. Learn more.
still the 1st point
if (!optionsParam.isEmpty) { | ||
val hasTemporal = hasValueInOptionsParam(optionsParam, OptionsValue.TEMPORAL_VALUES).bind() | ||
val hasAggregated = hasValueInOptionsParam(optionsParam, OptionsValue.AGGREGATED_VALUES).bind() | ||
when { | ||
hasTemporal && hasAggregated -> | ||
return BadRequestDataException("Only one temporal representation can be present").left() | ||
hasTemporal -> return TemporalRepresentation.TEMPORAL_VALUES.right() | ||
hasAggregated -> return TemporalRepresentation.AGGREGATED_VALUES.right() | ||
else -> return TemporalRepresentation.NORMALIZED.right() | ||
} | ||
} else | ||
return TemporalRepresentation.NORMALIZED.right() |
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.
if (!optionsParam.isEmpty) { | |
val hasTemporal = hasValueInOptionsParam(optionsParam, OptionsValue.TEMPORAL_VALUES).bind() | |
val hasAggregated = hasValueInOptionsParam(optionsParam, OptionsValue.AGGREGATED_VALUES).bind() | |
when { | |
hasTemporal && hasAggregated -> | |
return BadRequestDataException("Only one temporal representation can be present").left() | |
hasTemporal -> return TemporalRepresentation.TEMPORAL_VALUES.right() | |
hasAggregated -> return TemporalRepresentation.AGGREGATED_VALUES.right() | |
else -> return TemporalRepresentation.NORMALIZED.right() | |
} | |
} else | |
return TemporalRepresentation.NORMALIZED.right() | |
return if (!optionsParam.isEmpty) { | |
val hasTemporal = hasValueInOptionsParam(optionsParam, OptionsValue.TEMPORAL_VALUES).bind() | |
val hasAggregated = hasValueInOptionsParam(optionsParam, OptionsValue.AGGREGATED_VALUES).bind() | |
when { | |
hasTemporal && hasAggregated -> | |
BadRequestDataException( | |
"Found different temporal representations in options query parameter, only one can be provided" | |
).left() | |
hasTemporal -> TemporalRepresentation.TEMPORAL_VALUES.right() | |
hasAggregated -> TemporalRepresentation.AGGREGATED_VALUES.right() | |
else -> TemporalRepresentation.NORMALIZED.right() | |
} | |
} else | |
TemporalRepresentation.NORMALIZED.right() |
.flatMap { it.split(",") } | ||
val formatParam = queryParams.getFirst(QueryParameter.FORMAT.key) | ||
if (formatParam != null && FormatValue.fromString(formatParam) == null) { | ||
return InvalidRequestException("'$formatParam' is not a valid format value").left() | ||
} | ||
|
||
optionsParam.forEach { option -> | ||
OptionsValue.fromString(option).bind() | ||
} | ||
val attributeRepresentation = when { | ||
formatParam == FormatValue.KEY_VALUES.value || | ||
formatParam == FormatValue.SIMPLIFIED.value -> AttributeRepresentation.SIMPLIFIED | ||
formatParam == FormatValue.NORMALIZED.value -> AttributeRepresentation.NORMALIZED | ||
optionsParam.contains(FormatValue.KEY_VALUES.value) || | ||
optionsParam.contains(FormatValue.SIMPLIFIED.value) -> AttributeRepresentation.SIMPLIFIED | ||
else -> AttributeRepresentation.NORMALIZED | ||
} | ||
val includeSysAttrs = optionsParam.contains(OptionsValue.SYS_ATTRS.value) |
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.
.flatMap { it.split(",") } | |
val formatParam = queryParams.getFirst(QueryParameter.FORMAT.key) | |
if (formatParam != null && FormatValue.fromString(formatParam) == null) { | |
return InvalidRequestException("'$formatParam' is not a valid format value").left() | |
} | |
optionsParam.forEach { option -> | |
OptionsValue.fromString(option).bind() | |
} | |
val attributeRepresentation = when { | |
formatParam == FormatValue.KEY_VALUES.value || | |
formatParam == FormatValue.SIMPLIFIED.value -> AttributeRepresentation.SIMPLIFIED | |
formatParam == FormatValue.NORMALIZED.value -> AttributeRepresentation.NORMALIZED | |
optionsParam.contains(FormatValue.KEY_VALUES.value) || | |
optionsParam.contains(FormatValue.SIMPLIFIED.value) -> AttributeRepresentation.SIMPLIFIED | |
else -> AttributeRepresentation.NORMALIZED | |
} | |
val includeSysAttrs = optionsParam.contains(OptionsValue.SYS_ATTRS.value) | |
.flatMap { it.split(",") } | |
.map { OptionsValue.fromString(it).bind() } | |
val formatParam = queryParams.getFirst(QueryParameter.FORMAT.key)?.let { | |
FormatValue.fromString(it).bind() | |
} | |
val attributeRepresentation = when { | |
formatParam == FormatValue.KEY_VALUES || formatParam == FormatValue.SIMPLIFIED -> | |
AttributeRepresentation.SIMPLIFIED | |
formatParam == FormatValue.NORMALIZED -> | |
AttributeRepresentation.NORMALIZED | |
optionsParam.contains(OptionsValue.KEY_VALUES) || optionsParam.contains(OptionsValue.SIMPLIFIED) -> | |
AttributeRepresentation.SIMPLIFIED | |
else -> AttributeRepresentation.NORMALIZED | |
} | |
val includeSysAttrs = optionsParam.contains(OptionsValue.SYS_ATTRS) |
fun fromString(key: String): FormatValue? = | ||
FormatValue.entries.find { it.value == key } |
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.
fun fromString(key: String): FormatValue? = | |
FormatValue.entries.find { it.value == key } | |
fun fromString(key: String): Either<APIException, FormatValue> = either { | |
FormatValue.entries.find { it.value == key } | |
?: return InvalidRequestException("'$key' is not a valid value for the format query parameter").left() | |
} |
There were conflicts with develop that I fixed on github, I clicked on commit after and it did a merge. Can it be fixed? |
…RepresentationTests.kt Co-authored-by: Benoit Orihuela <[email protected]>
Quality Gate passedIssues Measures |
No description provided.