use of org.openforis.idm.metamodel.PersistedCodeListItem in project collect by openforis.
the class CodeListItemDao method visitChildItems.
public void visitChildItems(CodeList list, Integer parentItemId, Visitor<CodeListItem> visitor, ModelVersion version) {
JooqDSLContext dsl = dsl(list);
SelectQuery<Record> q = createSelectChildItemsQuery(dsl, list, parentItemId, true);
Cursor<Record> cursor = null;
try {
cursor = q.fetchLazy();
while (cursor.hasNext()) {
Record r = cursor.fetchOne();
PersistedCodeListItem item = dsl.fromRecord(r);
if (version == null || version.isApplicable(item)) {
visitor.visit(item);
visitChildItems(list, item.getSystemId(), visitor, version);
}
}
} finally {
if (cursor != null) {
cursor.close();
}
}
}
use of org.openforis.idm.metamodel.PersistedCodeListItem 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.PersistedCodeListItem 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.PersistedCodeListItem in project collect by openforis.
the class CodeListItemPersisterPR method persistItem.
protected void persistItem() {
CodeListImporter binder = getImporter();
PersistedCodeListItem persistedItem = (PersistedCodeListItem) item;
persistedItem.setSystemId(binder.nextItemId());
persistedItem.setSortOrder(calculateSortOrder());
if (parentItem != null) {
int parentId = ((PersistedCodeListItem) parentItem).getSystemId();
persistedItem.setParentId(parentId);
}
binder.persistItem(persistedItem);
itemPersisted = true;
}
use of org.openforis.idm.metamodel.PersistedCodeListItem in project collect by openforis.
the class CodeListsVM method closeCodeListItemPopUp.
@GlobalCommand
public void closeCodeListItemPopUp(@BindingParam("undoChanges") boolean undoChanges, @BindingParam("imageModified") boolean imageModified, @BindingParam("imageFileWrapper") FileWrapper imageFileWrapper) {
if (codeListItemPopUp == null) {
// handling code list from node editor form?
return;
}
closePopUp(codeListItemPopUp);
codeListItemPopUp = null;
if (undoChanges) {
dispatchCurrentFormValidatedCommand(true);
} else {
if (newChildItem) {
addChildItemToCodeList();
} else {
dispatchSurveySaveCommand();
if (editedChildItem instanceof PersistedCodeListItem) {
codeListManager.save((PersistedCodeListItem) editedChildItem);
}
BindUtils.postNotifyChange(null, null, editedChildItem, "*");
}
if (imageModified) {
PersistedCodeListItem persistedItem;
if (editedChildItem instanceof PersistedCodeListItem) {
persistedItem = (PersistedCodeListItem) editedChildItem;
} else {
CodeList codeList = editedChildItem.getCodeList();
codeListManager.persistCodeListItems(codeList);
reloadSelectedItems();
initItemsPerLevel();
persistedItem = codeListManager.loadItem(codeList, editedChildItem.getId());
}
if (imageFileWrapper == null) {
codeListManager.deleteImageContent(persistedItem);
} else {
codeListManager.saveImageContent(persistedItem, imageFileWrapper);
}
}
}
}
Aggregations