Search in sources :

Example 6 with MetacardMapper

use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper in project ddf by codice.

the class TestWfsFilterDelegate method testSequentialPropertyIsNotOfTemporalType.

private void testSequentialPropertyIsNotOfTemporalType(String methName, Object... inputParams) throws Throwable {
    String mockMetacardAttribute = "myMetacardAttribute";
    String mockFeatureType = "myFeatureType";
    String mockFeatureProperty = "myFeatureProperty";
    List<String> mockProperties = new ArrayList<>(1);
    mockProperties.add(mockFeatureProperty);
    when(mockFeatureMetacardType.getProperties()).thenReturn(mockProperties);
    when(mockFeatureMetacardType.getName()).thenReturn(mockFeatureType);
    List<String> mockTemporalProperties = Collections.emptyList();
    when(mockFeatureMetacardType.getTemporalProperties()).thenReturn(mockTemporalProperties);
    FeatureAttributeDescriptor mockFeatureAttributeDescriptor = mock(FeatureAttributeDescriptor.class);
    when(mockFeatureAttributeDescriptor.isIndexed()).thenReturn(true);
    when(mockFeatureAttributeDescriptor.getPropertyName()).thenReturn(mockFeatureProperty);
    when(mockFeatureMetacardType.getAttributeDescriptor(mockFeatureProperty)).thenReturn(mockFeatureAttributeDescriptor);
    MetacardMapper mockMapper = mock(MetacardMapper.class);
    when(mockMapper.getFeatureProperty(mockMetacardAttribute)).thenReturn(mockFeatureProperty);
    WfsFilterDelegate delegate = new WfsFilterDelegate(mockFeatureMetacardType, MockWfsServer.getFilterCapabilities(), GeospatialUtil.EPSG_4326_URN, mockMapper, GeospatialUtil.LAT_LON_ORDER);
    try {
        // Inject the mockMetacardAttribute at the head of the array
        Object[] methParams = ObjectArrays.concat(mockMetacardAttribute, inputParams);
        // Generate the array of class types for the reflection call
        Class<?>[] classTypes = FluentIterable.from(Arrays.asList(methParams)).transform(new Function<Object, Class>() {

            @Override
            public Class<?> apply(Object o) {
                // Autoboxing is a small problem with reflection when trying to be too clever
                return (o instanceof Long) ? long.class : o.getClass();
            }
        }).toArray(Class.class);
        Method method = WfsFilterDelegate.class.getMethod(methName, classTypes);
        method.invoke(delegate, methParams);
    } catch (InvocationTargetException e) {
        throw e.getCause();
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Function(com.google.common.base.Function) FeatureAttributeDescriptor(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureAttributeDescriptor) BeforeClass(org.junit.BeforeClass) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Example 7 with MetacardMapper

use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper in project ddf by codice.

the class TestWfsSource method testSortingAscendingSortingSupported.

/**
     * Verify that the SortBy is set with the mapped Feature Property and a ASC sort order.  In this case, the incoming sort property of TEMPORAL is mapped to
     * myTemporalFeatureProperty.
     * <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>
     * <SortBy>
     * <SortProperty>
     * <ValueReference>myTemporalFeatureProperty</ValueReference>
     * <SortOrder>ASC</SortOrder>
     * </SortProperty>
     * </SortBy>
     * </ns5:Query>
     * </ns5:GetFeature>
     */
@Test
public void testSortingAscendingSortingSupported() throws Exception {
    // Setup
    final String searchPhrase = "*";
    final String mockTemporalFeatureProperty = "myTemporalFeatureProperty";
    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);
    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();
    JAXBElement<?> abstractSortingClause = queryType.getAbstractSortingClause();
    SortByType sortByType = (SortByType) abstractSortingClause.getValue();
    assertThat(sortByType.getSortProperty().get(0).getValueReference(), is(mockTemporalFeatureProperty));
    assertThat(sortByType.getSortProperty().get(0).getSortOrder().name(), is(SortOrderType.ASC.value()));
}
Also used : SortBy(org.opengis.filter.sort.SortBy) ArrayList(java.util.ArrayList) SortByType(net.opengis.filter.v_2_0_0.SortByType) Matchers.containsString(org.hamcrest.Matchers.containsString) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(ddf.catalog.filter.impl.SortByImpl) QueryType(net.opengis.wfs.v_2_0_0.QueryType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) Test(org.junit.Test)

Example 8 with MetacardMapper

use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper in project ddf by codice.

the class WfsSource method buildFeatureFilters.

private void buildFeatureFilters(List<FeatureTypeType> featureTypes, FilterCapabilities filterCapabilities) throws SecurityServiceException {
    Wfs wfs = factory.getClient();
    if (filterCapabilities == null) {
        return;
    }
    // Use local Map for metacardtype registrations and once they are populated with latest
    // MetacardTypes, then do actual registration
    Map<String, MetacardTypeRegistration> mcTypeRegs = new HashMap<String, MetacardTypeRegistration>();
    this.featureTypeFilters.clear();
    for (FeatureTypeType featureTypeType : featureTypes) {
        String ftSimpleName = featureTypeType.getName().getLocalPart();
        if (StringUtils.isNotBlank(forcedFeatureType) && !StringUtils.equals(forcedFeatureType, ftSimpleName)) {
            continue;
        }
        if (mcTypeRegs.containsKey(ftSimpleName)) {
            LOGGER.debug("WfsSource {}: MetacardType {} is already registered - skipping to next metacard type", getId(), ftSimpleName);
            continue;
        }
        LOGGER.debug("ftName: {}", ftSimpleName);
        try {
            XmlSchema schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(featureTypeType.getName()));
            if (schema == null) {
                // Some WFS 2.0.0 DescribeFeatureRequests return inconsistent results when
                // the `:` character is encoded in the URL, ie Prefix:SomeFeature is encoded to
                // Prefix%3ASomeFeature. To avoid this issue, we will make a call without the prefix
                // if the previous call does not work.
                schema = wfs.describeFeatureType(new DescribeFeatureTypeRequest(new QName(featureTypeType.getName().getNamespaceURI(), featureTypeType.getName().getLocalPart(), "")));
            }
            if (schema != null) {
                // Update local map with enough info to create actual MetacardType registrations
                // later
                MetacardTypeRegistration registration = createFeatureMetacardTypeRegistration(featureTypeType, ftSimpleName, schema);
                mcTypeRegs.put(ftSimpleName, registration);
                FeatureMetacardType featureMetacardType = registration.getFtMetacard();
                lookupFeatureConverter(ftSimpleName, featureMetacardType);
                MetacardMapper metacardAttributeToFeaturePropertyMapper = lookupMetacardAttributeToFeaturePropertyMapper(featureMetacardType.getFeatureType());
                this.featureTypeFilters.put(featureMetacardType.getFeatureType(), new WfsFilterDelegate(featureMetacardType, filterCapabilities, registration.getSrs(), metacardAttributeToFeaturePropertyMapper, coordinateOrder));
            }
        } catch (WfsException | IllegalArgumentException wfse) {
            LOGGER.debug(WFS_ERROR_MESSAGE, wfse);
        } catch (WebApplicationException wae) {
            LOGGER.debug(handleWebApplicationException(wae), wae);
        }
    }
    registerFeatureMetacardTypes(mcTypeRegs);
    if (featureTypeFilters.isEmpty()) {
        LOGGER.debug("Wfs Source {}: No Feature Type schemas validated.", getId());
    }
    LOGGER.debug("Wfs Source {}: Number of validated Features = {}", getId(), featureTypeFilters.size());
    updateSupportedSpatialOperators(filterCapabilities.getSpatialCapabilities().getSpatialOperators());
}
Also used : FeatureTypeType(net.opengis.wfs.v_2_0_0.FeatureTypeType) WebApplicationException(javax.ws.rs.WebApplicationException) Wfs(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) XmlSchema(org.apache.ws.commons.schema.XmlSchema) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Example 9 with MetacardMapper

