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!
Accepted answer
Use
RAMAsset newAssetVersion = getPolicyContext().getRAMSession().replaceAssetNewVersion(getPolicyContext().getRAMAsset(), newVersion);
followed by:
getPolicyContext().getRAMSession().put(newAssetVersion, new RAMStatusMonitor());
RAMAsset newAssetVersion = getPolicyContext().getRAMSession().replaceAssetNewVersion(getPolicyContext().getRAMAsset(), newVersion);
followed by:
getPolicyContext().getRAMSession().put(newAssetVersion, new RAMStatusMonitor());
One other answer
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
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
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