Search in sources :

Example 21 with AttributeDefinition

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;
}
Also used : Attribute(org.openforis.idm.model.Attribute) Value(org.openforis.idm.model.Value) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 22 with AttributeDefinition

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);
    }
}
Also used : Window(org.zkoss.zul.Window) AttributeType(org.openforis.collect.designer.metamodel.AttributeType) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) Command(org.zkoss.bind.annotation.Command)

Example 23 with AttributeDefinition

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));
        }
    }
}
Also used : AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Example 24 with AttributeDefinition

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()));
            }
        }
    }
}
Also used : SurveyValidationResult(org.openforis.collect.manager.validation.SurveyValidator.SurveyValidationResult) SurveyValidator(org.openforis.collect.manager.validation.SurveyValidator) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 25 with AttributeDefinition

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);
        }
    }
}
Also used : KeyAttributeDefinition(org.openforis.idm.metamodel.KeyAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8