Skip to content
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

refactor: parse representations in entity handlers #1317

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading