It's all about the answers!

Ask a question

How to add a deleted item [SCM]


Tim Schumann (1464) | asked Jan 28 '08, 5:58 p.m.
Hi,

I'm experimenting a bit with the Jazz SCM component and I wonder, if there's
a way to add an item to workspace that has been deleted before.
If reverting the change that deleted this element is the only way to do
that, how would I implement this?


Many thanks,

--Tim

Here's a snippet that shows my example (sorry, it's rather lengthy):
In this example MMClass is a versionable item (inherits from Versionable).

// Create a new workspace.
IWorkspaceHandle workspaceHandleA =
scmService.createWorkspaceWithoutFlows(...);
IWorkspace workspaceA = (IWorkspace) itemService.fetchItem(...);
// Create a component
IComponent component = scmService.createComponent(...);
scmService.addComponent(workspaceHandleA, component,
IScmService.DELTA_PER_INVOCATION, null, null);
IChangeSetHandle changeSet = (IChangeSetHandle)
scmService.createChangeSet( workspaceA, component, ...).getItem();

// create root folder ("/")
List<IVersionable> newItems = new ArrayList<IVersionable>();
IFolder rootFolder = (IFolder) scmService.workspaceRootFolder(
workspaceHandleA, component, null, null, null).getWorkingCopy();
rootFolder.setName("");
newItems.add(rootFolder);

// Just create a new element.
MMClass myElement = (MMClass) getMMClassItemType().createItem();
((IVersionable) myElement).setName("ME_X");
myElement.setMMname("MyClass");
myElement.setParent(rootFolder);
newItems.add(myElement);

// Add new items to the change set and persist elements.
commitSave(workspaceA, changeSet, newItems, new ArrayList<IVersionable>());
getService(IScmService.class).closeChangeSets(
workspaceA, new IChangeSetHandle[] {changeSet}, true, null, null, null);

// Create new workspace initialized with this one just created.
IWorkspaceHandle workspaceHandleB =
scmService.createWorkspaceWithoutFlows(...);
scmService.addComponentFromWorkspace(workspaceHandleB, component,
workspaceHandleA, scmService.DELTA_PER_INVOCATION, null, null);

// We have just one component -- so get the first one!
IComponentHandle componentInB =
scmService.getWorkspaceComponentStateSummaries(workspaceHandleB,
null).getComponent();

// Call a helper method to fetch the element created above (i.e. our model
element).
MMClass myElementInWSB = (MMClass)
fetchVersionableByName("ME_X", MMClass.class, workspaceHandleB,
componentInB);
// Delete the element.
IChangeSetHandle changeSetWSB1 = (IChangeSetHandle)
scmService.createChangeSet(workspaceHandleB, componentInB,
....).getItem();

List<IVersionable> itemsToDelete = new ArrayList<IVersionable>();
itemsToDelete.add(myElementInWSB);
commitSave(workspaceHandleB, changeSetWSB1, new ArrayList<IVersionable>(),
itemsToDelete);
scmService.closeChangeSets(
workspaceHandleB, new IChangeSetHandle[] {changeSetWSB1}, ...);

// Add the element.
IChangeSetHandle changeSetWSB2 = (IChangeSetHandle)
scmService.createChangeSet(...).getItem();
List<IVersionable> itemsToAdd = new ArrayList<IVersionable>();
itemsToAdd.add(myElementInWSB);

// !!!!!!!!!!!!!!!!!
// This call fails -- probably because the element does not exist in this
workspace anymore.
// !!!!!!!!!!!!!!!!!
commitSave(workspaceHandleB, changeSetWSB2, itemsToAdd, new
ArrayList<IVersionable>());


//////////////////////////////
// helper methods
//////////////////////////////

protected void commitSave(IWorkspaceHandle workspace, IChangeSetHandle cs,
List<IVersionable> addedOrModifiedItems, List<IVersionable>
itemsToDelete)
throws TeamRepositoryException {
CommitParameter parm = ScmDtoFactory.eINSTANCE.createCommitParameter();
parm.setChangeSet(cs);
parm.addItemsToSave(addedOrModifiedItems);
parm.addItemsToDelete(itemsToDelete);
getService(IScmService.class).batchCommit(workspace, new
CommitParameter[] {parm},
IScmService.DELTA_PER_INVOCATION, null, null
);
}

8 answers



permanent link
Dmitry Karasik (1.8k11) | answered Jan 29 '08, 4:27 a.m.
JAZZ DEVELOPER
On Mon, 28 Jan 2008 23:57:50 +0100, Tim Schumann wrote:

Hi,

