In order to modify the currency formatting on a stand alone metric using the Java Web API follow these steps:
Sample Code:
package com.Strategy.sdk.examples.standalone;
import com.Strategy.web.app.beans.GridFormatHelper;
import com.Strategy.web.objects.WebFormat;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectSource;
import com.Strategy.web.objects.WebObjectsException;
import com.Strategy.web.objects.WebObjectsFactory;
import com.Strategy.web.objects.WebParsedMetric;
import com.Strategy.webapi.EnumDSSXMLParserOutFlags;
public class StandaloneMetric {
// Constants private static final String ISERVER = "";
private static final String PROJECT = "Strategy Tutorial";
private static final String LOGIN = "Administrator";
private static final String PWD = "";
private static final int PORT = 0;
private static final String METRIC_ID = "E40792574CE5654EDC544FA5359B12B4";
private static final int PARSER_OUT_FLAG_TOTAL = EnumDSSXMLParserOutFlags.DssXmlParserOutTotalMetric;
private static final int OUTPUT_FLAG = EnumDSSXMLParserOutFlags.DssXmlParserOutTokenStream | EnumDSSXMLParserOutFlags.DssXmlParserOutMetricExtendedProperties | EnumDSSXMLParserOutFlags.DssXmlParserOutMetricGridFormat | EnumDSSXMLParserOutFlags.DssXmlParserOutMetricHeaderFormat | EnumDSSXMLParserOutFlags.DssXmlParserOutMetricObjectInfo | EnumDSSXMLParserOutFlags.DssXmlParserOutMetricProperties | EnumDSSXMLParserOutFlags.DssXmlParserOutMetricSubtotals;
// Instance variables private static WebObjectsFactory factory = null;
private static WebIServerSession serverSession = null;
public static void main(String[] args) {
WebIServerSession serverSession = null;
WebObjectSource objSource = null;
WebParsedMetric parsedMetric = null;
try {
//Create a session using
serverSession = getSession();
objSource = serverSession.getFactory().getObjectSource();
// Retrieve the metric object
parsedMetric = objSource.getParsedMetric(METRIC_ID);
// Change the metric formatting
changeMetricFormatting(parsedMetric);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
closeSession(serverSession);
}
}
private static WebIServerSession getSession() {
if (serverSession == null) { //create factory object
factory = WebObjectsFactory.getInstance();
serverSession = factory.getIServerSession();
//Set up session properties
serverSession.setServerName(ISERVER);
serverSession.setServerPort(PORT);
serverSession.setProjectName(PROJECT);
serverSession.setLogin(LOGIN);
serverSession.setPassword(PWD);
//Initialize the session with the above parameters
try {
System.out.println("\nSession created with ID: " + serverSession.getSessionID() + "\n");
} catch (WebObjectsException ex) {
handleError(null, "Error creating session:" + ex.getMessage());
}
}
//Return session
return serverSession;
}
private static void handleError(WebIServerSession serverSession, String message) {
System.out.println(message);
if (serverSession != null) {
closeSession(serverSession);
}
System.exit(0);
}
private static void closeSession(WebIServerSession serverSession) {
try {
serverSession.closeSession();
} catch (WebObjectsException ex) {
System.out.println("\nError closing session:" + ex.getMessage());
return;
}
System.out.println("\nSession closeweb.obd.");
}
private static void setMetricFormatting(WebFormat metricFormat) throws WebObjectsException, IllegalArgumentException {
// Formatting parameters String category = String.valueOf(1);
String separator = "1";
String decimal = "1";
String currency = "G";
String currpos = String.valueOf(2);
String neg = String.valueOf(4);
String prevformat = "###0.0";
String format = GridFormatHelper.constructNumberFormat(category, separator, decimal, currency, currpos, neg, prevformat);
// Output format
System.out.println("\nFormat: " + format);
// Set the new formatting values
metricFormat.setValue("FormattingNumber", "Category", category);
metricFormat.setValue("FormattingNumber", "Format", format);
metricFormat.setValue("FormattingNumber", "NegativeNumbers", neg);
metricFormat.setValue("FormattingNumber", "CurrencyPosition", currpos);
metricFormat.setValue("FormattingNumber", "CurrencySymbol", currency);
metricFormat.setValue("FormattingNumber", "ThousandSeparator", separator);
metricFormat.setValue("FormattingNumber", "DecimalPlaces", decimal);
}
private static void changeMetricFormatting(WebParsedMetric parsedMetric) throws WebObjectsException {
parsedMetric.load(OUTPUT_FLAG);
// Print name
System.out.println("Name: "+parsedMetric.getName());
// Get the formatting
WebFormat metricFormat = parsedMetric.getGridFormat();
// Change the formatting
setMetricFormatting(metricFormat);
// Save the metric
parsedMetric.save(PARSER_OUT_FLAG_TOTAL);
}
}
PREREQUISITES:
For the sample to work, the Strategy Web JAR files must be accessible by the Java Runtime
Environment. The Strategy Web JAR files can be found under:
The example provided in this document is provided “as-is” and user has read the following customization warning:
ADDITIONAL INFORMATION:
The Strategy SDK allows you to customize several Strategy products and extend and integrate the Strategy business intelligence functionality into other applications. However, before changing the way Strategy products look or behave, it is helpful to understand how the application is built. For more information regarding the Strategy products or the process of customizing Strategy products, please refer to Strategy Developer Zone (https://developer.Strategy.com).
To access the Strategy Developer Zone, you must have access to the Strategy Knowledge Base, you must have purchased the Strategy SDK, and you must be current on your Strategy maintenance agreement. If you are a US-based business and believe that you satisfy all three of these conditions but you do not have access to the Strategy Developer Zone, please contact Strategy Technical Support at support@Strategy.com or at (703) 848-8700. If you are an international business, please contact Strategy Technical Support at the appropriate email address or phone number found at https://www.Strategy.com/us/services/support/contact.
CUSTOMIZATION WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.
CUSTOMIZATION WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.