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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations