MicroStrategy ONE
Pivoting the Metrics Template Unit
This example demonstrates how to pivot the metrics template unit.
Code sample
In order to see the results, you can use the code described in Executing a Report and Retrieving the Results.
This code sample assumes that a valid session ID is stored in a String variable called sessionID, and the report ID stored in a String variable called reportID.
//submit a report for execution and return a WebReportInstance object of the result of the execution.
//These steps are explained in detail in the previous examples
WebObjectsFactory woFact = WebObjectsFactory.getInstance();
WebIServerSession ss = woFact.getIServerSession();
ss.setSessionID(sessionID);
ss.setApplicationType(EnumDSSXMLApplicationType.DssXmlApplicationCustomApp);
WebReportSource rptSrc = woFact.getReportSource();
WebReportInstance rptInst = rptSrc.getNewInstance(reportID);
//sets the preferences for polling MicroStrategy Intelligence server,
//which is used for getResults or getTemplate calls
rptInst.setAsync(false); rptInst.setPollingFrequency(250); rptInst.setMaxWait(120000);
//uses the pollStatus method, which uses the polling parameters set on the report instance
//to poll Intelligence Server until either the report is in an end state (ready, error, or prompt),
//or until the maximum wait time is reached
int status = rptInst.pollStatus();
//ensure that the report is in result status before continuing, or prints an error message if it is not ready
if (status != EnumDSSXMLStatus.DssXmlStatusResult) {
Log.logger.log(Level.ERROR, "Error: unexpected status: " + status);
return;
}
//obtains the template definition of the report, and returns it as a WebTemplate object
WebTemplate template = rptInst.getTemplate();
//simply causes the metrics collection to be moved from its current location, to axis 2, position 1
//If the metrics collection does not exist anywhere else on the report,
//then an empty metrics collection is added in the given location
template.addMetrics(EnumDSSXMLAxisName.DssXmlAxisNameRows, 1); // pivot from current location to (2, 1)
//obtains the WebReportManipulation interface from the report instance
WebReportManipulation rptManip = rptInst.getReportManipulator();
//submits the changes to Intelligence Server, and returns a WebReportInstance object
//which is used to retrieve the results of the manipulation
WebReportInstance newInst = rptManip.applyChanges();