in Life&Travels

Decode BMC Remedy qualification with Java

Introduction

In this article I’ll give you a quick introduction on how to use BMC Remedy API to convert string qualification.

It’s a general introduction to Remedy APIs for experienced programmers, very quick and very easy, but if you want to know more (and more detailed), you can check for example this page.

If you are familiar with Remedy you know that filters’ qualification is written in a custom format using a “tree logic”.

It’s not a topic of this post to describe the format, you just need to know for example that a “run if” qualification is converted in a non-human-readable form, but very efficient to parse for the BMC ARS daemon.

So our goal is to write a simple Java program to convert a “encrypted” qualification passed by the user to a “plain” version.

To do these we have to use BMC Remedy Java API, which are installed with the Developer Studio and which you can find on your hard drive.

For example mine are located in: 

C:\Program Files (x86)\BMC Software\ARSystem\DeveloperStudio\plugins\com.bmc.arsys.studio.api_7.5.0\lib).

Speaking of Java APIs, you can use theme on the platform that you prefer: I copied mine from my Windows 7 virtual machine to my Mac.

Of course, the only caveat is to copy them in a directory wich is in the classpath.

The program

Here is the code for the qualdecoder.java script

import java.util.List;
import java.util.Scanner;
import com.bmc.arsys.api.ARException;  
import com.bmc.arsys.api.ARServerUser;  
import com.bmc.arsys.api.Constants;  
import com.bmc.arsys.api.QualifierInfo;
import com.bmc.arsys.api.Field;
  
public class qualdecoder {  
    public static void main(String[] args) throws ARException {  
    	ARServerUser ars; 
        String serverName = "servername.com";  
        String userName = "USERNAME";  
        String userPassword = "PASSWORD";  
        Scanner input = new Scanner( System.in );
    
        System.out.println("Qualification:");
        String qualification = input.nextLine();
   
        System.out.println("Form name:");
        String formName = input.nextLine();
     
        input.close();
         
        ars = new ARServerUser();  
        ars.setServer(serverName);  
        ars.setUser(userName);  
        ars.setPassword(userPassword);  
        
    	QualifierInfo myQual = ars.decodeQualification(qualification);
    	List fields = ars.getListFieldObjects(formName);
    	String decoded = ars.formatQualification(myQual, fields, fields,Constants.AR_QUALCONTEXT_DEFAULT,false );
    	System.out.println("Decoded qualification: \n"  + decoded + "\n");
    }  
}

Let’s discuss the more interesting parts.

First the script asks the user to enter the encrypted qualification and the name of the form it uses: infact Remedy store field names using a code which is relative form in which the field is set.

Then the magic happens.

End notes

It’s just an example.