Search in sources :

Example 21 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v200.PropertyIsLikeType in project ddf by codice.

the class TestWfsSource method testQueryTwoFeaturesOneInvalid.

@Test
public void testQueryTwoFeaturesOneInvalid() throws UnsupportedQueryException, WfsException, SecurityServiceException {
    setUp(TWO_TEXT_PROPERTY_SCHEMA, null, null, TWO_FEATURES, null);
    Filter orderPersonFilter = builder.attribute(EXT_PREFIX + sampleFeatures.get(0) + "." + 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("FAKE").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);
    assertEquals(ONE_FEATURE.intValue(), getFeatureType.getQuery().size());
    QueryType query = getFeatureType.getQuery().get(0);
    assertTrue(query.getTypeName().equals(sampleFeatures.get(0)));
    // The Text Properties should be ORed
    assertTrue(query.getFilter().isSetComparisonOps());
    assertTrue(query.getFilter().getComparisonOps().getValue() instanceof PropertyIsLikeType);
    PropertyIsLikeType pilt = (PropertyIsLikeType) query.getFilter().getComparisonOps().getValue();
    assertEquals(ORDER_PERSON, pilt.getPropertyName().getContent());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) PropertyIsLikeType(ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 22 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v200.PropertyIsLikeType 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());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryType(ogc.schema.opengis.wfs.v_1_0_0.QueryType) PropertyIsLikeType(ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType) Test(org.junit.Test)

Example 23 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v200.PropertyIsLikeType in project ddf by codice.

the class WfsFilterDelegate method createPropertyIsFilter.

private JAXBElement<? extends ComparisonOpsType> createPropertyIsFilter(String property, Object literal, PROPERTY_IS_OPS operation) {
    switch(operation) {
        case PropertyIsEqualTo:
            JAXBElement<BinaryComparisonOpType> propIsEqualTo = filterObjectFactory.createPropertyIsEqualTo(new BinaryComparisonOpType());
            propIsEqualTo.getValue().getExpression().add(createPropertyNameType(property));
            propIsEqualTo.getValue().getExpression().add(createLiteralType(literal));
            return propIsEqualTo;
        case PropertyIsNotEqualTo:
            JAXBElement<BinaryComparisonOpType> propIsNotEqualTo = filterObjectFactory.createPropertyIsNotEqualTo(new BinaryComparisonOpType());
            propIsNotEqualTo.getValue().getExpression().add(createPropertyNameType(property));
            propIsNotEqualTo.getValue().getExpression().add(createLiteralType(literal));
            return propIsNotEqualTo;
        case PropertyIsGreaterThan:
            JAXBElement<BinaryComparisonOpType> propIsGreaterThan = filterObjectFactory.createPropertyIsGreaterThan(new BinaryComparisonOpType());
            propIsGreaterThan.getValue().getExpression().add(createPropertyNameType(property));
            propIsGreaterThan.getValue().getExpression().add(createLiteralType(literal));
            return propIsGreaterThan;
        case PropertyIsGreaterThanOrEqualTo:
            JAXBElement<BinaryComparisonOpType> propIsGreaterThanOrEqualTo = filterObjectFactory.createPropertyIsGreaterThanOrEqualTo(new BinaryComparisonOpType());
            propIsGreaterThanOrEqualTo.getValue().getExpression().add(createPropertyNameType(property));
            propIsGreaterThanOrEqualTo.getValue().getExpression().add(createLiteralType(literal));
            return propIsGreaterThanOrEqualTo;
        case PropertyIsLessThan:
            JAXBElement<BinaryComparisonOpType> propIsLessThan = filterObjectFactory.createPropertyIsLessThan(new BinaryComparisonOpType());
            propIsLessThan.getValue().getExpression().add(createPropertyNameType(property));
            propIsLessThan.getValue().getExpression().add(createLiteralType(literal));
            return propIsLessThan;
        case PropertyIsLessThanOrEqualTo:
            JAXBElement<BinaryComparisonOpType> propIsLessThanOrEqualTo = filterObjectFactory.createPropertyIsLessThanOrEqualTo(new BinaryComparisonOpType());
            propIsLessThanOrEqualTo.getValue().getExpression().add(createPropertyNameType(property));
            propIsLessThanOrEqualTo.getValue().getExpression().add(createLiteralType(literal));
            return propIsLessThanOrEqualTo;
        case PropertyIsLike:
            JAXBElement<PropertyIsLikeType> propIsLike = filterObjectFactory.createPropertyIsLike(new PropertyIsLikeType());
            propIsLike.getValue().setPropertyName(createPropertyNameType(property).getValue());
            propIsLike.getValue().setEscape(WfsConstants.ESCAPE);
            propIsLike.getValue().setSingleChar(SINGLE_CHAR);
            propIsLike.getValue().setWildCard(WfsConstants.WILD_CARD);
            propIsLike.getValue().setLiteral(createLiteralType(literal).getValue());
            return propIsLike;
        default:
            throw new UnsupportedOperationException("Unsupported Property Comparison Type");
    }
}
Also used : BinaryComparisonOpType(ogc.schema.opengis.filter.v_1_0_0.BinaryComparisonOpType) PropertyIsLikeType(ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType)

