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;
}
}
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();
}
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;
}
}
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));
}
}
}
Aggregations