Search in sources :

Example 1 with AddDocumentFileAttachmentOperation

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();
}
Also used : SelectedWorkspace(io.lumeer.api.SelectedWorkspace) Arrays(java.util.Arrays) TaskExecutor(io.lumeer.core.task.TaskExecutor) PrintTextOperation(io.lumeer.core.task.executor.operation.PrintTextOperation) CollectionUtil(io.lumeer.api.util.CollectionUtil) Date(java.util.Date) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) FileAttachmentData(io.lumeer.core.task.executor.operation.data.FileAttachmentData) Operation(io.lumeer.core.task.executor.operation.Operation) TextPrintRequest(io.lumeer.core.task.executor.request.TextPrintRequest) StringUtils(org.apache.commons.lang3.StringUtils) UserMessageOperation(io.lumeer.core.task.executor.operation.UserMessageOperation) BigDecimal(java.math.BigDecimal) SmtpConfigurationBuilder(io.lumeer.core.task.executor.request.SmtpConfigurationBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ResourceType(io.lumeer.api.model.ResourceType) Map(java.util.Map) AddLinkFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddLinkFileAttachmentOperation) Collectors.toSet(java.util.stream.Collectors.toSet) ConstraintManager(io.lumeer.core.constraint.ConstraintManager) DocumentOperation(io.lumeer.core.task.executor.operation.DocumentOperation) RoleType(io.lumeer.api.model.RoleType) View(io.lumeer.api.model.View) ViewPermissionsOperation(io.lumeer.core.task.executor.operation.ViewPermissionsOperation) DataDocument(io.lumeer.engine.api.data.DataDocument) Value(org.graalvm.polyglot.Value) DummySequenceOperation(io.lumeer.core.task.executor.operation.DummySequenceOperation) Document(io.lumeer.api.model.Document) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) LinkInstance(io.lumeer.api.model.LinkInstance) StandardCharsets(java.nio.charset.StandardCharsets) LinkType(io.lumeer.api.model.LinkType) Group(io.lumeer.api.model.Group) DefaultConfigurationProducer(io.lumeer.core.facade.configuration.DefaultConfigurationProducer) PrintAttributeOperation(io.lumeer.core.task.executor.operation.PrintAttributeOperation) SendSmtpEmailRequest(io.lumeer.core.task.executor.request.SendSmtpEmailRequest) List(java.util.List) SendEmailOperation(io.lumeer.core.task.executor.operation.SendEmailOperation) EmailSecurityType(io.lumeer.core.util.EmailSecurityType) Optional(java.util.Optional) Attribute(io.lumeer.api.model.Attribute) WithId(io.lumeer.api.model.common.WithId) SendSmtpEmailOperation(io.lumeer.core.task.executor.operation.SendSmtpEmailOperation) ChangesTracker(io.lumeer.core.task.executor.ChangesTracker) LongAdder(java.util.concurrent.atomic.LongAdder) LinkOperation(io.lumeer.core.task.executor.operation.LinkOperation) Engine(com.floreysoft.jmte.Engine) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DocumentCreationOperation(io.lumeer.core.task.executor.operation.DocumentCreationOperation) SendEmailRequest(io.lumeer.core.task.executor.request.SendEmailRequest) HashMap(java.util.HashMap) AllowedPermissions(io.lumeer.api.model.AllowedPermissions) ArrayList(java.util.ArrayList) NavigationOperation(io.lumeer.core.task.executor.operation.NavigationOperation) SearchQueryStem(io.lumeer.storage.api.query.SearchQueryStem) HashSet(java.util.HashSet) Language(io.lumeer.api.model.Language) LinkCreationOperation(io.lumeer.core.task.executor.operation.LinkCreationOperation) PrintRequest(io.lumeer.core.task.executor.request.PrintRequest) DocumentRemovalOperation(io.lumeer.core.task.executor.operation.DocumentRemovalOperation) Query(io.lumeer.api.model.Query) ResourceOperation(io.lumeer.core.task.executor.operation.ResourceOperation) ContextualTask(io.lumeer.core.task.ContextualTask) LinkTypeUtil(io.lumeer.api.util.LinkTypeUtil) Task(io.lumeer.core.task.Task) PermissionUtils(io.lumeer.api.util.PermissionUtils) IOException(java.io.IOException) UserMessageRequest(io.lumeer.core.task.executor.request.UserMessageRequest) NavigationRequest(io.lumeer.core.task.executor.request.NavigationRequest) SmtpConfiguration(io.lumeer.core.task.executor.request.SmtpConfiguration) SearchQuery(io.lumeer.storage.api.query.SearchQuery) AddDocumentFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation) DocumentUtils(io.lumeer.core.util.DocumentUtils) FileAttachment(io.lumeer.api.model.FileAttachment) Collectors.toList(java.util.stream.Collectors.toList) ResourceVariable(io.lumeer.api.model.ResourceVariable) PdfCreator(io.lumeer.core.pdf.PdfCreator) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) DocumentOperation(io.lumeer.core.task.executor.operation.DocumentOperation) HashMap(java.util.HashMap) PrintAttributeOperation(io.lumeer.core.task.executor.operation.PrintAttributeOperation) UserMessageOperation(io.lumeer.core.task.executor.operation.UserMessageOperation) LinkOperation(io.lumeer.core.task.executor.operation.LinkOperation) AddLinkFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddLinkFileAttachmentOperation) DocumentCreationOperation(io.lumeer.core.task.executor.operation.DocumentCreationOperation) LinkCreationOperation(io.lumeer.core.task.executor.operation.LinkCreationOperation) NavigationOperation(io.lumeer.core.task.executor.operation.NavigationOperation) SendSmtpEmailOperation(io.lumeer.core.task.executor.operation.SendSmtpEmailOperation) LongAdder(java.util.concurrent.atomic.LongAdder) AddDocumentFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation) Collection(io.lumeer.api.model.Collection) SendEmailOperation(io.lumeer.core.task.executor.operation.SendEmailOperation) LinkType(io.lumeer.api.model.LinkType)

Example 2 with AddDocumentFileAttachmentOperation

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;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AddDocumentFileAttachmentOperation(io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation) FileAttachmentData(io.lumeer.core.task.executor.operation.data.FileAttachmentData) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

AddDocumentFileAttachmentOperation (io.lumeer.core.task.executor.operation.AddDocumentFileAttachmentOperation)2 Engine (com.floreysoft.jmte.Engine)1 SelectedWorkspace (io.lumeer.api.SelectedWorkspace)1 AllowedPermissions (io.lumeer.api.model.AllowedPermissions)1 Attribute (io.lumeer.api.model.Attribute)1 Collection (io.lumeer.api.model.Collection)1 Document (io.lumeer.api.model.Document)1 FileAttachment (io.lumeer.api.model.FileAttachment)1 Group (io.lumeer.api.model.Group)1 Language (io.lumeer.api.model.Language)1 LinkInstance (io.lumeer.api.model.LinkInstance)1 LinkType (io.lumeer.api.model.LinkType)1 Query (io.lumeer.api.model.Query)1 ResourceType (io.lumeer.api.model.ResourceType)1 ResourceVariable (io.lumeer.api.model.ResourceVariable)1 RoleType (io.lumeer.api.model.RoleType)1 User (io.lumeer.api.model.User)1 View (io.lumeer.api.model.View)1 WithId (io.lumeer.api.model.common.WithId)1 CollectionUtil (io.lumeer.api.util.CollectionUtil)1