Search in sources :

Example 16 with PersistedCodeListItem

use of org.openforis.idm.metamodel.PersistedCodeListItem 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;
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) Code(org.openforis.idm.model.Code) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 17 with PersistedCodeListItem

use of org.openforis.idm.metamodel.PersistedCodeListItem in project collect by openforis.

the class CodeListManager method createPersistedItems.

protected List<PersistedCodeListItem> createPersistedItems(Collection<CodeListItem> items, int nextId, Integer parentItemId) {
    List<PersistedCodeListItem> result = new ArrayList<PersistedCodeListItem>();
    int sortOrder = 1;
    for (CodeListItem item : items) {
        PersistedCodeListItem persistedChildItem = PersistedCodeListItem.fromItem(item);
        persistedChildItem.setParentId(parentItemId);
        int id = nextId++;
        persistedChildItem.setSystemId(id);
        persistedChildItem.setSortOrder(sortOrder++);
        result.add(persistedChildItem);
        List<PersistedCodeListItem> temp = createPersistedItems(item.getChildItems(), nextId, id);
        nextId += temp.size();
        result.addAll(temp);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ExternalCodeListItem(org.openforis.idm.metamodel.ExternalCodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 18 with PersistedCodeListItem

use of org.openforis.idm.metamodel.PersistedCodeListItem in project collect by openforis.

the class CodeListImagesImportTask method execute.

@Override
protected void execute() throws Throwable {
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        String entryName = entry.getName();
        if (CodeListImageEntry.isValidEntry(entryName)) {
            CodeListImageEntry codeListImageEntry = CodeListImageEntry.parseEntryName(entryName);
            CodeList codeList = survey.getCodeListById(codeListImageEntry.getListId());
            if (codeList != null) {
                CodeListItem item = codeListManager.loadItem(codeList, codeListImageEntry.getItemId());
                if (item != null && item instanceof PersistedCodeListItem) {
                    byte[] content = IOUtils.toByteArray(zipFile.getInputStream(entry));
                    codeListManager.saveImageContent((PersistedCodeListItem) item, new FileWrapper(content, codeListImageEntry.getFileName()));
                } else {
                    log().warn("Error restoring code list image file : " + entry.getName());
                }
            }
        }
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) ZipEntry(java.util.zip.ZipEntry) FileWrapper(org.openforis.collect.model.FileWrapper) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem) CodeListItem(org.openforis.idm.metamodel.CodeListItem) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

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