MicroStrategy ONE

Creating a Folder

This code sample uses SessionManagementSample.java from the Creating a Session topic to create a session on the MicroStrategy Tutorial project and then creates a folder under the Shared Reports folder. The code sample for creating a folder—FolderCreationSample.java—is provided in the samples/java/webobjects subfolder inside the MicroStrategy SDK installation.

/**

 * MicroStrategy SDK

 *

 * Copyright © 2001-2006 MicroStrategy Incorporated. All Rights Reserved.

 *

 * MICROSTRATEGY MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE

 * SUITABILITY OF THIS SAMPLE CODE, EITHER EXPRESS OR IMPLIED, INCLUDING

 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS

 * FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. MICROSTRATEGY SHALL NOT

 * BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,

 * MODIFYING OR DISTRIBUTING THIS SAMPLE CODE OR ITS DERIVATIVES.

 */

package com.microstrategy.sdk.samples.webobjects;

import com.microstrategy.web.objects.WebIServerSession;

import com.microstrategy.web.objects.WebFolder;

import com.microstrategy.webapi.EnumDSSXMLFolderNames;

import com.microstrategy.webapi.EnumDSSXMLObjectTypes;

import com.microstrategy.web.objects.WebObjectSource;

import com.microstrategy.web.objects.WebObjectsException;

/**

 * <p>Title: FolderCreationSample</p>

 * <p>Description: Create a folder under "Shared Reports" folder for the "MicroStrategy Tutorial" project.</p>

 * <p>Company: Microstrategy, Inc.</p>

 */

public class FolderCreationSample {

/**

 * Create a new folder under "Shared Reports" with the specified name

 * @param folderName {@link String} containing the name the new folder will have

 * @return {@link String} containing the new folder's DSSID

 */

    public static String createNewFolder(String folderName) {

    WebFolder newFolder = null;

    

        // Create a session

        WebIServerSession serverSession = SessionManagementSample.getSession();

        WebObjectSource objSource = serverSession.getFactory().getObjectSource();

        try {

            // Obtain ID for Shared Reports Folder and populate WebFolder

            // Setting

        String sharedReportsFolderID = objSource.getFolderID(EnumDSSXMLFolderNames.DssXmlFolderNamePublicReports);

        WebFolder folder = (WebFolder) objSource.getObject(sharedReportsFolderID, EnumDSSXMLObjectTypes.DssXmlTypeFolder);

            // Obtain new folder from WebObjectSource

            newFolder = (WebFolder)objSource.getNewObject(EnumDSSXMLObjectTypes.DssXmlTypeFolder, folderName);

            // Save new folder under "Shared Reports" folder

            objSource.saveAs(newFolder, newFolder.getName(), folder, true);

        } catch (WebObjectsException ex) {

            System.out.println("Error while creating new folder " + folderName + ": " + ex.getMessage());

        }

        //Close the session to clean up resources on Intelligence Server

        SessionManagementSample.closeSession(serverSession);

        

        return newFolder.getID();

    }

    /**

     * Execute Folder Creation Sample

     * @param args String[]

     */

    public static void main(String args[]) {

        createNewFolder("newFolder");

    }

}