How to use API (advisor) to query and list restricted work items?
WorkItemQueryModel model= WorkItemQueryModel.ROOT;IItemQuery query = IItemQuery.FACTORY.newInstance(model);IPredicate predicatePA = model.projectArea()._eq(query.newItemHandleArg());IPredicate predicateIterator = model.target()._eq(query.newItemHandleArg());IPredicate predicateType = model.workItemType()._eq(query.newStringArg());IPredicate predicate = predicatePA._and(predicateIterator)._and(predicateType);query.filter(predicate);
com.ibm.team.workitem.common.internal.util.ItemQueryIterator<IWorkItemHandle> iterator = new com.ibm.team.workitem.common.internal.util.ItemQueryIterator<IWorkItemHandle>(auditableCommon, query, new Object[] { projectArea, iterationHandle, workItemType });
List<IWorkItem> workItems = auditableCommon.resolveAuditables(iterator.toList(monitor), profile, monitor);
Accepted answer
You can find the E-Mail Notification code in the SDK, I found it recently, I would search the SDK for 'mail' or something.
I am not sure if there are drawbacks with that approach e.g. potential conflicts if the asynchronous task writes the work items.
Comments
Problem is he wants this synchronous with the save..
I suppose you could use the asynch task, and 'hope' that the linking happens soon enough that no one will complain.
also, I don't think you can pass parameters to these async tasks from outside, unless you design your own linked list message storage facility
also, and maybe more importantly, you should NOT be changing the workitem in the advisor. but more properly in a participant. Maybe the participant runs in admin context (don't remember)
Ok.
Yes, never modify in an advisor.
I don't know a better way. Others might, but I would be surprised. The participants and advisors, as far as I can tell, run in the context of the user that saves. I don't know if there is a way to elevate the user.
You can probably communicate information. At least I have heard that. the additional save parameters used in participants are only one example.
Please be aware that there is an issue with creating links in a participant as well, see: https://jazz.net/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/288105
I am not sure if that applies to all link types, but it prevents creation of back links due to a database lock on the work item that is processed by the participant, as I learned only recently.
3 other answers
Comments
I think the user has access to everything in the query results, but maybe everything needed is not IN the query results at all. so you cannot tell (from the result array) that items are not present, cause the user shouldn't see them anyhow.
rules based on admin level access to ALL content are problematic, and invite security breaches.
I know there is a permission aware API that allows you to at least get the handles to items you don't have permission to or that do not show up for other reasons. I am not sure if the permission aware API is accessible from queries. A quick look did not reveal it, so you will most likely only see the results you have access to.
Comments
sam detweiler
Nov 02 '13, 9:31 a.m.I believe the advisor runs in the context of the user making the workitem change, there is no method to change that, that I know of.
1 vote