Search in sources :

Example 26 with CollectAnnotations

use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.

the class CalculatedAttributeDefinitionFormObject method loadFrom.

@Override
public void loadFrom(T source, String languageCode) {
    super.loadFrom(source, languageCode);
    Type typeEnum = source.getType();
    type = typeEnum.name();
    formulas = new ArrayList<CalculatedAttributeDefinition.Formula>(source.getFormulas());
    CollectSurvey survey = (CollectSurvey) source.getSurvey();
    // show in UI
    UIOptions uiOptions = survey.getUIOptions();
    showInUI = uiOptions.isShownInUI(source);
    CollectAnnotations annotations = survey.getAnnotations();
    includeInDataExport = annotations.isIncludedInDataExport(source);
}
Also used : Formula(org.openforis.idm.metamodel.CalculatedAttributeDefinition.Formula) Type(org.openforis.idm.metamodel.CalculatedAttributeDefinition.Type) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 27 with CollectAnnotations

use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.

the class SurveyMigrator method migrate.

public void migrate(final CollectSurvey survey) {
    fixCodeListHierarchyLevelNames(survey);
    if (survey.getCollectVersion().compareTo(ENUMERATE_VERSION) < 0) {
        survey.getSchema().traverse(new NodeDefinitionVisitor() {

            public void visit(NodeDefinition defn) {
                if (defn instanceof EntityDefinition && defn.isMultiple()) {
                    EntityDefinition entityDefn = (EntityDefinition) defn;
                    UIConfiguration uiConfig = survey.getUIConfiguration();
                    if (uiConfig != null) {
                        UIModelObject uiModelObject = uiConfig.getModelObjectByNodeDefinitionId(entityDefn.getId());
                        CollectAnnotations annotations = survey.getAnnotations();
                        if (survey.getTarget() == SurveyTarget.COLLECT_EARTH || uiModelObject == null || uiModelObject instanceof UITable) {
                            if (defn.getMinCountExpression() != null) {
                                annotations.setAutoGenerateMinItems(entityDefn, true);
                            }
                            if (entityDefn.isEnumerable()) {
                                entityDefn.setEnumerate(true);
                            }
                        }
                    }
                }
            }
        });
    }
    survey.setCollectVersion(VERSION);
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UIModelObject(org.openforis.collect.metamodel.ui.UIModelObject) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) UIConfiguration(org.openforis.collect.metamodel.ui.UIConfiguration) UITable(org.openforis.collect.metamodel.ui.UITable) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor)

Example 28 with CollectAnnotations

use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.

the class RecordUpdater method isDefaultValueToBeApplied.

private boolean isDefaultValueToBeApplied(Attribute<?, ?> attr) {
    Survey survey = attr.getSurvey();
    if (survey instanceof CollectSurvey) {
        CollectAnnotations annotations = ((CollectSurvey) survey).getAnnotations();
        Step recordStep = ((CollectRecord) attr.getRecord()).getStep();
        AttributeDefinition def = attr.getDefinition();
        Step stepToApplyDefaultValue = annotations.getPhaseToApplyDefaultValue(def);
        return recordStep.compareTo(stepToApplyDefaultValue) >= 0;
    } else {
        return false;
    }
}
Also used : Survey(org.openforis.idm.metamodel.Survey) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) Step(org.openforis.collect.model.CollectRecord.Step)

Example 29 with CollectAnnotations

use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.

the class RecordUpdater method addEmptyChildren.

private int addEmptyChildren(Entity entity, NodeDefinition childDefn, int toBeInserted) {
    CollectSurvey survey = (CollectSurvey) entity.getSurvey();
    CollectAnnotations annotations = survey.getAnnotations();
    int count = 0;
    if (!childDefn.isMultiple() || annotations.isAutoGenerateMinItems(childDefn) || survey.getTarget() == SurveyTarget.COLLECT_EARTH) {
        while (count < toBeInserted) {
            if (childDefn instanceof AttributeDefinition) {
                Node<?> createdNode = childDefn.createNode();
                entity.add(createdNode);
            } else if (childDefn instanceof EntityDefinition) {
                Entity childEntity = performEntityAdd(entity, (EntityDefinition) childDefn);
                addEmptyNodes(childEntity);
            }
            count++;
        }
    }
    return count;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Entity(org.openforis.idm.model.Entity) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations)

Example 30 with CollectAnnotations

use of org.openforis.collect.metamodel.CollectAnnotations in project collect by openforis.

the class UIOptionsMigrator method createField.

protected UIField createField(UIFormContentContainer parent, NodeDefinition nodeDefn) {
    CollectSurvey survey = (CollectSurvey) nodeDefn.getSurvey();
    UIOptions uiOptions = survey.getUIOptions();
    CollectAnnotations annotations = survey.getAnnotations();
    UIField field;
    if (nodeDefn instanceof CodeAttributeDefinition) {
        UICodeField codeField = parent.createCodeField();
        CodeAttributeDefinition codeAttrDefn = (CodeAttributeDefinition) nodeDefn;
        codeField.setLayout(uiOptions.getLayoutType(codeAttrDefn));
        codeField.setShowCode(uiOptions.getShowCode(codeAttrDefn));
        codeField.setItemsOrientation(uiOptions.getLayoutDirection(codeAttrDefn));
        field = codeField;
    } else {
        field = parent.createField();
    }
    field.setAttributeDefinitionId(nodeDefn.getId());
    if (nodeDefn instanceof TextAttributeDefinition) {
        String autoCompleteGroup = annotations.getAutoCompleteGroup((TextAttributeDefinition) nodeDefn);
        field.setAutoCompleteGroup(autoCompleteGroup);
    } else if (nodeDefn instanceof CoordinateAttributeDefinition) {
        CoordinateAttributeFieldsOrder fieldsOrder = uiOptions.getFieldsOrder((CoordinateAttributeDefinition) nodeDefn);
        field.setFieldsOrder(fieldsOrder);
    }
    field.setHidden(uiOptions.isHidden(nodeDefn));
    return field;
}
Also used : CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey) CoordinateAttributeFieldsOrder(org.openforis.collect.metamodel.ui.UIOptions.CoordinateAttributeFieldsOrder)

Aggregations

CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)32 CollectSurvey (org.openforis.collect.model.CollectSurvey)21 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)11 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)7 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)7 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)6 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)6 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)5 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)5 ArrayList (java.util.ArrayList)4 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)4 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)4 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)4 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)4 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)3 NodeDefinitionVisitor (org.openforis.idm.metamodel.NodeDefinitionVisitor)3 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)3 TextInput (org.openforis.collect.metamodel.CollectAnnotations.TextInput)2 UIConfiguration (org.openforis.collect.metamodel.ui.UIConfiguration)2