Example - delete a report

The content store is a database that stores the information about BI Bus API objects. You can use the BI Bus API methods to delete objects from the content store. For example, you may want to delete a report because it is no longer being used.

The code examples in this section show you how to do the following:

  • retrieve a report from the content store using the query(searchPath, properties, sortBy, options) method
  • delete a report from the content store using the delete(objects, options) method

Before using these methods, you must do the following:

In the code examples, the object is a report and its parent is a folder or package.

Methods

You can use the following methods to delete reports.

  • query(searchPath, properties, sortBy, options)
  • delete(objects, options)

See the Methods chapter in the Software Development Kit Developer Guide for the permissions and capabilities required for each method.

Java code

To see the code in context, view the following sample:

installation_location/sdk/java/ReportDelete/DeleteReport.java

The following Java™ code snippet demonstrates how you can delete a report from the content store.

delOptions.setForce(true);
delOptions.setFaultIfObjectReferenced(false);
delOptions.setRecursive(true);

try
{
	if (reportToBeDeleted != null)
	{
		System.out.println("Deleting report: " + reportToBeDeleted);

		BaseClass reportsForDeletion[] =
			new BaseClass[] { reportToBeDeleted.getBaseClassObject()};
		int delReturnCode =
			connection.getCMService().delete(reportsForDeletion, delOptions);

C# code

To see the code in context, view the following sample:

installation_location/sdk/csharp/DeleteReport/DeleteReport.cs

The following C# code snippet demonstrates how you can delete a report from the content store.


deleteOptions del = new deleteOptions();
del.force = true;

// The recursive option guarantees that every report history 
// attached to this report will also be deleted.
del.recursive = true;

// extract the baseClass from the report parameter
baseClass[] bc = new baseClass[1];
bc[0] = report.baseclassobject;

int nbItemsDeleted = cBICMS.delete( bc, del );

if (nbItemsDeleted>0)
{
	resultMessage = "...The item \"" + report.searchPath.value +
		"\" was successfully deleted.";
}

Explanation

When you use the query(searchPath, properties, sortBy, options) method, you must specify the search parameter to identify the single object you want to retrieve.

You may also specify the properties parameter to set the properties you want returned and the options parameter to set the options of the query operation, such as the maximum number of objects in the result set. In the code examples, the options parameter is not specified. The query(searchPath, properties, sortBy, options) method returns the report that you request.

In all the code examples, the search path parameter is represented by the variable reportToBeDeleted. This value is used to construct the reference required by the delete(objects, options) method. The search path specifies the objects you want to delete. Objects in the content store are organized in a single hierarchy that starts with a single root object. The root object, shown in a search path as a slash (/), contains all the objects available in the content store.

Objects are related to other objects through parent-child relationships (containment) and through references. Parent-child relationships are used to construct the search path property for objects persistent in the content store. These relationships describe the location of objects in the content store and are reflected in the elements of the search path for each object.

For example, the following search path shows the location in the content store of the report named Order Product List in the folder named SDK Report Samples:

/content/package[@name='GO Data Warehouse (query)']/folder[@name='SDK Report Samples']/report[@name='Order Product List']

For information about managing content, see the Software Development Kit Developer Guide.

In all the code examples, the properties parameter is represented by the variable props. The properties parameter specifies the set of properties you want to be returned. You use the type propEnum to define the properties parameter because this enumeration set contains all the possible properties for all the persisted objects in the content store. In the Java example, the searchPath and defaultName properties are returned.

In all the code examples, the results from the query(searchPath, properties, sortBy, options) method are used as the value for the objects parameter in the call to the delete(objects, options) method. Objects persisted in the content store are all instances of classes found in the enumeration set classEnum. These classes are all derived from the class baseClass. Therefore, the objects parameter is of type baseClass to allow for the specification of any class of persisted object.

When you use the delete(objects, options) method, you may also specify the following delete options:

  • faultIfObjectReferenced
  • force
  • recursive

If you do not set the recursive option to true, objects that have descendants are not deleted and an exception is returned. The force option affects the permissions a user needs to delete an object. In both code examples, the options parameter is represented by the variable named del, which sets the force option to true.

In the code examples, an integer value is returned that indicates the number of objects deleted. If the value is greater than 0, the delete operation was successful.

Steps when writing your own programs

  1. Create an array of baseClass objects.
  2. Create a deleteOptions object and set its properties.

    In the code examples, the force property is set to true.

  3. Use the method query(searchPath, properties, sortBy, options) to retrieve the report from the content store. This action returns a baseClass object.

    In the examples, the search path for the report is specified by the user.

  4. Add the report to the baseClass array.
  5. Call the delete(objects, options) method, using the baseClass array that contains the report and the deleteOptions object as parameters.

    Tip: Prompt the user to confirm that the selected objects should be deleted.

    You cannot undo a delete operation.

  6. Check the integer returned for the number of objects deleted from the content store.