It's all about the answers!

Ask a question

How to create stream from a snapshot using plain Java API


Kaushambi Singh (371310379) | asked Apr 10 '13, 9:48 a.m.
edited Apr 10 '13, 1:25 p.m.
How to create a new stream from  a snapshot using plain java API ? Snapshot name and new stream name should be given as an input criteria. Please help.

2 answers



permanent link
Tim Mok (6.6k38) | answered Apr 10 '13, 3:24 p.m.
JAZZ DEVELOPER
Have you looked at the snippets included with the plain Java client libraries? Snippet 2 shows how to create a stream. You would do the same and add the component baselines from the snapshot. I'm not sure what you mean by the snapshot and stream names being input criteria.

Comments
Kaushambi Singh commented Apr 11 '13, 3:06 a.m.

Thanks for your reply. Yes, I saw the snippet but it doesn't create stream from snapshot, as well as I an new to the API interfaces. By input criteria I meant : I already have a snapshot created on a different stream B (using RTC Eclipse GUI feature) so I want that I should be prompted to ask the snapshot name ( which is already present on stream B) and the new stream name (which would be created from that snapshot) and then the new stream should get created with the provided snapshot name. If you could help me with this part, that would be great. thanks!



Kaushambi Singh commented Apr 11 '13, 9:01 a.m.

Also Tim, the snippet creates Project area and stream every time I run it because its calling Snippet 3 every time. I want to have the stream created in an existing project area. Is there a way where I can provide my existing project area as parameter.


Tim Mok commented Apr 11 '13, 9:47 a.m.
JAZZ DEVELOPER

From the snippet:

IWorkspaceConnection stream = wm.createStream(teamArea, "Example Stream", "Description", monitor);

Replace the team area with your existing project area and ignore the part of the snippet that creates a project area.

For finding your snapshot:
IBaselineSetSearchCriteria criteria = IBaselineSetSearchCriteria.FACTORY.newInstance();
criteria.setExactName(name);
criteria.setOwnerWorkspaceOptional(streamHandle);
wm.findBaselineSets(criteria, expectedMaxResults, monitor);
A snapshot is referred to as a baseline set. It's better to have the snapshot id but if it requires user input then this is fine. You'll have to show the user the search results if there are more than one snapshot with the same name owned by the same stream.


Kaushambi Singh commented Apr 11 '13, 3:39 p.m.

Thanks Tim. Probably in passing the project area worked. I used this and it worked:
       URI uri = URI.create(projectAreaName.replaceAll(" ", "%20"));


Kaushambi Singh commented Apr 12 '13, 8:17 a.m.

Thanks Tim, I could find the snapshot using the above snippet.


Kaushambi Singh commented Apr 15 '13, 9:31 a.m. | edited Apr 15 '13, 3:31 p.m.

Hi Tim,

I could successfully fetch the component baselines but these baselines are not getting applied on the new stream I created. My new stream is still blank with no components. Could you help me to figure out where am I mistaken and how to correct that: Below is the part of my code. Stream1 is my new stream.
// Get snapshot stream connection
                Iterator it = tmp_list.iterator();
                IWorkspaceHandle snapshot_hd = (IWorkspaceHandle)it.next();
                IWorkspaceConnection wc = wm.getWorkspaceConnection(snapshot_hd, monitor);
           
      //Get Snapshot
                IBaselineSetSearchCriteria criteria = IBaselineSetSearchCriteria.FACTORY.newInstance();
                criteria.setOwnerWorkspaceOptional(snapshot_hd);
                criteria.setExactName(snap_name);
                tmp_list = wm.findBaselineSets(criteria,Integer.MAX_VALUE, monitor);

//Get Baselines
                it = tmp_list.iterator();
                IBaselineSetHandle baselineSetHandle = (IBaselineSetHandle) it.next();
                   IBaselineSet snap1 = (IBaselineSet)repo.itemManager().fetchCompleteItem(baselineSetHandle,ItemManager.DEFAULT,monitor);

 //Get snapshot baselines
            List<IBaselineHandle> baselineHandles = snap1.getBaselines();
            List<IBaseline> baselines = repo.itemManager().fetchCompleteItems(baselineHandles,ItemManager.DEFAULT,monitor);
            System.out.println (baselines);
            
               List<IComponentOp> ops = new ArrayList<IComponentOp>(10);
                for (IBaseline baseline : baselines) {
                IBaselineConnection baselineConnection = wm.getBaselineConnection(baseline, monitor);
                IComponentHandle component = baseline.getComponent();
                list =baseline.getId()+ "\t"+ baseline.getName() + "\n";
                System.out.println (list);
                ops.add(stream1.componentOpFactory().addComponent(component,baselineConnection, true));
                IUpdateReport report = stream1.applyComponentOperations(ops,monitor);
            }
 


Tim Mok commented Apr 15 '13, 3:37 p.m.
JAZZ DEVELOPER

It looks fine to me other than you should create all the add component operations in the loop then make one call to apply the component operations outside of the loop.

How did you verify that the stream doesn't have the components? Did you check the IUpdateReport?

showing 5 of 7 show 2 more comments

permanent link
Ralph Schoon (63.5k33646) | answered Apr 11 '13, 3:35 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Please have a look at https://jazz.net/forum/questions/34819/create-a-stream-from-the-snap-shot-of-another-stream it might provide the answer.

Comments
Kaushambi Singh commented Apr 11 '13, 8:56 a.m.

Thanks Ralph. I did have a look at this question. It talks about fetching baselines from the given snapshot and replace operation for each baseline but then it doesn't talk about how are we creating stream after that.


Tim Mok commented Apr 11 '13, 9:48 a.m.
JAZZ DEVELOPER

That is exactly what you need to do to create a stream from a snapshot.


Kaushambi Singh commented Apr 11 '13, 3:43 p.m.

ok, coming on this part, what exactly should be the syntax when we are saying this:

IBaselineSet snapshot = ... // snapshot you're starting with

Is it the snapshot name(the string value) or what exactly it needs to be ?
Also, I donot understand why we are doing create and replace operation for baselines. Why is it required ? Are we doing this to get the latest baseline from the components. Can this part be skipped if we are sure of the baselines ? please reply.


Tim Mok commented Apr 11 '13, 4:29 p.m.
JAZZ DEVELOPER

The snapshot in that snippet is of type IBaselineSet. It is not defined as a String.

There is no operation that will create a stream and add all the component baselines from the snapshot. You have to break it down to creating the stream, getting the baselines from the snapshot, and adding the component baselines to the stream.


Kaushambi Singh commented Apr 12 '13, 3:22 a.m.

Thanks Tim, for your reply. All I need is an example format of this line:
IBaselineSet
snapshot = ... // snapshot you're starting with


Tim Mok commented Apr 12 '13, 10:22 a.m.
JAZZ DEVELOPER

Look at the snippet I posted as a comment for my answer to get your snapshot.

showing 5 of 6 show 1 more comments

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.