Polarion ALM SDK API getWorkItem() - java

I have a question about the Polarion SDK API
I am in a Project -> Documents and Pages -> Testing.
From there I created a new wiki article.
In the editing of the article I did the following:
1) created a sql query using: #set ($sql_result = $sqlService.executeQuery("<sql query here>")
The sql query produces an array that looks like this:
[[project.c_id, test_cases.c_id , test_cases count ], [project.c_id, test_cases.c_id , test_cases count ], [project.c_id, test_cases.c_id , test_cases count ], [project.c_id, test_cases.c_id , test_cases count ]]
2) Now I would like to iterate through this multi-dimensional array by doing this:
#foreach($item in $sql_result)
$getWorkItem($item.get(0), $item.get(1)) <br>
#end
Unfortunately, Polarion does not appear to recognize the $getWorkItem(). I am pretty newbie at this, I'm sure I'm just calling the function incorrectly. I found the API Doc here: https://almdemo.polarion.com/polarion/sdk/doc/javadoc/index.html
It is in TrackerService.getWorkItem()
But I still don't know how to call the API correctly. Any help will be greatly appreciated.

You need to reference the instance of TrackerService which is in the Velocity context to be able to call getWorkItem(), something like:
$trackerService.getWorkItem($item.get(0), $item.get(1))
The main point is that you cannot call a method without a base object in Velocity.

Related

Read JSON with special character in keys using apache velocity

I have a JSON which has an attribute with its List type. Can someone help me on how to read the value in Apache Velocity template? Following is an example of JSON. The challenge is to read the list of University from JSON and iterate through it.
{
"StudentName":"XYZ",
"List<Univesity>": [
{
"Name": "NYU",
"City": "NY",
"Country":"US",
} ]
}
The solution is dependent upon the JSON library you use, but for many of them, the following code should work:
#set( $universities = $document.get('List<University>') )
#foreach( $university in $universities )
... do something ...
#end
The main point to note here is that you can call any Java method on the object you get.
Also, if the security uberspector is not present, for debugging purposes you can display the Java class name of any object in the context, for instance: $document.class.name should display, in your case, something like com.fasterxml.jackson.databind.node.ObjectNode.

Java API to implement query for script_fields in Elastic search

I have tried to find the answer of this question but couldn't find. The scenario is: I have to get one extra field which is the calculation of two fileds in the elastic search query result. For this purpose I am using script_fields.
"script_fields": {
"result": {
"script": "doc['feild1'].value / doc['field2'].value"
}
}
The query is working fine, and I am getting the correct result.
But now I have to implement the query in Java, I couldn't find any way to implement script_fields in Java.
Can somebody please help ?
Very simply using the addScriptField() method like this:
SearchResponse response = client().prepareSearch()
.setQuery(matchAllQuery())
.addScriptField("result", new Script(ScriptType.INLINE, "groovy", "doc['field1'].value / doc['field2'].value", Collections.emptyMap()))

Which is the proper way to work with complex types (lists and objects) in Jaspersoft?

Please consider a MongoDB collection with the following document:
"_id": "clientsInfo"
"data": {
"clientsList" : [
{
"name" : "Mike",
"country" : "USA"
},
...
]
}
After setting the DataSet and defining the Query like this...
{
collectionName:'projectA',
findQuery: {
'_id':'clientsInfo',
},
findFields: {
'_id':0,
'data.clientsList':1
},
}
...I am able to display the first item of the fetched array (java.util.List type) in JasperSoft Studio inside a Text Field using the following expression:
$F{data.clientsList}.get(0)
But, considering that I would like to exhibit the whole data in a Name/Country Table...
Question1: How could I access any of the dictionary fields? Trying get method I obtain The method get(String) is undefined for the type Object. error. However, knowing that the object is an instance of com.mongodb.BasicDBObject it should have that method inherited (See doc).
I have also tried to cast object to org.json.JSONObject but then I get net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: (JSONObject)$F{data.clientsList}.get(0) error.
Question2: Let's suppose we have already solved first question... How can I iterate the list to access not only the first item but all of them according to the array length? Is it possible to use for-loop sentence inside the JasperSoft Expression Editor? (if-then-else seems to be available)
Thanks in advance, Any clue that point me in the right direction will be appreciated.
Just in case someone was in the same situation as I was, I must say this whole approach was wrong.
It's not about making a simple query which returns big block of complex data formatted as an object or list of objects and then manipulate it with JasperSoft Studio. Instead, what I had to do was design a more elaborated query which returns the simple fields I wanted to use straightforward. How to do this? By using Aggregation Framework.
So, by changing this...
{
collectionName:'projectA',
findQuery: {
'_id':'clientsInfo',
},
findFields: {
'_id':0,
'data.clientsList':1
},
}
...for this...
{
runCommand: {
aggregate : 'projectA',
pipeline : [
{'$match': {'_id':'clientsInfo'}},
{'$project': {'data.clientsList': 1}},
{'$unwind': '$data'},
{'$unwind': '$data.clientsList'}
]
}
}
...is how I get name and country fields in order to use them in Text Fields, Tables, ...etc.

ElasticSearch script to update if the value not exist

I am trying to update an es document using Java.
My document is as follows
"_source": {
"gender": "male" ,
"names": ["name1"]
}
I need to add more names to names list. But I want no duplicates.
How can I update an array in an ES document without duplicate values?
I tried something like this. But it's not working.
client.prepareUpdate(index,type,id)
.addScriptParam("newobject", "newName")
.setScript("ctx._source.names.contains(newobject) ? ctx.op = \"none\" : ctx._source.names+=newobject ").execute().actionGet();
The idea would be to simply call unique() on the resulting list:
client.prepareUpdate(index,type,id)
.addScriptParam("newobject", "newName")
.setScript("ctx._source.names+=newobject; ctx._source.names = ctx._source.names.unique(); ").execute().actionGet();
Also for this to work, you need to make sure that scripting is enabled.

Workaround on Scraping HTML by diving into js source code

I learn about jSoup recently and would like to dive more into it. However, I have met obstacle handling webpages with javascript (I have no knowledge in js, yet :/).
I have read that htmlunit would be the correct tool to perform webbrowser actions, but I figured out that I would need no knowledge in js if I can find out the JSON object obtained in the webpage using the javascript.
For example, this page:
among the source files, one of them is tooltips.js. In this file, variable rgNeededFeeds is generated and called in method LoadHeropediaData(), which is the method to generate the whole URL link for getting the json object.
URL = URL + 'jsfeed/heropediadata?feeds='+strFeeds+'&v=3633666222511362823&l=english';
I could not get my mind on what is actually strFeeds. I have tried various combinations but it doesn't work (it returned an empty array...). Or, my guess is totally off?
What I actually need is the data it displays on top when you click on one of the "items". The info in the "hover" would do too, but it lack the "recepi" info. And I'm presuming that by getting the json object from the full URL above, well, basically all data infos should be in that json.
Anyways, this is only based on what I understand from staring at those source files for hours. Do correct me if I'm wrong. (I'm in Java by the way)
**p/s: I would also like to take this opportunity to express my thanks to Balusc, he has been everywhere when I have doubts on jSoup. :>*
strFeeds is nothing but one of these two strings : itemdata or abilitydata
You can find this in tooltips.js at line 38-45
var rgNeededFeeds = [];
$.each( [ 'item', 'ability' ],
function( i, ttType ){
icons = GetIconCollection( ttType );
if ( icons.length ){
rgNeededFeeds.push( ttType+'data' );
//..............
}
}
)
ttType is the value of an iteration over the array [ 'item', 'ability' ] which concatenated with the string data is pushed into the array rgNeededFeeds
The function LoadHeropediaData is called at the end of the function above with rgNeededFeeds as parameter :
LoadHeropediaData( rgNeededFeeds );
Aside note : If you begin to start scraping websites, learning javascript will be MANDATORY.
NOTE : you're right, the JSON contains all the information needed...

Categories

Resources