MicroStrategy - SDK - Subscriptions

mstr-sdk

https://community.microstrategy.com/t5/SDK/TN44011-How-to-Modify-the-Email-Subject-for-the-Send-Now-Page-by/ta-p/193797
https://community.microstrategy.com/t5/SDK/TN44860-How-to-Change-the-History-List-Link-Sent-from-SendNow/ta-p/194586
https://community.microstrategy.com/t5/SDK/TN204736-How-to-Set-the-Send-Option-to-Link-to-history-list-in/ta-p/204736
https://community.microstrategy.com/t5/tkb/articleprintpage/tkb-id/sdk/article-id/1763
https://community.microstrategy.com/t5/tkb/articleprintpage/tkb-id/sdk/article-id/1695
https://lw.microstrategy.com/msdz/MSDZ_World2015/docs/ReferenceFiles/com/microstrategy/web/objects/WebSubscriptionDeliveryModeEmailProperties.html
https://community.microstrategy.com/t5/SDK/TN40354-How-to-Get-the-Subject-Line-for-an-E-mail-Alert-using/ta-p/190368
https://community.microstrategy.com/t5/tkb/articleprintpage/tkb-id/sdk/article-id/1561

How can we iterate over all subscriptions in the system?

WebSubscriptionsSource subSource = session.getFactory().getSubscriptionsSource();
SimpleList subList = subSource.getSubscriptionsByDeliveryMode(EnumDSSXMLSubscriptionDeliveryType.DssXmlDeliveryTypeAll);
for(int i = 0; i < subList.size(); i++) {
    WebSubscription ws = (WebSubscription)subList.item(i);
    System.out.println("\t\t Name: " + ws.getName() + "Report/Document: " + ws.getContent().getName());
    // getContent
    WebUserEntity wue = ws.getOwner();
    WebUser user = (WebUser) wue;
    user.populate();
    String loginID = user.getLoginName();
}

The above code retrieve a list of subscriptions / scheduled reports. This includes all the subscriptions in the system. It then use the getOwner method to retrieve the owner of the subscription, and then use the populate method and the getLoginName method to determine the LOGIN ID of the owner. I wrote this code when I need to look through the system to determine the list of users who have no security filter but have scheduled reports. I didn't use this code for this purpose. I end up using a different approach. I had one Java program using the Web SDK to determine the list of users who have no security filter. This program write the list of users that has no security filter to a text file. I then wrote another Command Manager script to process this text file and use the "LIST SUBSCRIPTIONS FOR OWNER … FOR PROJECT …" to determine if these users have scheduled reports.

NOTE: THE getSubscriptionsByDeliveryMode SEEMS TO RETURN AN EMPTY LIST IF WE DO NOT INVOKE setProjectName INSIDE THE getServerSession METHOD. TO GET ALL SUBSCRIPTIONS, WE MUST FIRST GET A LIST OF ACTIVE PROJECTS, AND THEN ITERATE OVER EACH PROJECT, AND WE MUST USE THE EnumDSSXMLNCSInstanceSourceField.DssXmlNCSInstanceAllInstancesLightWeightField FLAG WITH setFlags:

