Search in sources :

Example 1 with FileWrapper

use of org.openforis.collect.model.FileWrapper in project collect by openforis.

the class CodeListItemVM method onImageUpload.

@Command("imageUpload")
public void onImageUpload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
    UploadEvent upEvent = null;
    Object objUploadEvent = ctx.getTriggerEvent();
    if (objUploadEvent != null && (objUploadEvent instanceof UploadEvent)) {
        upEvent = (UploadEvent) objUploadEvent;
    }
    if (checkValidImage(upEvent)) {
        Media media = upEvent.getMedia();
        // Initialize the bind object to
        image = (AImage) media;
        // show image in zul page and
        // Notify it also
        newImageFileWrapper = new FileWrapper(media.getByteData(), media.getName());
        imageModified = true;
        notifyChange("image", "imageModified");
    }
}
Also used : Media(org.zkoss.util.media.Media) FileWrapper(org.openforis.collect.model.FileWrapper) FormObject(org.openforis.collect.designer.form.FormObject) CodeListItemFormObject(org.openforis.collect.designer.form.CodeListItemFormObject) UploadEvent(org.zkoss.zk.ui.event.UploadEvent) Command(org.zkoss.bind.annotation.Command)

Example 2 with FileWrapper

use of org.openforis.collect.model.FileWrapper in project collect by openforis.

the class CodeListImagesExportTask method execute.

@Override
protected void execute() throws Throwable {
    List<CodeList> codeLists = survey.getCodeLists();
    for (CodeList list : codeLists) {
        if (!list.isExternal()) {
            Deque<CodeListItem> stack = new LinkedList<CodeListItem>();
            List<CodeListItem> rootItems = codeListManager.loadRootItems(list);
            stack.addAll(rootItems);
            while (!stack.isEmpty()) {
                if (!isRunning()) {
                    break;
                }
                CodeListItem item = stack.pop();
                if (item instanceof PersistedCodeListItem && item.hasUploadedImage()) {
                    FileWrapper imageFileWrapper = codeListManager.loadImageContent((PersistedCodeListItem) item);
                    ZipEntry entry = new ZipEntry(getEntryName(item));
                    zipOutputStream.putNextEntry(entry);
                    IOUtils.write(imageFileWrapper.getContent(), zipOutputStream);
                    zipOutputStream.closeEntry();
                }
                List<CodeListItem> childItems = codeListManager.loadChildItems(item);
                for (CodeListItem childItem : childItems) {
                    stack.push(childItem);
                }
            }
        }
    }
}
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) LinkedList(java.util.LinkedList) PersistedCodeListItem(org.openforis.idm.metamodel.PersistedCodeListItem)

Example 3 with FileWrapper

use of org.openforis.collect.model.FileWrapper in project collect by openforis.

the class CodeListItemDao method loadImageContent.

public FileWrapper loadImageContent(PersistedCodeListItem item) {
    JooqDSLContext dsl = dsl(item.getCodeList());
    ResultQuery<?> selectQuery = dsl.selectByIdQuery(item.getSystemId());
    Record r = selectQuery.fetchOne();
    if (r == null) {
        return null;
    } else {
        byte[] content = r.getValue(OFC_CODE_LIST.IMAGE_CONTENT);
        if (content == null) {
            return null;
        } else {
            String fileName = r.getValue(OFC_CODE_LIST.IMAGE_FILE_NAME);
            return new FileWrapper(content, fileName);
        }
    }
}
Also used : FileWrapper(org.openforis.collect.model.FileWrapper) OfcCodeListRecord(org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord) Record(org.jooq.Record)

Example 4 with FileWrapper

use of org.openforis.collect.model.FileWrapper 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

FileWrapper (org.openforis.collect.model.FileWrapper)4 ZipEntry (java.util.zip.ZipEntry)2 CodeList (org.openforis.idm.metamodel.CodeList)2 CodeListItem (org.openforis.idm.metamodel.CodeListItem)2 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)2 LinkedList (java.util.LinkedList)1 Record (org.jooq.Record)1 CodeListItemFormObject (org.openforis.collect.designer.form.CodeListItemFormObject)1 FormObject (org.openforis.collect.designer.form.FormObject)1 OfcCodeListRecord (org.openforis.collect.persistence.jooq.tables.records.OfcCodeListRecord)1 Command (org.zkoss.bind.annotation.Command)1 Media (org.zkoss.util.media.Media)1 UploadEvent (org.zkoss.zk.ui.event.UploadEvent)1