use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper in project ddf by codice.

the class WfsSource method mapSortByPropertyName.

/**
     * If a MetacardMapper cannot be found or there is no mapping for the incomingPropertyName, return null.
     * This will cause a query to be constructed without an AbstractSortingClause.
     */
private String mapSortByPropertyName(QName featureType, String incomingPropertyName) {
    MetacardMapper metacardToFeaturePropertyMapper = lookupMetacardAttributeToFeaturePropertyMapper(featureType);
    String mappedPropertyName = null;
    if (metacardToFeaturePropertyMapper != null) {
        if (StringUtils.equals(Result.TEMPORAL, incomingPropertyName) || StringUtils.equals(Metacard.EFFECTIVE, incomingPropertyName)) {
            mappedPropertyName = StringUtils.isNotBlank(metacardToFeaturePropertyMapper.getSortByTemporalFeatureProperty()) ? metacardToFeaturePropertyMapper.getSortByTemporalFeatureProperty() : null;
        } else if (StringUtils.equals(Result.RELEVANCE, incomingPropertyName)) {
            mappedPropertyName = StringUtils.isNotBlank(metacardToFeaturePropertyMapper.getSortByRelevanceFeatureProperty()) ? metacardToFeaturePropertyMapper.getSortByRelevanceFeatureProperty() : null;
        } else if (StringUtils.equals(Result.DISTANCE, incomingPropertyName)) {
            mappedPropertyName = StringUtils.isNotBlank(metacardToFeaturePropertyMapper.getSortByDistanceFeatureProperty()) ? metacardToFeaturePropertyMapper.getSortByDistanceFeatureProperty() : null;
        } else {
            mappedPropertyName = null;
        }
    } else {
        mappedPropertyName = null;
    }
    return mappedPropertyName;
}
Also used : MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Example 10 with MetacardMapper

