Cancel.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. * Cancel.java
  10. *
  11. *
  12. * Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  13. * Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  14. *
  15. * Description: This code sample demonstrates how to run different types of reports using the following
  16. * methods:
  17. * - run
  18. * Use this method to run a report, query, or report view.
  19. * - cancel
  20. * Use this method to cancel a Content Manager request
  21. * - getOutput
  22. * Use this method to request that the output be sent to the issuer
  23. * of the request.
  24. * - query
  25. * Use this method to request objects from Content Manager.
  26. * - wait
  27. * Use this method to notify the server that the issuer of the request is still
  28. * waiting for the output, and to request that the processing be continued.
  29. */
  30. import com.cognos.developer.schemas.bibus._3.AsynchOptionEnum;
  31. import com.cognos.developer.schemas.bibus._3.AsynchOptionInt;
  32. import com.cognos.developer.schemas.bibus._3.AsynchReply;
  33. import com.cognos.developer.schemas.bibus._3.AsynchReplyStatusEnum;
  34. import com.cognos.developer.schemas.bibus._3.BaseParameter;
  35. import com.cognos.developer.schemas.bibus._3.Option;
  36. import com.cognos.developer.schemas.bibus._3.ParameterValue;
  37. import com.cognos.developer.schemas.bibus._3.RunOptionBoolean;
  38. import com.cognos.developer.schemas.bibus._3.RunOptionEnum;
  39. import com.cognos.developer.schemas.bibus._3.RunOptionStringArray;
  40. import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
  41. public class Cancel
  42. {
  43. /**
  44. * runAndCancelReport will execute a report or query in the content store
  45. * and then cancel the request
  46. *
  47. * @param connect
  48. * Specifies the Connection to Server.
  49. * @param report
  50. * Specifies the report or query.
  51. * @return
  52. * Returns the text message indicating whether the report or query ran successfully.
  53. */
  54. public String runAndCancelReport(
  55. CRNConnect connect,
  56. BaseClassWrapper report)
  57. {
  58. String output = new String();
  59. if ((connect != null)
  60. && (report != null)
  61. && (connect.getDefaultSavePath() != null))
  62. {
  63. ParameterValue reportParameters[] = new ParameterValue[] {};
  64. ReportParameters repParms = new ReportParameters();
  65. BaseParameter[] prm = null;
  66. try
  67. {
  68. prm = repParms.getReportParameters(report, connect);
  69. }
  70. catch (java.rmi.RemoteException remoteEx)
  71. {
  72. System.out.println("Caught Remote Exception:\n");
  73. remoteEx.printStackTrace();
  74. }
  75. if (prm != null && prm.length > 0)
  76. {
  77. reportParameters = ReportParameters.setReportParameters(prm);
  78. }
  79. if ((reportParameters == null) || (reportParameters.length <= 0))
  80. {
  81. reportParameters = new ParameterValue[] {};
  82. }
  83. output += execAndCancel(report, connect, reportParameters);
  84. }
  85. else
  86. {
  87. output += "Invalid parameter(s) passed to runReport."
  88. + System.getProperty("line.separator");
  89. }
  90. return output;
  91. }
  92. /**
  93. * This Java method executes and then cancels the specified report and returns a String
  94. * indicating whether the request was cancelled successfully.
  95. * @param report
  96. * Specifies the report.
  97. * @param connect
  98. * Specifies the Connection to Server.
  99. * @param pv
  100. * Specifies the parameter values, if any, to use for the report
  101. * @return
  102. * Returns the text message indicating whether the report ran successfully.
  103. */
  104. public String execAndCancel(
  105. BaseClassWrapper report,
  106. CRNConnect connect,
  107. ParameterValue pv[])
  108. {
  109. Option execReportRunOptions[] = new Option[5];
  110. RunOptionBoolean saveOutputRunOption = new RunOptionBoolean();
  111. RunOptionStringArray outputFormat = new RunOptionStringArray();
  112. RunOptionBoolean promptFlag = new RunOptionBoolean();
  113. AsynchOptionInt primaryWaitThreshold = new AsynchOptionInt();
  114. AsynchOptionInt secondaryWaitThreshold = new AsynchOptionInt();
  115. AsynchReply rsr = null;
  116. // We do not want to save this output
  117. saveOutputRunOption.setName(RunOptionEnum.saveOutput);
  118. saveOutputRunOption.setValue(false);
  119. //Output format is not important, but we have to pick one
  120. String[] reportFormat = new String[] { "HTML" };
  121. outputFormat.setName(RunOptionEnum.outputFormat);
  122. outputFormat.setValue(reportFormat);
  123. //Set the report not to prompt, as we pass the parameter if any
  124. promptFlag.setName(RunOptionEnum.prompt);
  125. promptFlag.setValue(false);
  126. //To ensure the wait loop, set the wait thresholds unreasonably short
  127. primaryWaitThreshold.setName(AsynchOptionEnum.primaryWaitThreshold);
  128. primaryWaitThreshold.setValue(1);
  129. secondaryWaitThreshold.setName(AsynchOptionEnum.secondaryWaitThreshold);
  130. secondaryWaitThreshold.setValue(1);
  131. // Fill the array with the run options.
  132. execReportRunOptions[0] = saveOutputRunOption;
  133. execReportRunOptions[1] = outputFormat;
  134. execReportRunOptions[2] = promptFlag;
  135. execReportRunOptions[3] = primaryWaitThreshold;
  136. execReportRunOptions[4] = secondaryWaitThreshold;
  137. SearchPathSingleObject reportSearchPath = new SearchPathSingleObject();
  138. reportSearchPath.set_value(
  139. report.getBaseClassObject().getSearchPath().getValue());
  140. try
  141. {
  142. rsr =
  143. connect.getReportService().run(
  144. reportSearchPath,
  145. pv,
  146. execReportRunOptions);
  147. // cancel() is only available when status is working or stillWorking
  148. if (!rsr.getStatus().equals(AsynchReplyStatusEnum.complete))
  149. {
  150. //We should be able to call cancel but we should check before calling it
  151. if (!RunReport.hasSecondaryRequest(rsr, "cancel"))
  152. {
  153. return "The conversation didn't lead to a valid state to call cancel()";
  154. }
  155. // sn_dg_sdk_method_reportService_cancel_start_1
  156. connect.getReportService().cancel(rsr.getPrimaryRequest());
  157. // sn_dg_sdk_method_reportService_cancel_end_1
  158. return "Call to cancel() succeeded.";
  159. }
  160. System.out.println("Secondary requests at complete:");
  161. for (int i = 0; i < rsr.getSecondaryRequests().length; i++)
  162. {
  163. System.out.println(rsr.getSecondaryRequests()[i].getName());
  164. }
  165. return "The conversation didn't lead to a valid state to call cancel().";
  166. }
  167. catch (java.rmi.RemoteException remoteEx)
  168. {
  169. return ("Caught Remote Exception:\n" + remoteEx.toString());
  170. }
  171. }
  172. }