Not able to delete a subscription using the RAM 7511 java api
I used the below code snippet to delete a subscription that gets added to an asset when it is created.
public static void main(String[] args) throws RAMAccessException {
RAMClient obj=RAMClient.getInstance();
RAMAsset asset=obj.getAsset("AC59BBF7-E4E9-7A43-F8D1-D054933519F4", "1.0");
RAMSubscription[] subscriptions=asset.getSubscriptions();
for(RAMSubscription subscription:subscriptions){
subscription.setAction(RAMAction.DELETE);
asset.addSubscription(subscription);
obj.session.put(asset, new RAMStatusMonitor());
System.out.println("Deleted the subscription");
}
But i noticed that i am able to fetch the subscription details even after executing the above code and in addition the subscription can also be seen on the UI.
Can you please help me with this issue?
}
public static void main(String[] args) throws RAMAccessException {
RAMClient obj=RAMClient.getInstance();
RAMAsset asset=obj.getAsset("AC59BBF7-E4E9-7A43-F8D1-D054933519F4", "1.0");
RAMSubscription[] subscriptions=asset.getSubscriptions();
for(RAMSubscription subscription:subscriptions){
subscription.setAction(RAMAction.DELETE);
asset.addSubscription(subscription);
obj.session.put(asset, new RAMStatusMonitor());
System.out.println("Deleted the subscription");
}
But i noticed that i am able to fetch the subscription details even after executing the above code and in addition the subscription can also be seen on the UI.
Can you please help me with this issue?
}
One answer
In the for loop, remove the asset.addSubscription(subscription); statement. Setting the action to RAMAction.DELETE is the only thing required. Also it's not necessary to update the asset inside the loop. If you have multiple subscriptions, it gets expensive to update the asset everytime.
Just a suggestion but in the println you could include the user as well.
Here's the code I executed against our 7.5.1.1 development test server:
public static RAMSession session = null;
public static void main(String[] args) {
session = new RAMSession("http://<ram_server_url>/", "admin_userid", "admin_password");
RAMAsset asset = session.getAsset(new AssetIdentification("asset_guid", "asset_version"));
RAMSubscription[] subscriptions = asset.getSubscriptions();
for (RAMSubscription subscription : subscriptions) {
subscription.setAction(RAMAction.DELETE);
System.out.println("Deleted the subscription for user" + subscription.getUser());
}
session.put(asset, new RAMStatusMonitor());
}
Just a suggestion but in the println you could include the user as well.
Here's the code I executed against our 7.5.1.1 development test server:
public static RAMSession session = null;
public static void main(String[] args) {
session = new RAMSession("http://<ram_server_url>/", "admin_userid", "admin_password");
RAMAsset asset = session.getAsset(new AssetIdentification("asset_guid", "asset_version"));
RAMSubscription[] subscriptions = asset.getSubscriptions();
for (RAMSubscription subscription : subscriptions) {
subscription.setAction(RAMAction.DELETE);
System.out.println("Deleted the subscription for user" + subscription.getUser());
}
session.put(asset, new RAMStatusMonitor());
}
Comments
Rich Kulp
FORUM MODERATOR / JAZZ DEVELOPER Dec 11 '12, 10:29 a.m.BTW: If you do not WANT to have subscriptions automatically added to assets you create then you can set this preference for yourself.
Go to My Dashboard->Edit and one of the checkbox on the page will say "Automatically subscribe to assets you create" Have this checkbox not checked and you will no longer get these subscriptions created for assets you create.