class EcmNodeDeletedEventHandler implements ApplicationListener<EcmEvent> {

    public void onEcmNodeDeleted(EcmEvent ecmEvent)
    {

        getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId());

        EcmFile deleteFile = getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId());
        if (deleteFile != null)
        {
            try
            {
                String message = String.format(DELETE_MESSAGE, deleteFile.getObjectType().toLowerCase());
                getFileService().removeLockAndSendMessage(deleteFile.getId(), message);

                getFileService().deleteFileFromArkcase(deleteFile.getId());
                log.info("Deleted file with CMIS ID [{}]", ecmEvent.getNodeId());
            }
            catch (PersistenceException e)
            {
                log.error("Could not delete file with id [{}], {} ", deleteFile.getId(), e.getMessage(), e);
            }
        }
        else
        {
            AcmFolder deleteFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getNodeId());
            if (deleteFolder != null)
            {
                String message = String.format(DELETE_MESSAGE, deleteFolder.getObjectType().toLowerCase());
                getFolderService().removeLockAndSendMessage(deleteFolder.getId(), message);

                getFolderService().deleteFolderContent(deleteFolder, AuthenticationUtils.getUsername());

                log.info("Deleted folder with CMIS ID [{}]", ecmEvent.getNodeId());
            }
        }
    }

}