Sunday, May 29, 2011

Intalio : example on how to manage deadline with tasks

In this post, I'll define a simple process to illustrate how to check whether a task deadline is reached. Below, you'll find a link to download my process project as well as the detailed process definition step by step.


Process definition (step by step)
  1. In the Intalio Designer, create a new project and name it "DeadlineManagement"
  2. Create a new "Business Process Diagram" and name it "DeadlineManagement.bpm"
  3. Add a pool to the diagram and name it "User"
  4. Set the "User" pool as non executable
  5. Add a task to the "User" pool and name it "Start process"
  6. Add a second pool and name it "Process tasks" (make sure this one is set as executable, which is the default configuration)
  7. Add a message start event to the "Process tasks" pool
  8. Drag the outgoing arrow from the "Start process" task (from the "User" pool) to the message start event
  9. In the project explorer, add a new directory and name it "messages".
  10. In the "messages" directory, create a new XML schema and name it "ProcessInput.xsd" (this schema defines the structure of the message that executes the process)
  11. In the XML schema, add a complex type and name it "InputMessage". In this complex type, add 3 elements :
    •  a string type element named "initialUser"
    • a string type element named "deadline"
    • a string type element named "reminderUser"
  12. Drag the complex type onto the arrow that links the "Start process" task and the message start event. Then choose the "Set schema type InputMessage as the content of the message"
  13. From the message start event, drag the outgoing arrow to the right and create a new task. Then, name this task "Create user task"
  14. Back in the project explorer view, create a new directory and name it "Forms"
  15. In the "Forms" directory, create a new Ajax form and name it "UserForm"
  16. Drag the form into the "User" pool and choose the "Create and complete" option
  17. From the "Create user task", drag the outgoing arrow to the right and create a new task named "Complete user task"
  18. From the "UserForm-create" node, drag both the outgoing and ingoing arrows to the "Create user task" task
  19. From the "Complete user task" task, drag both the outgoing and ingoing arrows to the "UserForm-complete" node
  20. Set the focus on the "Create user task" task and open the mapper view
  21. Map the "initialUser" from the input message to the "userOwner" task metadata. Then, map the "deadline" from the input message to the "until" task metadata
  22. From the "Complete user task" task, drag the outgoing arrow to the right and create a Gateway with type "Exclusive data-based gateway
  23. From the gateway, drag the outgoing arrow to the right; create a new task and name it "Process task without expiration"
  24. From the gateway, drag another outgoing arrow to the right; create a new task and name it "Clone task with high priority"
  25. Right click on the arrow that binds the gateway and the "Process task without expiration" task. Then choose "Condition type --> default" 
  26. Set the focus on the gateway and open the mapper view : 
    • add an "=" operator
    • Create a static argument with the value "DeadlineReached" and set it as input to the "=" operator
    • Set the "status" element from the "userFormNotifyTaskCompletionRequestMsg.root" node as the second argument of the "=" operator
    • map the result of the "=" operator to the "condition" node
  27. At this point, from the "Clone task with high priority" task, you could manage task expiration as you wish. In this example, I've chosen to recreate the initial task and assign it to another user, with another priority and a deadline = 31/12/2011 22:00  (this illustrates how you can reassign a task to a manager, in case it hasn't been completed by one of its underlings, for instance)
Running the process

Once the process is deploy, you can run it from the BPMS console. The input message we've defined through the XML schema will result in the user having to introduce the following info : 

Now, let's log in the UI-FW console as the "examples/msmith" user : 


Then, let's wait until 22:20. The task will disappear from the list of the "examples/msmith" user. Once logged in as "examples/ewilliams", we can see that the cloned task has been created : 


Download the sample project

    Wednesday, May 4, 2011

    Configuring JBoss mail service to use Gmail as SMTP server

    In this post, I'll show how to configure the JBoss mail service to use Gmail as an SMTP server, so that you'll be able to send emails using a valid Gmail account, from within an application that has been deployed in JBoss. 

    1° Environment / Prerequisites

    • As in the other posts, I am running JBoss AS 6
    • Any valid Gmail account
    2° Mail service configuration


    In the deploy directory of your JBoss server, you'll find a file name mail-service.xml (note that this file only exists in the deploy directory of the following server profiles : ALL, DEFAULT and standard). Simply edit this file as shown below :

    
    
     
     
     
    
     
      java:/GMail
    
      
      someuser@gmail.com
    
      
      myPassword
    
      
       
        
        
        
        
       
      
      jboss:service=Naming
     
    
    
    3° Sending mail : example

    On the personal project I am currently working at, mails are sent from a business method within a stateless session bean. Here's the code excerpt that does send the mail : 


    Context initCtx;
      try {
       initCtx = new InitialContext();
       Session session = (Session) initCtx.lookup("java:/GMail");
       Message message = new MimeMessage(session);
       
       InternetAddress to[] = new InternetAddress[1];
       to[0] = new InternetAddress("destination@gmail.com");  
       message.setRecipients(Message.RecipientType.TO, to);
       
       message.setSubject("How to send a mail with GMAIL from JBoss AS");
       message.setContent("Hello world", "text/plain");
       Transport.send(message);
      } catch (NamingException e) {
       e.printStackTrace();
      } catch (AddressException e) {
       e.printStackTrace();
      } catch (MessagingException e) {
       e.printStackTrace();
      }
    
    Now, let's take a look at the recipient mailbox :