private void deleteDataInstancesIfNecessary(
     final SProcessInstance processInstance, final SProcessDefinition processDefinition)
     throws SDataInstanceException {
   boolean dataPresent = true;
   if (processDefinition != null) {
     dataPresent = processDefinition.getProcessContainer().getDataDefinitions().size() > 0;
   }
   dataInstanceService.deleteLocalDataInstances(
       processInstance.getId(), DataInstanceContainer.PROCESS_INSTANCE.toString(), dataPresent);
 }
 private void deleteDataInstancesIfNecessary(
     final SFlowNodeInstance flowNodeInstance, final SProcessDefinition processDefinition)
     throws SDataInstanceException {
   boolean dataPresent = true;
   if (processDefinition != null) {
     final SActivityDefinition activityDefinition =
         (SActivityDefinition)
             processDefinition
                 .getProcessContainer()
                 .getFlowNode(flowNodeInstance.getFlowNodeDefinitionId());
     if (activityDefinition != null) {
       dataPresent = activityDefinition.getSDataDefinitions().size() > 0;
     }
   }
   dataInstanceService.deleteLocalDataInstances(
       flowNodeInstance.getId(), DataInstanceContainer.ACTIVITY_INSTANCE.toString(), dataPresent);
 }
 private void deleteArchivedFlowNodeInstanceElements(final SAFlowNodeInstance activityInstance)
     throws SFlowNodeReadException, SBonitaSearchException, SConnectorInstanceDeletionException,
         SDataInstanceException {
   if (activityInstance instanceof SAActivityInstance) {
     dataInstanceService.deleteLocalArchivedDataInstances(
         activityInstance.getSourceObjectId(), DataInstanceContainer.ACTIVITY_INSTANCE.toString());
     connectorInstanceService.deleteArchivedConnectorInstances(
         activityInstance.getSourceObjectId(), SConnectorInstance.FLOWNODE_TYPE);
     if (SFlowNodeType.USER_TASK.equals(activityInstance.getType())
         || SFlowNodeType.MANUAL_TASK.equals(activityInstance.getType())) {
       try {
         activityService.deleteArchivedPendingMappings(activityInstance.getSourceObjectId());
       } catch (final SActivityModificationException e) {
         throw new SFlowNodeReadException(e);
       }
     }
   }
 }
 @Override
 public void deleteArchivedProcessInstanceElements(
     final long processInstanceId, final long processDefinitionId)
     throws SProcessInstanceModificationException {
   final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
   try {
     final ClassLoader localClassLoader =
         classLoaderService.getLocalClassLoader("process", processDefinitionId);
     Thread.currentThread().setContextClassLoader(localClassLoader);
     deleteArchivedFlowNodeInstances(processInstanceId);
     dataInstanceService.deleteLocalArchivedDataInstances(
         processInstanceId, DataInstanceContainer.PROCESS_INSTANCE.toString());
     processDocumentService.deleteArchivedDocuments(processInstanceId);
     connectorInstanceService.deleteArchivedConnectorInstances(
         processInstanceId, SConnectorInstance.PROCESS_TYPE);
     transitionService.deleteArchivedTransitionsOfProcessInstance(processInstanceId);
     commentService.deleteArchivedComments(processInstanceId);
     deleteArchivedChidrenProcessInstanceElements(processInstanceId, processDefinitionId);
   } catch (final SBonitaException e) {
     throw new SProcessInstanceModificationException(e);
   } finally {
     Thread.currentThread().setContextClassLoader(contextClassLoader);
   }
 }