It's all about the answers!

Ask a question

How to add/modify change set comments using RTC Advisor ?


Nagendra Prasad (175) | asked Jun 19 '17, 3:19 a.m.

 I am working on an RTC advisor to append stream name to the changeset's comment so far with no luck. Everything seems to be working fine apart from the setComment(..) method. My code is posted below, any help is much appreciated. Thanks in advance.


import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.core.runtime.IProgressMonitor;

import com.ibm.team.links.common.ILink;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfoCollector;
import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.IRepositoryItemService;
import com.ibm.team.scm.common.IChangeSet;
import com.ibm.team.scm.common.IChangeSetHandle;
import com.ibm.team.scm.common.IScmService;
import com.ibm.team.scm.common.links.ChangeSetLinks;
import com.ibm.team.scm.common.links.ILinkConstants;
import com.ibm.team.scm.common.process.DeliverOperationData;
import com.ibm.team.scm.common.providers.ProviderFactory;
import com.ibm.team.scm.service.internal.AbstractScmService;
import com.ibm.team.scm.service.internal.utils.ServerProviderFactory;
import com.ibm.team.workitem.common.model.IWorkItemHandle;

@SuppressWarnings("restriction")
public class StreamNameAppender extends AbstractScmService implements
IOperationAdvisor{
private static Logger logger = LoggerUtility.getPluginLogger("StreamNameAppenderAdvisor");

@Override
public void run(AdvisableOperation advisableOperation, IProcessConfigurationElement arg1,
IAdvisorInfoCollector iAdvisorInfoCollector, IProgressMonitor iProgressMonitor)
throws TeamRepositoryException {
try{
Object operationData = advisableOperation.getOperationData();
if(operationData instanceof DeliverOperationData) {
DeliverOperationData data = (DeliverOperationData) operationData;
String streamName = data.getDestWorkspace().getName();
logger.log(Level.INFO, "Stream name: " + streamName);
IRepositoryItemService repositoryItemService = getService(IRepositoryItemService.class);
IScmService scmService = getService(IScmService.class);
List<IChangeSetHandle> changeSetHandles = data.getChangeSetHandles();
// Get the ProviderFactory to be able to find the links
ProviderFactory providerFactory = new ServerProviderFactory(this, repositoryItemService);
for(IChangeSetHandle changeSetHandle : changeSetHandles){
List<ILink> links = ChangeSetLinks.findLinks(providerFactory, changeSetHandle,
new String[] { ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID },
iProgressMonitor);
for(ILink link : links){
Object resolved = link.getTargetRef().resolve();
if (resolved instanceof IWorkItemHandle) {
IChangeSet changeSet = (IChangeSet) repositoryItemService.fetchItem(changeSetHandle, null);
String comment = changeSet.getComment();
logger.log(Level.INFO, "This changeset's existing comment: " + comment);
String firstChar = String.valueOf(comment.charAt(0));
if(!"[".equals(firstChar)){
String newComment = "[" + streamName + "]" + comment;
logger.log(Level.INFO, "New comment: " + newComment);
scmService.setComment(changeSetHandle, newComment, null, null);
// getScmService().setComment(changeSetHandle, newComment, null, null);
}
}
}
}
}
} catch(Exception e){
logger.log(Level.SEVERE, "Error while executing StreamNameAppender advisor : " + LoggerUtility.getStackTraceAsString(e));
}
}
}


Comments
Nagendra Prasad commented Jun 19 '17, 3:21 a.m.

 The advisor will be triggered on delivering the chengeset, even comment is printed in the log but the comment is not being set to the changeset.

Accepted answer


permanent link
Ralph Schoon (63.4k33646) | answered Jun 19 '17, 3:29 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

As described here: https://rsjazz.wordpress.com/2012/12/14/do-not-modify-the-triggering-element-in-an-operationadvisor/ an advisor must not modify the data. An advisor can block an operation ("Advise on the operation"), however, the interface is not designed to allow changes to the incoming data. A follow up action can modify the data of an operation. 

Nagendra Prasad selected this answer as the correct answer

Comments
Nagendra Prasad commented Jun 19 '17, 3:43 a.m.

 Thanks much for the quick response ralph! Can i achieve this through a follow up action then ?


