Repository navigation
add admin LIST API filters #684
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,9 @@ | |
| import java.util.Set; | ||
| import naksha.base.NakshaError; | ||
| import naksha.base.NakshaException; | ||
| import naksha.model.request.RequestQuery; | ||
| import naksha.model.request.ops.Op; | ||
| import naksha.model.request.ops.QueryConverter; | ||
| import naksha.model.request.query.ITagQuery; | ||
| import naksha.model.request.query.TagAnd; | ||
| import naksha.model.request.query.TagExists; | ||
|
|
@@ -52,6 +55,16 @@ private TagQueryUtil() { | |
| return rootTagOrQuery; | ||
| } | ||
|
|
||
| public static @Nullable Op tagOpFromParams(final @Nullable QueryParameterList queryParams) { | ||
| final ITagQuery tagQuery = tagQueryFromParams(queryParams); | ||
| if (tagQuery == null) { | ||
| return null; | ||
| } | ||
| final RequestQuery requestQuery = new RequestQuery(); | ||
| requestQuery.setTags(tagQuery); | ||
| return QueryConverter.PgQueryConverter_C.convert(requestQuery); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see we could make |
||
| } | ||
|
|
||
| private static void processParams( | ||
| final @NotNull TagOr rootOrQuery, | ||
| final @NotNull QueryParameter tagParams | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| package com.here.naksha.app.service.http.tasks; | ||
|
|
||
| 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 java.util.Collections.emptyList; | ||
| import static java.util.Objects.requireNonNull; | ||
| import static naksha.base.JvmBoxingUtil.box; | ||
|
|
@@ -27,7 +28,12 @@ | |
|
|
||
| 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.TagQueryUtil; | ||
| 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; | ||
|
|
@@ -41,10 +47,10 @@ | |
| import java.util.Map; | ||
| import naksha.base.AnyObject; | ||
| import naksha.base.FromJsonOptions; | ||
| import naksha.base.Platform; | ||
| import naksha.base.Action; | ||
| import naksha.model.NakshaContext; | ||
| import naksha.base.NakshaError; | ||
| import naksha.base.Platform; | ||
| import naksha.model.SessionOptions; | ||
| import naksha.model.XyzFeatureCollection; | ||
| import naksha.model.objects.NakshaFeature; | ||
|
|
@@ -54,6 +60,8 @@ | |
| import naksha.model.request.Response; | ||
| import naksha.model.request.SuccessResponse; | ||
| import naksha.model.request.WriteRequest; | ||
| import naksha.model.request.ops.Op; | ||
| import com.here.naksha.lib.core.models.payload.events.QueryParameterList; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.slf4j.Logger; | ||
|
|
@@ -108,6 +116,25 @@ protected XyzResponse handleNoElements(@NotNull NoElementsStrategy noElementsStr | |
| return verticle.sendErrorResponse(routingContext, noElementsStrategy.nakshaError); | ||
| } | ||
|
|
||
| protected <F extends NakshaFeature> @NotNull XyzResponse executeAdminListRequest( | ||
| @NotNull String collection, | ||
| @NotNull Class<F> type, | ||
| @Nullable FeaturePostProcessor<F> masking) { | ||
| final QueryParameterList queryParams = ApiParams.queryParamsFromRequest(routingContext); | ||
| long limit = ApiParams.extractQueryParamAsLong(queryParams, LIMIT, false, DEF_ADMIN_FEATURE_LIMIT); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for limit in Naksha v3 we usually used "extractQueryParamAsInt" , that way we don't have to cast it to int later. |
||
| limit = (limit < 0 || limit > DEF_ADMIN_FEATURE_LIMIT) ? DEF_ADMIN_FEATURE_LIMIT : limit; | ||
| final var propPaths = PropertySelectionUtil.buildPropPathSetFromQueryParams(queryParams); | ||
| final FeaturePostProcessor<F> postProcessor = SequentialPostProcessor.combine( | ||
| masking, propPaths == null ? null : new PropertySelectionPostProcessor<>(propPaths)); | ||
| final Op tagOp = TagQueryUtil.tagOpFromParams(queryParams); | ||
| final ReadFeatures request = new ReadFeatures().withCollectionId(collection); | ||
| request.setQueryMembers(tagOp); | ||
| request.setLimit((int) limit); | ||
| request.setCatalogId(naksha().getAdminMapId()); | ||
| final Response response = executeReadRequestFromSpaceStorage(request); | ||
| return transformResponseToXyzCollectionResponse(response, type, 0, (int) limit, null, postProcessor); | ||
| } | ||
|
|
||
| protected <F extends NakshaFeature> @NotNull XyzResponse transformResponseToXyzFeatureResponse( | ||
| final @Nullable Response response, | ||
| final @NotNull Class<F> type, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,10 @@ | |
| import com.here.naksha.lib.core.util.PropertyPathUtil; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import naksha.base.Platform; | ||
| import naksha.model.objects.NakshaFeature; | ||
|
|
||
| public final class PropertySelectionPostProcessor implements FeaturePostProcessor<NakshaFeature> { | ||
| public final class PropertySelectionPostProcessor<T extends NakshaFeature> implements FeaturePostProcessor<T> { | ||
|
|
||
| private final Set<String> propPaths; | ||
|
|
||
|
|
@@ -32,10 +33,10 @@ public PropertySelectionPostProcessor(Set<String> propPaths) { | |
| } | ||
|
|
||
| @Override | ||
| public NakshaFeature postProcess(NakshaFeature feature) { | ||
| Map<String, Object> tgtMap = PropertyPathUtil.extractPropertyMapFromFeature(feature, propPaths); | ||
| NakshaFeature newF = new NakshaFeature(); | ||
| newF.putAll(tgtMap); | ||
| return newF; | ||
| @SuppressWarnings("unchecked") | ||
| public T postProcess(T feature) { | ||
| final Map<String, Object> targetMap = PropertyPathUtil.extractPropertyMapFromFeature(feature, propPaths); | ||
| final Class<T> type = (Class<T>) feature.getClass(); | ||
| return Platform.javaProxy(Platform.fromJSON(Platform.toJSON(targetMap)), type); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With that change we would converse every feature to JSON and parse it back, and it's postProcessor so it's sheared by read API, that can became quite heavy quite fast. Instead we could use something like we wouldn't change nested values to Platform objects but it's posproccesor last step before we serialize it as HTTP response. |
||
| } | ||
| } | ||
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.
nice one 😃