use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class DefaultJDBCFeatureStore method decompose.
/**
* Decompose given type in flat types for table creation.
*/
private void decompose(FeatureType type, List<FeatureType> types, List<TypeRelation> relations) throws DataStoreException {
final GenericName dbName = NamesExt.create(type.getName().tip().toString());
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName(dbName);
for (PropertyType pt : type.getProperties(true)) {
if (pt instanceof FeatureAssociationRole) {
final FeatureAssociationRole asso = (FeatureAssociationRole) pt;
final FeatureType attType = asso.getValueType();
final TypeRelation relation = new TypeRelation();
relation.property = asso;
relation.parent = type;
relation.child = attType;
relations.add(relation);
decompose(attType, types, relations);
} else {
ftb.addProperty(pt);
}
}
final FeatureType flatType = ftb.build();
if (!types.contains(flatType)) {
types.add(flatType);
}
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class SQLQueryBuilder method encodeSelectColumnNames.
protected void encodeSelectColumnNames(StringBuilder sql, FeatureType featureType, Hints hints) {
for (PropertyType att : featureType.getProperties(true)) {
if (att instanceof DBRelationOperation) {
final RelationMetaModel relation = ((DBRelationOperation) att).getRelation();
final String str = att.getName().tip().toString();
if (relation.isImported()) {
dialect.encodeColumnName(sql, str);
} else {
// key is exported, it means the database field is in the other table.
continue;
}
} else if (att instanceof Operation || att instanceof FeatureAssociationRole || AttributeConvention.contains(att.getName())) {
continue;
} else if (AttributeConvention.isGeometryAttribute(att)) {
// encode as geometry
encodeGeometryColumn((AttributeType) att, sql, hints);
// alias it to be the name of the original geometry
dialect.encodeColumnAlias(sql, att.getName().tip().toString());
} else {
dialect.encodeColumnName(sql, att.getName().tip().toString());
}
sql.append(',');
}
sql.setLength(sql.length() - 1);
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class FeatureExt method fill.
private static void fill(final ParameterValueGroup source, final Feature target) {
final ParameterDescriptorGroup paramdesc = source.getDescriptor();
for (final PropertyType desc : target.getType().getProperties(true)) {
if (desc instanceof FeatureAssociationRole) {
final FeatureAssociationRole assRole = (FeatureAssociationRole) desc;
try {
final List<ParameterValueGroup> groups = source.groups(desc.getName().tip().toString());
if (groups != null) {
for (ParameterValueGroup gr : groups) {
final FeatureAssociation att = assRole.newInstance();
final Feature val = assRole.getValueType().newInstance();
att.setValue(val);
fill(gr, val);
target.setProperty(att);
}
}
} catch (Exception ex) {
// parameter might not exist of might be a group
}
} else if (desc instanceof AttributeType) {
final AttributeType at = (AttributeType) desc;
final String code = desc.getName().tip().toString();
final GeneralParameterValue gpv = searchParameter(source, code);
if (gpv instanceof ParameterValue) {
target.setPropertyValue(code, ((ParameterValue) gpv).getValue());
}
}
}
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class FeatureExt method copy.
/**
* @param deep true for a deep copy
*/
private static Feature copy(Feature feature, boolean deep) {
final FeatureType type = feature.getType();
final Feature cp = type.newInstance();
final Collection<? extends PropertyType> props = type.getProperties(true);
for (PropertyType pt : props) {
if (pt instanceof AttributeType) {
final String name = pt.getName().toString();
final Object val = feature.getPropertyValue(name);
if (val != null) {
cp.setPropertyValue(name, deep ? deepCopy(val) : val);
}
} else if (pt instanceof FeatureAssociationRole) {
final String name = pt.getName().toString();
final Object val = feature.getPropertyValue(name);
if (deep) {
if (val != null) {
cp.setPropertyValue(name, deepCopy(val));
}
} else {
if (val instanceof Collection) {
final Collection col = (Collection) val;
final Collection cpCol = new ArrayList(col.size());
for (Iterator ite = col.iterator(); ite.hasNext(); ) {
cpCol.add(copy((Feature) ite.next()));
}
cp.setPropertyValue(name, cpCol);
} else if (val != null) {
cp.setPropertyValue(name, copy((Feature) val));
}
}
}
}
return cp;
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class FeatureTypeExt method equalsIgnoreConvention.
private static boolean equalsIgnoreConvention(PropertyType pt1, PropertyType pt2) {
if (pt1 instanceof FeatureAssociationRole) {
if (pt2 instanceof FeatureAssociationRole) {
final FeatureAssociationRole far1 = (FeatureAssociationRole) pt1;
final FeatureAssociationRole far2 = (FeatureAssociationRole) pt2;
// check base properties
if (!Objects.equals(far1.getName(), far2.getName()) || !Objects.equals(far1.getDefinition(), far2.getDefinition()) || !Objects.equals(far1.getDesignation(), far2.getDesignation()) || !Objects.equals(far1.getDesignation(), far2.getDesignation())) {
return false;
}
if (far1.getMinimumOccurs() != far2.getMinimumOccurs() || far1.getMaximumOccurs() != far2.getMaximumOccurs()) {
return false;
}
if (!equalsIgnoreConvention(far1.getValueType(), far2.getValueType())) {
return false;
}
} else {
return false;
}
} else if (!pt1.equals(pt2)) {
return false;
}
return true;
}
Aggregations