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

Changing state of stored "related" work items - pr

Hi everybody!

I'm creating work item save operation participant.
During that, I would like to update state of all work items "related" to (parent) item being saved.

I expected that following should work:

workItemService.saveWorkItem2(relatedItem.getWorkingCopy(), null, "com.ibm.team.workitem.eclipseWayWorkflow.action.close");


But it is not. Saving finishes successfully but related items stay unchanged.

Could someone please point me in the right direction..
Thanks in advice!

Rasto

0 votes



3 answers

Permanent link
I'm creating work item save operation participant.
During that, I would like to update state of all work items
"related" to (parent) item being saved.

I expected that following should work:

workItemService.saveWorkItem2(relatedItem.getWorkingCopy(), null,
"com.ibm.team.workitem.eclipseWayWorkflow.action.close");


But it is not. Saving finishes successfully but related items stay
unchanged.

Could someone please point me in the right direction..
Thanks in advice!

The snippet looks basically ok to me. Are the related work items also
using the Eclipse Way Workflow? IIRC, the action IDs are validated
against the workitem's workflow.

--
Regards,
Patrick
Jazz Work Item Team

0 votes


Permanent link
Yes, there was the problem. The related work items used different workflow.
The action id should have been:
bugzillaWorkflow.action.close


Works well now. Thanks!

Rasto

0 votes


Permanent link
I attach my code according to Massimo Caprinali's request.
I welcome any code improvements. :)


/** All related parent items are closed during saving child work item */
public class StateChanger extends AbstractService implements IOperationParticipant {

// Using type id's form com.ibm.team.workitem.common plugin.xml (default for simple process)
private final static String CHILD_WORK_ITEM_TYPE_ID = "defect";
private final static String PARENT_WORK_ITEM_TYPE_ID = "task";

// Using workflow constants from eclipseWayWorkflow.xml (default for simple process)
private final static String PARENT_RESOLVING_WORKFLOW_ACTION_ID = "bugzillaWorkflow.action.resolve";
private final static String PARENT_CLOSING_WORKFLOW_ACTION_ID = "bugzillaWorkflow.action.close";

public void run(AdvisableOperation operation, IProcessConfigurationElement participantConfig, IParticipantInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
// Preparation I.
ISaveParameter saveParam = (ISaveParameter) operation.getOperationData();
IWorkItem child = (IWorkItem) saveParam.getNewState();

// Types other than CHILD_WORK_ITEM_TYPE_ID are not interesting
if (!CHILD_WORK_ITEM_TYPE_ID.equals(child.getWorkItemType())) {
return;
}

// Preparation II.
ILinkService linkService = getService(ILinkService.class);
ILinkServiceLibrary linkLibrary = (ILinkServiceLibrary) linkService.getServiceLibrary(ILinkServiceLibrary.class);

// Listing and resolving links to 'related' work items
IItemReference workItemRef = IReferenceFactory.INSTANCE.createReferenceToItem(child);
ILinkQueryPage linkPage = linkLibrary.findLinks(WorkItemLinkTypes.RELATED_WORK_ITEM, workItemRef);
if (linkPage.getResultSize() == 0) {
addErrorInfo("Defect must have related work item!", "Add related work item before save!", collector);
return;
}

// Preparation III.
IRepositoryItemService repositoryItemService = getService(IRepositoryItemService.class);
IWorkItemServer workItemService = getService(IWorkItemServer.class);
IWorkItemCommon workItemCommon = getService(IWorkItemCommon.class);

// Processing links
ILinkCollection links = linkPage.getAllLinksFromHereOn();
for (ILink link : links) {
IReference otherRef = link.getOtherRef(workItemRef);
IWorkItemHandle parentHandle = (IWorkItemHandle) otherRef.resolve();
IWorkItem parent = (IWorkItem) repositoryItemService.fetchItem(parentHandle, null);
if(PARENT_WORK_ITEM_TYPE_ID.equals(parent.getWorkItemType()) && !isClosed(workItemCommon, parent)) { // process only items with type = PARENT_WORK_ITEM_TYPE_ID and open ones
// Changing to "resolved"
listWorkflowActions(workItemCommon, monitor, parent);
IWorkItem parentWorkingCopy = (IWorkItem) parent.getWorkingCopy();
workItemService.saveWorkItem2(parentWorkingCopy, null, PARENT_RESOLVING_WORKFLOW_ACTION_ID);

// Changing to "closed"
parent = (IWorkItem) repositoryItemService.fetchItem(parentHandle, null);
listWorkflowActions(workItemCommon, monitor, parent);
parentWorkingCopy = (IWorkItem) parent.getWorkingCopy();
workItemService.saveWorkItem2(parentWorkingCopy, null, PARENT_CLOSING_WORKFLOW_ACTION_ID);
// ! Two-phase saving should not be needed for well customized workflow
}
}
}

private static void addErrorInfo(String summary, String description, IParticipantInfoCollector collector) {
if (collector != null) {
IReportInfo info = collector.createInfo(summary, description);
info.setSeverity(IProcessReport.ERROR);
collector.addInfo(info);
}
}

private boolean isClosed(IWorkItemCommon workItemCommon, IWorkItem workItem) {
if (workItem != null) {
Identifier<IState> state= workItem.getState2();
if (state != null) {
try {
IWorkflowInfo workflowInfo= workItemCommon.findWorkflowInfo(workItem, null);
if (workflowInfo.stateGroupContains(IWorkflowInfo.CLOSED_STATES, state))
return true;
} catch (TeamRepositoryException e) {
return false;
}
}
}
return false;
}

}

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,952

Question asked: Jan 25 '10, 12:25 p.m.

Question was seen: 6,637 times

Last updated: Jan 25 '10, 12:25 p.m.

Confirmation Cancel Confirm