ReportParameters.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * ReportParameters.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. * Description: This code sample demonstrates how to run and print a report with
  15. * prompts using the getParameters method.
  16. * Use this method to return the list of parameters used by the
  17. * report, including optional parameters. This method also returns
  18. * parameters from the model and stored procedures that are used
  19. * by the report.
  20. */
  21. import javax.swing.JOptionPane;
  22. import com.cognos.developer.schemas.bibus._3.AsynchDetailParameters;
  23. import com.cognos.developer.schemas.bibus._3.AsynchReply;
  24. import com.cognos.developer.schemas.bibus._3.AsynchReplyStatusEnum;
  25. import com.cognos.developer.schemas.bibus._3.BaseParameter;
  26. import com.cognos.developer.schemas.bibus._3.Option;
  27. import com.cognos.developer.schemas.bibus._3.Parameter;
  28. import com.cognos.developer.schemas.bibus._3.ParameterValue;
  29. import com.cognos.developer.schemas.bibus._3.ParmValueItem;
  30. import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
  31. import com.cognos.developer.schemas.bibus._3.SimpleParmValueItem;
  32. public class ReportParameters
  33. {
  34. /**
  35. *
  36. * This method calls the getParameters method to
  37. * to return the list of parameters used by the report.
  38. *
  39. * @param connection
  40. * Specifies the object that provides the Connection to the Server.
  41. * @param reportPath
  42. * Specifies the search path of the report.
  43. * @return
  44. * Returns an array of report parameters.
  45. */
  46. public BaseParameter[] getReportParameters(
  47. BaseClassWrapper report,
  48. CRNConnect connection)
  49. throws java.rmi.RemoteException
  50. {
  51. BaseParameter params[] = new Parameter[] {};
  52. AsynchReply response;
  53. String reportPathString = report.getBaseClassObject().getSearchPath().getValue();
  54. SearchPathSingleObject reportPath = new SearchPathSingleObject();
  55. reportPath.set_value(reportPathString);
  56. // sn_dg_sdk_method_reportService_getParameters_start_1
  57. response = connection.getReportService().getParameters(reportPath, new ParameterValue[] {}, new Option[] {} );
  58. // sn_dg_sdk_method_reportService_getParameters_end_1
  59. // If response is not immediately complete, call wait until complete
  60. if (!response.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  61. {
  62. while (!response.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  63. {
  64. response = connection.getReportService().wait(
  65. response.getPrimaryRequest(),
  66. new ParameterValue[] {},
  67. new Option[] {});
  68. }
  69. }
  70. // sn_dg_sdk_method_reportService_getParameters_start_2
  71. for (int i = 0; i < response.getDetails().length; i++)
  72. {
  73. if (response.getDetails()[i] instanceof AsynchDetailParameters)
  74. {
  75. params = ((AsynchDetailParameters)response.getDetails()[i]).getParameters();
  76. }
  77. }
  78. // sn_dg_sdk_method_reportService_getParameters_end_2
  79. return params;
  80. }
  81. /**
  82. * This Java method assigns values to each parameter for the specified report.
  83. *
  84. * @param reportName
  85. * Specifies the name of the report.
  86. * @param prm
  87. * Specifies an array of parameters.
  88. * @return params
  89. * Returns an array of parameter values.
  90. */
  91. // sn_dg_prm_smpl_runreport_P2_start_0
  92. public static ParameterValue[] setReportParameters(BaseParameter[] prm)
  93. {
  94. try
  95. {
  96. int numberOfParameters = 0;
  97. // Select the parameter values for the specified report.
  98. if (prm.length > 0)
  99. {
  100. numberOfParameters = prm.length;
  101. ParameterValue[] params =
  102. new ParameterValue[numberOfParameters];
  103. // Repeat for each parameter.
  104. for (int i = 0; i < prm.length; i++)
  105. {
  106. // Prompt the user to type a value for the parameter.
  107. // If the value is DateTime, the format must be in the ISO 8601
  108. // format. For example, a date and time of 2001-05-31T14:39:25.035Z
  109. // represents the thirty-first day of May in the year 2001. The time,
  110. // measured in Coordinated Universal Time (UTC) as indicated by the Z,
  111. // is 14 hours, 39 minutes, 25 seconds, and 35 milliseconds.
  112. String modelFilterItem = ((Parameter)prm[i]).getModelFilterItem();
  113. String item =
  114. modelFilterItem.substring(
  115. modelFilterItem.lastIndexOf("["),
  116. modelFilterItem.lastIndexOf("]") + 1);
  117. String inputValue =
  118. JOptionPane.showInputDialog(
  119. "Please input a value for "
  120. + item
  121. + " of datatype ["
  122. + prm[i].getType().getValue()
  123. + "]");
  124. SimpleParmValueItem item1 = new SimpleParmValueItem();
  125. item1.setUse(inputValue);
  126. // Create a new array to contains the values for the parameter.
  127. ParmValueItem pvi[] = new ParmValueItem[1];
  128. pvi[0] = item1;
  129. // Assign the values to the parameter.
  130. params[i] = new ParameterValue();
  131. params[i].setName(prm[i].getName());
  132. params[i].setValue(pvi);
  133. }
  134. return params;
  135. // sn_dg_prm_smpl_runreport_P2_end_0
  136. }
  137. else
  138. {
  139. return null;
  140. }
  141. }
  142. catch (Exception e)
  143. {
  144. System.out.println(e);
  145. return null;
  146. }
  147. }
  148. }