Search in sources :

Example 61 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project summerb by skarpushin.

the class EasyCrudDaoMySqlImpl method findById.

@Override
public TDto findById(TId id) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("id", id);
    try {
        return jdbc.queryForObject(sqlFindById, params, rowMapper);
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 62 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project summerb by skarpushin.

the class EasyCrudDaoMySqlImpl method findOneByQuery.

@Override
public TDto findOneByQuery(Query query) {
    MapSqlParameterSource params = new MapSqlParameterSource();
    String whereClause = queryToNativeSqlCompiler.buildWhereClauseAndPopulateParams(query, params);
    try {
        return jdbc.queryForObject(sqlFindByCustomQuery + "WHERE " + whereClause, params, rowMapper);
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 63 with EmptyResultDataAccessException

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

the class urn_perun_user_attribute_def_virt_groupNames method getAttributeValue.

@Override
public Attribute getAttributeValue(PerunSessionImpl sess, User user, AttributeDefinition attributeDefinition) {
    Attribute attribute = new Attribute(attributeDefinition);
    Set<String> groupNames = new TreeSet<>();
    List<Pair<String, String>> names;
    try {
        names = sess.getPerunBl().getDatabaseManagerBl().getJdbcPerunTemplate().query("SELECT" + " DISTINCT vos.short_name AS vo_short_name, groups.name AS group_name" + " FROM" + " members" + " JOIN vos ON vos.id = members.vo_id AND members.user_id = ? AND members.status = ?" + " JOIN groups_members ON groups_members.member_id = members.id AND groups_members.source_group_status = ?" + " JOIN groups ON groups_members.group_id = groups.id" + " ORDER BY vo_short_name, group_name", ROW_MAPPER, user.getId(), Status.VALID.getCode(), MemberGroupStatus.VALID.getCode());
    } catch (EmptyResultDataAccessException e) {
        names = new ArrayList<>();
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
    for (Pair<String, String> one : names) {
        String voShortName = one.getLeft();
        groupNames.add(voShortName);
        if (!VosManager.MEMBERS_GROUP.equals(one.getRight())) {
            String groupName = one.getRight();
            groupNames.add(voShortName + ":" + groupName);
        }
    }
    attribute.setValue(new ArrayList<>(groupNames));
    return attribute;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) Pair(cz.metacentrum.perun.core.api.Pair)

Example 64 with EmptyResultDataAccessException

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

the class PerunNotifTemplateDaoImpl method getPerunNotifTemplateById.

@Override
public PerunNotifTemplate getPerunNotifTemplateById(int id) {
    PerunNotifTemplate template = null;
    try {
        template = this.getJdbcTemplate().queryForObject("SELECT * from pn_template where id = ?", new Object[] { id }, PerunNotifTemplate.PERUN_NOTIF_TEMPLATE);
    } catch (EmptyResultDataAccessException ex) {
        // This exception is thrown when object is not found
        return null;
    }
    Set<PerunNotifRegex> regexes = perunNotifRegexDao.getPerunNotifRegexForTemplateId(template.getId());
    template.setMatchingRegexs(regexes);
    List<PerunNotifReceiver> perunNotifReceiver = this.getJdbcTemplate().query("SELECT * from pn_receiver where template_id = ?", new Object[] { template.getId() }, PerunNotifReceiver.PERUN_NOTIF_RECEIVER);
    template.setReceivers(perunNotifReceiver);
    List<PerunNotifTemplateMessage> perunNotifTemplateMessages = this.getJdbcTemplate().query("SELECT * from pn_template_message where template_id = ?", new Object[] { template.getId() }, PerunNotifTemplateMessage.PERUN_NOTIF_TEMPLATE_MESSAGE_ROW_MAPPER);
    template.setPerunNotifTemplateMessages(perunNotifTemplateMessages);
    return template;
}
Also used : PerunNotifTemplate(cz.metacentrum.perun.notif.entities.PerunNotifTemplate) PerunNotifTemplateMessage(cz.metacentrum.perun.notif.entities.PerunNotifTemplateMessage) PerunNotifReceiver(cz.metacentrum.perun.notif.entities.PerunNotifReceiver) PerunNotifRegex(cz.metacentrum.perun.notif.entities.PerunNotifRegex) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 65 with EmptyResultDataAccessException

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

the class FacilitiesManagerImpl method getAdmins.

@Override
public List<User> getAdmins(PerunSession sess, Facility facility) {
    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.facility_id=? and authz.role_id=(select id from roles where name=?)", UsersManagerImpl.USER_MAPPER, facility.getId(), Role.FACILITYADMIN.toLowerCase()));
        // admins through a group
        List<Group> listOfGroupAdmins = getAdminGroups(sess, facility);
        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 : 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)

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