RTC :6.0 : Get List of the components from stream
I am able to get/print the list of the streams in a project. I want to print the Components in any particular stream. And the list of all the files in any of the particular componenet without bother about the folder structure in the components. Thanks.!!
Here is the code i have used to print the list of the streams.
wsSearchCriteria.setPartialOwnerNameIgnoreCase("Project Name");
List <IWorkspaceHandle> workspaceHandles123 = wm.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, null);
List<String> streamNames = new ArrayList<String>(workspaceHandles.size());
IFetchResult fetchResults = repository.itemManager().fetchCompleteItemsPermissionAware(workspaceHandles, IItemManager.REFRESH, null);
List<Object> retrievedStreams = fetchResults.getRetrievedItems();
for (Object fetchedObject : retrievedStreams)
{
if (fetchedObject instanceof IWorkspace)
{
IWorkspace stream = (IWorkspace) fetchedObject;
System.out.println(stream.getName());
}
}
Here is the code i have used to print the list of the streams.
wsSearchCriteria.setPartialOwnerNameIgnoreCase("Project Name");
List <IWorkspaceHandle> workspaceHandles123 = wm.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, null);
List<String> streamNames = new ArrayList<String>(workspaceHandles.size());
IFetchResult fetchResults = repository.itemManager().fetchCompleteItemsPermissionAware(workspaceHandles, IItemManager.REFRESH, null);
List<Object> retrievedStreams = fetchResults.getRetrievedItems();
for (Object fetchedObject : retrievedStreams)
{
if (fetchedObject instanceof IWorkspace)
{
IWorkspace stream = (IWorkspace) fetchedObject;
System.out.println(stream.getName());
}
}
3 answers
Set up your environment for debugging and the ability to see the source code. Follow https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ to do that. Also see https://rsjazz.wordpress.com/2013/09/24/managing-workspaces-streams-and-components-using-the-plain-java-client-libraries/
To get the component from a workspace/stream use IWorkspaceConnection.getComponents()
To get the component from a workspace/stream use IWorkspaceConnection.getComponents()
public IWorkspaceHandle getStreamHandleByName(String projectName,String streamName ) throws TeamRepositoryException {
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
IWorkspaceHandle stream = null;
boolean not_found = true;
// Check stream name
if (streamName == null) {
throw new TeamRepositoryException("Stream Name required");
}
// Create search criteria
IWorkspaceSearchCriteria crit = IWorkspaceSearchCriteria.FACTORY.newInstance();
crit.setExactName(streamName);
crit.setExactOwnerName(projectName);
crit.setKind(IWorkspaceSearchCriteria.STREAMS);
List streams = wm.findWorkspaces(crit, 1, MONITOR);
Iterator it = streams.iterator();
if (!(it.hasNext())) {
// Check if stream is owned by a team
IProjectArea project = getProjectByName(projectName);
List teamAreas = project.getTeamAreas();
Iterator itt = teamAreas.iterator();
while (not_found && itt.hasNext()) {
ITeamAreaHandle teamAreaHandle = (ITeamAreaHandle) itt.next();
ITeamArea teamArea = (ITeamArea)repo.itemManager().fetchCompleteItem((ITeamAreaHandle)teamAreaHandle, IItemManager.DEFAULT, MONITOR);
String teamName = teamArea.getName();
// Create search Criteria
crit.setExactOwnerName(teamName);
streams = wm.findWorkspaces(crit, Integer.MAX_VALUE, MONITOR);
for (it = streams.iterator(); it.hasNext();) {
stream = (IWorkspaceHandle) it.next();
not_found = false;
}
}
} else {
// Load stream handle
stream = (IWorkspaceHandle) it.next();
not_found = false;
}
if (not_found) {
throw new TeamRepositoryException("Could not find Stream " + streamName);
}
return stream;
}
// to get components in a stream
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
IWorkspaceHandle streamHandle = getStreamHandleByName(projectName,streamName);
IWorkspaceConnection stream = wm.getWorkspaceConnection(streamHandle, null);
// Get component Handle
List components = stream.getComponents();
List comps = new ArrayList();
for (Iterator a = components.iterator(); a.hasNext();) {
IComponentHandle compHandle = (IComponentHandle) a.next();
IComponent comp = (IComponent)repo.itemManager().fetchCompleteItem(compHandle, IItemManager.DEFAULT, MONITOR);
}
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
IWorkspaceHandle stream = null;
boolean not_found = true;
// Check stream name
if (streamName == null) {
throw new TeamRepositoryException("Stream Name required");
}
// Create search criteria
IWorkspaceSearchCriteria crit = IWorkspaceSearchCriteria.FACTORY.newInstance();
crit.setExactName(streamName);
crit.setExactOwnerName(projectName);
crit.setKind(IWorkspaceSearchCriteria.STREAMS);
List streams = wm.findWorkspaces(crit, 1, MONITOR);
Iterator it = streams.iterator();
if (!(it.hasNext())) {
// Check if stream is owned by a team
IProjectArea project = getProjectByName(projectName);
List teamAreas = project.getTeamAreas();
Iterator itt = teamAreas.iterator();
while (not_found && itt.hasNext()) {
ITeamAreaHandle teamAreaHandle = (ITeamAreaHandle) itt.next();
ITeamArea teamArea = (ITeamArea)repo.itemManager().fetchCompleteItem((ITeamAreaHandle)teamAreaHandle, IItemManager.DEFAULT, MONITOR);
String teamName = teamArea.getName();
// Create search Criteria
crit.setExactOwnerName(teamName);
streams = wm.findWorkspaces(crit, Integer.MAX_VALUE, MONITOR);
for (it = streams.iterator(); it.hasNext();) {
stream = (IWorkspaceHandle) it.next();
not_found = false;
}
}
} else {
// Load stream handle
stream = (IWorkspaceHandle) it.next();
not_found = false;
}
if (not_found) {
throw new TeamRepositoryException("Could not find Stream " + streamName);
}
return stream;
}
// to get components in a stream
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(repo);
IWorkspaceHandle streamHandle = getStreamHandleByName(projectName,streamName);
IWorkspaceConnection stream = wm.getWorkspaceConnection(streamHandle, null);
// Get component Handle
List components = stream.getComponents();
List comps = new ArrayList();
for (Iterator a = components.iterator(); a.hasNext();) {
IComponentHandle compHandle = (IComponentHandle) a.next();
IComponent comp = (IComponent)repo.itemManager().fetchCompleteItem(compHandle, IItemManager.DEFAULT, MONITOR);
}
this will find a file in a component, you can probaly mod it to give all files
@SuppressWarnings("unchecked")
public IVersionableHandle findfile(IFolderHandle root,IConfiguration iconfig,String fileName)
throws TeamRepositoryException {
String fileNamePath[] = {fileName};
IVersionableHandle filePathHandle = null;
// Check if file at this folder level
filePathHandle = iconfig.resolvePath(root,fileNamePath, MONITOR);
if (filePathHandle != null) {
return filePathHandle;
}
// Check this file sub folders
Map<String, IVersionableHandle> childEntries = iconfig.childEntries(root,MONITOR);
for(Map.Entry<String, IVersionableHandle> next : childEntries.entrySet()) {
IVersionableHandle nextVersionable = next.getValue();
if (nextVersionable instanceof IFolderHandle) {
filePathHandle = findfile((IFolderHandle) nextVersionable,iconfig,fileName);
if (filePathHandle != null) {
break;
}
}
}
return filePathHandle;
}
// Get component root folder
IWorkspaceConnection stream = null;
IConfiguration iconfig = (IConfiguration) stream.configuration(component);
IFolderHandle root = iconfig.rootFolderHandle(MONITOR);
IVersionableHandle filePathHandle = findfile(root,iconfig,fileName)
@SuppressWarnings("unchecked")
public IVersionableHandle findfile(IFolderHandle root,IConfiguration iconfig,String fileName)
throws TeamRepositoryException {
String fileNamePath[] = {fileName};
IVersionableHandle filePathHandle = null;
// Check if file at this folder level
filePathHandle = iconfig.resolvePath(root,fileNamePath, MONITOR);
if (filePathHandle != null) {
return filePathHandle;
}
// Check this file sub folders
Map<String, IVersionableHandle> childEntries = iconfig.childEntries(root,MONITOR);
for(Map.Entry<String, IVersionableHandle> next : childEntries.entrySet()) {
IVersionableHandle nextVersionable = next.getValue();
if (nextVersionable instanceof IFolderHandle) {
filePathHandle = findfile((IFolderHandle) nextVersionable,iconfig,fileName);
if (filePathHandle != null) {
break;
}
}
}
return filePathHandle;
}
// Get component root folder
IWorkspaceConnection stream = null;
IConfiguration iconfig = (IConfiguration) stream.configuration(component);
IFolderHandle root = iconfig.rootFolderHandle(MONITOR);
IVersionableHandle filePathHandle = findfile(root,iconfig,fileName)