ManageAlerts.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. * ManageAlerts.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. */
  15. import com.cognos.developer.schemas.bibus._3.AgentNotificationStatusEnum;
  16. import com.cognos.developer.schemas.bibus._3.AsynchDetailAgentNotificationStatus;
  17. import com.cognos.developer.schemas.bibus._3.AsynchReply;
  18. import com.cognos.developer.schemas.bibus._3.AsynchReplyStatusEnum;
  19. import com.cognos.developer.schemas.bibus._3.AsynchRequest;
  20. import com.cognos.developer.schemas.bibus._3.AsynchSecondaryRequest;
  21. import com.cognos.developer.schemas.bibus._3.Option;
  22. import com.cognos.developer.schemas.bibus._3.ParameterValue;
  23. import com.cognos.developer.schemas.bibus._3.SearchPathSingleObject;
  24. public class ManageAlerts
  25. {
  26. /**
  27. * Add the current user to the alert list for a report.
  28. *
  29. * @param connection
  30. * Connection to Server
  31. * @param csobject
  32. * Specifies the report.
  33. */
  34. public String addNotificationForUser(CRNConnect connection, BaseClassWrapper csobject)
  35. {
  36. AsynchRequest response = null;
  37. AsynchReply asynchReply = null;
  38. String reportPath = csobject.getBaseClassObject().getSearchPath().getValue();
  39. if (csobject == null)
  40. {
  41. return "No valid report selected";
  42. }
  43. try
  44. {
  45. // sn_dg_sdk_method_deliveryService_addNotification_start_0
  46. asynchReply =
  47. connection.getDeliveryService().addNotification(new SearchPathSingleObject(reportPath));
  48. // sn_dg_sdk_method_deliveryService_addNotification_end_0
  49. // If response is not immediately complete, call wait until complete
  50. if (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  51. {
  52. while (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  53. {
  54. //before calling wait, double check that it is okay
  55. if (hasSecondaryRequest(asynchReply, "wait"))
  56. {
  57. asynchReply =
  58. connection.getReportService().wait(
  59. asynchReply.getPrimaryRequest(),
  60. new ParameterValue[] {},
  61. new Option[] {});
  62. }
  63. else
  64. {
  65. return "Error: Wait method not available as expected.";
  66. }
  67. }
  68. }
  69. return "Add notification request complete.";
  70. }
  71. catch (Exception e)
  72. {
  73. //System.out.println("An error occurred in the addNotificationForUser Java method.");
  74. //e.printStackTrace();
  75. return "An Error occurred. You may not have an email address defined, or you may already be on the alert list.";
  76. }
  77. }
  78. /**
  79. * Delete the current user from the alert list for a report.
  80. *
  81. * @param connection
  82. * Connection to Server
  83. * @param csobject
  84. * Specifies the report.
  85. */
  86. public String deleteSingleNotification(CRNConnect connection, BaseClassWrapper csobject)
  87. {
  88. AsynchRequest response = null;
  89. AsynchReply asynchReply = null;
  90. String reportPath = csobject.getBaseClassObject().getSearchPath().getValue();
  91. if (csobject == null)
  92. {
  93. return "No valid report selected";
  94. }
  95. try
  96. {
  97. // sn_dg_sdk_method_deliveryService_deleteNotification_start_0
  98. asynchReply =
  99. connection.getDeliveryService().deleteNotification(new SearchPathSingleObject(reportPath));
  100. // sn_dg_sdk_method_deliveryService_deleteNotification_end_0
  101. // If response is not immediately complete, call wait until complete
  102. if (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  103. {
  104. while (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  105. {
  106. //before calling wait, double check that it is okay
  107. if (hasSecondaryRequest(asynchReply, "wait"))
  108. {
  109. asynchReply =
  110. connection.getReportService().wait(
  111. asynchReply.getPrimaryRequest(),
  112. new ParameterValue[] {},
  113. new Option[] {});
  114. }
  115. else
  116. {
  117. return "Error: Wait method not available as expected.";
  118. }
  119. }
  120. }
  121. return "Delete notification request complete.";
  122. }
  123. catch (Exception e)
  124. {
  125. //System.out.println("An error occurred in the deleteSingleNotification Java method.");
  126. //e.printStackTrace();
  127. return "Error. You may not be on the alert list for this report.";
  128. }
  129. }
  130. /**
  131. * Delete the current user all alert lists.
  132. *
  133. * @param connection
  134. * Connection to Server
  135. */
  136. public String deleteAllNotifications(CRNConnect connection)
  137. {
  138. AsynchRequest response = null;
  139. AsynchReply asynchReply = null;
  140. try
  141. {
  142. // sn_dg_sdk_method_deliveryService_deleteAllNotifications_start_0
  143. asynchReply =
  144. connection.getDeliveryService().deleteAllNotifications();
  145. // sn_dg_sdk_method_deliveryService_deleteAllNotifications_end_0
  146. // If response is not immediately complete, call wait until complete
  147. if (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  148. {
  149. while (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  150. {
  151. //before calling wait, double check that it is okay
  152. if (hasSecondaryRequest(asynchReply, "wait"))
  153. {
  154. asynchReply =
  155. connection.getReportService().wait(
  156. asynchReply.getPrimaryRequest(),
  157. new ParameterValue[] {},
  158. new Option[] {});
  159. }
  160. else
  161. {
  162. return "Error: Wait method not available as expected.";
  163. }
  164. }
  165. }
  166. return "Delete all notifications request complete";
  167. }
  168. catch (Exception e)
  169. {
  170. //System.out.println("An error occurred in the deleteAllNotifications Java method.");
  171. //e.printStackTrace();
  172. return "An error occurred in the deleteAllNotifications Java method.";
  173. }
  174. }
  175. /**
  176. * Remove all users from the alert list for a report.
  177. *
  178. * @param connection
  179. * Connection to Server
  180. * @param csobject
  181. * Specifies the report.
  182. */
  183. public String clearNotifications(CRNConnect connection, BaseClassWrapper csobject)
  184. {
  185. AsynchRequest response = null;
  186. AsynchReply asynchReply = null;
  187. String reportPath = csobject.getBaseClassObject().getSearchPath().getValue();
  188. if (csobject == null)
  189. {
  190. return "No valid report selected";
  191. }
  192. try
  193. {
  194. // sn_dg_sdk_method_deliveryService_clearNotifications_start_0
  195. asynchReply =
  196. connection.getDeliveryService().clearNotifications(new SearchPathSingleObject(reportPath));
  197. // sn_dg_sdk_method_deliveryService_clearNotifications_end_0
  198. // If response is not immediately complete, call wait until complete
  199. if (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  200. {
  201. while (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  202. {
  203. //before calling wait, double check that it is okay
  204. if (hasSecondaryRequest(asynchReply, "wait"))
  205. {
  206. asynchReply =
  207. connection.getReportService().wait(
  208. asynchReply.getPrimaryRequest(),
  209. new ParameterValue[] {},
  210. new Option[] {});
  211. }
  212. else
  213. {
  214. return "Error: Wait method not available as expected.";
  215. }
  216. }
  217. }
  218. return "Clear notifications request complete.";
  219. }
  220. catch (Exception e)
  221. {
  222. //System.out.println("An error occurred in the clearNotifications Java method.");
  223. //e.printStackTrace();
  224. return "An error occurred in the clearNotifications Java method.";
  225. }
  226. }
  227. /**
  228. * Query whether the current user is on the alert list for a report.
  229. *
  230. * @param connection
  231. * Connection to Server
  232. * @param csobject
  233. * Specifies the report.
  234. */
  235. public String queryNotification(CRNConnect connection, BaseClassWrapper csobject)
  236. {
  237. AsynchReply asynchReply = null;
  238. String reportPath = csobject.getBaseClassObject().getSearchPath().getValue();
  239. String unknownResult = new String("No details returned.");
  240. if (csobject == null)
  241. {
  242. return "No valid report selected";
  243. }
  244. try
  245. {
  246. // sn_dg_sdk_method_deliveryService_queryNotification_start_0
  247. asynchReply =
  248. connection.getDeliveryService().queryNotification(new SearchPathSingleObject(reportPath));
  249. // sn_dg_sdk_method_deliveryService_queryNotification_end_0
  250. // If response is not immediately complete, call wait until complete
  251. if (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  252. {
  253. while (!asynchReply.getStatus().equals(AsynchReplyStatusEnum.conversationComplete))
  254. {
  255. //before calling wait, double check that it is okay
  256. if (hasSecondaryRequest(asynchReply, "wait"))
  257. {
  258. asynchReply =
  259. connection.getReportService().wait(
  260. asynchReply.getPrimaryRequest(),
  261. new ParameterValue[] {},
  262. new Option[] {});
  263. }
  264. else
  265. {
  266. return "Error: Wait method not available as expected.";
  267. }
  268. }
  269. }
  270. if (asynchReply != null)
  271. {
  272. for (int i = 0; i < asynchReply.getDetails().length; i++)
  273. {
  274. if ((asynchReply.getDetails()[i] instanceof AsynchDetailAgentNotificationStatus))
  275. {
  276. AgentNotificationStatusEnum currentStatus =((AsynchDetailAgentNotificationStatus)asynchReply.getDetails()[i]).getStatus();
  277. if (currentStatus == AgentNotificationStatusEnum.disabled)
  278. {
  279. return "Alert lists are not enabled for this report.";
  280. }
  281. else if (currentStatus == AgentNotificationStatusEnum.off)
  282. {
  283. return "The current user is not on the alert list for this report.";
  284. }
  285. else if (currentStatus == AgentNotificationStatusEnum.on)
  286. {
  287. return "The current user is on the alert list for this report.";
  288. }
  289. else
  290. {
  291. return "Unrecognized alert status returned.";
  292. }
  293. }
  294. }
  295. return "Query notification request returned no alert status information.";
  296. }
  297. }
  298. catch (Exception e)
  299. {
  300. //System.out.println("An error occurred in the queryNotification Java method.");
  301. //e.printStackTrace();
  302. return "An error occurred in the queryNotification Java method.";
  303. }
  304. return unknownResult;
  305. }
  306. public boolean hasSecondaryRequest(
  307. AsynchReply response,
  308. String secondaryRequest)
  309. {
  310. AsynchSecondaryRequest[] secondaryRequests =
  311. response.getSecondaryRequests();
  312. for (int i = 0; i < secondaryRequests.length; i++)
  313. {
  314. if (secondaryRequests[i].getName().compareTo(secondaryRequest)
  315. == 0)
  316. {
  317. return true;
  318. }
  319. }
  320. return false;
  321. }
  322. }