MicroStrategy ONE
Moving an Object in a Folder
There are a number of objects that can be moved within a folder, such as reports, documents, and other folders. The code sample below illustrates how to move a report, but you can extrapolate from the code that is provided to move any object in 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 and moves a report into it. The code sample for moving a report—ReportMoveSample.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.WebObjectInfo;
import com.microstrategy.web.objects.WebObjectSource;
import com.microstrategy.web.objects.WebObjectsException;
im/**
* <p>Title: ReportMoveSample</p>
* <p>Description: Create folder under "Shared Reports" folder for the "MicroStrategy Tutorial" project
* and move "Customer Income Analysis" report into it.</p>
* <p>Company: Microstrategy, Inc.</p>
*/port com.microstrategy.webapi.EnumDSSXMLObjectTypes;
public class ReportMoveSample {
/**
* Create folder under "Shared Reports" folder and move report into it
*/
public static void moveReport() {
// Create a session using
WebIServerSession serverSession = SessionManagementSample.getSession();
WebObjectSource objSource = serverSession.getFactory().getObjectSource();
String reportFolder = FolderCreationSample.createNewFolder("reportFolder");
String customerIncomeAnalysisID = "256263D142248D56446F3A80AD100C06";
try {
// Get WebFolder objects
WebFolder outer = (WebFolder)objSource.getObject(reportFolder, EnumDSSXMLObjectTypes.DssXmlTypeFolder);
WebObjectInfo report = objSource.getObject(customerIncomeAnalysisID, EnumDSSXMLObjectTypes.DssXmlTypeReportDefinition);
// Move inner folder to outer folder
objSource.save(report, 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 Report Move Sample
* @param args String[]
*/
public static void main(String args[]) {
moveReport();
}
}