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
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
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.
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.
14 other answers
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.
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.
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.
Hi Paulino,
I would try
IAuditableServer aServer = getService(IAuditableServer.class);
aServer.resolveAuditablesPermissionAware(handles, profile, monitor);
I haven't tested this however.
I would try
IAuditableServer aServer = getService(IAuditableServer.class);
aServer.resolveAuditablesPermissionAware(handles, profile, monitor);
I haven't tested this however.
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
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
page 1of 1 pagesof 2 pages