IBM Support

Maximo Rest Client API for Java on a Beagle Bone

Technical Blog Post


Abstract

Maximo Rest Client API for Java on a Beagle Bone

Body

I have written a couple of articles before using the Maximo REST functionality with the BeagleBone and I have linked them in the comments section. The Maximo Rest Client API for Java was recently released as a Maven Repository and I gave it a try on my BeagleBone. The API can be found here, Maximo Rest Client API for Java.

I wrote the example with Work Orders in mind, the BeagleBoard could be installed on a piece of equipment and monitor it's condition using different sensors. If some values goes out of range, a Work Order can be created in Maximo for  someone to service the Equipment.

To try out the example, setup a new Maven project using the information from the Maximo Rest Client web site. Copy and paste the code below and compile it in the Maven project. Make sure you set up a run configuration that takes the four parameters needed by the program, host, port, user and password. Test run the program and make sure it works on your desktop.

In order to make it easier to run on your Beagle Board I would suggest creating a jar file with all dependencies. In eclipse, right click on your Project and select export. Expand the Java section and select "Runnable JAR file" and click next. In the Launch configuration, select the run configuration you set up earlier to test the program and in Export Destination, name the file BeagleBone.jar. Make sure to select the "Package required libraries into generated JAR" and click finish. Transfer the BeagleBone.jar file to your BeagleBone under the /root directrory.

In order to run this on your BeagleBone, you need to install Java. This is actually not such a big deal, log in to your BeagleBone as root and run the following command,
root@beaglebone:~# apt-get update
This will update your package dependencies, it will take a few minutes and you can ignore the info. Once this is done, you can install Java with the following command,
root@beaglebone:~# apt-get install oracle-java8-installer
This will also take a few minutes and you will have to accept the license agreement in the middle of the install.
You can now run your JAR file with the following command,
root@beaglebone:~# java -jar BeagleBone.jar [Host_Name] [Port] wilson wilson
Here is one example where I logged in to the BeagleBone and ran the program,


{ ~ }  » ssh root@192.168.7.2                                                                   ~
Debian GNU/Linux 7
BeagleBoard.org Debian Image 2015-03-01
Support/FAQ: http://elinux.org/Beagleboard:BeagleBoneBlack_Debian
default username:password is [debian:temppwd]
The IP Address for usb0 is: 192.168.7.2
root@beaglebone:~# java -jar BeagleBone.jar MAXIMO_HOST 80 wilson wilson
Testing the Maximo REST API on the Beagle Bone Black:
https://developer.ibm.com/recipes/tutorials/maximo-rest-client-maximo-java-api-is-available-in-github-and-maven-repository-now/

Using where clause to find Work Orders: wonum="%1000%"
Found 3 Work Orders.
Data from first WO:
Wonum       : 1000
Description : Relocate Guard Rails Around Compressor

Created new Work Order:
Wonum       : 1208
Description : Created new WO Maximo REST API.
Status      : WAPPR

Wonum       : 1208
Description : Updated status from the Maximo REST API.
Status      : APPR
root@beaglebone:~#


This show how easy it is to use the API and that it is light weight enough to run on a low cost single board computer. A BeagleBone or Raspberry Pi could be set up to monitor equipment and send sensor data to Maximo, if values goes out of range, a Work Order can be created for service or repair.


import java.io.IOException;

import javax.json.Json;
import javax.json.JsonObject;
import javax.xml.datatype.DatatypeConfigurationException;

import com.ibm.maximo.oslc.MaximoConnector;
import com.ibm.maximo.oslc.Options;
import com.ibm.maximo.oslc.OslcException;
import com.ibm.maximo.oslc.QueryWhere;
import com.ibm.maximo.oslc.Resource;
import com.ibm.maximo.oslc.ResourceSet;

public class BeagleBone {

    public static void main(String[] args) throws IOException, OslcException, DatatypeConfigurationException {

        // Parameters from the command line.
        String host = args[0];
        int portNum = Integer.parseInt(args[1]);
        String user =  args[2];
        String password =  args[3];
        
        // Connect...
        MaximoConnector mc = new MaximoConnector(new Options().host(host).port(portNum).user(user).password(password)
                .mt(false).lean(true).auth("maxauth")).debug(false);
        mc.connect();
        
        System.out.println("Testing the Maximo REST API on the Beagle Bone Black:");
        System.out.println("https://developer.ibm.com/recipes/tutorials/maximo-rest-client-maximo-j…;);
        System.out.println();
        
        // Build Query...
        QueryWhere where = new QueryWhere().where("wonum").like("1000");
        System.out.println("Using where clause to find Work Orders: " + where.whereClause());
        
        // Get Work Orders...
        ResourceSet rs = mc.resourceSet("mxwodetail").select("wonum","description","status").where(where).fetch();
        System.out.println("Found " + rs.count() + " Work Orders.");
        
        // Get first Work order
        Resource res = rs.member(0);

        // Load the Work Order.
        res.load();
        
        if (res != null) {
            // To JSON Object.
            JsonObject woJSON = res.toJSON();
            
            // Print data.
            System.out.println("Data from first WO:");
            System.out.println("Wonum       : " + woJSON.getString("wonum"));
            System.out.println("Description : " + woJSON.getString("description"));
        }
        
        // Create new WO.
        JsonObject WOjo = Json.createObjectBuilder().add("siteid", "BEDFORD").add("description", "Created new WO Maximo REST API.").build();
        Resource newWO = rs.create(WOjo);
        JsonObject woJSON = newWO.toJSON();
        
        System.out.println();
        System.out.println("Created new Work Order:");
        System.out.println("Wonum       : " + woJSON.getString("wonum"));
        System.out.println("Description : " + woJSON.getString("description"));
        System.out.println("Status      : " + woJSON.getString("status"));

        // Change status of Work Order.
        JsonObject WOAPPRjo = Json.createObjectBuilder().add("status","APPR").add("memo","Status change from the Maximo REST API.").build();
        newWO.invokeAction("wsmethod:changeStatus", WOAPPRjo);

        // Change description.
        JsonObject WoChange = Json.createObjectBuilder().add("description", "Updated status from the Maximo REST API." ).build();
        newWO.update(WoChange);
        
        // Reload since it changed.
        newWO.reload();
        
        woJSON = newWO.toJSON();
        System.out.println();
        System.out.println("Wonum       : " + woJSON.getString("wonum"));
        System.out.println("Description : " + woJSON.getString("description"));
        System.out.println("Status      : " + woJSON.getString("status"));
        
        // Disconnect.
        mc.disconnect();
        
    }

}

 

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSLKT6","label":"IBM Maximo Asset Management"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11131129