use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class OpenSearchSiteUtil method translateToOpenSearchSort.
public static String translateToOpenSearchSort(SortBy ddfSort) {
String openSearchSortStr = null;
String orderType = null;
if (ddfSort == null || ddfSort.getSortOrder() == null) {
return openSearchSortStr;
}
if (ddfSort.getSortOrder().equals(SortOrder.ASCENDING)) {
orderType = ORDER_ASCENDING;
} else {
orderType = ORDER_DESCENDING;
}
// QualifiedString type = ddfSort.getType();
PropertyName sortByField = ddfSort.getPropertyName();
if (Result.RELEVANCE.equals(sortByField.getPropertyName())) {
// asc relevance not supported by spec
openSearchSortStr = SORT_RELEVANCE + SORT_DELIMITER + ORDER_DESCENDING;
} else if (Result.TEMPORAL.equals(sortByField.getPropertyName())) {
openSearchSortStr = SORT_TEMPORAL + SORT_DELIMITER + orderType;
} else {
LOGGER.debug("Couldn't determine sort policy, not adding sorting in request to federated site.");
}
return openSearchSortStr;
}
use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class SortedQueryMonitor method run.
@Override
public void run() {
SortBy sortBy = query.getSortBy();
// Prepare the Comparators that we will use
Comparator<Result> coreComparator = CachingFederationStrategy.DEFAULT_COMPARATOR;
if (sortBy != null && sortBy.getPropertyName() != null) {
PropertyName sortingProp = sortBy.getPropertyName();
String sortType = sortingProp.getPropertyName();
SortOrder sortOrder = (sortBy.getSortOrder() == null) ? SortOrder.DESCENDING : sortBy.getSortOrder();
LOGGER.debug("Sorting type: {}", sortType);
LOGGER.debug("Sorting order: {}", sortBy.getSortOrder());
// Temporal searches are currently sorted by the effective time
if (Metacard.EFFECTIVE.equals(sortType) || Result.TEMPORAL.equals(sortType)) {
coreComparator = new TemporalResultComparator(sortOrder);
} else if (Result.DISTANCE.equals(sortType)) {
coreComparator = new DistanceResultComparator(sortOrder);
} else if (Result.RELEVANCE.equals(sortType)) {
coreComparator = new RelevanceResultComparator(sortOrder);
}
}
List<Result> resultList = new ArrayList<>();
long totalHits = 0;
Set<ProcessingDetails> processingDetails = returnResults.getProcessingDetails();
Map<String, Serializable> returnProperties = returnResults.getProperties();
HashMap<String, Long> hitsPerSource = new HashMap<>();
for (int i = futures.size(); i > 0; i--) {
String sourceId = "Unknown Source";
QueryRequest queryRequest = null;
SourceResponse sourceResponse = null;
try {
Future<SourceResponse> future;
if (query.getTimeoutMillis() < 1) {
future = completionService.take();
} else {
future = completionService.poll(getTimeRemaining(deadline), TimeUnit.MILLISECONDS);
if (future == null) {
timeoutRemainingSources(processingDetails);
break;
}
}
queryRequest = futures.remove(future);
sourceId = getSourceIdFromRequest(queryRequest);
sourceResponse = future.get();
if (sourceResponse == null) {
LOGGER.debug("Source {} returned null response", sourceId);
executePostFederationQueryPluginsWithSourceError(queryRequest, sourceId, new NullPointerException(), processingDetails);
} else {
sourceResponse = executePostFederationQueryPlugins(sourceResponse, queryRequest);
resultList.addAll(sourceResponse.getResults());
long hits = sourceResponse.getHits();
totalHits += hits;
hitsPerSource.merge(sourceId, hits, (l1, l2) -> l1 + l2);
Map<String, Serializable> properties = sourceResponse.getProperties();
returnProperties.putAll(properties);
}
} catch (InterruptedException e) {
if (queryRequest != null) {
// First, add interrupted processing detail for this source
LOGGER.debug("Search interrupted for {}", sourceId);
executePostFederationQueryPluginsWithSourceError(queryRequest, sourceId, e, processingDetails);
}
// Then add the interrupted exception for the remaining sources
interruptRemainingSources(processingDetails, e);
break;
} catch (ExecutionException e) {
LOGGER.info("Couldn't get results from completed federated query. {}, {}", sourceId, Exceptions.getFullMessage(e), e);
executePostFederationQueryPluginsWithSourceError(queryRequest, sourceId, e, processingDetails);
}
}
returnProperties.put("hitsPerSource", hitsPerSource);
LOGGER.debug("All sources finished returning results: {}", resultList.size());
returnResults.setHits(totalHits);
if (CachingFederationStrategy.INDEX_QUERY_MODE.equals(request.getPropertyValue(CachingFederationStrategy.QUERY_MODE))) {
QueryResponse result = cachingFederationStrategy.queryCache(request);
returnResults.addResults(result.getResults(), true);
} else {
returnResults.addResults(sortedResults(resultList, coreComparator), true);
}
}
use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class FederationAdminServiceImpl method getRegistryMetacardsByFilter.
private List<Metacard> getRegistryMetacardsByFilter(Filter filter, Set<String> sourceIds) throws FederationAdminException {
if (filter == null) {
throw new FederationAdminException("Error getting registry metacards. Null filter provided.");
}
PropertyName propertyName = new PropertyNameImpl(Metacard.MODIFIED);
SortBy sortBy = new SortByImpl(propertyName, SortOrder.ASCENDING);
QueryImpl query = new QueryImpl(filter);
query.setSortBy(sortBy);
query.setPageSize(PAGE_SIZE);
QueryRequest queryRequest = new QueryRequestImpl(query, sourceIds);
try {
QueryResponse queryResponse = security.runWithSubjectOrElevate(() -> catalogFramework.query(queryRequest));
return queryResponse.getResults().stream().map(Result::getMetacard).filter(Objects::nonNull).collect(Collectors.toList());
} catch (SecurityServiceException | InvocationTargetException e) {
String message = "Error querying for registry metacards.";
LOGGER.debug("{} For Filter: {}", message, filter);
throw new FederationAdminException(message, e);
}
}
use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class CswQueryFactory method buildSort.
private SortBy buildSort(SortByType sort) throws CswException {
if (sort == null || sort.getSortProperty() == null) {
return null;
}
SortBy[] sortByArr = parseSortBy(sort);
if (sortByArr.length > 1) {
LOGGER.debug("Query request has multiple sort criteria, only primary will be used");
}
SortBy sortBy = sortByArr[0];
if (sortBy.getPropertyName() == null) {
LOGGER.debug("No property name in primary sort criteria");
return null;
}
if (!attributeRegistry.lookup(sortBy.getPropertyName().getPropertyName()).isPresent() && !DefaultCswRecordMap.hasDefaultMetacardFieldForPrefixedString(sortBy.getPropertyName().getPropertyName(), sortBy.getPropertyName().getNamespaceContext())) {
throw new CswException("Property " + sortBy.getPropertyName().getPropertyName() + " is not a valid SortBy Field", CswConstants.INVALID_PARAMETER_VALUE, "SortProperty");
}
String name = DefaultCswRecordMap.getDefaultMetacardFieldForPrefixedString(sortBy.getPropertyName().getPropertyName(), sortBy.getPropertyName().getNamespaceContext());
PropertyName propName = new AttributeExpressionImpl(new NameImpl(name));
return new SortByImpl(propName, sortBy.getSortOrder());
}
use of org.opengis.filter.expression.PropertyName in project ddf by codice.
the class CswRecordMapperFilterVisitor method visit.
@Override
public Object visit(Literal expression, Object extraData) {
if (extraData != null && extraData instanceof PropertyName && expression.getValue() instanceof String) {
String propName = ((PropertyName) extraData).getPropertyName();
AttributeDescriptor attrDesc = metacardType.getAttributeDescriptor(propName);
if (attrDesc != null && attrDesc.getType() != null) {
String value = (String) expression.getValue();
Serializable convertedValue = CswRecordConverter.convertStringValueToMetacardValue(attrDesc.getType().getAttributeFormat(), value);
return getFactory(extraData).literal(convertedValue);
}
}
return getFactory(extraData).literal(expression.getValue());
}
Aggregations