Hello,
The job is scheduled every weekend to send the notification mails to the BPM task creator. And the program use as reference the CE Table currently.
Now the new requirements is to change the logic of who receive the notifications. The mail should be sent to the actual owner of the task. How can I get the task actual owner? I checked the threadIdentify Actual owner for a task in NWDS 7.2 but I don't know how to use it in ejb program. Please advise. Thanks a lot.
Piece of codes:
@Override
public void onJob(JobContext ctx) throws Exception {
String processName = null;
Logger logger = ctx.getLogger();
logger.info("Job started OK");
int delayedTasks = 0;
try {
ejbService = EJBService.getInstance();
userCtx = PdsConnection.connect(null);
JobParameter nameParameter = ctx.getJobParameter("BpmProcessName");
if (nameParameter != null) {
processName = nameParameter.getStringValue();
}
if (processName == null || processName.isEmpty()) {
logger.info("Specify a process name in the BpmProcessName parameter.");
return;
}
if(!isWeekend()){
//Notifications for rejections
List<ProcessDTO> openRejections = getOpenRejections();
for(ProcessDTO processDTO : openRejections){
messageType = REJECTION_STANDARD_EMAIL;
sendRejectionEmail(processDTO);
delayedTasks++;
}
//Notifications for draft request
List<RequestDTO> draftRequests = getDraftRequests();
messageType = DRAFT_REQUEST_EMAIL;
for(RequestDTO requestDTO : draftRequests){
sendEmail(requestDTO);
delayedTasks++;
}
}
JobParameter lengthParameter = ctx.getJobParameter("NumberOfDelayedTasks");
lengthParameter.setIntegerValue(delayedTasks);
ctx.setJobParameter(lengthParameter);
} catch (Exception e) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(bout);
e.printStackTrace(ps);
logger.info(new String(bout.toByteArray()));
handleError(e);
}finally{
if(ejbService != null){
try{
ejbService.closeContext();
}catch (Exception e) {}
if(userCtx != null) {
SessionManager.getInstance().destroySessions(userCtx);
}
}
}
private void sendEmail(RequestDTO requestDTO){
try{
List<String> to = pmFromRequest(requestDTO.getCreatedBy());
List<String> cc = getProgramManager();
MailUtils.sendMailWithAttachment(getSubject(""+requestDTO.getId()), getMessage(), getSenderEmail(),
convertListToArray(to), convertListToArray(cc), null, null, null);
}catch (Exception e) {
handleError(e);
}
}
Happy holidays!
Justin