It's all about the answers!

Ask a question

create a new stream out of a snapshot using the server side api


Steffen Kriese (381921) | asked Jul 23 '14, 8:40 a.m.
Hello
I want to create a stream based on a snapshot. IScmService has the method "createWorkspaceFromBaselineSet" to create a workspace. Is there a similar method for streams available? If not what needs to be done to create a stream?
Thanx, Steffen 

Comments
Ralph Schoon commented Aug 04 '14, 9:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

The client API to set a baseline I have used looks looks this:

    private void setActiveBaseline(IWorkspaceConnection workspace,
            IComponentHandle component, IBaselineConnection lab2Baseline,
            IProgressMonitor monitor) throws TeamRepositoryException {
        workspace.applyComponentOperations(Collections.singletonList(workspace
                .componentOpFactory().replaceComponent(component, lab2Baseline,
                        false)), monitor);
    }


Ralph Schoon commented Aug 04 '14, 9:33 a.m. | edited Aug 04 '14, 9:34 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Steffen Kriese commented Aug 05 '14, 5:02 a.m.

in the server side api the IScmService class provides a method called "replaceComponent" which seams to provide the same functionality as the client side "replaceComponent". Unfortunately the method is marked as deprecated and IScmService.updateComponents2 should be used instead. 


Steffen Kriese commented Aug 05 '14, 5:03 a.m.

I changed the code to call updateComponents2:

IBaselineHandle currentBaseline = baselineIterator.next();
IComponentOpDescriptor desc = ComponentOpDescriptor.FACTORY.addComponent(currentComponent, currentBaseline ,false);
scmService.updateComponents2(w, null, new IComponentOpDescriptor[] { desc }, true, false, IScmService.DELTA_PER_INVOCATION, null, null);

this fails wit an exception


Steffen Kriese commented Aug 05 '14, 5:13 a.m.

com.ibm.team.repository.common.TeamRepositoryException: Component 'the first one Default Component' is already in workspace
        at com.ibm.team.scm.service.internal.utils.IExceptionFactory$1.createException(IExceptionFactory.java:52)
        at com.ibm.team.scm.service.internal.utils.IExceptionFactory$1.createException(IExceptionFactory.java:57)
        at com.ibm.team.scm.service.internal.utils.WorkspaceUtils.addComponent(WorkspaceUtils.java:1341)
        at com.ibm.team.scm.service.internal.ScmServiceInternal.updateComponents2(ScmServiceInternal.java:4848)
        at com.ibm.team.scm.service.internal.ScmService$85.run(ScmService.java:3950)
        at com.ibm.team.scm.service.internal.AbstractScmService$2.run(AbstractScmService.java:431)
        at com.ibm.team.repository.service.internal.rdb.RepositoryDatabase$Transaction.run(RepositoryDatabase.java:488)
     


Ralph Schoon commented Aug 05 '14, 5:32 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

What are you actually trying to do here? What is the use case? If it is server API, in which context do you run?


Steffen Kriese commented Aug 05 '14, 6:07 a.m.

we want to create a number of "maintenance streams" based on snapshots in  development streams on a regular base. The maintenance streams differ in the number of components and also have functional dependencies to each other and to work items. So we need some checking before the streams are created and we to set a number of attributes for each stream. Of cause the creation of the "maintenance streams" could be done via the eclipse gui or from the java api. But both cases have there own drawbacks. We ended up with a rest service with some get functions to query information in RTC and a post function to create the new streams.     

showing 5 of 7 show 2 more comments

2 answers



permanent link
Steffen Kriese (381921) | answered Aug 04 '14, 8:26 a.m.
Hello,

the code below creates a new stream  and adds the component from the snapshot. unfortunately the component is empty:

// create a new stream
IScmService scmService = super.getService(IScmService.class);
WorkspaceRefreshResult i = scmService.createStream((IProcessAreaHandle) currentProjectArea.getItemHandle(), streamName, "description", null, null);
IWorkspace w = i.getWorkspace();

//get component handle
IComponent currentComponent = (IComponent) itemSvc.fetchItem(currentComponentHandle, IRepositoryItemService.COMPLETE);

//add componet to stream
IComponentOpDescriptor desc = IComponentOpDescriptor.FACTORY.addComponent(currentComponent, false);
scmService.updateComponents2(w, null, new IComponentOpDescriptor[] { desc }, true, false, IScmService.DELTA_PER_INVOCATION, null, null);

looks like I need to replace the compete with a IBaselineHandle form the snapshot. Any Idea how this can be done?


Comments
Tim Mok commented Aug 06 '14, 8:40 a.m.
JAZZ DEVELOPER

You can get the baselines from the snapshot. I assume that's how you know which components to add. FYI, I don't see any code there that shows how you get the component from the snapshot in case you're looking for validation on that part.


permanent link
Tim Mok (6.6k38) | answered Jul 23 '14, 10:42 a.m.
JAZZ DEVELOPER
You use the same call. There is no difference between a stream and a workspace except for the stream flag. It's used for checks when SCM only permits operations on streams or does not permit operations on streams. In this case, this call is allowable for a stream.

Comments
Steffen Kriese commented Jul 24 '14, 3:00 a.m. | edited Jul 24 '14, 7:52 a.m.

the createWorkspaceFromBaselineSet method returns a workspace. How do I transform this workspace into a stream? The workspace owner is a IContributorHandle while the stream is owned by a IProcessAreaHandle. How do I change the owner? How can I set the stream flag?  


Tim Mok commented Jul 24 '14, 7:59 a.m.
JAZZ DEVELOPER

You're right, it only is used for creating workspaces. You'll have to create a stream and add the components from the snapshot yourself.


FYI, you can reply to answers instead of creating a new answer. This helps others read through the discussion of the answer.

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.