Search in sources :

Example 16 with Attribute

use of org.openforis.idm.model.Attribute 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 17 with Attribute

use of org.openforis.idm.model.Attribute in project collect by openforis.

the class AttributeUpdateRequestProxy method toAttributeUpdateRequest.

@Override
@SuppressWarnings("unchecked")
public AttributeUpdateRequest<?> toAttributeUpdateRequest(CodeListManager codeListManager, RecordSessionManager sessionManager, CollectRecord record) {
    AttributeUpdateRequest<Value> opts = new NodeUpdateRequest.AttributeUpdateRequest<Value>();
    Attribute<?, ?> attribute = (Attribute<?, ?>) record.getNodeByInternalId(nodeId);
    opts.setAttribute((Attribute<?, Value>) attribute);
    Value parsedValue;
    if (attribute instanceof FileAttribute) {
        parsedValue = parseFileAttributeValue(sessionManager, record, nodeId, value);
    } else if (value == null) {
        parsedValue = null;
    } else {
        Entity parentEntity = attribute.getParent();
        String attributeName = attribute.getName();
        parsedValue = parseCompositeAttributeValue(codeListManager, parentEntity, attributeName, value);
    }
    opts.setValue(parsedValue);
    opts.setSymbol(symbol);
    return opts;
}
Also used : Entity(org.openforis.idm.model.Entity) AttributeUpdateRequest(org.openforis.collect.remoting.service.NodeUpdateRequest.AttributeUpdateRequest) Attribute(org.openforis.idm.model.Attribute) FileAttribute(org.openforis.idm.model.FileAttribute) Value(org.openforis.idm.model.Value) FileAttribute(org.openforis.idm.model.FileAttribute)

Example 18 with Attribute

use of org.openforis.idm.model.Attribute in project collect by openforis.

the class ConfirmErrorRequestProxy method toNodeUpdateRequest.

@Override
public ErrorConfirmRequest toNodeUpdateRequest(CollectRecord record) {
    ErrorConfirmRequest opts = new NodeUpdateRequest.ErrorConfirmRequest();
    Attribute<?, ?> attribute = (Attribute<?, ?>) record.getNodeByInternalId(nodeId);
    opts.setAttribute(attribute);
    return opts;
}
Also used : Attribute(org.openforis.idm.model.Attribute) ErrorConfirmRequest(org.openforis.collect.remoting.service.NodeUpdateRequest.ErrorConfirmRequest)

Example 19 with Attribute

use of org.openforis.idm.model.Attribute in project collect by openforis.

the class DefaultValueApplyRequestProxy method toNodeUpdateRequest.

@Override
public DefaultValueApplyRequest toNodeUpdateRequest(CollectRecord record) {
    DefaultValueApplyRequest opts = new NodeUpdateRequest.DefaultValueApplyRequest();
    Attribute<?, ?> attribute = (Attribute<?, ?>) record.getNodeByInternalId(nodeId);
    opts.setAttribute(attribute);
    return opts;
}
Also used : Attribute(org.openforis.idm.model.Attribute) DefaultValueApplyRequest(org.openforis.collect.remoting.service.NodeUpdateRequest.DefaultValueApplyRequest)

Example 20 with Attribute

use of org.openforis.idm.model.Attribute in project collect by openforis.

the class RemarksUpdateRequestProxy method toNodeUpdateRequest.

@Override
public RemarksUpdateRequest toNodeUpdateRequest(CollectRecord record) {
    RemarksUpdateRequest o = new NodeUpdateRequest.RemarksUpdateRequest();
    Attribute<?, ?> attribute = (Attribute<?, ?>) record.getNodeByInternalId(nodeId);
    Field<?> field = attribute.getField(fieldIndex);
    o.setField(field);
    o.setRemarks(remarks);
    return o;
}
Also used : Attribute(org.openforis.idm.model.Attribute) RemarksUpdateRequest(org.openforis.collect.remoting.service.NodeUpdateRequest.RemarksUpdateRequest)

Aggregations

Attribute (org.openforis.idm.model.Attribute)23 ArrayList (java.util.ArrayList)8 Entity (org.openforis.idm.model.Entity)8 BooleanAttribute (org.openforis.idm.model.BooleanAttribute)7 CodeAttribute (org.openforis.idm.model.CodeAttribute)7 Value (org.openforis.idm.model.Value)6 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)5 Node (org.openforis.idm.model.Node)5 Test (org.junit.Test)4 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)4 Record (org.openforis.idm.model.Record)4 TextAttribute (org.openforis.idm.model.TextAttribute)4 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 BooleanValue (org.openforis.idm.model.BooleanValue)3 NodePointer (org.openforis.idm.model.NodePointer)3 NodeVisitor (org.openforis.idm.model.NodeVisitor)3 TextValue (org.openforis.idm.model.TextValue)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 FileAttribute (org.openforis.idm.model.FileAttribute)2