Search in sources :

Example 61 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class ConfluenceSourceTest method testAttributeOverrides.

@Test
public void testAttributeOverrides() throws Exception {
    QueryRequest request = new QueryRequestImpl(new QueryImpl(builder.attribute("anyText").is().like().text("searchValue"), 1, 1, new SortByImpl("title", SortOrder.DESCENDING), false, 1000));
    InputStream entity = new ByteArrayInputStream(JSON_RESPONSE.getBytes(StandardCharsets.UTF_8));
    when(clientResponse.getEntity()).thenReturn(entity);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    setupRegistryEntry("dateAttribute", BasicTypes.DATE_TYPE);
    setupRegistryEntry("boolAttribute", BasicTypes.BOOLEAN_TYPE);
    setupRegistryEntry("longAttribute", BasicTypes.LONG_TYPE);
    setupRegistryEntry("intAttribute", BasicTypes.INTEGER_TYPE);
    setupRegistryEntry("shortAttribute", BasicTypes.SHORT_TYPE);
    setupRegistryEntry("floatAttribute", BasicTypes.FLOAT_TYPE);
    setupRegistryEntry("doubleAttribute", BasicTypes.DOUBLE_TYPE);
    setupRegistryEntry("binaryAttribute", BasicTypes.BINARY_TYPE);
    setupRegistryEntry("badAttribute", BasicTypes.INTEGER_TYPE);
    when(registry.lookup("missingAttribute")).thenReturn(Optional.empty());
    Instant now = Instant.now();
    List<String> additionalAttributes = new ArrayList<>();
    additionalAttributes.add("attrib1=val1");
    additionalAttributes.add("attrib2=val1,val2,val3");
    additionalAttributes.add("dateAttribute=2018-06-28T10:44:00+07:00");
    additionalAttributes.add("boolAttribute=true");
    additionalAttributes.add("longAttribute=12345678900000");
    additionalAttributes.add("intAttribute=1234");
    additionalAttributes.add("shortAttribute=1");
    additionalAttributes.add("floatAttribute=1.1");
    additionalAttributes.add("doubleAttribute=1.23456");
    additionalAttributes.add("binaryAttribute=binaryString");
    additionalAttributes.add("badAttribute=1.23456");
    additionalAttributes.add("missingAttribute=something");
    confluence.setAttributeOverrides(additionalAttributes);
    SourceResponse response = confluence.query(request);
    assertThat(response.getHits(), is(1L));
    Metacard mcard = response.getResults().get(0).getMetacard();
    assertThat(mcard, notNullValue());
    assertThat(mcard.getAttribute("attrib1").getValue(), is("val1"));
    assertThat(mcard.getAttribute("attrib2").getValues().size(), is(3));
    assertThat(mcard.getAttribute("dateAttribute").getValue(), is(DatatypeConverter.parseDateTime("2018-06-28T10:44:00+07:00").getTime()));
    assertThat(mcard.getAttribute("boolAttribute").getValue(), is(true));
    assertThat(mcard.getAttribute("longAttribute").getValue(), is(12345678900000L));
    assertThat(mcard.getAttribute("intAttribute").getValue(), is(1234));
    assertThat(mcard.getAttribute("shortAttribute").getValue(), is((short) 1));
    assertThat(mcard.getAttribute("floatAttribute").getValue(), is(1.1f));
    assertThat(mcard.getAttribute("doubleAttribute").getValue(), is(1.23456));
    assertThat(mcard.getAttribute("binaryAttribute").getValue(), is("binaryString".getBytes(Charset.forName("UTF-8"))));
    assertThat(mcard.getAttribute("badAttribute"), is(nullValue()));
    assertThat(mcard.getAttribute("missingAttribute"), is(nullValue()));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) SortByImpl(ddf.catalog.filter.impl.SortByImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Instant(java.time.Instant) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 62 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class ConfluenceSourceTest method testQuerySortOnNonConfluenceAttribute.

@Test
public void testQuerySortOnNonConfluenceAttribute() throws Exception {
    QueryRequest request = new QueryRequestImpl(new QueryImpl(builder.attribute("anyText").is().like().text("searchValue"), 1, 1, new SortByImpl("someAttribute", SortOrder.DESCENDING), false, 1000));
    InputStream entity = new ByteArrayInputStream(JSON_RESPONSE.getBytes(StandardCharsets.UTF_8));
    when(clientResponse.getEntity()).thenReturn(entity);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    SourceResponse response = confluence.query(request);
    assertThat(response.getHits(), is(1L));
    assertThat(response.getResults().get(0).getMetacard(), notNullValue());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) SortByImpl(ddf.catalog.filter.impl.SortByImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 63 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class OpenSearchParserImplTest method populateSearchOptions.

// {@link OpenSearchParser#populateSearchOptions(WebClient, QueryRequest, Subject, List)} tests
@Test
public void populateSearchOptions() {
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.DESCENDING);
    Filter filter = mock(Filter.class);
    Query query = new QueryImpl(filter, 0, 2000, sortBy, true, 30000);
    QueryRequest queryRequest = new QueryRequestImpl(query);
    openSearchParser.populateSearchOptions(webClient, queryRequest, null, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    assertQueryParameterPopulated(OpenSearchConstants.COUNT);
    assertQueryParameterPopulated(OpenSearchConstants.MAX_RESULTS, MAX_RESULTS);
    assertQueryParameterPopulated(OpenSearchConstants.MAX_TIMEOUT, TIMEOUT);
    assertQueryParameterPopulated(OpenSearchConstants.SORT, DESCENDING_TEMPORAL_SORT);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SortByImpl(ddf.catalog.filter.impl.SortByImpl) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) Filter(org.opengis.filter.Filter) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 64 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class OpenSearchParserImplTest method populateSearchOptionsSortRelevance.

@Test
public void populateSearchOptionsSortRelevance() {
    SortBy sortBy = new SortByImpl(Result.RELEVANCE, SortOrder.ASCENDING);
    Filter filter = mock(Filter.class);
    Query query = new QueryImpl(filter, 0, 2000, sortBy, true, 30000);
    QueryRequest queryRequest = new QueryRequestImpl(query);
    openSearchParser.populateSearchOptions(webClient, queryRequest, null, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    assertQueryParameterPopulated(OpenSearchConstants.COUNT);
    assertQueryParameterPopulated(OpenSearchConstants.MAX_RESULTS, MAX_RESULTS);
    assertQueryParameterPopulated(OpenSearchConstants.MAX_TIMEOUT, TIMEOUT);
    assertQueryParameterPopulated(OpenSearchConstants.SORT, "relevance:desc");
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SortByImpl(ddf.catalog.filter.impl.SortByImpl) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) Filter(org.opengis.filter.Filter) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 65 with SortByImpl

use of ddf.catalog.filter.impl.SortByImpl in project ddf by codice.

the class OpenSearchParserImplTest method populateSearchOptionsSortAscending.

@Test
public void populateSearchOptionsSortAscending() {
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
    Filter filter = mock(Filter.class);
    Query query = new QueryImpl(filter, 0, 2000, sortBy, true, 30000);
    QueryRequest queryRequest = new QueryRequestImpl(query);
    openSearchParser.populateSearchOptions(webClient, queryRequest, null, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    assertQueryParameterPopulated(OpenSearchConstants.COUNT);
    assertQueryParameterPopulated(OpenSearchConstants.MAX_RESULTS, MAX_RESULTS);
    assertQueryParameterPopulated(OpenSearchConstants.MAX_TIMEOUT, TIMEOUT);
    assertQueryParameterPopulated(OpenSearchConstants.SORT, "date:asc");
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SortByImpl(ddf.catalog.filter.impl.SortByImpl) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) Filter(org.opengis.filter.Filter) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Aggregations

SortByImpl (ddf.catalog.filter.impl.SortByImpl)68 QueryImpl (ddf.catalog.operation.impl.QueryImpl)65 Test (org.junit.Test)56 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)47 SortBy (org.opengis.filter.sort.SortBy)45 SourceResponse (ddf.catalog.operation.SourceResponse)28 QueryRequest (ddf.catalog.operation.QueryRequest)23 Matchers.containsString (org.hamcrest.Matchers.containsString)21 Filter (org.opengis.filter.Filter)13 ArrayList (java.util.ArrayList)12 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)12 QueryType (net.opengis.wfs.v_2_0_0.QueryType)12 Query (ddf.catalog.operation.Query)9 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)8 InputStream (java.io.InputStream)8 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)8 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)8 CswException (org.codice.ddf.spatial.ogc.csw.catalog.common.CswException)8 MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7