How to get workitem based on modified date and time using RTC Java API

懵懂的女人 提交于 2019-12-12 09:06:08

问题


I want to query RTC with modified date. My query is to check modified date is same as given date and time but the response that I am getting is based on given date and it is ignoring time.

Response:

Queried Date: 08/07/2015 15:44:09

Id: 2583 Modified date :2015-08-07 14:43:19.157

Id: 2582 Modified date :2015-08-07 14:43:19.419

Ideally, both the records should not be received in response as it is before given time.

Below is my code:

IQueryableAttributeFactory factory = QueryableAttributes.getFactory( IWorkItem.ITEM_TYPE ); 

IQueryableAttribute recAttr1 = factory.findAttribute(projectArea, IItem.MODIFIED_PROPERTY, auditableClient, null ); 
IQueryableAttribute recAttr2 = factory.findAttribute(projectArea, IWorkItem.TYPE_PROPERTY, auditableClient, null );     

Date date = new Date();
date.setDate(date.getDate()-6);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
String reportDate = df.format(date);
System.out.println("Date: "+reportDate);
Timestamp timeStamp = new Timestamp(date.getTime()); 

AttributeExpression recExpr1 = new AttributeExpression(recAttr1, AttributeOperation.EQUALS, timeStamp ); 

Term term= new Term(Operator.AND); 
term.add(recExpr1); 

IQueryClient queryClient = (IQueryClient) teamRepository.getClientLibrary(IQueryClient.class); 
IQueryResult<IResolvedResult<IWorkItem>> result = queryClient.getResolvedExpressionResults(projectArea, (Expression)term, IWorkItem.FULL_PROFILE); 
System.out.println("This is total number: "+result.getResultSize(monitor).getTotal()+"\n");                 

while(result.hasNext(null)){ 
    IResolvedResult<IWorkItem> resolvedWorkItem = result.next(null); 
    IWorkItem workItem = resolvedWorkItem.getItem();
    Date date1 = resolvedWorkItem.getItem().modified(); 
    System.out.println("Id: "+workItem.getId());
    System.out.println("Modified date :"+date1.toString()+"\n"); 
}   

Can I get result not only based on date but also on time?

I strongly feel that the back-end logic of RTC is completely ignoring time and querying database only based on date.


回答1:


I have the exact same problem. I thought maybe the results were cached somewhere, but that wasn't it.

I haven't found a way to do this via RTC query, but it should be possible to filter out these records in your code after RTC query returned. Save the time you used to perform the search, then use that to skip any records by doing:

if (workItem.modified().getTime() < lastModified)
  continue;

I know this isn't ideal, but at least there's a way to get the desired set to work with.



来源:https://stackoverflow.com/questions/31985740/how-to-get-workitem-based-on-modified-date-and-time-using-rtc-java-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!