ViewPackagesAndReports.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. * ViewPackagesAndReports.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. * packages, reports and queries in the content store using the
  16. * following methods:
  17. * - query (searchPath, 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 ViewPackagesAndReports
  27. {
  28. /**
  29. * Use this method to show the packages, reports and queries in
  30. * the content store.
  31. *
  32. * @param connection
  33. * Specifies the object that provides the connection to
  34. * the server.
  35. *
  36. * @return Returns a string that either shows the name of each
  37. * package, report or query in the content store, or displays
  38. * a message to indicate that there are no packages, reports,
  39. * or queries to show.
  40. *
  41. */
  42. public String viewAll(CRNConnect connection)
  43. {
  44. String output = new String();
  45. PropEnum props[] =
  46. new PropEnum[] { PropEnum.searchPath, PropEnum.defaultName };
  47. if (connection.getCMService() != null)
  48. {
  49. Sort sortArray[] = { new Sort()};
  50. sortArray[0].setOrder(OrderEnum.ascending);
  51. sortArray[0].setPropName(PropEnum.defaultName);
  52. try
  53. {
  54. /**
  55. * Use this method to query the packages in
  56. * the content store.
  57. *
  58. * @param "/content//package"
  59. * Specifies the search path string so that
  60. * Content Manager can locate the requested
  61. * objects, which are packages in this example.
  62. * @param props
  63. * Specifies alternate properties that you want
  64. * returned for the package object.
  65. * When no properties are specified, as in this
  66. * example, the default properties of
  67. * searchPath and defaultName are provided.
  68. * @param sortArray
  69. * Specifies the sort criteria in an array.
  70. * @param QueryOptions
  71. * Specifies any options for this method.
  72. * @return Returns an array of packages.
  73. */
  74. String SearchPathPackages = "/content//package";
  75. BaseClass bc[] =
  76. connection.getCMService().query(
  77. new SearchPathMultipleObject(SearchPathPackages),
  78. props,
  79. sortArray,
  80. new QueryOptions());
  81. // If packages exist in the content store, the output shows the
  82. // package name on one line, followed by a second line that shows
  83. // the search path of the package. Then, list the reports in the
  84. // same output format that was used for the packages.
  85. if (bc == null)
  86. {
  87. System.out.println(
  88. "\n\nError occurred in function viewAll.");
  89. output =
  90. output.concat("Error occurred in function viewAll.");
  91. return output;
  92. }
  93. if (bc.length <= 0)
  94. {
  95. output =
  96. output.concat(
  97. "There are currently no published"
  98. + " packages or reports.");
  99. return output;
  100. }
  101. for (int i = 0; i < bc.length; i++)
  102. {
  103. output =
  104. output.concat(
  105. " " + bc[i].getDefaultName().getValue() + "\n");
  106. output =
  107. output.concat(
  108. " " + bc[i].getSearchPath().getValue() + "\n");
  109. output = output.concat("\n Reports:\n");
  110. //System.out.println(output);
  111. String quotChar = "\'";
  112. if (bc[i].getDefaultName().getValue().indexOf(quotChar)
  113. >= 0)
  114. {
  115. quotChar = "\"";
  116. }
  117. // Retrieve the list of reports for this package.
  118. String SearchPathReports = bc[i].getSearchPath().getValue()
  119. + "//report";
  120. BaseClass bcReports[] =
  121. connection.getCMService().query(
  122. new SearchPathMultipleObject(SearchPathReports),
  123. props,
  124. sortArray,
  125. new QueryOptions());
  126. if (bcReports != null && (bcReports.length > 0))
  127. {
  128. for (int j = 0; j < bcReports.length; j++)
  129. {
  130. output =
  131. output.concat(
  132. " "
  133. + bcReports[j]
  134. .getDefaultName()
  135. .getValue()
  136. + "\n");
  137. output =
  138. output.concat(
  139. " "
  140. + bcReports[j].getSearchPath().getValue()
  141. + "\n");
  142. //System.out.println(output);
  143. }
  144. }
  145. else
  146. {
  147. output =
  148. output.concat(
  149. " "
  150. + "No reports to view for this package\n");
  151. }
  152. output = output.concat("\n Queries:\n");
  153. //System.out.println(output);
  154. quotChar = "\'";
  155. if (bc[i].getDefaultName().getValue().indexOf(quotChar)
  156. >= 0)
  157. {
  158. quotChar = "\"";
  159. }
  160. // Retrieve the list of queries for this package.
  161. // List the queries in the same output format that
  162. // was used for the packages.
  163. String SearchPathQueries = bc[i].getSearchPath().getValue()
  164. + "//query";
  165. BaseClass bcQueries[] =
  166. connection.getCMService().query(
  167. new SearchPathMultipleObject(SearchPathQueries),
  168. props,
  169. sortArray,
  170. new QueryOptions());
  171. if (bcQueries != null && (bcQueries.length > 0))
  172. {
  173. for (int j = 0; j < bcQueries.length; j++)
  174. {
  175. output =
  176. output.concat(
  177. " "
  178. + bcQueries[j]
  179. .getDefaultName()
  180. .getValue()
  181. + "\n");
  182. output =
  183. output.concat(
  184. " "
  185. + bcQueries[j].getSearchPath().getValue()
  186. + "\n");
  187. //System.out.println(output);
  188. }
  189. }
  190. else
  191. {
  192. output =
  193. output.concat(
  194. " "
  195. + "No queries to view for this package\n\n");
  196. }
  197. }
  198. }
  199. catch (Exception e)
  200. {
  201. System.out.println(e.getMessage());
  202. output =
  203. output.concat(
  204. "View All:\nCannot connect to CM.\n"
  205. + "Ensure that IBM Cognos is running.");
  206. }
  207. }
  208. else
  209. {
  210. System.out.println("\n\nInvalid parameter passed to viewAll().");
  211. output = output.concat("Invalid parameter passed to viewAll().");
  212. }
  213. return output;
  214. }
  215. }