public class ForceExistingScheduledReportsToHistoryList {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        /*
         * This is based on:
         * https://community.microstrategy.com/t5/SDK/TN204736-How-to-Set-the-Send-Option-to-Link-to-history-list-in/ta-p/204736
         * https://lw.microstrategy.com/msdz/MSDL/931/docs/mergedProjects/websdk/topics/objbeans/Creating_a_Web_Subscription.htm
         */
        String methodName = "main";
        System.out.println("ForceExistingScheduledReportsToHistoryList::main invoked.");
        Vector v = getAccessibleProjectNames();
        for (int i = 0; i < v.size(); i++) {
            String projectName = v.get(i).toString();
            WebIServerSession session = getServerSession(projectName);
            forceSubscriptionToHistoryList(session);
            session.closeSession();
        }

    }

    private static void forceSubscriptionToHistoryList(WebIServerSession session) throws Exception {
        String projectName = session.getProjectName();
        WebSubscriptionsSource subSource = session.getFactory().getSubscriptionsSource();
        subSource.setFlags(EnumDSSXMLNCSInstanceSourceField.DssXmlNCSInstanceAllInstancesLightWeightField);
        SimpleList subList = subSource.getSubscriptionsByDeliveryMode(EnumDSSXMLSubscriptionDeliveryType.DssXmlDeliveryTypeAll);
        System.out.println("Processing.  projectName:" + projectName + ". Number of subscription found:" + subList.size());
        for(int i = 0; i < subList.size(); i++) {
            WebSubscription ws = (WebSubscription)subList.item(i);
            WebSubscriptionDeliveryModeEmailProperties prop = (WebSubscriptionDeliveryModeEmailProperties) ws.getDeliveryMode();
            prop.setSendToInbox(true);
            System.out.println("Saving. i: " + i);
            ws.save();
        }        
    }

    private static Vector getAccessibleProjectNames() throws Exception {
        Vector v = new Vector();
        WebIServerSession session = getServerSession("");
        WebObjectsFactory factory = session.getFactory();
        WebProjectSource oProjectSource = factory.getProjectSource();
        WebProjectInstances oPInstanceList = oProjectSource.getAccessibleProjectsInCluster();
        WebProjectInstance oPInstance = null;
        for (int i=0; i < oPInstanceList.size(); i++){
            oPInstance = oPInstanceList.get(i);
            if (oPInstance.getStatus() == EnumDSSXMLProjectStatus.DssXmlProjectStatusActive) {
                String projectName = oPInstance.getProjectName();
                v.add(projectName);
            }
        }
        session.closeSession();
        return v;
    }

    public static WebIServerSession getServerSession(String projectName) {

        WebIServerSession sessionInfo = null;

        try {

            String serverName = "QMIMSRDEV01";
            //String Project = "";
            String loginName = "Administrator";
            String password = "quantros";
            WebObjectsFactory woFact = WebObjectsFactory.getInstance();
            sessionInfo = woFact.getIServerSession();
            sessionInfo.setServerName(serverName);
            if (! projectName.equals("")) {
                sessionInfo.setProjectName(projectName);
            }
            sessionInfo.setLogin(loginName);
            sessionInfo.setPassword(password);
            sessionInfo.setAuthMode(EnumDSSXMLAuthModes.DssXmlAuthStandard);
            //sessionInfo.setApplicationType(EnumDSSXMLApplicationType.DssXmlApplicationCustomApp);

            //Create a new session
            sessionInfo.getSessionID();

        } catch (WebObjectsException ex) {
            System.out.println("Error creating a sesion");
        }
        return sessionInfo;
    }
}

How can we change the subject line for an email subscription?

See https://community.microstrategy.com/t5/SDK/TN44860-How-to-Change-the-History-List-Link-Sent-from-SendNow/ta-p/194586, particularly the props.setEmailSubject("blah blah testing");

How can we get reference to the report or document that is being subscribe?

See TN44860 on how to obtain the SubscriptionBean object, and then we can use the getTarget method of the SubscriptionBean object:

ObjectBean ob = sb.getTarget()

How can we determine the type of subscription from the SubscriptionBean object?

SubscriptionBean sb = (SubscriptionBean) event.getSource();
WebSubscription sub = sb.getSubscription();
props = (WebSubscriptionDeliveryModeProperties)sub.getDeliveryMode();
int mode = props.getMode();
if (mode == EnumDSSXMLSubscriptionDeliveryType.DssXmlDeliveryTypeEmail) {
    WebSubscriptionDeliveryModeEmailProperties propsEmail = (WebSubscriptionDeliveryModeEmailProperties) props;
    propsEmail.setEmailSubject("blah blah testing");
    sb.save();
}

How can we get a SubscriptionBean from an event?

SubscriptionBean sb = (SubscriptionBean) event.getSource();
sub.populate();

What is the relationship between SubscriptionEditorBean and SubscriptionBean?

The SubscriptionBean is contained within the SubscriptionEditorBean.

Why is it important to call the isOpen method of the SubscriptionEditorBean before attempting to adjust the email subject?

It is important to call the SubscriptionEditorBean's isOpen method before attempting to adjust the email subject otherwise a NullPointerException will be thrown.

Why is it necessary to iterate through all of the beans on the page and retrieve the specific SubscriptionEditorBean?

There are several SubscriptionEditorBeans contained on the page. It is therefore necessary to iterate through all of the beans on the page and retrieve the specific SubscriptionEditorBean.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License