Retrieve list of streams in a project area programatically
Hi All,
I am lloking to get the stream names from a project area and add the values into an enumeration. My Plugin is a server-side extension. Which methods can be used to achieve this?
I got the below code - but this is client-specific. Pls suggest an alternate code for server
IProgressMonitor monitor = new NullProgressMonitor();
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(teamRepository);
IWorkspaceSearchCriteria wsSearchCriteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
wsSearchCriteria.setPartialOwnerNameIgnoreCase(ProjectArea);
List <IWorkspaceHandle> workspaceHandles = wm.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, monitor);
List<String> streamNames = new ArrayList<String>(workspaceHandles.size());
IFetchResult fetchResults = teamRepository.itemManager().fetchCompleteItemsPermissionAware(workspaceHandles, IItemManager.REFRESH, monitor);
List<Object> retrievedStreams = fetchResults.getRetrievedItems();
for (Object fetchedObject : retrievedStreams) {
if (fetchedObject instanceof IWorkspace) {
IWorkspace stream = (IWorkspace) fetchedObject;
streamNames.add(stream.getName());
}
}
Thanks.
I am lloking to get the stream names from a project area and add the values into an enumeration. My Plugin is a server-side extension. Which methods can be used to achieve this?
I got the below code - but this is client-specific. Pls suggest an alternate code for server
IProgressMonitor monitor = new NullProgressMonitor();
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(teamRepository);
IWorkspaceSearchCriteria wsSearchCriteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
wsSearchCriteria.setPartialOwnerNameIgnoreCase(ProjectArea);
List <IWorkspaceHandle> workspaceHandles = wm.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, monitor);
List<String> streamNames = new ArrayList<String>(workspaceHandles.size());
IFetchResult fetchResults = teamRepository.itemManager().fetchCompleteItemsPermissionAware(workspaceHandles, IItemManager.REFRESH, monitor);
List<Object> retrievedStreams = fetchResults.getRetrievedItems();
for (Object fetchedObject : retrievedStreams) {
if (fetchedObject instanceof IWorkspace) {
IWorkspace stream = (IWorkspace) fetchedObject;
streamNames.add(stream.getName());
}
}
Thanks.
8 answers
Hi Michele,
I used this line below and am getting an error saying "cannot make a static reference to the non-static method findWorkspaces from the type ScmQueryService" at compilation itself
List<IWorkspaceHandle> streams = ScmQueryService.findWorkspaces(criteria, Integer.MAX_VALUE , (IRepositoryProgressMonitor) monitor).getItemHandles()
Am not sure how to fetch results as below to use fetchitems method
IFetchResult ws1 = (IFetchResult) ?.fetchItem(workspaceHandle, IRepositoryItemService.COMPLETE);
Complete part of the code looks like below:
criteria.setKind( IWorkspaceSearchCriteria.STREAMS );
criteria.setPartialOwnerNameIgnoreCase("ccm_user");
criteria.setPartialOwnerNameIgnoreCase("Demo Formal");
List<IWorkspaceHandle> streams = ScmQueryService.findWorkspaces(criteria, Integer.MAX_VALUE , (IRepositoryProgressMonitor) monitor).getItemHandles();
List<String> streamNames = new ArrayList<String>(workspaceHandles.size());
if (workspaceHandles.size() > 1)
{
throw new TeamRepositoryException( workspaceHandles.size() + " \"" + streamNames + "\" streams found" );
}
if (!workspaceHandles.isEmpty())
{
IWorkspaceHandle workspaceHandle = workspaceHandles.get( 0 );
IItemHandle it = workspaceHandle.getFullState();
IFetchResult ws1 = (IFetchResult) ?.fetchItem(workspaceHandle, IRepositoryItemService.COMPLETE);
if (ws1 instanceof IWorkspace) {
IWorkspace stream = (IWorkspace) ws1;
streamNames.add(stream.getName());
System.out.println("First Stream name is" + streamNames.get(0));
}
}
Thanks.
I used this line below and am getting an error saying "cannot make a static reference to the non-static method findWorkspaces from the type ScmQueryService" at compilation itself
List<IWorkspaceHandle> streams = ScmQueryService.findWorkspaces(criteria, Integer.MAX_VALUE , (IRepositoryProgressMonitor) monitor).getItemHandles()
Am not sure how to fetch results as below to use fetchitems method
IFetchResult ws1 = (IFetchResult) ?.fetchItem(workspaceHandle, IRepositoryItemService.COMPLETE);
Complete part of the code looks like below:
criteria.setKind( IWorkspaceSearchCriteria.STREAMS );
criteria.setPartialOwnerNameIgnoreCase("ccm_user");
criteria.setPartialOwnerNameIgnoreCase("Demo Formal");
List<IWorkspaceHandle> streams = ScmQueryService.findWorkspaces(criteria, Integer.MAX_VALUE , (IRepositoryProgressMonitor) monitor).getItemHandles();
List<String> streamNames = new ArrayList<String>(workspaceHandles.size());
if (workspaceHandles.size() > 1)
{
throw new TeamRepositoryException( workspaceHandles.size() + " \"" + streamNames + "\" streams found" );
}
if (!workspaceHandles.isEmpty())
{
IWorkspaceHandle workspaceHandle = workspaceHandles.get( 0 );
IItemHandle it = workspaceHandle.getFullState();
IFetchResult ws1 = (IFetchResult) ?.fetchItem(workspaceHandle, IRepositoryItemService.COMPLETE);
if (ws1 instanceof IWorkspace) {
IWorkspace stream = (IWorkspace) ws1;
streamNames.add(stream.getName());
System.out.println("First Stream name is" + streamNames.get(0));
}
}
Thanks.
Hi Muthukumar,
I did refer this link previously. But, there are 2 main problems:
I did refer this link previously. But, there are 2 main problems:
1. SportServiceData is not recognized 2. if i add cast <
SportServiceData
> to the function, then it says: "The method getScmQueryService() is undefined for the type SportServiceData"
Lines affected:
public static IWorkspace findStream( String streamName,SportServiceData commonData)
IScmQueryService scmQueryService = commonData.getScmQueryService();
Alternate tried:
public static <SportServiceData> IWorkspace findStream( String streamName,SportServiceData commonData )throws TeamRepositoryException
Thanks.
Hi Muthukumar,
I have changed it to:
IScmQueryService commondata = this.getService(IScmQueryService.class);
Thanks.
I have changed it to:
IScmQueryService commondata = this.getService(IScmQueryService.class);
ItemQueryResult streams = commondata.findWorkspaces(criteria, Integer.MAX_VALUE , (IRepositoryProgressMonitor) monitor);
How to retrieve
IRepositoryProgressMonitor
? Currently, I have cast the
IProgressMonitor "monitor" to the type "
IRepositoryProgressMonitor
".
Thanks.
Hi Muthukumar,
I have made some modifications and able to retrieve the streams now. Now, i am trying to add the values to the enumeration using :
IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(attribute1, monitor);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
My question here is : Even if i configure this enumeration as a dependent of another attribute in the process template, my code will run everytime the WI is saved. So, how to make sure that only 1 set is generated so that it will be used for later similar combinations? without adding on values over and over?
Thanks.
I have made some modifications and able to retrieve the streams now. Now, i am trying to add the values to the enumeration using :
IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>)workItemCommon.resolveEnumeration(attribute1, monitor);
List<ILiteral> enumerationLiterals = enumeration.getEnumerationLiterals();
My question here is : Even if i configure this enumeration as a dependent of another attribute in the process template, my code will run everytime the WI is saved. So, how to make sure that only 1 set is generated so that it will be used for later similar combinations? without adding on values over and over?
Thanks.