DeleteReport.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * DeleteReport.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 delete reports using the
  15. * following methods:
  16. * - query
  17. * Use this method to request objects from Content Manager.
  18. * - delete
  19. * Use this method to delete objects from the content store.
  20. */
  21. import com.cognos.developer.schemas.bibus._3.BaseClass;
  22. import com.cognos.developer.schemas.bibus._3.DeleteOptions;
  23. public class DeleteReport
  24. {
  25. /**
  26. * This Java method returns a string that contains either the
  27. * information about the specified objects if the request succeeded
  28. * or an error message if the request failed.
  29. *
  30. * @param connection
  31. * Specifies the object that provides the connection to
  32. * the service.
  33. * @param reportToBeDeleted
  34. * Specifies the search path of the report.
  35. *
  36. * @return output
  37. * Returns a message that indicates whether the request
  38. * succeeded or failed.
  39. */
  40. public String deleteReport(
  41. CRNConnect connection,
  42. BaseClassWrapper reportToBeDeleted)
  43. {
  44. String output = new String();
  45. if (connection != null)
  46. {
  47. // Set the options for the delete method.
  48. DeleteOptions delOptions = new DeleteOptions();
  49. // Set the force option to true. When the force option is true,
  50. // a selected object will be deleted if the current user has either
  51. // write or setPolicy permission for the following:
  52. // - the selected object
  53. // - the parent of the selected object
  54. // - every descendant of the selected object
  55. // sn_dg_prm_smpl_deletereport_start_0
  56. delOptions.setForce(true);
  57. delOptions.setFaultIfObjectReferenced(false);
  58. delOptions.setRecursive(true);
  59. try
  60. {
  61. if (reportToBeDeleted != null)
  62. {
  63. System.out.println("Deleting report: " + reportToBeDeleted);
  64. BaseClass reportsForDeletion[] =
  65. new BaseClass[] { reportToBeDeleted.getBaseClassObject()};
  66. int delReturnCode =
  67. connection.getCMService().delete(reportsForDeletion, delOptions);
  68. // sn_dg_prm_smpl_deletereport_end_0
  69. if (delReturnCode > 0)
  70. {
  71. output = "The report was deleted successfully.\n";
  72. }
  73. else
  74. {
  75. output =
  76. "An error occurred while deleting the report.\n";
  77. }
  78. }
  79. }
  80. //catch unhandled exceptions
  81. catch (java.rmi.RemoteException remoteEx)
  82. {
  83. remoteEx.printStackTrace();
  84. }
  85. }
  86. return output;
  87. }
  88. }