The sample code below shows how users can personalize the prompt answers for an existing report subscription and save it back to the Metadata with the new prompt answers using Strategy SDK version 9.x.
import com.Strategy.web.objects.EnumWebSubscriptionContentTypes;
import com.Strategy.web.objects.SimpleList;
import com.Strategy.web.objects.WebElements;
import com.Strategy.web.objects.WebElementsPrompt;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectInfo;
import com.Strategy.web.objects.WebObjectSource;
import com.Strategy.web.objects.WebObjectsFactory;
import com.Strategy.web.objects.WebPrompts;
import com.Strategy.web.objects.WebSubscription;
import com.Strategy.web.objects.WebSubscriptionContent;
import com.Strategy.web.objects.WebSubscriptionContentReport;
import com.Strategy.web.objects.WebSubscriptionsSource;
import com.Strategy.webapi.EnumDSSXMLApplicationType;
import com.Strategy.webapi.EnumDSSXMLObjectTypes;
public class EditSubscriptionWithPrompts {
private static WebObjectsFactory factory;
Private static WebIServerSession serverSession;
public static void main(String[] args) throws Exception {
try {
createSession();
editSubscription();
} finally {
closeSession();
}
}
static void createSession() throws Exception {
factory = WebObjectsFactory.getInstance();
serverSession = factory.getIServerSession();
serverSession.setServerName("SERVER_NAME");
serverSession.setServerPort(0);
serverSession.setProjectName("PROJECT_NAME");
serverSession.setLogin("USER_ID");
serverSession.setPassword("");
serverSession.setApplicationType(EnumDSSXMLApplicationType.DssXmlApplicationCustomApp);
String sessionID = serverSession.getSessionID();
}
static void closeSession() throws Exception {
WebIServerSession serverSession = factory.getIServerSession();
if (serverSession != null) {
serverSession.closeSession();
}
}
static void editSubscription() throws Exception {
WebObjectSource mysource = factory.getObjectSource();
//Get the report for which the subscription has been created
WebObjectInfo myreport = mysource.getObject("E9CC66724445EC9EF03A32B95DBDB570", EnumDSSXMLObjectTypes.DssXmlTypeReportDefinition, true);
WebSubscriptionsSource subSource =serverSession.getFactory().getSubscriptionsSource();
SimpleList list = subSource.getSubscriptions(myreport);
WebSubscription sub = null;
WebSubscriptionContentReport content = null;
//Get the first subscription defined on the report
sub = (com.Strategy.web.objects.WebSubscription) list.item(0);
//Get the subscription content report from which the prompts defined on the subscription can be accessed
WebSubscriptionContentReport contentReport = (WebSubscriptionContentReport) getSubscriptionContent(sub);
//Check if the subscription has prompts defined on it
if (contentReport.isPersonalized()) {
//If the subscription contains prompts call reprompt
contentReport.reprompt();
//Get the prompts defined clear the elements and add new elements before answering the prompts
WebPrompts prompts = contentReport.getPrompts();
WebElementsPrompt prompt = (WebElementsPrompt) prompts.get(0);
WebElements elements = prompt.getAnswer();
elements.clear();
elements.add("8D679D4B11D3E4981000E787EC6DE8A4:1", "Northeast");
elements.add("8D679D4B11D3E4981000E787EC6DE8A4:6", "Northwest");
prompt = (WebElementsPrompt) prompts.get(1);
elements = prompt.getAnswer();
elements.clear();
elements.add("8D679D5111D3E4981000E787EC6DE8A4:2010", "2010");
elements.add("8D679D5111D3E4981000E787EC6DE8A4:2011", "2011");
prompts.answerPrompts();
//Save the subscription after the prompts have been resolved
if (contentReport.isResolved()) {
sub.save();
}
}
}
static WebSubscriptionContent getSubscriptionContent(WebSubscription sub)
throws Exception {
WebSubscriptionContent content = sub.getContent();
WebSubscriptionContentReport contentReport = null;
int contentType = content.getContentType();
if (contentType == EnumWebSubscriptionContentTypes.CONTENT_TYPE_REPORT) {
contentReport = (WebSubscriptionContentReport) content;
}
return contentReport;
}
}