Get Available Project Areas, Stream and its Components for a user – IBM RTC Plain Java API
Working on IBM RTC Source Control requires frequent access to the Project Areas, Stream and its Components. In the below post we have explained how to access the same using IBM RTC Plain Java API.
We thank RSJAZZ Ralph and JAZZ Community for making RTC automation possible. The coding in this blogs are those of the developers working on RTC automation and does not represent IBM’s positions, strategies or opinions.
To execute most of the RTC related operations, a logged in repository connection to RTC is needed. Kindly check on the link for how to log in to RTC using Plan Java API https://jazz.net/library/article/1229
Get available Project Areas for an user from RTC
public void getAvailableProjectAreasForUser(IContributor user) { try { IProcessItemService processItemService=(IProcessItemService)repository.getClientLibrary(IProcessItemService.class); List userProcessAreas=processItemService.findProcessAreas(user, null, IProcessClientService.ALL_PROPERTIES, null); //Fetch the available Process Areas for the user for (Object object : userProcessAreas) { //The fetched Process Areas will be having Team Areas and Project Areas. if(object instanceof ProjectArea) { System.out.println(((IProjectArea)object).getName()); } else if (object instanceof TeamArea) { //Get corresponding Project Area from Team Area System.out.println((IProjectArea)repository.itemManager().fetchCompleteItem(((TeamArea)object).getProjectArea(), ItemManager.DEFAULT, null).getName()); } } } catch(Exception e) { System.out.println(e.toString()); } }
processItemService.findProcessAreas(user, null, IProcessClientService.ALL_PROPERTIES, null)
can be used to fetch the Team Areas and Project Areas. If only Project Areas are needed we can use the condition check filter to fetch only Project Areas.
Get Project Area From Team Area
System.out.println((IProjectArea)repository.itemManager().fetchCompleteItem(((TeamArea)object).getProjectArea(), ItemManager.DEFAULT, null).getName());
Since the TeamArea extends ProcessArea we have access to the function getProjectArea() which provides us an object of IProjectAreaHandle.
Now we can use itemManager().fetchCompleteItem() to resolve the IProjectAreaHandle to IProjectArea.
Get available Project Areas for an logged in user
We can call the method getAvailableProjectAreasForUser with the logged in Contributor from repository object to get the available project areas for the him like shown below
getAvailableProjectAreasForUser(repository.loggedInContributor())
Get available Streams from Project Area
public void getAllStreamsUnderProjectArea(String ProjectAreaName) { try { IWorkspaceManager iWorkspaceManager=SCMPlatform.getWorkspaceManager(repository); IWorkspaceSearchCriteria workspaceSearchCriteria=IWorkspaceSearchCriteria.FACTORY.newInstance().setKind(IWorkspaceSearchCriteria.STREAMS); workspaceSearchCriteria.setExactName(""); workspaceSearchCriteria.setExactOwnerName(ProjectAreaName); List<IWorkspaceHandle> foundWorkSpace =iWorkspaceManager.findWorkspaces(workspaceSearchCriteria, Integer.MAX_VALUE, null); for(IWorkspaceHandle xHandle:foundWorkSpace) { System.out.println(((IWorkspace) repository.itemManager().fetchCompleteItem(xHandle,IItemManager.DEFAULT, null)).getName()); } } catch(Exception e) { System.out.println(e.toString()); } }
We need to create a WorkspaceSearchCriteria
with the setExactName
set to empty and setExactOwnerName
to the project area to name to get all the streams under the given project area. It is important to set the WorkspaceSearchCriteria kind to STREAMS
Once the search criteria object is created use the iWorkspaceManager.findWorkspaces
to get the available streams.
Get available Components from Stream
public void getAllComponentsUnderStream(IWorkspaceHandle StreamHandle) { try { IWorkspaceManager iWorkspaceManager=SCMPlatform.getWorkspaceManager(repository); IWorkspaceConnection iWorkspaceConnection = iWorkspaceManager.getWorkspaceConnection(StreamHandle, null); @SuppressWarnings("rawtypes") List foundComponents=iWorkspaceConnection.getComponents(); for (Object object : foundComponents) { if(object instanceof ComponentHandle) { System.out.println(((IComponent) repository.itemManager().fetchCompleteItem((ComponentHandle)object,IItemManager.DEFAULT, null)).getName()); } } } catch(Exception e) { System.out.println(e.toString()); } }
To get the available components create a workspace connection to the IWorkspaceHandle
of the stream and call getComponents()
to fetch the components
List foundComponents=iWorkspaceConnection.getComponents();