Skip to Content

This wiki link already covers how to extract information from ESR / ID objects . This works fine for checking a single object. However, sometimes we may need to extract metadata of all PI objects ( for instance, to find all objects modified after a certain date ) or even analyse the source code ( to find all objects using a certian Java function / Value map ).

Through this blog, I’ll show how we can automate reading SimpleQuery.

Looking at the SimpleQuery structure in terms of HTML pages in the below image, the information we need is in the step highlighted in the Green box below.

/wp-content/uploads/2015/03/image1_671623.png

How to automate filling this information ?

Here we’ll use HtmlUnit. From it’s homepage link description : HtmlUnit is a “GUI-Less browser for Java programs”. It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc… just like you do in your “normal” browser.

For our example, we’re interested in filling up the below page.

/wp-content/uploads/2015/03/1_671689.png

/wp-content/uploads/2015/03/2_671693.png

We will need to run some tests to see what the default values are for each of the fields.

The general sequence of steps is:

– Create an instance of WebClient

WebClient webClient = new WebClient();

– Encode {username:password} using base 64 encoding and update the header


  setCredentials(webClient);


It can be implemented as


private static void setCredentials(WebClient _webClient) {

  String base64encodedUsernameAndPassword = base64Encode(combinePasswd);

  _webClient.addRequestHeader(“Authorization”, “Basic “

  + base64encodedUsernameAndPassword);

  }

– Create an instance of HtmlPage and get the form by checking the body

HtmlPage currentPage = webClient.getPage(url);

HtmlForm form = (HtmlForm) currentPage.getByXPath(“/html/body/form”).get(0);

– Once we have the form, select different objects, set/ unset values

// Get SWC

  HtmlRadioButtonInput choseSWC = form

  .getInputByValue(“All software components”);

  choseSWC.click();

//Unclick changeList User

HtmlCheckBoxInput changeListUser = form.getInputByName(“changeL”);

changeListUser.click();

– Click the Start Query button to get the result page.

HtmlSubmitInput submit = form.getInputByValue(“Start query”);

HtmlPage resultPage = submit.click();

This page will have all the links and we can convert it nicely to a String.

String resultPageText = resultPage.asXml().toString();

I wanted to keep this blog brief to focus on automating getting the result page.

This github link has the source code. Please make sure you have HtmlUnit library added to your project. You can run the source code – just adapt the static variables in the beginning of the file – SimpleQuery url , user and password.

We can now build up this knowledge to get more information. I’ll take two use cases:


–  Compare map versions between two PI systems.


Extract graphical maps using value mappings.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Michal Holic

    Great article. This is also possible to do directly in java with com.sap.aii.repclient module. Something like:

    QueryService queryService = new QueryService(repConnectionSettings);

    QueryResult queryResult = queryService.generalQuery(queryDefinition);

    Sadly I have not found a way to create / edit objects in ESR. Don’t you by chance know how to do it?

    (0) 

Leave a Reply