コード例 #1
0
ファイル: GroupsManagerImpl.java プロジェクト: Holdo/perun
 public int getGroupsCount(PerunSession sess, Vo vo) throws InternalErrorException {
   try {
     return jdbc.queryForInt("select count(1) from groups where vo_id=?", vo.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
コード例 #2
0
ファイル: GroupsManagerImpl.java プロジェクト: Holdo/perun
 public int getGroupsCount(PerunSession sess) throws InternalErrorException {
   try {
     return jdbc.queryForInt("select count(*) from groups");
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
コード例 #3
0
ファイル: GroupsManagerImpl.java プロジェクト: Holdo/perun
 public int getVoId(PerunSession sess, Group group) throws InternalErrorException {
   try {
     return jdbc.queryForInt("select vo_id from groups where id=?", group.getId());
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
コード例 #4
0
ファイル: GroupsManagerImpl.java プロジェクト: Holdo/perun
 public int getSubGroupsCount(PerunSession sess, Group parentGroup) throws InternalErrorException {
   try {
     return jdbc.queryForInt(
         "select count(1) from groups where parent_group_id=?", parentGroup.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
コード例 #5
0
ファイル: GroupsManagerImpl.java プロジェクト: Holdo/perun
 public boolean groupExists(PerunSession sess, Group group) throws InternalErrorException {
   try {
     return 1 == jdbc.queryForInt("select 1 from groups where id=?", group.getId());
   } catch (EmptyResultDataAccessException ex) {
     return false;
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
コード例 #6
0
ファイル: GroupsManagerImpl.java プロジェクト: Holdo/perun
 public boolean isGroupMember(PerunSession sess, Group group, Member member)
     throws InternalErrorException {
   try {
     return 1
         <= jdbc.queryForInt(
             "select count(1) from groups_members where group_id=? and member_id=?",
             group.getId(),
             member.getId());
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
コード例 #7
0
ファイル: GroupsManagerImpl.java プロジェクト: Holdo/perun
 public boolean isUserMemberOfGroup(PerunSession sess, User user, Group group)
     throws InternalErrorException {
   try {
     return 1
         <= jdbc.queryForInt(
             "select count(1) from groups_members join members on members.id = member_id where members.user_id=? and groups_members.group_id=?",
             user.getId(),
             group.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
コード例 #8
0
ファイル: GroupsManagerImpl.java プロジェクト: Holdo/perun
 public boolean isDirectGroupMember(PerunSession sess, Group group, Member member)
     throws InternalErrorException {
   try {
     int count =
         jdbc.queryForInt(
             "select count(1) from groups_members where group_id=? and member_id=? and membership_type = ?",
             group.getId(),
             member.getId(),
             MembershipType.DIRECT.getCode());
     if (1 < count)
       throw new ConsistencyErrorException(
           "There is more than one direct member in group" + group);
     return 1 == count;
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
コード例 #9
0
ファイル: GroupsManagerImpl.java プロジェクト: Holdo/perun
  public Group createGroup(PerunSession sess, Vo vo, Group group)
      throws GroupExistsException, InternalErrorException {
    Utils.notNull(group, "group");
    Utils.notNull(group.getName(), "group.getName()");

    // Check if the group already exists
    if (group.getParentGroupId() == null) {
      if (1
          == jdbc.queryForInt(
              "select count('x') from groups where lower(name)=lower(?) and vo_id=? and parent_group_id IS NULL",
              group.getName(),
              vo.getId())) {
        throw new GroupExistsException(
            "Group ["
                + group.getName()
                + "] already exists under VO ["
                + vo.getShortName()
                + "] and has parent Group with id is [NULL]");
      }
    } else {
      if (1
          == jdbc.queryForInt(
              "select count('x') from groups where lower(name)=lower(?) and vo_id=? and parent_group_id=?",
              group.getName(),
              vo.getId(),
              group.getParentGroupId())) {
        throw new GroupExistsException(
            "Group ["
                + group.getName()
                + "] already exists under VO ["
                + vo.getShortName()
                + "] and has parent Group with id ["
                + group.getParentGroupId()
                + "]");
      }
    }

    // Check the group name, it can contain only a-Z0-9_- and space
    if (!group.getShortName().matches("^[- a-zA-Z.0-9_]+$")) {
      throw new InternalErrorException(
          new IllegalArgumentException(
              "Wrong group name, group name can contain only a-Z0-9.-_: and space characters. "
                  + group));
    }

    try {
      // Store the group into the DB
      int newId = Utils.getNewId(jdbc, "groups_id_seq");

      jdbc.update(
          "insert into groups (id, parent_group_id, name, dsc, vo_id, created_by,created_at,modified_by,modified_at,created_by_uid,modified_by_uid) "
              + "values (?,?,?,?,?,?,"
              + Compatibility.getSysdate()
              + ",?,"
              + Compatibility.getSysdate()
              + ",?,?)",
          newId,
          group.getParentGroupId(),
          group.getName(),
          group.getDescription(),
          vo.getId(),
          sess.getPerunPrincipal().getActor(),
          sess.getPerunPrincipal().getActor(),
          sess.getPerunPrincipal().getUserId(),
          sess.getPerunPrincipal().getUserId());
      group.setId(newId);

      group.setVoId(vo.getId());

      return group;
    } catch (RuntimeException err) {
      throw new InternalErrorException(err);
    }
  }