use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class StateDependencyMap method registerDependencies.
private void registerDependencies(EntityDefinition entityDefinition) {
List<NodeDefinition> childDefinitions = entityDefinition.getChildDefinitions();
for (NodeDefinition nodeDefinition : childDefinitions) {
registerDependencies(nodeDefinition, nodeDefinition.getRelevantExpression(), relevantDependencies);
registerDependencies(nodeDefinition, nodeDefinition.getRequiredExpression(), requiredDependencies);
if (nodeDefinition instanceof AttributeDefinition) {
registerDependencies((AttributeDefinition) nodeDefinition);
} else {
registerDependencies((EntityDefinition) nodeDefinition);
}
}
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class DataHandler method startChildNode.
public void startChildNode(String localName, Attributes attributes) {
Entity entity = (Entity) node;
NodeDefinition childDefn = getNodeDefinition(entity, localName, attributes);
if (childDefn == null) {
warn(localName, "Undefined node");
pushIgnore();
} else {
ModelVersion version = record.getVersion();
if (version == null || version.isApplicable(childDefn)) {
Node<?> newNode = childDefn.createNode();
entity.add(newNode);
Integer stateValue = getNodeState();
if (stateValue != null) {
entity.setChildState(localName, stateValue);
}
this.node = newNode;
} else {
warn(localName, "Node definition is not applicable to the record version");
pushIgnore();
}
}
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class DataLoader method processRow.
private void processRow(CollectRecord record, Record row) throws DataInconsistencyException {
Integer id = row.getValueAsInteger(DATA.ID);
Integer parentId = row.getValueAsInteger(DATA.PARENT_ID);
Integer defnId = row.getValueAsInteger(DATA.DEFINITION_ID);
Node<?> o;
if (parentId == null) {
// Process root entity
o = record.getRootEntity();
Integer rootEntityDefnId = o.getDefinition().getId();
if (!rootEntityDefnId.equals(defnId)) {
throw new DataInconsistencyException(DATA.DEFINITION_ID + " " + defnId + " does not match " + RECORD.ROOT_ENTITY_ID + " " + rootEntityDefnId);
}
} else {
// Process other objects
Node<? extends NodeDefinition> parent = objectsById.get(parentId);
if (parent == null) {
throw new DataInconsistencyException("Parent " + parentId + " not yet loaded");
}
if (!(parent instanceof Entity)) {
throw new DataInconsistencyException("Parent " + parentId + " not an entity");
}
NodeDefinition defn = record.getSurvey().getSchema().getById(defnId);
if (defn == null) {
throw new DataInconsistencyException("Unknown schema definition " + DATA.DEFINITION_ID);
}
NodeMapper mapper = NodeMapper.getInstance(defn.getClass());
Node<?> o1 = mapper.addNode(defn, row, (Entity) parent);
if (defn instanceof AttributeDefinition) {
String remarks = row.getValue(DATA.REMARKS);
String s = row.getValueAsString(DATA.SYMBOL);
Character symbol = null;
if (s != null && s.length() == 1) {
symbol = s.charAt(0);
}
Attribute<?, ?> attribute = (Attribute<?, ?>) o1;
attribute.setRemarks(remarks);
attribute.setSymbol(symbol);
}
o = o1;
}
objectsById.put(id, o);
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class DataMarshaller method writeEntity.
private void writeEntity(Entity entity, Writer out) throws IOException {
out.write("{");
out.write("\"");
out.write(entity.getName());
out.write("\":{");
EntityDefinition defn = entity.getDefinition();
List<NodeDefinition> childDefns = defn.getChildDefinitions();
for (int j = 0; j < childDefns.size(); j++) {
if (j > 0) {
out.write(",");
}
NodeDefinition childDef = childDefns.get(j);
String name = childDef.getName();
int childCount = entity.getCount(name);
if (childCount > 0) {
if (childDef.isMultiple()) {
out.write("[");
for (int i = 0; i < childCount; i++) {
if (i > 0) {
out.write(",");
}
Node<?> child = entity.get(name, i);
write(child, i, out);
}
out.write("]");
} else {
Node<?> child = entity.get(name, 0);
write(child, 0, out);
}
}
}
out.write("}}");
}
use of org.openforis.idm.metamodel.NodeDefinition in project collect by openforis.
the class PathTest method testSingleAttributeWithIndex.
@Test
public void testSingleAttributeWithIndex() throws InvalidPathException {
Entity cluster = getRootEntity();
Entity plot = EntityBuilder.addEntity(cluster, "plot");
Entity tree1 = EntityBuilder.addEntity(plot, "tree");
EntityBuilder.addValue(tree1, "dbh", 12.2);
Entity tree2 = EntityBuilder.addEntity(plot, "tree");
RealAttribute dbh2 = EntityBuilder.addValue(tree2, "dbh", 15.7);
Path path = Path.parse("tree[2]/dbh[1]");
// Node
List<Node<?>> res = path.evaluate(plot);
Assert.assertEquals(1, res.size());
Assert.assertEquals(dbh2, res.get(0));
// Defn
NodeDefinition def = path.evaluate(plot.getDefinition());
Assert.assertEquals(dbh2.getDefinition(), def);
}
Aggregations