From f9dc1658c8a3cc7dd7623c1bfadc846e0756e04c Mon Sep 17 00:00:00 2001 From: Claudio Mezzasalma Date: Fri, 23 Jul 2021 14:58:29 +0200 Subject: [PATCH] Use standard SortOrder instead of SortDirection in Channels REST API Signed-off-by: Claudio Mezzasalma --- .../app/api/resources/v1/resources/DataChannels.java | 8 +++++--- .../openapi/dataChannel/dataChannel-scopeId.yaml | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java index 4877d7fb44b..6710a8221c6 100644 --- a/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java +++ b/rest-api/resources/src/main/java/org/eclipse/kapua/app/api/resources/v1/resources/DataChannels.java @@ -22,6 +22,7 @@ import org.eclipse.kapua.app.api.core.model.ScopeId; import org.eclipse.kapua.app.api.core.model.StorableEntityId; import org.eclipse.kapua.locator.KapuaLocator; +import org.eclipse.kapua.model.query.SortOrder; import org.eclipse.kapua.service.KapuaService; import org.eclipse.kapua.service.datastore.ChannelInfoFactory; import org.eclipse.kapua.service.datastore.ChannelInfoRegistryService; @@ -62,7 +63,7 @@ public class DataChannels extends AbstractKapuaResource { * @param clientId The client id to filter results. * @param name The channel name to filter results. It allows '#' wildcard in last channel level * @param sortParam The name of the parameter that will be used as a sorting key - * @param sortDir The sort direction. Can be DESC (default), ASC. Case-insensitive. + * @param sortDir The sort direction. Can be ASCENDING (default), DESCENDING. Case-insensitive. * @param offset The result set offset. * @param limit The result set limit. * @return The {@link ChannelInfoListResult} of all the channelInfos associated to the current selected scope. @@ -75,7 +76,7 @@ public ChannelInfoListResult simpleQuery(@PathParam("scopeId") ScopeId scopeId, @QueryParam("clientId") String clientId, @QueryParam("name") String name, @QueryParam("sortParam") String sortParam, - @QueryParam("sortDir") @DefaultValue("DESC") SortDirection sortDir, + @QueryParam("sortDir") @DefaultValue("ASCENDING") SortOrder sortDir, @QueryParam("offset") @DefaultValue("0") int offset, @QueryParam("limit") @DefaultValue("50") int limit) throws KapuaException { @@ -95,7 +96,8 @@ public ChannelInfoListResult simpleQuery(@PathParam("scopeId") ScopeId scopeId, query.setOffset(offset); query.setLimit(limit); if (!Strings.isNullOrEmpty(sortParam)) { - query.setSortFields(Collections.singletonList(SortField.of(sortParam, sortDir))); + SortDirection storableSortDirection = sortDir == SortOrder.DESCENDING ? SortDirection.DESC : SortDirection.ASC; + query.setSortFields(Collections.singletonList(SortField.of(sortParam, storableSortDirection))); } return query(scopeId, query); } diff --git a/rest-api/resources/src/main/resources/openapi/dataChannel/dataChannel-scopeId.yaml b/rest-api/resources/src/main/resources/openapi/dataChannel/dataChannel-scopeId.yaml index c9334fa8fe4..0d41a01ac7a 100644 --- a/rest-api/resources/src/main/resources/openapi/dataChannel/dataChannel-scopeId.yaml +++ b/rest-api/resources/src/main/resources/openapi/dataChannel/dataChannel-scopeId.yaml @@ -35,15 +35,15 @@ paths: in: query schema: type: string - - description: The sort direction. Can be ascending or descending (default). + - description: The sort direction. Can be ascending (default) or descending. name: sortDir in: query schema: type: string enum: - - ASC - - DESC - default: DESC + - ASCENDING + - DESCENDING + default: ASCENDING - $ref: '../openapi.yaml#/components/parameters/limit' - $ref: '../openapi.yaml#/components/parameters/offset' responses: