It's all about the answers!

Ask a question

Can a participant extension to RTC make API calls to non CLM servers?


Ryan McBryde (5911130) | asked Sep 29 '20, 1:01 p.m.

I have a participant that I built following the RTC Extensions Workshop and it works as advertised when executing a save of a work item in the RTC client launched from the Client Workspace.


I would now like to modify that basic participant code to communicate with another non-CLM application via REST API calls.  I have added the code and the necessary import statements to the participant java code and it executes correctly, ( I get a response code of 200 and the data being returned is 2191 characters in length.)

The problem that I am encountering is that I am using some json classes;  JSONException; JSONObject, JSONArray to process the data coming back from the Nexus API call, that looks like this:

[ {
  "name" : "docker-production",
  "format" : "docker",
  "type" : "hosted",
}, {
  "name" : "docker-staging",
  "format" : "docker",
  "type" : "hosted",
}, {
  "name" : "nuget.org-proxy",
  "format" : "nuget",
  "type" : "proxy",
},

My code builds without issue because I have added json.jar in my filesystem to the Build Path but when I try to execute the participant by forcing the state change that initiates it I am getting what I interpret is a runtime error, stating "java.lang. <wbr style="background-color: rgb(255, 255, 255); color: rgb(34, 34, 34); font-family: Arial, Helvetica, sans-serif; font-size: small;"> NoClassDefFoundError: org.json.JSONException".  

I can't seem to figure out how to get that jar file into the runtime classpath or even if that would solve the problem  and even tried add it as a bundle in the run configuration, with no success.

Any help or advice is appreciated.

Accepted answer


permanent link
Ralph Schoon (63.1k33646) | answered Oct 02 '20, 4:11 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Oct 03 '20, 5:24 a.m.

I have provided more than can be expected. There are training organizations, there are services. I can't provide more than I already did.

Ralph Schoon selected this answer as the correct answer

Comments
Ralph Schoon commented Oct 02 '20, 4:24 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

If you are interested in these topics, please read them up on my blog. there are enough examples. 

One other answer



permanent link
Ralph Schoon (63.1k33646) | answered Sep 30 '20, 8:47 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

A participant runs in an application server - the one you have installed EWM on.


Application servers have rules how they make libraries available. In your case, you have to bundle the libraries in the extension you create.  Since the extension mechanism is based on Eclipse, you have to look in the Eclipse project how you can do that. I have done this once in the past, but I don't know what I did in details any more.


Comments
Ryan McBryde commented Sep 30 '20, 9:42 a.m.

Thank you Ralph.

When you say, "have to bundle the libraries" are you referring to creating a bundle such as the ones that are added in the Bundles section of the Run Configuration of the server that we use in the workshop, "[RTCExt] Jetty RTC Server"?

I will research how one creates a bundle for a Run/Debug Configuration in Eclipse.

As far as you know, whatever the 'standard" process is for doing this would be applicable to the dev environment created for the workshop?

Any hints on where to start?  Besides google, is eclipse.org the best place to look?


Ralph Schoon commented Sep 30 '20, 9:50 a.m. | edited Sep 30 '20, 9:51 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

When I mean bundle, I mean it has to be available on the server. I have once, if I recall correctly, added the library to the Eclipse project for the advisor. So the library ended in the JAR file and was also accessible to the extension. 


So I had a subfolder lib/ in the plugin and some other settings in the plugin. 


Ryan McBryde commented Oct 01 '20, 9:52 a.m.

Ralph,


which allowed me to create a new "Plug-in Project from Existing JARS"  to which I added the json.jar.  Then I added that project to the list of Bundles in the Run Configuration and then the participant executed successfully when the client triggered it.

I was also able to modify the participant code to successfully execute the API call including the JSON class calls and correctly parse the response.  I would be glad to share it with you.

Thank you


Ralph Schoon commented Oct 01 '20, 10:45 a.m. | edited Oct 01 '20, 10:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Nice!


Please keep in mind that you have to integrate the bundle into the feature for publishing to deploy it on the application server for production usage.  

Also, there is some JSON support in the SDK, not sure if it is enough for you.


Ryan McBryde commented Oct 01 '20, 3:48 p.m.

Thank you Ralph,


I did find a number of json plugins from IBM, such as 
com.ibm.team.json,
com.ibm.team.repository.common.json

and was hopeful that I could use them but they did not seem to have what I needed, which was to retrieve a json array and step thru it. Would using them instead make the publishing less complicated?

Also, I was hoping that you could help me understand writing a value to an attribute on the work item. I found this code on your "working-with-work-item-attributes" blog.
IWorkItem workItem = IWorkItem workItem = workingCopy.getWorkItem();
Integer value = new Integer("4");
if (workItem.hasCustomAttribute(customInteger))
workItem.setValue(customInteger, value);
}
I would like to write a string variable to a custom string field named ryan on the WI that started the participant, can you share the correct setvalue statement with me to do so?



Ralph Schoon commented Oct 02 '20, 1:56 a.m. | edited Oct 02 '20, 2:01 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The code is the same you use, except you pass a String and not an Integer.
IWorkItem workItem = IWorkItem workItem = workingCopy.getWorkItem();
String value = "I am a String";
if (workItem.hasCustomAttribute(customInteger))
    workItem.setValue(customInteger, value);
}

Ralph Schoon commented Oct 02 '20, 2:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I corrected my comment above. 


Ryan McBryde commented Oct 02 '20, 10:27 a.m.

Thank you.


Is " customInteger" the id of the attribute from the Attributes section of the Types and Attributes page in the web client?

If my string attribute has the name of "Ryan" and the id of "ryan" my setvalue statement would read:

IWorkItem workitem = IWorkItem workitem = workingCopy.getWorkItem();
String value = "I am a String";
if (workitem.hasCustomAttribute(ryan))
     workitem.setValue(ryan,value);

Is this doubling of "IWorkItem workitem = " above correct?

I tried to insert that code, as is, into the run block of BuildOnStateChange.java and saw errors "IWorkItem cannot be resolved to a variable, workingCopy cannot be resolved to a variable, Syntax error, insert ":" to complete LocalVariableDeclarationStatement."

I used IWorkItem workitem = workingCopy.getWorkItem(); instead and now workingCopy and ryan are showing as unresolved


Ralph Schoon commented Oct 02 '20, 10:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Ryan, I have provided several examples on my blog, so I don't have to e-mail/forum train everyone. Look into https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ and how that works and why as in the text.  


Ralph Schoon commented Oct 02 '20, 10:47 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 IWorkItem workitem = workingCopy.getWorkItem(); would be correct the other statement should show an error.


Ryan McBryde commented Oct 02 '20, 3:06 p.m.

Thank you,


I get a message "workingCopy cannot be resolved" when I use that statement.

I want to write a value that I retrieved from API call to an attribute on the work item that initiated the participant.  I know the attribute name and id and I have the value stored in a variable.

Is there a library that I need to import?

I compared it to the update-parent-duration code which I have implemented previously and I see statements for the parent but not for the workitem itself and can't seem to extrapolate it for the workitem.

IWorkItem parent = (IWorkItem) fWorkItemServer
.getAuditableCommon()
.resolveAuditable(parentHandle, IWorkItem.FULL_PROFILE, monitor)
.getWorkingCopy();

parent = (IWorkItem) parent.getWorkingCopy();
 

showing 5 of 11 show 6 more comments

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.