Beispiel #1
0
 private static Group createGroup(Map<String, String> beanAttr) {
   if (beanAttr == null) return null;
   Group group = new Group();
   if (beanAttr.get("parentGroupId").equals("\\0")) group.setParentGroupId(null);
   else group.setParentGroupId(Integer.valueOf(beanAttr.get("parentGroupId")));
   group.setId(Integer.valueOf(beanAttr.get("id")).intValue());
   group.setName(BeansUtils.eraseEscaping(beanAttr.get("name")));
   group.setDescription(BeansUtils.eraseEscaping(beanAttr.get("description")));
   group.setVoId(Integer.valueOf(beanAttr.get("voId")));
   return group;
 }
Beispiel #2
0
  public Group updateGroup(PerunSession sess, Group group) throws InternalErrorException {
    Utils.notNull(group.getName(), "group.getName()");

    // Get the group stored in the DB
    Group dbGroup;
    try {
      dbGroup = this.getGroupById(sess, group.getId());
    } catch (GroupNotExistsException e) {
      throw new InternalErrorException("Group existence was checked at the higher level", e);
    }

    // we allow only update on shortName part of name
    if (!dbGroup.getShortName().equals(group.getShortName())) {
      dbGroup.setShortName(group.getShortName());
      try {
        jdbc.update(
            "update groups set name=?,modified_by=?, modified_by_uid=?, modified_at="
                + Compatibility.getSysdate()
                + " where id=?",
            dbGroup.getName(),
            sess.getPerunPrincipal().getActor(),
            sess.getPerunPrincipal().getUserId(),
            dbGroup.getId());
      } catch (RuntimeException e) {
        throw new InternalErrorException(e);
      }
    }

    if (group.getDescription() != null
        && !group.getDescription().equals(dbGroup.getDescription())) {
      try {
        jdbc.update(
            "update groups set dsc=?, modified_by=?, modified_by_uid=?, modified_at="
                + Compatibility.getSysdate()
                + " where id=?",
            group.getDescription(),
            sess.getPerunPrincipal().getActor(),
            sess.getPerunPrincipal().getUserId(),
            group.getId());
      } catch (RuntimeException e) {
        throw new InternalErrorException(e);
      }
      dbGroup.setDescription(group.getDescription());
    }
    return dbGroup;
  }
Beispiel #3
0
 public Group mapRow(ResultSet rs, int i) throws SQLException {
   Group g = new Group();
   g.setId(rs.getInt("groups_id"));
   // ParentGroup with ID=0 is not supported
   if (rs.getInt("groups_parent_group_id") != 0)
     g.setParentGroupId(rs.getInt("groups_parent_group_id"));
   else g.setParentGroupId(null);
   g.setName(rs.getString("groups_name"));
   g.setShortName(g.getName().substring(g.getName().lastIndexOf(":") + 1));
   g.setDescription(rs.getString("groups_dsc"));
   g.setVoId(rs.getInt("groups_vo_id"));
   g.setCreatedAt(rs.getString("groups_created_at"));
   g.setCreatedBy(rs.getString("groups_created_by"));
   g.setModifiedAt(rs.getString("groups_modified_at"));
   g.setModifiedBy(rs.getString("groups_modified_by"));
   if (rs.getInt("groups_modified_by_uid") == 0) g.setModifiedByUid(null);
   else g.setModifiedByUid(rs.getInt("groups_modified_by_uid"));
   if (rs.getInt("groups_created_by_uid") == 0) g.setCreatedByUid(null);
   else g.setCreatedByUid(rs.getInt("groups_created_by_uid"));
   return g;
 }