ViewPackages.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * ViewPackages.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 in the content store using the following methods:
  16. * - query (search, properties, sortBy, options)
  17. * Use this method to request objects from the content store.
  18. *
  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 ViewPackages
  27. {
  28. /**
  29. * Use this method to show the packages in the content store.
  30. *
  31. * @param connection
  32. * Connection to Server
  33. * @return Returns a string that either shows the name of each package in the content store
  34. * or displays a message to indicate that no packages have been published.
  35. */
  36. public String viewPackages(CRNConnect connection)
  37. {
  38. String output = new String();
  39. if (connection.getCMService() != null)
  40. {
  41. BaseClass bc[] = this.getPackages(connection);
  42. // If packages exist in the content store, the output shows the package name
  43. // on one line, followed by a second line that shows the search path of the package.
  44. if (bc != null)
  45. {
  46. for (int i = 0; i < bc.length; i++)
  47. {
  48. System.out.println(
  49. " " + bc[i].getDefaultName().getValue());
  50. System.out.println(
  51. " " + bc[i].getSearchPath().getValue() + "\n");
  52. output =
  53. output.concat(
  54. " " + bc[i].getDefaultName().getValue() + "\n");
  55. output =
  56. output.concat(
  57. " "
  58. + bc[i].getSearchPath().getValue()
  59. + "\n\n");
  60. }
  61. }
  62. else
  63. {
  64. output =
  65. output.concat(
  66. "There are currently no published packages to display.");
  67. System.out.println(
  68. "\n\nThere are currently no published packages to display..");
  69. }
  70. }
  71. return output;
  72. }
  73. public BaseClass[] getPackages(CRNConnect connection)
  74. {
  75. PropEnum props[] =
  76. new PropEnum[] { PropEnum.searchPath, PropEnum.defaultName };
  77. if (connection.getCMService() != null)
  78. {
  79. Sort s[] = { new Sort()};
  80. s[0].setOrder(OrderEnum.ascending);
  81. s[0].setPropName(PropEnum.defaultName);
  82. try
  83. {
  84. /**
  85. * Use this method to query the packages in the content store.
  86. *
  87. * @param "/content//package"
  88. * Specifies the search path string so that Content Manager can locate the requested
  89. * objects, which are packages in this example.
  90. * @param props
  91. * Specifies alternate properties that you want returned for the package object.
  92. * When no properties are specified, as in this example, the default properties of
  93. * searchPath and defaultName are provided.
  94. * @param s
  95. * Specifies the sort criteria in an array.
  96. * @param QueryOptions
  97. * Specifies any options for this method.
  98. * @return Returns an array of packages.
  99. */
  100. BaseClass bc[] =
  101. connection.getCMService().query(
  102. new SearchPathMultipleObject("/content//package"),
  103. props,
  104. s,
  105. new QueryOptions());
  106. if (bc != null)
  107. {
  108. if (bc.length > 0)
  109. {
  110. return bc;
  111. }
  112. }
  113. else
  114. {
  115. System.out.println(
  116. "\n\nError occurred in function viewPackages.");
  117. }
  118. }
  119. catch (Exception e)
  120. {
  121. System.out.println(e.getMessage());
  122. }
  123. }
  124. else
  125. {
  126. System.out.println(
  127. "\n\nInvalid parameter passed to function viewPackages.");
  128. }
  129. return null;
  130. }
  131. }