use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class VosManagerImpl method getAdmins.
public List<User> getAdmins(PerunSession sess, Vo vo, Role role) throws InternalErrorException {
try {
Set<User> setOfAdmins = new HashSet<User>();
// direct admins
setOfAdmins.addAll(jdbc.query("select " + UsersManagerImpl.userMappingSelectQuery + " from authz join users on authz.user_id=users.id " + "where authz.vo_id=? and authz.role_id=(select id from roles where name=?)", UsersManagerImpl.USER_MAPPER, vo.getId(), role.getRoleName()));
// admins through a group
List<Group> listOfGroupAdmins = getAdminGroups(sess, vo, role);
for (Group group : listOfGroupAdmins) {
setOfAdmins.addAll(jdbc.query("select " + UsersManagerImpl.userMappingSelectQuery + " from users join members on users.id=members.user_id " + "join groups_members on groups_members.member_id=members.id where groups_members.group_id=?", UsersManagerImpl.USER_MAPPER, group.getId()));
}
return new ArrayList(setOfAdmins);
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<User>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class GroupsManagerImpl method getName.
public String getName(int id) throws InternalErrorException {
List name = null;
try {
name = jdbc.query("group.name as (with temp (name, id, parent_group_id) as ((select name, id, parent_group_id from GROUPS where parent_group_id is null) union all (select cast((temp.name + ':' + groups.name) as varchar(128)), " + "groups.id, groups.parent_group_id from groups inner join temp on temp.id = groups.parent_group_id )) select name from temp where group.id = ?", new RowMapper() {
public Object mapRow(ResultSet resultSet, int i) throws SQLException {
return resultSet.getString(1);
}
}, id);
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
String result = (String) name.get(0);
return result;
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class GroupsManagerImpl method createGroup.
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) {
// check if the TOP level group exists
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 {
// check if subgroup exists under parent group
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);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class GroupsManagerImpl method getGroupsByIds.
public List<Group> getGroupsByIds(PerunSession sess, List<Integer> groupsIds) throws InternalErrorException {
// If groupsIds are empty, we can immediately return empty result
if (groupsIds.size() == 0) {
return new ArrayList<Group>();
}
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("ids", groupsIds);
try {
return this.namedParameterJdbcTemplate.query("select " + groupMappingSelectQuery + " from groups where groups.id in ( :ids )", parameters, GROUP_MAPPER);
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<Group>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class ResourcesManagerImpl method getAdmins.
public List<User> getAdmins(PerunSession sess, Resource resource) throws InternalErrorException {
try {
Set<User> setOfAdmins = new HashSet<>();
// Direct admins
setOfAdmins.addAll(jdbc.query("select " + UsersManagerImpl.userMappingSelectQuery + " from authz join users on authz.user_id=users.id" + " where authz.resource_id=? and authz.role_id=(select id from roles where name=?)", UsersManagerImpl.USER_MAPPER, resource.getId(), Role.RESOURCEADMIN.getRoleName()));
// Admins through a group
List<Group> listOfGroupAdmins = getAdminGroups(sess, resource);
for (Group authorizedGroup : listOfGroupAdmins) {
setOfAdmins.addAll(jdbc.query("select " + UsersManagerImpl.userMappingSelectQuery + " from users join members on users.id=members.user_id " + "join groups_members on groups_members.member_id=members.id where groups_members.group_id=?", UsersManagerImpl.USER_MAPPER, authorizedGroup.getId()));
}
return new ArrayList(setOfAdmins);
} catch (EmptyResultDataAccessException e) {
return new ArrayList<>();
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
Aggregations