CMTester.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. * CMTester.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 get information about
  15. * an object using the query method.
  16. * Use this method to request objects from Content Manager.
  17. */
  18. import com.cognos.developer.schemas.bibus._3.Account;
  19. import com.cognos.developer.schemas.bibus._3.BaseClass;
  20. import com.cognos.developer.schemas.bibus._3.PropEnum;
  21. import com.cognos.developer.schemas.bibus._3.QueryOptions;
  22. import com.cognos.developer.schemas.bibus._3.SearchPathMultipleObject;
  23. import com.cognos.developer.schemas.bibus._3.Sort;
  24. public class CMTester
  25. {
  26. /**
  27. * This Java method returns a string that contains either the information
  28. * about the specified objects if the request succeeded or an error message
  29. * if the request failed.
  30. *
  31. * @param connection
  32. * Connection to Server
  33. * @return output
  34. * Returns the searchPath, defaultName, creationTime, and version
  35. * of the specified objects.
  36. */
  37. public String contentMgrTester(CRNConnect connection)
  38. {
  39. String output = new String();
  40. PropEnum props[] =
  41. new PropEnum[] {
  42. PropEnum.searchPath,
  43. PropEnum.defaultName,
  44. PropEnum.creationTime,
  45. PropEnum.version };
  46. if (connection.getCMService() == null)
  47. {
  48. System.out.println(
  49. "\n\nInvalid parameter passed to function contentMgrTester.");
  50. output =
  51. output.concat(
  52. "Invalid parameter passed to function contentMgrTester.");
  53. return output;
  54. }
  55. try
  56. {
  57. BaseClass bc[] =
  58. connection.getCMService().query(
  59. new SearchPathMultipleObject("~"),
  60. props,
  61. new Sort[] {},
  62. new QueryOptions());
  63. if (bc != null)
  64. {
  65. if (bc.length > 0)
  66. {
  67. for (int i = 0; i < bc.length; i++)
  68. {
  69. Account myAccount = (Account)bc[i];
  70. String sCD = new String();
  71. // Build up the formatted date and time
  72. String crDatTim = new String();
  73. sCD = myAccount.getCreationTime().getValue().toString();
  74. // Define the appropriate strings to look for to
  75. // return the date and time values
  76. String yrSrchStr = new String();
  77. yrSrchStr = ",YEAR=";
  78. String monSrchStr = new String();
  79. monSrchStr = ",MONTH=";
  80. String daySrchStr = new String();
  81. daySrchStr = ",DAY_OF_MONTH=";
  82. String hrSrchStr = new String();
  83. hrSrchStr = ",HOUR_OF_DAY=";
  84. String minSrchStr = new String();
  85. minSrchStr = ",MINUTE=";
  86. String secSrchStr = new String();
  87. secSrchStr = ",SECOND=";
  88. // Find the correct position in the returned
  89. // string for date and time values
  90. int yearPos = sCD.indexOf(yrSrchStr);
  91. int monthPos = sCD.indexOf(monSrchStr);
  92. int dayPos = sCD.indexOf(daySrchStr);
  93. int hourPos = sCD.indexOf(hrSrchStr);
  94. int minPos = sCD.indexOf(minSrchStr);
  95. int secPos = sCD.indexOf(secSrchStr);
  96. String chrsMonth = new String();
  97. // Build the creation date string starting
  98. // with the month
  99. String char1 =
  100. sCD.substring(monthPos + 8, monthPos + 9);
  101. if (char1.equals(","))
  102. {
  103. crDatTim =
  104. "The CreationTime is: 0"
  105. + sCD.substring(monthPos + 7, monthPos + 8)
  106. + "/";
  107. chrsMonth =
  108. sCD.substring(monthPos + 7, monthPos + 8);
  109. }
  110. else
  111. {
  112. crDatTim =
  113. "The CreationTime is: "
  114. + sCD.substring(monthPos + 7, monthPos + 9)
  115. + "/";
  116. chrsMonth =
  117. sCD.substring(monthPos + 7, monthPos + 9);
  118. }
  119. // adjust the month from the index
  120. // starting at 0 for January
  121. int intMonth;
  122. intMonth = Integer.parseInt(chrsMonth);
  123. intMonth = intMonth + 1;
  124. crDatTim =
  125. "The creation time is: "
  126. + Integer.toString(intMonth)
  127. + "/";
  128. // add the day
  129. String char2 = sCD.substring(dayPos + 15, dayPos + 16);
  130. if (char2.equals(","))
  131. {
  132. crDatTim =
  133. crDatTim
  134. + sCD.substring(dayPos + 14, dayPos + 15)
  135. + "/";
  136. }
  137. else
  138. {
  139. crDatTim =
  140. crDatTim
  141. + sCD.substring(dayPos + 14, dayPos + 16)
  142. + "/";
  143. }
  144. // add the year
  145. crDatTim =
  146. crDatTim
  147. + sCD.substring(yearPos + 6, yearPos + 10)
  148. + " ";
  149. // add the hour
  150. String char3 =
  151. sCD.substring(hourPos + 14, hourPos + 15);
  152. if (char3.equals(","))
  153. {
  154. crDatTim =
  155. crDatTim
  156. + "0"
  157. + sCD.substring(hourPos + 13, hourPos + 14)
  158. + ":";
  159. }
  160. else
  161. {
  162. crDatTim =
  163. crDatTim
  164. + sCD.substring(hourPos + 13, hourPos + 15)
  165. + ":";
  166. }
  167. // add the minute
  168. String char4 = sCD.substring(minPos + 9, minPos + 10);
  169. if (char4.equals(","))
  170. {
  171. crDatTim =
  172. crDatTim
  173. + "0"
  174. + sCD.substring(minPos + 8, minPos + 9)
  175. + ":";
  176. }
  177. else
  178. {
  179. crDatTim =
  180. crDatTim
  181. + sCD.substring(minPos + 8, minPos + 10)
  182. + ":";
  183. }
  184. // add the second
  185. String char5 = sCD.substring(secPos + 9, secPos + 10);
  186. if (char5.equals(","))
  187. {
  188. crDatTim =
  189. crDatTim
  190. + "0"
  191. + sCD.substring(secPos + 8, secPos + 9)
  192. + " \n";
  193. }
  194. else
  195. {
  196. crDatTim =
  197. crDatTim
  198. + sCD.substring(secPos + 8, secPos + 10)
  199. + " \n";
  200. }
  201. System.out.println(
  202. "The searchPath is: "
  203. + myAccount.getSearchPath().getValue());
  204. System.out.println(
  205. "\n\nThe DefaultName is: "
  206. + myAccount.getDefaultName().getValue());
  207. System.out.println(crDatTim);
  208. System.out.println(
  209. "The Version is: "
  210. + myAccount.getVersion().getValue());
  211. System.out.println(
  212. "\nContent Manager is responding and operational.");
  213. output =
  214. output.concat(
  215. "The searchPath is: "
  216. + myAccount.getSearchPath().getValue()
  217. + "\n");
  218. output =
  219. output.concat(
  220. "The DefaultName is: "
  221. + myAccount.getDefaultName().getValue()
  222. + "\n");
  223. output = output.concat(crDatTim);
  224. output =
  225. output.concat(
  226. "The Version is: "
  227. + myAccount.getVersion().getValue()
  228. + "\n\n");
  229. output =
  230. output.concat(
  231. "Content Manager is responding and operational.");
  232. }
  233. }
  234. }
  235. else
  236. {
  237. System.out.println("\n\nError occurred in contentMgrTester.");
  238. output = output.concat("Error occurred in contentMgrTester.");
  239. }
  240. }
  241. catch (java.rmi.RemoteException remoteEx)
  242. {
  243. output =
  244. output.concat(
  245. "CM Tester:"
  246. + "\nCannot connect to CM."
  247. + "\nEnsure that IBM Cognos is running.");
  248. output = output.concat("\n\n" + remoteEx.getMessage());
  249. }
  250. return output;
  251. }
  252. }