It's all about the answers!

Ask a question

Server participant


0
1
Yehiel Glass (25538986) | asked Dec 29 '11, 7:07 a.m.
Hi,
I need help in writing simple participant on my server.
The participant should remove the approval on state change to specific state.
In debug with Jetty I can see it goes to the right function but doesn't remove the approvals..
Can you please help? What did I forget? Or maybe I need to use handle? Maybe save?

here is my code:

package net.jazz.rtcext.workitem.extensions.service;

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;

//import com.ibm.team.build.common.model.IBuildDefinition;
//import com.ibm.team.build.internal.common.ITeamBuildRequestService;
//import com.ibm.team.build.internal.common.ITeamBuildService;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.advice.AdvisableOperation;
//import com.ibm.team.process.common.advice.IItemsResponse;
import com.ibm.team.process.common.advice.runtime.IOperationParticipant;
import com.ibm.team.process.common.advice.runtime.IParticipantInfoCollector;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.AbstractService;
import com.ibm.team.workitem.common.ISaveParameter;
import com.ibm.team.workitem.common.model.IApproval;
import com.ibm.team.workitem.common.model.IApprovals;
import com.ibm.team.workitem.common.model.IState;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.model.Identifier;



public class RemoveApprovalOnStateChange extends AbstractService implements
IOperationParticipant {

public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
/*
* First check that the operation data is work item save data.
*/
Object data = operation.getOperationData();
ISaveParameter saveParameter = null;
if (data instanceof ISaveParameter) {
saveParameter = (ISaveParameter) data;
/*
* If the state id has not changed, do not build.
*/
IWorkItem newState = (IWorkItem) saveParameter.getNewState();
Identifier<IState> newStateId = newState.getState2();
Identifier<IState> oldStateId = null;
IWorkItem oldState = (IWorkItem) saveParameter.getOldState();
if (oldState != null) // New work item check.
oldStateId = oldState.getState2();
if ((newStateId != null) && !(newStateId.equals(oldStateId))) {
String newType = newState.getWorkItemType();
if (newType.equals("com.ibm.team.apt.workItemType.story")) {
/*
* Finally, if the new state is the target state, build.
*/
if (newState.getState2().getStringIdentifier().equals(
"com.ibm.team.apt.story.tested")) {
//remove approval
IApprovals approvals = newState.getApprovals();
List<IApproval> approvalList = approvals.getContents();
for (IApproval approval : approvalList) {
approvals.remove(approval);
}
}
}
}
}
}
}

One answer



permanent link
Yehiel Glass (25538986) | answered Dec 29 '11, 9:18 a.m.
I think I have the solution - the participant works for me!
Here is my code: (Enjoy)

package net.jazz.rtcext.workitem.extensions.service;

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;

//import com.ibm.team.build.common.model.IBuildDefinition;
//import com.ibm.team.build.internal.common.ITeamBuildRequestService;
//import com.ibm.team.build.internal.common.ITeamBuildService;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.advice.AdvisableOperation;
//import com.ibm.team.process.common.advice.IItemsResponse;
import com.ibm.team.process.common.advice.runtime.IOperationParticipant;
import com.ibm.team.process.common.advice.runtime.IParticipantInfoCollector;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.AbstractService;
import com.ibm.team.workitem.common.ISaveParameter;
import com.ibm.team.workitem.common.model.IApproval;
import com.ibm.team.workitem.common.model.IApprovals;
import com.ibm.team.workitem.common.model.IState;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.common.model.Identifier;
import com.ibm.team.workitem.service.IWorkItemServer;



public class RemoveApprovalOnStateChange extends AbstractService implements
IOperationParticipant {

public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
/*
* First check that the operation data is work item save data.
*/
Object data = operation.getOperationData();
ISaveParameter saveParameter = null;
if (data instanceof ISaveParameter) {
saveParameter = (ISaveParameter) data;
/*
* If the state id has not changed, do not build.
*/
IWorkItem newState = (IWorkItem) saveParameter.getNewState();
Identifier<IState> newStateId = newState.getState2();
Identifier<IState> oldStateId = null;
IWorkItem oldState = (IWorkItem) saveParameter.getOldState();
if (oldState != null) // New work item check.
oldStateId = oldState.getState2();
if ((newStateId != null) && !(newStateId.equals(oldStateId))) {
String newType = newState.getWorkItemType();
if (newType.equals("com.ibm.team.apt.workItemType.story")) {
/*
* Finally, if the new state is the target state, build.
*/
if (newState.getState2().getStringIdentifier().equals(
"com.ibm.team.apt.story.tested")) {
//remove approval
Integer myid = newState.getId();
IWorkItemServer itemServer= getService(IWorkItemServer.class);
IWorkItem item = itemServer.findWorkItemById(myid, IWorkItem.FULL_PROFILE, null);
IWorkItem itemCopy = (IWorkItem)item.getWorkingCopy();

IApprovals approvals = itemCopy.getApprovals();
List<IApproval> approvalList = approvals.getContents();
for (IApproval approval : approvalList) {
boolean remove = approvals.remove(approval);
}

itemServer.saveWorkItem2(itemCopy, null, null);

}
}
}
}
}
}

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.