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