throws ProcessException { try { AttributeDescriptor lrsMeasureAttbType = targetFeatureType.getDescriptor("lrs_measure"); Object[] attributes = new Object[targetFeatureType.getAttributeCount()]; for (int i = 0; i < attributes.length; i++) { AttributeDescriptor attbType = targetFeatureType.getAttributeDescriptors().get(i); if (attbType.equals(lrsMeasureAttbType)) { attributes[i] = lrsMeasure; } else { attributes[i] = feature.getProperty(attbType.getName()).getValue(); targetFeatureType, attributes, feature.getIdentifier().getID()); } catch (Exception e) { LOGGER.warning("Error creating feature: " + e);
/** We can handle *one* case and one case only */ public boolean canHandle(Object object, String xpath, Class target) { if (object instanceof Property) { Property property = (Property) object; final Name name = property.getName(); if (name != null) { return name.getLocalPart().equals(xpath); } else { // A property with no name? this is probably a place holder // or Null Object (such as Diff.NULL). return false; } } return false; }
propertyFields.add(p.getName().toString()); ft.setId(Integer.toString(i)); } else { ft.setId(feature.getProperty(originIDField).getValue().toString()); String propName = prop.getName().toString(); if (propertyFields.contains(propName)) { Object binding = prop.getType().getBinding(); val = (Integer)prop.getValue(); } else if(binding.equals(Long.class)){ val = ((Long)prop.getValue()).intValue(); } else if(binding.equals(String.class)){ try{ val = Integer.parseInt((String)prop.getValue()); } catch (NumberFormatException ex ){ continue; LOG.debug("Property {} of feature {} could not be interpreted as int, skipping", prop.getName().toString(), ft.getId()); continue;
attributeDescr = property.getDescriptor(); value = buildComplex((ComplexAttribute) property); } else if (property != null) { value = property.getValue(); entrySet.add(new MapEntry<Object, Object>("name", attributeName.getLocalPart())); entrySet.add( new MapEntry<Object, Object>("namespace", getNamespace(attributeName)));
private boolean hasChild(Property p) throws DataSourceException { boolean result = false; if (p.getValue() instanceof Collection) { Collection c = (Collection) p.getValue(); values.add(o); result = true; } else if (((Property) o).getDescriptor().getMinOccurs() > 0) { if (((Property) o).getDescriptor().isNillable()) { p.setValue(values); } else if (p.getName().equals(ComplexFeatureConstants.FEATURE_CHAINING_LINK_NAME)) { } else if (p.getValue() != null && p.getValue().toString().length() > 0) { result = true;
@Test public void testSweValues() { Map<String, String> expected = new HashMap<String, String>(); expected.put( "ID1.2", "missing missing 8.9 7.9 14.2 15.4 18.1 19.1 21.7 20.8 19.6 14.9 10.8 8.8 8.5 10.4"); expected.put( "ID2.2", "16.2 17.1 22.0 25.1 23.9 22.8 17.0 10.2 9.2 7.1 12.3 12.9 17.2 23.6 21.6 21.9 17.6 14.0 9.3 3.8"); FeatureIterator<? extends Feature> featIt = obsFeatures.features(); while (featIt.hasNext()) { Feature f = featIt.next(); PropertyName pf = ff.property("om:result/swe:DataArray/swe:values", namespaces); Object sweValues = pf.evaluate(f); assertNotNull(sweValues); assertTrue(sweValues instanceof ComplexAttribute); ComplexAttribute sweValuesAttr = (ComplexAttribute) sweValues; assertEquals( expected.get(f.getIdentifier().getID()), sweValuesAttr.getProperty(ComplexFeatureConstants.SIMPLE_CONTENT).getValue()); } } }
DefaultFeatureCollection results = new DefaultFeatureCollection(); try { if (featureCollection == null || featureCollection.size() == 0) { LOGGER.info("No features provided in request"); return results; || featureCollection.getSchema().getDescriptor(fromMeasureAttb) == null) { throw new ProcessException( "The from_measure_attb parameter was not provided or not defined in schema"); || featureCollection.getSchema().getDescriptor(toMeasureAttb) == null) { throw new ProcessException("The to_measure_attb parameter was not provided"); try { featureIterator = featureCollection.features(); Feature feature = featureIterator.next(); Double featureFromMeasure = (Double) feature.getProperty(fromMeasureAttb).getValue(); Double featureToMeasure = (Double) feature.getProperty(toMeasureAttb).getValue(); LengthIndexedLine lengthIndexedLine = new LengthIndexedLine( (Geometry) feature.getDefaultGeometryProperty().getValue()); double featureLength = featureToMeasure - featureFromMeasure; double startOffset = measure - featureFromMeasure; results.add(createTargetFeature(feature, targetFeatureType, point)); } finally { if (featureIterator != null) featureIterator.close();
/** Test CategorizeFunction */ @Test public void testCategorizeFunction() { final Map<String, String> VALUE_MAP = new HashMap<String, String>() { { put("sc.1", "missing value"); put("sc.2", "a valid value"); put("sc.3", "a valid value"); } }; FeatureIterator<Feature> features = exCollection.features(); try { while (features.hasNext()) { Feature feature = features.next(); String fId = feature.getIdentifier().getID(); Property attribute = feature.getProperty("someAttribute"); // <OCQL>Categorize(getID(), 'missing value', 2, 'a valid value')</OCQL> assertEquals(attribute.getValue(), VALUE_MAP.get(fId)); } } finally { features.close(); } }
/** * Helper method that tests that mappings files obtained through an hTTP request are correctly * handled, as well the included types and schemas. */ private void testHttpMapping(String mappingFileName) throws Exception { // instantiate a store for the mapping file AppSchemaDataAccess store = buildAppSchemaDataStore(mappingFileName); // check that a stations type is available assertThat(store.getTypeNames().length, is(1)); Name name = new NameImpl("http://www.stations.org/1.0", "Station"); assertThat(store.getTypeNames()[0], is(name)); // read the complex features FeatureIterator iterator = store.getFeatureSource(name).getFeatures().features(); List<Feature> features = new ArrayList<>(); while (iterator.hasNext()) { features.add(iterator.next()); } // three stations should be available assertThat(features.size(), is(3)); for (Feature feature : features) { // check that each station has at least a measurement Name measurements = new NameImpl("http://www.stations.org/1.0", "measurements"); Property property = feature.getProperty(measurements); assertThat(property.getValue(), instanceOf(List.class)); List values = (List) property.getValue(); assertThat(values.size() > 0, is(true)); } }
@Test public void testRemoveFeatureAttributePatch() throws Exception { Patch patch = new Patch(); String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID()); Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap(); Optional<?> oldValue = Optional.fromNullable(points1B.getProperty("extra").getValue()); GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, null); map.put(modifiedPointsType.getDescriptor("extra"), diff); FeatureDiff featureDiff = new FeatureDiff(path, map, RevFeatureType.build(modifiedPointsType), RevFeatureType.build(pointsType)); patch.addModifiedFeature(featureDiff); patch.addFeatureType(RevFeatureType.build(pointsType)); testPatch(patch); }
@Override public Feature next() { Feature original = delegate.next(); // this does not really work... // for (PropertyDescriptor pd : original.getType().getDescriptors()) { // Collection<Property> properties = original.getProperties(pd.getName()); // if(properties != null) { // for (Property p : properties) { // if (names.contains(p.getName()) || names.contains(p.getName().getLocalPart())) { // builder.append(pd.getName(), p); // } // } // } // } for (Property p : original.getProperties()) { if (names.contains(p.getName()) || names.contains(p.getName().getLocalPart())) { // this makes the thing type specific, but at least it works for the record case // TODO: eventually figure out how to make this for the general case... if (p.getType().equals(CSWRecordDescriptor.SIMPLE_LITERAL)) { builder.append(CSWRecordDescriptor.DC_ELEMENT_NAME, p); } else { builder.append(p.getName(), p); } } } return builder.buildFeature(original.getIdentifier().getID()); }
private void encodeSimpleLiteral(Property p) { String value = p.getValue().toString(); Name dn = p.getDescriptor().getName(); String name = dn.getLocalPart(); String prefix = MetaDataDescriptor.NAMESPACES.getPrefix(dn.getNamespaceURI()); AttributesImpl attributes = new AttributesImpl(); element(prefix + ":" + name, value, attributes); } }
private Function<Feature, Optional<Feature>> getTransformingFunction( final SimpleFeatureType featureType) { Function<Feature, Optional<Feature>> function = (feature) -> { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType); for (Property property : feature.getProperties()) { if (property instanceof GeometryAttribute) { builder.set(featureType.getGeometryDescriptor().getName(), property.getValue()); } else { builder.set(property.getName(), property.getValue()); } } Feature modifiedFeature = builder.buildFeature(feature.getIdentifier().getID()); return Optional.fromNullable(modifiedFeature); }; return function; }
/** * Mapping specifies station_no --> wq_plus/@id. A FidFilter over wq_plus type should result in * a compare equals filter over the station_no attribute of wq_ir_results simple type. */ @Test public void testUnrollFidMappedToAttribute() throws Exception { String fid = "station_no.1"; Id fidFilter = ff.id(Collections.singleton(ff.featureId(fid))); Filter unrolled = (Filter) fidFilter.accept(visitor, null); assertNotNull(unrolled); FeatureCollection<SimpleFeatureType, SimpleFeature> results = mapping.getSource().getFeatures(unrolled); assertEquals(1, getCount(results)); FeatureIterator<SimpleFeature> features = results.features(); SimpleFeature unmappedFeature = (SimpleFeature) features.next(); features.close(); assertNotNull(unmappedFeature); Object object = unmappedFeature.getProperty("station_no").getValue(); assertEquals(fid, object); }
FeatureIterator iterator = features.features(); while (iterator.hasNext()) { Feature next = iterator.next(); Collection<Property> children = next.getProperties("nestedFeature"); if (next.getIdentifier().toString().equals("cc.1")) { Object value = nestedFeature.getValue(); assertNotNull(value); value = ((Collection) value).iterator().next(); assertTrue(value instanceof FeatureImpl); Feature feature = (Feature) value; assertNotNull(feature.getProperty("someAttribute").getValue()); iterator = features.features(); while (iterator.hasNext()) { Feature next = iterator.next(); Collection<Property> children = next.getProperties("nestedFeature"); Object value = nestedFeature.getValue(); assertNotNull(value); value = ((Collection) value).iterator().next(); assertTrue(value instanceof FeatureImpl); Feature feature = (Feature) value; assertNotNull(feature.getProperty("someAttribute").getValue());
private String getAttributesJson(Feature feature) { JSONBuilder builder = new JSONStringer().object(); builder.key("id").value(feature.getIdentifier().toString()); if (feature instanceof SimpleFeature) { SimpleFeature sf = (SimpleFeature) feature; for (AttributeDescriptor ad : sf.getFeatureType().getAttributeDescriptors()) { if (ad instanceof GeometryDescriptor) { continue; } else { String name = ad.getLocalName(); Object value = sf.getAttribute(name); addAttribute(builder, name, value); } } } else { for (Property p : feature.getProperties()) { if (p.getType() instanceof GeometryPropertyType) { continue; } String name = p.getName().getLocalPart(); Object value = p.getValue(); addAttribute(builder, name, value); } } builder.endObject(); return builder.toString(); }
if (feature.getUserData().get("xlink:id") != null) { return Collections.EMPTY_LIST; FeatureType featureType = feature.getType(); String namespace = featureType.getName().getNamespaceURI(); String typeName = featureType.getName().getLocalPart(); QName qualifiedTypeName = new QName(namespace, typeName); feature.getDescriptor() .getUserData() .get(XSDElementDeclaration.class); value = property.getValue(); if (value != null) { value = property.getValue();
/** * Encode any client properties (XML attributes) found in the UserData map of a ComplexAttribute * as XML attributes of the element. * * @param complex the ComplexAttribute to search for client properties * @param element the element to which XML attributes should be added */ @SuppressWarnings("unchecked") public static void encodeClientProperties(Property complex, Element element) { Map<Name, Object> clientProperties = (Map<Name, Object>) complex.getUserData().get(Attributes.class); if (clientProperties != null) { for (Name name : clientProperties.keySet()) { if (clientProperties.get(name) != null) { element.setAttributeNS( name.getNamespaceURI(), name.getLocalPart(), clientProperties.get(name).toString()); } } } }
/** * Only used for Joining, to make sure that rows with different foreign id's aren't interpreted * as one feature and merged. */ public List<Object> getIdValues(Object source) { List<Object> ids = new ArrayList<Object>(); Expression idExpression = mapping.getFeatureIdExpression(); if (Expression.NIL.equals(idExpression) || idExpression instanceof Literal) { // GEOT-4554: if idExpression is not specified, should use PK if (source instanceof Feature) { for (Property p : ((Feature) source).getProperties()) { if (p.getName() .getLocalPart() .startsWith(JoiningJDBCFeatureSource.PRIMARY_KEY)) { ids.add(p.getValue()); } } } } else { FilterAttributeExtractor extractor = new FilterAttributeExtractor(); idExpression.accept(extractor, null); for (String att : extractor.getAttributeNameSet()) { ids.add(peekValue(source, namespaceAwareFilterFactory.property(att))); } } if (foreignIds != null) { ids.addAll(getForeignIdValues(source)); } return ids; }
private Map<String, CollectionLayer> getCollectionPublishingConfigurations() throws IOException { FeatureSource<FeatureType, Feature> collectionSource = getCollectionSource(); Query query = new Query(collectionSource.getName().getLocalPart()); query.setPropertyNames(new String[] {COLLECTION_NAME, LAYER}); FeatureCollection<FeatureType, Feature> features = collectionSource.getFeatures(query); Map<String, CollectionLayer> result = new LinkedHashMap<>(); features.accepts( f -> { Property p = f.getProperty(COLLECTION_NAME); String name = (String) p.getValue(); CollectionLayer config = CollectionLayer.buildCollectionLayerFromFeature(f); result.put(name, config); }, null); return result; }