Search in sources :

Example 1 with TextAttributeDefinition

use of org.openforis.idm.metamodel.TextAttributeDefinition in project collect by openforis.

the class NodeDefinitionProxy method fromList.

static List<NodeDefinitionProxy> fromList(EntityDefinitionProxy parent, List<? extends NodeDefinition> list) {
    List<NodeDefinitionProxy> proxies = new ArrayList<NodeDefinitionProxy>();
    if (list != null) {
        for (NodeDefinition n : list) {
            NodeDefinitionProxy p = null;
            CollectSurvey survey = (CollectSurvey) n.getSurvey();
            UIOptions uiOptions = survey.getUIOptions();
            boolean hidden = uiOptions.isHidden(n);
            if (!hidden) {
                if (n instanceof AttributeDefinition) {
                    if (n instanceof BooleanAttributeDefinition) {
                        p = new BooleanAttributeDefinitionProxy(parent, (BooleanAttributeDefinition) n);
                    } else if (n instanceof CodeAttributeDefinition) {
                        p = new CodeAttributeDefinitionProxy(parent, (CodeAttributeDefinition) n);
                    } else if (n instanceof CoordinateAttributeDefinition) {
                        p = new CoordinateAttributeDefinitionProxy(parent, (CoordinateAttributeDefinition) n);
                    } else if (n instanceof DateAttributeDefinition) {
                        p = new DateAttributeDefinitionProxy(parent, (DateAttributeDefinition) n);
                    } else if (n instanceof FileAttributeDefinition) {
                        p = new FileAttributeDefinitionProxy(parent, (FileAttributeDefinition) n);
                    } else if (n instanceof NumberAttributeDefinition) {
                        p = new NumberAttributeDefinitionProxy(parent, (NumberAttributeDefinition) n);
                    } else if (n instanceof RangeAttributeDefinition) {
                        p = new RangeAttributeDefinitionProxy(parent, (RangeAttributeDefinition) n);
                    } else if (n instanceof TaxonAttributeDefinition) {
                        p = new TaxonAttributeDefinitionProxy(parent, (TaxonAttributeDefinition) n);
                    } else if (n instanceof TextAttributeDefinition) {
                        p = new TextAttributeDefinitionProxy(parent, (TextAttributeDefinition) n);
                    } else if (n instanceof TimeAttributeDefinition) {
                        p = new TimeAttributeDefinitionProxy(parent, (TimeAttributeDefinition) n);
                    } else {
                        throw new RuntimeException("AttributeDefinition not supported: " + n.getClass().getSimpleName());
                    }
                } else if (n instanceof EntityDefinition) {
                    p = new EntityDefinitionProxy(parent, (EntityDefinition) n);
                }
                if (p != null) {
                    proxies.add(p);
                }
            }
        }
    }
    return proxies;
}
Also used : TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) ArrayList(java.util.ArrayList) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) TaxonAttributeDefinition(org.openforis.idm.metamodel.TaxonAttributeDefinition) DateAttributeDefinition(org.openforis.idm.metamodel.DateAttributeDefinition) CoordinateAttributeDefinition(org.openforis.idm.metamodel.CoordinateAttributeDefinition) BooleanAttributeDefinition(org.openforis.idm.metamodel.BooleanAttributeDefinition) FileAttributeDefinition(org.openforis.idm.metamodel.FileAttributeDefinition) TimeAttributeDefinition(org.openforis.idm.metamodel.TimeAttributeDefinition) NumberAttributeDefinition(org.openforis.idm.metamodel.NumberAttributeDefinition) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) RangeAttributeDefinition(org.openforis.idm.metamodel.RangeAttributeDefinition)

Example 2 with TextAttributeDefinition

use of org.openforis.idm.metamodel.TextAttributeDefinition in project collect by openforis.

the class TextAttributeDefinitionPR method onStartDefinition.

@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
    super.onStartDefinition();
    String typeStr = getAttribute(TYPE, false);
    TextAttributeDefinition defn = (TextAttributeDefinition) getDefinition();
    try {
        defn.setType(typeStr == null ? Type.SHORT : Type.valueOf(typeStr.toUpperCase()));
    } catch (IllegalArgumentException e) {
        throw new XmlParseException(getParser(), "invalid type " + typeStr);
    }
}
Also used : TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) XmlParseException(org.openforis.idm.metamodel.xml.XmlParseException)

Example 3 with TextAttributeDefinition

use of org.openforis.idm.metamodel.TextAttributeDefinition 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)

Example 4 with TextAttributeDefinition

use of org.openforis.idm.metamodel.TextAttributeDefinition in project collect by openforis.

the class SurveyCreator method createTemporarySimpleSurvey.

