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

RTC Java API Query for workitems created last 24h

Hello,

I' trying to write server side async task, that will be searching for workitems created in last 24h, that state was not changed. I'm using IQueryCommon and AttributeExpresion:

Date date = new Date();
Timestamp creationDate = new Timestamp(date.getTime()-(24*60*60*1000));
AttributeExpression creationDateExpression = new AttributeExpression(attribute, AttributeOperation.BEFORE, creationDate);

    

but this expression is not respecting time, only date. In WebUI when you create query, you can select option created in last xx hours:


Is it possible to create this kind of expression in Java API?

0 votes



2 answers

Permanent link

The code you show is incomplete. 


In the SDK I find:

assertResult(custom, AttributeOperation.BEFORE, new Timestamp(now.getTime() + ONE_DAY), copy.getWorkItem());

So, I assume you are following the correct approach, but there is something else going on.

the SDK code:

private void assertResult(IAttribute custom, AttributeOperation operator, Object value, IWorkItem expected) throws TeamRepositoryException {
IQueryResult<IResolvedResult<IWorkItem>> result= getResult(custom, operator, value);
assertEquals(1, result.getTotalSize(null));
IWorkItem resultItem= result.next(null).getItem();
assertEquals(expected.getId(), resultItem.getId());
}



private IQueryResult<IResolvedResult<IWorkItem>> getResult(IAttribute custom, AttributeOperation operator, Object value) throws TeamRepositoryException {
IQueryableAttributeFactory factory= QueryableAttributes.getFactory(IWorkItem.ITEM_TYPE);
IQueryableAttribute attribute= factory.findAttribute(fgProjectArea, custom.getIdentifier(), fgAuditableClient, null);
AttributeExpression expression= new AttributeExpression(attribute, operator, value);
IQueryResult<IResolvedResult<IWorkItem>> result= fgQueryClient.getResolvedExpressionResults(fgProjectArea, expression, IWorkItem.SMALL_PROFILE);
result.setLimit(10);
return result;
}

0 votes

Comments

Note in the server you would have to use IAuditableCommon and not the client. 


Permanent link
Hi Ralph,

here is full function used to find workitems in project area:
private List<IWorkItem> findWorkItems(IProjectAreaHandle projectArea, IProgressMonitor monitor)
            throws TeamRepositoryException {   

        List<IWorkItem> matchingWorkItems = new ArrayList<IWorkItem>();   

        try { 

            IQueryResult<IResolvedResult<IWorkItem>> result;      
        IQueryableAttribute attribute = findQueryableAttribute(projectArea,
                  IWorkItem.CREATION_DATE_PROPERTY, monitor);
            if (attribute == null)
                  return Collections.emptyList();      
            IWorkItemType escalationWItype = findWIType(projectArea, "Escalation", monitor);    

            if (escalationWItype == null)
                  return Collections.emptyList();
            Date now = new Date();

            AttributeExpression creationDateExpression = new AttributeExpression(attribute,
                   AttributeOperation.BEFORE, new Timestamp(now.getTime() - (24*60*60*1000+1000)));  
            IQueryableAttribute projectAreaAttribute = findQueryableAttribute(projectArea,
                   IWorkItem.PROJECT_AREA_PROPERTY, monitor);
            AttributeExpression projectAreaExpression = new AttributeExpression(projectAreaAttribute, 
                   AttributeOperation.EQUALS, projectArea);
            IQueryableAttribute stateAttribute = findQueryableAttribute(projectArea,
                   IWorkItem.STATE_PROPERTY, monitor);
            VariableAttributeExpression stateGroupExpression = new VariableAttributeExpression(
                   stateAttribute, AttributeOperation.EQUALS, 
new StatusVariable(IWorkflowInfo.OPEN_STATES_GROUP));                        IQueryableAttribute typeAttribute = findQueryableAttribute(projectArea, IWorkItem.TYPE_PROPERTY, monitor);                        AttributeExpression wiTypeExpression = new AttributeExpression(typeAttribute, AttributeOperation.EQUALS, escalationWItype.getIdentifier());                      
Term term = new Term(Operator.AND); term.add(projectAreaExpression);
            term.add(creationDateExpression);
term.add(stateGroupExpression);
            term.add(wiTypeExpression);           
            IQueryCommon queryService = getQueryCommon();             result = queryService
.getResolvedExpressionResults(projectArea, term, IWorkItem.FULL_PROFILE);             while (result.hasNext(monitor)) {                 matchingWorkItems.add(result.next(monitor).getItem());
            }         }         catch (Exception ex) {             getLog().error(NLS.bind("Error during finding workitems for project area {0}, error message: {1}, stack trace {2}",                     projectArea.toString(), ex.getMessage(), ex.getStackTrace().toString()));\         }         return matchingWorkItems;        }

0 votes

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
× 10,936
× 411
× 201
× 26

Question asked: Dec 01 '22, 3:41 a.m.

Question was seen: 1,676 times

Last updated: Dec 02 '22, 4:14 a.m.

Confirmation Cancel Confirm