use of org.openforis.idm.model.Record in project collect by openforis.
the class RecordUpdater method initializeEntity.
protected NodeChangeMap initializeEntity(Entity entity, boolean newEntity) {
Record record = entity.getRecord();
NodeChangeMap changeMap = new NodeChangeMap();
changeMap.addEntityAddChange(entity);
List<NodePointer> entityDescendantPointers = getDescendantNodePointers(entity);
updateMinCount(entityDescendantPointers);
updateMaxCount(entityDescendantPointers);
addEmptyNodes(entity);
applyInitialValues(entity);
// recalculate attributes
// TODO exclude this when exporting for backup (not for Calc)
List<Attribute<?, ?>> calculatedAttributes = recalculateDependentCalculatedAttributes(entity);
changeMap.addValueChanges(calculatedAttributes);
if (validateAfterUpdate) {
// min/max count
entityDescendantPointers = getDescendantNodePointers(entity);
// for root entity there is no node pointer so we iterate over its descendants
Collection<NodePointer> minCountDependentNodes = record.determineMinCountDependentNodes(entityDescendantPointers);
Collection<NodePointer> updatedMinCountPointers = updateMinCount(minCountDependentNodes);
changeMap.addMinCountChanges(updatedMinCountPointers);
Collection<NodePointer> maxCountDependentNodes = record.determineMaxCountDependentNodes(entityDescendantPointers);
Collection<NodePointer> updatedMaxCountPointers = updateMaxCount(maxCountDependentNodes);
changeMap.addMaxCountChanges(updatedMaxCountPointers);
Set<NodePointer> updatedCardinalityPointers = new HashSet<NodePointer>(updatedMinCountPointers);
updatedCardinalityPointers.addAll(updatedMaxCountPointers);
// relevance
Set<NodePointer> pointersToRecalculateRelevanceFor = new HashSet<NodePointer>();
pointersToRecalculateRelevanceFor.addAll(getChildNodePointers(entity));
pointersToRecalculateRelevanceFor.addAll(record.determineRelevanceDependentNodes(calculatedAttributes));
if (entity.getParent() != null) {
pointersToRecalculateRelevanceFor.addAll(record.determineRelevanceDependentNodePointers(Arrays.asList(new NodePointer(entity))));
}
Set<NodePointer> updatedRelevancePointers = new RelevanceUpdater(new ArrayList<NodePointer>(pointersToRecalculateRelevanceFor)).update();
changeMap.addRelevanceChanges(updatedRelevancePointers);
// cardinality
Collection<NodePointer> nodePointersToCheckCardinalityFor = new HashSet<NodePointer>(entityDescendantPointers);
if (entity.getParent() != null) {
nodePointersToCheckCardinalityFor.add(new NodePointer(entity));
}
validateCardinality(record, nodePointersToCheckCardinalityFor, changeMap);
// validate attributes
Set<Node<?>> nodesToCheckValidationFor = new HashSet<Node<?>>();
nodesToCheckValidationFor.add(entity);
nodesToCheckValidationFor.addAll(pointersToNodes(updatedCardinalityPointers));
Set<Attribute<?, ?>> attributesToValidate = record.determineValidationDependentNodes(nodesToCheckValidationFor);
validateAttributes(record, attributesToValidate, changeMap);
}
return changeMap;
}
use of org.openforis.idm.model.Record in project collect by openforis.
the class EntityProxy method isApplicable.
protected boolean isApplicable(NodeDefinition childDefinition) {
Record record = entity.getRecord();
ModelVersion version = record.getVersion();
return version == null || version.isApplicable(childDefinition);
}
use of org.openforis.idm.model.Record in project collect by openforis.
the class DescendantNodeFilter method accept.
@Override
public boolean accept(Node<?> node) {
NodeDefinition nodeDef = node.getDefinition();
if (!(nodeDef instanceof EntityDefinition) || !descendantAttributeDefinition.isDescendantOf((EntityDefinition) nodeDef)) {
return false;
}
Record record = node.getRecord();
SurveyContext surveyContext = record.getSurveyContext();
ExpressionEvaluator expressionEvaluator = surveyContext.getExpressionEvaluator();
List<Node<?>> attributes = record.findNodesByPath(descendantAttributeDefinition.getPath());
for (Node<?> attribute : attributes) {
try {
Entity parentEntity = attribute.getParent();
if (parentEntity == node && expressionEvaluator.evaluateBoolean(parentEntity, attribute, descendantAttributeCondition)) {
return true;
}
} catch (InvalidExpressionException e) {
throw new RuntimeException(e);
}
}
return false;
}
use of org.openforis.idm.model.Record in project collect by openforis.
the class Check method getExpressionEvaluator.
private ExpressionEvaluator getExpressionEvaluator(Attribute<?, ?> context) {
Record record = context.getRecord();
SurveyContext surveyContext = record.getSurveyContext();
ExpressionEvaluator evaluator = surveyContext.getExpressionEvaluator();
return evaluator;
}
use of org.openforis.idm.model.Record in project collect by openforis.
the class ComparisonCheck method evaluate.
@Override
public ValidationResultFlag evaluate(Attribute<?, ?> node) {
Record record = node.getRecord();
SurveyContext recordContext = record.getSurveyContext();
ExpressionEvaluator expressionEvaluator = recordContext.getExpressionEvaluator();
String expr = getExpression();
try {
boolean valid = expressionEvaluator.evaluateBoolean(node.getParent(), node, expr, true);
return ValidationResultFlag.valueOf(valid, this.getFlag());
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Error evaluating comparison check", e);
}
}
Aggregations