示例#1
0
  /**
   * Delete one of a community's roles
   *
   * @param context The current DSpace context.
   * @param communityID The community id.
   * @param roleName ADMIN.
   * @param groupID The id of the group associated with this role.
   * @return A process result's object.
   */
  public static FlowResult processDeleteCommunityRole(
      Context context, int communityID, String roleName, int groupID)
      throws SQLException, UIException, IOException, AuthorizeException {
    FlowResult result = new FlowResult();

    Community community = Community.find(context, communityID);
    Group role = Group.find(context, groupID);

    // First, unregister the role
    if (ROLE_ADMIN.equals(roleName)) {
      community.removeAdministrators();
    }

    // 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, community);
    for (ResourcePolicy policy : policies) {
      if (policy.getGroupID() == groupID) {
        policy.delete();
      }
    }

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

    result.setContinue(true);
    result.setOutcome(true);
    result.setMessage(new Message("default", "The role was successfully deleted."));
    return result;
  }
示例#2
0
  /**
   * Delete community itself
   *
   * @param context The current DSpace context.
   * @param communityID The community id.
   * @return A process result's object.
   */
  public static FlowResult processDeleteCommunity(Context context, int communityID)
      throws SQLException, AuthorizeException, IOException {
    FlowResult result = new FlowResult();

    Community community = Community.find(context, communityID);

    community.delete();
    context.commit();

    result.setContinue(true);
    result.setOutcome(true);
    result.setMessage(new Message("default", "The community was successfully deleted."));

    return result;
  }
示例#3
0
 /**
  * processCurateCommunity
  *
  * <p>Utility method to process curation tasks submitted via the DSpace GUI
  *
  * @param context
  * @param dsoID
  * @param request
  */
 public static FlowResult processCurateCommunity(Context context, int dsoID, Request request)
     throws AuthorizeException, IOException, SQLException, Exception {
   String task = request.getParameter("curate_task");
   Curator curator = FlowCurationUtils.getCurator(task);
   try {
     Community community = Community.find(context, dsoID);
     if (community != null) {
       // Call curate(context,ID) to ensure a Task Performer (Eperson) is set in Curator
       curator.curate(context, community.getHandle());
     }
     return FlowCurationUtils.getRunFlowResult(task, curator, true);
   } catch (Exception e) {
     curator.setResult(task, e.getMessage());
     return FlowCurationUtils.getRunFlowResult(task, curator, false);
   }
 }
  private Community resolveCommunity(Context c, String communityID) throws SQLException {
    Community community = null;

    if (communityID.indexOf('/') != -1) {
      // has a / must be a handle
      community = (Community) HandleManager.resolveToObject(c, communityID);

      // ensure it's a community
      if ((community == null) || (community.getType() != Constants.COMMUNITY)) {
        community = null;
      }
    } else {
      community = Community.find(c, Integer.parseInt(communityID));
    }

    return community;
  }
  /**
   * Get a preserved community backup file and respective children from cloud.
   *
   * @param context context DSpace
   * @param ref ID of the community
   * @param establishConnection true if pretend establish connection to cloud
   * @return true if file correctly sent to cloud, or false if not
   */
  public Boolean getCommunityAndChilds(Context context, Integer ref, Boolean establishConnection) {
    // if true make the connection available
    if (establishConnection == true) {
      this.makeConnection();
      this.filesInCloud.putAll(this.newCloudConnection.getInfoFilesIn(Constants.COMMUNITY));
    }

    // get file community from cloud
    getCommunity(context, ref, false);

    Community obj;
    Community[] subCommunities;
    Collection[] collections;

    // get community and the respective sub-communities and childs
    try {
      obj = Community.find(context, ref);
      subCommunities = obj.getSubcommunities();
      collections = obj.getCollections();
    } catch (Exception ex) {
      // it means it is the first father in the order, so close connection
      if (establishConnection == true) this.closeConnection();
      Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex);
      return false;
    }

    // get from cloud all the respective files sub-communities and childs
    if (subCommunities.length != 0) {
      for (int i = 0; i < subCommunities.length; i++)
        getCommunityAndChilds(context, subCommunities[i].getID(), false);
    }

    // get from cloud all files collections and childs
    if (collections.length != 0) {
      for (int i = 0; i < collections.length; i++)
        getCollectionAndChilds(context, collections[i].getID(), false);
    }

    // it means it is the first father in the order
    if (establishConnection == true) this.closeConnection();

    return true;
  }
