Archive for the ‘Maximo Backend Development’ Category

Show Workorder on Google Map

Google Map in Workorder Tracking

Google Map in Workorder Tracking

Hello;

If you store coordinates in your workorders or location etc. you can show the places on google maps in Maximo. I implemented this on Maximo 6. There are many steps to accomplish this task.. I will tell you about it step by step…
1-You have to get a Google Map api key from this address: http://code.google.com/apis/maps/signup.html .. Write your maximo server address to the textbox and click Generate Key.. Note your key.. We will use it later…
2-Create iframe control: Go to %MAXIMOROOT%\applications\maximo\maximouiweb\webmodule\webclient\controls and create a folder named: iframe. We will send data to google map script from this control. I assume that longitude and latitude are stored in Workorder object as Longitude and Latitude attributes…
Create a jsp file named control.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<%@ include  file="../../common/controlheader.jsp" %>
	<%-- 
		PROPERTY	GLOBAL		VALUES
		id		true		...
		height 		false 		###
		width		false 		###
		url 		false		...
	--%>
	<mro:handleevent eventtype="loadinit">
		<mro:loadglobalproperties />
		<%
		int height = controlProperties.getInt("height", 100);
		int width = controlProperties.getInt("width", 100);
		String url = controlProperties.getString("src");
		%>
	</mro:handleevent>
 
	<mro:handleevent eventtype="render">
		<%
		int height = controlProperties.getInt("height", 100);
		int width = controlProperties.getInt("width", 100);
		String url = controlProperties.getString("src");
		String apptitle = sessionContext.getCurrentApp().getAppTitle();
		psdi.util.MXSession mxs=sessionContext.getMXSession();
		psdi.mbo.MboSetRemote woSet=mxs.getMboSet("WORKORDER");
		woSet.setWhere("WOCLASS in ('WORKORDER', 'ACTIVITY') and istask=0 and boylam is not null and enlem is not null");
		System.out.println("WO Count: "+woSet.count());
		java.util.ArrayList coordinateList = new java.util.ArrayList(woSet.count());
		for(int i=0;i<woSet.count();i++){
		java.util.ArrayList coordinate=new java.util.ArrayList(5);
		psdi.mbo.MboRemote wo=woSet.getMbo(i);
		coordinate.add(0,wo.getString("WONUM"));
		coordinate.add(1,wo.getString("DESCRIPTION"));
		coordinate.add(2,wo.getString("STATUS"));
		coordinate.add(3,wo.getString("LONGITUDE"));
		coordinate.add(4,wo.getString("LATITUDE"));
		coordinateList.add(coordinate);
 
		}
		session.setAttribute("CoordinatesList",coordinateList);
		%>
		<iframe src="<%=url%>" height="<%=height%>" width="<%=width%>"> </iframe>
	</mro:handleevent>
 
 
<%@ include file="../../common/controlfooter.jsp" %>

Here we defined iframe control and we added the workorder information to the CoordinatesList variable of session.

Now create another file called allwoongmaps.jsp in the same folder..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
	  <head>
	    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
	    <title></title>
	    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<strong>KEY</strong>"
	            type="text/javascript"></script>
	    <script type="text/javascript">
 
	    function initialize() {
 
	      if (GBrowserIsCompatible()) {
	        var map = new GMap2(document.getElementById("map_canvas"));
			 GEvent.addListener(map, "click", function(overlay, point){
			 if (point) {
			     map.addOverlay(new GMarker(point));
			     var msg = "Latitude: "+point.lat()+"<br>"+"Longitude: "+point.lng();
			     document.getElementById("mypoint").innerHTML = msg;
			 }  //close if(point)...
 
 
		   });   //close GEvent...
 
			var yellowIcon = new GIcon();
	yellowIcon.image ="http://esa.ilmari.googlepages.com/markeryellow.png";
	yellowIcon.iconSize = new GSize(20, 34);
	yellowIcon.iconAnchor = new GPoint(9, 34);
	var turqIcon = new GIcon();
	turqIcon.image = "http://www.google.com/uds/samples/places/temp_marker.png";
	turqIcon.iconSize = new GSize(20, 34);
	turqIcon.iconAnchor = new GPoint(9, 34);
 
 
 
	 <%
	java.util.ArrayList CoordinateList=(java.util.ArrayList) session.getAttribute("CoordinatesList");
		for(int i=1;i<CoordinateList.size()+1;i++){
			java.util.ArrayList Coordinate=(java.util.ArrayList)CoordinateList.get(i-1);
			String wonum=(String)Coordinate.get(0);
			String description=(String)Coordinate.get(1);
			String status=(String)Coordinate.get(2);
			String enlem=(String)Coordinate.get(3);
			String boylam=(String)Coordinate.get(4);
			double boydouble=Double.parseDouble(boylam);
			double enlemdouble=Double.parseDouble(enlem); 
			String marker="marker"+i;
			String point="point"+i;
			String icon;
			if(wonum.equalsIgnoreCase("1000"))
			icon="yellowIcon";
			else icon="turqIcon";
			if(i==1){ %>
	        map.setUIToDefault();
			map.setCenter(new GLatLng(<%=boydouble%>,<%=enlemdouble%>), 5);
			<%}%>
	          var <%=point%> = new GLatLng(<%=boydouble%>,<%=enlemdouble%>);
			  var <%=marker%>=new GMarker(<%=point%>,{icon:<%=icon%>});
	          map.addOverlay(<%=marker%>);
	     <% 
	    }%>
	}
	}
	    </script>
	  </head>
 
	  <body onload="initialize()" onunload="GUnload()">
	  <div id="mypoint"></div>
	    <div id="map_canvas" style="width: 470px; height: 200px"></div>
 
	  </body>
	</html>

