It's all about the answers!

Ask a question

Replace components with active change-sets


SEC Servizi (94622244) | asked Mar 28 '13, 4:43 a.m.
edited Aug 02 '16, 9:10 a.m. by David Lafreniere (4.4k7)
 We are trying to programmatically create a new repository workspace even with components having active change-sets.
We use a stream as base seed workspace and a repository workspace to obtain the updated components (with active change-sets).
Our first code was:
IWorkspace newWks = scmService.createWorkspace(user, newWksName, newWksDescription, stream, null, stream, null, null, null).getWorkspace();
IComponentHandle[] components = scmService.getComponentsForWorkspace(stream, null);
final int n = components.length;
IComponentOpDescriptor[] ops = new IComponentOpDescriptor[n];
for (int i=0; i<n; i++) {
ops[i] = IComponentOpDescriptor.FACTORY.replaceComponent(components[i], wks, false);
}
scmService.updateComponents(newWks, null, ops, true, IScmService.DELTA_PER_INVOCATION, null, null);
but it throws an exception:
com.ibm.team.repository.common.TeamRepositoryException: Source change history era must not have active change sets
So, instead of replace components, we change our code to use drop & add components:
IComponentOpDescriptor[] dropOps = new IComponentOpDescriptor[n];
IComponentOpDescriptor[] addOps = new IComponentOpDescriptor[n];
for (int i=0; i<n; i++) {
dropOps[i] = IComponentOpDescriptor.FACTORY.dropComponent(components[i], false);
addOps[i] = IComponentOpDescriptor.FACTORY.addComponent(components[i], wks, false);
}
scmService.updateComponents(newWks, null, dropOps, true, IScmService.DELTA_PER_INVOCATION, null, null); scmService.updateComponents(newWks, null, addOps, true, IScmService.DELTA_PER_INVOCATION, null, null);
It seems odd, but now it works... :)
We cannot use only one array of ops because an exeception is throwned:
com.ibm.team.repository.common.TeamRepositoryException: Cannot have 2 operations on 1 component
In the new repository workspace, the active change-sets appear to belong to ADMIN instead of the original owner... Any advice?
Thanks in advance.

Comments
Sonia Dimitrov commented Apr 02 '13, 10:06 a.m.
JAZZ DEVELOPER

Could you provide more information around this use case?  Why are components being replaced from the workspace once created?  Why are the change sets active?

Accepted answer


permanent link
Tim Mok (6.6k38) | answered Apr 02 '13, 12:00 p.m.
JAZZ DEVELOPER
Those change sets are cloned because they cannot reference the same change sets from the seed workspace (active change sets can only exist in one workspace). The logged-in user will be the owner of the change sets.
David Lafreniere selected this answer as the correct answer

Your answer


Register or to post your answer.