It's all about the answers!

Ask a question

How to get RTC Stream URL from Java API


Chandan M B (1133574) | asked Nov 17 '21, 9:57 a.m.

 Hello All,


I need to get the Stream URL from Java API.
This URL will be stored for documentation purpose and when user paste this link in browser, it should get resolved and navigate to corresponding stream in browser

Regards,
Chandan

Accepted answer


permanent link
Ralph Schoon (63.1k33646) | answered Nov 18 '21, 8:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I am not totally sure if this works for you, but I would suggest to look into 



                logger.info("Publish links to build result...");
                IBuildResult buildResult = BuildUtil.getBuildResult(teamRepository, buildResultUUID, monitor);

            URI componentURI = URIUtil.getURIForItem(componentHandle);
            BuildUtil.publishLink(teamRepository, buildResult, "IP Links", componentURI.toString(),
                    "Component - " + componentName, monitor);

            URI baselineURI = URIUtil.getURIForItem(baseline.getBaseline());
            BuildUtil.publishLink(teamRepository, buildResult, "IP Links", baselineURI.toString(),
                    "Baseline - " + baselineName, monitor);

            URI streamURI = URIUtil.getURIForItem(targetStream.getResolvedWorkspace().getItemHandle());
            BuildUtil.publishLink(teamRepository, buildResult, "IP Links", streamURI.toString(),
                    "Stream - " + scmConnection, monitor);
</pre>


Chandan M B selected this answer as the correct answer

Comments
Chandan M B commented Nov 18 '21, 8:42 a.m.
Thanks Ralph.
I will test this. How about getting the component url. Is it the similar way ?

My current output based on above code will lead like below

Ralph Schoon commented Nov 18 '21, 8:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Look at the URIUtil it uses available code to get the URI from a handle. The API know how to make the rest. 


public static URI getURIForItem(IItemHandle item) {
Location location = Location.itemLocation(item, getPublicURI(item));
return location.toAbsoluteUri();
}

Should not be too difficult to get the code and test it.
 


Chandan M B commented Nov 18 '21, 11:22 a.m.
Thanks Ralph.
Both the way works. I opted for URIUtil to get both Stream and Component URI.

One other answer



permanent link
Chandan M B (1133574) | answered Nov 18 '21, 7:33 a.m.
edited Nov 18 '21, 7:35 a.m.

 I tried the constructing the Stream URL from Java API.

Thanks to Ralph blog scm

Code Snippet 

                private static String BASE_STREAM_URL = "resource/itemOid/com.ibm.team.scm.Workspace/";
                TeamPlatform.startup();
        String repositoryURI = "https://xxx/ccm";
        String userId = "xxx";
        String password = "xxx";
        ITeamRepository teamRepository = TeamPlatform
                .getTeamRepositoryService().getTeamRepository(repositoryURI);
            teamRepository.registerLoginHandler(new LoginHandler(userId, password));
            teamRepository.login(null);

        IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(teamRepository);
        IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();
        wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
        wsSearchCriteria.setPartialOwnerNameIgnoreCase("xxx");   // Provide the project Area Name
        List&lt;IWorkspaceHandle&gt; workspaceHandles = findConnections(workspaceManager,wsSearchCriteria);
        List&lt;? extends IWorkspaceConnection&gt; connections = workspaceManager.getWorkspaceConnections(workspaceHandles, null);
        System.out.println(workspaceHandles.size());
        for (Iterator&lt;? extends IWorkspaceConnection&gt; iterator = connections.iterator(); iterator.hasNext();) {
            IWorkspaceConnection workspaceConnection = (IWorkspaceConnection) iterator.next();
            String workspaceConnectionName = workspaceConnection.getName();
            System.out.println(workspaceConnectionName);
            System.out.println(teamRepository.getRepositoryURI()+BASE_STREAM_URL+workspaceConnection.getContextHandle().getItemId().getUuidValue());
        }

                  private static List<IWorkspaceHandle> findConnections(IWorkspaceManager workspaceManager,IWorkspaceSearchCriteria criteria) throws TeamRepositoryException {
             List<IWorkspaceHandle> connections = workspaceManager.findWorkspaces(criteria, Integer.MAX_VALUE, null);
             return connections;
              }

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.