It's all about the answers!

Ask a question

How to fetch the all work flow states based on the every Work Item Type in IBM RTC using Java API?


ramesh m (13310) | asked Sep 07 '15, 9:41 a.m.
 Hi All,
 I want to display the All the Work flow states based on the selected Work Item Type. Please help me on this.

Regards,
Ramesh M

2 answers



permanent link
Arne Bister (2.6k12832) | answered Sep 07 '15, 5:36 p.m.
JAZZ DEVELOPER
edited Sep 07 '15, 5:38 p.m.
Ramesh,

starting from
IWorkItemHandle wiHandle;
you need to resolve this to a full work item:
IAuditableCommon auditableCommon = (IAuditableCommon) teamRepository.getClientLibrary(IAuditableCommon.class);
IWorkItem workItem = auditableCommon.resolveAuditable(wiHandle, IWorkItem.SMALL_PROFILE, null);
Then obtain a workItemClient and use it to get an IWorkflowInfo object then use its .getAllStateIds method:
IWorkItemClient workItemClient = (IWorkItemClient) teamRepository
                    .getClientLibrary(IWorkItemClient.class);
IWorkflowInfo workflowInfo = workItemClient.findWorkflowInfo(workItem, monitor);
List< IState> allStates = workflowInfo.getAllStateIds();
If you want the names of the states, loop over the list and use
workflowInfo.getStateName();

If this is helpful please mark the answer as accepted.
- Arne


Comments
ramesh m commented Sep 08 '15, 8:34 a.m.

 HI Arne,

             Thanks for the clear explanation. bu i am getting null pointer exception on below.
Please assist on below.

        IAuditableCommon auditableCommon = (IAuditableCommon) repository.getClientLibrary(IAuditableCommon.class);

 how to initialize the IWorkItemHandle wiHandle;

Regards,
Ramesh


Arne Bister commented Sep 08 '15, 8:52 a.m.
JAZZ DEVELOPER

Ramesh,

please work through https://jazz.net/library/article/1000 to be up to par with terminology.
Then please describe where you are starting from. Are you using a client plugin, a server side extension or are you e.g. writing a java script against Plain Java API?

In either case at one point you need to query for a work item by name, by id or some other mechanism. Please cp. the excellent article from Ralph Schoon on work item querying: https://rsjazz.wordpress.com/2012/11/19/using-expressions-for-automation/

Using any such technique will leave you with either a valid IWorkItemHandle or possibly already a full IWorkItem.
Once you log in (basic exercise in workshop or the snippets shipped with Plain Java SDK) from the session you can obtain the necessary ITeamRepository object.

Then you should be all set.

gg,
Arne


permanent link
ramesh m (13310) | answered Sep 09 '15, 9:52 a.m.
 Hi All ,
I found the solutions to retrive the all the states based on the work item type. Please find code from below.

First Step1 :
 ITeamRepository iTeamRepository ; Login in to RTC

IWorkItemCommon workItemCommon = (IWorkItemCommon) iTeamRepository.getClientLibrary(IWorkItemCommon.class);

Step2 : use Work Item Common get the Work item types:
List<IWorkItemType> workItemTypes = null;
workItemTypes = workItemCommon.findWorkItemTypes(projectArea, monitor);

Step3:
IWorkItemClient workItemClient = (IWorkItemClient) iTeamRepository.getClientLibrary(IWorkItemClient.class);

Step4:
IWorkItemWorkingCopyManager workingManager = workItemClient.getWorkItemWorkingCopyManager();

Step5:
Iterate the work item types to get states:
List status = new ArrayList();
for (IWorkItemType iworkItemType : workItemTypes) {
wc = workingManager.getWorkingCopy(workingManager.connectNew(iworkItemType, monitor));
workFlowInfo = workItemCommon.findWorkflowInfo(wc.getWorkItem(), monitor);
states = workFlowInfo.getAllStateIds();
for (Identifier<IState> identifier : states) {
                                       sysout(workFlowInfo.getStateName(identifier))
status.add(workFlowInfo.getStateName(identifier));
}
}

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.