MicroStrategy ONE

Moving 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 two new folders under the Shared Reports folder and moves one into the other. The code sample for moving a folder—FolderMoveSample.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.web.objects.WebObjectSource;

import com.microstrategy.web.objects.WebObjectsException;

import com.microstrategy.webapi.EnumDSSXMLObjectTypes;

/**

 * <p>Title: FolderMoveSample</p>

 * <p>Description: Create two folders under "Shared Reports" folder for the "MicroStrategy Tutorial" project

 * and move one into the other.</p>

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

 */

public class FolderMoveSample {

    /**

     * Create two folders under "Shared Reports" folder and move one into the other

     */

    public static void moveFolder() {

        // Create a session using

        WebIServerSession serverSession = SessionManagementSample.getSession();

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

        String outerID = FolderCreationSample.createNewFolder("outer");

        String innerID = FolderCreationSample.createNewFolder("inner");

        

        try {

        // Get WebFolder objects

        WebFolder outer = (WebFolder)objSource.getObject(outerID, EnumDSSXMLObjectTypes.DssXmlTypeFolder);

        WebFolder inner = (WebFolder)objSource.getObject(innerID, EnumDSSXMLObjectTypes.DssXmlTypeFolder);

        

        // Move inner folder to outer folder

        objSource.save(inner, outer);

        } catch (WebObjectsException ex) {

            System.out.println("Error while moving folder: " + ex.getMessage());

        }

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

        SessionManagementSample.closeSession(serverSession);

    }

    /**

     * Execute Folder Move Sample

     * @param args String[]

     */

    public static void main(String args[]) {

        moveFolder();

    }

}