Search in sources :

Example 31 with CodeListItem

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

the class SurveyViewGenerator method createCodeListItemView.

private CodeListItemView createCodeListItemView(CodeListItem item) {
    CodeListService service = item.getSurvey().getContext().getCodeListService();
    CodeListItemView itemView = new CodeListItemView();
    itemView.id = item.getId();
    itemView.code = item.getCode();
    itemView.label = item.getLabel(languageCode);
    itemView.color = item.getColor();
    List<CodeListItemView> childItemsView = new ArrayList<CodeListItemView>();
    List<CodeListItem> childItems = service.loadChildItems(item);
    for (CodeListItem childItem : childItems) {
        childItemsView.add(createCodeListItemView(childItem));
    }
    itemView.items.addAll(childItemsView);
    return itemView;
}
Also used : ArrayList(java.util.ArrayList) CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 32 with CodeListItem

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

the class EnumerableEntityColumnProvider method createProviders.

private static List<ColumnProvider> createProviders(CSVDataExportParameters config, EntityDefinition defn) {
    List<ColumnProvider> providers = new ArrayList<ColumnProvider>();
    List<AttributeDefinition> keyDefs = defn.getKeyAttributeDefinitions();
    CodeAttributeDefinition keyDef = (CodeAttributeDefinition) keyDefs.get(0);
    CodeList codeList = keyDef.getList();
    SurveyContext context = defn.getSurvey().getContext();
    CodeListService codeListService = context.getCodeListService();
    List<CodeListItem> items = codeListService.loadRootItems(codeList);
    for (CodeListItem item : items) {
        String code = item.getCode();
        String keyName = keyDef.getName();
        EnumeratedCodeItemColumnProvider p = new EnumeratedCodeItemColumnProvider(config, defn, keyName, code);
        providers.add(p);
    }
    return providers;
}
Also used : ArrayList(java.util.ArrayList) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) SurveyContext(org.openforis.idm.metamodel.SurveyContext) CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 33 with CodeListItem

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

the class CodeAttributeProxy method getCodeListItem.

@ExternalizedProperty
public CodeListItemProxy getCodeListItem() {
    if (isEnumerator()) {
        CodeListService codeListManager = getCodeListService();
        CodeListItem codeListItem = codeListManager.loadItem(codeAttribute);
        return codeListItem == null ? null : new CodeListItemProxy(codeListItem);
    } else {
        return null;
    }
}
Also used : CodeListService(org.openforis.idm.metamodel.CodeListService) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CodeListItemProxy(org.openforis.collect.metamodel.proxy.CodeListItemProxy) ExternalizedProperty(org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedProperty)

Example 34 with CodeListItem

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

the class SurveyViewGenerator method generateView.

public SurveyView generateView(final CollectSurvey survey) {
    final SurveyView surveyView = new SurveyView(survey);
    List<CodeList> codeLists = survey.getCodeLists();
    for (CodeList codeList : codeLists) {
        CodeListView codeListView = new CodeListView();
        codeListView.setId(codeList.getId());
        codeListView.setName(codeList.getName());
        codeListView.setLabel(codeList.getLabel(CodeListLabel.Type.ITEM, languageCode));
        if (includeCodeListValues && !codeList.isExternal()) {
            CodeListService service = survey.getContext().getCodeListService();
            List<CodeListItem> items = service.loadRootItems(codeList);
            for (CodeListItem item : items) {
                codeListView.addItem(createCodeListItemView(item));
            }
        }
        surveyView.addCodeList(codeListView);
    }
    final Map<Integer, NodeDefView> viewById = new HashMap<Integer, NodeDefView>();
    survey.getSchema().traverse(new NodeDefinitionVisitor() {

        public void visit(NodeDefinition def) {
            int id = def.getId();
            String name = def.getName();
            String label = getLabel(def);
            NodeDefView view;
            if (def instanceof EntityDefinition) {
                view = new EntityDefView(((EntityDefinition) def).isRoot(), id, name, label, def.isMultiple());
            } else if (def instanceof CodeAttributeDefinition) {
                CodeAttributeDefinition attrDef = (CodeAttributeDefinition) def;
                int codeListId = attrDef.getList() == null ? -1 : attrDef.getList().getId();
                view = new CodeAttributeDefView(id, name, label, AttributeType.valueOf(attrDef), attrDef.getFieldNames(), attrDef.isKey(), attrDef.isMultiple(), survey.getAnnotations().isShowInSummary(attrDef), survey.getAnnotations().isQualifier(attrDef), codeListId);
            } else {
                AttributeDefinition attrDef = (AttributeDefinition) def;
                view = new AttributeDefView(id, name, label, AttributeType.valueOf(attrDef), attrDef.getFieldNames(), attrDef.isKey(), attrDef.isMultiple(), survey.getAnnotations().isShowInSummary(attrDef), survey.getAnnotations().isQualifier(attrDef));
            }
            NodeDefinition parentDef = def.getParentDefinition();
            if (parentDef == null) {
                surveyView.getSchema().addRootEntity((EntityDefView) view);
            } else {
                EntityDefView parentView = (EntityDefView) viewById.get(parentDef.getId());
                parentView.addChild(view);
            }
            viewById.put(id, view);
        }
    });
    return surveyView;
}
Also used : HashMap(java.util.HashMap) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) CodeListService(org.openforis.idm.metamodel.CodeListService) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) NodeDefinitionVisitor(org.openforis.idm.metamodel.NodeDefinitionVisitor) CodeList(org.openforis.idm.metamodel.CodeList) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 35 with CodeListItem

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

the class CodeListManagerIntegrationTest method cascadeDeleteTest.

@Test
public void cascadeDeleteTest() {
    CodeList list = survey.getCodeList("admin_unit");
    List<CodeListItem> rootItems = codeListManager.loadItems(list, 1);
    assertEquals(8, rootItems.size());
    PersistedCodeListItem parentItem = (PersistedCodeListItem) rootItems.get(1);
    List<CodeListItem> childItems = codeListManager.loadChildItems(parentItem);
    assertEquals(3, childItems.size());
    codeListManager.delete(parentItem);
    rootItems = codeListManager.loadItems(list, 1);
    assertEquals(7, rootItems.size());
    PersistedCodeListItem fakeItem = new PersistedCodeListItem(list, parentItem.getId());
    fakeItem.setSystemId(parentItem.getSystemId());
    List<CodeListItem> reloadedItems = codeListManager.loadChildItems(fakeItem);
    assertTrue(reloadedItems.isEmpty());
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Aggregations

CodeListItem (org.openforis.idm.metamodel.CodeListItem)69 CodeList (org.openforis.idm.metamodel.CodeList)26 ArrayList (java.util.ArrayList)19 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)19 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)18 CodeListService (org.openforis.idm.metamodel.CodeListService)13 List (java.util.List)7 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 ModelVersion (org.openforis.idm.metamodel.ModelVersion)7 Test (org.junit.Test)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)5 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)5 Entity (org.openforis.idm.model.Entity)5 Record (org.openforis.idm.model.Record)5 CodeListItemProxy (org.openforis.collect.metamodel.proxy.CodeListItemProxy)4 CollectRecord (org.openforis.collect.model.CollectRecord)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 CodeAttribute (org.openforis.idm.model.CodeAttribute)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3