On line 7 we add our own Google api key that we noted before… and we create our own map from longitude and latitude information on Workorder…
Now open Application Designer and export your application as xml file.Save it and back it up. then add this line to whereever you want.

<iframe src="http://localhost:7001/maximo/webclient/controls/iframe/allwoongmaps.jsp" height="200" width="500" id="genid_headera_4_child_1" />

localhost should be your servers ip…;
Save it and import from application designer.. Rebuild and redeploy… You’re going to see map like this…

read comments here

Creating an Action Class

Hello;
Now I am going to tell about custom action classes…
These classes help us to add custom actions to workflows…
We must write these classes in the psdi.common.action package.. We extend ActionCustomClass and override applyCustomAction method to make maximo do what we want to do…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package psdi.common.action;
 
import java.io.PrintStream;
import java.rmi.RemoteException;
import psdi.mbo.MboRemote;
import psdi.server.MXServer;
import psdi.util.MXApplicationYesNoCancelException;
import psdi.util.*;
import com.custom.workorder.*;
 
public class newFlowAction
    implements ActionCustomClass
{
 
            newFlowAction()
            {
            }
 
            public void applyCustomAction(MboRemote mboremote, Object aobj[])
                throws MXException, RemoteException
            {
 
              com.custom.workorder.newWORemote mbo=(com.custom.workorder.newWORemote)mboremote;
	       if(mbo.getString("STATUS").equalsIgnoreCase("INPRG")){
                        mbo.getMboSet("OTHEROBJECT").deleteAll();
                 }
            }
}

Here on line 23 we cast our mbo to custom Workorder object. Now we are able to use workorder’s methods on mbo object. On line 24 we check if the status is INPRG or not…
And on line 25 if the status is INPRG we select the OTHEROBJECT relationship and delete all mbo’s that came with OTHEROBJECT relationship…

Then we compile the code… Rebuild Maximo.ear.. Redeploy it… Now you can use it in the related workflow..

Have a good day…

read comments here

Writing a Custom Condition Class

One of the best improvements in Maximo 7.x is conditional user interfaces. You can create your conditions in Conditional Expression Manager application. But sometimes there are some issues that you can not write sql sentences. For these cases we can write our own condition class. We must extend psdi.common.condition.CustomCondition class to write the new class. And we need to override evaluateCondition(MboRemote mbo, Object arg1) method. Here is an basic example..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.custom.workorder;
 
import java.rmi.RemoteException;
import psdi.mbo.*;
import psdi.common.condition.CustomCondition;
import psdi.util.*;
 
public class TipCondition implements CustomCondition {
 
    public boolean evaluateCondition(MboRemote mbo, Object arg1) throws MXException, RemoteException {
        newWORemote wo = (newWORemote) mbo;
 if (wo.getString("ISSUETYPE").equalsIgnoreCase("PROBLEM")) {
            psdi.server.MXServer mxs = psdi.server.MXServer.getMXServer();
            MboSetRemote loc_set = mxs.getMboSet("LOCATIONS", wo.getUserInfo());
            loc_set.setWhere("location in('"+wo.getString("CENTER1")+"')");
            loc_set.reset();
            if (loc_set.count() > 0) {
                String kanal = loc_set.getMbo(0).getString("CAPACITY");
                if (kanal.startsWith("4")) {
                    return true;
                }
            }
            return false;
        } else {
            return false;
        }
    }
 
    public String toWhereClause(Object arg0, MboSetRemote arg1) throws MXException, RemoteException {
        return "";
    }
}

Have a good day…

read comments here

Import AlnDomain from Excel Sheet

Hello;

Now I will explain a bit about importing from excel sheet. Here I will use Jexcel Api to read excel files. This script was written for Maximo 6.2.1, and I will use Jexcel Api 2.6.9 which can be downloaded from here.
Here is the code:

/*
 * addAlnDomain.java
 *
 * Created on September 2, 2008, 4:00 PM
 */
import java.io.File;
import java.io.PrintStream;
import jxl.*;
import psdi.app.system.*;
import psdi.mbo.MboRemote;
import psdi.util.MXSession;
/**
 *
 * @author  bbolek
 */
