Skip to content

Commit

Permalink
chore(core): Move Async Email Actionlet to Core #28360 (#28361)
Browse files Browse the repository at this point in the history
* #28360 migrating the async email to core

* #28360 adding refactor for sonarq feedback

* #28360 adding refactor for sonarq feedback

* #28360 adding refactor for sonarq feedback
  • Loading branch information
jdotcms committed May 9, 2024
1 parent c3f6242 commit 10b5858
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.dotmarketing.portlets.workflows.actionlet;

import com.dotcms.api.system.event.message.MessageSeverity;
import com.dotcms.api.system.event.message.SystemMessageEventUtil;
import com.dotcms.api.system.event.message.builder.SystemMessageBuilder;
import com.dotcms.concurrent.DotConcurrentFactory;
import com.dotmarketing.portlets.workflows.model.WorkflowProcessor;
import com.dotmarketing.util.Mailer;

import java.util.ArrayList;
import java.util.List;

/**
* Same of the {@link EmailActionlet} but runs asynchronously.
* @author jsanca
*/
public class AsyncEmailActionlet extends EmailActionlet {

private static final long serialVersionUID = 1L;

protected final SystemMessageEventUtil systemMessageEventUtil =
SystemMessageEventUtil.getInstance();


@Override
public String getName() {
return "Async Send an Email";
}

@Override
protected void sendEmail(final Mailer mail, final WorkflowProcessor processor) {
DotConcurrentFactory.getInstance().getSubmitter().submit(()->{
try {
mail.sendMessage();
} catch (Exception e) {

final List<String> userList = new ArrayList<>();
userList.add(processor.getUser().getUserId());
this.systemMessageEventUtil.pushMessage(new SystemMessageBuilder().setMessage("Error sending the email: " + e.getMessage())
.setLife(5000)
.setSeverity(MessageSeverity.ERROR).create(), userList);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,15 @@ public void executeAction(WorkflowProcessor processor, Map<String, WorkflowActio
}
}

mail.sendMessage();

sendEmail(mail, processor);
} catch (Exception e) {
Logger.error(EmailActionlet.class, e.getMessage(), e);
}

}

}
protected void sendEmail(final Mailer mail, final WorkflowProcessor processor) {
mail.sendMessage();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import com.dotmarketing.portlets.workflows.MessageActionlet;
import com.dotmarketing.portlets.workflows.actionlet.Actionlet;
import com.dotmarketing.portlets.workflows.actionlet.ArchiveContentActionlet;
import com.dotmarketing.portlets.workflows.actionlet.AsyncEmailActionlet;
import com.dotmarketing.portlets.workflows.actionlet.BatchAction;
import com.dotmarketing.portlets.workflows.actionlet.CheckURLAccessibilityActionlet;
import com.dotmarketing.portlets.workflows.actionlet.CheckinContentActionlet;
Expand Down Expand Up @@ -265,6 +266,7 @@ public WorkflowAPIImpl() {
PushPublishActionlet.class,
CheckURLAccessibilityActionlet.class,
EmailActionlet.class,
AsyncEmailActionlet.class,
SetValueActionlet.class,
ReindexContentActionlet.class,
PushNowActionlet.class,
Expand Down

0 comments on commit 10b5858

Please sign in to comment.