I'm experimenting a bit with the Jazz SCM component and I wonder, if
there's a way to add an item to workspace that has been deleted before.
If reverting the change that deleted this element is the only way to do
that, how would I implement this?


Can you post the stack trace you are getting? The code snippet you posted
looks correct except maybe you need to call getWorkingCopy() on your Item
before saving it a second time.

- Dmitry

permanent link
John Camelon (1.7k14) | answered Jan 29 '08, 8:28 a.m.
JAZZ DEVELOPER
If the change-set that deleted the item is active, you can undo the
change via commit.


Otherwise, you can commit a new change which selects the desired state
to restore it to the configuration.

@see CommitParameter#getItemsToUndo() and
CommitParameter#getItemsToRevert().

I hope to clean this interface up a bit so it is easier to use.

HTH,
JohnC

Tim Schumann wrote:
Hi,

I'm experimenting a bit with the Jazz SCM component and I wonder, if there's
a way to add an item to workspace that has been deleted before.
If reverting the change that deleted this element is the only way to do
that, how would I implement this?


Many thanks,

--Tim

Here's a snippet that shows my example (sorry, it's rather lengthy):
In this example MMClass is a versionable item (inherits from Versionable).

// Create a new workspace.
IWorkspaceHandle workspaceHandleA =
scmService.createWorkspaceWithoutFlows(...);
IWorkspace workspaceA = (IWorkspace) itemService.fetchItem(...);
// Create a component
IComponent component = scmService.createComponent(...);
scmService.addComponent(workspaceHandleA, component,
IScmService.DELTA_PER_INVOCATION, null, null);
IChangeSetHandle changeSet = (IChangeSetHandle)
scmService.createChangeSet( workspaceA, component, ...).getItem();

// create root folder ("/")
List<IVersionable> newItems = new ArrayList<IVersionable>();
IFolder rootFolder = (IFolder) scmService.workspaceRootFolder(
workspaceHandleA, component, null, null, null).getWorkingCopy();
rootFolder.setName("");
newItems.add(rootFolder);

// Just create a new element.
MMClass myElement = (MMClass) getMMClassItemType().createItem();
((IVersionable) myElement).setName("ME_X");
myElement.setMMname("MyClass");
myElement.setParent(rootFolder);
newItems.add(myElement);

// Add new items to the change set and persist elements.
commitSave(workspaceA, changeSet, newItems, new ArrayList<IVersionable>());
getService(IScmService.class).closeChangeSets(
workspaceA, new IChangeSetHandle[] {changeSet}, true, null, null, null);

// Create new workspace initialized with this one just created.
IWorkspaceHandle workspaceHandleB =
scmService.createWorkspaceWithoutFlows(...);
scmService.addComponentFromWorkspace(workspaceHandleB, component,
workspaceHandleA, scmService.DELTA_PER_INVOCATION, null, null);

// We have just one component -- so get the first one!
IComponentHandle componentInB =
scmService.getWorkspaceComponentStateSummaries(workspaceHandleB,
null).getComponent();

// Call a helper method to fetch the element created above (i.e. our model
element).
MMClass myElementInWSB = (MMClass)
fetchVersionableByName("ME_X", MMClass.class, workspaceHandleB,
componentInB);
// Delete the element.
IChangeSetHandle changeSetWSB1 = (IChangeSetHandle)
scmService.createChangeSet(workspaceHandleB, componentInB,
...).getItem();

List<IVersionable> itemsToDelete = new ArrayList<IVersionable>();
itemsToDelete.add(myElementInWSB);
commitSave(workspaceHandleB, changeSetWSB1, new ArrayList<IVersionable>(),
itemsToDelete);
scmService.closeChangeSets(
workspaceHandleB, new IChangeSetHandle[] {changeSetWSB1}, ...);

// Add the element.
IChangeSetHandle changeSetWSB2 = (IChangeSetHandle)
scmService.createChangeSet(...).getItem();
List<IVersionable> itemsToAdd = new ArrayList<IVersionable>();
itemsToAdd.add(myElementInWSB);

// !!!!!!!!!!!!!!!!!
// This call fails -- probably because the element does not exist in this
workspace anymore.
// !!!!!!!!!!!!!!!!!
commitSave(workspaceHandleB, changeSetWSB2, itemsToAdd, new
ArrayList<IVersionable>());


//////////////////////////////
// helper methods
//////////////////////////////

