ViewReports.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. * ViewReports.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 display all the
  15. * reports and queries in the content store using the
  16. * following methods:
  17. * - query (search, properties, sortBy, options)
  18. * Use this method to request objects from the content store.
  19. */
  20. import com.cognos.developer.schemas.bibus._3.BaseClass;
  21. import com.cognos.developer.schemas.bibus._3.OrderEnum;
  22. import com.cognos.developer.schemas.bibus._3.PropEnum;
  23. import com.cognos.developer.schemas.bibus._3.QueryOptions;
  24. import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
  25. import com.cognos.developer.schemas.bibus._3.Sort;
  26. public class ViewReports
  27. {
  28. /**
  29. * Use this method to show the reports and queries in the content store.
  30. *
  31. * @param connection Connection to Server
  32. *
  33. * @return Returns a string that either shows the name of each report
  34. * or query in the content store, or displays a message to
  35. * indicate that there are no reports or queries to show.
  36. */
  37. public String viewReportsAndQueries(CRNConnect connection)
  38. {
  39. String output = new String();
  40. PropEnum props[] =
  41. new PropEnum[] { PropEnum.searchPath, PropEnum.defaultName };
  42. if (connection.getCMService() != null)
  43. {
  44. Sort sortOptions[] = { new Sort()};
  45. sortOptions[0].setOrder(OrderEnum.ascending);
  46. sortOptions[0].setPropName(PropEnum.defaultName);
  47. try
  48. {
  49. /**
  50. * Use this method to query the reports in the content store.
  51. *
  52. * @param "/content//report"
  53. * Specifies the search path string so that Content Manager
  54. * can locate the requested objects, which are reports in
  55. * this example.
  56. * @param props
  57. * Specifies alternate properties that you want returned for
  58. * the report object.
  59. * When no properties are specified, as in this example, the
  60. * default properties of searchPath and defaultName are
  61. * provided.
  62. * @param sortOptions
  63. * Specifies the sort criteria in an array.
  64. * @param QueryOptions
  65. * Specifies any options for this ReportNet method.
  66. *
  67. * @return Returns an array of reports.
  68. */
  69. BaseClass bc[] =
  70. connection.getCMService().query(
  71. new SearchPathMultipleObject("/content//report"),
  72. props,
  73. sortOptions,
  74. new QueryOptions());
  75. // If reports exist in the content store, the output shows the report
  76. // name on one line, followed by a second line that shows the search
  77. // path of the report.
  78. if (bc != null)
  79. {
  80. if (bc.length > 0)
  81. {
  82. output = output.concat("Reports:\n\n");
  83. for (int i = 0; i < bc.length; i++)
  84. {
  85. output =
  86. output.concat(
  87. " "
  88. + bc[i].getDefaultName().getValue()
  89. + "\n");
  90. output =
  91. output.concat(
  92. " "
  93. + bc[i].getSearchPath().getValue()
  94. + "\n\n");
  95. }
  96. }
  97. else
  98. {
  99. output =
  100. output.concat(
  101. "There are currently no reports to view.\n");
  102. }
  103. }
  104. else
  105. {
  106. output =
  107. output.concat(
  108. "Error occurred in viewReportsAndQueries().");
  109. }
  110. }
  111. catch (Exception e)
  112. {
  113. System.out.println(e.getMessage());
  114. output =
  115. output.concat(
  116. "View Reports:\nCannot connect to CM.\n"
  117. + "Ensure that IBM Cognos is running");
  118. }
  119. try
  120. {
  121. /**
  122. * Use this ReportNet method to query the query objects in the content
  123. * store. Query objects are created when users save reports that they
  124. * create using Query Studio.
  125. *
  126. * @param "/content//query"
  127. * Specifies the search path string so that Content Manager
  128. * can locate the requested objects, which are queries in
  129. * this example.
  130. * @param props
  131. * Specifies alternate properties that you want returned for
  132. * the query object.
  133. * When no properties are specified, as in this example,
  134. * the default properties of searchPath and defaultName are
  135. * provided.
  136. * @param sortOptions
  137. * Specifies the sort criteria in an array.
  138. * @param QueryOptions
  139. * Specifies any options for this ReportNet method.
  140. *
  141. * @return Returns an array of queries.
  142. */
  143. BaseClass bc[] =
  144. connection.getCMService().query(
  145. new SearchPathMultipleObject("/content//query"),
  146. props,
  147. sortOptions,
  148. new QueryOptions());
  149. // If queries exist in the content store, the output shows the query
  150. // name on one line, followed by a second line that shows the search
  151. // path of the query.
  152. if (bc != null)
  153. {
  154. if (bc.length > 0)
  155. {
  156. output = output.concat("\n\nQueries:\n\n");
  157. for (int i = 0; i < bc.length; i++)
  158. {
  159. output =
  160. output.concat(
  161. " "
  162. + bc[i].getDefaultName().getValue()
  163. + "\n");
  164. output =
  165. output.concat(
  166. " "
  167. + bc[i].getSearchPath().getValue()
  168. + "\n\n");
  169. }
  170. }
  171. else
  172. {
  173. output =
  174. output.concat("There are no queries to view.\n\n");
  175. }
  176. }
  177. else
  178. {
  179. output =
  180. output.concat(
  181. "Error occurred in viewReportsAndQueries().\n");
  182. }
  183. }
  184. catch (Exception e)
  185. {
  186. System.out.println(e.getMessage());
  187. output =
  188. output.concat(
  189. "View Reports:\nCannot connect to CM.\n"
  190. + "Ensure that IBM Cognos is running\n");
  191. }
  192. }
  193. else
  194. {
  195. output =
  196. output.concat(
  197. "Invalid parameter passed to viewReportsAndQueries().\n");
  198. }
  199. return output;
  200. }
  201. }