It's all about the answers!

Ask a question

Retrieve list of streams in a project area programatically


VK L (8177155159) | asked Jul 25 '12, 12:50 a.m.
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.

8 answers



permanent link
Michele Pegoraro (1.8k14118103) | answered Jul 25 '12, 5:32 a.m.
 Hi,
you have to use IScmQueryService with a IWorkspaceSearchCriteria:

List<IWorkspaceHandle> streams = scmQueryService.findWorkspaces(wsSearchCriteria,  Integer.MAX_VALUE , monitor).getItemHandles();

Best regards,
Michele.

permanent link
VK L (8177155159) | answered Aug 03 '12, 7:55 a.m.
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.           
                   
                             

permanent link
VK L (8177155159) | answered Aug 06 '12, 2:26 a.m.
Hi All,
            Anyone has tried this out?

Thanks.

permanent link
Muthukumar C (32712833) | answered Aug 06 '12, 4:22 a.m.
Hi ,

See the post https://jazz.net/forum/questions/72283/use-of-iscmqueryservicefindworkspaces-on-rtc-server

permanent link
VK L (8177155159) | answered Aug 06 '12, 4:56 a.m.
Hi Muthukumar,
                             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.

permanent link
Muthukumar C (32712833) | answered Aug 06 '12, 5:02 a.m.
Seems to be a User Defined variable. 
Use the getService method to get the access to that.

public static IWorkspace findStream( String streamName )throws TeamRepositoryException
{
// Get the I
ScmQueryService here and use the variable
}


permanent link
VK L (8177155159) | answered Aug 07 '12, 6:14 a.m.
Hi Muthukumar,
                            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.

Comments
Muthukumar C commented Aug 07 '12, 6:26 a.m.

I Hope "null" will be enough for monitor parameters.

findWorkspaces(criteria, Integer.MAX_VALUE ,null).getItemHandles;


permanent link
VK L (8177155159) | answered Aug 09 '12, 7:02 a.m.
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.

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.