It's all about the answers!

Ask a question

Getting the workitems through plain java API


xuan li (111) | asked Jul 16 '12, 4:32 a.m.
retagged Jul 16 '12, 9:28 a.m. by Evan Hughes (2.4k1318)
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.

2 answers



permanent link
Ralph Schoon (63.2k33646) | answered Jul 16 '12, 5:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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();


Comments
1
Jia Jia Li commented Sep 04 '12, 1:54 p.m.

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);


permanent link
Jia Jia Li (8057152192) | answered Sep 04 '12, 1:55 p.m.
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..

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.