-
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 70 files +1 70 suites +1 1m 21s ⏱️ -1s Results for commit e89b116. ± Comparison against base commit a76f793. This pull request removes 194 and adds 44 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
package com.egm.stellio.shared.queryparameter | ||
|
||
enum class FormatValue(val value: String) { | ||
KEY_VALUES("keyValues"), |
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.
don't forget to remove it in the OptionsValues
enum
shared/src/main/kotlin/com/egm/stellio/shared/queryparameter/FormatValue.kt
Show resolved
Hide resolved
TEMPORAL_VALUES("temporalValues"), | ||
AUDIT("audit"), | ||
AGGREGATED_VALUES("aggregatedValues") | ||
} | ||
|
||
fun hasValueInOptionsParam(options: Optional<String>, optionValue: OptionsParamValue): Boolean = | ||
fun hasValueInQueryParam(options: Optional<String>, queryParamValue: QueryParamValue): Boolean = |
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.
options
is no longer a good name for the 1st parameter
@@ -168,16 +168,16 @@ internal fun canExpandJsonLdKeyFromCore(contexts: List<String>): Boolean { | |||
return expandedType == NGSILD_DATASET_ID_PROPERTY | |||
} | |||
|
|||
enum class OptionsParamValue(val value: String) { | |||
enum class QueryParamValue(val value: 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.
TEMPORAL_VALUES
and AGGREGATED_VALUES
should be moved / merged in FormatValue
. AUDIT
should be moved / merged in OptionsValue
@@ -33,27 +33,27 @@ class ApiUtilsTests { | |||
|
|||
@Test | |||
fun `it should not find a value if there is no options query param`() { |
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.
also update the names of the test functions (options
is no longer valid)
@@ -480,6 +480,47 @@ class EntityHandlerTests { | |||
) | |||
} | |||
|
|||
@Test | |||
fun `get entity by id should correctly return the representation asked in the format parameter`() { |
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.
better add one or more tests on the parseRepresentations
function in NgsiLdDataRepresentation
@@ -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
@@ -42,21 +43,29 @@ fun composeTemporalEntitiesQueryFromGet( | |||
requestParams, | |||
contexts | |||
).bind() | |||
|
|||
if (inQueryEntities) | |||
var withTemporalValues = false |
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.
instead of using these 2 booleans, it will be cleaner to switch to an enum similar to the AttributeRepresentation
one
…/web/TemporalEntityHandlerTests.kt Co-authored-by: Benoit Orihuela <[email protected]>
Quality Gate passedIssues Measures |
fun extractTemporalRepresentation(requestParams: MultiValueMap<String, String>): | ||
Either<APIException, TemporalRepresentation> = either { | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can be simplified. By adding a fromString function to the TemporalRepresentation enum.
No description provided.