use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class Emailer method persistSendingMessage.
protected void persistSendingMessage(EntityManager em, SendingMessage message, MessagePersistingContext context) throws FileStorageException {
boolean useFileStorage = config.isFileStorageUsed();
if (useFileStorage) {
byte[] bodyBytes = bodyTextToBytes(message);
FileDescriptor contentTextFile = createBodyFileDescriptor(message, bodyBytes);
fileStorage.saveFile(contentTextFile, bodyBytes);
context.files.add(contentTextFile);
em.persist(contentTextFile);
message.setContentTextFile(contentTextFile);
message.setContentText(null);
}
em.persist(message);
for (SendingAttachment attachment : message.getAttachments()) {
if (useFileStorage) {
FileDescriptor contentFile = createAttachmentFileDescriptor(attachment);
fileStorage.saveFile(contentFile, attachment.getContent());
context.files.add(contentFile);
em.persist(contentFile);
attachment.setContentFile(contentFile);
attachment.setContent(null);
}
em.persist(attachment);
}
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class FileUploading method getFileDescriptor.
@Override
public FileDescriptor getFileDescriptor(UUID fileId, String name) {
File file = getFile(fileId);
if (file == null) {
return null;
}
Metadata metadata = AppBeans.get(Metadata.NAME);
FileDescriptor fDesc = metadata.create(FileDescriptor.class);
fDesc.setSize(file.length());
fDesc.setExtension(FilenameUtils.getExtension(name));
fDesc.setName(name);
fDesc.setCreateDate(timeSource.currentTimestamp());
return fDesc;
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class FileUploading method putFileIntoStorage.
@Override
public FileDescriptor putFileIntoStorage(final TaskLifeCycle<Long> taskLifeCycle) throws FileStorageException, InterruptedException {
checkNotNullArgument(taskLifeCycle);
UUID fileId = (UUID) taskLifeCycle.getParams().get("fileId");
String fileName = (String) taskLifeCycle.getParams().get("fileName");
checkNotNull(fileId);
checkNotNull(fileName);
UploadToStorageProgressListener progressListener = (fileId1, uploadedBytes, totalBytes) -> taskLifeCycle.publish(uploadedBytes);
FileDescriptor fileDescriptor = getFileDescriptor(fileId, fileName);
uploadFileIntoStorage(fileId, fileDescriptor, progressListener);
deleteFile(fileId);
return fileDescriptor;
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class FileBrowser method init.
@Override
public void init(Map<String, Object> params) {
super.init(params);
filesTable.addAction(new ItemTrackingAction("download").withCaption(getMessage("download")).withHandler(event -> {
FileDescriptor fileDescriptor = filesTable.getSingleSelected();
if (fileDescriptor != null) {
exportDisplay.show(fileDescriptor, null);
}
}));
BaseAction multiUploadAction = new BaseAction("multiupload").withCaption(getMessage("multiupload")).withHandler(event -> {
if (!security.isEntityOpPermitted(FileDescriptor.class, EntityOp.READ)) {
throw new AccessDeniedException(PermissionType.ENTITY_OP, FileDescriptor.class.getSimpleName());
}
Window window = openWindow("multiuploadDialog", OpenType.DIALOG);
window.addCloseListener(actionId -> {
if (COMMIT_ACTION_ID.equals(actionId)) {
Collection<FileDescriptor> items = ((MultiUploader) window).getFiles();
for (FileDescriptor fdesc : items) {
boolean modified = filesDs.isModified();
filesDs.addItem(fdesc);
((DatasourceImplementation) filesDs).setModified(modified);
}
filesTable.focus();
}
});
});
multiUploadAction.setEnabled(security.isEntityOpPermitted(FileDescriptor.class, EntityOp.CREATE));
multiUploadBtn.setAction(multiUploadAction);
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class SendingMessageBrowser method getFileDescriptor.
protected FileDescriptor getFileDescriptor(SendingAttachment attachment) throws FileStorageException {
UUID uuid = fileUploading.saveFile(attachment.getContent());
FileDescriptor fileDescriptor = fileUploading.getFileDescriptor(uuid, attachment.getName());
fileUploading.putFileIntoStorage(uuid, fileDescriptor);
return dataSupplier.commit(fileDescriptor);
}
Aggregations