It's all about the answers!

Ask a question

Replacing Baseline using API


Aley Zaidi (43111) | asked Oct 20 '15, 4:07 a.m.
edited Oct 20 '15, 5:52 a.m.
I am trying to replace a baseline of a component via API. Unfortunately it is not working.
I am using
public void replace(IWorkspaceConnection workspace, IBaselineConnection sourceBaseline); 
of
IWorkspaceUpdateOperation class.

Here is my scenario:
I have a stream "ComponentContainer_Stream" with following components
- Comp1 - (1:InitialBaseline 2:bl1 3:bl2)
- Comp2 - (1:InitialBaseline 2:bl1 3:bl2)
- Comp3 - (1:InitialBaseline 2:bl1 3:bl2)
with different baselines as mentioned above.

My Use Cases are as follows:

Use Case #1
- A Stream "Stream_Target" (Empty, have no component within it)
-  I want to add Comp2(bl1) in to Stream_Target

Use Case #2
- A Stream "Stream_Target" has Comp2(bl1)
-  I want to replace Comp2(bl1) with Comp2(bl2) in Stream_Target

Use Case #3
- A Stream "Stream_Target" has Comp2(bl2)
-  I want to replace Comp2(bl2) with Comp2(bl1) in Stream_Target


Here is my Code (To make it readable, I have removed try catch blocks)
private static String _repository ="{repository}";
private static String _projectName = "{Project name}";
private static String _user = "{userId}";  
private static String _pwd ="{pwd}";
private static String _stream = "{Stream name}";
private static ITeamRepository teamRepository;
private static IWorkspaceHandle wsHandle;
private static IWorkspaceConnection wsConn;
private static IWorkspaceManager wm;
//team repository and login
teamRepository = TeamPlatform.getTeamRepositoryService().getTeamRepository(repositoryURI);
teamRepository.registerLoginHandler(new LoginHandler(userId, password));
teamRepository.login(null);
// Workspace manager
wm = SCMPlatform.getWorkspaceManager(teamRepository);
// load stream
IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
wsSearchCriteria.setExactOwnerName({projectName});
wsSearchCriteria.setExactName("Stream_Target");
wsSearchCriteria.setExactOwnerName("{OwnerName}");
wsHandle = wsHandleList.get(0);
// workspace connection to the stream
wsConn = wm.getWorkspaceConnection(wsHandle, null);

// find & load a componenthandle for component "Comp2"
IComponentHandle currentCompHandle = wm.findComponents(IComponentSearchCriteria.FACTORY.newInstance().setExactName("Comp2"), Integer.MAX_VALUE, null).get(0);
// find all baselineHandles for the component handle of Comp2 
List<IBaselineHandle> blHandles = wm.findBaselines(IBaselineSearchCriteria.FACTORY.newInstance().setComponentRequired(compHandle), Integer.MAX_VALUE, null);
 for (IBaselineHandle blHandle: blHandles ) {
     // fetch IBaseline from BaselineHandle
     IBaseline desiredBaseline = (IBaseline) teamRepository.itemManager().fetchCompleteItem(blHandle, IItemManager.DEFAULT, null);
     // compare baselineName with baselineName as specified in UseCase, if it is our required baseline which is to be added.
     if ("bl1".equalsIgnoreCase(desiredBaseline.getName()) {

        // replace baseline operation
        IBaselineConnection desiredBaselineConnection = wm.getBaselineConnection(blHandle, null);
        IWorkspaceUpdateOperation wsUpdateOp = IOperationFactory.instance.getWorkspaceUpdateOperation(WorkspaceUpdateDilemmaHandler.getDefault());
        wsUpdateOp.replace(wsConn, desiredBaselineConnection);
      }
      // I expected that Comp1(bl2) will be added to "Stream_Target"
      // But no component is added to "Stream_Target"

Accepted answer


permanent link
Ralph Schoon (63.1k33646) | answered Oct 20 '15, 1:15 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
See https://rsjazz.wordpress.com/2013/09/30/delivering-change-sets-and-baselines-to-a-stream-using-the-plain-java-client-libraries/
Aley Zaidi selected this answer as the correct answer

One other answer



permanent link
Aley Zaidi (43111) | answered Oct 28 '15, 11:21 a.m.
Thanks Ralph. It worked

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.