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

Example: "Delete" workflow

The workflow for deleting elements consists of the workflow itself and the corresponding scripts: clientdelete (for deleting individual objects) and serverdelete (for deleting subtrees).

If the clientdelete action is run, the element is locked by the corresponding script and then deleted. After deletion, the workflow is advanced to the subsequent “End” status.

If the serverdelete action is run, the element is locked recursively via the corresponding script. This means that the serverdelete action can be used to delete subtrees, not just individual elements. In this case, the delete operation is performed using a ServerHandle, which returns a results report and, in the event of an error, throws an exception.

After successful deletion, the workflow is advanced to the subsequent “End” status. The following applies to both actions: In the event of an error, the workflow is not advanced to the end status, but to an error status that was modeled in the workflow.

“clientdelete” script

//!Beanshell
import de.espirit.firstspirit.common.gui.*;
import de.espirit.firstspirit.ui.operations.RequestOperation;
import de.espirit.firstspirit.agency.OperationAgent;
 
se = context.getElement();
try {
se.setLock(true);
          se.delete();
          context.doTransition("->End");
} catch (Exception ex) {
          text = "Error while deleting: " + ex;
          requestOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(RequestOperation.TYPE);
          requestOperation.setKind(RequestOperation.Kind.INFO);
          requestOperation.addOk();
          requestOperation.perform(text);
 
          context.getSession().put("error", ex.toString());
          context.doTransition("->Error");
}

“serverdelete” script

//!Beanshell
import de.espirit.firstspirit.common.gui.*;
import de.espirit.firstspirit.ui.operations.RequestOperation;
import de.espirit.firstspirit.agency.OperationAgent;
 
se = context.getElement();
parent = se.getParent();
try {
          se.setLock(false, false);
          handle = de.espirit.firstspirit.access.AccessUtil.delete(se, true);
          handle.getResult();
          handle.checkAndThrow();
         
          Set notDeleted = new HashSet();
          progress = handle.getProgress(true);
          notDeleted.addAll(progress.getDeleteFailedElements());
          notDeleted.addAll(progress.getMissingPermissionElements());
          notDeleted.addAll(progress.getLockFailedElements());
          notDeleted.addAll(progress.getReferencedElements());
          if (!notDeleted.isEmpty()) {
                      text = "Unable to delete the following elements: " + notDeleted;
                      requestOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(RequestOperation.TYPE);
                      requestOperation.setKind(RequestOperation.Kind.INFO);
                      requestOperation.addOk();
                      requestOperation.perform(text);
          }
 
          if (parent != null) {
                      parent.refresh();
                      context.getGuiHost().gotoTreeNode(parent);
          }
 
          if (!se.isDeleted()) {
                      se.setLock(true, false);
          }
          context.doTransition("->End");
 
} catch (Exception ex) {
          text = "Error while deleting: " + ex;
          requestOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(RequestOperation.TYPE);
          requestOperation.setKind(RequestOperation.Kind.INFO);
          requestOperation.addOk();
          requestOperation.perform(text);
 
          context.getSession().put("error", ex.toString());
          context.doTransition("->Error");
}

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