示例#6
0
 /** queues curation tasks */
 public static FlowResult processQueueCommunity(Context context, int dsoID, Request request)
     throws AuthorizeException, IOException, SQLException, Exception {
   String task = request.getParameter("curate_task");
   Curator curator = FlowCurationUtils.getCurator(task);
   String objId = String.valueOf(dsoID);
   String taskQueueName = ConfigurationManager.getProperty("curate", "ui.queuename");
   boolean status = false;
   Community community = Community.find(context, dsoID);
   if (community != null) {
     objId = community.getHandle();
     try {
       curator.queue(context, objId, taskQueueName);
       status = true;
     } catch (IOException ioe) {
       // no-op
     }
   }
   return FlowCurationUtils.getQueueFlowResult(task, status, objId, taskQueueName);
 }
示例#7
0
  /**
   * Look up the id of a group authorized for one of the given roles. If no group is currently
   * authorized to perform this role then a new group will be created and assigned the role.
   *
   * @param context The current DSpace context.
   * @param communityID The collection id.
   * @param roleName ADMIN.
   * @return The id of the group associated with that particular role, or -1 if the role was not
   *     found.
   */
  public static int getCommunityRole(Context context, int communityID, String roleName)
      throws SQLException, AuthorizeException, IOException {
    Community community = Community.find(context, communityID);

    // Determine the group based upon which role we are looking for.
    Group role = null;
    if (ROLE_ADMIN.equals(roleName)) {
      role = community.getAdministrators();
      if (role == null) {
        role = community.createAdministrators();
      }
    }

    // In case we needed to create a group, save our changes
    community.update();
    context.commit();

    // If the role name was valid then role should be non null,
    if (role != null) {
      return role.getID();
    }

    return -1;
  }
