Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Naksha_2.2.27
- Added tag filtering, property selection, and limit support to the storage, handler, and space LIST APIs.

## Naksha_2.2.26
- Added HTTP storage circuit-breaker support to isolate slow or failing requests by `storageId`.

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ mavenPassword=YourPassword
# - here-naksha-lib-core/src/main/com/here/naksha/lib/core/NakshaVersion (static property: latest)
# - here-naksha-app-service/src/main/resources/swagger/openapi.yaml (info.version property)
# - CHANGELOG.md
version=2.2.26
version=2.2.27

Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@
import static com.here.naksha.app.service.http.tasks.NoElementsStrategy.FAIL_ON_NO_ELEMENTS;
import static com.here.naksha.app.service.http.tasks.NoElementsStrategy.NOT_FOUND_ON_NO_ELEMENTS;
import static com.here.naksha.common.http.apis.ApiParamsConst.DEF_ADMIN_FEATURE_LIMIT;
import static com.here.naksha.common.http.apis.ApiParamsConst.LIMIT;
import static com.here.naksha.lib.core.util.storage.ResultHelper.readFeatureFromResult;
import static com.here.naksha.lib.core.util.storage.ResultHelper.readFeaturesFromResult;
import static java.util.Collections.emptyList;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.here.naksha.app.service.http.HttpResponseType;
import com.here.naksha.app.service.http.NakshaHttpVerticle;
import com.here.naksha.app.service.http.apis.ApiParams;
import com.here.naksha.app.service.http.ops.PropertySelectionUtil;
import com.here.naksha.app.service.http.ops.TagsUtil;
import com.here.naksha.app.service.http.tasks.processor.FeaturePostProcessor;
import com.here.naksha.app.service.http.tasks.processor.PropertySelectionPostProcessor;
import com.here.naksha.app.service.http.tasks.processor.SequentialPostProcessor;
import com.here.naksha.app.service.models.IterateHandle;
import com.here.naksha.lib.core.AbstractTask;
import com.here.naksha.lib.core.INaksha;
Expand All @@ -38,6 +44,7 @@
import com.here.naksha.lib.core.models.geojson.implementation.XyzFeature;
import com.here.naksha.lib.core.models.geojson.implementation.XyzFeatureCollection;
import com.here.naksha.lib.core.models.payload.XyzResponse;
import com.here.naksha.lib.core.models.payload.events.QueryParameterList;
import com.here.naksha.lib.core.models.storage.ContextXyzFeatureResult;
import com.here.naksha.lib.core.models.storage.EExecutedOp;
import com.here.naksha.lib.core.models.storage.ErrorResult;
Expand Down Expand Up @@ -169,6 +176,18 @@ protected XyzResponse handleNoElements(NoElementsStrategy noElementsStrategy) {
}
}

protected @NotNull XyzResponse executeAdminListRequest(@NotNull String collection, @Nullable FeaturePostProcessor<XyzFeature> masking) {
final QueryParameterList queryParams = ApiParams.queryParamsFromRequest(routingContext);
long limit = ApiParams.extractQueryParamAsLong(queryParams, LIMIT, false, DEF_ADMIN_FEATURE_LIMIT);
limit = (limit < 0 || limit > DEF_ADMIN_FEATURE_LIMIT) ? DEF_ADMIN_FEATURE_LIMIT : limit;
final var propPaths = PropertySelectionUtil.buildPropPathSetFromQueryParams(queryParams);
final FeaturePostProcessor<XyzFeature> postProcessor = SequentialPostProcessor.combine(masking, propPaths == null ? null : new PropertySelectionPostProcessor(propPaths));
final ReadFeatures request = new ReadFeatures(collection).withLimit(limit).withPropertyOp(TagsUtil.buildOperationForTagsQueryParam(queryParams));
try (Result rdResult = executeReadRequestFromSpaceStorage(request)) {
return transformReadResultToXyzCollectionResponse(rdResult, XyzFeature.class, 0, limit, null, postProcessor);
Comment thread
rlakde marked this conversation as resolved.
Resolved
}
}

protected <R extends XyzFeature> @NotNull XyzResponse transformReadResultToXyzCollectionResponse(
final @Nullable Result rdResult,
final @NotNull Class<R> type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,7 @@ protected void init() {}
}

