Search in sources :

Example 16 with FeatureMetacardType

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType in project ddf by codice.

the class FeatureMetacardTypeTest method testFeatureMetacardTypeMultipleStringProperties.

@Test
public void testFeatureMetacardTypeMultipleStringProperties() {
    XmlSchema schema = new XmlSchema();
    XmlSchemaElement stringElement = new XmlSchemaElement(schema, true);
    stringElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
    stringElement.setSchemaTypeName(Constants.XSD_STRING);
    stringElement.setName(ELEMENT_NAME_1);
    XmlSchemaElement stringElement2 = new XmlSchemaElement(schema, true);
    stringElement2.setSchemaType(new XmlSchemaSimpleType(schema, false));
    stringElement2.setSchemaTypeName(Constants.XSD_STRING);
    stringElement2.setName(ELEMENT_NAME_2);
    schema.getElements().put(new QName(ELEMENT_NAME_1), stringElement);
    schema.getElements().put(new QName(ELEMENT_NAME_2), stringElement2);
    FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, NON_QUERYABLE_PROPS, Wfs20Constants.GML_3_2_NAMESPACE);
    assertTrue(featureMetacardType.getTextualProperties().size() == 2);
    assertAttributeDescriptor(featureMetacardType, ELEMENT_NAME_2, BasicTypes.STRING_TYPE);
    assertAttributeDescriptor(featureMetacardType, ELEMENT_NAME_1, BasicTypes.STRING_TYPE);
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Test(org.junit.Test)

Example 17 with FeatureMetacardType

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType in project ddf by codice.

the class FeatureMetacardTypeTest method testfeatureMetacardTypeFindFloatProperties.

@Test
public void testfeatureMetacardTypeFindFloatProperties() {
    XmlSchema schema = new XmlSchema();
    XmlSchemaElement floatElement = new XmlSchemaElement(schema, true);
    floatElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
    floatElement.setSchemaTypeName(Constants.XSD_FLOAT);
    floatElement.setName(ELEMENT_NAME_1);
    schema.getElements().put(new QName(ELEMENT_NAME_1), floatElement);
    FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, NON_QUERYABLE_PROPS, Wfs20Constants.GML_3_2_NAMESPACE);
    assertAttributeDescriptor(featureMetacardType, ELEMENT_NAME_1, BasicTypes.FLOAT_TYPE);
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) QName(javax.xml.namespace.QName) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Test(org.junit.Test)

Example 18 with FeatureMetacardType

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType in project ddf by codice.

the class FeatureMetacardTypeTest method testFeatureMetacardTypeStringNonQueryProperty.

@Test
public void testFeatureMetacardTypeStringNonQueryProperty() {
    XmlSchema schema = new XmlSchema();
    XmlSchemaElement stringElement = new XmlSchemaElement(schema, true);
    stringElement.setSchemaType(new XmlSchemaSimpleType(schema, false));
    stringElement.setSchemaTypeName(Constants.XSD_STRING);
    stringElement.setName(ELEMENT_NAME_1);
    XmlSchemaElement stringElement2 = new XmlSchemaElement(schema, true);
    stringElement2.setSchemaType(new XmlSchemaSimpleType(schema, false));
    stringElement2.setSchemaTypeName(Constants.XSD_STRING);
    stringElement2.setName(ELEMENT_NAME_2);
    List<String> nonQueryProps = new ArrayList<String>();
    nonQueryProps.add(ELEMENT_NAME_1);
    FeatureMetacardType featureMetacardType = new FeatureMetacardType(schema, FEATURE_TYPE, nonQueryProps, Wfs20Constants.GML_3_2_NAMESPACE);
    assertTrue(featureMetacardType.getTextualProperties().size() == 2);
    AttributeDescriptor attrDesc = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_1));
    assertNotNull(attrDesc);
    assertFalse(attrDesc.isIndexed());
    AttributeDescriptor attrDesc2 = featureMetacardType.getAttributeDescriptor(prefix(ELEMENT_NAME_2));
    assertNotNull(attrDesc2);
    assertTrue(attrDesc2.isIndexed());
}
Also used : XmlSchema(org.apache.ws.commons.schema.XmlSchema) XmlSchemaElement(org.apache.ws.commons.schema.XmlSchemaElement) XmlSchemaSimpleType(org.apache.ws.commons.schema.XmlSchemaSimpleType) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Test(org.junit.Test)

Example 19 with FeatureMetacardType

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType in project ddf by codice.

the class AbstractFeatureConverter method createMetacardFromFeature.

