Skip to content

Commit

Permalink
CASL-576 Property Search - Draft
Browse files Browse the repository at this point in the history
Signed-off-by: adamczyk-HERE <[email protected]>
  • Loading branch information
adamczyk-HERE committed Oct 8, 2024
1 parent 91cea2b commit 02f6176
Show file tree
Hide file tree
Showing 4 changed files with 350 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ protected void init() {}
queryParamsMap.put(EAST, east);
queryParamsMap.put(SOUTH, south);
queryParamsMap.put(LIMIT, limit);
queryParamsMap.put(CLIP_GEO, clip);
if (propSearchOp != null) {
queryParamsMap.put(PROPERTY_SEARCH_OP, propSearchOp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
@JsonTypeName(value = "PropertyQuery")
public class PropertyQuery {

public PropertyQuery() {}

public PropertyQuery(@NotNull String key, @NotNull QueryOperation op) {}
public PropertyQuery(@NotNull String key, @NotNull QueryOperation op) {
this.key = key;
this.operation = op;
}

/** The property key as JSON path. */
private String key;
Expand Down Expand Up @@ -93,4 +94,14 @@ public void setValues(@NotNull List<@Nullable Object> values) {
this.values = values;
return this;
}

public enum QueryOperation {
EQUALS,
NOT_EQUALS,
LESS_THAN,
GREATER_THAN,
LESS_THAN_OR_EQUALS,
GREATER_THAN_OR_EQUALS,
CONTAINS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,103 @@
*/
package com.here.naksha.storage.http.connector;

import static com.here.naksha.common.http.apis.ApiParamsConst.FEATURE_IDS;
import static com.here.naksha.common.http.apis.ApiParamsConst.*;

import com.here.naksha.lib.core.NakshaContext;
import com.here.naksha.lib.core.models.geojson.coordinates.BBox;
import com.here.naksha.lib.core.models.geojson.implementation.XyzFeatureCollection;
import com.here.naksha.lib.core.models.naksha.Space;
import com.here.naksha.lib.core.models.payload.Event;
import com.here.naksha.lib.core.models.payload.events.PropertyQueryOr;
import com.here.naksha.lib.core.models.payload.events.feature.GetFeaturesByBBoxEvent;
import com.here.naksha.lib.core.models.payload.events.feature.GetFeaturesByIdEvent;
import com.here.naksha.lib.core.models.storage.POp;
import com.here.naksha.lib.core.models.storage.ReadFeaturesProxyWrapper;
import com.here.naksha.lib.core.models.storage.Result;
import com.here.naksha.lib.core.util.json.JsonSerializable;
import com.here.naksha.storage.http.PrepareResult;
import com.here.naksha.storage.http.RequestSender;
import java.net.http.HttpResponse;
import java.util.List;
import org.apache.commons.lang3.NotImplementedException;
import org.jetbrains.annotations.NotNull;

public class ConnectorInterfaceReadExecute {

@NotNull
public static Result execute(NakshaContext context, ReadFeaturesProxyWrapper request, RequestSender sender) {
return switch (request.getReadRequestType()) {
case GET_BY_IDS -> executeFeaturesByIds(context, request, sender);
default -> throw new IllegalStateException("Unexpected value: " + request.getReadRequestType());
};
}
String streamId = context.getStreamId();
String dataHubSpaceName = request.getCollections().get(0);
Space dataHubSpace = new Space(dataHubSpaceName);

Event event =
switch (request.getReadRequestType()) {
case GET_BY_ID -> createFeatureByIdEvent(request);
case GET_BY_IDS -> createFeaturesByIdsEvent(request);
case GET_BY_BBOX -> createFeatureByBBoxEvent(request);
case GET_BY_TILE -> createFeaturesByTileEvent(request);
default -> throw new IllegalStateException("Unexpected value: " + request.getReadRequestType());
};

private static Result executeFeaturesByIds(
NakshaContext context, ReadFeaturesProxyWrapper request, RequestSender sender) {
Event event = createFeaturesByIdsEvent(request, context.getStreamId());
event.setSpace(dataHubSpace);
event.setStreamId(streamId);

String jsonEvent = JsonSerializable.serialize(event);
HttpResponse<byte[]> httpResponse = post(sender, jsonEvent);

return PrepareResult.prepareResult(httpResponse, XyzFeatureCollection.class, XyzFeatureCollection::getFeatures);
}

private static Event createFeaturesByIdsEvent(ReadFeaturesProxyWrapper request, String streamId) {
String dataHubSpaceName = request.getCollections().get(0);
Space dataHubSpace = new Space(dataHubSpaceName);
private static Event createFeaturesByIdsEvent(ReadFeaturesProxyWrapper request) {
List<String> id = request.getQueryParameter(FEATURE_IDS);
Event getFeaturesByIdEvent = new GetFeaturesByIdEvent().withIds(id);
return new GetFeaturesByIdEvent().withIds(id);
}

private static Event createFeatureByIdEvent(ReadFeaturesProxyWrapper request) {
String id = request.getQueryParameter(FEATURE_ID);
return new GetFeaturesByIdEvent().withIds(List.of(id));
}

private static Event createFeatureByBBoxEvent(ReadFeaturesProxyWrapper request) {
BBox bBox = new BBox(
request.getQueryParameter(WEST),
request.getQueryParameter(SOUTH),
request.getQueryParameter(EAST),
request.getQueryParameter(NORTH));
Long limit = request.getQueryParameter(LIMIT);
boolean clip = request.getQueryParameter(CLIP_GEO);
POp propertyOp = request.getPropertyOp();

GetFeaturesByBBoxEvent getFeaturesByBBoxEvent = new GetFeaturesByBBoxEvent();
getFeaturesByBBoxEvent.setLimit(limit);
getFeaturesByBBoxEvent.setBbox(bBox);
getFeaturesByBBoxEvent.setClip(clip);
if (propertyOp != null) {
PropertyQueryOr propertiesQuery = new PropertyQueryOr();
propertiesQuery.add(POpToPropQueryConverter.p0pToQuery(propertyOp));
getFeaturesByBBoxEvent.setPropertiesQuery(propertiesQuery);
}

return getFeaturesByBBoxEvent;
}

private static Event createFeaturesByTileEvent(ReadFeaturesProxyWrapper request) throws NotImplementedException {
// Long margin = request.getQueryParameter(MARGIN);
// Long limit = request.getQueryParameter(LIMIT);
// String tileType = request.getQueryParameter(TILE_TYPE);
// String tileId = request.getQueryParameter(TILE_ID);
//
// if (tileType != null && !tileType.equals(TILE_TYPE_QUADKEY))
// throw new NotImplementedException("Tile type other than " + TILE_TYPE_QUADKEY);
// // TODO adamczyk - do we support other?
// // TODO adamczyk catch the exception
//
// GetFeaturesByTileEvent getFeaturesByTileEvent = new GetFeaturesByTileEvent();
// getFeaturesByTileEvent.setHereTileFlag(false);
// getFeaturesByTileEvent.setMargin(margin.intValue());
// getFeaturesByTileEvent.setLimit(limit);

getFeaturesByIdEvent.setSpace(dataHubSpace);
getFeaturesByIdEvent.setStreamId(streamId);
return getFeaturesByIdEvent;
throw new NotImplementedException();
}

private static HttpResponse<byte[]> post(RequestSender sender, String body) {
Expand Down
Loading

0 comments on commit 02f6176

Please sign in to comment.