November 22, 2012

Custom Java Class for Roles

This entry is part of the Maximo Java Development series.

This is just an example of a Maximo role defined with a custom Java class. In this example I have defined a role that can be used to send emails (Communication Template) to the workorder's supervisor or to the owner group if the supervisor is not set.

This is the definition of the role.



And this is the Java code.

package cust.psdi.workflow;

import java.rmi.RemoteException;

import psdi.common.role.CustomRoleAdapter;
import psdi.common.role.CustomRoleInterface;
import psdi.common.role.MaxRole;
import psdi.mbo.MboRemote;
import psdi.util.MXApplicationException;
import psdi.util.MXException;

/**
 * Returns the supervisor if set otherwise returns the owner group
 */
public class SupervisorOrOwnerGroup extends CustomRoleAdapter implements CustomRoleInterface
{
  public MboRemote evaluateCustomRole(MaxRole roleMbo, MboRemote currentMbo)
      throws MXException, RemoteException
  {
    // check if the current MBO is a WorkOrder
    if (currentMbo instanceof psdi.app.workorder.WO)
    {
      throw new MXApplicationException("workflow", "WrongObject");
    }

    String sup = currentMbo.getString("SUPERVISOR");
    if(sup.length()!=0)
    {
      // if the supervisor is set returns the corresponding person
      MboRemote mbs = currentMbo.getMboSet("SUPERVISOR").getMbo(0);
      return mbs.getMboSet("PERSON").getMbo(0);
    }
    // otherwise returns the corresponding owner group
    return currentMbo.getMboSet("WORKORDERTOPERSONGROUP").getMbo(0);
  }
}

4 comments:

  1. Hi,

    I have modified this code - i need to get only Owner group as the Role (it will be dynamic in Work order) and used in Work flow but this is not working.

    ReplyDelete
  2. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's. 
    best rpa training in bangalore
    rpa training in bangalore | rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  3. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    python Course in Pune
    python Course institute in Chennai
    python Training institute in Bangalore

    ReplyDelete
  4. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    AWS training in sholinganallur
    AWS training in Tambaram
    AWS training in Velachery

    ReplyDelete