DrillThrough.java 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /**
  2. Licensed Materials - Property of IBM
  3. IBM Cognos Products: DOCS
  4. (C) Copyright IBM Corp. 2005, 2008
  5. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with
  6. IBM Corp.
  7. */
  8. /**
  9. * DrillThrough.java
  10. *
  11. * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  12. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  13. */
  14. import java.rmi.RemoteException;
  15. import java.util.Enumeration;
  16. import java.util.Hashtable;
  17. import com.cognos.developer.schemas.bibus._3.Account;
  18. import com.cognos.developer.schemas.bibus._3.AddOptions;
  19. import com.cognos.developer.schemas.bibus._3.BaseClass;
  20. import com.cognos.developer.schemas.bibus._3.BaseClassArrayProp;
  21. import com.cognos.developer.schemas.bibus._3.BaseParameter;
  22. import com.cognos.developer.schemas.bibus._3.BaseParameterAssignment;
  23. import com.cognos.developer.schemas.bibus._3.BaseParameterAssignmentArrayProp;
  24. import com.cognos.developer.schemas.bibus._3.BaseReportActionEnum;
  25. import com.cognos.developer.schemas.bibus._3.BaseReportActionEnumProp;
  26. import com.cognos.developer.schemas.bibus._3.DeploymentReference;
  27. import com.cognos.developer.schemas.bibus._3.DeploymentReferenceArrayProp;
  28. import com.cognos.developer.schemas.bibus._3.DeploymentReferenceProp;
  29. import com.cognos.developer.schemas.bibus._3.DrillPath;
  30. import com.cognos.developer.schemas.bibus._3.Locale;
  31. import com.cognos.developer.schemas.bibus._3.MetadataModelItemName;
  32. import com.cognos.developer.schemas.bibus._3.MultilingualToken;
  33. import com.cognos.developer.schemas.bibus._3.Parameter;
  34. import com.cognos.developer.schemas.bibus._3.ParameterAssignmentDataItem;
  35. import com.cognos.developer.schemas.bibus._3.PropEnum;
  36. import com.cognos.developer.schemas.bibus._3.QueryOptions;
  37. import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
  38. import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
  39. import com.cognos.developer.schemas.bibus._3.Sort;
  40. import com.cognos.developer.schemas.bibus._3.StringProp;
  41. import com.cognos.developer.schemas.bibus._3.TokenProp;
  42. import com.cognos.developer.schemas.bibus._3.UpdateActionEnum;
  43. public class DrillThrough {
  44. // default constructor
  45. public DrillThrough() {
  46. super();
  47. }
  48. // Use to create a Drill-through definition
  49. public String createDrillThroughDefinition(CRNConnect myConnect,
  50. String dtDefinition, BaseClassWrapper packageName,
  51. BaseClassWrapper reportName, Hashtable reportList) {
  52. String result = null;
  53. DrillPath myDrillPath = null;
  54. // get current account information
  55. Account myAccount = this.getCurrentAccountInfo(myConnect);
  56. myDrillPath = new DrillPath();
  57. // set drill through name and description
  58. myDrillPath = this.setDrillThroughNameDesc(dtDefinition, myDrillPath);
  59. // set drill through contact
  60. myDrillPath = this.setDrillThroughContact(myAccount, myDrillPath);
  61. // set the drill through action
  62. myDrillPath = this.setDrillThroughAction(myDrillPath);
  63. // set the drill through target
  64. myDrillPath = this.setDrillThroughTarget(reportName, myDrillPath);
  65. // set the drill through parameter values
  66. myDrillPath = this.setDrillThroughParameters(reportName, reportList,
  67. myDrillPath);
  68. result = this.addDrillThroughDefinition(myConnect, myDrillPath,
  69. packageName);
  70. return result;
  71. }
  72. /**
  73. * Retrieve the report parameters from a Hashtable
  74. *
  75. * @param oneReport:
  76. * given report
  77. * @param myHash:
  78. * one Hashtable
  79. * @return: one Hashtable contains report name and its parameters
  80. */
  81. public Hashtable getReportParameters(BaseClassWrapper oneReport,
  82. Hashtable myHash) {
  83. Hashtable paraList = new Hashtable();
  84. BaseParameter[] myPara = null;
  85. myPara = (BaseParameter[]) myHash.get(oneReport);
  86. if (myPara != null) {
  87. for (int i = 0; i < myPara.length; i++) {
  88. String paraName = ((Parameter) myPara[i]).getName();
  89. String modelFilterItemStr = ((Parameter) myPara[i])
  90. .getModelFilterItem();
  91. paraList.put(paraName, modelFilterItemStr);
  92. }
  93. }
  94. return paraList;
  95. }
  96. // Get package search path
  97. public String getPackagePath(BaseClassWrapper aPackage) {
  98. String packagePath = null;
  99. if (aPackage != null) {
  100. packagePath = aPackage.getBaseClassObject().getSearchPath()
  101. .getValue();
  102. }
  103. return packagePath;
  104. }
  105. // Get current account information to assign to Drill-through definition
  106. public Account getCurrentAccountInfo(CRNConnect myConn) {
  107. BaseClass[] bcAccountInfo = null;
  108. Account currentAccount = null;
  109. PropEnum propEnum[] = new PropEnum[] { PropEnum.searchPath,
  110. PropEnum.defaultName };
  111. SearchPathMultipleObject searchPathObject = new SearchPathMultipleObject("~");
  112. try {
  113. bcAccountInfo = myConn.getCMService().query(searchPathObject,
  114. propEnum, new Sort[] {}, new QueryOptions());
  115. if (bcAccountInfo != null) {
  116. currentAccount = (Account) bcAccountInfo[0];
  117. }
  118. } catch (RemoteException ex) {
  119. System.out.println("Failed to get current account information."
  120. + "\n" + "The error: " + ex.getMessage());
  121. }
  122. return currentAccount;
  123. }
  124. // use to set drill through name and description
  125. public DrillPath setDrillThroughNameDesc(String aDefinition,
  126. DrillPath drillPathObj) {
  127. TokenProp myDrillName = new TokenProp();
  128. StringProp myDrillDesc = new StringProp();
  129. // set drill name and description
  130. myDrillName.setValue(aDefinition);
  131. myDrillDesc
  132. .setValue("This is an example of how to create a Drill-through definition in the SDK.");
  133. drillPathObj.setDefaultName(myDrillName);
  134. drillPathObj.setDefaultDescription(myDrillDesc);
  135. return drillPathObj;
  136. }
  137. // use to set drill through contact
  138. public DrillPath setDrillThroughContact(Account accountInfo,
  139. DrillPath drillPathObj) {
  140. BaseClass[] userInfo = new BaseClass[1];
  141. BaseClassArrayProp contact = new BaseClassArrayProp();
  142. userInfo[0] = accountInfo;
  143. contact.setValue(userInfo);
  144. drillPathObj.setContact(contact);
  145. return drillPathObj;
  146. }
  147. // use to set drill through action
  148. public DrillPath setDrillThroughAction(DrillPath drillPathObj) {
  149. BaseReportActionEnumProp drillRptAction = new BaseReportActionEnumProp();
  150. drillRptAction.setValue(BaseReportActionEnum.run);
  151. drillPathObj.setAction(drillRptAction);
  152. return drillPathObj;
  153. }
  154. // use to set drill through target
  155. public DrillPath setDrillThroughTarget(BaseClassWrapper targetReport,
  156. DrillPath drillPathObj) {
  157. DeploymentReferenceArrayProp drArrPropTarget = new DeploymentReferenceArrayProp();
  158. BaseClass[] bcArrTarget = new BaseClass[1];
  159. bcArrTarget[0] = targetReport.getBaseClassObject();
  160. DeploymentReference[] dArrTarget = new DeploymentReference[1];
  161. DeploymentReference drTarget = new DeploymentReference();
  162. MultilingualToken[] targetNames = new MultilingualToken[1];
  163. targetNames[0] = new MultilingualToken();
  164. targetNames[0].setValue("targets");
  165. targetNames[0].setLocale("en");
  166. drTarget.setObjects(bcArrTarget);
  167. drTarget.setName(targetNames);
  168. dArrTarget[0] = drTarget;
  169. drArrPropTarget.setValue(dArrTarget);
  170. drillPathObj.setDeploymentReferences(drArrPropTarget);
  171. return drillPathObj;
  172. }
  173. // use to set drill through parameters
  174. public DrillPath setDrillThroughParameters(BaseClassWrapper targetReport,
  175. Hashtable reportAndPara, DrillPath drillPathObj) {
  176. Hashtable listOfPara = new Hashtable();
  177. listOfPara = this.getReportParameters(targetReport, reportAndPara);
  178. int numOfPara = listOfPara.size();
  179. int myCount = 0;
  180. BaseParameterAssignmentArrayProp parameters = new BaseParameterAssignmentArrayProp();
  181. BaseParameterAssignment[] prmAssignArr = new BaseParameterAssignment[numOfPara];
  182. ParameterAssignmentDataItem myParaDataItem = null;
  183. MetadataModelItemName myMetaModelItemName = null;
  184. Enumeration keyEnum = listOfPara.keys(); // get all reports
  185. while (keyEnum.hasMoreElements()) {
  186. String myNameOfPara = (String) keyEnum.nextElement();
  187. String myModelFilterItemStr = (String) listOfPara.get(myNameOfPara);
  188. myMetaModelItemName = new MetadataModelItemName(myModelFilterItemStr);
  189. myParaDataItem = new ParameterAssignmentDataItem();
  190. myParaDataItem.setParameterName(myNameOfPara);
  191. myParaDataItem.setDataItemName(myMetaModelItemName);
  192. prmAssignArr[myCount] = myParaDataItem;
  193. myCount++;
  194. }
  195. parameters.setValue(prmAssignArr);
  196. drillPathObj.setParameterAssignments(parameters);
  197. return drillPathObj;
  198. }
  199. // add a Drill-through definition
  200. public String addDrillThroughDefinition(CRNConnect myConn,
  201. DrillPath drillPathObj, BaseClassWrapper aPackage) {
  202. String addResult;
  203. SearchPathSingleObject path = null;
  204. path = new SearchPathSingleObject();
  205. BaseClass[] bcDrill = new BaseClass[1];
  206. bcDrill[0] = drillPathObj;
  207. AddOptions addOpts = new AddOptions();
  208. addOpts.setUpdateAction(UpdateActionEnum.replace);
  209. String pathOfPackage = getPackagePath(aPackage);
  210. if (pathOfPackage != null) {
  211. path.set_value(pathOfPackage);
  212. }
  213. try {
  214. BaseClass[] drillResult = myConn.getCMService().add(path, bcDrill,
  215. addOpts);
  216. DrillPath rs = (DrillPath) drillResult[0];
  217. addResult = (rs.getStoreID().getValue()).get_value();
  218. } catch (RemoteException ex) {
  219. System.out
  220. .println("Failed to add a Drill-through definition in the content store."
  221. + "\n" + "The error: " + ex.getMessage());
  222. return null;
  223. }
  224. return addResult;
  225. }
  226. }