use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class ResendMessage method retrieveContent.
protected byte[] retrieveContent(SendingAttachment sendingAttachment) {
byte[] content = sendingAttachment.getContent();
if (content != null) {
return content;
}
FileDescriptor contentFile = dataManager.load(FileDescriptor.class).query("select e.contentFile from sys$SendingAttachment e where e.id = :id").parameter("id", sendingAttachment.getId()).one();
try (InputStream inputStream = fileLoader.openStream(contentFile)) {
content = IOUtils.toByteArray(inputStream);
} catch (FileStorageException | IOException e) {
throw new RuntimeException("Can't read content from message attachment", e);
}
return content;
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class Emailer method migrateAttachment.
protected void migrateAttachment(EntityManager em, SendingAttachment attachment) {
attachment = em.merge(attachment);
FileDescriptor contentFile = createAttachmentFileDescriptor(attachment);
try {
fileStorage.saveFile(contentFile, attachment.getContent());
} catch (FileStorageException e) {
throw new RuntimeException("Unable to save file to storage", e);
}
em.persist(contentFile);
attachment.setContentFile(contentFile);
attachment.setContent(null);
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class Emailer method createBodyFileDescriptor.
protected FileDescriptor createBodyFileDescriptor(SendingMessage message, byte[] bodyBytes) {
FileDescriptor contentTextFile = metadata.create(FileDescriptor.class);
contentTextFile.setCreateDate(timeSource.currentTimestamp());
contentTextFile.setName("Email_" + message.getId() + "." + BODY_FILE_EXTENSION);
contentTextFile.setExtension(BODY_FILE_EXTENSION);
contentTextFile.setSize((long) bodyBytes.length);
return contentTextFile;
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class WebFileUploadField method getFileContent.
@Override
public InputStream getFileContent() {
if (contentProvider != null) {
return contentProvider.get();
}
FileDescriptor fileDescriptor = getValue();
switch(mode) {
case MANUAL:
if (fileId == null) {
return new FileDataProvider(fileDescriptor).provide();
}
File file = fileUploading.getFile(fileId);
if (file != null) {
try {
return new FileInputStream(file);
} catch (FileNotFoundException e) {
log.error("Unable to get content of {}", file, e);
}
return null;
}
FileStorageService fileStorageService = beanLocator.get(FileStorageService.NAME);
try {
if (fileStorageService.fileExists(fileDescriptor)) {
return new FileDataProvider(fileDescriptor).provide();
}
} catch (FileStorageException e) {
log.error("Unable to get content of {}", fileDescriptor, e);
return null;
}
break;
case IMMEDIATE:
if (fileDescriptor != null) {
return new FileDataProvider(fileDescriptor).provide();
}
}
return null;
}
use of com.haulmont.cuba.core.entity.FileDescriptor in project cuba by cuba-platform.
the class WebFileUploadField method initComponent.
protected void initComponent() {
component.addFileNameClickListener(e -> {
FileDescriptor value = getValue();
if (value == null) {
return;
}
switch(mode) {
case MANUAL:
String name = getFileName();
String fileName = StringUtils.isEmpty(name) ? value.getName() : name;
exportDisplay.show(this::getFileContent, fileName);
break;
case IMMEDIATE:
exportDisplay.show(value);
break;
}
});
component.setClearButtonListener(this::clearButtonClicked);
component.setRequiredError(null);
applyPermissions();
}
Aggregations