Start page / Tutorials / Workflows / Workflow “Delete” / Example: ContentDeleteDemo

Example: “ContentDeleteDemo” workflow

 

Aside from individual elements and subtrees (see Example: Delete), a workflow can also be used to delete structured data.

For this to happen, a distinction must be made within the workflow (in the script) between normal elements (“StoreElement”, such as pages, media, page references) and “entities”.

In the script, this information is retrieved using the workflow's context (WorkflowScriptContext):         

workflowable = context.getWorkflowable()

The getWorkflowable() method returns information to indicate whether the element where the workflow was started is a “StoreElement” (such as a medium) or an “entity” (in the form of a dataset). The output of the script can be adapted accordingly. For instance:

if (workflowable instanceof ContentWorkflowable) {
...
} else {
...
}

In the example, the output is controlled according to the context in which the workflow was started. If the delete function is started on a dataset, the script outputs:

If the delete functionality is started on a medium, the script outputs:

For information on pop-up dialogs, see Workflows / Messages and Plug-In Development / Message Boxes.

In this example, data is once again deleted directly via the WorkflowScriptContext:

workflowable.delete();

Here, the Delete method is called on the Workflowable object and not (as in the case of Example: Messages) on the StoreElement. This Delete method is suitable for deleting a dataset (entity) as well as a StoreElement.

The workflow for deleting entities consists of the workflow itself and the corresponding “deletecontentdemo” script (for deleting individual entities).

After successful deletion, the workflow is automatically advanced to the subsequent “End” status.

“deletecontentdemo” script

//!Beanshell
import de.espirit.firstspirit.access.*;
import de.espirit.firstspirit.access.store.contentstore.*;
import de.espirit.firstspirit.ui.operations.RequestOperation;
import de.espirit.firstspirit.agency.OperationAgent;
 
workflowable = context.getWorkflowable();
if (workflowable instanceof ContentWorkflowable) {
          message = "Delete entity:\n  content=" + workflowable.getContent().getName() + "\n  entity="
+ workflowable.getEntity().getKeyValue();
requestOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(RequestOperation.TYPE);
          requestOperation.setKind(RequestOperation.Kind.INFO);
          requestOperation.addOk();
          requestOperation.perform(message);}
else {
          message = "Delete StoreElement:\n  store=" + workflowable.getStore().getName() + "\n  id=" + workflowable.getId();
requestOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(RequestOperation.TYPE);
          requestOperation.setKind(RequestOperation.Kind.INFO);
          requestOperation.addOk();
          requestOperation.perform(message);
}
workflowable.delete();
context.doTransition("->End");

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.5 | Data privacy