1

I am working currently on a project using RTC (Rational Team Concert) through Plain Java API. I have a online-repository on which I have a main stream named Sample_ROOT. From this stream I want to create another one named Sample_Client_Application. The Sample_Client_Application should have all components of Sample_ROOT and whenever changes are committed in Sample_ROOT, they have to be pushed into Sample_Client_Application.

I tried to implement all the process described above in eclipse with RTC Plain Java API with the code below.


/*
parentStream : represents Sample_ROOT
appStream : represents DTO of  Sample_Client_Application
projectStreams is a map of projects with their workspaces : HashMap<String, List<IWorkspaceHandle>> 
*/
public IWorkspaceConnection createAppInTeamAreas(String parentStream, StreamDTO appStream)
            throws TeamRepositoryException {
        monitor.println("Getting Workspace");
        IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repository);

        IWorkspaceConnection workspaceConnection = null;

        Optional<IWorkspaceHandle> handle = projectStreams.get(appStream.getProjectName()).stream().filter(xHandle -> {
            IWorkspace workspace = null;
            try {
                workspace = (IWorkspace) repository.itemManager().fetchCompleteItem(xHandle, IItemManager.DEFAULT,
                        null);
            } catch (TeamRepositoryException e) {
                e.printStackTrace();
            }
            return workspace != null && workspace.getName() == parentStream;
        }).findFirst();

        if (handle.isPresent()) {
            IWorkspace parentWorkSpace = null;
            try {
                parentWorkSpace = (IWorkspace) repository.itemManager().fetchCompleteItem(handle.get(),
                        IItemManager.DEFAULT, null);
            } catch (TeamRepositoryException e) {
                e.printStackTrace();
                return null;
            }
            IWorkspaceConnection parentConn = workspaceManager.getWorkspaceConnection(handle.get(), monitor);

            List<IComponentHandle> parentComps = (List<IComponentHandle>) parentConn.getComponents();
            IWorkspaceConnection childConn = null;
            IItemManager itemManager = repository.itemManager();

            for (IComponentHandle parentCompHandle : parentComps) {
                IItemHandle itemHandle = (IItemHandle) parentCompHandle;
                IComponent parentComp = (IComponent) itemManager.fetchCompleteItem(itemHandle, IItemManager.DEFAULT,
                        monitor);
                monitor.println(String.format("Component name : %s", parentComp.getName()));
                childConn = createAndAddSycrhronizedComponents(parentWorkSpace, parentComp, parentConn, appStream,
                        childConn);
            }
            workspaceConnection = childConn;
        }

        return workspaceConnection;
    }

    
    private IWorkspaceConnection createAndAddSycrhronizedComponents(IWorkspace parentStream, IComponent parentComp,
            IWorkspaceConnection parentConnection, StreamDTO childStream, IWorkspaceConnection childConnection) {

        IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repository);
        IWorkspaceConnection workspaceConnection = null;

        try {
            if (childConnection == null) {

                workspaceConnection = workspaceManager.createWorkspace(repository.loggedInContributor(),
                        childStream.getName(), childStream.getDescription(), monitor);
            } else {
                workspaceConnection = childConnection;
                 //Set flow for the newly created repository
                 IFlowTable flowTarget=workspaceConnection.getFlowTable().getWorkingCopy();
                 flowTarget.addDeliverFlow(parentStream, repository.getId(), repository.getRepositoryURI(), parentConnection.getComponents(), "Scoped");
                 flowTarget.addAcceptFlow(parentStream, repository.getId(), repository.getRepositoryURI(), parentConnection.getComponents(), "Scoped");
                 
                 flowTarget.setCurrent(flowTarget.getDeliverFlow(parentStream));
                 flowTarget.setCurrent(flowTarget.getAcceptFlow(parentStream));
                 flowTarget.setDefault(flowTarget.getDeliverFlow(parentStream));
                 flowTarget.setDefault(flowTarget.getAcceptFlow(parentStream));
                 
                 
                 workspaceConnection.setFlowTable(flowTarget, monitor);
                 
                 
                 //Add the components to the workspace
                 List<Object> componentsToBeAdded=new ArrayList<>();
                 componentsToBeAdded.add(workspaceConnection.componentOpFactory().addComponent(parentComp, true));
                 workspaceConnection.applyComponentOperations(componentsToBeAdded, monitor);
                 
                 //Accept stream changes to local repository
                 IChangeHistorySyncReport streamChangeHistorySyncReport=workspaceConnection.compareTo(parentConnection, WorkspaceComparisonFlags.INCLUDE_BASELINE_INFO, Collections.EMPTY_LIST, null);
                 workspaceConnection.accept(AcceptFlags.DEFAULT, parentConnection, streamChangeHistorySyncReport, streamChangeHistorySyncReport.incomingBaselines(parentComp), streamChangeHistorySyncReport.incomingChangeSets(parentComp), monitor);

        
                
            }
        } catch (TeamRepositoryException e) {
            e.printStackTrace();
        }

        return workspaceConnection;
    }



Sample_Client_Application is created successfully but it has no components. Can anyone help me Please ?

Brandon
  • 33
  • 6

0 Answers0