protected Metacard createMetacardFromFeature(HierarchicalStreamReader hreader, MetacardType metacardType) {
    StringWriter metadataWriter = new StringWriter();
    HierarchicalStreamReader reader = copyXml(hreader, metadataWriter);
    MetacardImpl mc = new MetacardImpl(metacardType);
    mc.setContentTypeName(metacardType.getName());
    while (reader.hasMoreChildren()) {
        reader.moveDown();
        String featureProperty = prefix + reader.getNodeName();
        AttributeDescriptor attributeDescriptor = metacardType.getAttributeDescriptor(featureProperty);
        //Check MetacardMapper for mappings of incoming values
        String mappedMetacardAttribute = null;
        if (metacardMapper != null) {
            LOGGER.debug("Looking up metacard attribute for feature property {} using metacard mapper", featureProperty);
            mappedMetacardAttribute = metacardMapper.getMetacardAttribute(featureProperty);
            LOGGER.debug("Found metacard attribute {} for feature property {}", mappedMetacardAttribute, featureProperty);
        }
        Serializable value = null;
        if (attributeDescriptor != null && (StringUtils.isNotBlank(reader.getValue()) || BasicTypes.GEO_TYPE.getAttributeFormat().equals(attributeDescriptor.getType().getAttributeFormat()) || BasicTypes.DATE_TYPE.getAttributeFormat().equals(attributeDescriptor.getType().getAttributeFormat()))) {
            if (StringUtils.isNotBlank(mappedMetacardAttribute)) {
                if (StringUtils.equals(mappedMetacardAttribute, Core.RESOURCE_SIZE)) {
                    String sizeBeforeConversion = reader.getValue();
                    String bytes = convertToBytes(reader, metacardMapper.getDataUnit());
                    if (StringUtils.isNotBlank(bytes)) {
                        LOGGER.debug("Setting mapped metacard attribute {} with value {}", mappedMetacardAttribute, bytes);
                        mc.setAttribute(mappedMetacardAttribute, bytes);
                    }
                    if (StringUtils.isNotBlank(sizeBeforeConversion)) {
                        LOGGER.debug("Setting metacard attribute {} with value {}", featureProperty, sizeBeforeConversion);
                        mc.setAttribute(featureProperty, sizeBeforeConversion);
                    }
                } else {
                    value = getValueForMetacardAttribute(attributeDescriptor.getType().getAttributeFormat(), reader);
                    if (value != null) {
                        LOGGER.debug("Setting mapped metacard attribute {} with value {}", mappedMetacardAttribute, value);
                        mc.setAttribute(mappedMetacardAttribute, value);
                        mc.setAttribute(featureProperty, value);
                    }
                }
            } else {
                value = getValueForMetacardAttribute(attributeDescriptor.getType().getAttributeFormat(), reader);
                if (value != null) {
                    LOGGER.debug("Setting metacard attribute {} with value {}", featureProperty, value);
                    mc.setAttribute(featureProperty, value);
                }
            }
            if (BasicTypes.GEO_TYPE.getAttributeFormat().equals(attributeDescriptor.getType().getAttributeFormat())) {
                mc.setLocation((String) value);
            }
            // populate that field as well
            if (isBasicMetacardAttribute(reader.getNodeName())) {
                LOGGER.debug("Setting metacard basic attribute: {} = {}", reader.getNodeName(), value);
                mc.setAttribute(reader.getNodeName(), value);
            }
        }
        reader.moveUp();
    }
    mc.setMetadata(metadataWriter.toString());
    try {
        if (metacardType instanceof FeatureMetacardType) {
            URI namespaceUri = new URI(((FeatureMetacardType) metacardType).getNamespaceURI());
            mc.setTargetNamespace(namespaceUri);
        }
    } catch (URISyntaxException e) {
        LOGGER.debug("Error setting target namespace uri on metacard.", e);
    }
    return mc;
}
Also used : Serializable(java.io.Serializable) StringWriter(java.io.StringWriter) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) URISyntaxException(java.net.URISyntaxException) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 20 with FeatureMetacardType

use of org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType 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)

Aggregations

FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)40 XmlSchema (org.apache.ws.commons.schema.XmlSchema)37 QName (javax.xml.namespace.QName)34 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)32 Test (org.junit.Test)32 XmlSchemaSimpleType (org.apache.ws.commons.schema.XmlSchemaSimpleType)26 XmlSchemaComplexType (org.apache.ws.commons.schema.XmlSchemaComplexType)10 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)7 ArrayList (java.util.ArrayList)6 MetacardType (ddf.catalog.data.MetacardType)2 HashMap (java.util.HashMap)2 Hashtable (java.util.Hashtable)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 XmlSchemaComplexContent (org.apache.ws.commons.schema.XmlSchemaComplexContent)2 XmlSchemaComplexContentExtension (org.apache.ws.commons.schema.XmlSchemaComplexContentExtension)2 XmlSchemaSequence (org.apache.ws.commons.schema.XmlSchemaSequence)2 WfsException (org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1