It's all about the answers!

Ask a question

Create a work item programatically


Alexander Clary (133) | asked Jun 05 '18, 7:35 p.m.
edited Jun 05 '18, 7:36 p.m.

 We want to configure our Java-based Springboot web application to be able to create work items on demand. 


First I started with this example I found after searching: https://jazz.net/wiki/bin/view/Main/WorkItemExampleSource

Then I downloaded and extracted the Rational Plain Java API libraries from here: https://jazz.net/downloads/rational-team-concert/releases/6.0.5/RTC-Client-plainJavaLib-6.0.5.zip and added them to my project as external JARs. It still failed, with an error about missing an eclipse core class, so I searched for that and downloaded org.eclipse.core.expressions-3.4.300.jar from https://mvnrepository.com/artifact/org.eclipse.core/org.eclipse.core.expressions/3.4.300 and added it as an external JAR as well. 

This time it ran, but failed due to lack of arguments, so I added some. Now it fails with this error:

Exception in thread "main" com.ibm.team.repository. <wbr> common.transport. <wbr> ServiceMethodInvocationError: java.lang.NoSuchMethodError: com.ibm.team.repository. <wbr> common.internal.util.ItemUtil. <wbr> isProvisionalAndDisabled(Lorg/ <wbr> eclipse/emf/ecore/ <wbr> EModelElement;)Z

                at com.ibm.team.repository. <wbr> transport.client. <wbr> RemoteTeamService. <wbr> getAppropriateException( <wbr> RemoteTeamService.java:737)

                at com.ibm.team.repository. <wbr> transport.client. <wbr> RemoteTeamService. <wbr> executeMethod( <wbr> RemoteTeamService.java:573)

                at com.ibm.team.repository. <wbr> transport.client. <wbr> RemoteTeamService.invoke( <wbr> RemoteTeamService.java:202)

                at com.ibm.team.repository. <wbr> transport.client. <wbr> ServiceInvocationHandler. <wbr> invoke( <wbr> ServiceInvocationHandler.java: <wbr> 43)

                at com.sun.proxy.$Proxy0. <wbr> describe(Unknown Source)

                at sun.reflect. <wbr> NativeMethodAccessorImpl. <wbr> invoke0(Native Method)

                at sun.reflect. <wbr> NativeMethodAccessorImpl. <wbr> invoke( <wbr> NativeMethodAccessorImpl.java: <wbr> 62)

                at sun.reflect. <wbr> DelegatingMethodAccessorImpl. <wbr> invoke( <wbr> DelegatingMethodAccessorImpl. <wbr> java:43)

                at java.lang.reflect.Method. <wbr> invoke(Method.java:498)

                at com.ibm.team.repository. <wbr> client.internal. <wbr> ServiceInterfaceProxy. <wbr> invokeServiceCall( <wbr> ServiceInterfaceProxy.java: <wbr> 254)

                at com.ibm.team.repository. <wbr> client.internal. <wbr> ServiceInterfaceProxy.invoke( <wbr> ServiceInterfaceProxy.java: <wbr> 110)

                at com.sun.proxy.$Proxy0. <wbr> describe(Unknown Source)

                at com.ibm.team.repository. <wbr> client.internal. <wbr> TeamRepository$4.run( <wbr> TeamRepository.java:1564)

                at com.ibm.team.repository. <wbr> client.internal. <wbr> TeamRepository$4.run( <wbr> TeamRepository.java:1)

                at com.ibm.team.repository. <wbr> client.internal. <wbr> TeamRepository$3.run( <wbr> TeamRepository.java:1327)

                at com.ibm.team.repository. <wbr> common.transport. <wbr> CancelableCaller.call( <wbr> CancelableCaller.java:79)

                at com.ibm.team.repository. <wbr> client.internal. <wbr> TeamRepository. <wbr> callCancelableService( <wbr> TeamRepository.java:1322)

                at com.ibm.team.repository. <wbr> client.internal. <wbr> TeamRepository.internalLogin( <wbr> TeamRepository.java:1557)

                at com.ibm.team.repository. <wbr> client.internal. <wbr> TeamRepository.login( <wbr> TeamRepository.java:653)

                at com.ibm.team.repository. <wbr> client.internal. <wbr> TeamRepository.login( <wbr> TeamRepository.java:627)

                at com.ibm.team.workitem.ide.ui. <wbr> example.CreateWorkItem.run( <wbr> CreateWorkItem.java:117)

                at com.ibm.team.workitem.ide.ui. <wbr> example.CreateWorkItem.main( <wbr> CreateWorkItem.java:87)


I get this error even if all of my parameters are garbage except for the Rational server address, which I believe means it's able to connect but is having some trouble communicating. Isn't there some simple way to create work items in Rational using Java without spending weeks wading through mediocre documentation? Our Rational server is version 6.0.5.

Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered Jun 06 '18, 4:37 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jun 06 '18, 4:38 a.m.

The simplest  - and it does not get simpler from here - is to follow

https://jazz.net/wiki/bin/view/Main/ProgrammaticWorkItemCreation go to the section

Plain-Java Client

You should be able to cut and paste the code. You should only have to provide the Plain Java Client libraries.
The other example you downloaded is an addition to the Eclipse UI.

I would also suggest https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/
for some context.  https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ as a minimum.

Alexander Clary selected this answer as the correct answer

Comments
Alexander Clary commented Jun 06 '18, 9:14 p.m.

 Thanks that worked. One issue I ran into is that the work item type had to be in all lower case ("task"), even though when I pulled the list of types using fetchAllWorkITemTypesNames it returned results with capitalization ("Task"). Now I need to figure out how to set attributes like Description, Severity, Impact, etc. before it will let me save.


Ralph Schoon commented Jun 07 '18, 2:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

fetchAllWorkITemTypesNames it returned results with capitalization ("Task")

You want the type ID and not the name.

Now I need to figure out how to set attributes like Description, Severity, Impact, etc. before it will let me save.

I gave you the links above for a reason. I provide example code, explanation and background on https://rsjazz.wordpress.com/


Alexander Clary commented Jun 07 '18, 10:22 a.m.

Believe me, I have spent many hours reading that blog. I do appreciate all of the time you've put into helping people. I think the best long-term solution would be for someone to write a wrapper around the plain Java API called the Simple Java API, and all valuese are entered as key value pairs. Imagine how fun it would be to code like this:

IWorkItem workItem = workItemClient.createWorkItem("Task");
workItem.setAttribute("Summary", "Test Summary");
workItem.setAttribute("Severity", "High");
workItem.setAttribute("Owner", "John Doe");
workItem.addLink("Parent", "110256");
workItem.save();


Ralph Schoon commented Jun 07 '18, 10:29 a.m. | edited Jun 07 '18, 10:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Would be nice. I have pretty much all you'd need in the WorkItem CommandLine for that.
Realistically what you ask for is for scripting, because in an API you don't necessarily get all that stuff as a string. More often than not you also need some mapping.

But I agree you would like to have an API that might sacrifice performance and is a bit easier to understand. Mind you the work item API is just a small part of the APIs.

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.