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

Read in additional sorts from query properties #20

Merged
merged 1 commit into from
May 28, 2020
Merged
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
82 changes: 51 additions & 31 deletions src/main/java/com/connexta/ddf/catalog/direct/CatalogMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,53 @@ private Object update(Map<String, Object> params) {
.collect(Collectors.toList()));
}

private static Object getSortBy(Map<String, Object> rawSortPolicy) {
if (!(rawSortPolicy.get("propertyName") instanceof String)) {
return new Error(
INVALID_PARAMS,
"propertyName was not a string or was missing",
ImmutableMap.of("irritant", ImmutableList.of("params", "sortPolicy", "propertyName")));
}
String propertyName = (String) rawSortPolicy.get("propertyName");

if (!(rawSortPolicy.get("sortOrder") instanceof String)) {
return new Error(
INVALID_PARAMS,
"sortOrder was not a string or was missing",
ImmutableMap.of("irritant", ImmutableList.of("params", "sortPolicy", "sortOrder")));
}
String sortOrderString = (String) rawSortPolicy.get("sortOrder");
SortOrder sortOrder;
if ("ascending".equalsIgnoreCase(sortOrderString) || "asc".equalsIgnoreCase(sortOrderString)) {
sortOrder = SortOrder.ASCENDING;
} else if ("descending".equalsIgnoreCase(sortOrderString)
|| "desc".equalsIgnoreCase(sortOrderString)) {
sortOrder = SortOrder.DESCENDING;
} else {
return new Error(
INVALID_PARAMS,
"sortOrder was not asc[ending] or desc[ending]",
ImmutableMap.of("irritant", ImmutableList.of("params", "sortPolicy", "sortOrder")));
}
SortBy sortPolicy = new SortByImpl(new PropertyNameImpl(propertyName), sortOrder);
return sortPolicy;
}

private Map getProperties(Map<String, Object> properties) {
Map<String, Object> result = new HashMap<>();
if (properties.containsKey("additional-sort-bys")) {
SortBy[] additionalSortBys =
(SortBy[])
((List) properties.get("additional-sort-bys"))
.stream()
.map(sort -> getSortBy((Map) sort))
.toArray(SortBy[]::new);
result.put("additional-sort-bys", additionalSortBys);
}

return result;
}

private Object query(Map<String, Object> params) {
Filter filter = null;
if (params.containsKey("cql") && params.containsKey("query")) {
Expand Down Expand Up @@ -321,37 +368,7 @@ private Object query(Map<String, Object> params) {
if (params.containsKey("sortPolicy")) {
if (params.get("sortPolicy") instanceof Map) {
Map<String, Object> rawSortPolicy = (Map) params.get("sortPolicy");

if (!(rawSortPolicy.get("propertyName") instanceof String)) {
return new Error(
INVALID_PARAMS,
"propertyName was not a string or was missing",
ImmutableMap.of(
"irritant", ImmutableList.of("params", "sortPolicy", "propertyName")));
}
String propertyName = (String) rawSortPolicy.get("propertyName");

if (!(rawSortPolicy.get("sortOrder") instanceof String)) {
return new Error(
INVALID_PARAMS,
"sortOrder was not a string or was missing",
ImmutableMap.of("irritant", ImmutableList.of("params", "sortPolicy", "sortOrder")));
}
String sortOrderString = (String) rawSortPolicy.get("sortOrder");
SortOrder sortOrder;
if ("ascending".equalsIgnoreCase(sortOrderString)
|| "asc".equalsIgnoreCase(sortOrderString)) {
sortOrder = SortOrder.ASCENDING;
} else if ("descending".equalsIgnoreCase(sortOrderString)
|| "desc".equalsIgnoreCase(sortOrderString)) {
sortOrder = SortOrder.DESCENDING;
} else {
return new Error(
INVALID_PARAMS,
"sortOrder was not asc[ending] or desc[ending]",
ImmutableMap.of("irritant", ImmutableList.of("params", "sortPolicy", "sortOrder")));
}
sortPolicy = new SortByImpl(new PropertyNameImpl(propertyName), sortOrder);
sortPolicy = (SortBy) getSortBy(rawSortPolicy);
}
}

Expand Down Expand Up @@ -379,6 +396,9 @@ private Object query(Map<String, Object> params) {
}

Map<String, Serializable> properties = new HashMap<>();
if (params.containsKey("properties")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this key just not being used before?

Copy link
Contributor Author

@samuelechu samuelechu May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is always passed empty when constructing the queryRequest sent to the catalogFramework query method https://github.com/connexta/ddf-jsonrpc/blob/master/src/main/java/com/connexta/ddf/catalog/direct/CatalogMethods.java#L384-L409

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
^ Here is an example queryRequest to the catalogFramework not using the rpc

I think we will have to update the getProperties method to also read in other properties as well https://github.com/connexta/ddf-jsonrpc/pull/20/files#diff-4b8f31c7553886d543ac3f68641f3f4eR296

properties = getProperties((Map) params.get("properties"));
}
QueryResponse queryResponse;

QueryRequestImpl queryRequest =
Expand Down