It's all about the answers!

Ask a question

Using a custom policy to set/override an asset version


Allen Earnest (6212437) | asked Jul 29 '13, 5:33 p.m.
 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!

Accepted answer


permanent link
Rich Kulp (3.6k38) | answered Jul 30 '13, 10:47 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
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

Comments
Allen Earnest commented Jul 30 '13, 11:03 a.m.

worked great... thanks rich! 

One other answer



permanent link
Lara Ziosi (33811112) | answered Jul 30 '13, 3:50 a.m.
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


Comments
Allen Earnest commented Jul 30 '13, 9:05 a.m. | edited Jul 30 '13, 9:09 a.m.

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 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.