I want to programmatically create Jazz Source Control User properties using Java API
Hello,
I am migrating file revisions into RTC from a differrent change control system. There needs to be a file revision property on each repository file such that we can check it against the files changed for the work items I will also be migrating. I can programmatically extract the necessary property from the metadata in the previous tool, but can see no obvious way of adding this data as a Jazz Source Control User Property automatically. Please help...
Cheers,
Richard
3 answers
https://www-01.ibm.com/support/knowledgecenter/SSCP65_4.0.6/com.ibm.team.scm.doc/topics/set_property.html?cp=SSCP65_4.0.6&lang=en
Comments
Hi Geoff,
Thank you for the tip. This would be fine for changing one file, but I will be changing thousands. I was imagining I would have to use the Java API. I want to achieve the following
1) I will have created a Stream and a component manuallly int RTC to start
2) I will have a directory of files replete with the other tools metadata to import
3) I will have a form to take the repository uri, stream name, component name and directory to export
4) On pressing Go on the form I will add all the files in the directory to RTC and add one or more properties pertaining to the previous change control tool at the same time.
Can I do all this by piping commands to scm?
I am already having to write a java application for migrating work items, some of the code can be reused for this utlity, there looks like there is an scm package in the Java API, can I deliver the files, replete with my properties using this - if so can you point me at an example? It is possible to work from the java docs, but a lot more efficient to massage an example into a new tool.
Cheers,
Richard
If possible, use the SCM commandline as suggested by Geoff. If not, please see https://rsjazz.wordpress.com/2013/10/15/extracting-an-archive-into-jazz-scm-using-the-plain-java-client-libraries/ for hints on the Java SCM API.
This code should allow you to set user properties.
IFileItem fileWorkingCopy = (IFileItem) aFile.getWorkingCopy(); fileWorkingCopy.setContent(storedzipContent); fileWorkingCopy.setUserProperty("MyProperty", "MyValue"); fWorkspace.commit(fChangeSet, Collections .singletonList(fWorkspace.configurationOpFactory() .save(fileWorkingCopy)), fMonitor);
Comments
Thanks Ralph, thats exactly the kind of example I am after. I will take that and the code in your referenced blog and have a play. However, as you imply I think things might be more resilient/simpler if my application creates a batch file of scm commands, rather than do this with the java api, not absolutely sure the following will work, but looks promising. Anything wrong with the technique/ am I missing something. I'll try the scm thing first and go back to java api if I find it impossible.
::login once rather than no need to add credentials all the time nice to save these credentials to a file
lscm login -r https://localhost:9443/jazz -n local -u ADMIN -P ADMIN
lscm create workspace -r local -s Stream1 Workspace1
::make sure you are in top level of dimensions working area for all subsequent actions
cd TopLevelDirOtherToolsWorkingDirectory
::load just my component into the workspace
::Not sure how to load a particular component, but probably best not to load all of them here
::need to assume we will have created a hierarchy of componenets and are just delivering to one
::If the user wants these as eclipse projcts then we probably need to do some of this manually
::although importing a directory of files as an eclipse project sounds possible to automate
::better than using ropey explorer plugin in most cases
lscm load -r local --all Workspace1
lscm checkin .
::produce command in batch file for every file in the sandbox to add properties
::can only do this after adding sandbox files to repository workspace because the file properties are really rows in a database table I imagine??
lscm set property DimensionsItemSpec 12345 c:\FileInMySandbox.txt
::need to get these numbers before hand or use env vars in script??
lscm changeset comment 4827 "Migrating baseline?? from dimensions project: take this line from form"
lscm changeset complete 4827
::Have work item include the migration details as these may be substantially differrent depending on customer
::create template and add details such as sql statements ran, requests added and owners relate this work item to
::all imported work items imported in other script - either join or have element to specify import work item
lscm changeset associate 4827 101
::deliver change set to repository
lscm deliver
API automation is more expensive than using available tools like SM command line. And it is more complex to use. It depends on the situation and if you already run a Java program to export the data.
You could also likely use an input file that you can read and then dispatch SCM command line.
Hi Ralph,
I used your very helpful article on importing work items and attachments to create a method to import work items into RTC in very short order. I couldn't just use the Eclipse Import csv function because the tool we are migrating from uses the rtf format so I needed to attach some fields as files. So its not as if I am unfamiliar with battling with java, what put me off using your uploading archive code is the use of encoding and encryption and need to use bytestreams. I am not sure why this was necessary. I want all files to be uploaded just as they are on the filesystem I don't want to inadvertantly change them on import. Is there not an alternative command to commit a file as is? I imagine scm must work out what to do by looking at the file?
Richard, basically encoding is necessary. The RTC Eclipse client will use the specified encoding, the SCM commandline as well. I think the encoding is needed to be able to compare/merge the files. In the SCM commandline, I am not sure where the default encoding comes from. there is a .magic file. Maybe that.
The API simply requires the encoding information,otherwise it will not allow to check in and deliver.
Richard, I've cleaned up your posts. Please reply to answers instead of creating a new one so that others may follow the conversation thread. This will help others that are trying to find an answer.
Fair enough - I just typed in the big open box, not used this forum before ;-)
For the java api answer. I don't quite understand how to scroll through each and every file in the workspace to add the metadata. Can someone please explain how to do this? Reason for this is that the SCM method is just incredibly slow even after substantial effort to speed it up it still takes a couple of hours to apply the metadata for 7000 files.
Still having an issue getting hold of all the files in a sandbox so I can write loads of file propeties using the java API, Need to cast my files to something that resembles an IFileItem so I can add metadata to each - a pointer would be appreciated! Looked at the snippets and a couple of blog articles, missing an obvious trick I expect.
Cheers
Richard