/** Licensed Materials - Property of IBM IBM Cognos Products: DOCS (C) Copyright IBM Corp. 2005, 2008 US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /** * DrillThrough.java * * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated). */ import java.rmi.RemoteException; import java.util.Enumeration; import java.util.Hashtable; import com.cognos.developer.schemas.bibus._3.Account; import com.cognos.developer.schemas.bibus._3.AddOptions; import com.cognos.developer.schemas.bibus._3.BaseClass; import com.cognos.developer.schemas.bibus._3.BaseClassArrayProp; import com.cognos.developer.schemas.bibus._3.BaseParameter; import com.cognos.developer.schemas.bibus._3.BaseParameterAssignment; import com.cognos.developer.schemas.bibus._3.BaseParameterAssignmentArrayProp; import com.cognos.developer.schemas.bibus._3.BaseReportActionEnum; import com.cognos.developer.schemas.bibus._3.BaseReportActionEnumProp; import com.cognos.developer.schemas.bibus._3.DeploymentReference; import com.cognos.developer.schemas.bibus._3.DeploymentReferenceArrayProp; import com.cognos.developer.schemas.bibus._3.DeploymentReferenceProp; import com.cognos.developer.schemas.bibus._3.DrillPath; import com.cognos.developer.schemas.bibus._3.Locale; import com.cognos.developer.schemas.bibus._3.MetadataModelItemName; import com.cognos.developer.schemas.bibus._3.MultilingualToken; import com.cognos.developer.schemas.bibus._3.Parameter; import com.cognos.developer.schemas.bibus._3.ParameterAssignmentDataItem; import com.cognos.developer.schemas.bibus._3.PropEnum; import com.cognos.developer.schemas.bibus._3.QueryOptions; import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject; import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject; import com.cognos.developer.schemas.bibus._3.Sort; import com.cognos.developer.schemas.bibus._3.StringProp; import com.cognos.developer.schemas.bibus._3.TokenProp; import com.cognos.developer.schemas.bibus._3.UpdateActionEnum; public class DrillThrough { // default constructor public DrillThrough() { super(); } // Use to create a Drill-through definition public String createDrillThroughDefinition(CRNConnect myConnect, String dtDefinition, BaseClassWrapper packageName, BaseClassWrapper reportName, Hashtable reportList) { String result = null; DrillPath myDrillPath = null; // get current account information Account myAccount = this.getCurrentAccountInfo(myConnect); myDrillPath = new DrillPath(); // set drill through name and description myDrillPath = this.setDrillThroughNameDesc(dtDefinition, myDrillPath); // set drill through contact myDrillPath = this.setDrillThroughContact(myAccount, myDrillPath); // set the drill through action myDrillPath = this.setDrillThroughAction(myDrillPath); // set the drill through target myDrillPath = this.setDrillThroughTarget(reportName, myDrillPath); // set the drill through parameter values myDrillPath = this.setDrillThroughParameters(reportName, reportList, myDrillPath); result = this.addDrillThroughDefinition(myConnect, myDrillPath, packageName); return result; } /** * Retrieve the report parameters from a Hashtable * * @param oneReport: * given report * @param myHash: * one Hashtable * @return: one Hashtable contains report name and its parameters */ public Hashtable getReportParameters(BaseClassWrapper oneReport, Hashtable myHash) { Hashtable paraList = new Hashtable(); BaseParameter[] myPara = null; myPara = (BaseParameter[]) myHash.get(oneReport); if (myPara != null) { for (int i = 0; i < myPara.length; i++) { String paraName = ((Parameter) myPara[i]).getName(); String modelFilterItemStr = ((Parameter) myPara[i]) .getModelFilterItem(); paraList.put(paraName, modelFilterItemStr); } } return paraList; } // Get package search path public String getPackagePath(BaseClassWrapper aPackage) { String packagePath = null; if (aPackage != null) { packagePath = aPackage.getBaseClassObject().getSearchPath() .getValue(); } return packagePath; } // Get current account information to assign to Drill-through definition public Account getCurrentAccountInfo(CRNConnect myConn) { BaseClass[] bcAccountInfo = null; Account currentAccount = null; PropEnum propEnum[] = new PropEnum[] { PropEnum.searchPath, PropEnum.defaultName }; SearchPathMultipleObject searchPathObject = new SearchPathMultipleObject("~"); try { bcAccountInfo = myConn.getCMService().query(searchPathObject, propEnum, new Sort[] {}, new QueryOptions()); if (bcAccountInfo != null) { currentAccount = (Account) bcAccountInfo[0]; } } catch (RemoteException ex) { System.out.println("Failed to get current account information." + "\n" + "The error: " + ex.getMessage()); } return currentAccount; } // use to set drill through name and description public DrillPath setDrillThroughNameDesc(String aDefinition, DrillPath drillPathObj) { TokenProp myDrillName = new TokenProp(); StringProp myDrillDesc = new StringProp(); // set drill name and description myDrillName.setValue(aDefinition); myDrillDesc .setValue("This is an example of how to create a Drill-through definition in the SDK."); drillPathObj.setDefaultName(myDrillName); drillPathObj.setDefaultDescription(myDrillDesc); return drillPathObj; } // use to set drill through contact public DrillPath setDrillThroughContact(Account accountInfo, DrillPath drillPathObj) { BaseClass[] userInfo = new BaseClass[1]; BaseClassArrayProp contact = new BaseClassArrayProp(); userInfo[0] = accountInfo; contact.setValue(userInfo); drillPathObj.setContact(contact); return drillPathObj; } // use to set drill through action public DrillPath setDrillThroughAction(DrillPath drillPathObj) { BaseReportActionEnumProp drillRptAction = new BaseReportActionEnumProp(); drillRptAction.setValue(BaseReportActionEnum.run); drillPathObj.setAction(drillRptAction); return drillPathObj; } // use to set drill through target public DrillPath setDrillThroughTarget(BaseClassWrapper targetReport, DrillPath drillPathObj) { DeploymentReferenceArrayProp drArrPropTarget = new DeploymentReferenceArrayProp(); BaseClass[] bcArrTarget = new BaseClass[1]; bcArrTarget[0] = targetReport.getBaseClassObject(); DeploymentReference[] dArrTarget = new DeploymentReference[1]; DeploymentReference drTarget = new DeploymentReference(); MultilingualToken[] targetNames = new MultilingualToken[1]; targetNames[0] = new MultilingualToken(); targetNames[0].setValue("targets"); targetNames[0].setLocale("en"); drTarget.setObjects(bcArrTarget); drTarget.setName(targetNames); dArrTarget[0] = drTarget; drArrPropTarget.setValue(dArrTarget); drillPathObj.setDeploymentReferences(drArrPropTarget); return drillPathObj; } // use to set drill through parameters public DrillPath setDrillThroughParameters(BaseClassWrapper targetReport, Hashtable reportAndPara, DrillPath drillPathObj) { Hashtable listOfPara = new Hashtable(); listOfPara = this.getReportParameters(targetReport, reportAndPara); int numOfPara = listOfPara.size(); int myCount = 0; BaseParameterAssignmentArrayProp parameters = new BaseParameterAssignmentArrayProp(); BaseParameterAssignment[] prmAssignArr = new BaseParameterAssignment[numOfPara]; ParameterAssignmentDataItem myParaDataItem = null; MetadataModelItemName myMetaModelItemName = null; Enumeration keyEnum = listOfPara.keys(); // get all reports while (keyEnum.hasMoreElements()) { String myNameOfPara = (String) keyEnum.nextElement(); String myModelFilterItemStr = (String) listOfPara.get(myNameOfPara); myMetaModelItemName = new MetadataModelItemName(myModelFilterItemStr); myParaDataItem = new ParameterAssignmentDataItem(); myParaDataItem.setParameterName(myNameOfPara); myParaDataItem.setDataItemName(myMetaModelItemName); prmAssignArr[myCount] = myParaDataItem; myCount++; } parameters.setValue(prmAssignArr); drillPathObj.setParameterAssignments(parameters); return drillPathObj; } // add a Drill-through definition public String addDrillThroughDefinition(CRNConnect myConn, DrillPath drillPathObj, BaseClassWrapper aPackage) { String addResult; SearchPathSingleObject path = null; path = new SearchPathSingleObject(); BaseClass[] bcDrill = new BaseClass[1]; bcDrill[0] = drillPathObj; AddOptions addOpts = new AddOptions(); addOpts.setUpdateAction(UpdateActionEnum.replace); String pathOfPackage = getPackagePath(aPackage); if (pathOfPackage != null) { path.set_value(pathOfPackage); } try { BaseClass[] drillResult = myConn.getCMService().add(path, bcDrill, addOpts); DrillPath rs = (DrillPath) drillResult[0]; addResult = (rs.getStoreID().getValue()).get_value(); } catch (RemoteException ex) { System.out .println("Failed to add a Drill-through definition in the content store." + "\n" + "The error: " + ex.getMessage()); return null; } return addResult; } }