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);
}
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);
}
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());
}
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;
}
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());
}
Aggregations