Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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.

0 votes



8 answers

Permanent link
 Hi,
you have to use IScmQueryService with a IWorkspaceSearchCriteria:

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

Best regards,
Michele.

0 votes


Permanent link
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.           
                   
                             

0 votes


Permanent link
Hi All,
            Anyone has tried this out?

Thanks.

0 votes


Permanent link
Hi ,

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

0 votes


Permanent link
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.

0 votes


Permanent link
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
}

0 votes


Permanent link
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.

0 votes

Comments

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

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


Permanent link
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.

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,953

Question asked: Jul 25 '12, 12:50 a.m.

Question was seen: 5,839 times

Last updated: Aug 09 '12, 7:02 a.m.

Confirmation Cancel Confirm