EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB31222: How to Execute a Document, Answer Prompts and Create a New File Subscription Using the MicroStrategy Java Web SDK


Community Admin

• Strategy


How to Execute a Document, Answer Prompts and Create a New File Subscription Using the MicroStrategy Java Web SDK.

SUMMARY: Using the Strategy Java Web SDK 9.x, it is possible to programmatically create subscriptions for report and documents, answer prompts and save the subscriptions as personalized.
 
 The following flow is required to accomplish this: 

  1. Execute the report or document
  2. Answer prompts passing xml if necessary
  3. Create a subscription and set its content to the report or document (reportbean or rwbean)
  4. Configure the subscription (set format, delivery mode, trigger, address etc)
  5. Save it.

 
In the following code sample, a prompted document is executed and a personalized file subscription is created:
 


package samples.standalone;

import java.util.Date;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectsException;
import com.Strategy.web.objects.WebObjectsFactory;
import com.Strategy.webapi.EnumDSSXMLApplicationType;
import com.Strategy.web.beans.BeanFactory;
import com.Strategy.web.beans.RWBean;
import com.Strategy.web.beans.SubscriptionBean;
import java.util.Enumeration;
import com.Strategy.web.objects.EnumWebSubscriptionContentTypes;
import com.Strategy.web.objects.SimpleList;
import com.Strategy.web.objects.WebPrompts;
import com.Strategy.web.objects.WebSubscription;
import com.Strategy.web.objects.WebSubscriptionAddress;
import com.Strategy.web.objects.WebSubscriptionContentFormat;
import com.Strategy.web.objects.WebSubscriptionDeliveryModeFileProperties;
import com.Strategy.web.objects.WebSubscriptionTrigger;
import com.Strategy.web.objects.WebSubscriptionsSource;
import com.Strategy.web.objects.rw.RWInstance;
import com.Strategy.webapi.EnumDSSXMLSubscriptionDeliveryType;


public class CreateFileSubscription {

// Create factory object.
  static WebObjectsFactory factory=WebObjectsFactory.getInstance();
  static WebIServerSession serverSession=factory.getIServerSession(); 

 public static void main(String[] args) {

   String SessionID = "";

   serverSession.setServerName("IServerName");
   serverSession.setServerPort(0);
   serverSession.setProjectName("Strategy Tutorial");
   serverSession.setLogin("administrator");
   serverSession.setPassword("");
serverSession.setApplicationType(EnumDSSXMLApplicationType.DssXmlApplicationCustomApp);   

   try {   
    SessionID = serverSession.getSessionID();
    System.out.println("Welcome " + serverSession.getLogin());
    System.out.println("SessionID: " + SessionID);
   } catch (WebObjectsException ex) {}

   String docID = "177482C44172C7F11A187C9577808CAD";

 //prompt answer xml:

  String ansXML = "<rsl lcl=\"1033\"><pa pt=\"7\" pin=\"0\" did=\"E8F30ADB41E7A548698C49BA284510E4\" tp=\"10\"><mi><es dirty=\"1\"><at did=\"8D679D3711D3E4981000E787EC6DE8A4\" tp=\"12\" stp=\"3072\" n=\"Category\" disp_n=\"Category\"/><e ei=\"8D679D3711D3E4981000E787EC6DE8A4:1\" emt=\"1\" art=\"1\" disp_n=\"\" disp_id=\"1\"/></es></mi></pa></rsl>";

   //create new file subscription
   boolean success = createFileSubs(docID, ansXML);
   System.out.println("File Subscription Created Successfully? "+ success);

 }

