Tarun
Tarun

Reputation: 3165

versionone: get defects with project and change date filter from version one java sdk

I am looking to retrieve list of all defects that belongs to project A and that have modified in last 24 hours. I used the given below code to retrieve list of all defects that belongs to project(project is a string variable containing name of the project)

        scope=defectType.getAttributeDefinition("Scope.Name");
        FilterTerm toDoTerm = Query.term(scope);
        toDoTerm.Equal(project);

Now i want to add one more condition, list only those defects that have been changed in last 24 hours.
I checked the versionone api but could not find any relevant java source code/example or function name.

How can i add conditions like "and" or "or" ?

Upvotes: 0

Views: 894

Answers (1)

vplechuc
vplechuc

Reputation: 198

You can use the GroupFilterTerm to concatenate filters (And or Or) like this:

FilterTerm toDoTerm = new FilterTerm(nameAttribute);
toDoTerm.equal(project);
FilterTerm dateFilter = new FilterTerm(dateAttribute);
Calendar c = Calendar.getInstance();
dateFilter.lessOrEqual(c.getTime());

GroupFilterTerm groupFilter = new AndFilterTerm(toDoTerm, dateFilter);
Collection<IAttributeDefinition> attributesToQuery = new LinkedList<IAttributeDefinition>();
attributesToQuery.add(nameAttribute);
attributesToQuery.add(dateAttribute);
query = new Query(storyAsset.getOid().getMomentless(), true);
query.getSelection().addAll(attributesToQuery);
query.setFilter(groupFilter);

In this example I am querying Defects that are in a specific project, and where the Defect ChangeDate (dateAttribute) value is less than or equal to today.

You´ll need to take into account how Java handles Date variables when you do the comparison.

Upvotes: 2

Related Questions