Problems With Update WorkItem Subscribers PlugIn
Hi, i have a problem with my plugin .
A brief description how it works:
" When the workitem "defect" changes its state in "Closed", the members with a role equal to "subscriber" ( custom role ) and belonging to the Project Area are added as subscribers. "
The problem is :
Subscribers are properly added to the workitem working copy but the original workItem is not updated.
This is the plugin java code :
----------------------------------------------------------------------------------------------------------------------------------------------------------
public class SubscriberOnChange extends AbstractService implements IOperationParticipant {
// Stati WI
private static final String NAME_STATE_CHIUSO = "Chiuso";
// Role
private static final String ROLE_NAME_SUBSCRIBER = "subscriber";
// ID WI
private static final String WI_ID_DEF = "defect";
// Services we need
static private IWorkItemServer wiServer;
private IRepositoryItemService items;
private IContributorService contributorService;
@Override
public void run(AdvisableOperation operation,
IProcessConfigurationElement advisorConfiguration,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
// First check that the operation was a 'save' and get he operation data
Object opData = operation.getOperationData();
if(!(opData instanceof ISaveParameter)){
return;
}
// Check that this was a save operation on a work item
ISaveParameter data = (ISaveParameter)opData;
if(!(data.getNewState() instanceof IWorkItem)) {
return;
}
String wfAction = data.getWorkflowAction();
// Get the required service interfaces
wiServer = getService(IWorkItemServer.class);
items = getService(IRepositoryItemService.class);
contributorService = getService(IContributorService.class);
IWorkItem wi = (IWorkItem)data.getNewState();
IWorkItem workItemOld =(IWorkItem)data.getOldState();
if (!(wi.getWorkItemType().equals(WI_ID_DEF)) ){
return;
}
// Info workItem
Integer wiID = wi.getId();
XMLString wiSummary = wi.getHTMLSummary();
System.out.println("wiID : "+ wiID);
System.out.println("wiSummury : "+ wiSummary);
IWorkflowInfo wfInfo = wiServer.findWorkflowInfo(wi, monitor);
String nameStateNow = wfInfo.getStateName(wi.getState2());
String roleName;
if (nameStateNow.equalsIgnoreCase(NAME_STATE_CHIUSO)){
roleName = ROLE_NAME_SUBSCRIBER;
} else return;
System.out.println("RoleName :"+roleName);
// WorkItem Working Copy **************************************************************************************************
IWorkItem wiOnServer = wiServer.findWorkItemById(wiID,IWorkItem.FULL_PROFILE,null);
IWorkItem wiOnServerCopy = (IWorkItem)wiOnServer.getWorkingCopy();
//*********************************************************************************************************************************
if(workItemOld!=null){
System.out.println("Start Change subscriber section code.....");
ISubscriptions subscriptions= workItemOld.getSubscriptions();
System.out.println("Numero Subscriber WI-OLD :"+subscriptions.getContents().length);
//Contributors with a role equal to "subscriber" and belonging to the Project Area
//The method subscribersArrayByRoleName works
ArrayList<IContributor> subscribersArray =
subscribersArrayByRoleName(operation.getProcessArea(), wi, roleName, monitor);
if (subscribersArray==null) return;
if (subscribersArray.size()==0) {
//Tracciatura fine esecuzione plugin
System.out.println("END " + header);
return;
}
//Add new subscribers to the wi workingCopy*****************************************************************************
for (IContributor contr : subscribersArray){
IContributorHandle user = contributorService.fetchContributorByUserId(contr.getUserId());
wiOnServerCopy.getSubscriptions().add(user);
}
//*******************************************************************************************************************************
//Try to Save - This section code does not work; in the log file I only see the first sys.out
try{
System.out.println("Pre-Save......");
wiServer.saveWorkItem2(wiOnServerCopy, null, null); // ??? <------------
System.out.println("Post-Save.....");
}catch (Exception e) {;
System.out.println("ERRORE nel getService");
e.printStackTrace();
System.out.println(e.getMessage());
System.out.println(e.getStackTrace());
}}
}
Can you help me PLEASE???
Thanks.
Giuseppe Gravina.
4 answers
Comments
If you debug it with Jetty, what happens when the code runs? Is there a recursion?
Hi Ralph,
I read the article ( https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/) and I have some questions for you....Can you answer , please?
- How can I get the WI Working Copy?
1) **************************************************************** WAY 1 ********************************************************
Object opData = operation.getOperationData();
ISaveParameter data = (ISaveParameter)opData;
IWorkItemServer wiServer = getService(IWorkItemServer.class);
IWorkItem wi = (IWorkItem)data.getNewState();
IWorkItem wiOnServer = wiServer.findWorkItemById (wi.getId (),IWorkItem.FULL_PROFILE,null);
IWorkItem wiOnServerCopy = (IWorkItem)wiOnServer.getWorkingCopy();
2)**************************************************************** WAY 2*********************************************************
Object opData = operation.getOperationData();
ISaveParameter data = (ISaveParameter)opData;
IWorkItemServer wiServer = getService(IWorkItemServer.class);
IWorkItemHandle currentWIHandle =
(IWorkItemHandle)data.getNewState().getItemHandle();
IWorkItem workItem=(IWorkItem)wiServer.getAuditableCommon()
.resolveAuditable(currentWIHandle,IWorkItem.FULL_PROFILE,monitor)
.getWorkingCopy();
workItemCopy = (IWorkItem)workItem.getWorkingCopy();
3)*************************************************************** OTHER WAY ? ************************************************
???
- After working on WI Working Copy, how can i save changes?
IWorkItemServer wiServer = getService(IWorkItemServer.class);
wiServer.saveWorkItem2(workitemCopy, null, null);
Is this correct??
*************************************************************************************************************************************
Thanks,
Giuseppe.
Hi Ralph,
I read the article ( https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/) and I have some questions for you....Can you answer , please?
- How can I get the WI Working Copy?
1) **************************************************************** WAY 1 ********************************************************
Object opData = operation.getOperationData();
ISaveParameter data = (ISaveParameter)opData;
IWorkItemServer wiServer = getService(IWorkItemServer.class);
IWorkItem wi = (IWorkItem)data.getNewState();
IWorkItem wiOnServer = wiServer.findWorkItemById (wi.getId (),IWorkItem.FULL_PROFILE,null);
IWorkItem wiOnServerCopy = (IWorkItem)wiOnServer.getWorkingCopy();
2)**************************************************************** WAY 2*********************************************************
Object opData = operation.getOperationData();
ISaveParameter data = (ISaveParameter)opData;
IWorkItemServer wiServer = getService(IWorkItemServer.class);
IWorkItemHandle currentWIHandle =
(IWorkItemHandle)data.getNewState().getItemHandle();
IWorkItem workItem=(IWorkItem)wiServer.getAuditableCommon()
.resolveAuditable(currentWIHandle,IWorkItem.FULL_PROFILE,monitor)
.getWorkingCopy();
workItemCopy = (IWorkItem)workItem.getWorkingCopy();
3)*************************************************************** OTHER WAY ? ************************************************
???
- After working on WI Working Copy, how can i save changes?
IWorkItemServer wiServer = getService(IWorkItemServer.class);
wiServer.saveWorkItem2(workitemCopy, null, null);
Is this correct??
*************************************************************************************************************************************
Thanks,
Giuseppe.