protected void commitSave(IWorkspaceHandle workspace, IChangeSetHandle cs,
List<IVersionable> addedOrModifiedItems, List<IVersionable
itemsToDelete)
throws TeamRepositoryException {
CommitParameter parm = ScmDtoFactory.eINSTANCE.createCommitParameter();
parm.setChangeSet(cs);
parm.addItemsToSave(addedOrModifiedItems);
parm.addItemsToDelete(itemsToDelete);
getService(IScmService.class).batchCommit(workspace, new
CommitParameter[] {parm},
IScmService.DELTA_PER_INVOCATION, null, null
);
}


permanent link
John Camelon (1.7k14) | answered Jan 29 '08, 8:38 a.m.
JAZZ DEVELOPER
BTW, extending Versionable may require some adoption code if you plan to
move to our M5D1 deployment. (You may indeed be the first person to do
it outside of the Jazz project itself!)

see the com.ibm.team.scm.tests.service plugin and how it contributes a
repository internal component metadata provider factory in order to
allow for persistance of additional tables in the repo.

JohnC
SCM Server team

Tim Schumann wrote:
Hi,

I'm experimenting a bit with the Jazz SCM component and I wonder, if there's
a way to add an item to workspace that has been deleted before.
If reverting the change that deleted this element is the only way to do
that, how would I implement this?


Many thanks,

--Tim

Here's a snippet that shows my example (sorry, it's rather lengthy):
In this example MMClass is a versionable item (inherits from Versionable).

// Create a new workspace.
IWorkspaceHandle workspaceHandleA =
scmService.createWorkspaceWithoutFlows(...);
IWorkspace workspaceA = (IWorkspace) itemService.fetchItem(...);
// Create a component
IComponent component = scmService.createComponent(...);
scmService.addComponent(workspaceHandleA, component,
IScmService.DELTA_PER_INVOCATION, null, null);
IChangeSetHandle changeSet = (IChangeSetHandle)
scmService.createChangeSet( workspaceA, component, ...).getItem();

// create root folder ("/")
List<IVersionable> newItems = new ArrayList<IVersionable>();
IFolder rootFolder = (IFolder) scmService.workspaceRootFolder(
workspaceHandleA, component, null, null, null).getWorkingCopy();
rootFolder.setName("");
newItems.add(rootFolder);

// Just create a new element.
MMClass myElement = (MMClass) getMMClassItemType().createItem();
((IVersionable) myElement).setName("ME_X");
myElement.setMMname("MyClass");
myElement.setParent(rootFolder);
newItems.add(myElement);

// Add new items to the change set and persist elements.
commitSave(workspaceA, changeSet, newItems, new ArrayList<IVersionable>());
getService(IScmService.class).closeChangeSets(
workspaceA, new IChangeSetHandle[] {changeSet}, true, null, null, null);

// Create new workspace initialized with this one just created.
IWorkspaceHandle workspaceHandleB =
scmService.createWorkspaceWithoutFlows(...);
scmService.addComponentFromWorkspace(workspaceHandleB, component,
workspaceHandleA, scmService.DELTA_PER_INVOCATION, null, null);

// We have just one component -- so get the first one!
IComponentHandle componentInB =
scmService.getWorkspaceComponentStateSummaries(workspaceHandleB,
null).getComponent();

// Call a helper method to fetch the element created above (i.e. our model
element).
MMClass myElementInWSB = (MMClass)
fetchVersionableByName("ME_X", MMClass.class, workspaceHandleB,
componentInB);
// Delete the element.
IChangeSetHandle changeSetWSB1 = (IChangeSetHandle)
scmService.createChangeSet(workspaceHandleB, componentInB,
...).getItem();

List<IVersionable> itemsToDelete = new ArrayList<IVersionable>();
itemsToDelete.add(myElementInWSB);
commitSave(workspaceHandleB, changeSetWSB1, new ArrayList<IVersionable>(),
itemsToDelete);
scmService.closeChangeSets(
workspaceHandleB, new IChangeSetHandle[] {changeSetWSB1}, ...);

// Add the element.
IChangeSetHandle changeSetWSB2 = (IChangeSetHandle)
scmService.createChangeSet(...).getItem();
List<IVersionable> itemsToAdd = new ArrayList<IVersionable>();
itemsToAdd.add(myElementInWSB);

// !!!!!!!!!!!!!!!!!
// This call fails -- probably because the element does not exist in this
workspace anymore.
// !!!!!!!!!!!!!!!!!
commitSave(workspaceHandleB, changeSetWSB2, itemsToAdd, new
ArrayList<IVersionable>());


//////////////////////////////
// helper methods
//////////////////////////////

