use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class TestWfsSource method testGmlImport.
@Test
public void testGmlImport() throws UnsupportedQueryException, WfsException, SecurityServiceException {
List<Object> bbox = new ArrayList<Object>();
bbox.add(new BBOX());
setUp(GML_IMPORT_SCHEMA, bbox, SRS_NAME, ONE_FEATURE, null);
Filter intersectFilter = builder.attribute(Metacard.ANY_GEO).is().intersecting().wkt(POLYGON_WKT);
QueryImpl intersectQuery = new QueryImpl(intersectFilter);
intersectQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
source.query(new QueryRequestImpl(intersectQuery));
verify(mockWfs).getFeature(captor.capture());
GetFeatureType getFeatureType = captor.getValue();
assertMaxFeatures(getFeatureType, intersectQuery);
assertTrue(getFeatureType.getQuery().size() == ONE_FEATURE);
QueryType query = getFeatureType.getQuery().get(0);
assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
assertTrue(query.getFilter().isSetSpatialOps());
assertTrue(query.getFilter().getSpatialOps().getValue() instanceof SpatialOpsType);
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class TestWfsSource method testTwoContentTypeAndNoPropertyQuery.
@Test
public void testTwoContentTypeAndNoPropertyQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
setUp(NO_PROPERTY_SCHEMA, null, null, TWO_FEATURES, null);
Filter contentTypeFilter = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(0).getLocalPart());
Filter contentTypeFilter2 = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(1).getLocalPart());
QueryImpl twoContentTypeQuery = new QueryImpl(builder.anyOf(Arrays.asList(contentTypeFilter, contentTypeFilter2)));
twoContentTypeQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
source.query(new QueryRequestImpl(twoContentTypeQuery));
verify(mockWfs).getFeature(captor.capture());
GetFeatureType getFeatureType = captor.getValue();
assertMaxFeatures(getFeatureType, twoContentTypeQuery);
Collections.sort(getFeatureType.getQuery(), QUERY_TYPE_COMPARATOR);
assertEquals(TWO_FEATURES.intValue(), getFeatureType.getQuery().size());
assertEquals(sampleFeatures.get(0), getFeatureType.getQuery().get(0).getTypeName());
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class TestWfsSource method testQueryTwoFeaturesWithMixedPropertyNames.
@Test
public void testQueryTwoFeaturesWithMixedPropertyNames() throws UnsupportedQueryException, WfsException, SecurityServiceException {
setUp(TWO_TEXT_PROPERTY_SCHEMA, null, null, TWO_FEATURES, null);
Filter orderPersonFilter = builder.attribute(EXT_PREFIX + sampleFeatures.get(0).getLocalPart() + "." + ORDER_PERSON).is().like().text(LITERAL);
Filter mctFeature1Fitler = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(0).getLocalPart());
Filter feature1Filter = builder.allOf(Arrays.asList(orderPersonFilter, mctFeature1Fitler));
Filter orderDogFilter = builder.attribute(EXT_PREFIX + sampleFeatures.get(1).getLocalPart() + "." + ORDER_DOG).is().like().text(LITERAL);
Filter mctFeature2Fitler = builder.attribute(Metacard.CONTENT_TYPE).is().like().text(sampleFeatures.get(1).getLocalPart());
Filter feature2Filter = builder.allOf(Arrays.asList(orderDogFilter, mctFeature2Fitler));
Filter totalFilter = builder.anyOf(Arrays.asList(feature1Filter, feature2Filter));
QueryImpl inQuery = new QueryImpl(totalFilter);
inQuery.setPageSize(MAX_FEATURES);
ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
source.query(new QueryRequestImpl(inQuery));
verify(mockWfs).getFeature(captor.capture());
GetFeatureType getFeatureType = captor.getValue();
assertMaxFeatures(getFeatureType, inQuery);
Collections.sort(getFeatureType.getQuery(), QUERY_TYPE_COMPARATOR);
assertEquals(TWO_FEATURES.intValue(), getFeatureType.getQuery().size());
// Feature 1
QueryType query = getFeatureType.getQuery().get(0);
assertThat(query.getTypeName(), equalTo(sampleFeatures.get(0)));
// this should only have 1 filter which is a comparison
assertTrue(query.getFilter().isSetComparisonOps());
assertTrue(query.getFilter().getComparisonOps().getValue() instanceof PropertyIsLikeType);
PropertyIsLikeType pilt = (PropertyIsLikeType) query.getFilter().getComparisonOps().getValue();
assertNotNull(pilt);
assertEquals(ORDER_PERSON, pilt.getPropertyName().getContent());
// Feature 2
QueryType query2 = getFeatureType.getQuery().get(1);
assertTrue(query2.getTypeName().equals(sampleFeatures.get(1)));
// this should only have 1 filter which is a comparison
assertTrue(query2.getFilter().isSetComparisonOps());
assertTrue(query2.getFilter().getComparisonOps().getValue() instanceof PropertyIsLikeType);
PropertyIsLikeType pilt2 = (PropertyIsLikeType) query2.getFilter().getComparisonOps().getValue();
assertEquals(ORDER_DOG, pilt2.getPropertyName().getContent());
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class TestWfsSource method testTwoIDQuery.
@Test
public void testTwoIDQuery() throws UnsupportedQueryException, WfsException, SecurityServiceException {
setUp(NO_PROPERTY_SCHEMA, null, null, TWO_FEATURES, null);
Filter idFilter1 = builder.attribute(Core.ID).is().text(ORDER_PERSON);
Filter idFilter2 = builder.attribute(Core.ID).is().text(ORDER_DOG);
QueryImpl twoIDQuery = new QueryImpl(builder.anyOf(Arrays.asList(idFilter1, idFilter2)));
ArgumentCaptor<GetFeatureType> captor = ArgumentCaptor.forClass(GetFeatureType.class);
source.query(new QueryRequestImpl(twoIDQuery));
verify(mockWfs).getFeature(captor.capture());
GetFeatureType getFeatureType = captor.getValue();
assertEquals(TWO_FEATURES.intValue(), getFeatureType.getQuery().get(0).getFilter().getFeatureId().size());
assertTrue(ORDER_PERSON.equals(getFeatureType.getQuery().get(0).getFilter().getFeatureId().get(0).getFid()) || ORDER_PERSON.equals(getFeatureType.getQuery().get(0).getFilter().getFeatureId().get(1).getFid()));
assertTrue(ORDER_DOG.equals(getFeatureType.getQuery().get(0).getFilter().getFeatureId().get(0).getFid()) || ORDER_DOG.equals(getFeatureType.getQuery().get(0).getFilter().getFeatureId().get(1).getFid()));
}
use of net.opengis.wfs.v_1_1_0.GetFeatureType in project ddf by codice.
the class WfsSource method query.
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
Wfs wfs = factory.getClient();
Query query = request.getQuery();
if (query == null) {
LOGGER.debug("WFS Source {}: Incoming query is null.", getId());
return null;
}
LOGGER.debug("WFS Source {}: Received query: \n{}", getId(), query);
SourceResponseImpl simpleResponse = null;
GetFeatureType getFeature = buildGetFeatureRequest(query);
try {
LOGGER.debug("WFS Source {}: Sending query ...", getId());
Wfs20FeatureCollection featureCollection = wfs.getFeature(getFeature);
int numResults = -1;
if (featureCollection == null) {
throw new UnsupportedQueryException("Invalid results returned from server");
}
numResults = featureCollection.getMembers().size();
if (featureCollection.getNumberReturned() == null) {
LOGGER.debug("Number Returned Attribute was not added to the response");
} else if (!featureCollection.getNumberReturned().equals(BigInteger.valueOf(numResults))) {
LOGGER.debug("Number Returned Attribute ({}) did not match actual number returned ({})", featureCollection.getNumberReturned(), numResults);
}
availabilityTask.updateLastAvailableTimestamp(System.currentTimeMillis());
LOGGER.debug("WFS Source {}: Received featureCollection with {} metacards.", getId(), numResults);
List<Result> results = new ArrayList<>(numResults);
for (int i = 0; i < numResults; i++) {
Metacard mc = featureCollection.getMembers().get(i);
mc = transform(mc, DEFAULT_WFS_TRANSFORMER_ID);
Result result = new ResultImpl(mc);
results.add(result);
debugResult(result);
}
// Fetch total results available
long totalResults = 0;
if (featureCollection.getNumberMatched() == null) {
totalResults = numResults;
} else if (featureCollection.getNumberMatched().equals(UNKNOWN)) {
totalResults = numResults;
} else if (StringUtils.isNumeric(featureCollection.getNumberMatched())) {
totalResults = Long.parseLong(featureCollection.getNumberMatched());
}
simpleResponse = new SourceResponseImpl(request, results, totalResults);
} catch (WfsException wfse) {
LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
throw new UnsupportedQueryException("Error received from WFS Server", wfse);
} catch (Exception ce) {
String msg = handleClientException(ce);
throw new UnsupportedQueryException(msg, ce);
}
return simpleResponse;
}
Aggregations