It's all about the answers!

Ask a question

operation advisor precondition link


Eray İzgin (1161724) | asked Dec 14 '11, 8:40 a.m.
I am working on a server side OperationAdvisor,trying to precondition.
I try to get detailed info of related workitem.

Here is I'm trying code.

Object data = operation.getOperationData();

if (data instanceof ISaveParameter) {
ISaveParameter param = (ISaveParameter) data;
IAuditable auditable = param.getNewState();
if (auditable instanceof IWorkItem) {
IWorkItem sourceworkItem = (IWorkItem) auditable;

IWorkItemReferences iwr = ((ISaveParameter) data).getNewReferences();
List<IEndPointDescriptor> epdl = iwr.getTypes();

ILinkType lt = epdl.get(0).getLinkType();

IAdvisorInfo problem = collector.createProblemInfo(
"Hello World!", "This work item is of type: " + lt.getLinkTypeId() + " " + epdl.get(0).getDisplayName()
+ sourceworkItem.getWorkItemType(),
PROBLEM_TYPE);
collector.addInfo(problem);
}
}

It works successfully, but in addition
- I try to get related workItem identifier(id -)
- I want to control whether related workitem has a parent work item ?

I try on https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=182769&&tab=links
But I can't. Server rtc 3.0.1, client rtc 3.0 sdk

Thanks

6 answers



permanent link
sam detweiler (12.5k6195201) | answered Dec 14 '11, 8:52 a.m.
sorry, don't quite understand the question..

- I try to get related workItem identifier(id -)

in my code which u reference, you get the referenced workitem

// get the item, and it SHOULD always be a workitem
IWorkItem r = iac.resolveAuditable((IWorkItemHandle)wir.get(j).resolve(),IWorkItem.FULL_PROFILE, null);


and then its id (I put it in the error message)

"Workitem "+ r.getId()+ " is not Resolved"


- I want to control whether related workitem has a parent work item ?

control, or know?

once u have the workitem, then you would have to start over, and get its list of references, and check the link for parent, and.....

so, like this
IWorkItemReferences resolveWorkItemReferences(IWorkItemHandle workItem, org.eclipse.core.runtime.IProgressMonitor monitor)

see the javadoc provided with 3.0.1.1.. downloadable separately

sam

permanent link
Eray İzgin (1161724) | answered Dec 14 '11, 10:59 a.m.
Yes, I try to get referenced workitem id. I got it by r.getId() as you said.

and next I want to know whether related workitem has a parent?

IWorkItemServer workItemService = getService(IWorkItemServer.class);
IWorkItemReferences references = workItemService .resolveWorkItemReferences(currentworkitem, null);

List<IEndPointDescriptor> epdl = iwr.getTypes();

epdl.get(0).getId()

But I can't get referenced parent info. Is this right way?

Thanks

sorry, don't quite understand the question..

- I try to get related workItem identifier(id -)

in my code which u reference, you get the referenced workitem

// get the item, and it SHOULD always be a workitem
IWorkItem r = iac.resolveAuditable((IWorkItemHandle)wir.get(j).resolve(),IWorkItem.FULL_PROFILE, null);


and then its id (I put it in the error message)

"Workitem "+ r.getId()+ " is not Resolved"


- I want to control whether related workitem has a parent work item ?

control, or know?

once u have the workitem, then you would have to start over, and get its list of references, and check the link for parent, and.....

so, like this
IWorkItemReferences resolveWorkItemReferences(IWorkItemHandle workItem, org.eclipse.core.runtime.IProgressMonitor monitor)

see the javadoc provided with 3.0.1.1.. downloadable separately

sam

permanent link
sam detweiler (12.5k6195201) | answered Dec 14 '11, 11:21 a.m.
the javadoc says you can call resolveWorkItemReferences directly from a workitem

IWorkItemReferences targetWIreferences = currentworkitem.resolveWorkItemReferences(referencedworkitemHandle, null);

>and next I want to know whether related workitem has a parent?

then you have to loop thru the references same as the first pass..

Sam

permanent link
Eray İzgin (1161724) | answered Dec 15 '11, 3:13 a.m.
I looked at javadoc ,Iworkitem doesn't have resolveWorkItemReferences. IWorkItemServer or workitemClient has resolveWorkItemReferences. I tried like

IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IWorkItemReferences references= workItemServer.resolveWorkItemReferences(workitem, null);
List<IEndPointDescriptor> epdl2 = references.getTypes();

Internal Error. Unable to instantiate advisor HelloWorldAdvisor.prohibitSave.
CRJAZ6010E:An exception occurred creating extension.

the javadoc says you can call resolveWorkItemReferences directly from a workitem

IWorkItemReferences targetWIreferences = currentworkitem.resolveWorkItemReferences(referencedworkitemHandle, null);

>and next I want to know whether related workitem has a parent?

then you have to loop thru the references same as the first pass..

Sam

permanent link
sam detweiler (12.5k6195201) | answered Dec 15 '11, 7:46 a.m.
yes, sorry, most of the xCommon class interfaces are shared between server and client.. this one is not.. IWorkitemCommon.

anyhow.. you don't really need it, as the operation advisor has access to the AuditableCommon class and methods..

Sam

permanent link
Eduardo Bello (4401922) | answered Dec 20 '11, 3:06 p.m.
I'm not sure if I understand the question correctly.

In order to resolve parent reference into WorkItem you can use something like this:



try {
IItemHandle referencedItem = null;
IWorkItem relatedWorkItem = null;
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
IRepositoryItemService repositoryItemService = getService(IRepositoryItemService.class);
IWorkItemReferences references = workItemServer.resolveWorkItemReferences(workItem, null);
List<IReference> parentRef = references.getReferences(WorkItemEndPoints.PARENT_WORK_ITEM);
if (parentRef!=null && parentRef.size()>0) {
for (IReference reference : parentRef) {
if (reference.isItemReference()) {
referencedItem = ((IItemReference) parentRef.get(0)).getReferencedItem();
if (referencedItem instanceof IWorkItemHandle) {
relatedWorkItem = (IWorkItem) repositoryItemService.fetchItem(referencedItem, null);
}
}
}

}
} catch (TeamRepositoryException e1) {
e1.printStackTrace();
}




Where relatedWorkItem would be the parent (if exists) of your workitem. Note that you can change WorkItemEndPoints.PARENT_WORK_ITEM to any endpoint type you want. But you also have to change a little bit the code, as an WorkItem can only have one Parent, the code works fine, but for endpoints like Children, you have to put relatedWorkItem into a List.

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.