It's all about the answers!

Ask a question

I want to programmatically create Jazz Source Control User properties using Java API


Richard Good (872158) | asked Aug 14 '14, 1:51 p.m.
edited Aug 20 '14, 4:52 p.m. by Stephanie Taylor (24115)

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



permanent link
Geoffrey Clemm (30.1k33035) | answered Aug 14 '14, 5:21 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
You can use the scm command line "set property" command.   See:
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
Richard Good commented Aug 15 '14, 4:17 a.m. | edited Aug 15 '14, 8:00 a.m.

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


permanent link
Ralph Schoon (63.1k33645) | answered Aug 15 '14, 5:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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
Richard Good commented Aug 15 '14, 6:55 a.m. | edited Aug 15 '14, 8:03 a.m.

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


Ralph Schoon commented Aug 15 '14, 7:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Richard Good commented Aug 15 '14, 7:31 a.m. | edited Aug 15 '14, 8:03 a.m.

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? 


Ralph Schoon commented Aug 15 '14, 7:44 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.


Tim Mok commented Aug 15 '14, 8:05 a.m.
JAZZ DEVELOPER

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.


Richard Good commented Aug 15 '14, 8:09 a.m.

Fair enough - I just typed in the big open box, not used this forum before ;-)


Richard Good commented Apr 22 '15, 11:34 a.m. | edited Apr 22 '15, 11:38 a.m.

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.

showing 5 of 7 show 2 more comments

permanent link
Richard Good (872158) | answered Apr 29 '15, 12:30 p.m.
edited Apr 29 '15, 12:33 p.m.

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

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.