protected void commitSave(IWorkspaceHandle workspace, IChangeSetHandle cs,
List<IVersionable> addedOrModifiedItems, List<IVersionable
itemsToDelete)
throws TeamRepositoryException {
CommitParameter parm = ScmDtoFactory.eINSTANCE.createCommitParameter();
parm.setChangeSet(cs);
parm.addItemsToSave(addedOrModifiedItems);
parm.addItemsToDelete(itemsToDelete);
getService(IScmService.class).batchCommit(workspace, new
CommitParameter[] {parm},
IScmService.DELTA_PER_INVOCATION, null, null
);
}


permanent link
Tim Schumann (1464) | answered Jan 29 '08, 1:38 p.m.
"Dmitry Karasik" <dkarasik@ca.ibm.com> wrote in message
news:fnn9jo$qjv$1@localhost.localdomain...
On Mon, 28 Jan 2008 23:57:50 +0100, Tim Schumann wrote:

Hi,

I'm experimenting a bit with the Jazz SCM component and I wonder, if
there's a way to add an item to workspace that has been deleted before.
If reverting the change that deleted this element is the only way to do
that, how would I implement this?


Can you post the stack trace you are getting? The code snippet you posted
looks correct except maybe you need to call getWorkingCopy() on your Item
before saving it a second time.

Hi Dmitry,

thanks for your response. You were right, I just needed to get the working
copy again and my code worked.

Thanks!

permanent link
Tim Schumann (1464) | answered Jan 29 '08, 2:08 p.m.
Hi,
"John Camelon" <jcamelon@ca.ibm.com.no.spam> wrote in message
news:fnn9p0$rqq$1@localhost.localdomain...
BTW, extending Versionable may require some adoption code if you plan to
move to our M5D1 deployment. (You may indeed be the first person to do it
outside of the Jazz project itself!)
Thanks for the remark. We're currently planning a prototype as a proof of

concept. For this purpose, sticking to Beta 2 should be fine. But for our
future work, I guess we want to stay up-to-date with Jazz (and besides this
I'm definitely interested in ongoing changes in Jazz concerning the SCM ;-))

see the com.ibm.team.scm.tests.service plugin and how it contributes a
repository internal component metadata provider factory in order to allow
for persistance of additional tables in the repo.
Thanks for the pointer -- sounds great !!.

But I was not able to locate the contributions you mentioned.
I only found the plugins com.ibm.team.scm.tests.service and
com.ibm.team.scm.tests.common that were named similar to the one you pointed
me to but didn't see something like what you mentioned.

Many thanks,

--Tim
JohnC
SCM Server team

permanent link
John Camelon (1.7k14) | answered Jan 29 '08, 3:28 p.m.
JAZZ DEVELOPER
Tim Schumann wrote:
Thanks for the pointer -- sounds great !!.
But I was not able to locate the contributions you mentioned.
I only found the plugins com.ibm.team.scm.tests.service and
com.ibm.team.scm.tests.common that were named similar to the one you pointed
me to but didn't see something like what you mentioned.

Many thanks,

--Tim

Its a new plugin available only in M5D1 onward. Beta2 does not contain
this plugin.

HTH,
JohnC
SCM Server

permanent link
Tim Schumann (1464) | answered Jan 29 '08, 4:48 p.m.
Its a new plugin available only in M5D1 onward. Beta2 does not contain
this plugin.

Its a new plugin available only in M5D1 onward. Beta2 does not contain
this plugin.

I see. Are there any major changes planned concerning the SCM?
The thing is, that I don't care too much if the finished plugins need some
minor fixups in order to run with Jazz M5, but if the some more complex
mechanisms implemented in my plugins wouldn't work anymore, this would be
kind of frustrating.


Thanks for your great support!

--Tim

permanent link
John Camelon (1.7k14) | answered Jan 30 '08, 2:58 p.m.
JAZZ DEVELOPER
We do have more changes in this release (and again in future releases,
until we freeze model and API).

I should be able to walk you through anything you will need to do in the
near/medium term. Technically what you are doing (implementing your own
Versionable) is not officially supported yet (I believe that the Team
Concert UI may have some weird behaviour when it comes to unknown
Versionables).

Cheers,
JC

Tim Schumann wrote:
Its a new plugin available only in M5D1 onward. Beta2 does not contain
this plugin.
Its a new plugin available only in M5D1 onward. Beta2 does not contain
this plugin.

I see. Are there any major changes planned concerning the SCM?
The thing is, that I don't care too much if the finished plugins need some
minor fixups in order to run with Jazz M5, but if the some more complex
mechanisms implemented in my plugins wouldn't work anymore, this would be
kind of frustrating.


Thanks for your great support!

--Tim

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.