Server participant
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);
}
}
}
}
}
}
}
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
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);
}
}
}
}
}
}
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);
}
}
}
}
}
}