use of org.openforis.idm.model.Value in project collect by openforis.
the class UniquenessCheck method evaluate.
@Override
public ValidationResultFlag evaluate(final Attribute<?, ?> attribute) {
try {
SurveyContext recordContext = attribute.getRecord().getSurveyContext();
ExpressionEvaluator expressionEvaluator = recordContext.getExpressionEvaluator();
Node<?> duplicateNode = expressionEvaluator.findNode(attribute.getParent(), attribute, expression, new Predicate<Node<?>>() {
public boolean evaluate(Node<?> node) {
if (node instanceof Attribute && node != attribute) {
Value value = ((Attribute<?, ?>) node).getValue();
if (value != null && value.equals(attribute.getValue())) {
return true;
}
}
return false;
}
});
boolean unique = duplicateNode == null;
return ValidationResultFlag.valueOf(unique, this.getFlag());
} catch (InvalidExpressionException e) {
throw new IdmInterpretationError("Error evaluating uniqueness check", e);
}
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class ModelRelationalExpression method getValue.
private Object getValue(Object object) {
if (object instanceof Number || object instanceof NumericRange || object instanceof String) {
return object;
}
if (object instanceof Boolean) {
return ((Boolean) object).booleanValue() ? 0.0 : 1.0;
} else if (object instanceof Value) {
return AttributeValueUtils.extractMainFieldValue((Value) object, normalizeNumbers);
}
if (object instanceof NodePointer) {
if (object instanceof VariablePointer && normalizeNumbers) {
ModelNodePointer valuePointer = (ModelNodePointer) ((NodePointer) object).getValuePointer();
valuePointer.setNormalizeNumbers(true);
}
return getValue(((NodePointer) object).getValue());
}
if (object instanceof EvalContext) {
EvalContext ctx = (EvalContext) object;
Pointer ptr = ctx.getSingleNodePointer();
return ptr == null ? Double.NaN : getValue(ptr);
}
return null;
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class RecordGenerator method setRecordKeyValues.
private void setRecordKeyValues(CollectRecord record, RecordKey recordKey) {
CollectSurvey survey = (CollectSurvey) record.getSurvey();
List<AttributeDefinition> keyAttributeDefs = survey.getSchema().getFirstRootEntityDefinition().getKeyAttributeDefinitions();
for (AttributeDefinition keyAttrDef : keyAttributeDefs) {
String keyPart = recordKey.getValue(keyAttrDef.getPath());
Attribute<?, Value> keyAttribute = record.findNodeByPath(keyAttrDef.getPath());
Value value = keyAttrDef.createValue(keyPart);
recordUpdater.updateAttribute(keyAttribute, value);
}
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class RecordManager method addQualifierValues.
private void addQualifierValues(CollectRecord record, User user) {
if (userGroupManager == null) {
return;
}
NodeChangeMap changeSet = new NodeChangeMap();
CollectSurvey survey = (CollectSurvey) record.getSurvey();
UserGroup surveyUserGrup = survey.getUserGroup();
UserInGroup userInGroup = userGroupManager.findUserInGroupOrDescendants(surveyUserGrup, user);
if (userInGroup == null) {
throw new IllegalArgumentException(String.format("User %s is not allowed to create records for survey %s", user.getUsername(), survey.getName()));
}
UserGroup group = userGroupManager.loadById(userInGroup.getGroupId());
Map<String, String> qualifiersByName = group.getQualifiersByName();
for (Entry<String, String> qualifier : qualifiersByName.entrySet()) {
String attributePath = record.getRootEntity().getName() + "/" + qualifier.getKey();
Attribute<?, Value> attribute = record.findNodeByPath(attributePath);
Value qualifierValue = attribute.getDefinition().createValue(qualifier.getValue());
NodeChangeSet changes = updater.updateAttribute(attribute, qualifierValue);
changeSet.addMergeChanges(changes);
}
}
use of org.openforis.idm.model.Value in project collect by openforis.
the class RecordUpdater method applyInitialValue.
private Value applyInitialValue(Attribute<?, ?> attr) {
Value value = null;
if (!attr.getDefinition().isCalculated()) {
if (attr.isEmpty() && isDefaultValueToBeApplied(attr)) {
value = performDefaultValueApply(attr);
}
if (attr instanceof BooleanAttribute && ((BooleanAttributeDefinition) attr.getDefinition()).isAffirmativeOnly() && attr.isEmpty()) {
BooleanAttribute boolAttr = (BooleanAttribute) attr;
value = new BooleanValue(false);
boolAttr.setValue((BooleanValue) value);
boolAttr.updateSummaryInfo();
}
}
return value;
}
Aggregations