示例#8
0
  public DSpaceObject getParentObject() throws SQLException {
    // could a collection/community administrator manage related groups?
    // check before the configuration options could give a performance gain
    // if all group management are disallowed
    if (AuthorizeConfiguration.canCollectionAdminManageAdminGroup()
        || AuthorizeConfiguration.canCollectionAdminManageSubmitters()
        || AuthorizeConfiguration.canCollectionAdminManageWorkflows()
        || AuthorizeConfiguration.canCommunityAdminManageAdminGroup()
        || AuthorizeConfiguration.canCommunityAdminManageCollectionAdminGroup()
        || AuthorizeConfiguration.canCommunityAdminManageCollectionSubmitters()
        || AuthorizeConfiguration.canCommunityAdminManageCollectionWorkflows()) {
      // is this a collection related group?
      TableRow qResult =
          DatabaseManager.querySingle(
              myContext,
              "SELECT collection_id, workflow_step_1, workflow_step_2, "
                  + " workflow_step_3, submitter, admin FROM collection "
                  + " WHERE workflow_step_1 = ? OR "
                  + " workflow_step_2 = ? OR "
                  + " workflow_step_3 = ? OR "
                  + " submitter =  ? OR "
                  + " admin = ?",
              getID(),
              getID(),
              getID(),
              getID(),
              getID());
      if (qResult != null) {
        Collection collection = Collection.find(myContext, qResult.getIntColumn("collection_id"));

        if ((qResult.getIntColumn("workflow_step_1") == getID()
            || qResult.getIntColumn("workflow_step_2") == getID()
            || qResult.getIntColumn("workflow_step_3") == getID())) {
          if (AuthorizeConfiguration.canCollectionAdminManageWorkflows()) {
            return collection;
          } else if (AuthorizeConfiguration.canCommunityAdminManageCollectionWorkflows()) {
            return collection.getParentObject();
          }
        }
        if (qResult.getIntColumn("submitter") == getID()) {
          if (AuthorizeConfiguration.canCollectionAdminManageSubmitters()) {
            return collection;
          } else if (AuthorizeConfiguration.canCommunityAdminManageCollectionSubmitters()) {
            return collection.getParentObject();
          }
        }
        if (qResult.getIntColumn("admin") == getID()) {
          if (AuthorizeConfiguration.canCollectionAdminManageAdminGroup()) {
            return collection;
          } else if (AuthorizeConfiguration.canCommunityAdminManageCollectionAdminGroup()) {
            return collection.getParentObject();
          }
        }
      }
      // is the group related to a community and community administrator allowed
      // to manage it?
      else if (AuthorizeConfiguration.canCommunityAdminManageAdminGroup()) {
        qResult =
            DatabaseManager.querySingle(
                myContext, "SELECT community_id FROM community " + "WHERE admin = ?", getID());

        if (qResult != null) {
          Community community = Community.find(myContext, qResult.getIntColumn("community_id"));
          return community;
        }
      }
    }
    return null;
  }
  public void addBody(Body body) throws WingException, SQLException, AuthorizeException {
    int communityID = parameters.getParameterAsInteger("communityID", -1);
    Community thisCommunity = Community.find(context, communityID);

    String baseURL = contextPath + "/admin/community?administrative-continue=" + knot.getId();

    Group admins = thisCommunity.getAdministrators();

    // DIVISION: main
    Division main =
        body.addInteractiveDivision(
            "community-assign-roles",
            contextPath + "/admin/community",
            Division.METHOD_POST,
            "primary administrative community");
    main.setHead(T_main_head.parameterize(thisCommunity.getName()));

    List options = main.addList("options", List.TYPE_SIMPLE, "horizontal");
    options.addItem().addXref(baseURL + "&submit_metadata", T_options_metadata);
    options.addItem().addHighlight("bold").addXref(baseURL + "&submit_roles", T_options_roles);
    options.addItem().addXref(baseURL + "&submit_curate", T_options_curate);

    // The table of admin roles
    Table rolesTable = main.addTable("roles-table", 6, 5);
    Row tableRow;

    // The header row
    Row tableHeader = rolesTable.addRow(Row.ROLE_HEADER);
    tableHeader.addCell().addContent(T_role_name);
    tableHeader.addCell().addContent(T_role_group);
    tableHeader.addCell().addContent(T_role_buttons);
    rolesTable.addRow();

    /*
     * The community admins
     */
    // data row
    tableRow = rolesTable.addRow(Row.ROLE_DATA);
    tableRow.addCell(Cell.ROLE_HEADER).addContent(T_label_admins);
    if (admins != null) {
      try {
        AuthorizeUtil.authorizeManageAdminGroup(context, thisCommunity);
        tableRow.addCell().addXref(baseURL + "&submit_edit_admin", admins.getName());
      } catch (AuthorizeException authex) {
        // add a notice, the user is not authorized to create/edit community's admin group
        tableRow.addCell().addContent(T_sysadmins_only);
      }
      try {
        AuthorizeUtil.authorizeRemoveAdminGroup(context, thisCommunity);
        tableRow.addCell().addButton("submit_delete_admin").setValue(T_delete);
      } catch (AuthorizeException authex) {
        // nothing to add, the user is not allowed to delete the group
      }
    } else {
      tableRow.addCell().addContent(T_no_role);
      Cell commAdminCell = tableRow.addCell();
      try {
        AuthorizeUtil.authorizeManageAdminGroup(context, thisCommunity);
        commAdminCell.addButton("submit_create_admin").setValue(T_create);
      } catch (AuthorizeException authex) {
        // add a notice, the user is not authorized to create/edit community's admin group
        addAdministratorOnlyButton(commAdminCell, "submit_create_admin", T_create);
      }
    }
    // help and directions row
    tableRow = rolesTable.addRow(Row.ROLE_DATA);
    tableRow.addCell();
    tableRow.addCell(1, 2).addHighlight("fade offset").addContent(T_help_admins);

    try {
      AuthorizeUtil.authorizeManageCommunityPolicy(context, thisCommunity);
      // add one last link to edit the raw authorizations
      Cell authCell = rolesTable.addRow().addCell(1, 3);
      authCell.addXref(baseURL + "&submit_authorizations", T_edit_authorizations);
    } catch (AuthorizeException authex) {
      // nothing to add, the user is not authorized to manage community's policies
    }

    Para buttonList = main.addPara();
    buttonList.addButton("submit_return").setValue(T_submit_return);

    main.addHidden("administrative-continue").setValue(knot.getId());
  }
  public void addBody(Body body) throws WingException, SQLException, AuthorizeException {
    int communityID = parameters.getParameterAsInteger("communityID", -1);
    Community parentCommunity = Community.find(context, communityID);

    // DIVISION: main
    Division main =
        body.addInteractiveDivision(
            "create-collection",
            contextPath + "/admin/collection",
            Division.METHOD_MULTIPART,
            "primary administrative collection");
    main.setHead(T_main_head.parameterize(parentCommunity.getMetadata("name")));

    // The grand list of metadata options
    List metadataList = main.addList("metadataList", "form");

    // collection name
    metadataList.addLabel(T_label_name);
    Text name = metadataList.addItem().addText("name");
    name.setSize(40);

    // short description
    metadataList.addLabel(T_label_short_description);
    Text short_description = metadataList.addItem().addText("short_description");
    short_description.setSize(40);

    // introductory text
    metadataList.addLabel(T_label_introductory_text);
    TextArea introductory_text = metadataList.addItem().addTextArea("introductory_text");
    introductory_text.setSize(6, 40);

    // copyright text
    metadataList.addLabel(T_label_copyright_text);
    TextArea copyright_text = metadataList.addItem().addTextArea("copyright_text");
    copyright_text.setSize(6, 40);

    // legacy sidebar text; may or may not be used for news
    metadataList.addLabel(T_label_side_bar_text);
    TextArea side_bar_text = metadataList.addItem().addTextArea("side_bar_text");
    side_bar_text.setSize(6, 40);

    // license text
    metadataList.addLabel(T_label_license);
    TextArea license = metadataList.addItem().addTextArea("license");
    license.setSize(6, 40);

    // provenance description
    metadataList.addLabel(T_label_provenance_description);
    TextArea provenance_description = metadataList.addItem().addTextArea("provenance_description");
    provenance_description.setSize(6, 40);

    // the row to upload a new logo
    metadataList.addLabel(T_label_logo);
    metadataList.addItem().addFile("logo");

    Para buttonList = main.addPara();
    buttonList.addButton("submit_save").setValue(T_submit_save);
    buttonList.addButton("submit_cancel").setValue(T_submit_cancel);

    main.addHidden("administrative-continue").setValue(knot.getId());
  }
