Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Using a custom policy to set/override an asset version

 Hello All,

I'd like to write a custom policy that will set/override an asset version number.  For example, if a user submits an asset with the default version (1.0), then I would like to have the policy automatically change the asset version to something else.

Here's a code snippet of the custom policy that sets the new version number:

  • RAMAsset ramAsset = getPolicyContext().getRAMAsset();
  • AssetIdentification assetID = ramAsset.getIdentification();
  • assetID.setVersion("my.new.version.number.goes.here");
  • ramAsset.setIdentification(assetID);

However when I run this, I get a runtime exception telling me:
CRRAM0001E  846894011 ERROR web com.ibm.ram.common.data.exception.RAMRuntimeException - RAM Runtime Exception.
com.ibm.ram.common.data.exception.RAMRuntimeException: The Identifaction cannot be set by the client
	

Am I going about this the wrong way?  Or is this not possible to do?

Thanks!

0 votes


Accepted answer

Permanent link
Use

RAMAsset newAssetVersion = getPolicyContext().getRAMSession().replaceAssetNewVersion(getPolicyContext().getRAMAsset(), newVersion);

followed by:

getPolicyContext().getRAMSession().put(newAssetVersion, new RAMStatusMonitor());
Allen Earnest selected this answer as the correct answer

1 vote

Comments

worked great... thanks rich! 


One other answer

Permanent link
Hello,

I have not tested this, but what happens if you omit the line:
ramAsset.setIdentification(assetID);
The error message states that the client cannot set the Identification. You already got the Identification, and you modified the version. That might be sufficient.

Thank you, Lara

0 votes

Comments

HI Lara


I had already tried what you suggested as my initial attempt at this.  What happens is nothing, unfortunately.  The version does not change and no exception is thrown.

The documentation tells me that the getIdentification method gives you a copy of the object, so any changes to it are not applied to the actual asset.

So that's when I added that line to apply the identification change to the ramAsset object and got the exception.

Thanks for your reply :)

Allen

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Jul 29 '13, 5:33 p.m.

Question was seen: 4,916 times

Last updated: Jul 30 '13, 11:03 a.m.

Confirmation Cancel Confirm