Search in sources :

Example 1 with AbstractAssociation

use of org.apache.sis.feature.AbstractAssociation in project geotoolkit by Geomatys.

the class DBRelationOperation method apply.

@Override
public Property apply(Feature ftr, ParameterValueGroup pvg) {
    final Object key = ftr.getPropertyValue(relation.getCurrentColumn());
    final Query qb = new Query();
    qb.setTypeName(NamesExt.create(relation.getForeignTable()));
    qb.setSelection(relation.toFilter(key));
    final FeatureCollection res = store.createSession(false).getFeatureCollection(qb);
    final Object value;
    if (type.getMaximumOccurs() == 1) {
        try (FeatureIterator ite = res.iterator()) {
            if (ite.hasNext()) {
                value = ite.next();
            } else {
                value = null;
            }
        }
    } else {
        value = res;
    }
    return new AbstractAssociation(type) {

        @Override
        public Feature getValue() throws MultiValuedPropertyException {
            if (value == null || value instanceof Feature) {
                return (Feature) value;
            }
            throw new MultiValuedPropertyException();
        }

        @Override
        public Collection<Feature> getValues() {
            if (value == null) {
                return Collections.EMPTY_LIST;
            } else if (value instanceof Feature) {
                return Arrays.asList((Feature) value);
            } else {
                return res;
            }
        }

        @Override
        public void setValue(Feature value) throws InvalidPropertyValueException {
            throw new UnsupportedOperationException("Not supported.");
        }
    };
}
Also used : FeatureIterator(org.geotoolkit.storage.feature.FeatureIterator) AbstractAssociation(org.apache.sis.feature.AbstractAssociation) Query(org.geotoolkit.storage.feature.query.Query) FeatureCollection(org.geotoolkit.storage.feature.FeatureCollection) MultiValuedPropertyException(org.opengis.feature.MultiValuedPropertyException) Feature(org.opengis.feature.Feature)

Aggregations

AbstractAssociation (org.apache.sis.feature.AbstractAssociation)1 FeatureCollection (org.geotoolkit.storage.feature.FeatureCollection)1 FeatureIterator (org.geotoolkit.storage.feature.FeatureIterator)1 Query (org.geotoolkit.storage.feature.query.Query)1 Feature (org.opengis.feature.Feature)1 MultiValuedPropertyException (org.opengis.feature.MultiValuedPropertyException)1