Search in sources :

Example 1 with SendSmtpEmailOperation

use of io.lumeer.core.task.executor.operation.SendSmtpEmailOperation in project engine by Lumeer.

the class LumeerBridge method sendEmail.

@SuppressWarnings("unused")
public void sendEmail(final String to, final String fromName, final String subject, final String body, final LinkBridge l, final String attrId, final Value smtpConfig) throws Exception {
    if (task.getDaoContextSnapshot().increaseEmailCounter() <= Task.MAX_EMAILS) {
        if (StringUtils.isNotEmpty(to) && to.split(",").length > Task.MAX_EMAIL_RECIPIENTS) {
            cause = new IllegalStateException("Too many email recipients (more than 100).");
            throw cause;
        }
        final SmtpConfiguration smtpConfiguration = getSmtpConfiguration(smtpConfig);
        if (smtpConfiguration != null) {
            final SendSmtpEmailRequest sendSmtpEmailRequest = new SendSmtpEmailRequest(subject, to, body, fromName, smtpConfiguration);
            registerAttachment(sendSmtpEmailRequest, l, attrId);
            operations.add(new SendSmtpEmailOperation(sendSmtpEmailRequest));
        }
    } else {
        cause = new IllegalStateException("Too many requests to send email in a single rule (more than 3).");
        throw cause;
    }
}
Also used : SendSmtpEmailRequest(io.lumeer.core.task.executor.request.SendSmtpEmailRequest) SendSmtpEmailOperation(io.lumeer.core.task.executor.operation.SendSmtpEmailOperation) SmtpConfiguration(io.lumeer.core.task.executor.request.SmtpConfiguration)

Example 2 with SendSmtpEmailOperation

use of io.lumeer.core.task.executor.operation.SendSmtpEmailOperation 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 3 with SendSmtpEmailOperation

use of io.lumeer.core.task.executor.operation.SendSmtpEmailOperation in project engine by Lumeer.

the class LumeerBridge method sendEmail.

@SuppressWarnings("unused")
public void sendEmail(final String to, final String fromName, final String subject, final String body, final DocumentBridge d, final String attrId, final Value smtpConfig) throws Exception {
    if (task.getDaoContextSnapshot().increaseEmailCounter() <= Task.MAX_EMAILS) {
        if (StringUtils.isNotEmpty(to)) {
            if (to.split(",").length > Task.MAX_EMAIL_RECIPIENTS) {
                cause = new IllegalStateException("Too many email recipients (more than 100).");
                throw cause;
            }
            final SmtpConfiguration smtpConfiguration = getSmtpConfiguration(smtpConfig);
            if (smtpConfiguration != null) {
                final SendSmtpEmailRequest sendSmtpEmailRequest = new SendSmtpEmailRequest(subject, to, body, fromName, smtpConfiguration);
                registerAttachment(sendSmtpEmailRequest, d, attrId);
                operations.add(new SendSmtpEmailOperation(sendSmtpEmailRequest));
            }
        } else {
            cause = new IllegalStateException("Recipients list is empty.");
            throw cause;
        }
    } else {
        cause = new IllegalStateException("Too many requests to send email in a single rule (more than 3).");
        throw cause;
    }
}
Also used : SendSmtpEmailRequest(io.lumeer.core.task.executor.request.SendSmtpEmailRequest) SendSmtpEmailOperation(io.lumeer.core.task.executor.operation.SendSmtpEmailOperation) SmtpConfiguration(io.lumeer.core.task.executor.request.SmtpConfiguration)

Example 4 with SendSmtpEmailOperation

use of io.lumeer.core.task.executor.operation.SendSmtpEmailOperation in project engine by Lumeer.

the class LumeerBridge method sendEmail.

@SuppressWarnings("unused")
public void sendEmail(final String to, final String fromName, final String subject, final String body, final Value smtpConfig) {
    if (task.getDaoContextSnapshot().increaseEmailCounter() <= Task.MAX_EMAILS) {
        final SmtpConfiguration smtpConfiguration = getSmtpConfiguration(smtpConfig);
        if (smtpConfiguration != null) {
            final SendSmtpEmailRequest sendSmtpEmailRequest = new SendSmtpEmailRequest(subject, to, body, fromName, smtpConfiguration);
            operations.add(new SendSmtpEmailOperation(sendSmtpEmailRequest));
        }
    }
}
Also used : SendSmtpEmailRequest(io.lumeer.core.task.executor.request.SendSmtpEmailRequest) SendSmtpEmailOperation(io.lumeer.core.task.executor.operation.SendSmtpEmailOperation) SmtpConfiguration(io.lumeer.core.task.executor.request.SmtpConfiguration)

Aggregations

SendSmtpEmailOperation (io.lumeer.core.task.executor.operation.SendSmtpEmailOperation)4 SendSmtpEmailRequest (io.lumeer.core.task.executor.request.SendSmtpEmailRequest)4 SmtpConfiguration (io.lumeer.core.task.executor.request.SmtpConfiguration)4 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