Skip to content

Commit

Permalink
DDF-3741 Add query multisort and refactor sorting (#3154)
Browse files Browse the repository at this point in the history
* DDF-3741 Add query multisort and refactor sorting

DDF-3741 Fix search settings view

DDF-3741 Fix query sorting

DDF-3741 Correct formatting

DDF-3741 Fix boon parsing

DDF-3741 Fix frontend sorting

DDF-3741 Add 'add sort' button

DDF-3741 Update unit tests

* DDF-3741 Add duplicate sort warnings

* DDF-3741 Fix package.json

* DDF-3741 Fix sort persistence

* DDF-3741 Pair programming with Brendan

 - Change to a vertical grouping so right-side panel fits better
 - Factor out a reusable bracket mixin
 - Fix spacing when views are too narrow

* DDF-3741 Clean up additional sorts property

* DDF-3741 Pull out sort layout view

* DDF-3741 Missed a sorts.bys

* DDF-3741 Fix remove and depends

* DDF-3741 Fix sending sorts to backend

* DDF-3741 Fix wildcard imports
  • Loading branch information
brendan-hofmann authored Apr 30, 2018
1 parent 61c50c9 commit 33ce12d
Show file tree
Hide file tree
Showing 52 changed files with 569 additions and 358 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ public final class Constants {
public static final String SUGGESTION_DICT_KEY = "suggestion-dictionary";

public static final String SUGGESTION_RESULT_KEY = "suggestion-result";

public static final String ADDITIONAL_SORT_BYS = "additional-sort-bys";
}
2 changes: 1 addition & 1 deletion catalog/core/catalog-core-directorymonitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
<version>1.2</version>
<version>${servicemix-depends.version}</version>
<executions>
<execution>
<id>generate-depends-file</id>
Expand Down
Binary file not shown.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package ddf.catalog.source.solr;

import static ddf.catalog.Constants.ADDITIONAL_SORT_BYS;
import static ddf.catalog.Constants.EXPERIMENTAL_FACET_PROPERTIES_KEY;
import static ddf.catalog.Constants.EXPERIMENTAL_FACET_RESULTS_KEY;
import static ddf.catalog.Constants.SUGGESTION_CONTEXT_KEY;
Expand Down Expand Up @@ -92,8 +93,6 @@ public class SolrMetacardClientImpl implements SolrMetacardClient {
private static final String GEOMETRY_SORT_FIELD =
Metacard.GEOGRAPHY + SchemaFields.GEO_SUFFIX + SchemaFields.SORT_KEY_SUFFIX;

private static final String EXT_SORT_BY = "additional.sort.bys";

private static final Logger LOGGER = LoggerFactory.getLogger(SolrMetacardClientImpl.class);

private static final String QUOTE = "\"";
Expand Down Expand Up @@ -378,7 +377,7 @@ protected SolrQuery getSolrQuery(QueryRequest request, SolrFilterDelegate solrFi
}
}

Serializable sortBySer = request.getPropertyValue(EXT_SORT_BY);
Serializable sortBySer = request.getPropertyValue(ADDITIONAL_SORT_BYS);
if (sortBySer instanceof SortBy[]) {
SortBy[] extSortBys = (SortBy[]) sortBySer;
sortBys.addAll(Arrays.asList(extSortBys));
Expand Down Expand Up @@ -524,7 +523,7 @@ protected String setSortProperty(
}
}

Serializable sortBySer = request.getPropertyValue(EXT_SORT_BY);
Serializable sortBySer = request.getPropertyValue(ADDITIONAL_SORT_BYS);
if (sortBySer instanceof SortBy[]) {
SortBy[] extSortBys = (SortBy[]) sortBySer;
if (extSortBys.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package ddf.catalog.source.solr.provider;

import static com.google.common.truth.Truth.assertThat;
import static ddf.catalog.Constants.ADDITIONAL_SORT_BYS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

Expand Down Expand Up @@ -53,8 +54,6 @@ public class SolrProviderSorting extends SolrProviderTestBase {

private static final Logger LOGGER = LoggerFactory.getLogger(SolrProviderSorting.class);

private static final String EXT_SORT_BY = "additional.sort.bys";

private static final String DOUBLE_FIELD = "hertz";
private static final double DOUBLE_FIELD_VALUE = 16065.435;

Expand Down Expand Up @@ -443,7 +442,7 @@ public void testSortingMultipleAttributes() throws Exception {
SortBy titleSort =
new ddf.catalog.filter.impl.SortByImpl(Metacard.TITLE, SortOrder.ASCENDING.name());
SortBy[] additionalSorts = new SortBy[] {relevanceSort, titleSort};
properties.put(EXT_SORT_BY, additionalSorts);
properties.put(ADDITIONAL_SORT_BYS, additionalSorts);
sourceResponse = provider.query(new QueryRequestImpl(query, properties));

assertEquals(list.size(), sourceResponse.getResults().size());
Expand Down Expand Up @@ -488,7 +487,7 @@ public void testSortingMultipleAttributesGeoAndRelevance() throws Exception {
SortBy distanceSort =
new ddf.catalog.filter.impl.SortByImpl(Result.DISTANCE, SortOrder.ASCENDING.name());
SortBy[] additionalSorts = new SortBy[] {distanceSort};
properties.put(EXT_SORT_BY, additionalSorts);
properties.put(ADDITIONAL_SORT_BYS, additionalSorts);
sourceResponse = provider.query(new QueryRequestImpl(query, properties));

assertEquals(list.size(), sourceResponse.getResults().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package ddf.catalog.cache.solr.impl;

import static ddf.catalog.Constants.ADDITIONAL_SORT_BYS;

import ddf.catalog.data.Attribute;
import ddf.catalog.data.Metacard;
import ddf.catalog.data.Result;
Expand Down Expand Up @@ -56,8 +58,6 @@
import org.slf4j.LoggerFactory;

class SortedQueryMonitor implements Runnable {
private static final String EXT_SORT_BY = "additional.sort.bys";

private static final Logger LOGGER = LoggerFactory.getLogger(SortedQueryMonitor.class);

private final QueryRequest request;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void run() {
if (sortBy != null && sortBy.getPropertyName() != null) {
sortBys.add(sortBy);
}
Serializable sortBySer = request.getPropertyValue(EXT_SORT_BY);
Serializable sortBySer = request.getPropertyValue(ADDITIONAL_SORT_BYS);
if (sortBySer instanceof SortBy[]) {
SortBy[] extSortBys = (SortBy[]) sortBySer;
if (extSortBys.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion catalog/rest/catalog-rest-endpoint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
<plugin>
<groupId>org.apache.servicemix.tooling</groupId>
<artifactId>depends-maven-plugin</artifactId>
<version>1.3.1</version>
<version>${servicemix-depends.version}</version>
<executions>
<execution>
<id>generate-depends-file</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package org.codice.ddf.spatial.ogc.csw.catalog.endpoint;

import static ddf.catalog.Constants.ADDITIONAL_SORT_BYS;

import ddf.catalog.data.AttributeRegistry;
import ddf.catalog.data.types.Core;
import ddf.catalog.filter.FilterAdapter;
Expand Down Expand Up @@ -81,8 +83,6 @@ public class CswQueryFactory {
private static final Configuration PARSER_CONFIG =
new org.geotools.filter.v1_1.OGCConfiguration();

private static final String EXT_SORT_BY = "additional.sort.bys";

private static JAXBContext jaxBContext;

private final FilterBuilder builder;
Expand Down Expand Up @@ -152,7 +152,7 @@ public QueryRequest getQuery(GetRecordsType request) throws CswException {

Map<String, Serializable> properties = new HashMap<>();
if (extSortBys != null && extSortBys.length > 0) {
properties.put(EXT_SORT_BY, extSortBys);
properties.put(ADDITIONAL_SORT_BYS, extSortBys);
}

QueryRequest queryRequest = getQueryRequest(frameworkQuery, isEnterprise, properties);
Expand Down Expand Up @@ -241,7 +241,7 @@ private QueryRequest normalizeSort(QueryRequest request) {
// Additional sort parameters
Map<String, Serializable> newProperties = request.getProperties();
if (newProperties != null) {
Serializable extraSortBys = request.getPropertyValue(EXT_SORT_BY);
Serializable extraSortBys = request.getPropertyValue(ADDITIONAL_SORT_BYS);
if (extraSortBys instanceof SortBy[]) {
List<SortBy> extraSortBysList = Arrays.asList((SortBy[]) extraSortBys);
extraSortBysList
Expand All @@ -250,14 +250,14 @@ private QueryRequest normalizeSort(QueryRequest request) {
.filter(Objects::nonNull)
.forEach(sortBys::add);
} else {
LOGGER.debug("The \"{}\" query request property could not be read", EXT_SORT_BY);
LOGGER.debug("The \"{}\" query request property could not be read", ADDITIONAL_SORT_BYS);
}

if (sortBys.size() > 1) {
SortBy[] extraSortBysArray = sortBys.subList(1, sortBys.size()).toArray(new SortBy[0]);
newProperties.put(EXT_SORT_BY, extraSortBysArray);
newProperties.put(ADDITIONAL_SORT_BYS, extraSortBysArray);
} else {
newProperties.remove(EXT_SORT_BY);
newProperties.remove(ADDITIONAL_SORT_BYS);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package org.codice.ddf.spatial.ogc.csw.catalog.common.source;

import static ddf.catalog.Constants.ADDITIONAL_SORT_BYS;

import com.thoughtworks.xstream.converters.Converter;
import ddf.catalog.Constants;
import ddf.catalog.data.ContentType;
Expand Down Expand Up @@ -188,7 +190,6 @@ public abstract class AbstractCswSource extends MaskableImpl

private static final String BYTES_SKIPPED = "bytes-skipped";

private static final String EXT_SORT_BY = "additional.sort.bys";
private static final String OCTET_STREAM_OUTPUT_SCHEMA =
"http://www.iana.org/assignments/media-types/application/octet-stream";
private static final String ERROR_ID_PRODUCT_RETRIEVAL = "Error retrieving resource for ID: %s";
Expand Down Expand Up @@ -1184,7 +1185,7 @@ private SortByType createSortBy(QueryRequest queryRequest) {
if (query != null && query.getSortBy() != null && query.getSortBy().getPropertyName() != null) {
List<SortBy> sortBys = new ArrayList<>();
sortBys.add(query.getSortBy());
Serializable extSortBySer = queryRequest.getPropertyValue(EXT_SORT_BY);
Serializable extSortBySer = queryRequest.getPropertyValue(ADDITIONAL_SORT_BYS);
if (extSortBySer instanceof SortBy[]) {
SortBy[] extSortBys = (SortBy[]) extSortBySer;
if (extSortBys.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.codice.ddf.spatial.geocoding.query;

import static ddf.catalog.Constants.ADDITIONAL_SORT_BYS;
import static ddf.catalog.Constants.SUGGESTION_CONTEXT_KEY;
import static ddf.catalog.Constants.SUGGESTION_DICT_KEY;
import static ddf.catalog.Constants.SUGGESTION_QUERY_KEY;
Expand Down Expand Up @@ -76,8 +77,6 @@ public class GazetteerQueryCatalog implements GeoEntryQueryable {

private static final String ERROR_MESSAGE = "Unable to execute query on the catalog.";

private static final String SORT_BY = "additional.sort.bys";

private static final GeometryFactory GEOMETRY_FACTORY = new GeometryFactory();

private static final ThreadLocal<WKTWriter> WKT_WRITER_THREAD_LOCAL =
Expand Down Expand Up @@ -128,7 +127,7 @@ public List<GeoEntry> query(String queryString, int maxResults) throws GeoEntryQ
SortBy populationSortBy =
new SortByImpl(GeoEntryAttributes.POPULATION_ATTRIBUTE_NAME, SortOrder.DESCENDING);
SortBy[] sortbys = {populationSortBy};
properties.put(SORT_BY, sortbys);
properties.put(ADDITIONAL_SORT_BYS, sortbys);

Query query = new QueryImpl(queryFilter, 1, maxResults, featureCodeSortBy, false, TIMEOUT);
QueryRequest queryRequest = new QueryRequestImpl(query, properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public class QueryMetacardTypeImpl extends MetacardTypeImpl {

public static final String QUERY_ENTERPRISE = "enterprise";

public static final String QUERY_SORT_ORDER = "sortOrder";

public static final String QUERY_SORT_FIELD = "sortField";
public static final String QUERY_SORTS = "sorts";

public static final String QUERY_POLLING = "polling";

Expand Down Expand Up @@ -82,20 +80,11 @@ public class QueryMetacardTypeImpl extends MetacardTypeImpl {

QUERY_DESCRIPTORS.add(
new AttributeDescriptorImpl(
QUERY_SORT_FIELD,
QUERY_SORTS,
false /* indexed */,
true /* stored */,
false /* tokenized */,
false /* multivalued */,
BasicTypes.STRING_TYPE));

QUERY_DESCRIPTORS.add(
new AttributeDescriptorImpl(
QUERY_SORT_ORDER,
false /* indexed */,
true /* stored */,
false /* tokenized */,
false /* multivalued */,
true /* multivalued */,
BasicTypes.STRING_TYPE));

QUERY_DESCRIPTORS.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.boon.core.value.ValueMap;
import org.codice.ddf.catalog.ui.util.EndpointUtil;

public class WorkspaceTransformer {
Expand Down Expand Up @@ -104,6 +105,16 @@ private void setupMetacardMappers() {
.filter(StringUtils::isNotBlank)
.collect(Collectors.toCollection(ArrayList::new));
}));
metacardToJsonEntryMapper.put(
QueryMetacardTypeImpl.QUERY_SORTS,
remapValue(
value ->
((List<ValueMap>) value)
.stream()
.map(
lazyValueMap ->
lazyValueMap.get("attribute") + "," + lazyValueMap.get("direction"))
.collect(Collectors.toList())));
}

// for use during mapping keys/value from a metacard to a json map (metacard -> json)
Expand All @@ -126,6 +137,24 @@ private void setupJsonMappers() {
.map(this::transform)
.collect(Collectors.toList());
}));
jsonToMetacardEntryMapper.put(
QueryMetacardTypeImpl.QUERY_SORTS,
remapValue(
value -> {
List<String> sorts = (List) value;

return sorts
.stream()
.map(
s -> {
String[] split = s.split(",");
HashMap<String, Object> map = new HashMap<>();
map.put("attribute", split[0]);
map.put("direction", split[1]);
return map;
})
.collect(Collectors.toList());
}));
jsonToMetacardEntryMapper.put(
WorkspaceAttributes.WORKSPACE_LISTS,
remapValue(
Expand Down
Loading

0 comments on commit 33ce12d

Please sign in to comment.