code: private void handlePurgeProject(final HttpServletRequest req,
        final HttpServletResponse resp, final Session session) throws ServletException,
        IOException {
      final User user = session.getUser();
      final HashMap<String, Object> ret = new HashMap<>();
      boolean isOperationSuccessful = true;
  
      try {
        Project project = null;
        final String projectParam = getParam(req, "project");
  
        if (StringUtils.isNumeric(projectParam)) {
          project = this.projectManager.getProject(Integer.parseInt(projectParam)); // get
          // project
          // by
          // Id
        } else {
          project = this.projectManager.getProject(projectParam); // get project by
          // name (name cannot
          // start
          // from ints)
        }
  
        // invalid project
        if (project == null) {
          ret.put(ERROR_PARAM, "invalid project");
          isOperationSuccessful = false;
        }
  
        // project is already deleted
        if (isOperationSuccessful
            && this.projectManager.isActiveProject(project.getId())) {
          ret.put(ERROR_PARAM, "Project " + project.getName()
              + " should be deleted before purging");
          isOperationSuccessful = false;
        }
  
        // only eligible users can purge a project
        if (isOperationSuccessful && !hasPermission(project, user, Type.ADMIN)) {
          ret.put(ERROR_PARAM, "Cannot purge. User '" + user.getUserId()
              + "' is not an ADMIN.");
          isOperationSuccessful = false;
        }
  
        if (isOperationSuccessful) {
          this.projectManager.purgeProject(project, user);
        }
      } catch (final Exception e) {
        ret.put(ERROR_PARAM, e.getMessage());
        isOperationSuccessful = false;
      }
  
      ret.put("success", isOperationSuccessful);
      this.writeJSON(resp, ret);
    }
docs: validate readiness of a project and user permission and use projectManager to purge the project
  if things looks good