It's all about the answers!

Ask a question

Not able to delete a subscription using the RAM 7511 java api


Manjiri Kamat (5132325) | asked Dec 06 '12, 1:31 a.m.
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?

    }

Comments
Rich Kulp commented Dec 11 '12, 10:29 a.m.
FORUM MODERATOR / JAZZ DEVELOPER

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.

One answer



permanent link
Peter Walker (168136) | answered Dec 06 '12, 11:50 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
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());
    }

Your answer


Register or to post your answer.