It's all about the answers!

Ask a question

list all WorkItems of one Project Area


Paulino Alonso (381215) | asked Jul 24 '12, 6:32 a.m.
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

Accepted answer


permanent link
Ralph Schoon (63.3k33646) | answered Jul 24 '12, 7:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jul 24 '12, 7:37 a.m.
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

Comments
Ralph Schoon commented Jul 24 '12, 7:36 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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
Jared Russell (1.3k12019) | answered Jul 24 '12, 6:51 a.m.
 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.

permanent link
Paulino Alonso (381215) | answered Jul 24 '12, 7:00 a.m.
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


permanent link
Paulino Alonso (381215) | answered Jul 24 '12, 10:07 a.m.
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.


permanent link
Ralph Schoon (63.3k33646) | answered Jul 24 '12, 10:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

permanent link
Paulino Alonso (381215) | answered Jul 24 '12, 11:09 a.m.
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;

Comments
Ralph Schoon commented Jul 24 '12, 11:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


permanent link
Paulino Alonso (381215) | answered Jul 25 '12, 5:16 a.m.
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

permanent link
Paulino Alonso (381215) | answered Jul 25 '12, 5:18 a.m.
Sorry, I´m asking for this

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

Thanks

permanent link
Ralph Schoon (63.3k33646) | answered Jul 25 '12, 5:44 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi Paulino,

I would try

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

I haven't tested this however.

Comments
Ralph Schoon commented Jul 25 '12, 5:49 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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

IWorkItemServer.getAuditableServer()


permanent link
Paulino Alonso (381215) | answered Jul 25 '12, 7:44 a.m.
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

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.