123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- /**
- 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;
- }
- }
|