How do I copy a work item to another project area using the client java api
Hello,
I am working on a database migration script. I have successfully created a work item type to hold the migrated data in one project area (for reference only), but need to copy all these work items to another area in the new form (without old database details) and then link back. I have been using some of Ralph Schoon's very useful articles as a starting point. I was hoping for a IWorkItemClient saveas(IProjectArea NewProj) method. All I essentially want is a method that is the equivalent of the "move/copy to project area" function in the eclipse client. Any pointers?
I might be being a bit thick , but I was hoping to create a new workItem of the required type then load the entire contents of another workitem over the top of it, but how to do this?
Thanks for any help
Richard
2 answers
why do you want to reinvent the wheel here? There is such a function available already in RTC.
If you want to reinvent the wheel, you would have to read every attribute in the source work item, then you have to find the matching data in the target attribute and set it. This is easy for simple attributes like strings, but for iterations, enumerations etc, you need a mapping by name or ID or literal mapping. Same for Team Area/List and other complex attributes.
Across repositories you will have to match all data (except trivial such as strings, ints, durations). That is, why it is not trivial to implement things like project move.
As an alternative have a look at the com.ibm.team.workitem.rcp.ui.internal.wizards.CopyToProjectAreaWizard class. You can get this by opening the wizard in Eclipse and SHIFT+ALT+F1 it with the Plugin Spy.
Assuming you set up the SDK as described by me, you should now be able to see the source code of that wizard and look into the method performFinish() to figure out how the code does the move.
Comments
Had a look at the copytoprojectarea code (excerpt below) and imagine that this could work (I can easily get some Workitemhandles to throw at it) I need to set the following properties from my java project then run the public copytoprojectarea method. Not sure how I can change the members to public and recompile - probably can't ;-) , (not as easy as extracting the java file changing the private to public then putting it back in is it?) or pump/ simulate the dialog box settings into the java class some how. Need to know how to cheat here!! Not an accomplished java user as yet.
private static final String DIALOG_SETTINGS_KEY = "copyToProjectArea";
private static final String TARGET_AREA_KEY = "targetArea";
private static final String MOVE_KEY = "move";
private static final String RESOLVE_SOURCE_KEY = "resolveSource";
private IDialogSettings fDialogSettings;
private List<IWorkItemHandle> fWorkItems;
private ITeamRepository fTeamRepository;
private IProjectAreaHandle fTargetArea;
private boolean fMove;
private boolean fResolveSource;
private boolean fMoveAttachments;
private boolean fCopyAllowed;
public CopyToProjectAreaWizard(List<IWorkItemHandle> workItems) {
//compiled code
throw new RuntimeException("Compiled Code");
}