use of org.openforis.idm.model.NodeVisitor 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.NodeVisitor in project collect by openforis.
the class AbstractExpression method evaluateMultiple.
/**
* Returns a list of Node that matches the expression
*
* @throws InvalidExpressionException
*/
public List<Node<?>> evaluateMultiple(Node<?> contextNode, final Node<?> thisNode) throws InvalidExpressionException {
final List<Node<?>> list = new ArrayList<Node<?>>();
iterateMultiple(contextNode, thisNode, new NodeVisitor() {
public void visit(Node<?> item, int index) {
list.add(item);
}
});
return list;
}
use of org.openforis.idm.model.NodeVisitor in project collect by openforis.
the class RecordConverter method convertToLatestUnitStorage.
/**
* This is a workaround: it avoids to refer to the old unit field to get data
*
* TODO remove this conversion or apply only for records stored using version prior to 3.0 Alpha 5
*
* @param survey
* @param rootEntity
*/
protected void convertToLatestUnitStorage(CollectRecord record) {
final CollectSurvey survey = (CollectSurvey) record.getSurvey();
Entity rootEntity = record.getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int idx) {
if (node instanceof NumberAttribute<?, ?> || node instanceof NumericRangeAttribute<?, ?>) {
Field<String> unitNameField;
Field<Integer> unitField;
if (node instanceof NumberAttribute<?, ?>) {
unitNameField = ((NumberAttribute<?, ?>) node).getUnitNameField();
unitField = ((NumberAttribute<?, ?>) node).getUnitField();
} else {
unitNameField = ((NumericRangeAttribute<?, ?>) node).getUnitNameField();
unitField = ((NumericRangeAttribute<?, ?>) node).getUnitField();
}
if (unitNameField.hasData()) {
moveDataToNewUnitField(survey, unitNameField, unitField);
}
}
}
});
}
use of org.openforis.idm.model.NodeVisitor in project collect by openforis.
the class RecordIndexManager method index.
protected void index(final IndexWriter indexWriter, CollectRecord record) throws RecordIndexException {
try {
Entity rootEntity = record.getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int idx) {
NodeDefinition defn = node.getDefinition();
if (defn instanceof AttributeDefinition) {
index(indexWriter, (Attribute<?, ?>) node);
}
}
});
} catch (Exception e) {
throw new RecordIndexException(e);
}
}
use of org.openforis.idm.model.NodeVisitor in project collect by openforis.
the class RecordUpdater method applyInitialValues.
private List<Attribute<?, ?>> applyInitialValues(Entity entity) {
final List<Attribute<?, ?>> updatedAttributes = new ArrayList<Attribute<?, ?>>();
entity.traverse(new NodeVisitor() {
public void visit(Node<?> node, int idx) {
if (node instanceof Attribute && node.isEmpty()) {
Attribute<?, ?> attr = (Attribute<?, ?>) node;
Value value = applyInitialValue(attr);
if (value != null) {
updatedAttributes.add(attr);
}
}
}
});
return updatedAttributes;
}
Aggregations