Ralph Schoon commented Jun 19 '17, 3:44 a.m. | edited Jun 19 '17, 3:45 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 As mentioned above:

A follow up action can modify the data of an operation. 
So you can try that.


Nagendra Prasad commented Jun 19 '17, 5:54 a.m.

 Sure. Thanks a lot!


Nagendra Prasad commented Jun 20 '17, 12:46 a.m.

 Hi Ralph, i tried the follow up action, but i see a Stale data error while trying to deliver any changeset where this follow up action is applied.


But when i complete the chengeset and deliver it, its getting delivered. Later when i accept the changeset, i can see the changeset comment being modified as i require.
Any idea why this happens ? Is it due to passing null in ISynchronizationTimes[] parameter of the setComment() method ? if so, how do i pass ISynchronizationTimes[] ?


Nagendra Prasad commented Jun 20 '17, 12:48 a.m.

 CRJAZ0223I The following item has been changed by another operation:

Input: com.ibm.team.scm.common.internal.impl.ChangeSetImpl@86ff758b (stateId: [UUID _OjWzQVVyEeeEyJGAUJn5vw], itemId: [UUID _OSeeoFVyEeeEyJGAUJn5vw], origin: <unset>, immutable: false) (contextId: [UUID _Dp6kMdwTEd2jUupDpQV1Rw], modified: 2017-06-20 10:07:54.85, workingCopy: true) (mergePredecessor: null, workingCopyPredecessor: [UUID _OYdK0FVyEeeEyJGAUJn5vw], workingCopyMergePredecessor: null, predecessor: null) (active: false, comment: hello world, lastUpdatedDate: 2017-06-20 10:07:54.85, sourceId: null, sourceType: 0, originalSourceId: null, originalSourceType: 0)


Nagendra Prasad commented Jun 20 '17, 12:48 a.m.

 Current: com.ibm.team.scm.common.internal.impl.ChangeSetImpl@aed37d5a (stateId: [UUID _OjnR8FVyEeeEyJGAUJn5vw], itemId: [UUID _OSeeoFVyEeeEyJGAUJn5vw], origin: <unset>, immutable: true) (contextId: [UUID _Dp6kMdwTEd2jUupDpQV1Rw], modified: 2017-06-20 10:07:54.959, workingCopy: false) (mergePredecessor: null, workingCopyPredecessor: <unset>, workingCopyMergePredecessor: <unset>, predecessor: [UUID _OYdK0FVyEeeEyJGAUJn5vw]) (active: true, comment: [NAGESH-SCM-TEST_20NOV2015]hello world, lastUpdatedDate: 2017-06-20 10:07:53.219, sourceId: null, sourceType: 0, originalSourceId: null, originalSourceType: 0)


Nagendra Prasad commented Jun 20 '17, 12:49 a.m.

Both comments above is the error description i see while delivering the changeset, had to post 2 comments cause of the character length limit.


Ralph Schoon commented Jun 20 '17, 3:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

A stale data is basically telling you that there is a new version of the item, so I refresh information I work with in a follow up action, before modifying it. I don't have an example where I tried to do what you do, so that is all  I can provide at the moment.


Nagesh Srinivas commented Jun 20 '17, 3:56 a.m.

Hi Ralph,

This advisor is setup on Deliver operation to amend the stream name into the change set comments.

Advisor is amending the comment with stream name [<stream name>] but meanwhile something else (???) is resetting comment back to original before deliver operation completes. So, there are conflicts with the comment data.

So, do you have any idea on what possible service is resetting the comment.?

Regards,

Nagesh S


Ralph Schoon commented Aug 01 '17, 7:22 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Nagesh, I don't and without trying it myself I can't. Unfortunately I don't have example code and the time to try this out.

I have used follow up actions with work items to modify the work item that was saved. That has worked for me and you can find examples on my blog e.g. where I refresh the work item before saving.

I have not tried that with SCM and SCM might be different. I am unable to help you here. Maybe other contributors have hints. If you could provide more of the code, e.g. somewhere online, maybe someone can spot something.

showing 5 of 10 show 5 more comments

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.