Get Stream from ProjectArea using RTC API 4

2019-06-06 18:49发布

问题:

Hello I have been trying to get the stream name using projectArea. I have the following parameter: Repository IFileItem WorkItem and its ChangeSets

Is it possible to get it.

Thanks in advance.

Please don't give me a link to the advisor example as I already read it and I couldn't make it.

At this post,it was mentioned the following : https://jazz.net/forum/questions/49910/how-to-get-an-iconfiguration-from-ichangeset

There is a hint that is often useful (but not necessarily always correct), hidden in the ILink which serves as the binding between the IChangeSetHandle (source) and the IWorkItemHandle (target). The IItemReference for the source side has a String extraInfo field which can be retrieved via IItemReference#getExtraInfo(). This string will be of the format IWorkspace= which indicates the originating workspace. You can create a handle to the IWorkspace by using IWorkspace.ITEM_TYPE.createItemHandle(suppliedUUID, null).

public void testWorkspaceConnection(ITeamRepository repository, IWorkItem workItem) throws TeamRepositoryException, IOException{
       List<ILink> changeSetLinks = (List<ILink>)linkCollection.getLinksById("com.ibm.team.filesystem.workitems.change_set");
       List<IReference> changeSetReferences = new ArrayList<IReference>();

         for (ILink link : changeSetLinks) {
            changeSetReferences.add(link.getSourceRef());
         }

         List<IItemHandle> itemHandles = new ArrayList<IItemHandle>();

         for (IReference reference : changeSetReferences) {
             itemHandles.add((IItemHandle)reference.resolve());
         }

         if(itemHandles.isEmpty()){
             return;
         }

         IItemHandle itemHandle = itemHandles.get(itemHandles.size() - 1);
         IChangeSet changeSet = (IChangeSet)repository.itemManager().fetchCompleteItem(itemHandle, 0, monitor);
         List changes = changeSet.changes();         

         IFileItem fileItem = getLogidiagFile(changeSet, repository);
         // TILL HERE THAT WAS AN EXISTING CODE THAT WAS ALREADY THERE AND IT FETCHES THE REQUIRED FILE.
         //NEXT IS WHAT |'VE ADDED TO BE ABLE TO DETERMINE THE FULL PATH
         String uuid=changeSetReferences.get(changeSetReferences.size()-1).getExtraInfo(); //Here I need to get workspace uuid to be abble to create a connection over as the post said
         IWorkspaceHandle workspaceHandle = (IWorkspaceHandle)IWorkspace.ITEM_TYPE.createItemHandle(UUID.valueOf(uuid), null);

         IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repository);
         IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandle,monitor);

Exception I get is the following:

Exception in thread "main" java.lang.IllegalArgumentException: invalid UUID [Workspace=_iibA0GlNEeKd76sMjPDLRA] at com.ibm.team.repository.common.UUID.valueOf(UUID.java:76)

So am I walking on the right course or there are a better one you can guide me through!

回答1:

 IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repository);

IWorkspaceSearchCriteria wsSearchCriteria = WorkspaceSearchCriteria.FACTORY.newInstance();

wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);

wsSearchCriteria.setPartialOwnerNameIgnoreCase(projectAreaName);

List <IWorkspaceHandle> workspaceHandles = workspaceManager.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, Application.getMonitor()); 

IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandles.get(0),Application.getMonitor()); 


标签: java rtc jazz