public class addAlnDomain {
 
    /** Creates a new instance of addAlnDomain*/
    public addAlnDomain() {
    }
 
    public void add(String filename) {
        try {
            MXSession s;
            s = MXSession.getSession();
            s.setHost("localhost:9898/MXServer"); //Server Name
            s.setUserName("wilson");
            s.setPassword("wilson");
            s.connect();
 
            Workbook workbook = Workbook.getWorkbook(new File(filename + ".xls"));
            Sheet sheet = workbook.getSheet(0);
            int k = 1;
            String description, value;
                MaxDomainSetRemote maxdomain=(MaxDomainSetRemote) s.getMboSet("MAXDOMAIN");
                maxdomain.setWhere("DOMAINID='DOMAINNAME'");
                maxdomain.reset();
                MboRemote maxDomain=maxdomain.getMbo(0);
            while (sheet.getCell(0, k).getContents().length() &gt; 1) {
                value = sheet.getCell(0, k).getContents().toString();
                description = sheet.getCell(1, k).getContents().toString();
                System.out.println("VALUE :"+value+ " DESCRIPTION: "+description );
 
                ALNValueSetRemote alnSet =(ALNValueSetRemote) maxDomain.getMboSet("ALNDOMAINVALUE");
                ALNValueRemote aln = null;
                aln = (ALNValueRemote) alnSet.addAtEnd();
                aln.setValue("VALUE", value);
                aln.setValue("DESCRIPTION", description);
	        alnSet.save();
                k++;
            }
        } catch (Exception E) {
            E.printStackTrace();
        }
}
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        addAlnDomain new_AlnDomain = new addAlnDomain();
        new_AlnDomain.add("Example");
    }
}

In here; between line 28-32 server settings are set. Then on line 34 excel workbook is opened.
On line 35 first sheet is selected. On line 39 the domain with name “DOMAINNAME” is selected.
Line 42 shows that the loop will continue if there is a value on the first column of excel.
Line 43 and 44 reads the excel and sets the variables. And on line 48 we create a new ALNDomain mbo. And on 49 we added it to the AlnDomainSet.
Then we bind the variables and save the MboSet…
On line 62 we set the excel filename…Here it is Example.xls

All Mbo’s can be read from excel and imported to Maximo in this way. It is quite easy and customizable…For example you can set some rules to import in java like
-import data that starts with 1,
-import data which is like ‘%10%’
-etc…

Have a good day…

read comments here

Creating a New Mbo Class

Hello;

One of the basic java functionality is to create new mbo’s and changing its default behaviour. For example we can create a new mbo as the child of Workorder. And assume there is a relationship between workorder and newMbo as wonum=:wonum. When we add a new record from the user interface, new record’s wonum is not populated automatically. So we have to extend psdi.mbo.Mbo to automate this. Here is how it is done….
File :custom.newMbo.newMbo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package custom.newMbo;
 
import psdi.util.*;
import java.util.*;
import psdi.mbo.*;
import java.rmi.*;
import psdi.server.MXServer;
 
 
public class newMbo extends Mbo
        implements newMboRemote {
 
    /**
     * Constructor
     */
    public newMbo(MboSet ms) throws MXException, RemoteException {
        super(ms);
    }
 
    public void add() throws MXException, RemoteException {
        super.add();        
        MboRemote mboremote = getOwner();
        setValue("WONUM", mboremote.getString("WONUM"), 2L);
 
 
    }
 
}

File :custom.newMbo.newMboSet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package custom.newMbo;
import psdi.mbo.*;
import psdi.util.*;
import java.util.*;
import java.rmi.*;
 
public class newMboSet extends MboSet
implements newMboSetRemote
{
/**
* Constructor
*/
 
public newMboSet(MboServerInterface ms)
throws MXException, RemoteException
{
super(ms);
}
 
 
 
protected Mbo getMboInstance(MboSet ms)
throws MXException, RemoteException
{
return new newMbo(ms); // this is the key line ...
}
}

File :custom.newMbo.newMboRemote

1
2
3
4
5
6
7
8
9
package custom.newMbo;
import psdi.mbo.*;
import psdi.util.*;
import java.rmi.*;
 
public interface newMboRemote extends MboRemote
{
 
}

File :custom.newMbo.newMboSetRemote

1
2
3
4
5
6
7
8
9
package custom.newMbo;
import psdi.mbo.*;
import psdi.util.*;
import java.rmi.*;
 
public interface newMboSetRemote
extends MboSetRemote
{
}

Then you have to compile and rmic these files. Then Go to the database configuration find your object. Enter ‘custom.newMbo.newMboSet’ to the class…

Configure DB
Build Maximo.ear
Deploy Maximo.ear

Tip: It is better to make Wonum field readonly on user interface. Users must not change the field from the user interface

Then you’re good to go….

Have a good day…

read comments here