/**
   * Delete one of collection's roles
   *
   * @param context The current DSpace context.
   * @param collectionID The collection id.
   * @param roleName ADMIN, WF_STEP1, WF_STEP2, WF_STEP3, SUBMIT, DEFAULT_READ.
   * @param groupID The id of the group associated with this role.
   * @return A process result's object.
   */
  public static FlowResult processDeleteCollectionRole(
      Context context, int collectionID, String roleName, int groupID)
      throws SQLException, UIException, IOException, AuthorizeException,
          WorkflowConfigurationException {
    FlowResult result = new FlowResult();

    Collection collection = Collection.find(context, collectionID);
    Group role = Group.find(context, groupID);

    // First, Unregister the role
    if (ROLE_ADMIN.equals(roleName)) {
      collection.removeAdministrators();
    } else if (ROLE_SUBMIT.equals(roleName)) {
      collection.removeSubmitters();
    } else {
      WorkflowUtils.deleteRoleGroup(context, collection, roleName);
    }
    //		else if (ROLE_WF_STEP1.equals(roleName))
    //		{
    //			collection.setWorkflowGroup(1, null);
    //		}
    //		else if (ROLE_WF_STEP2.equals(roleName))
    //		{
    //			collection.setWorkflowGroup(2, null);
    //		}
    //		else if (ROLE_WF_STEP3.equals(roleName))
    //		{
    //			collection.setWorkflowGroup(3, null);
    //
    //		}

    // Second, remove all authorizations for this role by searching for all policies that this
    // group has on the collection and remove them otherwise the delete will fail because
    // there are dependencies.
    @SuppressWarnings("unchecked") // the cast is correct
    List<ResourcePolicy> policies = AuthorizeManager.getPolicies(context, collection);
    for (ResourcePolicy policy : policies) {
      if (policy.getGroupID() == groupID) {
        policy.delete();
      }
    }

    // Finally, Delete the role's actual group.
    collection.update();
    role.delete();
    context.commit();

    result.setContinue(true);
    result.setOutcome(true);
    result.setMessage(new Message("default", "The role was successfully deleted."));
    return result;
  }
 private static Group getXMLWorkflowRole(
     Context context, int collectionID, String roleName, Collection collection, Group roleGroup)
     throws IOException, WorkflowConfigurationException, SQLException, AuthorizeException {
   Role role = WorkflowUtils.getCollectionAndRepositoryRoles(collection).get(roleName);
   if (role.getScope() == Role.Scope.COLLECTION || role.getScope() == Role.Scope.REPOSITORY) {
     roleGroup = WorkflowUtils.getRoleGroup(context, collectionID, role);
     if (roleGroup == null) {
       AuthorizeManager.authorizeAction(context, collection, Constants.WRITE);
       roleGroup = Group.create(context);
       if (role.getScope() == Role.Scope.COLLECTION) {
         roleGroup.setName("COLLECTION_" + collection.getID() + "_WORKFLOW_ROLE_" + roleName);
       } else {
         roleGroup.setName(role.getName());
       }
       roleGroup.update();
       AuthorizeManager.addPolicy(context, collection, Constants.ADD, roleGroup);
       if (role.getScope() == Role.Scope.COLLECTION) {
         WorkflowUtils.createCollectionWorkflowRole(context, collectionID, roleName, roleGroup);
       }
     }
   }
   return roleGroup;
 }