use of io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation in project engine by Lumeer.
the class LumeerBridge method getOperationsDescription.
public String getOperationsDescription() {
final Map<String, Collection> collections = new HashMap<>();
final Map<String, LinkType> linkTypes = new HashMap<>();
final StringBuilder sb = new StringBuilder();
final LongAdder i = new LongAdder();
operations.forEach(operation -> {
if (operation instanceof DocumentCreationOperation) {
final DocumentCreationOperation documentCreationOperation = (DocumentCreationOperation) operation;
if (StringUtils.isEmpty(documentCreationOperation.getEntity().getId())) {
i.increment();
documentCreationOperation.getEntity().setId("NEW" + i.intValue());
}
}
});
operations.forEach(operation -> {
if (operation instanceof DocumentCreationOperation) {
final DocumentCreationOperation documentCreationOperation = (DocumentCreationOperation) operation;
final Collection collection = collections.computeIfAbsent(documentCreationOperation.getEntity().getCollectionId(), id -> task.getDaoContextSnapshot().getCollectionDao().getCollectionById(id));
sb.append("new Document(").append(collection.getName()).append(")\n");
} else if (operation instanceof DocumentOperation) {
final DocumentOperation documentChange = (DocumentOperation) operation;
final Collection collection = collections.computeIfAbsent(documentChange.getEntity().getCollectionId(), id -> task.getDaoContextSnapshot().getCollectionDao().getCollectionById(id));
appendOperation(sb, collection.getName(), collection.getAttributes(), documentChange);
} else if (operation instanceof LinkOperation) {
final LinkOperation linkChange = (LinkOperation) operation;
final LinkType linkType = linkTypes.computeIfAbsent(linkChange.getEntity().getId(), id -> task.getDaoContextSnapshot().getLinkTypeDao().getLinkType(id));
appendOperation(sb, linkType.getName(), linkType.getAttributes(), linkChange);
} else if (operation instanceof UserMessageOperation || operation instanceof PrintAttributeOperation || operation instanceof NavigationOperation || operation instanceof SendEmailOperation) {
sb.append(operation.toString());
} else if (operation instanceof LinkCreationOperation) {
final LinkCreationOperation linkCreationOperation = (LinkCreationOperation) operation;
final LinkType linkType = linkTypes.computeIfAbsent(linkCreationOperation.getEntity().getLinkTypeId(), id -> task.getDaoContextSnapshot().getLinkTypeDao().getLinkType(id));
sb.append("new Link(").append(linkType.getName()).append(")\n");
} else if (operation instanceof AddDocumentFileAttachmentOperation) {
final AddDocumentFileAttachmentOperation addDocumentFileAttachmentOperation = (AddDocumentFileAttachmentOperation) operation;
final Collection collection = collections.computeIfAbsent(addDocumentFileAttachmentOperation.getEntity().getCollectionId(), id -> task.getDaoContextSnapshot().getCollectionDao().getCollectionById(id));
sb.append("new record file attachment (").append(collection.getName()).append(".").append(CollectionUtil.getAttribute(collection, addDocumentFileAttachmentOperation.getAttrId())).append(": ").append(addDocumentFileAttachmentOperation.getFileAttachmentData().getFileName()).append(")\n");
} else if (operation instanceof AddLinkFileAttachmentOperation) {
final AddLinkFileAttachmentOperation addLinkFileAttachmentOperation = (AddLinkFileAttachmentOperation) operation;
final LinkType linkType = linkTypes.computeIfAbsent(addLinkFileAttachmentOperation.getEntity().getLinkTypeId(), id -> task.getDaoContextSnapshot().getLinkTypeDao().getLinkType(id));
sb.append("new link file attachment (").append(linkType.getName()).append(".").append(LinkTypeUtil.getAttribute(linkType, addLinkFileAttachmentOperation.getAttrId())).append(": ").append(addLinkFileAttachmentOperation.getFileAttachmentData().getFileName()).append(")\n");
} else if (operation instanceof SendSmtpEmailOperation) {
final SendSmtpEmailOperation sendSmtpEmailOperation = (SendSmtpEmailOperation) operation;
sb.append("send email (to: ").append(sendSmtpEmailOperation.getEntity().getEmail()).append(", subject: ").append(sendSmtpEmailOperation.getEntity().getSubject()).append(")\n");
}
});
return sb.toString();
}
use of io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation in project engine by Lumeer.
the class LumeerBridge method writePdf.
@SuppressWarnings("unused")
public void writePdf(final DocumentBridge d, final String attrId, final String fileName, final boolean overwrite, final String html) throws IOException {
try {
if (html.length() > 5L * 1024 * 1024) {
throw new IllegalArgumentException("Input HTML too large.");
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfCreator.createPdf(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8)), baos);
var relatedOperation = setDocumentAttribute(d, attrId, Value.asValue(getUpdateFileAttachmentsList(d, attrId, fileName, overwrite)));
operations.add(new AddDocumentFileAttachmentOperation(d.getDocument(), attrId, new FileAttachmentData(baos.toByteArray(), fileName, overwrite), relatedOperation));
} catch (Exception e) {
cause = e;
throw e;
}
}
Aggregations