Example 24 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v200.PropertyIsLikeType in project geotoolkit by Geomatys.

the class CswXMLBindingTest method getRecordsUnMarshalingTest.

/**
 * Test simple Record Marshalling.
 */
@Test
public void getRecordsUnMarshalingTest() throws JAXBException {
    Unmarshaller unmarshaller = pool.acquireUnmarshaller();
    /*
         * Test unmarshalling csw getRecordByIdResponse v2.0.2
         */
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<csw:GetRecords xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:csw=\"http://www.opengis.net/cat/csw/2.0.2\"" + " maxRecords=\"20\" startPosition=\"1\" outputSchema=\"http://www.opengis.net/cat/csw/2.0.2\" outputFormat=\"application/xml\"" + " resultType=\"results\" version=\"2.0.2\" service=\"CSW\">\n" + "  <csw:Query typeNames=\"csw:Record\">\n" + "    <csw:ElementSetName>full</csw:ElementSetName>\n" + "    <csw:Constraint version=\"1.1.0\">\n" + "      <ogc:Filter>\n" + "        <ogc:Not>\n" + "          <ogc:PropertyIsLike wildCard=\"*\" singleChar=\"?\" escapeChar=\"\\\">\n" + "            <ogc:PropertyName>dc:Title</ogc:PropertyName>\n" + "            <ogc:Literal>something?</ogc:Literal>\n" + "          </ogc:PropertyIsLike>\n" + "        </ogc:Not>\n" + "      </ogc:Filter>\n" + "    </csw:Constraint>\n" + "  </csw:Query>\n" + "</csw:GetRecords>\n";
    StringReader sr = new StringReader(xml);
    Object result = unmarshaller.unmarshal(sr);
    /*
         * we build the first filter : < dublinCore:Title IS LIKE '*' >
         */
    List<QName> typeNames = new ArrayList<>();
    PropertyNameType pname = new PropertyNameType("dc:Title");
    PropertyIsLikeType pil = new PropertyIsLikeType(pname, "something?", "*", "?", "\\");
    NotType n = new NotType(pil);
    FilterType filter1 = new FilterType(n);
    QueryConstraintType constraint = new QueryConstraintType(filter1, "1.1.0");
    typeNames.add(_Record_QNAME);
    QueryType query = new QueryType(typeNames, new ElementSetNameType(ElementSetType.FULL), null, constraint);
    GetRecordsType expResult = new GetRecordsType("CSW", "2.0.2", ResultType.RESULTS, null, "application/xml", "http://www.opengis.net/cat/csw/2.0.2", 1, 20, query, null);
    LOGGER.log(Level.FINER, "RESULT:\n{0}", result);
    LOGGER.log(Level.FINER, "EXPRESULT:\n{0}", expResult);
    GetRecordsType gres = (GetRecordsType) result;
    QueryType expQT = (QueryType) expResult.getAbstractQuery();
    QueryType resQT = (QueryType) gres.getAbstractQuery();
    assertEquals(expQT.getConstraint().getFilter().getLogicOps().getValue(), resQT.getConstraint().getFilter().getLogicOps().getValue());
    assertEquals(expQT.getConstraint().getFilter(), resQT.getConstraint().getFilter());
    assertEquals(expQT.getConstraint(), resQT.getConstraint());
    assertEquals(expResult.getAbstractQuery(), gres.getAbstractQuery());
    assertEquals(expResult, result);
    xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<cat:GetRecords xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:cat=\"http://www.opengis.net/cat/csw\"" + " maxRecords=\"20\" startPosition=\"1\" outputSchema=\"http://www.opengis.net/cat/csw\" outputFormat=\"application/xml\"" + " resultType=\"results\" version=\"2.0.0\" service=\"CSW\">\n" + "  <cat:Query typeNames=\"cat:Record\">\n" + "    <cat:ElementSetName>full</cat:ElementSetName>\n" + "    <cat:Constraint version=\"1.1.0\">\n" + "      <ogc:Filter>\n" + "        <ogc:Not>\n" + "          <ogc:PropertyIsLike wildCard=\"*\" singleChar=\"?\" escapeChar=\"\\\">\n" + "            <ogc:PropertyName>dc:Title</ogc:PropertyName>\n" + "            <ogc:Literal>something?</ogc:Literal>\n" + "          </ogc:PropertyIsLike>\n" + "        </ogc:Not>\n" + "      </ogc:Filter>\n" + "    </cat:Constraint>\n" + "  </cat:Query>\n" + "</cat:GetRecords>\n";
    org.geotoolkit.csw.xml.v200.QueryConstraintType constraint200 = new org.geotoolkit.csw.xml.v200.QueryConstraintType(filter1, "1.1.0");
    typeNames = new ArrayList<>();
    typeNames.add(org.geotoolkit.csw.xml.v200.ObjectFactory._Record_QNAME);
    org.geotoolkit.csw.xml.v200.QueryType query200 = new org.geotoolkit.csw.xml.v200.QueryType(typeNames, new org.geotoolkit.csw.xml.v200.ElementSetNameType(ElementSetType.FULL), constraint200);
    org.geotoolkit.csw.xml.v200.GetRecordsType expResult200 = new org.geotoolkit.csw.xml.v200.GetRecordsType("CSW", "2.0.0", ResultType.RESULTS, null, "application/xml", "http://www.opengis.net/cat/csw", 1, 20, query200, null);
    sr = new StringReader(xml);
    result = unmarshaller.unmarshal(sr);
    assertTrue(result instanceof JAXBElement);
    org.geotoolkit.csw.xml.v200.GetRecordsType result200 = (org.geotoolkit.csw.xml.v200.GetRecordsType) ((JAXBElement) result).getValue();
    assertEquals(expResult200.getAbstractQuery(), result200.getAbstractQuery());
    assertEquals(expResult200, result200);
    pool.recycle(unmarshaller);
}
Also used : ArrayList(java.util.ArrayList) QueryConstraintType(org.geotoolkit.csw.xml.v202.QueryConstraintType) NotType(org.geotoolkit.ogc.xml.v110.NotType) StringReader(java.io.StringReader) ElementSetNameType(org.geotoolkit.csw.xml.v202.ElementSetNameType) Unmarshaller(javax.xml.bind.Unmarshaller) PropertyNameType(org.geotoolkit.ogc.xml.v110.PropertyNameType) QName(javax.xml.namespace.QName) GetRecordsType(org.geotoolkit.csw.xml.v202.GetRecordsType) JAXBElement(javax.xml.bind.JAXBElement) FilterType(org.geotoolkit.ogc.xml.v110.FilterType) QueryType(org.geotoolkit.csw.xml.v202.QueryType) PropertyIsLikeType(org.geotoolkit.ogc.xml.v110.PropertyIsLikeType) Test(org.junit.Test)