private @NotNull XyzResponse executeGetHandlers() {
// Create ReadFeatures Request to read all handlers from Admin DB
final ReadFeatures request = new ReadFeatures(EVENT_HANDLERS);
// Submit request to NH Space Storage
try (Result rdResult = executeReadRequestFromSpaceStorage(request)) {
// transform ReadResult to Http FeatureCollection response
return transformReadResultToXyzCollectionResponse(rdResult, EventHandler.class, HANDLER_MASKING);
}
return executeAdminListRequest(EVENT_HANDLERS, new MaskingPostProcessor<>());
Comment thread
rlakde marked this conversation as resolved.
Resolved
}

private @NotNull XyzResponse executeGetHandlerById() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ private XyzResponse executeDeleteSpace() {
}

private @NotNull XyzResponse executeGetSpaces() {
final ReadFeatures request = new ReadFeatures(SPACES);
try (Result rdResult = executeReadRequestFromSpaceStorage(request)) {
return transformReadResultToXyzCollectionResponse(rdResult, Space.class);
}
return executeAdminListRequest(SPACES, null);
}

private @NotNull XyzResponse executeGetSpaceById() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ protected void init() {}
}

private @NotNull XyzResponse executeGetStorages() {
final ReadFeatures request = new ReadFeatures(STORAGES);
try (Result rdResult = executeReadRequestFromSpaceStorage(request)) {
return transformReadResultToXyzCollectionResponse(rdResult, Storage.class, STORAGE_MASKING);
}
return executeAdminListRequest(STORAGES, new MaskingPostProcessor<>());
Comment thread
rlakde marked this conversation as resolved.
Resolved
}