private CollectSurvey createTemporarySimpleSurvey(String name, List<SimpleCodeList> simpleCodeLists) {
    CollectSurvey survey = surveyManager.createTemporarySurvey(name, languageCode);
    for (int codeListIdx = 0; codeListIdx < simpleCodeLists.size(); codeListIdx++) {
        SimpleCodeList simpleCodeList = simpleCodeLists.get(codeListIdx);
        CodeList codeList = survey.createCodeList();
        codeList.setName("values_" + (codeListIdx + 1));
        codeList.setLabel(CodeListLabel.Type.ITEM, survey.getDefaultLanguage(), simpleCodeList.getName());
        List<ListItem> items = simpleCodeList.getItems();
        for (int itemIdx = 0; itemIdx < items.size(); itemIdx++) {
            ListItem paramItem = items.get(itemIdx);
            CodeListItem item = codeList.createItem(1);
            // specified code or item index
            item.setCode(ObjectUtils.defaultIfNull(paramItem.getCode(), String.valueOf(itemIdx + 1)));
            item.setLabel(languageCode, paramItem.getLabel());
            item.setColor(paramItem.getColor());
            codeList.addItem(item);
        }
        survey.addCodeList(codeList);
    }
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDef = schema.createEntityDefinition();
    rootEntityDef.setName(singleAttributeSurveyRootEntityName);
    schema.addRootEntityDefinition(rootEntityDef);
    CodeAttributeDefinition idAttrDef = schema.createCodeAttributeDefinition();
    idAttrDef.setName(singleAttributeSurveyKeyAttributeName);
    idAttrDef.setKey(true);
    idAttrDef.setList(survey.getSamplingDesignCodeList());
    rootEntityDef.addChildDefinition(idAttrDef);
    TextAttributeDefinition operatorAttrDef = schema.createTextAttributeDefinition();
    operatorAttrDef.setName(singleAttributeSurveyOperatorAttributeName);
    operatorAttrDef.setKey(true);
    operatorAttrDef.setLabel(Type.INSTANCE, languageCode, singleAttributeSurveyOperatorAttributeLabel);
    survey.getAnnotations().setMeasurementAttribute(operatorAttrDef, true);
    rootEntityDef.addChildDefinition(operatorAttrDef);
    EntityDefinition secondLevelEntityDef = schema.createEntityDefinition();
    secondLevelEntityDef.setName(singleAttributeSurveySecondLevelEntityName);
    secondLevelEntityDef.setMultiple(true);
    rootEntityDef.addChildDefinition(secondLevelEntityDef);
    CodeAttributeDefinition secondLevelIdAttrDef = schema.createCodeAttributeDefinition();
    secondLevelIdAttrDef.setName(singleAttributeSurveySecondLevelIdAttributeName);
    secondLevelIdAttrDef.setKey(true);
    secondLevelIdAttrDef.setList(survey.getSamplingDesignCodeList());
    secondLevelIdAttrDef.setParentCodeAttributeDefinition(idAttrDef);
    secondLevelEntityDef.addChildDefinition(secondLevelIdAttrDef);
    for (int i = 0; i < simpleCodeLists.size(); i++) {
        String codeListName = "values_" + (i + 1);
        CodeList codeList = survey.getCodeList(codeListName);
        CodeAttributeDefinition valueAttrDef = schema.createCodeAttributeDefinition();
        valueAttrDef.setName(codeListName);
        valueAttrDef.setList(codeList);
        secondLevelEntityDef.addChildDefinition(valueAttrDef);
    }
    // create root tab set
    UIOptions uiOptions = survey.getUIOptions();
    UITabSet rootTabSet = uiOptions.createRootTabSet((EntityDefinition) rootEntityDef);
    UITab mainTab = uiOptions.getMainTab(rootTabSet);
    mainTab.setLabel(languageCode, singleAttributeSurveyTabLabel);
    UIConfiguration uiConfiguration = new UIOptionsMigrator().migrateToUIConfiguration(uiOptions);
    survey.setUIConfiguration(uiConfiguration);
    SurveyObjectsGenerator surveyObjectsGenerator = new SurveyObjectsGenerator();
    surveyObjectsGenerator.addPredefinedObjects(survey);
    if (survey.getSamplingDesignCodeList() == null) {
        survey.addSamplingDesignCodeList();
    }
    return survey;
}
Also used : Schema(org.openforis.idm.metamodel.Schema) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) UITabSet(org.openforis.collect.metamodel.ui.UITabSet) SurveyObjectsGenerator(org.openforis.collect.manager.SurveyObjectsGenerator) UIOptionsMigrator(org.openforis.collect.metamodel.ui.UIOptionsMigrator) UIConfiguration(org.openforis.collect.metamodel.ui.UIConfiguration) SimpleCodeList(org.openforis.collect.metamodel.SimpleSurveyCreationParameters.SimpleCodeList) SimpleCodeList(org.openforis.collect.metamodel.SimpleSurveyCreationParameters.SimpleCodeList) CodeList(org.openforis.idm.metamodel.CodeList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UITab(org.openforis.collect.metamodel.ui.UITab) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) TextAttributeDefinition(org.openforis.idm.metamodel.TextAttributeDefinition) ListItem(org.openforis.collect.metamodel.SimpleSurveyCreationParameters.ListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Aggregations

TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)4 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)3 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)2 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)2 ArrayList (java.util.ArrayList)1 SurveyObjectsGenerator (org.openforis.collect.manager.SurveyObjectsGenerator)1 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)1 ListItem (org.openforis.collect.metamodel.SimpleSurveyCreationParameters.ListItem)1 SimpleCodeList (org.openforis.collect.metamodel.SimpleSurveyCreationParameters.SimpleCodeList)1 UIConfiguration (org.openforis.collect.metamodel.ui.UIConfiguration)1 CoordinateAttributeFieldsOrder (org.openforis.collect.metamodel.ui.UIOptions.CoordinateAttributeFieldsOrder)1 UIOptionsMigrator (org.openforis.collect.metamodel.ui.UIOptionsMigrator)1 UITab (org.openforis.collect.metamodel.ui.UITab)1 UITabSet (org.openforis.collect.metamodel.ui.UITabSet)1 AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)1 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)1 CodeList (org.openforis.idm.metamodel.CodeList)1 CodeListItem (org.openforis.idm.metamodel.CodeListItem)1