Introduction
Bonita is an open-source platform for automating business processes. Bonita Studio (IDE) contains all the elements needed to develop the processes. It is a graphical environment for creating processes, applications, data models, and user’s views (pages and forms). The Bonita IDE is built on top of the well-known development environment eclipse.
This blog explains how a Bonita case can be created upon receiving a new email in the inbox. This has two different processes: one is continuously listening to the email inbox (email listener process) and another (callee process) is the actual process for which a new case is created. Email listener process has only one active case (never ending) which will be listening to the email inbox on a continuous interval (which can be supplied through the process parameter). The callee process details will also be supplied through the respective process parameters so that the listener process knows about the callee process for process instantiation.
Real-time Usage
Email to case can be used in certain issues we encounter in resolving day-to-day problems. Few of them are explained below:
- Order placements
- Raising complaints
- Feedback provision
Complaints are raised where it is inevitable to raise a process request whenever a new complaint from the customers is received. The complaints can certainly be through an email and whenever a new email arrives to the inbox, the complaint/process request should be created accordingly. This can be fully automated trough the Bonita email to case request. Feedback is another place where after the completion of any event the performer would look for the feedback for the quality purpose. This can be done when a new email is received for feedback and later a case can be initiated accordingly.
Glance of the Processes Used
Email Listener Process
The process looks as shown below. It has two major tasks (scripts): Poll Email and Instantiate Callee Process. We’ll deep dive into these steps in the coming sections.
Poll Email
Poll email step is responsible for poking the email server at a specified interval for the arrival of new emails. If it encounters any new email, then the information is being stored in the process variable and the same can be used for the process instantiation. Once if the mail is read, then it will be marked as seen so that the case creation for the same email can be stopped in the successive turns.
The code snippet from the fetchAllEmails is shown below.
public ListreadMails() { Logger logger = Logger.getLogger("org.bonitasoft.checkEmailStatus"); logger.info("Inside fetchAllEmails method"); List mailsList = new ArrayList<>(); Session session = null; Store store = null; Folder inbox = null; String userName = "XXXXXXXX@gmail.com";// provide user name String password = "XXXXXXXX";// provide password Properties properties = new Properties(); properties.setProperty("mail.host", "imap.gmail.com"); properties.setProperty("mail.port", "995"); properties.setProperty("mail.transport.protocol", "imaps"); logger.info("Inside fetchAllEmails method..."); session = Session.getInstance(properties, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); } }); try { store = session.getStore("imaps"); store.connect(); inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_WRITE); Message[] allMessages = inbox.search(new FlagTerm(new Flags(Flag.SEEN), false)); logger.info("Number of mails = " + allMessages.toString()); if(allMessages.length > 0){ for (int i = 0; i < allMessages.length; i++) { Message message = allMessages[i]; mailsList.add(message.getSubject()); Address[] from = message.getFrom(); logger.info("-------------------------------"); logger.info("Date : " + message.getSentDate()); logger.info("From : " + from[0]); logger.info("Subject: " + message.getSubject()); logger.info("Content :"); processMessageBody(message); logger.info("--------------------------------"); //message.setFlag(Flags.Flag.SEEN,true); } } inbox.close(true); store.close(); } catch (NoSuchProviderException e) { logger.info("--------------------------------"+e.getMessage()); } catch (MessagingException e) { logger.info("--------------------------------"+e.getMessage()); } return mailsList; }
List of parameters for the process are as shown below. It has three parameters which are used for instantiation of the other process.
Instantiate Callee Process
Instantiate callee process is responsible for creation of the case. It holds a connector, which will be invoked in certain intervals as specified by the process parameter. If this connector finds any new emails from Poll Email task, it instantiates the callee process. The code under this task may look like this:
Logger logger = Logger.getLogger("org.bonitasoft.instantiateCalleeProcess"); logger.info("Inside instantiateCalleeProcess "); ProcessAPI processAPI = apiAccessor.getProcessAPI(); long procDefId = processAPI.getProcessDefinitionId(processToCall, processVersion); logger.info("procDefId is: "+procDefId); ProcessDefinition procDef = processAPI.getProcessDefinition(procDefId); logger.info("procDef is: "+procDef); User user = apiAccessor.getIdentityAPI().getUserByUserName("lsp_user1"); logger.info("user is: "+user.getId()); for(String localMessage : mailsList){ logger.info("################ Creating case with: "+localMessage); JSONObject contractMap = new JSONObject(); contractMap.put("header", localMessage); ProcessInstance processInstance = processAPI.startProcessWithInputs(user.getId(), procDef.getId(), contractMap); logger.info("Case was created with header: "+ localMessage + " and case id: " + processInstance.getId()); }
Callee Process
The callee process is a new process for which the new process instances will be created based on the new email arrivals. This process information will be supplied to the main (Poll Email) process through the process parameters as mentioned above.
End form from the mails data will look as shown below.
Conclusion
Email to case in Bonita can be useful in many ways to automate major processes without human intervention. By following the steps advised above Bonita case instantiation upon new email arrival can be achieved.
Wish to know more about Bonita Case Creation? Feel free to leave your question below. We’ll get back to you in the shortest possible time.
Author
Vineeth Kumar Vyasabhattu is a Technical Lead at Evoke Technologies. He is part of a key BPM project for a leading North American conglomerate. Vineeth is technically adept on Java/J2EE based technologies and keen to explore Hadoop and NoSQL databases. He is currently pursuing his part-time Ph.D. in Web Services and Semantic Web from JNTU Hyderabad. |