Skip to Content
Author's profile photo Vikas Singh

Compare map versions between two PI systems

In this blog, I’ll extend to what we learnt in this blog ( link ) about populating SimpleQuery Parameters and getting metadata about ESR Objects. We’ll get the maps in system 1 and compare them with the map version in system 2.

We can visualise the process as in the below simple diagram.

Screen Shot 2015-03-26 at 12.56.30 pm.png

SimpleQuery gives us information in the below format with R being a hyperlink to the metadata of the graphical map.


Clicking the link we get information in the below format.

Here, element idInfo’s attribute VID has the message map id which represents a unique version of the map.


It’s interesting to get some more information apart from version ID. So we can create a Class to hold the attributes we’re interested in.

String SID;
String mapName;
String version;
String modifBy;
String modifAt;
String SWCV;
String namespace;

Now, we have the required information to build our required program. Before moving ahead, let me introduce to one more friend: jsoup

From it’s webpage:  jsoup is a Java library for working with real-world HTML. It provides a very convenient API for extracting and manipulating data, using the best of DOM, CSS, and jquery-like methods.

it’s my personal rule of thumb – for filling out pages etc I prefer HtmlUnit and for just extracting information from a web page I prefer using jsoup. Ofcourse,

we can use only HtmlUnit but I’ll leave that as an exercise for you to do  🙂 .

The structure of the program will be something along these lines:

– Retrieve all the links

String resultPageTextSys1 = fillSimpleQueryParams(usrSys1,  combinePasswdSys1);

Document docSys1 = Jsoup.parse(resultPageTextSys1, “UTF-8”);

Elements linksSys1 =“a[href]”);

– for each link, get the HTTP response

– “Cleanse” the output as jsoup doesn’t work well with the <p1> , <tr> etc tags we have in the response. It could be implemented as follows:

static String removeExtraTags(HttpEntity responseEntity) throws IOException {

  String content = EntityUtils.toString(responseEntity);

  content = content.replace(“<p1:”, “<“);

  content = content.replace(“</p1:”, “</”);

  content = content.replace(“<tr:”, “<“);

  content = content.replace(“</tr:”, “</”);

  return content;


– Retrieve a Document and parse it to retrieve SWCV, namespace, Version ID, modifyBy, modifyAt .

for (Element e :“xiObj”)) {

  MappingObject map = new MappingObject();

  for (Element e1 :“idInfo”)) {

  for (Element e2 :“vc”)) {

  String SWCV = e2.attr(“caption”);




– Add this map information to a List.

– Repeat the same process for information from the second system as well.

If we have m is the processing time from sys1 and n from sys2, the processing time will be in order of O(m*n).

To make processing faster, sort the smaller list. For instance, if comparing the information between dev and prod systems, we’ll sort the prod list as we need to iterate on the dev list and search the prod list to check if the prod version is the same. We’ll also have more maps in development system which may be missing in prod system and iterating over dev and then searching in prod list will ensure that we’re not missing any maps.

– To allow sorting of the list, implement a Comparator. As maps can span across SWCVs and namespaces, we need to consider them as well ins order. Else, we can get unexpected results.

Collections.sort(sys2Maps, MappingObject.MapNameComparator);

public static Comparator<MappingObject> MapNameComparator = new Comparator<MappingObject>() {

public int compare(MappingObject map1, MappingObject map2) {

String mapName1 = map1.getMapName().toUpperCase();
String mapName2 = map2.getMapName().toUpperCase();
String ns1 = map1.getNamespace();
String ns2 = map2.getNamespace();
String swcv1 = map1.getSWCV();
String swcv2 = map2.getSWCV();
String str1 = mapName1.concat(ns1.concat(swcv1));
String str2 = mapName2.concat(ns2.concat(swcv2));

// ascending order
return str1.compareTo(str2);



– Now try to find the corresponding map for the map at the current iterator value.

MappingObject sys2Map = new MappingObject();

index = Collections.binarySearch(sys2Maps, sys1Map,MappingObject.MapNameComparator);

– We can use Apache POI libraries to write the information to a spreadsheet.

Information will appear in the below format.


This github link has the full source code. Make sure you have the required libraries from Apache POI , HtmlUnit & jsoup and you should be able to extract the information.You can run the source code – just adapt the static variables in the beginning of the file.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.