docs: @FFDCIgnore({ EntityNotFoundException.class })
      public Root deleteImpl(Root root) throws WIMException {
          final String METHODNAME = "deleteImpl";
  
          if (root == null)
              return null;
  
          AuditManager auditManager = new AuditManager();
          auditManager.setRequestType(AuditConstants.DELETE_AUDIT);
          if (repositoryManager.getNumberOfRepositories() == 1) {
              auditManager.setRepositoryId(repositoryManager.getRepoIds().get(0));
          }
  
          // Check if this is logged in user.
          // Logged-in User cannot be deleted. isReferenceToLoggedInUser will throw exception in case
          // the user being deleted is logged in User.
          this.isReferenceToLoggedInUser(root);
  
          boolean returnDeleted = false;
  
          List<Entity> entities = root.getEntities();
  
          if (entities.size() == 0) {
              Audit.audit(Audit.EventID.SECURITY_MEMBER_MGMT_01, auditManager.getRESTRequest(), AuditConstants.DELETE_AUDIT, null, null, getRealmName(root), root,
                          Integer.valueOf("201"));
  
              throw new EntityNotFoundException(WIMMessageKey.MISSING_ENTITY_DATA_OBJECT, Tr.formatMessage(tc,
                                                                                                           WIMMessageKey.MISSING_ENTITY_DATA_OBJECT,
                                                                                                           WIMMessageHelper.generateMsgParms(DELETE_EMITTER)));
          } else if (entities.size() > 1) {
              Audit.audit(Audit.EventID.SECURITY_MEMBER_MGMT_01, auditManager.getRESTRequest(), AuditConstants.DELETE_AUDIT, null, null, getRealmName(root), root,
                          Integer.valueOf("202"));
  
              throw new OperationNotSupportedException(WIMMessageKey.ACTION_MULTIPLE_ENTITIES_SPECIFIED, Tr.formatMessage(tc,
                                                                                                                          WIMMessageKey.ACTION_MULTIPLE_ENTITIES_SPECIFIED,
                                                                                                                          WIMMessageHelper.generateMsgParms(RepositoryManager.ACTION_DELETE)));
          }
  
          Entity entity = entities.get(0);
          Map<String, Control> ctrlMap = ControlsHelper.getControlMap(root);
  
          DeleteControl deleteCtrl = (DeleteControl) ctrlMap.get(DO_DELETE_CONTROL);
          //boolean deleteDesc = false;
          if (deleteCtrl != null) {
              //deleteDesc = deleteCtrl.isDeleteDescendants();
              returnDeleted = deleteCtrl.isReturnDeleted();
          }
  
          /* Ensure the principal is authorized to delete the entity */
          // profileSecManager.checkPermission_DELETE(new EntityResource(inRoot, entity), deleteDesc);
  
          IdentifierType identifier = entity.getIdentifier();
          if (identifier == null) {
              Audit.audit(Audit.EventID.SECURITY_MEMBER_MGMT_01, auditManager.getRESTRequest(), AuditConstants.DELETE_AUDIT, null, null, getRealmName(root), root,
                          Integer.valueOf("203"));
  
              throw new EntityIdentifierNotSpecifiedException(WIMMessageKey.ENTITY_IDENTIFIER_NOT_SPECIFIED, Tr.formatMessage(tc, WIMMessageKey.ENTITY_IDENTIFIER_NOT_SPECIFIED));
          }
  
          // If repository id is set in the identifier then use it, else determine it from the uniqueName
          String repositoryId = identifier.getRepositoryId();
          String uniqueName = identifier.getUniqueName();
  
          if (repositoryId == null)
              repositoryId = getRepositoryManager().getRepositoryId(uniqueName);
  
          // check realm
          String realmName = getRealmName(root);
          if (realmName != null && !getConfigManager().isUniqueNameInRealm(uniqueName, realmName)) {
              Audit.audit(Audit.EventID.SECURITY_MEMBER_MGMT_01, auditManager.getRESTRequest(), AuditConstants.DELETE_AUDIT, repositoryId, uniqueName, realmName, root,
                          Integer.valueOf("204"));
  
              throw new EntityNotInRealmScopeException(WIMMessageKey.ENTITY_NOT_IN_REALM_SCOPE, Tr.formatMessage(tc, WIMMessageKey.ENTITY_NOT_IN_REALM_SCOPE,
                                                                                                                 WIMMessageHelper.generateMsgParms(uniqueName, realmName)));
          }
  
          // String realEntityType = realEntity.getTypeName();
          // checkAccessibility(DELETE, RepositoryManager.ACTION_DELETE, repositoryId, realEntityType);
  
          auditManager.setRepositoryId(repositoryId);
          auditManager.setRepositoryRealm(realmName);
          auditManager.setRepositoryUniqueName(uniqueName);
  
          Root retRoot = null;
          try {
              retRoot = repositoryManager.getRepository(repositoryId).delete(root);
          } catch (EntityNotFoundException ex) {
              Audit.audit(Audit.EventID.SECURITY_MEMBER_MGMT_01, auditManager.getRESTRequest(), AuditConstants.DELETE_AUDIT, repositoryId, uniqueName, realmName, root,
                          Integer.valueOf("212"));
              throw ex;
          }
  
          if (retRoot != null) {
              retRoot = postDelete(retRoot, repositoryId, returnDeleted);
          }
  
          Audit.audit(Audit.EventID.SECURITY_MEMBER_MGMT_01, auditManager.getRESTRequest(), AuditConstants.DELETE_AUDIT, repositoryId, uniqueName,
                      realmName != null ? realmName : getRealmNameOrFirstBest(retRoot), retRoot, Integer.valueOf("200"));
  
          return retRoot;
      }