use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class NodeBuilder method createAttribute.
private Attribute<?, ?> createAttribute(Entity parent) {
AttributeDefinition def = (AttributeDefinition) parent.getDefinition().getChildDefinition(name);
@SuppressWarnings("unchecked") Attribute<?, Value> attr = (Attribute<?, Value>) def.createNode();
if (value != null) {
if (value instanceof Value) {
attr.setValue((Value) value);
} else {
attr.setValue(def.<Value>createValue(value.toString()));
}
attr.updateSummaryInfo();
}
return attr;
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class AttributeConversionVM method convert.
@Command
public void convert(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
if (validateForm(ctx)) {
String typeLabel = form.get("type");
AttributeType type = AttributeType.fromLabel(typeLabel);
AttributeDefinition convertedAttribute = new AttributeConverter().convert(attributeDefinition, type);
dispatchNodeConvertedCommand(convertedAttribute);
Window popUp = ComponentUtil.getClosest(ctx.getComponent(), Window.class);
closePopUp(popUp);
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class AttributeDefaultFormValidator method validateValue.
private void validateValue(ValidationContext ctx) {
String value = getValue(ctx, VALUE_FIELD);
String expression = getValue(ctx, EXPRESSION_FIELD);
if (StringUtils.isBlank(value) && StringUtils.isBlank(expression)) {
addInvalidMessage(ctx, VALUE_FIELD, Labels.getLabel(VALUE_OR_EXPRESSION_REQUIRED_MESSAGE_KEY));
} else if (StringUtils.isNotBlank(value) && StringUtils.isNotBlank(expression)) {
addInvalidMessage(ctx, VALUE_FIELD, Labels.getLabel(CANNOT_SPECIFY_BOTH_VALUE_AND_EXPRESSION_MESSAGE_KEY));
} else if (StringUtils.isNotBlank(value)) {
AttributeDefinition contextNode = (AttributeDefinition) getContextNode(ctx);
try {
contextNode.createValue(value);
} catch (Exception e) {
addInvalidMessage(ctx, VALUE_FIELD, Labels.getLabel(INVALID_EXPRESSION_MESSAGE_KEY));
}
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class AttributeDefinitionFormValidator method validateReferencedAttribute.
private void validateReferencedAttribute(ValidationContext ctx) {
String referencedAttributePath = getValue(ctx, REFERENCED_ATTRIBUTE_PATH_FIELD, false);
if (StringUtils.isNotBlank(referencedAttributePath)) {
AttributeDefinition attrDef = (AttributeDefinition) getEditedNode(ctx);
CollectSurvey survey = attrDef.getSurvey();
AttributeDefinition referencedAttribute = (AttributeDefinition) survey.getSchema().getDefinitionByPath(referencedAttributePath);
if (referencedAttribute == null) {
addInvalidMessage(ctx, REFERENCED_ATTRIBUTE_PATH_FIELD, Labels.getLabel(REFERENCED_ATTRIBUTE_DELETED_MESSAGE_KEY));
} else {
SurveyValidationResult validationResult = new SurveyValidator().validateReferencedKeyAttribute(attrDef, referencedAttribute);
if (validationResult.getFlag() == Flag.ERROR) {
addInvalidMessage(ctx, REFERENCED_ATTRIBUTE_PATH_FIELD, Labels.getLabel(validationResult.getMessageKey(), validationResult.getMessageArgs()));
}
}
}
}
use of org.openforis.idm.metamodel.AttributeDefinition in project collect by openforis.
the class Validator method validateAttributeChecks.
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void validateAttributeChecks(Attribute<?, ?> attribute, ValidationResults results) {
AttributeDefinition defn = attribute.getDefinition();
List<Check<?>> checks = defn.getChecks();
for (Check check : checks) {
if (check.evaluateCondition(attribute)) {
ValidationResultFlag result = check.evaluate(attribute);
results.addResult(check, result);
}
}
}
Aggregations