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");
}
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());
}
}
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, ".");
}
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;
}
}
}
}
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;
}
Aggregations