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

How to programmatically add components to workspace

We would programmatically add existing components to new workspace:
IScmService scmService = ...
IContributorHandle contributorH = ...
IWorkspaceHandle stream = ...
IWorkspace wks = scmService.createWorkspace(contributorH, wksName, wksDescription, stream, null, stream, null, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor)).getWorkspace();
IComponentHandle componentH = ...
IWorkspaceHandle targetH = ...
scmService.addComponentFromWorkspace(wks, componentH, targetH, false, IScmService.DELTA_PER_INVOCATION, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor));
While the createWorkspace operation creates the new repository workspace, the addComponentFromWorkspace operation does not add the component... We have to call any save/refresh operation?
The code above is called by a save work-item follow up action.
Thanks in advance.

1

0 votes

Comments

During further investigation, it appears that added components are dropped by the save transaction. Any advice?



4 answers

Permanent link
I worked from Snippet 2 from the plain Java Client Libraries. I am not sure where you have your code. On a client I was able to add components this way:

// Add new components
Collection components = extComponents.values();
for (Object comp : components) {
	IComponentHandle cHandle = (IComponentHandle) comp;
	workspaceConnection.applyComponentOperations(Collections
			.singletonList(workspaceConnection.componentOpFactory()
					.addComponent(cHandle, false)), true, monitor);
}


1 vote

Comments

The snippet is the correct way to do it. Using the service is a different layer, not recommended, and is also the deprecated call.

Tim, I think the snippets should be reworked, there are several deprecated methods in usage and I actually had to dig into the deprecated call to figure out the ones not deprecated.

1 vote

We are using the IScmService service beacuse we are on a server extension, not on a client...

IScmService#updateComponents2(...) is the current call to add a component to a workspace.


Permanent link
We tried a different approach adding an existing flow target to the new workspace:
IWorkspace wks = ...
List<FlowEntry> flows = ((Workspace) wks).getFlows();
List<FlowEntry> acceptFlows = new ArrayList<FlowEntry>();
List<FlowEntry> deliverFlows = new ArrayList<FlowEntry>();
for (FlowEntry flow : flows) {
if ((flow.getFlags() & FlowFlags.ACCEPT ) != 0) {
acceptFlows.add((FlowEntry) EcoreUtil.copy((EObject) flow));
} else if ((flow.getFlags() & FlowFlags.DELIVER) != 0) {
deliverFlows.add((FlowEntry) EcoreUtil.copy((EObject) flow));
}
}
FlowEntry flow = ScmFactory.eINSTANCE.createFlowEntry();
flow.setTargetWorkspace(target);
flow.setFlags(FlowFlags.DELIVER);
deliverFlows.add(flow);
CurrentFlows currentFlows = (CurrentFlows) EcoreUtil.copy((EObject) ((Workspace) wks).getCurrentFlows());
IComponentHandle[] components = ...
CurrentFlows[] currentComponentFlows = ...
scmService.setWorkspaceFlows(wks, acceptFlows.toArray(new FlowEntry[0]), deliverFlows.toArray(new FlowEntry[0]), currentFlows, components, currentComponentFlows, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor));
We have to use EcoreUtil.copy() due to ImmutablePropertyException throwned.
We don't undertand how to set components and currentComponentFlows values... Looking at SCMHelper.addDeliverFlow(), we see empty arrays were passed, but in our case we need to add components, too... Any advice?
In fact, we would obtain this client behavior: adding a flow target to build workspace leads to add all components to workspace when a build is request.
Thanks in advance.

0 votes

Comments
Adding a deliver flow is not enough, we have to add an accept flow, too.
FlowEntry acceptFlow = ScmFactory.eINSTANCE.createFlowEntry();
acceptFlow.setTargetWorkspace(targetH);
acceptFlow.setFlags(FlowFlags.ACCEPT);
acceptFlows.add(acceptFlow);
Now all works like a sharme!


Permanent link
We tried to use IScmService#updateComponents (instead of IScmService#updateComponents2 beacuse we are still on RTC v2.0.0.2) but nothing changed:
IWorkspace wks = scmService.createWorkspace(contributorH, wksName, wksDescription, stream, null, stream, null, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor)).getWorkspace();
IComponentHandle componentH = ...
IWorkspaceHandle seedH = ...
IComponentOpDescriptor op = IComponentOpDescriptor.FACTORY.addComponent(componentH, seedH, false);
scmService.updateComponents(wksH, null, new IComponentOpDescriptor[]{ op }, false, IScmService.DELTA_PER_INVOCATION, null, IRepositoryProgressMonitor.ITEM_FACTORY.createItem(monitor));
Any advice? (To solve this problem is really important for us!)
Thanks in advance.

0 votes

Comments

I don't know what you mean by nothing changed. Can you post what you did to check if the component was added to the workspace?

We mean "nothing changed despite to use a IComponentOpDescriptor operation".
We run the code above by a save work-item post-operation, we searched for workspace created in to repository, then we opened it.

This workspace lists components added by IScmService.createWorkspace(), but components added by IComponentOpDescriptor operations were missing.


Permanent link
Ok, we found what was the problem! :D
The repository worskpace is created as well as components are added, but when that workspace is used as a build workspace (and this is our case!), components are dropped by the build request process if the flow targets table does not contain streams where components belong.
By the way, this behavior seems quite strange for us...

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,947
× 17

Question asked: Sep 09 '13, 7:19 a.m.

Question was seen: 6,725 times

Last updated: Sep 13 '13, 8:53 a.m.

Confirmation Cancel Confirm