Query to get all the categories of currently loged in user.
I have the below method to get all the categories the current logged in user is associated with.
The query result does not returns any result.
Can you please help me in this
private IItemHandle[] getAssociatedCategories() throws Exception {
CategoryQueryModel catQueryModel = BaseCategoryQueryModel.CategoryQueryModel.ROOT;
IItemQuery catQuery = IItemQuery.FACTORY.newInstance(catQueryModel);
IPredicate contributorPredicate = catQueryModel.defaultTeamArea().contributors()._contains(catQuery.newItemHandleArg());
catQuery.filter(contributorPredicate);
List<IItemHandle> categoriesList = runQuery(catQuery, new Object[]{getAuthenticatedContributor()}, -1);
if (categoriesList == null || categoriesList.isEmpty()) {
throw new Exception("No Category found for the current user");
}
IItemHandle[] categories = new IItemHandle;
int i = 0;
for (Iterator<IItemHandle> iterator = categoriesList.iterator(); iterator.hasNext(); i++) {
IItemHandle catHandle = (IItemHandle) iterator.next();
System.out.println("category ID" + catHandle.getItemId());
categories = catHandle;
}
return categories;
}
Thanks
Aradhya
The query result does not returns any result.
Can you please help me in this
private IItemHandle[] getAssociatedCategories() throws Exception {
CategoryQueryModel catQueryModel = BaseCategoryQueryModel.CategoryQueryModel.ROOT;
IItemQuery catQuery = IItemQuery.FACTORY.newInstance(catQueryModel);
IPredicate contributorPredicate = catQueryModel.defaultTeamArea().contributors()._contains(catQuery.newItemHandleArg());
catQuery.filter(contributorPredicate);
List<IItemHandle> categoriesList = runQuery(catQuery, new Object[]{getAuthenticatedContributor()}, -1);
if (categoriesList == null || categoriesList.isEmpty()) {
throw new Exception("No Category found for the current user");
}
IItemHandle[] categories = new IItemHandle;
int i = 0;
for (Iterator<IItemHandle> iterator = categoriesList.iterator(); iterator.hasNext(); i++) {
IItemHandle catHandle = (IItemHandle) iterator.next();
System.out.println("category ID" + catHandle.getItemId());
categories = catHandle;
}
return categories;
}
Thanks
Aradhya
One answer
I have the below method to get all the categories the current logged
in user is associated with.
The query result does not returns any result.
We currently don't expose this as API, but you could take a look at:
WorkItemQueries#categoriesByContributor(IAuditableCommon auditableCommon,
IContributorHandle contributor)
The query is basically:
CategoryQueryModel model= CategoryQueryModel.ROOT;
IItemQuery query= IItemQuery.FACTORY.newInstance(model);
IItemHandleInputArg contributorArg= query.newItemHandleArg();
query.filter(model.defaultTeamArea().contributors()._contains(contributorArg)._or(model.teamAreas().contributors()._contains(contributorArg)));
--
Regards,
Patrick
Jazz Work Item Team