use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class PostgresComplexTypeTest method testComplex2Insert.
/**
* 3 level depths feature test.
*/
@Test
public void testComplex2Insert() throws DataStoreException, VersioningException {
reload(false);
store.createFeatureType(FTYPE_COMPLEX2);
final FeatureType soundingType = store.getFeatureType(store.getNames().iterator().next().toString());
final FeatureType recordType = ((FeatureAssociationRole) soundingType.getProperty("records")).getValueType();
final FeatureType dataType = ((FeatureAssociationRole) recordType.getProperty("datas")).getValueType();
final Feature sounding = soundingType.newInstance();
sounding.setPropertyValue("identifier", 120l);
final Feature record1 = recordType.newInstance();
record1.setPropertyValue("time", new Date(5000000));
final Feature data11 = dataType.newInstance();
data11.setPropertyValue("values", new Float[] { 1f, 2f, 3f });
final Feature data12 = dataType.newInstance();
data12.setPropertyValue("values", new Float[] { 4f, 5f, 6f });
record1.setPropertyValue("datas", Arrays.asList(data11, data12));
final Feature record2 = recordType.newInstance();
record2.setPropertyValue("time", new Date(6000000));
final Feature data21 = dataType.newInstance();
data21.setPropertyValue("values", new Float[] { 7f, 8f, 9f });
record2.setPropertyValue("datas", Arrays.asList(data21));
sounding.setPropertyValue("records", Arrays.asList(record1, record2));
List<ResourceId> addedIds = store.addFeatures(soundingType.getName().toString(), Collections.singleton(sounding));
assertEquals(1, addedIds.size());
assertEquals(FF.resourceId("Sounding.1"), addedIds.get(0));
final Session session = store.createSession(false);
final FeatureCollection col = session.getFeatureCollection(new Query(soundingType.getName()));
assertEquals(1, col.size());
final FeatureIterator ite = store.getFeatureReader(new Query(soundingType.getName()));
try {
final Feature resFeature = ite.next();
assertNotNull(resFeature);
assertEquals(120l, resFeature.getPropertyValue("identifier"));
final Collection<Feature> records = (Collection<Feature>) resFeature.getPropertyValue("records");
assertEquals(2, records.size());
final boolean[] found = new boolean[2];
for (Feature record : records) {
final Timestamp time = (Timestamp) record.getPropertyValue("time");
if (time.getTime() == 5000000) {
found[0] = true;
final Collection<Feature> datas = (Collection<Feature>) record.getPropertyValue("datas");
assertEquals(2, datas.size());
final boolean[] dfound = new boolean[2];
for (Feature data : datas) {
final Float[] values = (Float[]) data.getPropertyValue("values");
if (Arrays.equals(values, new Float[] { 1f, 2f, 3f })) {
dfound[0] = true;
} else if (Arrays.equals(values, new Float[] { 4f, 5f, 6f })) {
dfound[1] = true;
} else {
fail("Unexpected property \n" + data);
}
}
for (boolean b : dfound) assertTrue(b);
} else if (time.getTime() == 6000000) {
found[1] = true;
final Collection<Feature> datas = (Collection<Feature>) record.getPropertyValue("datas");
assertEquals(1, datas.size());
final boolean[] dfound = new boolean[1];
for (Feature data : datas) {
final Float[] values = (Float[]) data.getPropertyValue("values");
if (Arrays.equals(values, new Float[] { 7f, 8f, 9f })) {
dfound[0] = true;
} else {
fail("Unexpected property \n" + data);
}
}
for (boolean b : dfound) assertTrue(b);
} else {
fail("Unexpected property \n" + record);
}
}
for (boolean b : found) assertTrue(b);
} finally {
ite.close();
}
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class FeatureLoop method loop.
public static void loop(Feature feature, PropertyType pt, BiFunction<PropertyType, Object, Object> function) {
final String attName = pt.getName().toString();
if (pt instanceof AttributeType) {
final AttributeType at = (AttributeType) pt;
Object val = feature.getPropertyValue(attName);
if (at.getMaximumOccurs() > 1) {
// value is a collection
if (val instanceof List) {
// use list iterator to avoid creating a new collection
final ListIterator ite = ((List) val).listIterator();
while (ite.hasNext()) {
Object v = ite.next();
Object r = function.apply(pt, v);
if (v != r)
ite.set(r);
}
} else {
Collection c = (Collection) val;
// delay the creation of a new collection until it is really necessary
List cp = null;
int i = 0;
for (Iterator ite = c.iterator(); ite.hasNext(); ) {
Object v = ite.next();
Object r = function.apply(pt, v);
if (v != r) {
cp = new ArrayList(c);
cp.set(i, r);
}
i++;
}
if (cp != null) {
feature.setPropertyValue(attName, val);
}
}
} else {
// single value
Object r = function.apply(pt, val);
if (r != val) {
// we do this test, since we know setting a null may
// cause the creation of a property is sis feature implementation
feature.setPropertyValue(attName, val);
}
}
} else if (pt instanceof FeatureAssociationRole) {
// TODO
} else if (pt instanceof Operation) {
// NOTE : value is a Property, the bifunction can call the set value when needed
Object val = feature.getPropertyValue(attName);
// we can't do anything to store and operation value back
Object newValue = function.apply(pt, val);
}
}
use of org.opengis.feature.FeatureAssociationRole in project geotoolkit by Geomatys.
the class XmlFeatureTypeTest method testReadGroupChoice.
@Test
public void testReadGroupChoice() throws JAXBException, IllegalNameException {
final JAXBFeatureTypeReader reader = getReader(true);
final GenericNameIndex<FeatureType> types = reader.read(XmlFeatureTypeTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/GroupChoiceMinMaxType.xsd"));
assertEquals(5, types.getNames().size());
FeatureType dataset = types.get("dataset");
assertEquals("http://www.iho.int/S-121:dataset", dataset.getName().toString());
// check we should have 4 properties, sis:id, gml:id, and the two group choices
final PropertyType[] properties = dataset.getProperties(true).toArray(new PropertyType[0]);
assertEquals("sis:identifier", properties[0].getName().toString());
assertEquals("http://www.opengis.net/gml/3.2:@id", properties[1].getName().toString());
assertEquals("http://www.iho.int/S-121:Right", properties[2].getName().toString());
assertEquals("http://www.iho.int/S-121:Source", properties[3].getName().toString());
assertTrue(properties[2] instanceof FeatureAssociationRole);
assertTrue(properties[3] instanceof FeatureAssociationRole);
FeatureAssociationRole far1 = (FeatureAssociationRole) properties[2];
FeatureAssociationRole far2 = (FeatureAssociationRole) properties[3];
assertEquals("http://www.iho.int/S-121:Right", far1.getValueType().getName().toString());
assertEquals("http://www.iho.int/S-121:Source", far2.getValueType().getName().toString());
// check min max occurs
assertEquals(0, far1.getMinimumOccurs());
assertEquals(Integer.MAX_VALUE, far1.getMaximumOccurs());
assertEquals(0, far2.getMinimumOccurs());
assertEquals(Integer.MAX_VALUE, far2.getMaximumOccurs());
}
Aggregations