use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListItemDao method updateSortOrder.
protected void updateSortOrder(PersistedCodeListItem item, int newSortOrder) {
CodeList list = item.getCodeList();
CollectSurvey survey = (CollectSurvey) list.getSurvey();
JooqDSLContext dsl = dsl(list);
Integer oldSortOrder = item.getSortOrder();
if (newSortOrder == oldSortOrder) {
return;
} else {
// give top sort order to the item
dsl.update(OFC_CODE_LIST).set(OFC_CODE_LIST.SORT_ORDER, 0).where(OFC_CODE_LIST.ID.equal(item.getSystemId())).execute();
Condition parentIdCondition = item.getParentId() == null ? OFC_CODE_LIST.PARENT_ID.isNull() : OFC_CODE_LIST.PARENT_ID.equal(item.getParentId());
if (newSortOrder > oldSortOrder) {
// move backwards previous items
dsl.update(OFC_CODE_LIST).set(OFC_CODE_LIST.SORT_ORDER, OFC_CODE_LIST.SORT_ORDER.sub(1)).where(OFC_CODE_LIST.SURVEY_ID.equal(survey.getId()), OFC_CODE_LIST.CODE_LIST_ID.equal(list.getId()), parentIdCondition, OFC_CODE_LIST.SORT_ORDER.greaterThan(oldSortOrder), OFC_CODE_LIST.SORT_ORDER.lessOrEqual(newSortOrder)).execute();
} else {
// move forward next items
dsl.update(OFC_CODE_LIST).set(OFC_CODE_LIST.SORT_ORDER, OFC_CODE_LIST.SORT_ORDER.add(1)).where(OFC_CODE_LIST.SURVEY_ID.equal(survey.getId()), OFC_CODE_LIST.CODE_LIST_ID.equal(list.getId()), parentIdCondition, OFC_CODE_LIST.SORT_ORDER.greaterOrEqual(newSortOrder), OFC_CODE_LIST.SORT_ORDER.lessThan(oldSortOrder)).execute();
}
// set item sort order to final value
dsl.update(OFC_CODE_LIST).set(OFC_CODE_LIST.SORT_ORDER, newSortOrder).where(OFC_CODE_LIST.ID.equal(item.getSystemId())).execute();
if (isCacheInUse(list)) {
cache.clearItemsByCodeList(list);
}
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListItemDao method removeLabels.
public void removeLabels(CollectSurvey survey, int fromLanguagePosition) {
JooqDSLContext jf = dsl(null);
List<CodeList> codeLists = survey.getCodeLists();
for (CodeList codeList : codeLists) {
int codeListId = codeList.getId();
Map<TableField<OfcCodeListRecord, String>, String> updateFields = new HashMap<TableField<OfcCodeListRecord, String>, String>();
for (int i = fromLanguagePosition - 1; i < LABEL_FIELDS.length; i++) {
@SuppressWarnings("unchecked") TableField<OfcCodeListRecord, String> labelField = LABEL_FIELDS[i];
updateFields.put(labelField, (String) null);
}
jf.update(OFC_CODE_LIST).set(updateFields).where(OFC_CODE_LIST.SURVEY_ID.eq(survey.getId()).and(OFC_CODE_LIST.CODE_LIST_ID.eq(codeListId))).execute();
if (isCacheInUse(codeList)) {
cache.clearItemsByCodeList(codeList);
}
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class DatabaseExternalCodeListProvider method createChildItemsFilters.
protected List<NameValueEntry> createChildItemsFilters(ExternalCodeListItem item) {
List<NameValueEntry> filters = new ArrayList<NameValueEntry>();
CodeList list = item.getCodeList();
Collection<NameValueEntry> parentKeys = getParentKeys(item);
filters.addAll(parentKeys);
addSurveyFilter(list, filters);
int itemLevel = item.getLevel();
int childrenLevel = itemLevel + 1;
String itemKeyColName = getLevelKeyColumnName(list, itemLevel);
filters.add(new NameValueEntry(itemKeyColName, item.getCode()));
List<NameValueEntry> emptyNextLevelsFilters = createEmptyNextLevelFilters(list, childrenLevel);
filters.addAll(emptyNextLevelsFilters);
return filters;
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class DatabaseExternalCodeListProvider method getParentItem.
public ExternalCodeListItem getParentItem(ExternalCodeListItem item) {
List<NameValueEntry> filters = new ArrayList<NameValueEntry>();
CodeList list = item.getCodeList();
Collection<NameValueEntry> parentKeys = getParentKeys(item);
filters.addAll(parentKeys);
addSurveyFilter(list, filters);
int level = parentKeys.size() + 1;
int parentLevel = level - 1;
List<NameValueEntry> emptyNextLevelsFilters = createEmptyNextLevelFilters(list, parentLevel);
filters.addAll(emptyNextLevelsFilters);
Map<String, String> row = dynamicTableDao.loadRow(list.getLookupTable(), filters.toArray(new NameValueEntry[0]));
return parseRow(row, list, parentLevel);
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class DatabaseExternalCodeListProvider method getChildItems.
@Override
public List<ExternalCodeListItem> getChildItems(ExternalCodeListItem item) {
CodeList list = item.getCodeList();
int itemLevel = item.getLevel();
int childrenLevel = itemLevel + 1;
if (childrenLevel > list.getHierarchy().size()) {
return Collections.emptyList();
}
List<NameValueEntry> filters = createChildItemsFilters(item);
String childrenKeyColName = getLevelKeyColumnName(list, childrenLevel);
String[] notNullColumns = new String[] { childrenKeyColName };
List<Map<String, String>> rows = dynamicTableDao.loadRows(list.getLookupTable(), filters.toArray(new NameValueEntry[filters.size()]), notNullColumns);
List<ExternalCodeListItem> result = new ArrayList<ExternalCodeListItem>();
for (Map<String, String> row : rows) {
ExternalCodeListItem child = parseRow(row, list, childrenLevel);
result.add(child);
}
return result;
}
Aggregations