Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

operation advisor precondition link

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

0 votes



6 answers

Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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.

0 votes

Your answer

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Dec 14 '11, 8:40 a.m.

Question was seen: 7,889 times

Last updated: Dec 14 '11, 8:40 a.m.

Confirmation Cancel Confirm