It's all about the answers!

Ask a question

Query to get all the categories of currently loged in user.


Aradhya K (1.4k44345) | asked Jan 29 '09, 9:57 p.m.
JAZZ DEVELOPER
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

One answer



permanent link
Patrick Streule (4.9k21) | answered Feb 03 '09, 4:28 a.m.
JAZZ DEVELOPER
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

Your answer


Register or 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.