Example 25 with PropertyIsLikeType

use of org.geotoolkit.ogc.xml.v200.PropertyIsLikeType in project geotoolkit by Geomatys.

the class WfsXMLBindingTest method marshallingTest.

@Test
public void marshallingTest() throws JAXBException {
    WFSCapabilitiesType capa = new WFSCapabilitiesType();
    List<FeatureTypeType> featList = new ArrayList<FeatureTypeType>();
    LatLongBoundingBoxType bbox = new LatLongBoundingBoxType(29.8, -90.1, 30, -89.9);
    FeatureTypeType ft1 = new FeatureTypeType(new QName("http://www.opengis.net/ows-6/utds/0.3", "Building", "utds"), "", "urn:ogc:def:crs:EPSG::4979", Arrays.asList(bbox));
    featList.add(ft1);
    FeatureTypeListType featureList = new FeatureTypeListType(null, featList);
    capa.setFeatureTypeList(featureList);
    StringWriter sw = new StringWriter();
    marshaller.marshal(capa, sw);
    DeleteElementType del = null;
    TransactionType transac = new TransactionType("WFS", "1.1.0", null, AllSomeType.ALL, del);
    PropertyIsLikeType pis = new PropertyIsLikeType("NAME", "Ashton", "*", "?", "\\");
    org.geotoolkit.ogc.xml.v100.ObjectFactory factory = new org.geotoolkit.ogc.xml.v100.ObjectFactory();
    final JAXBElement<? extends ComparisonOpsType> jbPis = factory.createPropertyIsLike(pis);
    FilterType filter = new FilterType(null, jbPis, null, null);
    CoordType dp = new CoordType(21400.0, 2001368.0);
    PointType pt = new PointType(dp);
    pt.setSrsName("urn:ogc:def:crs:epsg:7.4:27582");
    PropertyType property = new PropertyType("the_geom", pt);
    UpdateElementType update = new UpdateElementType(Arrays.asList(property), filter, new QName("http://www.opengis.net/gml", "NamedPlaces"));
    transac.getInsertOrUpdateOrDelete().add(update);
// marshaller.marshal(transac, System.out);
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) FilterType(org.geotoolkit.ogc.xml.v100.FilterType) StringWriter(java.io.StringWriter) PointType(org.geotoolkit.gml.xml.v212.PointType) PropertyIsLikeType(org.geotoolkit.ogc.xml.v100.PropertyIsLikeType) CoordType(org.geotoolkit.gml.xml.v212.CoordType)

Aggregations

ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 PropertyIsLikeType (net.opengis.filter.v_2_0_0.PropertyIsLikeType)11 FilterType (net.opengis.filter.v_2_0_0.FilterType)10 Filter (org.opengis.filter.Filter)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 Method (java.lang.reflect.Method)6 JAXBElement (javax.xml.bind.JAXBElement)6 BinaryLogicOpType (net.opengis.filter.v_2_0_0.BinaryLogicOpType)6 PropertyIsLikeType (ogc.schema.opengis.filter.v_1_0_0.PropertyIsLikeType)6 QName (javax.xml.namespace.QName)5 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)5 QueryType (ogc.schema.opengis.wfs.v_1_0_0.QueryType)5 PropertyIsLikeType (org.geotoolkit.ogc.xml.v110.PropertyIsLikeType)5 StringWriter (java.io.StringWriter)4 PropertyIsLikeType (net.opengis.filter.v_1_1_0.PropertyIsLikeType)4 PropertyNameType (org.geotoolkit.ogc.xml.v110.PropertyNameType)4 LikeOperator (org.opengis.filter.LikeOperator)4 ValueReference (org.opengis.filter.ValueReference)4