use of org.openforis.idm.model.NodePointer 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.NodePointer in project collect by openforis.
the class NodeChangeMap method addMinCountChanges.
public void addMinCountChanges(Collection<NodePointer> pointers) {
for (NodePointer nodePointer : pointers) {
EntityChange change = prepareEntityChange(nodePointer.getEntity());
change.setMinCount(nodePointer.getChildDefinitionId(), nodePointer.getNodesMinCount());
}
}
use of org.openforis.idm.model.NodePointer in project collect by openforis.
the class NodeChangeMap method addRelevanceChanges.
public void addRelevanceChanges(Set<NodePointer> pointers) {
for (NodePointer nodePointer : pointers) {
EntityChange change = prepareEntityChange(nodePointer.getEntity());
change.setRelevance(nodePointer.getChildName(), nodePointer.areNodesRelevant());
}
}
use of org.openforis.idm.model.NodePointer in project collect by openforis.
the class NodeChangeMap method addMaxCountChanges.
public void addMaxCountChanges(Collection<NodePointer> pointers) {
for (NodePointer nodePointer : pointers) {
EntityChange change = prepareEntityChange(nodePointer.getEntity());
change.setMaxCount(nodePointer.getChildDefinitionId(), nodePointer.getNodesMaxCount());
}
}
use of org.openforis.idm.model.NodePointer in project collect by openforis.
the class RecordUpdater method getAncestorsAndSelfPointers.
private List<NodePointer> getAncestorsAndSelfPointers(Node<?> node) {
List<NodePointer> pointers = getAncestorPointers(node);
pointers.add(new NodePointer(node));
return pointers;
}
Aggregations