Getting the workitems through plain java API
hi,I want to get all of the workitems of one project area.
//My code
IAuditableClient auditableClient = (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
IQueryClient queryClient = (IQueryClient) teamRepository.getClientLibrary(IQueryClient.class);
IQueryableAttributeFactory factory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);
IQueryableAttribute attribute = factory.findAttribute(projectareaname,IWorkItem.PROJECT_AREA_PROPERTY, auditableClient,null);
//
It accured an error as follows:
Exception in thread "main" com.ibm.team.repository.common.transport.ServiceMethodInvocationError: java.lang.IllegalStateException: Unable to find type for com.ibm.team.workitem.Attribute
How can I resolve it?
Thanks.
//My code
IAuditableClient auditableClient = (IAuditableClient) teamRepository.getClientLibrary(IAuditableClient.class);
IQueryClient queryClient = (IQueryClient) teamRepository.getClientLibrary(IQueryClient.class);
IQueryableAttributeFactory factory = QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);
IQueryableAttribute attribute = factory.findAttribute(projectareaname,IWorkItem.PROJECT_AREA_PROPERTY, auditableClient,null);
//
It accured an error as follows:
Exception in thread "main" com.ibm.team.repository.common.transport.ServiceMethodInvocationError: java.lang.IllegalStateException: Unable to find type for com.ibm.team.workitem.Attribute
How can I resolve it?
Thanks.
2 answers
Hi,
his code has worked for me in the past. Please note, it passes the project area object and not the name.
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();
his code has worked for me in the past. Please note, it passes the project area object and not the name.
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();
Comments
Hi, Ralph, I think you have given a very useful example. My question is if query the enum custom attribute, how to create teh expression? I know such code, but for line 2, Identifier.create(), which class should I use for custom enum attribute? Thanks!
String severity_2="severity.literal.l08"; Identifier sIdentifier2 = Identifier.create(com.ibm.team.workitem.common.model.ISeverity.class,severity_2); IQueryableAttribute customAttribute = findAttribute(projectArea, auditableClient, "test", monitor); AttributeExpression customAttrExpression= new AttributeExpression(customAttribute, AttributeOperation.EQUALS, sIdentifier2);
1 vote
Hi, Ralph, I think you have given a very useful example.
My question is if query the enum custom attribute, how to create teh expression?
I know such code, but for line 2,
Identifier.create(), which class should I use for custom enum attribute?
Thanks!
String severity_2="severity.literal.l08";
Identifier sIdentifier2 = Identifier.create(com.ibm.team.workitem.common.model.ISeverity.class,severity_2);
IQueryableAttribute customAttribute = findAttribute(projectArea, auditableClient, "test", monitor);
AttributeExpression customAttrExpression= new AttributeExpression(customAttribute, AttributeOperation.EQUALS, sIdentifier2);
I post again since the comment has no format..