It's all about the answers!

Ask a question

RTC server side plugin : Getting null in operationData while creating baseline


Akash Kape (133) | asked Dec 05 '16, 7:37 a.m.
Hi,

I want to apply some naming convention to baseline but when I am creating baseline of the component I am getting "null" in  operationData.
Object operationData = operation.getOperationData();

But when I create snapshot I am getting the data.
I am not getting why operationData is getting null as a value when I create a baseline

Below is my code snippet,

/**
 *
 */
package com.fcagroup.pmbd.plugin.namingconvention;

import org.eclipse.core.runtime.IProgressMonitor;

import com.fcagroup.pmbd.plugin.FCANamingConventionUtility;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.IProjectArea;
import com.ibm.team.process.common.IProjectAreaHandle;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfo;
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.process.IModifyStreamOperationData;
import com.ibm.team.scm.service.internal.AbstractScmService;
import com.ibm.team.scm.service.internal.ScmService;

/**
 *
 * Class created to validate name convention of Snapshot
 * @author nileshp14
 *
 */
public class FCASnapShotNameAdvisor extends AbstractScmService
implements IOperationAdvisor{

    public void run(AdvisableOperation operation,
            IProcessConfigurationElement advisorConfiguration,
            IAdvisorInfoCollector collector, IProgressMonitor monitor)
            throws TeamRepositoryException {
       
        try
        {
            Object operationData = operation.getOperationData();
            if(operationData ==  null)return;
            if (!(operationData instanceof IModifyStreamOperationData)) {
                throw new IllegalArgumentException("Wrong type of argument: " + operationData);
            }
                       
            IModifyStreamOperationData opData = (IModifyStreamOperationData)operationData;
            //8-- OP type tells that, it is modified for snapshot name change
            if(opData.isOperationType(8))
            {
                String snapshotName = opData.getAddedBaselineSetName();
                if(snapshotName != null && !"".equals(snapshotName.trim()))
                {
                    IProjectAreaHandle projectAreaHandle = operation.getProcessArea().getProjectArea();
                    IRepositoryItemService repositoryItemService = getService(IRepositoryItemService.class);
                    IProjectArea projectArea = (IProjectArea) repositoryItemService.fetchItem(projectAreaHandle, IRepositoryItemService.COMPLETE);
                    String projectAreaName = projectArea.getName();
                    /*String machingPattern = projectAreaName + "_"+"[A-Z]*_[a-zA-Z0-9]{0,10}_[a-zA-Z0-9.a-zA-Z0-9]{0,10}_(Dev|RFI|Release)_[\\S]{0,15}_\\d*";*/
                    String matchingPattern = projectAreaName + "_"+"[a-zA-Z0-9]+{0,10}_[a-zA-Z0-9.a-zA-Z0-9]+{0,10}_(Dev|RFI|Release)_[a-zA-z0-9]+";
                    if(!FCANamingConventionUtility.isMatchingNamePattern(matchingPattern, snapshotName))
                    {
                        IAdvisorInfo createProblemInfo = collector.createProblemInfo("Save Operation failed.", "Incorrect naming convention for snapshot. '"+snapshotName+"' is not valid name.\n" +
                                "snapshot should match '<ProjectName>_<ModelYear>_<PhaseNumber>_<Dev|RFI|Release>_<ReasonForTheSnapshot>_<TaskType>' pattern, where \n"+
                                "1) ModelYear can be maximum 10 digit (alphanumerics) \n"+
                                "2) Phase Number can be maximum 10 characters \n"+
                                "3) Based on stream type choose Release/RFI/Dev (alphanumerics)\n"+
                                "4) Reason for creating snapshot \n"+
                                "5) TaskType is actual task number \n"+
                                "(PMBD_2019_1.0.0_Dev_TheActualReason_TaskType)"
                                , "error");
                        collector.addInfo(createProblemInfo);
                    }
                }
                else
                {
                    IAdvisorInfo createProblemInfo = collector.createProblemInfo("Save Operation failed.", "Snapshot name can not be null or empty.", "error");
                    collector.addInfo(createProblemInfo);
                }
            }
           
        }
        catch (Exception e)
        {
            System.err.println("Error ");
            e.printStackTrace();
        }
       
    }

}

A small piece of code would be helpful.
Thank you!


Comments
Kajal Chaudhari commented Dec 04 '18, 12:12 a.m. | edited Dec 05 '18, 12:01 a.m.

Optype for snapshot is 8 ..then what for baseline?

2 answers



permanent link
Ralph Schoon (63.2k33646) | answered Dec 05 '16, 8:10 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
 Without the plugin.xml, the operation ID and debugging I don't know who should be able to answer here. 
When you debug the code you can look at the AdvisableOperation  and check what data you really get. If you can't debug with Jetty, you should go here https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ and follow the Extensions Workshop and learn it.

Comments
Akash Kape commented Dec 06 '16, 1:09 a.m.

Thank you Ralph for your reply.
I am using tomcat server and I am able to debug the code.But the api itself returns null value in operationData  when I create baseline of the component.


Ralph Schoon commented Dec 06 '16, 1:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You should not debug on Tomcat, you should debug on Jetty. I have no example for what you do above and short of spending an hour and trying it myself, I can't help.


permanent link
David Lafreniere (4.8k7) | answered Dec 04 '18, 8:43 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
edited Dec 04 '18, 8:45 p.m.
IModifyStreamOperationData javadoc explains the operation types available, which are:

    /**
     * Operation type constant that indicates that a stream is being created.
     * The operation data for a create will contain property changes for the
     * fields that are being set (e.g. name, owner, description) but the
     * target workspace handle will be <code>null</code>.
     */
    public static final int CREATE = 1;
   
    /**
     * Operation type constant that indicates that a stream is being delete.
     * The operation data for a delete will not contain any property changes
     * or component deltas.
     */
   
    public static final int DELETE = 2;
   
    /**
     * Operation type that indicates that there are changes to properties of the stream.
     */
    public static final int CHANGES = 4;
   
    /**
     * Operation type that indicates that a baseline has been created or moved to the stream
     */
    public static final int ADD_BASELINE_SET = 8;



Note: Modifying or creating a baseline is not a 'property' of the stream, and thus it doesn't exist in the IModifyStreamOperationData.

Comments
Kajal Chaudhari commented Dec 04 '18, 11:40 p.m. | edited Dec 05 '18, 12:00 a.m.

 Modifying or creating baseline is comes under which API?


David Lafreniere commented Dec 04 '18, 11:59 p.m.
FORUM MODERATOR / JAZZ DEVELOPER

The API for creating a baseline is IScmService.createBaseline(...)
The API for modifying a baseline name is IScmService.setBaselineName(...)

, as of now (RTC 6.0.6.1), the 'modify baseline/snapshot' operation does not currently support advisors/participants (unlike the 'modify stream/component' operation). Please open an enhancement or RFE request if you want these operations to support advisors/participants.

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.