 public static boolean createFileSubs(String documentID, String promptAnswerXML) {

  Date dt = new Date();

  try {
   //create new RWBean:
   RWBean rwb = (RWBean)BeanFactory.getInstance().newBean("RWBean");     
   rwb.setSessionInfo(serverSession); 

   //get the instance, answer prompts, make sure status is ready
   //set document ID   
   rwb.setObjectID(documentID);
   RWInstance rwi = rwb.getRWInstance();
   rwi.setAsync(false);
   rwi.pollStatus();
   int status = rwi.getStatus();
   out("Current status of the rsdoc: "+ status);

   WebPrompts prompts = rwi.getPrompts();
   prompts.populateAnswers(promptAnswerXML);
   prompts.validate();
   prompts.answerPrompts();
   int newStatus = rwi.pollStatus();
   out("New status is: "+ newStatus);

   SubscriptionBean sb= (SubscriptionBean)BeanFactory.getInstance().newBean("SubscriptionBean");;
   sb.setSessionInfo(serverSession);
   sb.setContent(rwb);    

    //set subscription content to document
    WebSubscription ws = sb.getSubscription();   

    //set delivery mode
    ws.populate();
ws.setDeliveryMode(EnumDSSXMLSubscriptionDeliveryType.DssXmlDeliveryTypeFile);
    ws.setSendNow(true);
    ws.setName("MyFileSub "+dt);
    WebSubscriptionsSource  wss = serverSession.getFactory().getSubscriptionsSource();

    //set the content format to PDF. If this is not set, it will default to HTML format
    SimpleList formats = ws.getContent().getAvailableFormats();
    WebSubscriptionContentFormat format = null;
    for(int z=0;z<formats.size();z++){
      format = (WebSubscriptionContentFormat)formats.item(z);
      if(format.getName().equalsIgnoreCase("PDF")){
        ws.getContentProperties().setFormat(format);
      }
     }

    //set deliveryMode Properties:
    WebSubscriptionDeliveryModeFileProperties wdp = (WebSubscriptionDeliveryModeFileProperties) ws.getDeliveryMode();

   //set file name
   wdp.setFileName("TestFileName "+ dt);   

   //search for and set the trigger (Books Closed)
   SimpleList triggers = sb.getAvailableTriggers();
   Enumeration<WebSubscriptionTrigger> e = triggers.elements();
   while (e.hasMoreElements()) {
    WebSubscriptionTrigger woiPlanning = (WebSubscriptionTrigger) e
      .nextElement();
    out("Trigger name:"+ woiPlanning.getName());
    if (woiPlanning.getName().equals("Books Closed"))
     ws.setTrigger(woiPlanning);
   }

   SimpleList addresses = sb.getAvailableAddresses();
   Enumeration<WebSubscriptionAddress> adds = addresses.elements();
   WebSubscriptionAddress addy = null;
   while (adds.hasMoreElements()) {
    WebSubscriptionAddress address = adds.nextElement();
    out("Address: "+ address.getName()+" = "+ address.getValue());
    if (address.getName().equalsIgnoreCase("MyAddress")){
     addy = address;
    }     
   }

   ws.setAddress(addy);   

   boolean p = ws.isPersonalized();   
   out("is personalized? "+ p); 

   //save the new subscription
   sb.save();   

  } catch (Exception e) {
   e.printStackTrace();
   return false;
  }
  return true;
 }

 public static void out(String s){
  System.out.println(s);
 }
}

 
 
The example provided in this document is provided “as-is” to the user and assumes that the user:

  • Can program, compile (e.g. javac, jikes, etc.), and execute Java programs
  • Can configure environment variables (e.g. JAR files, property files, etc.)
  • Have all the necessary tools to create Java applications (JDK, IDE, etc.)
  • Has access to the Strategy SDK documentation.
  • Has read the customization warning at the bottom of this document

 
PREREQUISITES:
For the sample to work, the Strategy Web JAR files must be accessible by the Java Runtime
Environment. The Strategy Web JAR files can be found under:

  • Strategy Web Universal (JSP): {web_root}/WEB-INF/lib directory.
  • Strategy Web (.NET): Program Files\Common Files\Strategy directory.

 
Note:
More elaborate programs will require additional library files and are out of the scope of this document.
 
ADDITIONAL INFORMATION:
The Strategy SDK allows you to customize the standard Strategy Web interface, and extend and integrate the Strategy business intelligence functionality into other applications. However, before changing the way Strategy Web products look or behave, it is helpful to understand how the application is built. For more information regarding the Strategy Web architecture or the process of customizing Strategy Web, please refer to Strategy Developer Zone (https://community.strategy.com/topic/0TO44000000FliLGAS/sdk).
 
To access the Strategy Developer Zone, you must have access to the Strategy Knowledge Base, you must have purchased the Strategy SDK, and you must be current on your Strategy maintenance agreement. If you are a US-based business and believe that you satisfy all three of these conditions but you do not have access to the Strategy Developer Zone, please contact Strategy Technical Support at support@microstrategy.com or at (703) 848-8700. If you are an international business, please contact Strategy Technical Support at the appropriate email address or phone number found at https://www.microstrategy.com/en/support/contact-support.
 
CUSTOMIZATION WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.
 


Comment

0 comments

Details

Knowledge Article

Published:

June 12, 2017

Last Updated:

October 23, 2017