Ejemplo n.º 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)));
  }
Ejemplo n.º 2
0
  @Override
  public Community create(Community parent, Context context, String handle)
      throws SQLException, AuthorizeException {
    if (!(authorizeService.isAdmin(context)
        || (parent != null
            && authorizeService.authorizeActionBoolean(context, parent, Constants.ADD)))) {
      throw new AuthorizeException("Only administrators can create communities");
    }

    Community newCommunity = communityDAO.create(context, new Community());

    try {
      if (handle == null) {
        handleService.createHandle(context, newCommunity);
      } else {
        handleService.createHandle(context, newCommunity, handle);
      }
    } catch (IllegalStateException ie) {
      // If an IllegalStateException is thrown, then an existing object is already using this handle
      throw ie;
    }

    if (parent != null) {
      parent.addSubCommunity(newCommunity);
      newCommunity.addParentCommunity(parent);
    }

    // create the default authorization policy for communities
    // of 'anonymous' READ
    Group anonymousGroup = groupService.findByName(context, Group.ANONYMOUS);

    authorizeService.createResourcePolicy(
        context, newCommunity, anonymousGroup, null, Constants.READ, null);

    communityDAO.save(context, newCommunity);

    context.addEvent(
        new Event(
            Event.CREATE,
            Constants.COMMUNITY,
            newCommunity.getID(),
            newCommunity.getHandle(),
            getIdentifiers(context, newCommunity)));

    // if creating a top-level Community, simulate an ADD event at the Site.
    if (parent == null) {
      context.addEvent(
          new Event(
              Event.ADD,
              Constants.SITE,
              siteService.findSite(context).getID(),
              Constants.COMMUNITY,
              newCommunity.getID(),
              newCommunity.getHandle(),
              getIdentifiers(context, newCommunity)));
    }

    log.info(
        LogManager.getHeader(context, "create_community", "community_id=" + newCommunity.getID())
            + ",handle="
            + newCommunity.getHandle());

    return newCommunity;
  }