use of org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper in project ddf by codice.

the class WfsSource method lookupFeatureConverter.

private void lookupFeatureConverter(String ftSimpleName, FeatureMetacardType ftMetacard) {
    FeatureConverter featureConverter = null;
    /**
         * The list of feature converter factories injected into this class is a live list.  So, feature converter factories
         * can be added and removed from the system while running.
         */
    if (CollectionUtils.isNotEmpty(featureConverterFactories)) {
        for (FeatureConverterFactory factory : featureConverterFactories) {
            if (ftSimpleName.equalsIgnoreCase(factory.getFeatureType())) {
                featureConverter = factory.createConverter();
                break;
            }
        }
    }
    // Found a specific feature converter
    if (featureConverter != null) {
        LOGGER.debug("WFS Source {}: Features of type: {} will be converted using {}", getId(), ftSimpleName, featureConverter.getClass().getSimpleName());
    } else {
        LOGGER.debug("WfsSource {}: Unable to find a feature specific converter; {} will be converted using the GenericFeatureConverter", getId(), ftSimpleName);
        // Since we have no specific converter, we will check to see if we have a mapper to do
        // feature property to metacard attribute mappings.
        MetacardMapper featurePropertyToMetacardAttributeMapper = lookupMetacardAttributeToFeaturePropertyMapper(ftMetacard.getFeatureType());
        if (featurePropertyToMetacardAttributeMapper != null) {
            featureConverter = new GenericFeatureConverterWfs20(featurePropertyToMetacardAttributeMapper);
            LOGGER.debug("WFS Source {}: Created {} for feature type {} with feature property to metacard attribute mapper.", getId(), featureConverter.getClass().getSimpleName(), ftSimpleName);
        } else {
            featureConverter = new GenericFeatureConverterWfs20();
            LOGGER.debug("WFS Source {}: Created {} for feature type {} with no feature property to metacard attribute mapper.", getId(), featureConverter.getClass().getSimpleName(), ftSimpleName);
        }
    }
    featureConverter.setSourceId(getId());
    featureConverter.setMetacardType(ftMetacard);
    featureConverter.setWfsUrl(wfsUrl);
    featureConverter.setCoordinateOrder(coordinateOrder);
    // Add the Feature Type name as an alias for xstream
    LOGGER.debug("Registering feature converter {} for feature type {}.", featureConverter.getClass().getSimpleName(), ftSimpleName);
    getFeatureCollectionReader().registerConverter(featureConverter);
}
Also used : GenericFeatureConverterWfs20(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.impl.GenericFeatureConverterWfs20) FeatureConverterFactory(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.converter.FeatureConverterFactory) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)

Aggregations

MetacardMapper (org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper)10 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 SortByImpl (ddf.catalog.filter.impl.SortByImpl)4 QueryImpl (ddf.catalog.operation.impl.QueryImpl)4 GetFeatureType (net.opengis.wfs.v_2_0_0.GetFeatureType)4 QueryType (net.opengis.wfs.v_2_0_0.QueryType)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 SortBy (org.opengis.filter.sort.SortBy)4 HashMap (java.util.HashMap)2 SortByType (net.opengis.filter.v_2_0_0.SortByType)2 FeatureConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter)2 Function (com.google.common.base.Function)1 XStream (com.thoughtworks.xstream.XStream)1 WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)1 Metacard (ddf.catalog.data.Metacard)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 WebApplicationException (javax.ws.rs.WebApplicationException)1