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?
|
2 answers
Ralph Schoon (63.5k●3●36●46)
| answered Dec 01 '22, 11:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER 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;
}
Comments
Ralph Schoon
commented Dec 01 '22, 11:38 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Note in the server you would have to use IAuditableCommon and not the client. |
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,
Generally, I'm basing on example from https://jazz.net/wiki/bin/view/Main/QueryDevGuide and from yours article from https://rsjazz.wordpress.com/2015/10/16/due-date-notifier-an-asynchronous-task-example/
|
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.