Skip to content

Commit

Permalink
refactor: parse representations in entity handlers (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranim-n authored Jan 16, 2025
1 parent 991c7bb commit 14f80e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,13 @@ class EntityAccessControlHandler(
@AllowedParameters(implemented = [QP.ID, QP.TYPE, QP.ATTRS, QP.COUNT, QP.OFFSET, QP.LIMIT, QP.INCLUDE_DELETED])
@RequestParam queryParams: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val mediaType = getApplicableMediaType(httpHeaders).bind()
val ngsiLdDataRepresentation = parseRepresentations(queryParams, mediaType).bind()

val sub = getSubFromSecurityContext()
val includeDeleted = queryParams.getFirst(QueryParameter.INCLUDE_DELETED.key)?.toBoolean() == true

val contexts = getAuthzContextFromLinkHeaderOrDefault(httpHeaders, applicationProperties.contexts).bind()
val mediaType = getApplicableMediaType(httpHeaders).bind()

val entitiesQuery = composeEntitiesQueryFromGet(
applicationProperties.pagination,
Expand All @@ -105,7 +107,6 @@ class EntityAccessControlHandler(

val compactedEntities = compactEntities(entities, contexts)

val ngsiLdDataRepresentation = parseRepresentations(queryParams, mediaType).bind()
buildQueryResponse(
compactedEntities.toFinalRepresentation(ngsiLdDataRepresentation),
count,
Expand All @@ -126,10 +127,12 @@ class EntityAccessControlHandler(
@AllowedParameters(implemented = [QP.COUNT, QP.OFFSET, QP.LIMIT])
@RequestParam params: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val mediaType = getApplicableMediaType(httpHeaders).bind()
val ngsiLdDataRepresentation = parseRepresentations(params, mediaType).bind()

val sub = getSubFromSecurityContext()

val contexts = getAuthzContextFromLinkHeaderOrDefault(httpHeaders, applicationProperties.contexts).bind()
val mediaType = getApplicableMediaType(httpHeaders).bind()
val entitiesQuery = composeEntitiesQueryFromGet(
applicationProperties.pagination,
params,
Expand All @@ -150,7 +153,6 @@ class EntityAccessControlHandler(

val compactedEntities = compactEntities(entities, contexts)

val ngsiLdDataRepresentation = parseRepresentations(params, mediaType).bind()
buildQueryResponse(
compactedEntities.toFinalRepresentation(ngsiLdDataRepresentation),
count,
Expand All @@ -171,12 +173,14 @@ class EntityAccessControlHandler(
@AllowedParameters(implemented = [QP.COUNT, QP.OFFSET, QP.LIMIT])
@RequestParam params: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val mediaType = getApplicableMediaType(httpHeaders).bind()
val ngsiLdDataRepresentation = parseRepresentations(params, mediaType).bind()

val sub = getSubFromSecurityContext()

authorizationService.userIsAdmin(sub).bind()

val contexts = getAuthzContextFromLinkHeaderOrDefault(httpHeaders, applicationProperties.contexts).bind()
val mediaType = getApplicableMediaType(httpHeaders).bind()
val entitiesQuery = composeEntitiesQueryFromGet(
applicationProperties.pagination,
params,
Expand All @@ -196,7 +200,6 @@ class EntityAccessControlHandler(

val compactedEntities = compactEntities(entities, contexts)

val ngsiLdDataRepresentation = parseRepresentations(params, mediaType).bind()
buildQueryResponse(
compactedEntities.toFinalRepresentation(ngsiLdDataRepresentation),
count,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ class EntityHandler(
@RequestParam queryParams: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val mediaType = getApplicableMediaType(httpHeaders).bind()
val sub = getSubFromSecurityContext()
val ngsiLdDataRepresentation = parseRepresentations(queryParams, mediaType).bind()

val sub = getSubFromSecurityContext()
val contexts = getContextFromLinkHeaderOrDefault(httpHeaders, applicationProperties.contexts.core).bind()
val entitiesQuery = composeEntitiesQueryFromGet(applicationProperties.pagination, queryParams, contexts).bind()
.validateMinimalQueryEntitiesParameters().bind()
Expand Down Expand Up @@ -230,7 +231,6 @@ class EntityHandler(
warnings to (mergedEntities ?: emptyList())
}

val ngsiLdDataRepresentation = parseRepresentations(queryParams, mediaType).bind()
buildQueryResponse(
mergedEntities.toFinalRepresentation(ngsiLdDataRepresentation),
maxCount,
Expand Down Expand Up @@ -262,6 +262,7 @@ class EntityHandler(
@RequestParam queryParams: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val mediaType = getApplicableMediaType(httpHeaders).bind()
val ngsiLdDataRepresentation = parseRepresentations(queryParams, mediaType).bind()
val sub = getSubFromSecurityContext()

val contexts = getContextFromLinkHeaderOrDefault(httpHeaders, applicationProperties.contexts.core).bind()
Expand Down Expand Up @@ -302,7 +303,6 @@ class EntityHandler(
val mergedEntityWithLinkedEntities =
linkedEntityService.processLinkedEntities(mergedEntity, entitiesQuery, sub.getOrNull()).bind()

val ngsiLdDataRepresentation = parseRepresentations(queryParams, mediaType).bind()
prepareGetSuccessResponseHeaders(mediaType, contexts)
.let {
val body = if (mergedEntityWithLinkedEntities.size == 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,12 @@ class EntityOperationHandler(
)
@RequestParam queryParams: MultiValueMap<String, String>
): ResponseEntity<*> = either {
val sub = getSubFromSecurityContext()
val contexts = getContextFromLinkHeaderOrDefault(httpHeaders, applicationProperties.contexts.core).bind()
val mediaType = getApplicableMediaType(httpHeaders).bind()
val query = Query(requestBody.awaitFirst()).bind()

val ngsiLdDataRepresentation = parseRepresentations(queryParams, mediaType).bind()
.copy(languageFilter = query.lang)
val sub = getSubFromSecurityContext()
val contexts = getContextFromLinkHeaderOrDefault(httpHeaders, applicationProperties.contexts.core).bind()
val entitiesQuery = composeEntitiesQueryFromPost(
applicationProperties.pagination,
query,
Expand All @@ -280,10 +281,6 @@ class EntityOperationHandler(
val filteredEntities = entities.filterAttributes(entitiesQuery.attrs, entitiesQuery.datasetId)

val compactedEntities = compactEntities(filteredEntities, contexts)

val ngsiLdDataRepresentation = parseRepresentations(queryParams, mediaType).bind()
.copy(languageFilter = query.lang)

buildQueryResponse(
compactedEntities.toFinalRepresentation(ngsiLdDataRepresentation),
count,
Expand Down

0 comments on commit 14f80e3

Please sign in to comment.