To define the methods that work with SAS Foundation Services, BusinessQuery service, and OLAPTableView, add the following code near the end of the Java source.
Note that you will need to supply OMR server and SAS Foundation Services settings that are specific to your environment.
Specifically, you will need to provide your host name, port number, domain name, user ID, password, and repository in the appropriate locations below. For detailed information on deploying and
connecting to services, see
SAS Foundation Services.
/**
* Deploys SAS Foundation Services using either a specified XML deployment file or by
* identifying a location in the SAS Metadata Server.
* @param xmlDeploymentFile The name of the XML deployment file to use (optional).
* If null, the services will be deployed using information in the SAS Metadata Server.
* @exception Exception
*/
public void FSDeploy(String xmlDeploymentFile) throws Exception
{
if ( discoveryService != null )
{
return;
}
//Set JVM env variables to enable authentication via Platform Services;
com.sas.net.ClassResourceLocator policy =
new com.sas.net.ClassResourceLocator("java.app.policy", this.getClass());
com.sas.net.ClassResourceLocator login =
new com.sas.net.ClassResourceLocator("login.config", this.getClass());
try {
java.lang.System.setProperty("java.security.auth.login.config",
login.getResource().toString());
} catch (Exception e) {
throw new Exception
("Cannot load the login.config file. Make sure it exists in the same directory as the application.");
}
try {
java.lang.System.setProperty("java.security.policy",
policy.getResource().toString());
} catch (Exception e) {
throw new Exception
("Cannot load the policy file. Make sure it exists in the same directory as the application.");
}
final String applicationDeploymentName = "ADS Local Services";
final String serviceDeploymentGroupName = "BIP Core Services";
MetadataSourceInterface metadataSource = null;
// If an XML deployment file was specified...
if (xmlDeploymentFile != null)
{
// Create a metadata source from the XML deployment file.
com.sas.net.ClassResourceLocator crl =
new com.sas.net.ClassResourceLocator(xmlDeploymentFile, this.getClass());
metadataSource = new URLMetadataSource(crl.getResource(),
applicationDeploymentName, serviceDeploymentGroupName);
}
else
{
// Create a metadata source for an Open Metadata Repository
final String serverHost = "server";
final String serverPort = "9999";
final String serverIdentityId = "username";
final String serverIdentityPassword = SasPasswordString.
encode(SasPasswordString.SAS001_ENCODING, "password");
final String serverRepositoryName = "Repository Name";
metadataSource = new OMRMetadataSource(serverHost, serverPort,
serverIdentityId, serverIdentityPassword, serverRepositoryName,
applicationDeploymentName, serviceDeploymentGroupName);
}
// Obtain the local discovery service
discoveryService = DiscoveryService.defaultInstance();
// Deploy the services using the created metadata source.
ServiceLoader.deployServices(metadataSource, discoveryService);
}
/**
* Logs into the SAS Foundation Services that were obtained
* via the FSConnect method.
* @exception Exception
*/
public void FSLogin() throws Exception
{
// Use the remote discovery services to find a user service.
userService = (UserServiceInterface)discoveryService.findService(
new ServiceTemplate(
new Class[] {com.sas.services.user.UserServiceInterface.class}
));
// Get a user context from the user service by logging in.
final String domain = "DOMAIN";
final String username = "username";
final String password = SasPasswordString.encode
(SasPasswordString.SAS001_ENCODING, "password");
userContext = userService.newUser(username, password, domain);
// Use the remote discovery services to find a session service.
sessionService = (SessionServiceInterface)discoveryService.findService(
new ServiceTemplate(
new Class[] {com.sas.services.session.SessionServiceInterface.class}
));
// Create a session for this user and bind it to the user context.
sessionContext = sessionService.newSessionContext(userContext);
userContext.setSessionContext(sessionContext);
}
/**
* Loads the BusinessQuery Information Map identified by the mapName parameter,
* and creates and populates a BQ data selection object based on the contents
* of the InformationMap.
* @param mapName The name of the InformationMap to load.
* @exception Exception
* @return A boolean value representing whether or not the map was loaded.
*/
public boolean BQGetDataSelection(String mapName) throws Exception
{
// Get a BusinessQuery metadata service object.
IntelligentQueryMetadataServiceInterface IQMetadataService =
IntelligentQueryMetadataServiceFactory.newService();
// Get a specific InformationMap from the metadata service object.
PathUrl pathURL = new PathUrl(mapName);
InformationMap informationMap =
IQMetadataService.getInformationMap(sessionContext, pathURL);
if (informationMap != null)
{
// Determine the structure of the data in the InformationMap.
if (!informationMap.getStructure().isOLAP())
{
javax.swing.JOptionPane.showMessageDialog(this,
"The selected map doesn't represent OLAP data.",
"Error", javax.swing.JOptionPane.ERROR_MESSAGE);
return false;
}
// Create a dataSelection from the InformationMap and add ResultItems to it
// to create a sample. Since we're passing in null for the maxElements parameter,
// only 2 Hierarchies and 2 Measures will be used.
dataSelection = DataSelectionFactory.newSampleDataSelection(informationMap, null);
}
return true;
}
/**
* Disconnects from the SAS Foundation Services and releases any used resources.
* @exception Exception
*/
public void FSDisconnect() throws Exception
{
// Release the remote discovery service
if (discoveryService != null)
discoveryService.destroy();
}
/**
* This is the primary entry point for this example. It connects and logs into
* the SAS Foundation Services, then obtains a BusinessQuery data selection from
* the requested InformationMap.
*
* The data selection is then adapted to fit into the OLAPTableView object, where
* it is then appropriately rendered.
* @param mapName The name of the InformationMap to load.
*/
public void LoadInformationMap(String mapName)
{
try
{
JLabel2.setText("Building DataSelection from requested InformationMap...");
if (BQGetDataSelection(mapName))
{
JLabel2.setText("Building BusinessQuery/OLAP dataset adapter...");
BusinessQueryToOLAPDataSetAdapter businessQueryToOLAPDataSetAdapter =
new BusinessQueryToOLAPDataSetAdapter(dataSelection);
JLabel2.setText("Building OLAP table model adapter...");
final OLAPTableModelAdapter olapTableModelAdapter =
new OLAPTableModelAdapter(businessQueryToOLAPDataSetAdapter);
JLabel2.setText("Setting model for OLAPTableView...");
// Note that setting the model needs to be performed back in
// the original event queue thread.
java.awt.EventQueue.invokeLater( new Runnable() {
public void run()
{
OLAPTableView1.setModel(olapTableModelAdapter);
JLabel2.setText("Done.");
}
});
}
}
catch (Exception e)
{
showException(e);
}
}
public String populateList(String mapPath)
{
try{
JLabel2.setText("Deploying SAS Foundation Services...");
FSDeploy(null);
JLabel2.setText("Logging in to SAS Foundation Services...");
FSLogin();
java.util.List repos = userContext.getRepositories();
com.sas.services.information.RepositoryInterface reposInt =
(com.sas.services.information.RepositoryInterface)repos.get(0);
String startDir = "";
if (mapPath != null)
{
int index = mapPath.lastIndexOf("/");
if (index != -1)
{
startDir = mapPath.substring(0, index);
}
}
java.util.Map fileTypes = new java.util.HashMap();
fileTypes.put("Information Maps", "InformationMap");
InformationServicesSelectorPanel panel =
new InformationServicesSelectorPanel(startDir, reposInt, fileTypes, false);
RemoteFileSelectorDialog dialog =
new RemoteFileSelectorDialog(Util.getParentAWTFrame(this),
"Select an Information Map", true, 2, panel);
dialog.setVisible(true);
java.util.List items = new java.util.ArrayList();
//if (!panel.wasCancelled())
items = panel.getReturnedInformation(true);
if (items != null && items.size() > 0)
{
mapPath = items.get(0).toString();
}
return mapPath;
}catch (Exception e)
{
showException(e);
return "";
}
}