Search in sources :

Example 71 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class AttributesManagerImpl method getAttributes.

@Override
public List<Attribute> getAttributes(PerunSession sess, Vo vo, List<String> attrNames) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("vId", vo.getId());
    parameters.addValue("nSC", AttributesManager.NS_VO_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_VO_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_VO_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_VO_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("vot") + " from attr_names " + "left join vo_attr_values vot on id=vot.attr_id and vo_id=:vId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new SingleBeanAttributeRowMapper<>(sess, this, vo));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 72 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class AttributesManagerImpl method getAttributes.

@Override
public List<Attribute> getAttributes(PerunSession sess, UserExtSource ues, List<String> attrNames) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("uesId", ues.getId());
    parameters.addValue("nSC", AttributesManager.NS_UES_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_UES_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_UES_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_UES_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("ues") + " from attr_names " + "left join user_ext_source_attr_values ues on id=ues.attr_id and user_ext_source_id=:uesId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new SingleBeanAttributeRowMapper<>(sess, this, ues));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 73 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class GroupsManagerImpl method getGroupMembers.

@Override
public List<Member> getGroupMembers(PerunSession sess, Group group, List<Status> statuses, boolean excludeStatus) {
    try {
        MapSqlParameterSource parameters = new MapSqlParameterSource();
        List<Integer> statusesCodes = new ArrayList<>();
        for (Status status : statuses) {
            statusesCodes.add(status.getCode());
        }
        parameters.addValue("statuses", statusesCodes);
        parameters.addValue("group_id", group.getId());
        if (excludeStatus) {
            // Exclude members with one of the status
            return this.namedParameterJdbcTemplate.query("select " + MembersManagerImpl.groupsMembersMappingSelectQuery + " from groups_members join members on members.id=groups_members.member_id " + "where groups_members.group_id=:group_id and members.status not in (:statuses)", parameters, MembersManagerImpl.MEMBER_MAPPER_WITH_GROUP);
        } else {
            // Include members with one of the status
            return this.namedParameterJdbcTemplate.query("select " + MembersManagerImpl.groupsMembersMappingSelectQuery + " from groups_members join members on members.id=groups_members.member_id " + "where groups_members.group_id=:group_id and members.status in (:statuses)", parameters, MembersManagerImpl.MEMBER_MAPPER_WITH_GROUP);
        }
    } catch (EmptyResultDataAccessException e) {
        return new ArrayList<>();
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) GroupResourceStatus(cz.metacentrum.perun.core.api.GroupResourceStatus) Status(cz.metacentrum.perun.core.api.Status) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 74 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class GroupsManagerImpl method getAdmins.

@Override
public List<User> getAdmins(PerunSession sess, Group group) {
    try {
        // direct admins
        Set<User> setOfAdmins = new HashSet<>(jdbc.query("select " + UsersManagerImpl.userMappingSelectQuery + " from authz join users on authz.user_id=users.id " + "where authz.group_id=? and authz.role_id=(select id from roles where name='groupadmin')", UsersManagerImpl.USER_MAPPER, group.getId()));
        // admins through a group
        List<Group> listOfGroupAdmins = getGroupAdmins(sess, group);
        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);
    }
}
Also used : EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) Group(cz.metacentrum.perun.core.api.Group) User(cz.metacentrum.perun.core.api.User) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) HashSet(java.util.HashSet)

Example 75 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.

the class DatabaseManagerImpl method updateDatabaseVersion.

@Override
public void updateDatabaseVersion(List<DBVersion> dbVersions) {
    Collections.reverse(dbVersions);
    for (DBVersion v : dbVersions) {
        log.debug("Executing update commands of version " + v.getVersion());
        List<String> successfulCommands = new ArrayList<>();
        for (String c : v.getCommands()) {
            try {
                jdbc.execute(c);
                log.debug("Command executed: " + c);
                successfulCommands.add(c);
            } catch (EmptyResultDataAccessException ex) {
                log.error("Update unsuccessful. All versions before " + v.getVersion() + " were successfully executed. " + "Error executing command in version " + v.getVersion() + ": " + c, ex);
                log.error("Successful commands from " + v.getVersion() + ": " + successfulCommands);
                throw new ConsistencyErrorException("Update unsuccessful. Error executing command in version " + v.getVersion() + ": " + c, ex);
            } catch (RuntimeException ex) {
                log.error("Update unsuccessful. All versions before " + v.getVersion() + " were successfully executed. " + "Error executing command in version " + v.getVersion() + ": " + c, ex);
                log.error("Successful commands from " + v.getVersion() + ": " + successfulCommands);
                throw new InternalErrorException("Update unsuccessful. Error executing command in version " + v.getVersion() + ": " + c, ex);
            }
        }
    }
}
Also used : DBVersion(cz.metacentrum.perun.core.api.DBVersion) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Aggregations

EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)99 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)46 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)31 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)9 Transactional (org.springframework.transaction.annotation.Transactional)9 Group (cz.metacentrum.perun.core.api.Group)8 User (cz.metacentrum.perun.core.api.User)8 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)7 SQLException (java.sql.SQLException)7 Test (org.junit.Test)6 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)6 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Service (cz.metacentrum.perun.core.api.Service)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)3