Search in sources :

Example 26 with EmptyResultDataAccessException

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

the class AttributesManagerImpl method getAttributes.

public List<Attribute> getAttributes(PerunSession sess, Vo vo, List<String> attrNames) throws InternalErrorException {
    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 AttributeRowMapper(sess, this, vo));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<Attribute>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 27 with EmptyResultDataAccessException

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

the class DatabaseManagerImpl method updateDatabaseVersion.

public void updateDatabaseVersion(List<DBVersion> dbVersions) throws InternalErrorException {
    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)

Example 28 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.

the class UserRepository method findUserByNickname.

public User findUserByNickname(String nickname) {
    String query = "SELECT * FROM User WHERE nickname = ?";
    List<User> resultUser;
    try {
        resultUser = jdbcTemplate.query(query, (rs, rowNum) -> {
            User user = new User();
            user.setId(rs.getLong("id"));
            user.setEmail(rs.getString("email"));
            user.setPassword(rs.getString("password"));
            user.setNickname(rs.getString("nickname"));
            return user;
        }, nickname);
    } catch (EmptyResultDataAccessException e) {
        log.error(e.getMessage());
        return null;
    }
    return resultUser.size() > 0 ? resultUser.get(0) : null;
}
Also used : List(java.util.List) User(com.mapia.domain.User) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Repository(org.springframework.stereotype.Repository) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) User(com.mapia.domain.User) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 29 with EmptyResultDataAccessException

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

the class VosManagerImpl method getAdmins.

@Deprecated
@Override
public List<User> getAdmins(PerunSession sess, Vo vo) 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='voadmin')", UsersManagerImpl.USER_MAPPER, vo.getId()));
        // admins through a group
        List<Group> listOfGroupAdmins = getAdminGroups(sess, vo);
        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);
    }
}
Also used : 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 30 with EmptyResultDataAccessException

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

the class UsersManagerImpl method getUserExtsourcesByIds.

public List<UserExtSource> getUserExtsourcesByIds(PerunSession sess, List<Integer> ids) throws InternalErrorException {
    if (ids.size() == 0) {
        return new ArrayList<UserExtSource>();
    }
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", ids);
    try {
        return namedParameterJdbcTemplate.query("select " + userExtSourceMappingSelectQuery + "," + ExtSourcesManagerImpl.extSourceMappingSelectQuery + " from user_ext_sources left join ext_sources on user_ext_sources.ext_sources_id=ext_sources.id where" + " user_ext_sources.id in ( :ids )", parameters, USEREXTSOURCE_MAPPER);
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<UserExtSource>();
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Aggregations

EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)47 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)20 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)19 Attribute (cz.metacentrum.perun.core.api.Attribute)10 ConsistencyErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException)10 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)10 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)9 ArrayList (java.util.ArrayList)9 User (cz.metacentrum.perun.core.api.User)6 SQLException (java.sql.SQLException)6 Group (cz.metacentrum.perun.core.api.Group)5 HashSet (java.util.HashSet)5 ResultSet (java.sql.ResultSet)4 RowMapper (org.springframework.jdbc.core.RowMapper)4 Member (cz.metacentrum.perun.core.api.Member)3 User (com.mapia.domain.User)2 UserMetadataServiceException (com.netflix.metacat.common.server.usermetadata.UserMetadataServiceException)2 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)2 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)2 PerunNotifObject (cz.metacentrum.perun.notif.entities.PerunNotifObject)2