private @NotNull XyzResponse executeGetStorageById() {
Expand Down
16 changes: 14 additions & 2 deletions here-naksha-app-service/src/main/resources/swagger/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ servers:
info:
title: "Naksha Hub-API"
description: "Naksha Hub-API is a REST API to provide simple access to geo data."
version: "2.2.26"
version: "2.2.27"

security:
- AccessToken: [ ]
Expand Down Expand Up @@ -50,6 +50,10 @@ paths:
description: >-
Lists the storages, which the current authenticated user has access to.
operationId: getStorages
parameters:
- $ref: '#/components/parameters/TagList'
- $ref: '#/components/parameters/PropertiesSelection'
- $ref: '#/components/parameters/Limit'
responses:
'200':
$ref: '#/components/responses/StoragesResponse'
Expand Down Expand Up @@ -193,6 +197,10 @@ paths:
summary: List event handlers
description: Lists the event handlers, which the current authenticated user has access to.
operationId: getHandlers
parameters:
- $ref: '#/components/parameters/TagList'
- $ref: '#/components/parameters/PropertiesSelection'
- $ref: '#/components/parameters/Limit'
responses:
'200':
$ref: '#/components/responses/HandlersResponse'
Expand Down Expand Up @@ -329,6 +337,10 @@ paths:
summary: List spaces
description: Lists the spaces, which the current authenticated user has access to.
operationId: getSpaces
parameters:
- $ref: '#/components/parameters/TagList'
- $ref: '#/components/parameters/PropertiesSelection'
- $ref: '#/components/parameters/Limit'
responses:
'200':
$ref: '#/components/responses/SpacesResponse'
Expand Down Expand Up @@ -1070,7 +1082,7 @@ components:
name: limit
in: query
description: >-
The maximum number of features in the response.
The maximum number of resources in the response.
Default is _30000_. Hard limit is _100000_.
Comment thread
rlakde marked this conversation as resolved.
Resolved
schema:
type: integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import static com.here.naksha.app.common.assertions.ResponseAssertions.assertThat;
import static org.junit.jupiter.api.Named.named;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.here.naksha.app.common.ApiTest;
import com.here.naksha.app.common.CommonApiTestSetup;
import com.here.naksha.app.common.NakshaTestWebClient;
Expand Down Expand Up @@ -377,6 +379,41 @@ void tc0140_testGetHandlers() throws Exception {
List<String> eventHandlerIds =
returnedXyzFeatures.stream().map(XyzFeature::getId).toList();
Assertions.assertTrue(eventHandlerIds.containsAll(expectedHandlerIds));

// OR tag matching returns handlers with either tag.
final HttpResponse<String> orResponse =
getNakshaClient().get("hub/handlers?tags=handler_tag_alpha,handler_tag_beta", streamId);
assertThat(orResponse).hasStatus(200);
final List<String> orHandlerIds = parseJson(orResponse.body(), XyzFeatureCollection.class).getFeatures().stream()
.map(XyzFeature::getId).toList();
Assertions.assertEquals(2, orHandlerIds.size());
Assertions.assertTrue(orHandlerIds.containsAll(expectedHandlerIds));

// AND tag matching returns only the handler carrying both tags.
final HttpResponse<String> andResponse =
getNakshaClient().get("hub/handlers?tags=handler_tag_alpha+handler_tag_shared", streamId);
assertThat(andResponse).hasStatus(200);
Assertions.assertEquals(
List.of("tc_140_event_handler_1"),
parseJson(andResponse.body(), XyzFeatureCollection.class).getFeatures().stream()
.map(XyzFeature::getId).toList());

// A non-matching tag returns an empty collection.
final HttpResponse<String> noMatchResponse =
getNakshaClient().get("hub/handlers?tags=handler_tag_missing", streamId);
assertThat(noMatchResponse).hasStatus(200);
Assertions.assertEquals(0, parseJson(noMatchResponse.body(), XyzFeatureCollection.class).getFeatures().size());

// Tags, selection, and limit can be combined.
final HttpResponse<String> selectedResponse = getNakshaClient().get(
"hub/handlers?tags=handler_tag_alpha,handler_tag_beta&selection=p.selectionMarker&limit=1",
streamId);
assertThat(selectedResponse).hasStatus(200);
final JsonNode selectedFeatures = new ObjectMapper().readTree(selectedResponse.body()).get("features");
Assertions.assertEquals(1, selectedFeatures.size());
final JsonNode selectedProperties = selectedFeatures.get(0).get("properties");
Assertions.assertTrue(selectedProperties.has("selectionMarker"));
Assertions.assertFalse(selectedProperties.has("storageId"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import static com.here.naksha.app.common.assertions.ResponseAssertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.here.naksha.app.common.ApiTest;
import com.here.naksha.app.common.NakshaTestWebClient;
import com.here.naksha.lib.core.models.geojson.implementation.XyzFeature;
Expand Down Expand Up @@ -169,6 +171,41 @@ void tc0240_testGetSpaces() throws Exception {
List<String> spaceIds =
returnedXyzFeatures.stream().map(XyzFeature::getId).toList();
Assertions.assertTrue(spaceIds.containsAll(expectedSpaceIds));

// OR tag matching returns spaces with either tag.
final HttpResponse<String> orResponse =
getNakshaClient().get("hub/spaces?tags=space_tag_alpha,space_tag_beta", streamId);
assertThat(orResponse).hasStatus(200);
final List<String> orSpaceIds = parseJson(orResponse.body(), XyzFeatureCollection.class).getFeatures().stream()
.map(XyzFeature::getId).toList();
assertEquals(2, orSpaceIds.size());
Assertions.assertTrue(orSpaceIds.containsAll(expectedSpaceIds));

// AND tag matching returns only the space carrying both tags.
final HttpResponse<String> andResponse =
getNakshaClient().get("hub/spaces?tags=space_tag_alpha+space_tag_shared", streamId);
assertThat(andResponse).hasStatus(200);
assertEquals(
List.of("tc_240_space_1"),
parseJson(andResponse.body(), XyzFeatureCollection.class).getFeatures().stream()
.map(XyzFeature::getId).toList());

// A non-matching tag returns an empty collection.
final HttpResponse<String> noMatchResponse =
getNakshaClient().get("hub/spaces?tags=space_tag_missing", streamId);
assertThat(noMatchResponse).hasStatus(200);
assertEquals(0, parseJson(noMatchResponse.body(), XyzFeatureCollection.class).getFeatures().size());

// Tags, selection, and limit can be combined without returning unselected properties.
final HttpResponse<String> selectedResponse = getNakshaClient().get(
"hub/spaces?tags=space_tag_alpha,space_tag_beta&selection=p.selectionMarker&limit=1",
streamId);
assertThat(selectedResponse).hasStatus(200);
final JsonNode selectedFeatures = new ObjectMapper().readTree(selectedResponse.body()).get("features");
assertEquals(1, selectedFeatures.size());
final JsonNode selectedProperties = selectedFeatures.get(0).get("properties");
Assertions.assertTrue(selectedProperties.has("selectionMarker"));
Assertions.assertFalse(selectedProperties.has("collection"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,41 @@ void tc0040_testGetStorages() throws Exception {
}
}
}

// OR tag matching returns resources with either tag.
final HttpResponse<String> orResponse =
getNakshaClient().get("hub/storages?tags=storage_tag_alpha,storage_tag_beta", streamId);
assertThat(orResponse).hasStatus(200);
final List<String> orStorageIds = parseJson(orResponse.body(), XyzFeatureCollection.class).getFeatures().stream()
.map(XyzFeature::getId).toList();
assertEquals(2, orStorageIds.size());
Assertions.assertTrue(orStorageIds.containsAll(expectedStorageIds));

// AND tag matching returns only the resource carrying both tags.
final HttpResponse<String> andResponse =
getNakshaClient().get("hub/storages?tags=storage_tag_alpha+storage_tag_shared", streamId);
assertThat(andResponse).hasStatus(200);
assertEquals(
List.of("tc_040_storage_1"),
parseJson(andResponse.body(), XyzFeatureCollection.class).getFeatures().stream()
.map(XyzFeature::getId).toList());

// A non-matching tag returns an empty collection.
final HttpResponse<String> noMatchResponse =
getNakshaClient().get("hub/storages?tags=storage_tag_missing", streamId);
assertThat(noMatchResponse).hasStatus(200);
assertEquals(0, parseJson(noMatchResponse.body(), XyzFeatureCollection.class).getFeatures().size());

// Tags, selection, and limit can be combined.
final HttpResponse<String> selectedResponse = getNakshaClient().get(
"hub/storages?tags=storage_tag_alpha,storage_tag_beta&selection=p.appName&limit=1",
streamId);
assertThat(selectedResponse).hasStatus(200);
final JsonNode selectedFeatures = new ObjectMapper().readTree(selectedResponse.body()).get("features");
assertEquals(1, selectedFeatures.size());
final JsonNode selectedProperties = selectedFeatures.get(0).get("properties");
Assertions.assertTrue(selectedProperties.has("appName"));
assertFalse(selectedProperties.has("dbConfig"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"active": true,
"extensionId": null,
"properties": {
"@ns:com:here:xyz": {
"tags": ["handler_tag_alpha", "handler_tag_shared"]
},
"selectionMarker": "handler-one",
"storageId": "event_handler_api_test_storage",
"collection": {
"maxAge": 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"active": true,
"extensionId": null,
"properties": {
"@ns:com:here:xyz": {
"tags": ["handler_tag_beta", "handler_tag_shared"]
},
"selectionMarker": "handler-two",
"storageId": "event_handler_api_test_storage",
"collection": {
"maxAge": 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"space-api-test-handler"
],
"properties": {
"@ns:com:here:xyz": {
"tags": ["space_tag_alpha", "space_tag_shared"]
},
"selectionMarker": "space-one",
"collection": {
"id": "um-mod-dev:test",
"type": "NakshaCollection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"space-api-test-handler"
],
"properties": {
"@ns:com:here:xyz": {
"tags": ["space_tag_beta", "space_tag_shared"]
},
"selectionMarker": "space-two",
"collection": {
"id": "um-mod-dev:test",
"type": "NakshaCollection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"description": "UniMap Moderation storage for Dev environment, holding collections managed by Naksha service",
"className": "com.here.naksha.lib.psql.PsqlStorage",
"properties": {
"@ns:com:here:xyz": {
"tags": ["storage_tag_alpha", "storage_tag_shared"]
},
"appName": "storage-one",
"dbConfig": {
"host": "${dataDb.host}",
"db": "${dataDb.db}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"description": "UniMap Moderation storage for Dev environment, holding collections managed by Naksha service",
"className": "com.here.naksha.lib.psql.PsqlStorage",
"properties": {
"@ns:com:here:xyz": {
"tags": ["storage_tag_beta", "storage_tag_shared"]
},
"appName": "storage-two",
"dbConfig": {
"host": "${dataDb.host}",
"db": "${dataDb.db}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ public class NakshaVersion implements Comparable<NakshaVersion> {
public static final String v2_2_24 = "2.2.24";
public static final String v2_2_25 = "2.2.25";
public static final String v2_2_26 = "2.2.26";
public static final String v2_2_27 = "2.2.27";

/**
* The latest version of the naksha-extension stored in the resources.
*/
@AvailableSince(v2_0_5)
public static final NakshaVersion latest = of(v2_2_26);
public static final NakshaVersion latest = of(v2_2_27);

private final int major;
private final int minor;
Expand Down
Loading