Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

list all WorkItems of one Project Area

Hello,

I´m working with a Follow up that extends AbstractService and implements IOperationParticipant ...

I need to list all WorkItems of one Project Area, to get especifics values of atributes for each WI...



With this I list all attributes but not the values....

List<IWorkItemType> listaWIT=workItemServer.findWorkItemTypes(pa, monitor);
Iterator<IWorkItemType> iterW =listaWI2.iterator();
while (iterW.hasNext()){
         List<IAttributeHandle> listaAtt=iterW.next().getCustomAttributes();
         Iterator<IAttributeHandle> iterAtt=listaAtt.iterator();
                        while (iterAtt.hasNext()){
                            IAttribute  attribute= auditableServer.resolveAuditable(
                                         iterAtt.next(),
                                         ItemProfile.<IAttribute>createFullProfile(IAttribute.ITEM_TYPE),
                                         monitor);
                            //attribute.getValue() ------>I need something like that....????
                          }
}

Anyone know any solution???

thanks

1 vote


Accepted answer

Permanent link
You can get all work items like this

        IWorkItemClient  workItemService = (IWorkItemClient) targetRepository
            .getClientLibrary(IWorkItemClient.class);
        IQueryClient queryClient = workItemService.getQueryClient();
        IAuditableClient auditableClient = (IAuditableClient)targetRepository.getClientLibrary(IAuditableClient.class);
        IQueryableAttribute attribute=QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE).findAttribute(targetProjectArea, IWorkItem.PROJECT_AREA_PROPERTY, auditableClient, monitor);
        Expression inProjectArea= new AttributeExpression(attribute,AttributeOperation.EQUALS, targetProjectArea);
        IQueryResult<IResolvedResult<IWorkItem>> results=queryClient.getResolvedExpressionResults(targetProjectArea, inProjectArea,IWorkItem.SMALL_PROFILE);
        results.setLimit(Integer.MAX_VALUE);

        while (results.hasNext(monitor)) {
            IResolvedResult<IWorkItem> resresult = (IResolvedResult<IWorkItem>) results.next(monitor);
            IWorkItem item = resresult.getItem();
            System.out.println(item.getId()+" " + item.getHTMLSummary().toString());                       
..... }

You can get the attributes using workitem.get.... for some of the build in attributes.
You can get all built in attributes using

         List<IAttributeHandle> builtInAttributeHandles = workItemClient.findBuiltInAttributes(projectArea, monitor);
        IFetchResult builtIn = teamrepository.itemManager().fetchCompleteItemsPermissionAware(builtInAttributeHandles, IItemManager.REFRESH, monitor);
 
You can get all custom attributes using

       List<IAttributeHandle> custAttributeHandles = workItem.getCustomAttributes();
        IFetchResult custom = teamrepository.itemManager().fetchCompleteItemsPermissionAware(custAttributeHandles, IItemManager.REFRESH, monitor);

The result is in builtIn.getRetrievedItems()

You can access all attributes provide you have the IAttribute like this:

            if(workItem.hasAttribute(iAttribute)){
                Object value = workItem.getValue(iAttribute);
                if(value != null){
                    outStr=value.toString();
                }               
            }

You have to cast based on the attribute type.

Paulino Alonso selected this answer as the correct answer

1 vote

Comments

Be aware that this is client code. You will have to find the right services that provide this. You can get to the ITeamReposiory using .getOrigin() at the work item.


14 other answers

Permanent link
 To answer your specific question, in order to get the value of a work item's attribute you need to call the IWorkItem#getValue(IAttribute) method.

I don't think that what you're trying to do is a good idea for an operation participant, as every time a user saves a work item the server will have to iterate through every single work item. This will cause the save operation to take a very long time.

1 vote


Permanent link
Jared thanks for your response.

I know
call the IWorkItem#getValue(IAttribute) method only for the WI is throwing the action...

But I need the same for the rest of WI...and i dont know how...

Do you know how list all WI´s objects??

thanks

0 votes


Permanent link
Thanks for your info....

With your code I have this error:

Internal Error. Unable to instantiate participant com.ibm.san.propagator.action.participant.
CRJAZ6011E The operation participant cannot be created because an exception occurred. For more information, see the exception.

0 votes


Permanent link
I would suggest debugging it in the development environment like described in https://jazz.net/library/article/1000 and its predecessors.

As mentioned in the comment this is client code that runs in the Plain Java Client Libraries - I have no time to re write all that code for a participant. This is what I can offer right now. It should give you an idea how to approach the API.

You probably want to replace all getClientLibrary() calls by getService() and you also have to look which service replaces the client library.

If you want to use services you need to add them into the prerequisites in the plugin.xml. The UI and the logs should provide you with more information about the exception.

0 votes


Permanent link
Thank you very much Ralph!!!

With this works...

import com.ibm.team.workitem.service.IAuditableServer;
import com.ibm.team.workitem.service.IQueryServer;
import com.ibm.team.workitem.service.IWorkItemServer;

0 votes

Comments

Great Paulino, if you are so kind, accept the best answer.


Permanent link
Do you know how complete the items like participant? (Abstract Service)

item.getCustomAttributes();-> is empty....

 IFetchResult builtIn = teamrepository.itemManager().fetchCompleteItemsPermissionAware(builtInAttributeHandles, IItemManager.REFRESH, monitor);


Thanks

0 votes


Permanent link
Sorry, I´m asking for this

List<iattributehandle> custAttributeHandles = workItem.getCustomAttributes();
        IFetchResult custom = teamrepository.itemManager().fetchCompleteItemsPermissionAware(custAttributeHandles, IItemManager.REFRESH, monitor);

Thanks

0 votes


Permanent link
Hi Paulino,

I would try

            IAuditableServer aServer = getService(IAuditableServer.class);
            aServer.resolveAuditablesPermissionAware(handles, profile, monitor);

I haven't tested this however.

0 votes

Comments

I just realized you can get the Auditable server and Common from the IWorkitemServer

IWorkItemServer.getAuditableServer()


Permanent link
Ralph,

I´m trying this code but not run like I want...

List<IAttributeHandle> customAtr=item.getCustomAttributes();

List<IAttribute>  listAu=auditableServer.resolveAuditablesPermissionAware(customAtr, ItemProfile.<IAttribute>createFullProfile(IAttribute.ITEM_TYPE), monitor);

//List<IAttribute>  listAu3=auditableServer.resolveAuditables(customAtr, ItemProfile.<IAttribute>createFullProfile(IAttribute.ITEM_TYPE), monitor);

NOTE:
customAtr.size() = 0 ---->I think this is the problem...
listAu.size() = 0
listAu3.size() = 0

thanks

0 votes

1–15 items
page 1of 1 pagesof 2 pages

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Jul 24 '12, 6:32 a.m.

Question was seen: 10,496 times

Last updated: Jul 30 '12, 6:30 p.m.

Confirmation Cancel Confirm