This java snippet explains how to delete history list subscriptions using the Strategy Web SDK. For this logic to work, the user requires permissions to unsubscribe from subscriptions.
package com.mstr.standalone;
import java.util.ArrayList;
import java.util.List;
import com.Strategy.web.objects.*;
public class DeleteSubScription {
private WebIServerSession isession;
private WebObjectsFactory factory;
private WebInboxSource inbox;
public DeleteSubScription() {
factory = WebObjectsFactory.getInstance();
isession = factory.getIServerSession();
isession.setServerName("was-rrchang");
isession.setProjectName("Strategy Tutorial");
isession.setLogin("bkelt");
isession.setPassword("bkelt");
isession.setServerPort(34952);
isession.setClientID("127.0.0.1");
try {
isession.refresh();
} catch (WebObjectsException e) {
e.printStackTrace();
}
inbox = isession.getFactory().getInboxSource();
}
public static void main(String[] args) {
DeleteSubScription historyList = new DeleteSubScription();
List<WebMessage> list = historyList.getMessages();
for (WebMessage message : list) {
//checks the message by Display name.
if (message.getDisplayName().indexOf("Unit Tracking by Supplier")>=0)
{
try {
// This deletes the subscription for the user logged in
// as long the user has permission to un-subscribe this subscription
message.removeFromInbox();
} catch (WebObjectsException e) {
e.printStackTrace();
}
}
}
}
// Getting the list of message from History List
public List<WebMessage> getMessages() {
List<WebMessage> list = new ArrayList<WebMessage>();
try {
//Getting the inbox messages
WebMessages messages = inbox.getInboxMessages();
for (int i = 0; i < messages.size(); i++) {
WebMessage message = messages.get(i);
list.add(message);
}
} catch (WebObjectsException e) {
e.printStackTrace();
}
return list;
}
}