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");
}
}
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);
}
}
}
}
}
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);
}
}
}
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());
}
}
}
}
}
Aggregations