cancel
Showing results for 
Search instead for 
Did you mean: 

How to use BPM API in Java Scheduler Job program

Former Member
0 Kudos

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 thread 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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Please kindly help.

rohit_j
Participant
0 Kudos

Hi Justin,

First of all there is no BPM API in CE 7.2

I assume there is a CEDB table where you have the list of potential owners stored to whom the notification is being sent through the Job.

So a new column needs to be created in your table which will be a flag that marks a potential owner as actual owner.

Now you can get the actual owner of the task by doing the below mapping in your process.

Note that this will not work for In Progress tasks.

Best Regards,

Rohit

Former Member
0 Kudos

Hi Rohit,

Thanks a lot for your reply. I am using CE 7.3. Do you know if we can use any BPM API on this issue?

BR,

Justin

rohit_j
Participant
0 Kudos

Hi Justin,

If you are using SAP CE 7.3 then BPM API directly gives the actual owner.

First you can get the "TaskInstanceManager" instance from BPMFactory.

Below code might work for you.

TaskInstanceManager tm = BPMFactory.getTaskInstanceManager();

TaskDetail td= tm.getTaskDetail(new URI("bpm://bpm.sap.com/task-instance/" + taskInstanceId));

td.getActualOwner() gives the actual owner of the task.

Best Regards,

Rohit

Former Member
0 Kudos

Hi Rohit,

Yes, I am using CEDB and CE7.3. But I only can get the BPM process ID.

Is there any way I can get the taskInstanceId by process ID?

Thanks a lot for your help.

BR,

Justin

Former Member
0 Kudos

Hello there,

Can anybody help on this question? Appreciate your time and efforts.

Happy New Year!

Regards,

Justin