use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListItemDao method insert.
/**
* Inserts the items in batch.
*
* @param items
*/
public void insert(List<PersistedCodeListItem> items) {
if (items != null && items.size() > 0) {
PersistedCodeListItem firstItem = items.get(0);
CodeList list = firstItem.getCodeList();
JooqDSLContext jf = dsl(list);
int nextId = jf.nextId();
int maxId = nextId;
Insert<OfcCodeListRecord> query = jf.createInsertStatement();
BatchBindStep batch = jf.batch(query);
for (PersistedCodeListItem item : items) {
Integer id = item.getSystemId();
if (id == null) {
id = nextId++;
item.setSystemId(id);
}
List<Object> values = jf.extractValues(item);
batch.bind(values.toArray(new Object[values.size()]));
maxId = Math.max(maxId, id);
}
batch.execute();
jf.restartSequence(maxId + 1);
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListItemDao method shiftItem.
public void shiftItem(PersistedCodeListItem item, int toIndex) {
CodeList list = item.getCodeList();
List<PersistedCodeListItem> siblings = loadChildItems(list, item.getParentId());
int newSortOrder;
int prevItemIdx;
if (toIndex >= siblings.size()) {
prevItemIdx = siblings.size() - 1;
} else {
prevItemIdx = toIndex;
}
PersistedCodeListItem previousItem = siblings.get(prevItemIdx);
newSortOrder = previousItem.getSortOrder();
updateSortOrder(item, newSortOrder);
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class CodeListItemDao method delete.
public void delete(PersistedCodeListItem item) {
CodeList codeList = item.getCodeList();
JooqDSLContext dsl = dsl(null);
dsl.deleteQuery(item.getSystemId()).execute();
if (dsl.getDialect() == SQLDialect.SQLITE) {
// SQLite foreign keys support disabled in order to have better performances
// delete referencing items programmatically
deleteInvalidParentReferenceItems(codeList);
}
if (isCacheInUse(codeList)) {
cache.clearItemsByCodeList(codeList);
}
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class DatabaseExternalCodeListProvider method visitChildItems.
@Override
public void visitChildItems(final ExternalCodeListItem item, final Visitor<CodeListItem> visitor) {
final CodeList list = item.getCodeList();
int itemLevel = item.getLevel();
final int childrenLevel = itemLevel + 1;
if (childrenLevel > list.getHierarchy().size()) {
return;
}
List<NameValueEntry> filters = createChildItemsFilters(item);
String childrenKeyColName = getLevelKeyColumnName(list, childrenLevel);
String[] notNullColumns = new String[] { childrenKeyColName };
dynamicTableDao.visitRows(list.getLookupTable(), filters.toArray(new NameValueEntry[filters.size()]), notNullColumns, new Visitor<Map<String, String>>() {
public void visit(Map<String, String> row) {
ExternalCodeListItem item = parseRow(row, list, childrenLevel);
visitor.visit(item);
}
});
}
use of org.openforis.idm.metamodel.CodeList in project collect by openforis.
the class DatabaseExternalCodeListProvider method getItem.
@Override
public ExternalCodeListItem getItem(CodeAttribute attribute) {
CodeAttributeDefinition defn = attribute.getDefinition();
CodeList list = defn.getList();
List<NameValueEntry> filters = new ArrayList<NameValueEntry>();
addSurveyFilter(list, filters);
CodeAttribute codeParent = attribute.getCodeParent();
while (codeParent != null) {
String colName = getLevelKeyColumnName(codeParent);
String codeValue = getCodeValue(codeParent);
filters.add(new NameValueEntry(colName, codeValue));
codeParent = codeParent.getCodeParent();
}
String colName = getLevelKeyColumnName(attribute);
String codeValue = getCodeValue(attribute);
filters.add(new NameValueEntry(colName, codeValue));
int level = defn.getLevelPosition();
List<NameValueEntry> emptyNextLevelsFilters = createEmptyNextLevelFilters(list, level);
filters.addAll(emptyNextLevelsFilters);
Map<String, String> row = dynamicTableDao.loadRow(list.getLookupTable(), filters.toArray(new NameValueEntry[filters.size()]));
if (row == null) {
return null;
} else {
ExternalCodeListItem result = parseRow(row, list, level);
return result;
}
}
Aggregations