public SimpleFeature next() throws NoSuchElementException { final SimpleFeature next = delegate.next(); // check all write protected attributes are null final SimpleFeatureType featureType = next.getFeatureType(); for (AttributeDescriptor att : featureType.getAttributeDescriptors()) { String name = att.getLocalName(); if (!writableAttributes.contains(name)) { Object value = next.getAttribute(name); if (value != null) { String typeName = getSchema().getName().getLocalPart(); if (response == Response.CHALLENGE) { throw SecureCatalogImpl.unauthorizedAccess(typeName); } else { throw new UnsupportedOperationException( "Trying to write on the write protected attribute " + name); } } } } return next; } }
public <T extends ResourceInfo> T getResourceByName(Name name, Class<T> clazz) { return getResourceByName(name.getNamespaceURI(), name.getLocalPart(), clazz); }
private SimpleHash buildType(ComplexType ft) { // create a variable "attributes" which his a list of all the // attributes, but at the same time, is a map keyed by name Map<String, Object> attributeMap = new LinkedHashMap<String, Object>(); Collection<PropertyDescriptor> descriptors = ft.getDescriptors(); for (Iterator<PropertyDescriptor> it = descriptors.iterator(); it.hasNext(); ) { PropertyDescriptor descr = it.next(); Map<String, Object> attribute = new HashMap<String, Object>(); attribute.put("name", descr.getName().getLocalPart()); attribute.put("namespace", getNamespace(descr.getName())); attribute.put("prefix", getPrefix(descr.getName())); attribute.put("type", descr.getType().getBinding().getName()); attribute.put( "isGeometry", Boolean.valueOf(Geometry.class.isAssignableFrom(descr.getType().getBinding()))); attributeMap.put(descr.getName().toString(), attribute); } // build up the result, feature type is represented by its name an // attributes SimpleHash map = new SimpleHash(); map.put("attributes", new SequenceMapModel(attributeMap, this)); map.put("name", ft.getName().getLocalPart()); map.put("namespace", getNamespace(ft.getName())); map.put("prefix", getPrefix(ft.getName())); return map; }
/** * Create a new {@link OracleFeatureTypeMapper} on top of the original featureType provided * * @param featureType * @throws CQLException */ public OracleFeatureTypeMapper(SimpleFeatureType featureType) throws CQLException { wrappedFeatureType = featureType; originalName = featureType.getName(); mappedName = originalName.getLocalPart(); mappedName = remap(mappedName); List<AttributeDescriptor> attributes = featureType.getAttributeDescriptors(); definitions = new LinkedList<Definition>(); definitionsMapping = new HashMap<Name, Definition>(); // Loop over attributes and prepare the definitions for (AttributeDescriptor attribute : attributes) { final String originalAttribute = attribute.getLocalName(); final AttributeType type = attribute.getType(); final Class<?> binding = type.getBinding(); String attributeName = remap(originalAttribute); // Create the definition to map the original attribute to the Oracle specific one final Definition definition = new Definition(originalAttribute, ECQL.toExpression(attributeName), binding); definitions.add(definition); definitionsMapping.put(attribute.getName(), definition); } remapFeatureType(); }
List<String> retainedAttributes, SimpleFeatureTypeBuilder tb) { for (AttributeDescriptor descriptor : schema.getAttributeDescriptors()) { isInRetainList = retainedAttributes.contains(descriptor.getLocalName()); logger.fine("Checking " + descriptor.getLocalName() + " --> " + isInRetainList); if (!isInRetainList || schema.getGeometryDescriptor() == descriptor) { continue; builder.setName(schema.getName().getLocalPart() + "_" + descriptor.getName()); builder.setNillable(descriptor.isNillable()); builder.setBinding(descriptor.getType().getBinding()); builder.setMinOccurs(descriptor.getMinOccurs()); builder.setMaxOccurs(descriptor.getMaxOccurs()); AttributeDescriptor intersectionDescriptor = builder.buildDescriptor( schema.getName().getLocalPart() + "_" + descriptor.getName(), descriptor.getType()); tb.add(intersectionDescriptor);
/** * Checks if the feature type specified is a GridCoverage wrapper * * @param featureType * @return */ public static boolean isWrappedCoverage(SimpleFeatureType featureType) { if (!"GridCoverage".equals(featureType.getName().getLocalPart())) return false; if (featureType.getAttributeCount() != 2) return false; AttributeDescriptor polyDescriptor = featureType.getDescriptor("geom"); if (polyDescriptor == null || !Polygon.class.equals(polyDescriptor.getType().getBinding())) return false; AttributeDescriptor gridDescriptor = featureType.getDescriptor("grid"); if (gridDescriptor == null || !GridCoverage.class.equals(gridDescriptor.getType().getBinding())) return false; return true; }
throws SchemaException { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); tb.setName(schema.getTypeName()); tb.setNamespaceURI(schema.getName().getNamespaceURI()); tb.setAbstract(schema.isAbstract()); for (int i = 0; i < schema.getAttributeCount(); i++) { if (!forceOnlyMissing || geometryType.getCoordinateReferenceSystem() == null) { tb.crs(crs); tb.add(geometryType.getLocalName(), geometryType.getType().getBinding()); } else { tb.add(attributeType);
public void testFixture() throws Exception { SimpleFeatureType type = DataUtilities.createType( "namespace.typename", "name:String,id:0,geom:MultiLineString"); assertEquals("namespace", "namespace", type.getName().getNamespaceURI()); assertEquals("typename", "typename", type.getTypeName()); assertEquals("attributes", 3, type.getAttributeCount()); assertEquals("a1", "name", type.getDescriptor(0).getLocalName()); assertEquals("a1", String.class, type.getDescriptor(0).getType().getBinding()); assertEquals("a2", "id", type.getDescriptor(1).getLocalName()); assertEquals("a2", Integer.class, type.getDescriptor(1).getType().getBinding()); assertEquals("a3", "geom", type.getDescriptor(2).getLocalName()); assertEquals("a3", MultiLineString.class, type.getDescriptor(2).getType().getBinding()); }
/** Initializes the builder with state from a pre-existing feature type. */ public void init(SimpleFeatureType type) { init(); if (type == null) return; uri = type.getName().getNamespaceURI(); local = type.getName().getLocalPart(); description = type.getDescription(); restrictions = null; restrictions().addAll(type.getRestrictions()); this.defaultCrs = type.getCoordinateReferenceSystem(); this.defaultCrsSet = true; if (type.getGeometryDescriptor() != null) { this.defaultGeometry = type.getGeometryDescriptor().getLocalName(); } attributes = null; attributes().addAll(type.getAttributeDescriptors()); isAbstract = type.isAbstract(); superType = (SimpleFeatureType) type.getSuper(); }
@Test public void testGetFeaturesFeatureSource() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); assertEquals(RENAMED, fs.getSchema().getName().getLocalPart()); SimpleFeatureCollection fc = fs.getFeatures(); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertTrue(fc.size() > 0); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(RENAMED, sf.getFeatureType().getName().getLocalPart()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); }
String tableName = featureType.getTypeName(); schemaName = schemaName != null ? schemaName : "PUBLIC"; for (PropertyDescriptor ad : featureType.getDescriptors()) { if (ad instanceof GeometryDescriptor) { GeometryDescriptor gd = (GeometryDescriptor) ad; Class binding = ad.getType().getBinding(); String propertyName = ad.getName().getLocalPart(); CoordinateReferenceSystem crs = gd.getCoordinateReferenceSystem(); if (crs != null) { Integer code = CRS.lookupEpsgCode(crs, true); epsg = code != null ? code : -1; } else { LOGGER.warning("Column " + gd.getLocalName() + " has no crs"); sql.append(", '").append(gd.getLocalName()).append("'"); sql.append(", ").append(epsg); sql.append(", '")
for (AttributeDescriptor d : original.getAttributeDescriptors()) { if (Geometry.class.isAssignableFrom(d.getType().getBinding()) && multiWriter) { GeometryDescriptor gd = (GeometryDescriptor) d; builder.add(gd.getLocalName(), target, gd.getCoordinateReferenceSystem()); builder.setDefaultGeometry(gd.getLocalName()); } else { builder.add(d); builder.setNamespaceURI(original.getName().getURI());
@Test public void testFeautureSourceFidFilter() throws Exception { // grab the last feature in the collection (there are more than one) SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); // build a filter that will retrieve that feature only FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); final String fid = RENAMED + ".1107531701011"; Filter fidFilter = ff.id(Collections.singleton(ff.featureId(fid))); SimpleFeatureCollection fc = fs.getFeatures(new Query(RENAMED, fidFilter)); assertEquals(RENAMED, fc.getSchema().getName().getLocalPart()); assertEquals(1, fc.size()); FeatureIterator<SimpleFeature> it = fc.features(); assertTrue(it.hasNext()); SimpleFeature sf = it.next(); assertFalse(it.hasNext()); it.close(); assertEquals(fid, sf.getID()); }
public DataStoreAdaptor(SimpleFeatureSource source) { this.source = source; this.schema = source.getSchema(); this.name = schema.getName(); this.typeName = name.getLocalPart(); }
public List<AttributeTypeInfo> loadAttributes(FeatureTypeInfo info) throws IOException { List<AttributeTypeInfo> attributes = new ArrayList(); FeatureType ft = getFeatureType(info); for (PropertyDescriptor pd : ft.getDescriptors()) { AttributeTypeInfo att = catalog.getFactory().createAttribute(); att.setFeatureType(info); att.setName(pd.getName().getLocalPart()); att.setMinOccurs(pd.getMinOccurs()); att.setMaxOccurs(pd.getMaxOccurs()); att.setNillable(pd.isNillable()); att.setBinding(pd.getType().getBinding()); int length = FeatureTypes.getFieldLength(pd); if (length > 0) { att.setLength(length); } attributes.add(att); } return attributes; }
SimpleFeature f = it.next(); SimpleFeature g = w.next(); for (PropertyDescriptor pd : collection.getSchema().getDescriptors()) { String name = pd.getName().getLocalPart(); if (pd.getType().getBinding() == Boolean.class) { int bool = 0; if (f.getAttribute(name) != null) { bool = (Boolean) (f.getAttribute(name)) ? 1 : 0; g.setAttribute(name, bool); } else { g.setAttribute(name, f.getAttribute(name));
FeatureType featureType = featureSource.getSchema(); Name name = featureSource.getName(); if (name == null) { name = featureType.getName(); ftinfo.setNativeName(name.getLocalPart()); ftinfo.setName(name.getLocalPart()); CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem(); if (crs == null && featureType.getGeometryDescriptor() != null) { crs = featureType.getGeometryDescriptor().getCoordinateReferenceSystem();
public String toString() { StringBuffer sb = new StringBuffer(getClass().getSimpleName()).append(":"); sb.append(getDescriptor().getName().getLocalPart()); if (!getDescriptor() .getName() .getLocalPart() .equals(getDescriptor().getType().getName().getLocalPart()) || id != null) { sb.append("<"); sb.append(getDescriptor().getType().getName().getLocalPart()); if (id != null) { sb.append(" id="); sb.append(id); } sb.append(">"); } sb.append("="); sb.append(value); return sb.toString(); }
/** * Create the modified feature type. * * @param sourceFeatureType the source feature type * @return the modified feature type * @throws ProcessException errror */ private SimpleFeatureType createTargetFeatureType(FeatureType sourceFeatureType) throws ProcessException { try { SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder(); typeBuilder.setName(sourceFeatureType.getName().getLocalPart()); typeBuilder.setNamespaceURI(sourceFeatureType.getName().getNamespaceURI()); for (PropertyDescriptor attbType : sourceFeatureType.getDescriptors()) { typeBuilder.add((AttributeDescriptor) attbType); } typeBuilder.minOccurs(1).maxOccurs(1).nillable(false).add("lrs_measure", Double.class); typeBuilder.setDefaultGeometry( sourceFeatureType.getGeometryDescriptor().getLocalName()); return typeBuilder.buildFeatureType(); } catch (Exception e) { LOGGER.warning("Error creating type: " + e); throw new ProcessException("Error creating type: " + e, e); } }
@Test public void testGetFeaturesReader() throws Exception { FeatureReader<SimpleFeatureType, SimpleFeature> fr; fr = rts.getFeatureReader(new Query(RENAMED), Transaction.AUTO_COMMIT); SimpleFeature sf = fr.next(); fr.close(); assertEquals(RENAMED, sf.getFeatureType().getName().getLocalPart()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); }