Search in sources :

Example 6 with NodePointer

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;
}
Also used : CodeAttribute(org.openforis.idm.model.CodeAttribute) Attribute(org.openforis.idm.model.Attribute) BooleanAttribute(org.openforis.idm.model.BooleanAttribute) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) NodePointer(org.openforis.idm.model.NodePointer) Record(org.openforis.idm.model.Record) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with NodePointer

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());
    }
}
Also used : NodePointer(org.openforis.idm.model.NodePointer)

Example 8 with NodePointer

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());
    }
}
Also used : NodePointer(org.openforis.idm.model.NodePointer)

Example 9 with NodePointer

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());
    }
}
Also used : NodePointer(org.openforis.idm.model.NodePointer)

Example 10 with NodePointer

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;
}
Also used : NodePointer(org.openforis.idm.model.NodePointer)

Aggregations

NodePointer (org.openforis.idm.model.NodePointer)14 ArrayList (java.util.ArrayList)7 Entity (org.openforis.idm.model.Entity)6 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)5 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 Attribute (org.openforis.idm.model.Attribute)3 BooleanAttribute (org.openforis.idm.model.BooleanAttribute)3 CodeAttribute (org.openforis.idm.model.CodeAttribute)3 Node (org.openforis.idm.model.Node)3 Record (org.openforis.idm.model.Record)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 ModelVersion (org.openforis.idm.metamodel.ModelVersion)2 ValidationResultFlag (org.openforis.idm.metamodel.validation.ValidationResultFlag)1 Validator (org.openforis.idm.metamodel.validation.Validator)1 BooleanValue (org.openforis.idm.model.BooleanValue)1 Value (org.openforis.idm.model.Value)1