コード例 #1
0
  @Override
  public void addSubcommunity(Context context, Community parentCommunity, Community childCommunity)
      throws SQLException, AuthorizeException {
    // Check authorisation
    authorizeService.authorizeAction(context, parentCommunity, Constants.ADD);

    log.info(
        LogManager.getHeader(
            context,
            "add_subcommunity",
            "parent_comm_id="
                + parentCommunity.getID()
                + ",child_comm_id="
                + childCommunity.getID()));

    if (!parentCommunity.getSubcommunities().contains(childCommunity)) {
      parentCommunity.addSubCommunity(childCommunity);
      childCommunity.addParentCommunity(parentCommunity);
    }
    context.addEvent(
        new Event(
            Event.ADD,
            Constants.COMMUNITY,
            parentCommunity.getID(),
            Constants.COMMUNITY,
            childCommunity.getID(),
            parentCommunity.getHandle(),
            getIdentifiers(context, parentCommunity)));
  }
コード例 #2
0
  /** Internal method to process subcommunities recursively */
  protected void addCollectionList(Community community, List<Collection> collectionList)
      throws SQLException {
    for (Community subcommunity : community.getSubcommunities()) {
      addCollectionList(subcommunity, collectionList);
    }

    for (Collection collection : community.getCollections()) {
      collectionList.add(collection);
    }
  }
コード例 #3
0
  /**
   * Internal method to remove the community and all its children from the database, and perform any
   * pre/post-cleanup
   *
   * @throws SQLException
   * @throws AuthorizeException
   * @throws IOException
   */
  protected void rawDelete(Context context, Community community)
      throws SQLException, AuthorizeException, IOException {
    log.info(
        LogManager.getHeader(context, "delete_community", "community_id=" + community.getID()));

    context.addEvent(
        new Event(
            Event.DELETE,
            Constants.COMMUNITY,
            community.getID(),
            community.getHandle(),
            getIdentifiers(context, community)));

    // Remove collections
    Iterator<Collection> collections = community.getCollections().iterator();

    while (collections.hasNext()) {
      Collection collection = collections.next();
      collections.remove();
      removeCollection(context, community, collection);
    }
    // delete subcommunities
    Iterator<Community> subCommunities = community.getSubcommunities().iterator();

    while (subCommunities.hasNext()) {
      Community subComm = subCommunities.next();
      subCommunities.remove();
      delete(context, subComm);
    }

    // Remove the logo
    setLogo(context, community, null);

    // Remove all authorization policies
    authorizeService.removeAllPolicies(context, community);

    // Remove any Handle
    handleService.unbindHandle(context, community);

    deleteMetadata(context, community);

    Group g = community.getAdministrators();

    // Delete community row
    communityDAO.delete(context, community);

    // Remove administrators group - must happen after deleting community

    if (g != null) {
      groupService.delete(context, g);
    }
  }
コード例 #4
0
 @Override
 public int countItems(Context context, Community community) throws SQLException {
   int total = 0;
   // add collection counts
   List<Collection> cols = community.getCollections();
   for (Collection col : cols) {
     total += itemService.countItems(context, col);
   }
   // add sub-community counts
   List<Community> comms = community.getSubcommunities();
   for (int j = 0; j < comms.size(); j++) {
     total += countItems(context, comms.get(j));
   }
   return total;
 }
コード例 #5
0
  @Override
  public List<Collection> getAllCollections(Context context, Community community)
      throws SQLException {
    List<Collection> collectionList = new ArrayList<Collection>();
    List<Community> subCommunities = community.getSubcommunities();
    for (Community subCommunity : subCommunities) {
      addCollectionList(subCommunity, collectionList);
    }

    List<Collection> collections = community.getCollections();
    for (Collection collection : collections) {
      collectionList.add(collection);
    }
    return collectionList;
  }
コード例 #6
0
  @Override
  public void delete(Context context, Community community)
      throws SQLException, AuthorizeException, IOException {
    // Check authorisation
    // FIXME: If this was a subcommunity, it is first removed from it's
    // parent.
    // This means the parentCommunity == null
    // But since this is also the case for top-level communities, we would
    // give everyone rights to remove the top-level communities.
    // The same problem occurs in removing the logo
    if (!authorizeService.authorizeActionBoolean(
        context, getParentObject(context, community), Constants.REMOVE)) {
      authorizeService.authorizeAction(context, community, Constants.DELETE);
    }
    ArrayList<String> removedIdentifiers = getIdentifiers(context, community);
    String removedHandle = community.getHandle();
    UUID removedId = community.getID();

    // If not a top-level community, have parent remove me; this
    // will call rawDelete() before removing the linkage
    Community parent = (Community) getParentObject(context, community);

    if (parent != null) {
      // remove the subcommunities first
      Iterator<Community> subcommunities = community.getSubcommunities().iterator();
      while (subcommunities.hasNext()) {
        Community subCommunity = subcommunities.next();
        subcommunities.remove();
        delete(context, subCommunity);
      }
      // now let the parent remove the community
      removeSubcommunity(context, parent, community);

      return;
    }

    rawDelete(context, community);
    context.addEvent(
        new Event(
            Event.REMOVE,
            Constants.SITE,
            siteService.findSite(context).getID(),
            Constants.COMMUNITY,
            removedId,
            removedHandle,
            removedIdentifiers));
  }