CreateDrillThroughTarget.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. // * CreateDrillThroughTarget.sln
  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. // * Description: Creates a target definition for drill through.
  15. using System;
  16. using System.IO;
  17. using System.Windows.Forms;
  18. using System.Web;
  19. using System.Xml;
  20. using SamplesCommon;
  21. using cognosdotnet_10_2;
  22. namespace CreateDrillThroughTarget
  23. {
  24. /// <summary>
  25. /// Summary description for Class1.
  26. /// </summary>
  27. class CreateDrillThroughTarget
  28. {
  29. /// <summary>
  30. /// The main entry point for the application.
  31. /// </summary>
  32. ///
  33. public CreateDrillThroughTarget() { }
  34. [STAThread]
  35. static void Main(string[] args)
  36. {
  37. string cBIUrl = "";
  38. contentManagerService1 cBICMS = null;
  39. SamplesConnect connectDlg = new SamplesConnect();
  40. CreateDrillThroughTargetDlg createDrillThroughTargetDlgObject = new CreateDrillThroughTargetDlg();
  41. if (args.GetLength(0) == 0)
  42. {
  43. // GUI mode
  44. connectDlg.ShowDialog();
  45. if (connectDlg.IsConnectedToCBI() == true)
  46. {
  47. cBICMS = connectDlg.CBICMS;
  48. cBIUrl = connectDlg.CBIURL;
  49. createDrillThroughTargetDlgObject.setConnection(connectDlg, cBIUrl);
  50. createDrillThroughTargetDlgObject.setPackageList(BaseClassWrapper.getPackageNameList(cBICMS));
  51. createDrillThroughTargetDlgObject.ShowDialog();
  52. }
  53. }
  54. }
  55. public string createDrillThrough(SamplesConnect cBIConnection, BaseClassWrapper report, string packageName)
  56. {
  57. if (cBIConnection == null)
  58. {
  59. return null;
  60. }
  61. baseParameter[] reportPrompts = getPrompts(cBIConnection, report);
  62. drillPath drillThroughDef = new drillPath();
  63. //Get a name from the user and set it
  64. SamplesInput getDrillThroughName = new SamplesInput();
  65. string dtName = getDrillThroughName.getInput("Drill Through Name", "Enter a name for the Drill Through Definition", "IBM Cognos Software Development Kit Drill Through Sample");
  66. drillThroughDef = setDrillThroughName(dtName, drillThroughDef);
  67. // set a description
  68. drillThroughDef = setDrillThroughDescription(drillThroughDef);
  69. // set drill through contact to the current user
  70. account myAccount = SamplesConnect.getLogonAccount(cBIConnection);
  71. drillThroughDef = setDrillThroughContact(myAccount, drillThroughDef);
  72. // set the drill through action
  73. drillThroughDef = setDrillThroughAction(drillThroughDef);
  74. // set the drill through target
  75. drillThroughDef = setDrillThroughTarget(report, drillThroughDef);
  76. // set the drill through parameter values
  77. drillThroughDef = setDrillThroughParameters(cBIConnection, report, drillThroughDef);
  78. return addDrillThroughDefinition(cBIConnection, drillThroughDef, packageName);
  79. }
  80. public BaseClassWrapper[] getPromptedReports(SamplesConnect cBIConnection, String packageName)
  81. {
  82. baseClass[] reports = new baseClass[0];
  83. propEnum[] props =
  84. new propEnum[] { propEnum.searchPath, propEnum.defaultName, propEnum.objectClass, propEnum.parent };
  85. sort[] sortOptions = { new sort() };
  86. sortOptions[0].order = orderEnum.ascending;
  87. sortOptions[0].propName = propEnum.defaultName;
  88. searchPathMultipleObject reportsPath = new searchPathMultipleObject();
  89. reportsPath.Value = "/content/folder[@name='Samples']/folder[@name='Models']/package[@name='" + packageName + "']//report";
  90. reports =
  91. cBIConnection.CBICMS.query(
  92. reportsPath,
  93. props,
  94. sortOptions,
  95. new queryOptions());
  96. BaseClassWrapper[] reportList = new BaseClassWrapper[reports.GetLength(0)];
  97. int nbReports = 0;
  98. int count = 0;
  99. if ((reports != null) && (reports.GetLength(0) > 0))
  100. {
  101. nbReports = reports.GetLength(0);
  102. for (int i = 0; i < nbReports; i++)
  103. {
  104. BaseClassWrapper report = new BaseClassWrapper(reports[i]);
  105. if (hasPrompts(cBIConnection, report))
  106. {
  107. reportList[count++] = report;
  108. }
  109. }
  110. }
  111. BaseClassWrapper[] promptedReportList = new BaseClassWrapper[count];
  112. for (int i = 0; i < count; i++)
  113. promptedReportList[i] = reportList[i];
  114. return promptedReportList;
  115. }
  116. public bool hasPrompts(SamplesConnect cBIConnection, BaseClassWrapper report)
  117. {
  118. searchPathSingleObject reportPath = new searchPathSingleObject();
  119. reportPath.Value = report.searchPath.value;
  120. asynchReply getParamsReply = cBIConnection.CBIRS.getParameters(reportPath, new parameterValue[] { }, new option[] { });
  121. if (!getParamsReply.status.Equals(asynchReplyStatusEnum.conversationComplete))
  122. {
  123. while (!getParamsReply.status.Equals(asynchReplyStatusEnum.conversationComplete))
  124. {
  125. getParamsReply = cBIConnection.CBIRS.wait(
  126. getParamsReply.primaryRequest,
  127. new parameterValue[] { },
  128. new option[] { });
  129. }
  130. }
  131. for (int i = 0; i < getParamsReply.details.Length; i++)
  132. {
  133. if (getParamsReply.details[i] is asynchDetailParameters)
  134. {
  135. return (((asynchDetailParameters)getParamsReply.details[i]).parameters.Length > 0);
  136. }
  137. }
  138. return false;
  139. }
  140. public baseParameter[] getPrompts(SamplesConnect cBIConnection, BaseClassWrapper report)
  141. {
  142. searchPathSingleObject reportPath = new searchPathSingleObject();
  143. reportPath.Value = report.searchPath.value;
  144. asynchReply getParamsReply = cBIConnection.CBIRS.getParameters(reportPath, new parameterValue[] { }, new option[] { });
  145. if (!getParamsReply.status.Equals(asynchReplyStatusEnum.conversationComplete))
  146. {
  147. while (!getParamsReply.status.Equals(asynchReplyStatusEnum.conversationComplete))
  148. {
  149. getParamsReply = cBIConnection.CBIRS.wait(
  150. getParamsReply.primaryRequest,
  151. new parameterValue[] { },
  152. new option[] { });
  153. }
  154. }
  155. for (int i = 0; i < getParamsReply.details.Length; i++)
  156. {
  157. if (getParamsReply.details[i] is asynchDetailParameters)
  158. {
  159. return ((asynchDetailParameters)getParamsReply.details[i]).parameters;
  160. }
  161. }
  162. return null;
  163. }
  164. public BaseClassWrapper getPackage(SamplesConnect cBIConnection, string packageName)
  165. {
  166. searchPathMultipleObject packagesPath = new searchPathMultipleObject();
  167. packagesPath.Value = "/content//package[@name='" + packageName + "']";
  168. baseClass[] bc = cBIConnection.CBICMS.query(packagesPath, new propEnum[] {}, new sort[] {}, new queryOptions());
  169. string[] packageNames = new string[bc.GetLength(0)];
  170. if (bc.Length == 1)
  171. {
  172. return new BaseClassWrapper(bc[0]);
  173. }
  174. return null;
  175. }
  176. public bool hasSecondaryRequest(asynchReply response, string secondaryRequest)
  177. {
  178. asynchSecondaryRequest[] secondaryRequests =
  179. response.secondaryRequests;
  180. for (int i = 0; i < secondaryRequests.Length; i++)
  181. {
  182. if (secondaryRequests[i].name.CompareTo(secondaryRequest)
  183. == 0)
  184. {
  185. return true;
  186. }
  187. }
  188. return false;
  189. }
  190. // set a name
  191. public drillPath setDrillThroughName(string dtName, drillPath drillThroughDef)
  192. {
  193. tokenProp myDrillName = new tokenProp();
  194. myDrillName.value = dtName;
  195. drillThroughDef.defaultName = myDrillName;
  196. return drillThroughDef;
  197. }
  198. // set a description
  199. public drillPath setDrillThroughDescription(drillPath drillThroughDef)
  200. {
  201. stringProp myDrillDesc = new stringProp();
  202. myDrillDesc.value = "This is an example of how to create a Drill-through definition using the SDK.";
  203. drillThroughDef.defaultDescription = myDrillDesc;
  204. return drillThroughDef;
  205. }
  206. // set a contact
  207. public drillPath setDrillThroughContact(account myAccount, drillPath drillThroughDef)
  208. {
  209. baseClass[] contactData = new baseClass[] {myAccount};
  210. baseClassArrayProp contact = new baseClassArrayProp();
  211. contact.value = contactData;
  212. drillThroughDef.contact = contact;
  213. return drillThroughDef;
  214. }
  215. // set an action
  216. public drillPath setDrillThroughAction(drillPath drillThroughDef)
  217. {
  218. baseReportActionEnumProp drillAction = new baseReportActionEnumProp();
  219. drillAction.value = baseReportActionEnum.run;
  220. drillThroughDef.action = drillAction;
  221. return drillThroughDef;
  222. }
  223. // set a target
  224. public drillPath setDrillThroughTarget(BaseClassWrapper targetReport, drillPath drillThroughDef)
  225. {
  226. baseClassArrayProp targetProp = new baseClassArrayProp();
  227. baseClass[] targets = new baseClass[] {targetReport.baseclassobject};
  228. targetProp.value = targets;
  229. drillThroughDef.target = targetProp;
  230. return drillThroughDef;
  231. }
  232. // set parameters
  233. public drillPath setDrillThroughParameters(SamplesConnect cBIConnection, BaseClassWrapper report, drillPath drillThroughDef)
  234. {
  235. //get the parameters for the target report
  236. baseParameter[] parameters = getPrompts(cBIConnection, report);
  237. baseParameterAssignment[] paramAssignments = new baseParameterAssignment[parameters.Length];
  238. //loop through and set parameter info
  239. parameterAssignmentDataItem paramAssignmentItem;
  240. metadataModelItemName paramDataItemName;
  241. for (int i = 0; i < parameters.Length; i++)
  242. {
  243. paramAssignmentItem = new parameterAssignmentDataItem();
  244. string parameterName = ( (parameter) parameters[i]).name;
  245. paramAssignmentItem.parameterName = parameterName;
  246. paramDataItemName = new metadataModelItemName();
  247. string itemNameStr = ( (parameter) parameters[i]).modelFilterItem;
  248. paramDataItemName.Value = itemNameStr;
  249. paramAssignmentItem.dataItemName = paramDataItemName;
  250. paramAssignments[i] = paramAssignmentItem;
  251. }
  252. //add the parameter info to the drillThroughDef
  253. baseParameterAssignmentArrayProp parameterAssignmentsProp = new baseParameterAssignmentArrayProp();
  254. parameterAssignmentsProp.value = paramAssignments;
  255. drillThroughDef.parameterAssignments = parameterAssignmentsProp;
  256. return drillThroughDef;
  257. }
  258. public string addDrillThroughDefinition(SamplesConnect cBIConnection, drillPath drillThroughDef, string packageName)
  259. {
  260. string addResult;
  261. searchPathSingleObject parentPath = new searchPathSingleObject();
  262. baseClass[] bcDrill = new baseClass[1];
  263. bcDrill[0] = drillThroughDef;
  264. addOptions addOpts = new addOptions();
  265. addOpts.updateAction = updateActionEnum.replace;
  266. string packagePathStr = getPackage(cBIConnection, packageName).baseclassobject.searchPath.value;
  267. if (packagePathStr != null)
  268. {
  269. parentPath.Value = packagePathStr;
  270. }
  271. baseClass[] drillResult = cBIConnection.CBICMS.add(parentPath, bcDrill, addOpts);
  272. drillPath response = (drillPath) drillResult[0];
  273. addResult = "Added Drill Through Definition with search path: " + response.searchPath.value;
  274. return addResult;
  275. }
  276. }
  277. }