use of org.openforis.idm.model.Entity 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.model.Entity 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.model.Entity in project collect by openforis.
the class IDMFunctionsTest method testDistinctValuesFunctionWithEmptyList.
@Test
public void testDistinctValuesFunctionWithEmptyList() throws InvalidExpressionException {
Entity plot1 = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot1, "no", new Code("1"));
Entity plot2 = EntityBuilder.addEntity(cluster, "plot");
EntityBuilder.addValue(plot2, "no", new Code("2"));
Entity plot3 = EntityBuilder.addEntity(cluster, "plot");
// duplicate value
EntityBuilder.addValue(plot3, "no", new Code("1"));
String expr = ExpressionFactory.IDM_PREFIX + ":" + "distinct-values(plot/accessibility)";
Object result = evaluateExpression(expr);
Assert.assertNull(result);
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class ModelPathExpressionTest method testIteratePath2.
@Test
public void testIteratePath2() throws InvalidExpressionException {
String entityName = "plot";
Entity plot1 = EntityBuilder.addEntity(cluster, entityName);
EntityBuilder.addValue(plot1, "no", new Code("1"));
Entity plot2 = EntityBuilder.addEntity(cluster, entityName);
EntityBuilder.addValue(plot2, "no", new Code("1"));
Entity plot3 = EntityBuilder.addEntity(cluster, entityName);
EntityBuilder.addValue(plot3, "no", new Code("1"));
String expr = "plot/no";
List<Node<?>> list = iterateExpression(expr, cluster);
Assert.assertEquals(3, list.size());
}
use of org.openforis.idm.model.Entity in project collect by openforis.
the class ModelPathExpressionTest method testParent.
@Test
public void testParent() throws InvalidExpressionException {
Entity plot = EntityBuilder.addEntity(cluster, "plot");
List<Node<?>> plots = iterateExpression("parent()", plot);
Assert.assertEquals(1, plots.size());
}
Aggregations