It's all about the answers!

Ask a question

Can anyone please provide a sample java client which will get all the attributes and the values of the specified workitem


Trilok Chand (3133) | asked Feb 10 '14, 8:00 a.m.
Can anyone please provide a sample java client which will get all the attributes and the values of the specified workitem

2 answers



permanent link
Ralph Schoon (63.1k33645) | answered Feb 10 '14, 8:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You can get at the built in attributes from somewhere else:

		log("WorkItem: " + workItem.getId() + " "
				+ workItem.getHTMLSummary().getPlainText() + "\t Type "
				+ workItemType.getDisplayName() + "\n");
		List builtInAttributeHandles = getWorkItemClient()
				.findBuiltInAttributes(fProjectArea, monitor);
		IFetchResult builtIn = getTeamRepository().itemManager()
				.fetchCompleteItemsPermissionAware(builtInAttributeHandles,
						IItemManager.REFRESH, monitor);
		List custAttributeHandles = workItem
				.getCustomAttributes();
		IFetchResult custom = getTeamRepository().itemManager()
				.fetchCompleteItemsPermissionAware(custAttributeHandles,
						IItemManager.REFRESH, monitor);
		log(builtIn.getMissingItems().size() + " "
				+ builtIn.getNotFoundItems().size() + " "
				+ builtIn.getPermissionDeniedItems().size() + " "
				+ builtIn.getRetrievedItems().size() + "\n");
		printAttributes(workItem, builtIn.getRetrievedItems());
		printAttributes(workItem, custom.getRetrievedItems());


You can find more information about e.g. casting here: https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/

Comments
Trilok Chand commented Feb 10 '14, 8:30 a.m.

Below is my example i am trying...

List builtInAttributeHandles = workItemClient.findBuiltInAttributes(projectArea, null);

    for (Iterator iterator = builtInAttributeHandles.iterator(); iterator.hasNext();) {

        IAttributeHandle iAttributeHandle = (IAttributeHandle) iterator.next();
        IAttribute iAttribute = (IAttribute) repository.itemManager().fetchCompleteItem(iAttributeHandle, IItemManager.DEFAULT ,null);

        System.out.println("getIdentifier->"+ iAttribute.getIdentifier());
        System.out.println("getAttributeType->"+ iAttribute.getAttributeType());
        System.out.println("getDisplayName->"+ iAttribute.getDisplayName());
        System.out.println("getFullTextKind->"+ iAttribute.getFullTextKind());


        IAttribute someAttribute= workItemClient.findAttribute(projectArea, iAttribute.getIdentifier(), null);
    }

Just want to use this someAttribute variable to get the workItem and finally to print the value of the attribute...

Can you please help me in this... Or please if you have any class file, you can share me... I will refer to that and complete the rest.. Thanks


permanent link
Piotr Aniola (3.7k11738) | answered Feb 10 '14, 8:10 a.m.
List<IAttributeHandle> customAttributeHandles = workitem
                .getCustomAttributes();
        for (IAttributeHandle attributeHandle : customAttributeHandles) {
            IAttribute attribute = (IAttribute) teamRepository.itemManager()
                    .fetchCompleteItem(attributeHandle, IItemManager.DEFAULT,
                            null);
            //.... do something with attribute.
        }

Please note that this only fetches custom attributes.
I'm not sure if it's possible to fetch all attributes. You normally access built-in attributes, by their individual getters and setters, for example:
workitem.getDueDate(...)

Comments
Trilok Chand commented Feb 10 '14, 8:18 a.m.

Hi,
Thanks for the reply. I am looking for a method or a simple class which prints the attributes and also its corresponding values for the given workitem.

Thanks,


Ralph Schoon commented Feb 10 '14, 8:25 a.m. | edited Feb 10 '14, 8:25 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I guess you have to write that yourself as I did below.
The methods below get the data, cast it and print it.


sam detweiler commented Feb 10 '14, 11:39 a.m.

see the function static void printAttributes(IWorkItem workItem, 
            IAuditableClient auditableClient, IProjectArea projectArea, 
            org.eclipse.core.runtime.IProgressMonitor monitor, ITeamRepository repository, String XML) 


in post 2 of this topic 

this will print the details for all attributes of a workitem
 

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.