Search in sources :

Example 56 with SortByImpl

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

the class LatestCommand method executeWithSubject.

@Override
protected Object executeWithSubject() throws Exception {
    String formatString = "%1$-7s %2$-33s %3$-26s %4$-" + MAX_LENGTH + "s%n";
    console.printf(formatString, "", "", "", "");
    printHeaderMessage(String.format(formatString, NUMBER, ID, DATE, TITLE));
    Filter filter = filterBuilder.attribute(Core.METACARD_MODIFIED).before().date(new Date());
    QueryImpl query = new QueryImpl(filter);
    query.setPageSize(numberOfItems);
    query.setSortBy(new SortByImpl(Core.METACARD_MODIFIED, SortOrder.DESCENDING.name()));
    QueryRequest queryRequest = new QueryRequestImpl(query);
    List<Result> results = Lists.newArrayList(resultIterable(getCatalog()::query, queryRequest, numberOfItems > 0 ? numberOfItems : 1000));
    int i = 1;
    for (Result result : results) {
        if (result.getMetacard() == null) {
            continue;
        }
        String postedDate = "";
        String title = "";
        if (result.getMetacard().getAttribute(Core.METACARD_MODIFIED) != null) {
            postedDate = new DateTime(result.getMetacard().getAttribute(Core.METACARD_MODIFIED).getValue()).toString(DATETIME_FORMATTER);
        }
        if (isNotBlank(result.getMetacard().getTitle())) {
            title = result.getMetacard().getTitle();
        }
        console.printf(formatString, i, result.getMetacard().getId(), postedDate, title.substring(0, Math.min(title.length(), MAX_LENGTH)));
        i++;
    }
    return null;
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Date(java.util.Date) DateTime(org.joda.time.DateTime) Result(ddf.catalog.data.Result)

Example 57 with SortByImpl

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

the class RangeCommand method executeWithSubject.

@Override
protected Object executeWithSubject() throws Exception {
    Filter filter;
    Date wayInTheFuture = new DateTime().plusYears(5000).toDate();
    Date endDate = wayInTheFuture;
    SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
    if (WILDCARD.equals(rangeBeginning) && WILDCARD.equals(rangeEnd)) {
        filter = filterBuilder.attribute(attributeName).before().date(endDate);
    } else if (WILDCARD.equals(rangeBeginning) && !WILDCARD.equals(rangeEnd)) {
        try {
            endDate = formatter.parse(rangeEnd);
        } catch (ParseException e) {
            throw new InterruptedException("Could not parse second parameter [" + rangeEnd + "]");
        }
        filter = filterBuilder.attribute(attributeName).before().date(endDate);
    } else if (!WILDCARD.equals(rangeBeginning) && WILDCARD.equals(rangeEnd)) {
        try {
            Date startDate = formatter.parse(rangeBeginning);
            filter = filterBuilder.attribute(attributeName).during().dates(startDate, endDate);
        } catch (ParseException e) {
            throw new InterruptedException("Could not parse first parameter [" + rangeBeginning + "]");
        }
    } else {
        try {
            Date startDate = formatter.parse(rangeBeginning);
            endDate = formatter.parse(rangeEnd);
            filter = filterBuilder.attribute(attributeName).during().dates(startDate, endDate);
        } catch (ParseException e) {
            throw new InterruptedException("Could not parse date parameters.");
        }
    }
    QueryImpl query = new QueryImpl(filter);
    query.setPageSize(MAX_RESULTS);
    query.setSortBy(new SortByImpl(attributeName, SortOrder.DESCENDING.name()));
    QueryRequest queryRequest = new QueryRequestImpl(query);
    SourceResponse response = getCatalog().query(queryRequest);
    List<Result> results = response.getResults();
    final ShellTable table = new ShellTable();
    table.column(NUMBER);
    table.column(ID);
    table.column(attributeName);
    table.column(TITLE).maxSize(MAX_LENGTH);
    table.emptyTableText("No results");
    int i = 1;
    for (Result result : results) {
        Attribute attribute = result.getMetacard().getAttribute(attributeName);
        if (attribute != null && attribute.getValue() != null) {
            String returnedDate = new DateTime(attribute.getValue()).toString(DATETIME_FORMATTER);
            String title = result.getMetacard().getTitle();
            final Row row = table.addRow();
            row.addContent(i, result.getMetacard().getId(), returnedDate, title);
        }
        i++;
    }
    table.print(console, true);
    return null;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Attribute(ddf.catalog.data.Attribute) Date(java.util.Date) DateTime(org.joda.time.DateTime) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) ShellTable(org.apache.karaf.shell.support.table.ShellTable) Filter(org.opengis.filter.Filter) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ParseException(java.text.ParseException) Row(org.apache.karaf.shell.support.table.Row) SimpleDateFormat(java.text.SimpleDateFormat)

Example 58 with SortByImpl

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

the class OpenSearchParserImplTest method populateSearchOptionsSortRelevanceUnsupported.

@Test
public void populateSearchOptionsSortRelevanceUnsupported() {
    SortBy sortBy = new SortByImpl(Result.DISTANCE, 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);
    assertQueryParameterNotPopulated(OpenSearchConstants.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 59 with SortByImpl

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

the class ConfluenceSourceTest method testFailedQuery.

@Test(expected = UnsupportedQueryException.class)
public void testFailedQuery() 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("Something bad happened".getBytes(StandardCharsets.UTF_8));
    when(clientResponse.getEntity()).thenReturn(entity);
    when(clientResponse.getStatus()).thenReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    SourceResponse response = confluence.query(request);
}
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 60 with SortByImpl

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

the class ConfluenceSourceTest method testFailedQueryStreamError.

@Test(expected = UnsupportedQueryException.class)
public void testFailedQueryStreamError() 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 = mock(InputStream.class);
    when(entity.read(any())).thenThrow(new IOException("exception"));
    when(clientResponse.getEntity()).thenReturn(entity);
    when(clientResponse.getStatus()).thenReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    SourceResponse response = confluence.query(request);
}
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) InputStream(java.io.InputStream) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) IOException(java.io.IOException) 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