use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class RegistryIdPostIngestPlugin method init.
/**
* Init method initializes the id sets from the catalog. If the catalog is not available it
* will retry later.
*/
public void init() {
try {
List<Metacard> registryMetacards;
Filter registryFilter = filterBuilder.anyOf(filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG), filterBuilder.attribute(Metacard.TAGS).is().equalTo().text(RegistryConstants.REGISTRY_TAG_INTERNAL));
QueryImpl query = new QueryImpl(registryFilter);
query.setPageSize(PAGE_SIZE);
QueryRequest request = new QueryRequestImpl(query);
QueryResponse response = security.runAsAdminWithException(() -> security.runWithSubjectOrElevate(() -> catalogFramework.query(request)));
if (response == null) {
throw new PluginExecutionException("Failed to initialize RegistryIdPostIngestPlugin. Query for registry metacards came back null");
}
registryMetacards = response.getResults().stream().map(Result::getMetacard).collect(Collectors.toList());
addIdsFromMetacards(registryMetacards);
} catch (PrivilegedActionException | PluginExecutionException e) {
LOGGER.debug("Error getting registry metacards. Will try again later");
executorService.schedule(this::init, RETRY_INTERVAL, TimeUnit.SECONDS);
}
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class TestWfsSource method testSearchByMultipleTypes.
@Test
public void testSearchByMultipleTypes() throws Exception {
//Setup
int pageSize = 10;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 10, false);
Filter filter0 = builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(SAMPLE_FEATURE_NAME + "8");
Filter filter1 = builder.attribute(Metacard.CONTENT_TYPE).is().equalTo().text(SAMPLE_FEATURE_NAME + "9");
Filter filter2 = builder.attribute(Metacard.ANY_TEXT).is().like().text("*");
Filter typeSearchFilters = builder.anyOf(filter0, filter1);
QueryImpl query = new QueryImpl(builder.allOf(filter2, typeSearchFilters));
query.setPageSize(pageSize);
//Execute
GetFeatureType featureType = source.buildGetFeatureRequest(query);
int numTypes = featureType.getAbstractQueryExpression().size();
//Validate
assertEquals(2, numTypes);
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class TestWfsSource method testResultNumReturnedNegative.
@Test
public void testResultNumReturnedNegative() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
//Setup
final String TITLE = "title";
final String searchPhrase = "*";
final int pageSize = 1;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 3, false, true, -1);
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
SortBy sortBy = new SortByImpl(TITLE, SortOrder.DESCENDING);
query.setSortBy(sortBy);
QueryRequestImpl queryReq = new QueryRequestImpl(query);
// Perform test
SourceResponse resp = source.query(queryReq);
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class TestWfsSource method testSortingAscendingNoFeaturePropertyMappingSortingSupported.
/**
* Verify that the SortBy is NOT set. In this case, there is no mapping for the incoming sort property of TEMPORAL so no SortBy should be set.
* <p/>
* <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
* <ns5:GetFeature startIndex="1" count="1" service="WFS" version="2.0.0" xmlns:ns2="http://www.opengis.net/ows/1.1" xmlns="http://www.opengis.net/fes/2.0" xmlns:ns4="http://www.opengis.net/gml" xmlns:ns3="http://www.w3.org/1999/xlink" xmlns:ns5="http://www.opengis.net/wfs/2.0">
* <ns5:Query typeNames="SampleFeature0" handle="SampleFeature0">
* <Filter>
* <PropertyIsLike wildCard="*" singleChar="?" escapeChar="!">
* <Literal>*</Literal>
* <ValueReference>title</ValueReference>
* </PropertyIsLike>
* </Filter>
* </ns5:Query>
* </ns5:GetFeature>
*/
@Test
public void testSortingAscendingNoFeaturePropertyMappingSortingSupported() throws Exception {
// Setup
final String searchPhrase = "*";
final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
final int pageSize = 1;
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, 1, false, false, 0);
MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
List<MetacardMapper> mappers = new ArrayList<MetacardMapper>(1);
mappers.add(mockMetacardMapper);
source.setMetacardToFeatureMapper(mappers);
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
query.setSortBy(sortBy);
// Perform Test
GetFeatureType featureType = source.buildGetFeatureRequest(query);
// Verify
QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
assertFalse(queryType.isSetAbstractSortingClause());
}
use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.
the class TestWfsSource method testSortingAscendingSortingNotSupported.
/**
* Verify that the SortBy is NOT set. In this case, sorting is not supported in the capabilities.
*/
@Test
public void testSortingAscendingSortingNotSupported() throws Exception {
// Setup
final String searchPhrase = "*";
final String mockTemporalFeatureProperty = "myTemporalFeatureProperty";
final String mockFeatureType = "{http://example.com}" + SAMPLE_FEATURE_NAME + 0;
final int pageSize = 1;
// Set ImplementsSorting to FALSE (sorting not supported)
FilterCapabilities mockCapabilitiesSortingNotSupported = MockWfsServer.getFilterCapabilities();
ConformanceType conformance = mockCapabilitiesSortingNotSupported.getConformance();
List<DomainType> domainTypes = conformance.getConstraint();
for (DomainType domainType : domainTypes) {
if (StringUtils.equals(domainType.getName(), "ImplementsSorting")) {
ValueType valueType = new ValueType();
valueType.setValue("FALSE");
domainType.setDefaultValue(valueType);
break;
}
}
WfsSource source = getWfsSource(ONE_TEXT_PROPERTY_SCHEMA, mockCapabilitiesSortingNotSupported, GeospatialUtil.EPSG_4326_URN, 1, false, false, 0);
MetacardMapper mockMetacardMapper = mock(MetacardMapper.class);
when(mockMetacardMapper.getFeatureType()).thenReturn(mockFeatureType);
when(mockMetacardMapper.getSortByTemporalFeatureProperty()).thenReturn(mockTemporalFeatureProperty);
List<MetacardMapper> mappers = new ArrayList<MetacardMapper>(1);
mappers.add(mockMetacardMapper);
source.setMetacardToFeatureMapper(mappers);
QueryImpl query = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text(searchPhrase));
query.setPageSize(pageSize);
SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.ASCENDING);
query.setSortBy(sortBy);
// Perform Test
GetFeatureType featureType = source.buildGetFeatureRequest(query);
// Verify
QueryType queryType = (QueryType) featureType.getAbstractQueryExpression().get(0).getValue();
assertFalse(queryType.isSetAbstractSortingClause());
}
Aggregations