Search in sources :

Example 1 with UIConfiguration

use of org.openforis.collect.metamodel.ui.UIConfiguration in project collect by openforis.

the class CollectSurveyIdmlBinder method onUnmarshallingComplete.

@Override
protected void onUnmarshallingComplete(Survey survey) {
    super.onUnmarshallingComplete(survey);
    CollectSurvey collectSurvey = (CollectSurvey) survey;
    CollectAnnotations annotations = collectSurvey.getAnnotations();
    collectSurvey.setTarget(annotations.getSurveyTarget());
    collectSurvey.setCollectVersion(annotations.getCollectVersion());
    if (collectSurvey.getUIOptions() != null) {
        try {
            UIConfiguration uiConfiguration = new UIOptionsMigrator().migrateToUIConfiguration(collectSurvey.getUIOptions());
            collectSurvey.setUIConfiguration(uiConfiguration);
        } catch (UIOptionsMigrationException e) {
            log.error("Error generating UI model for survey " + collectSurvey.getUri() + ": " + e.getMessage());
        } catch (Exception e) {
            log.error("Error generating UI model for survey " + collectSurvey.getUri() + ": " + e.getMessage(), e);
        }
    }
}
Also used : UIOptionsMigrator(org.openforis.collect.metamodel.ui.UIOptionsMigrator) UIConfiguration(org.openforis.collect.metamodel.ui.UIConfiguration) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey) IOException(java.io.IOException) SurveyImportException(org.openforis.collect.persistence.SurveyImportException) UIOptionsMigrationException(org.openforis.collect.metamodel.ui.UIOptionsMigrator.UIOptionsMigrationException) UIOptionsMigrationException(org.openforis.collect.metamodel.ui.UIOptionsMigrator.UIOptionsMigrationException)

Example 2 with UIConfiguration

use of org.openforis.collect.metamodel.ui.UIConfiguration 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 3 with UIConfiguration

use of org.openforis.collect.metamodel.ui.UIConfiguration in project collect by openforis.

the class CollectEarthBalloonGenerator method generateRootComponent.

private CETabSet generateRootComponent() {
    EntityDefinition rootEntityDef = getRootEntity();
    UIOptions uiOptions = survey.getUIOptions();
    UIConfiguration uiConfiguration = survey.getUIConfiguration();
    if (uiConfiguration == null) {
        // $NON-NLS-1$
        throw new IllegalStateException("Error unmarshalling the survey - no UI configruration!");
    }
    if (uiConfiguration.getFormSets().isEmpty()) {
        // no ui configuration defined
        // $NON-NLS-1$ //$NON-NLS-2$
        CETabSet tabSet = new CETabSet("", "");
        // $NON-NLS-1$
        CETab tab = new CETab(rootEntityDef.getName(), "");
        for (NodeDefinition childDef : rootEntityDef.getChildDefinitions()) {
            if (!uiOptions.isHidden(childDef)) {
                tab.addChild(createComponent(childDef));
            }
        }
        tabSet.addTab(tab);
        return tabSet;
    } else {
        // $NON-NLS-1$ //$NON-NLS-2$
        CETabSet tabSet = new CETabSet("", "");
        UIFormSet formSet = uiConfiguration.getMainFormSet();
        for (UIForm form : formSet.getForms()) {
            boolean main = tabSet.getTabs().isEmpty();
            CETab tab = createTabComponent(rootEntityDef, form, main);
            tabSet.addTab(tab);
        }
        return tabSet;
    }
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) UIConfiguration(org.openforis.collect.metamodel.ui.UIConfiguration) UIForm(org.openforis.collect.metamodel.ui.UIForm) UIFormSet(org.openforis.collect.metamodel.ui.UIFormSet)

Example 4 with UIConfiguration

use of org.openforis.collect.metamodel.ui.UIConfiguration 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

UIConfiguration (org.openforis.collect.metamodel.ui.UIConfiguration)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)3 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)2 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 UIOptionsMigrator (org.openforis.collect.metamodel.ui.UIOptionsMigrator)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)2 IOException (java.io.IOException)1 SurveyObjectsGenerator (org.openforis.collect.manager.SurveyObjectsGenerator)1 ListItem (org.openforis.collect.metamodel.SimpleSurveyCreationParameters.ListItem)1 SimpleCodeList (org.openforis.collect.metamodel.SimpleSurveyCreationParameters.SimpleCodeList)1 UIForm (org.openforis.collect.metamodel.ui.UIForm)1 UIFormSet (org.openforis.collect.metamodel.ui.UIFormSet)1 UIModelObject (org.openforis.collect.metamodel.ui.UIModelObject)1 UIOptionsMigrationException (org.openforis.collect.metamodel.ui.UIOptionsMigrator.UIOptionsMigrationException)1 UITab (org.openforis.collect.metamodel.ui.UITab)1 UITabSet (org.openforis.collect.metamodel.ui.UITabSet)1 UITable (org.openforis.collect.metamodel.ui.UITable)1 SurveyImportException (org.openforis.collect.persistence.SurveyImportException)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1