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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations