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

Get latest component baseline within Stream via RTC API

Hi

I am using following code to retrieve the latest baseline of a component within a stream:

          // Get baselines for component
          IComponent component = (IComponent) item;
          IHistoricBaselineIterator baselineIterator =
              workspaceConn.getBaselinesInHistory(component, 1, new NullProgressMonitor());

          List<? extends IBaselineHandle> baselines = baselineIterator.getBaselines();
          for (IBaselineHandle iBaselineHandle : baselines) {
            IItem itemBaseline =
                this.repository.itemManager().fetchCompleteItem(
                    iBaselineHandle,
                    IItemManager.UNSHARED,
                    new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN,
                        SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));

For some streams it works (I think) but I have a few streams where the resulting baseline is the overall newest baseline and not the newest baseline (is the "Initial baseline") in the stream context. (like it is shown in the Eclipse client UI in the Team Artifacts" view).

If this code is wrong can you point me to a source with the right piece of code?

Thank you

1

0 votes


Accepted answer

Permanent link
If you only want to get the latest baseline (i.e. the basis) of a component, then it's simply:

// Fetch a handle to the last baseline (basis)
ITeamRepository repo = <repo_of_the_workspace>
IWorkspaceManager manager = SCMPlatform.getWorkspaceManager(repo);
IWorkspaceHandle workspaceHandle = <this_is_the_handle_for_the_stream>
IWorkspaceConnection wc = manager.getWorkspaceConnection(workspaceHandle , monitor);
IComponentHandle componentHandle = <this_is_the_component_you_care_about>
IBaselineHandle basisHandle = wc.getComponentInfo(componentHandle ).basis();

// Fetch the full baseline
IFetchResult fetchResult =  repo.itemManager().fetchCompleteItemsPermissionAware(Collections.singletonList(basisHandle), ItemManager.DEFAULT, monitor);
IBaseline fetchedBaseline;
if (fetchResult.getRetrievedItems().size() == 1) {
   fetchedBaseline = fetchResult.getRetrievedItems().get(0);
}
Geoffrey Clemm selected this answer as the correct answer

0 votes


2 other answers

Permanent link
Found the solution by looking at the RTC plugin code in class BaselinesInWorkspaceQuery.

Solution:

          // Get component for component handle
          IComponentHandle compHandle = (IComponentHandle) compObj;
          IItem item =
              this.repository.itemManager().fetchCompleteItem(
                  compHandle,
                  IItemManager.UNSHARED,
                  new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN,
                      SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
          if (monitor.isCanceled()) {
            return Status.OK_STATUS;
          }
          IComponent component = (IComponent) item;

          // Get current baseline of component in workspace
          ICurrentComponentInfo currCompInfo = wsConn.getComponentInfo(compHandle);
          long numBasisInHistory = currCompInfo.numBasisInHistory();
          List<IComponentInfo> componentInfos =
              wsConn.getComponentAuditTrail(compHandle, numBasisInHistory - 1, 1, new NullProgressMonitor());
          for (IComponentInfo compInfo : componentInfos) {
            ItemId<IBaseline> itemId = new ItemId<IBaseline>(compInfo.basis());
            IItemHandle baseLineHandle = itemId.toHandle();
            IItem itemBaseline =
                this.repository.itemManager().fetchCompleteItem(
                    baseLineHandle,
                    IItemManager.UNSHARED,
                    new SubProgressMonitor(monitor, IProgressMonitor.UNKNOWN,
                        SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK));
            if (monitor.isCanceled()) {
              return Status.OK_STATUS;
            }
            IBaseline baseline = (IBaseline) itemBaseline;


PS. The API is really really NOT intuitive to use.

1 vote


Permanent link
For getting all the baselines as seen from ui  right clicking on the component of a specific repository workspace or stream(Show > Baselines) and getting IBaseline from  IComponentInfo in a more concise way...: 
currentComponentInfo = workspaceConnection.getComponentInfo(componentHandle);
// the number of past basis
long numBasisInHistory = currentComponentInfo.numBasisInHistory();
log.trace(" numBasisInHistory :" + numBasisInHistory);

//BE CAREFUL: from oldest to newest... 
componentInfos = workspaceConnection.getComponentAuditTrail(
		componentHandle, 
		0, 
		numBasisInHistory , 
progressMonitor); for (IComponentInfo componentInfo : componentInfos) { IBaselineHandle baselineHandle = componentInfo.basis(); IBaseline baseline = (IBaseline) itemManager.fetchCompleteItem(baselineHandle, IItemManager.DEFAULT, progressMonitor); log.trace("Baseline UUID =>" + baseline.getItemId() + "<="); log.trace(" Baseline id =>" + baseline.getId() + "<="); log.trace(" Baseline name =>" + baseline.getName() + "<="); }

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,927
× 1,201
× 84

Question asked: Aug 07 '15, 12:27 p.m.

Question was seen: 6,542 times

Last updated: Jun 12 '16, 5:47 p.m.

Confirmation Cancel Confirm