use of org.openforis.idm.model.Attribute in project collect by openforis.
the class RecordIndexManager method index.
protected void index(final IndexWriter indexWriter, CollectRecord record) throws RecordIndexException {
try {
Entity rootEntity = record.getRootEntity();
rootEntity.traverse(new NodeVisitor() {
@Override
public void visit(Node<? extends NodeDefinition> node, int idx) {
NodeDefinition defn = node.getDefinition();
if (defn instanceof AttributeDefinition) {
index(indexWriter, (Attribute<?, ?>) node);
}
}
});
} catch (Exception e) {
throw new RecordIndexException(e);
}
}
use of org.openforis.idm.model.Attribute in project collect by openforis.
the class RecordUpdater method recalculateDependentCalculatedAttributes.
private List<Attribute<?, ?>> recalculateDependentCalculatedAttributes(Node<?> node) {
Record record = node.getRecord();
List<Attribute<?, ?>> attributesToRecalculate = record.determineCalculatedAttributes(node);
return recalculateValues(attributesToRecalculate);
}
use of org.openforis.idm.model.Attribute in project collect by openforis.
the class RecordUpdater method applyInitialValues.
private List<Attribute<?, ?>> applyInitialValues(Entity entity) {
final List<Attribute<?, ?>> updatedAttributes = new ArrayList<Attribute<?, ?>>();
entity.traverse(new NodeVisitor() {
public void visit(Node<?> node, int idx) {
if (node instanceof Attribute && node.isEmpty()) {
Attribute<?, ?> attr = (Attribute<?, ?>) node;
Value value = applyInitialValue(attr);
if (value != null) {
updatedAttributes.add(attr);
}
}
}
});
return updatedAttributes;
}
use of org.openforis.idm.model.Attribute in project collect by openforis.
the class RecordUpdater method recalculateValues.
@SuppressWarnings({ "rawtypes", "unchecked" })
private List<Attribute<?, ?>> recalculateValues(List<Attribute<?, ?>> attributesToRecalculate) {
List<Attribute<?, ?>> updatedAttributes = new ArrayList<Attribute<?, ?>>();
for (Attribute calcAttr : attributesToRecalculate) {
Value previousValue = calcAttr.getValue();
Value newValue = recalculateValue(calcAttr);
if (!((previousValue == newValue) || (previousValue != null && previousValue.equals(newValue)))) {
calcAttr.setValue(newValue);
calcAttr.updateSummaryInfo();
updatedAttributes.add(calcAttr);
}
}
return updatedAttributes;
}
use of org.openforis.idm.model.Attribute in project collect by openforis.
the class RecordUpdater method afterAttributeInsertOrUpdate.
private NodeChangeSet afterAttributeInsertOrUpdate(NodeChangeMap changeMap, Attribute<?, ?> attribute) {
attribute.updateSummaryInfo();
Record record = attribute.getRecord();
NodePointer attributeNodePointer = new NodePointer(attribute);
List<Attribute<?, ?>> updatedAttributes = new ArrayList<Attribute<?, ?>>();
// calculated attributes
List<Attribute<?, ?>> updatedCalculatedAttributes = recalculateDependentCalculatedAttributes(attribute);
updatedAttributes.addAll(updatedCalculatedAttributes);
changeMap.addValueChanges(updatedCalculatedAttributes);
// dependent code attributes
if (attribute instanceof CodeAttribute && clearDependentCodeAttributes) {
Set<CodeAttribute> updatedCodeAttributes = clearDependentCodeAttributes(attribute);
updatedAttributes.addAll(updatedCodeAttributes);
changeMap.addValueChanges(updatedCodeAttributes);
}
if (validateAfterUpdate) {
// relevance
Collection<Node<?>> nodesToCheckRelevanceFor = new ArrayList<Node<?>>(updatedAttributes);
nodesToCheckRelevanceFor.add(attribute);
List<NodePointer> relevanceToUpdate = record.determineRelevanceDependentNodes(nodesToCheckRelevanceFor);
RelevanceUpdater relevanceUpdater = new RelevanceUpdater(relevanceToUpdate);
Set<NodePointer> updatedRelevancePointers = relevanceUpdater.update();
Set<Node<?>> updatedRelevanceNodes = pointersToNodes(updatedRelevancePointers);
// apply default values to relevant nodes (if not applied yet)
for (Node<?> updatedRelevanceNode : updatedRelevanceNodes) {
if (updatedRelevanceNode instanceof Attribute) {
Attribute<?, ?> updatedRelevanceAttr = (Attribute<?, ?>) updatedRelevanceNode;
if (!updatedRelevanceAttr.getDefinition().isCalculated()) {
if (updatedRelevanceAttr.isEmpty() || isDefaultValueApplied(updatedRelevanceAttr)) {
Value appliedValue = applyInitialValue(updatedRelevanceAttr);
if (appliedValue != null) {
updatedAttributes.add((Attribute<?, ?>) updatedRelevanceNode);
}
}
}
}
}
changeMap.addRelevanceChanges(updatedRelevancePointers);
if (clearNotRelevantAttributes) {
Set<Attribute<?, ?>> noMoreRelevantAttributes = retainNotRelevantAttributes(updatedRelevanceNodes);
Set<Attribute<?, ?>> clearedAttributes = clearUserSpecifiedAttributes(noMoreRelevantAttributes);
updatedAttributes.addAll(clearedAttributes);
changeMap.addValueChanges(clearedAttributes);
}
// min count
Collection<NodePointer> pointersToCheckMinCountFor = new HashSet<NodePointer>(updatedRelevancePointers);
pointersToCheckMinCountFor.add(attributeNodePointer);
pointersToCheckMinCountFor.addAll(nodesToPointers(updatedAttributes));
Collection<NodePointer> minCountPointersToUpdate = record.determineMinCountDependentNodes(pointersToCheckMinCountFor);
Collection<NodePointer> updatedMinCountPointers = updateMinCount(minCountPointersToUpdate);
changeMap.addMinCountChanges(updatedMinCountPointers);
// max count
Collection<NodePointer> pointersToCheckMaxCountFor = new HashSet<NodePointer>(updatedRelevancePointers);
pointersToCheckMaxCountFor.add(attributeNodePointer);
pointersToCheckMaxCountFor.addAll(nodesToPointers(updatedAttributes));
Collection<NodePointer> maxCountPointersToUpdate = record.determineMaxCountDependentNodes(pointersToCheckMaxCountFor);
Collection<NodePointer> updatedMaxCountPointers = updateMaxCount(maxCountPointersToUpdate);
changeMap.addMaxCountChanges(updatedMaxCountPointers);
Set<NodePointer> updatedCardinalityPointers = new HashSet<NodePointer>(updatedMinCountPointers);
updatedCardinalityPointers.addAll(updatedMaxCountPointers);
// validate cardinality
List<NodePointer> ancestorsAndSelfPointers = getAncestorsAndSelfPointers(attribute);
Set<NodePointer> pointersToValidateCardinalityFor = new HashSet<NodePointer>(updatedMinCountPointers.size() + updatedMaxCountPointers.size() + updatedRelevancePointers.size() + ancestorsAndSelfPointers.size());
pointersToValidateCardinalityFor.addAll(nodesToPointers(updatedAttributes));
pointersToValidateCardinalityFor.addAll(updatedMinCountPointers);
pointersToValidateCardinalityFor.addAll(updatedMaxCountPointers);
pointersToValidateCardinalityFor.addAll(updatedRelevancePointers);
// validate cardinality on ancestor node pointers because we are considering empty nodes as missing nodes
pointersToValidateCardinalityFor.addAll(ancestorsAndSelfPointers);
validateCardinality(record, pointersToValidateCardinalityFor, changeMap);
// validate attributes
Set<Node<?>> nodesToCheckValidationFor = new HashSet<Node<?>>(updatedAttributes);
nodesToCheckValidationFor.add(attribute);
nodesToCheckValidationFor.addAll(updatedRelevanceNodes);
nodesToCheckValidationFor.addAll(pointersToNodes(updatedCardinalityPointers));
Set<Attribute<?, ?>> attributesToRevalidate = record.determineValidationDependentNodes(nodesToCheckValidationFor);
validateAttributes(record, attributesToRevalidate, changeMap);
}
return changeMap;
}
Aggregations