Search in sources :

Example 1 with PersistedCodeListItem

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();
        }
    }
}
Also used : OfcCodeListRecord(org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord) Record(org.jooq.Record) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 2 with PersistedCodeListItem

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);
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) BatchBindStep(org.jooq.BatchBindStep) SurveyObject(org.openforis.idm.metamodel.SurveyObject) OfcCodeListRecord(org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 3 with PersistedCodeListItem

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);
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 4 with PersistedCodeListItem

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;
}
Also used : CodeListImporter(org.openforis.idm.metamodel.xml.CodeListImporter) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 5 with PersistedCodeListItem

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);
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) GlobalCommand(org.zkoss.bind.annotation.GlobalCommand)

Aggregations

PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)18 CodeList (org.openforis.idm.metamodel.CodeList)12 CodeListItem (org.openforis.idm.metamodel.CodeListItem)8 Test (org.junit.Test)5 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)5 OfcCodeListRecord (org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord)3 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 ZipEntry (java.util.zip.ZipEntry)2 Record (org.jooq.Record)2 FileWrapper (org.openforis.collect.model.FileWrapper)2 ModelVersion (org.openforis.idm.metamodel.ModelVersion)2 Code (org.openforis.idm.model.Code)2 Record (org.openforis.idm.model.Record)2 List (java.util.List)1 BatchBindStep (org.jooq.BatchBindStep)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)1 SurveyObject (org.openforis.idm.metamodel.SurveyObject)1