Create Repository Workspace, Load Components, Set Flow Table and Accept Change sets – IBM RTC Plain Java API
IBM RTC Source Control automation needs a local repository workspace baselined with the RTC Stream for its operation. The local repository workspace should accept pending changes from server in order to push any new change set through IBM RTC Plain Java API or through RTC Interface Integrated with Eclipse.
In the below post we have explained how to create a local user repository workspace, load available components from stream to the local repository, set its flow target to accept incoming changes and deliver outgoing changes to stream.
The coding in this blogs are those of the developers working on RTC automation and does not represent IBM’s positions, strategies or opinions.
There are many ways available to create a Local Repository Workspace. In this post we have explained two approaches by with local repository can be created.
Identifying the Stream to which local repository workspace to be created is common to both the approach and the below link will help you to achieve the same.
Approach 1: Get Stream Repository Connection and let the IBM RTC Plain Java API to handle the process of loading components and setting flow target.
In this method all the components available in the Stream Repository will be loaded to the local repository.
For this approach we only need to have IWorkspaceConnection object to the Stream to which the local repository is to be created. The below code lets you to achieve the same.
public IWorkspaceConnection createUserRepository(IWorkspace stream,IComponent component) { try { IWorkspaceManager iWorkspaceManager=SCMPlatform.getWorkspaceManager(repository); IWorkspaceConnection streamWorkspaceConnection=iWorkspaceManager.getWorkspaceConnection(stream, null); IWorkspaceConnection localWorkspaceConnection=iWorkspaceManager.createWorkspace(repository.loggedInContributor(), stream.getName()+"_CreatedFromCode", "Created using IBM RTC Plain Java Auto FlowTable Set and Componenets Load", streamWorkspaceConnection, streamWorkspaceConnection, null); //Accept stream changes to local repository IChangeHistorySyncReport streamChangeHistorySyncReport=localWorkspaceConnection.compareTo(streamWorkspaceConnection, WorkspaceComparisonFlags.INCLUDE_BASELINE_INFO, Collections.EMPTY_LIST, null); localWorkspaceConnection.accept(AcceptFlags.DEFAULT, streamWorkspaceConnection, streamChangeHistorySyncReport, streamChangeHistorySyncReport.incomingBaselines(component), streamChangeHistorySyncReport.incomingChangeSets(component), null); return localWorkspaceConnection; } catch(Exception e) { System.out.println(e.toString()); return null; } }
Approach 2: Get Stream Repository Connection and manually load the necessary components and set flow to the repository.
- Create local/user repository workspace and get its IWorkspaceConnection
- Set the AcceptFlow and DeliverFlow for the local repository workspace connection
- Add the components to the local repository workspace
Create Local Repository Workspace
In the below method signature of iWorkspaceManager.createWorkspace() we are not providing any Stream Workspace connection object, hence a blank workspace without reference to any stream is created here. The scope of the created repository workspace is private and owned by the logged in user of IBM RTC Plain Java API.
IWorkspaceManager iWorkspaceManager=SCMPlatform.getWorkspaceManager(repository); IWorkspaceConnection localWorkspaceConnection=iWorkspaceManager.createWorkspace (repository.loggedInContributor(), stream.getName()+"_CreatedFromCode", "Created using IBM RTC Plain Java", null);
Set Flow Table (Accept Flow and Delivery Flow) to local repository workspace
//Set flow for the newly created repository IFlowTable flowTarget=localWorkspaceConnection.getFlowTable().getWorkingCopy(); flowTarget.addDeliverFlow(stream, null, null, streamWorkspaceConnection.getComponents(), "Scoped"); flowTarget.addAcceptFlow(stream, null, null, streamWorkspaceConnection.getComponents(), "Scoped"); flowTarget.setCurrent(flowTarget.getDeliverFlow(stream)); flowTarget.setCurrent(flowTarget.getAcceptFlow(stream)); flowTarget.setDefault(flowTarget.getDeliverFlow(stream)); flowTarget.setDefault(flowTarget.getAcceptFlow(stream)); localWorkspaceConnection.setFlowTable(flowTarget, null);
Add Components to the local repository workspace
//Add the components to the workspace List<Object> componentsToBeAdded=new ArrayList<>(); componentsToBeAdded.add(localWorkspaceConnection.componentOpFactory().addComponent(component, true)); localWorkspaceConnection.applyComponentOperations(componentsToBeAdded, null);
Accepting Stream Changes to Local Repository Workspace
In both approaches we have created local repository workspace and loaded its components, still if we need to deliver some change sets to the stream we need to accept the pending changes from stream to our local repository.
To accept the pending changes from Stream to Local Repository, create a ChangeHistorySyncReport between stream and local repository and accept the changes to local repository.
//Accept stream changes to local repository IChangeHistorySyncReport streamChangeHistorySyncReport=localWorkspaceConnection.compareTo(streamWorkspaceConnection, WorkspaceComparisonFlags.INCLUDE_BASELINE_INFO, Collections.EMPTY_LIST, null); localWorkspaceConnection.accept(AcceptFlags.DEFAULT, streamWorkspaceConnection, streamChangeHistorySyncReport, streamChangeHistorySyncReport.incomingBaselines(component), streamChangeHistorySyncReport.incomingChangeSets(component), null);
The full working module for Approach 2 is given below
public IWorkspaceConnection createUserRepository(IWorkspace stream,IComponent component) { try { IWorkspaceManager iWorkspaceManager=SCMPlatform.getWorkspaceManager(repository); IWorkspaceConnection streamWorkspaceConnection=iWorkspaceManager.getWorkspaceConnection(stream, null); IWorkspaceConnection localWorkspaceConnection=iWorkspaceManager.createWorkspace (repository.loggedInContributor(), stream.getName()+"_CreatedFromCode", "Created using IBM RTC Plain Java", null); //Set flow for the newly created repository IFlowTable flowTarget=localWorkspaceConnection.getFlowTable().getWorkingCopy(); flowTarget.addDeliverFlow(stream, null, null, streamWorkspaceConnection.getComponents(), "Scoped"); flowTarget.addAcceptFlow(stream, null, null, streamWorkspaceConnection.getComponents(), "Scoped"); flowTarget.setCurrent(flowTarget.getDeliverFlow(stream)); flowTarget.setCurrent(flowTarget.getAcceptFlow(stream)); flowTarget.setDefault(flowTarget.getDeliverFlow(stream)); flowTarget.setDefault(flowTarget.getAcceptFlow(stream)); localWorkspaceConnection.setFlowTable(flowTarget, null); //Add the components to the workspace List<Object> componentsToBeAdded=new ArrayList<>(); componentsToBeAdded.add(localWorkspaceConnection.componentOpFactory().addComponent(component, true)); localWorkspaceConnection.applyComponentOperations(componentsToBeAdded, null); //Accept stream changes to local repository IChangeHistorySyncReport streamChangeHistorySyncReport=localWorkspaceConnection.compareTo(streamWorkspaceConnection, WorkspaceComparisonFlags.INCLUDE_BASELINE_INFO, Collections.EMPTY_LIST, null); localWorkspaceConnection.accept(AcceptFlags.DEFAULT, streamWorkspaceConnection, streamChangeHistorySyncReport, streamChangeHistorySyncReport.incomingBaselines(component), streamChangeHistorySyncReport.incomingChangeSets(component), null); return localWorkspaceConnection; } catch(Exception e) { System.out.println(e.toString()) return null; } }
Get IContributor for User Id
To change the repository owner replace the repository.loggedInContributor() for both the approaches with the corresponding users IContributorHandle Object. You can use the below method to get the IContributor object for an RTC User Id.
repository.contributorManager().fetchContributorByUserId(“id”, null)