Replacing Baseline using API
I am trying to replace a baseline of a component via API. Unfortunately it is not working.
I am using
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)
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"