示例#11
0
  /**
   * Process the community metadata edit form.
   *
   * @param context The current DSpace context.
   * @param communityID The community id.
   * @param deleteLogo Determines if the logo should be deleted along with the metadata editing
   *     action.
   * @param request the Cocoon request object
   * @return A process result's object.
   */
  public static FlowResult processEditCommunity(
      Context context, int communityID, boolean deleteLogo, Request request)
      throws AuthorizeException, IOException, SQLException {
    FlowResult result = new FlowResult();

    Community community = Community.find(context, communityID);

    String name = request.getParameter("name");
    String shortDescription = request.getParameter("short_description");
    String introductoryText = request.getParameter("introductory_text");
    String copyrightText = request.getParameter("copyright_text");
    String sideBarText = request.getParameter("side_bar_text");

    // If they don't have a name then make it untitled.
    if (name == null || name.length() == 0) {
      name = "Untitled";
    }

    // If empty, make it null.
    if (shortDescription != null && shortDescription.length() == 0) {
      shortDescription = null;
    }
    if (introductoryText != null && introductoryText.length() == 0) {
      introductoryText = null;
    }
    if (copyrightText != null && copyrightText.length() == 0) {
      copyrightText = null;
    }
    if (sideBarText != null && sideBarText.length() == 0) {
      sideBarText = null;
    }

    // Save the data
    community.setMetadata("name", name);
    community.setMetadata("short_description", shortDescription);
    community.setMetadata("introductory_text", introductoryText);
    community.setMetadata("copyright_text", copyrightText);
    community.setMetadata("side_bar_text", sideBarText);

    if (deleteLogo) {
      // Remove the logo
      community.setLogo(null);
    } else {
      // Update the logo
      Object object = request.get("logo");
      Part filePart = null;
      if (object instanceof Part) {
        filePart = (Part) object;
      }

      if (filePart != null && filePart.getSize() > 0) {
        InputStream is = filePart.getInputStream();

        community.setLogo(is);
      }
    }

    // Save everything
    community.update();
    context.commit();

    // No notice...
    result.setContinue(true);
    return result;
  }
示例#12
0
  /**
   * Create a new community
   *
   * @param context The current DSpace context.
   * @param communityID The id of the parent community (-1 for a top-level community).
   * @return A process result's object.
   */
  public static FlowResult processCreateCommunity(Context context, int communityID, Request request)
      throws AuthorizeException, IOException, SQLException {
    FlowResult result = new FlowResult();

    Community parent = Community.find(context, communityID);
    Community newCommunity;

    if (parent != null) {
      newCommunity = parent.createSubcommunity();
    } else {
      newCommunity = Community.create(null, context);
    }

    String name = request.getParameter("name");
    String shortDescription = request.getParameter("short_description");
    String introductoryText = request.getParameter("introductory_text");
    String copyrightText = request.getParameter("copyright_text");
    String sideBarText = request.getParameter("side_bar_text");

    // If they don't have a name then make it untitled.
    if (name == null || name.length() == 0) {
      name = "Untitled";
    }

    // If empty, make it null.
    if (shortDescription != null && shortDescription.length() == 0) {
      shortDescription = null;
    }
    if (introductoryText != null && introductoryText.length() == 0) {
      introductoryText = null;
    }
    if (copyrightText != null && copyrightText.length() == 0) {
      copyrightText = null;
    }
    if (sideBarText != null && sideBarText.length() == 0) {
      sideBarText = null;
    }

    newCommunity.setMetadata("name", name);
    newCommunity.setMetadata("short_description", shortDescription);
    newCommunity.setMetadata("introductory_text", introductoryText);
    newCommunity.setMetadata("copyright_text", copyrightText);
    newCommunity.setMetadata("side_bar_text", sideBarText);

    // Upload the logo
    Object object = request.get("logo");
    Part filePart = null;
    if (object instanceof Part) {
      filePart = (Part) object;
    }

    if (filePart != null && filePart.getSize() > 0) {
      InputStream is = filePart.getInputStream();

      newCommunity.setLogo(is);
    }

    // Save everything
    newCommunity.update();
    context.commit();
    // success
    result.setContinue(true);
    result.setOutcome(true);
    result.setMessage(new Message("default", "The community was successfully created."));
    result.setParameter("communityID", newCommunity.getID());

    return result;
  }