Search in sources :

Example 41 with CodeListItem

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

the class CodeListsVM method reloadSelectedItems.

private void reloadSelectedItems() {
    List<CodeListItem> newItems = new ArrayList<CodeListItem>(selectedItemsPerLevel.size());
    for (CodeListItem item : selectedItemsPerLevel) {
        CodeListItem newItem = codeListManager.loadItem(item.getCodeList(), item.getId());
        newItems.add(newItem);
    }
    selectedItemsPerLevel = newItems;
    notifyChange("selectedItemsPerLevel");
}
Also used : ArrayList(java.util.ArrayList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 42 with CodeListItem

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

the class CodeListsVM method reloadSiblingsSortOrder.

/**
 * Reloads the siblings from the database.
 * The sort order of these items changes after calling codeListManager.shiftItem method.
 *
 * @param item
 */
protected void reloadSiblingsSortOrder(PersistedCodeListItem item) {
    int levelIdx = getLevelIndex(item);
    List<CodeListItem> newItems;
    if (levelIdx == 0) {
        newItems = codeListManager.loadRootItems(item.getCodeList());
    } else {
        CodeListItem parentItem = codeListManager.loadParentItem(item);
        newItems = codeListManager.loadChildItems(parentItem);
    }
    List<CodeListItem> items = itemsPerLevel.get(levelIdx);
    for (int i = 0; i < items.size(); i++) {
        CodeListItem oldItem = items.get(i);
        CodeListItem newItem = newItems.get(i);
        ((PersistedCodeListItem) oldItem).setSortOrder(((PersistedCodeListItem) newItem).getSortOrder());
    }
}
Also used : PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 43 with CodeListItem

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

the class CodeListsVM method addChildItemToCodeList.

private void addChildItemToCodeList() {
    if (editedItem.isEmpty() && isSurveyStored()) {
        // persist item in db
        PersistedCodeListItem persistedChildItem = (PersistedCodeListItem) editedChildItem;
        if (editedChildItemParentItem != null) {
            persistedChildItem.setParentId(((PersistedCodeListItem) editedChildItemParentItem).getSystemId());
        }
        codeListManager.save(persistedChildItem);
        dispatchSurveySaveCommand();
    } else if (editedChildItemParentItem == null) {
        // add item among the root items
        editedItem.addItem(editedChildItem);
    } else {
        // add item as a child of the edited parent item in the code list
        editedChildItemParentItem.addChildItem(editedChildItem);
    }
    List<CodeListItem> itemsForCurrentLevel = itemsPerLevel.get(editedChildItemLevelIndex);
    itemsForCurrentLevel.add(editedChildItem);
    deselectItemsAfterLevel(editedChildItemLevelIndex);
    selectedItemsPerLevel.add(editedChildItem);
    initItemsPerLevel();
    notifyChange("selectedItemsPerLevel");
    BindUtils.postNotifyChange(null, null, editedItem, ".");
}
Also used : PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 44 with CodeListItem

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

the class CodeListManager method loadPersistedItem.

protected PersistedCodeListItem loadPersistedItem(CodeAttribute attribute) {
    Code code = attribute.getValue();
    if (code == null || StringUtils.isBlank(code.getCode())) {
        return null;
    } else {
        String codeVal = code.getCode();
        CodeAttributeDefinition defn = attribute.getDefinition();
        CodeList list = defn.getList();
        Record record = attribute.getRecord();
        ModelVersion version = record.getVersion();
        if (StringUtils.isBlank(defn.getParentExpression())) {
            CodeListItem item = codeListItemDao.loadRootItem(list, codeVal, version);
            return (PersistedCodeListItem) item;
        } else {
            PersistedCodeListItem parentItem = (PersistedCodeListItem) loadParentItem(attribute);
            if (parentItem == null) {
                return null;
            } else {
                CodeListItem item = codeListItemDao.loadItem(list, parentItem.getSystemId(), codeVal, version);
                return (PersistedCodeListItem) item;
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) Code(org.openforis.idm.model.Code) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 45 with CodeListItem

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

the class CodeListManager method getInternalCodeListItem.

protected CodeListItem getInternalCodeListItem(CodeAttribute attribute) {
    Code code = attribute.getValue();
    if (code != null) {
        String codeValue = code.getCode();
        if (StringUtils.isNotBlank(codeValue)) {
            ModelVersion currentVersion = attribute.getRecord().getVersion();
            CodeAttributeDefinition definition = attribute.getDefinition();
            String parentExpression = definition.getParentExpression();
            if (StringUtils.isBlank(parentExpression)) {
                return getCodeListItem(definition.getList().getItems(), codeValue, currentVersion);
            } else {
                CodeAttribute codeParent = attribute.getCodeParent();
                if (codeParent != null) {
                    CodeListItem codeListItemParent = loadItemByAttribute(codeParent);
                    if (codeListItemParent != null) {
                        return getCodeListItem(codeListItemParent.getChildItems(), codeValue, currentVersion);
                    }
                }
            }
        }
    }
    return null;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CodeAttribute(org.openforis.idm.model.CodeAttribute) ModelVersion(org.openforis.idm.metamodel.ModelVersion) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) Code(org.openforis.idm.model.Code)

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