use of org.openforis.idm.model.Attribute in project collect by openforis.
the class ValidationMessageBuilder method getKeyText.
public String getKeyText(Entity entity, Locale locale) {
EntityDefinition defn = entity.getDefinition();
List<AttributeDefinition> keyDefns = defn.getKeyAttributeDefinitions();
if (!keyDefns.isEmpty()) {
List<String> shortKeyParts = new ArrayList<String>();
List<String> fullKeyParts = new ArrayList<String>();
for (AttributeDefinition keyDefn : keyDefns) {
Attribute<?, ?> keyAttr = (Attribute<?, ?>) entity.getChild(keyDefn, 0);
if (keyAttr != null) {
Object keyValue = getKeyLabelPart(keyAttr);
if (keyValue != null && StringUtils.isNotBlank(keyValue.toString())) {
shortKeyParts.add(keyValue.toString());
String label = getPrettyLabelText(keyDefn, locale);
String fullKeyPart = label + " " + keyValue;
fullKeyParts.add(fullKeyPart);
}
}
}
return StringUtils.join(shortKeyParts, RECORD_KEYS_LABEL_SEPARATOR);
} else if (entity.getParent() != null) {
return "" + (entity.getIndex() + 1);
} else {
return null;
}
}
use of org.openforis.idm.model.Attribute in project collect by openforis.
the class QueryExecutorIntegrationTest method testSimpleQuery.
@Test
public void testSimpleQuery() {
// select region from tree where dbh > 20
DataQuery query = new DataQuery(survey);
EntityDefinition treeDef = (EntityDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree");
AttributeDefinition dbhDef = (AttributeDefinition) survey.getSchema().getDefinitionByPath("/cluster/plot/tree/dbh");
query.setEntityDefinition(treeDef);
query.setAttributeDefinition(dbhDef);
query.setConditions("dbh > 20");
final List<Node<?>> nodes = new ArrayList<Node<?>>();
DataQueryExecutorJob job = jobManager.createJob(DataQueryExecutorJob.class);
DataQueryExecutorJobInput input = new DataQueryExecutorJobInput(query, Step.ENTRY, new NodeProcessor() {
public void process(Node<?> node) {
nodes.add(node);
}
});
job.setInput(input);
jobManager.start(job, false);
assertFalse(nodes.isEmpty());
// first result
Node<?> node = nodes.get(0);
assertTrue(node instanceof Attribute);
CollectRecord record = (CollectRecord) node.getRecord();
assertEquals(Arrays.asList("10_117"), record.getRootEntityKeyValues());
}
use of org.openforis.idm.model.Attribute in project collect by openforis.
the class EventProducer method produceFor.
public List<RecordEvent> produceFor(CollectRecord record, final String userName) {
final List<RecordEvent> events = new ArrayList<RecordEvent>();
final Integer recordId = record.getId();
final RecordStep recordStep = record.getStep().toRecordStep();
record.getRootEntity().traverse(new NodeVisitor() {
public void visit(Node<? extends NodeDefinition> node, int idx) {
NodeDefinition nodeDef = node.getDefinition();
List<String> ancestorIds = getAncestorIds(nodeDef, node.getAncestorIds());
EventFactory factory = new EventFactory(recordId, recordStep, ancestorIds, node, userName);
if (node instanceof Entity) {
events.addAll(factory.entityCreated());
} else if (node instanceof Attribute) {
if (nodeDef.isMultiple()) {
events.addAll(factory.attributeCreated());
} else {
events.addAll(factory.attributeUpdated());
}
}
}
});
return events;
}
use of org.openforis.idm.model.Attribute in project collect by openforis.
the class DataHandler method endAttributeElement.
@SuppressWarnings({ "rawtypes" })
protected void endAttributeElement() {
Attribute attr = (Attribute) node;
try {
if (field != null) {
Field<?> fld = getField();
if (fld != null) {
setField(fld);
} else {
warn(field, "Can't parse field with type " + attr.getClass().getSimpleName());
// this.node = node.getParent();
}
}
} catch (NumberFormatException e) {
warn(field, e.toString());
}
if (field == null) {
Node<?> oldNode = node;
this.node = node.getParent();
removeIfEmpty(oldNode);
} else {
this.field = null;
}
}
use of org.openforis.idm.model.Attribute 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);
}
Aggregations