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);
  }
}

Labels: , ,