use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class PathTest method testMultipleFieldPathWithIndex.
@Test
public void testMultipleFieldPathWithIndex() throws InvalidPathException {
Entity cluster = getRootEntity();
Entity plot = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addEntity(plot, "tree");
Entity tree2 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree2, "dbh", 12.2);
RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
Path path = Path.parse("tree[2]/dbh[2]/value");
// Node
List<Node<?>> res = path.evaluate(plot);
Assert.assertEquals(1, res.size());
Assert.assertEquals(15.7, ((Field<?>) res.get(0)).getValue());
// Defn
NodeDefinition def = path.evaluate(plot.getDefinition());
Assert.assertEquals(dbh2.getDefinition().getFieldDefinition("value"), def);
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class DataPersister method insertRow.
private int insertRow(CollectRecord record, Node<? extends NodeDefinition> node, Integer parentId, int idx) {
Integer defnId = node.getDefinition().getId();
if (defnId == null) {
throw new IllegalArgumentException("Null schema object definition id");
}
int dataRowId = jooqFactory.nextval(DATA_ID_SEQ).intValue();
InsertSetMoreStep<?> insert = jooqFactory.insertInto(DATA).set(DATA.ID, dataRowId).set(DATA.DEFINITION_ID, defnId).set(DATA.RECORD_ID, record.getId()).set(DATA.IDX, idx + 1).set(DATA.PARENT_ID, parentId);
NodeDefinition defn = node.getDefinition();
Class<? extends NodeDefinition> defnClass = defn.getClass();
if (node instanceof Attribute) {
Attribute<?, ?> attr = (Attribute<?, ?>) node;
if (attr.getRemarks() != null) {
insert.set(DATA.REMARKS, attr.getRemarks());
}
if (attr.getSymbol() != null) {
insert.set(DATA.SYMBOL, attr.getSymbol().toString());
}
}
NodeMapper mapper = NodeMapper.getInstance(defnClass);
mapper.setFields(node, insert);
insert.execute();
return dataRowId;
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class ProtostuffSerializationTest method testSkipRemovedAttribute.
@Test
public void testSkipRemovedAttribute() throws Exception {
// Set up
Survey survey = getTestSurvey();
// assignFakeNodeDefinitionIds(survey.getSchema());
Record record1 = createTestRecord(survey);
Entity cluster1 = record1.getRootEntity();
// Write
ModelSerializer ser = new ModelSerializer(10000);
byte[] data = ser.toByteArray(cluster1);
// remove attribute from record before comparing it with the new one
cluster1.remove("crew_no", 0);
// remove node definition from schema
Schema schema = survey.getSchema();
EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
NodeDefinition crewNumDefn = clusterDefn.getChildDefinition("crew_no");
clusterDefn.removeChildDefinition(crewNumDefn);
Record record2 = new Record(survey, "2.0", "cluster");
ser.mergeFrom(data, record2.getRootEntity());
// Compare
Assert.assertTrue(record1.getRootEntity().deepEquals(record2.getRootEntity()));
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class ProtostuffSerializationTest method testSkipRemovedEntity.
@Test
public void testSkipRemovedEntity() throws Exception {
// Set up
Survey survey = getTestSurvey();
// assignFakeNodeDefinitionIds(survey.getSchema());
Record record1 = createTestRecord(survey);
Entity cluster1 = record1.getRootEntity();
// Write
ModelSerializer ser = new ModelSerializer(10000);
byte[] data = ser.toByteArray(cluster1);
// remove data
cluster1.remove("map_sheet", 1);
cluster1.remove("map_sheet", 0);
Schema schema = survey.getSchema();
EntityDefinition clusterDefn = schema.getRootEntityDefinition("cluster");
NodeDefinition mapSheetDefn = clusterDefn.getChildDefinition("map_sheet");
clusterDefn.removeChildDefinition(mapSheetDefn);
Record record2 = new Record(survey, "2.0", "cluster");
ser.mergeFrom(data, record2.getRootEntity());
// Compare
Assert.assertTrue(record1.getRootEntity().deepEquals(record2.getRootEntity()));
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class AttributeVM method generateEntityAlias.
@Command
public void generateEntityAlias() {
AttributeDefinitionFormObject<?> fo = (AttributeDefinitionFormObject<?>) formObject;
String referencedAttributePath = fo.getReferencedAttributePath();
EntityDefinition sourceDef = editedItem.getParentEntityDefinition();
String aliasName = sourceDef + "_alias";
NodeDefinition referencedAttributeDef = editedItem.getDefinitionByPath(referencedAttributePath);
EntityDefinition parentDef = referencedAttributeDef.getNearestAncestorMultipleEntity();
if (parentDef.containsChildDefinition(aliasName)) {
MessageUtil.showError("survey.schema.attribute.generate_entity_alias.error.alias_already_existing", aliasName, parentDef.getName());
} else {
EntityDefinition aliasDef = schemaUpdater.generateAlias(sourceDef, editedItem.getName(), parentDef, referencedAttributeDef.getName());
((CollectSurvey) aliasDef.getSurvey()).getUIOptions().setLayout(aliasDef, Layout.TABLE);
aliasDef.rename(aliasName);
dispatchSchemaChangedCommand();
MessageUtil.showInfo("survey.schema.attribute.generate_entity_alias.generation_successfull", aliasName, parentDef.getName());
}
}
Aggregations