Search in sources :

Example 91 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) {
    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.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<>();
    } 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 92 with EmptyResultDataAccessException

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

the class ResourcesManagerImpl method getAssignedResourcesWithStatus.

@Override
public List<AssignedResource> getAssignedResourcesWithStatus(PerunSession sess, Member member) {
    try {
        List<AssignedResource> resources = jdbc.query("select distinct " + assignedResourceMappingSelectQuery + " from resources" + " join (SELECT group_id, resource_id, NULL as source_group_id, auto_assign_subgroups FROM groups_resources" + "	UNION" + "	SELECT group_id, resource_id, source_group_id, true as auto_assign_subgroups FROM groups_resources_automatic)" + " 	groups_resources_automatic on groups_resources_automatic.resource_id = resources.id" + " join groups_resources_state on groups_resources_automatic.resource_id=groups_resources_state.resource_id and groups_resources_automatic.group_id=groups_resources_state.group_id" + " join facilities on resources.facility_id=facilities.id" + " join groups on groups_resources_state.group_id=groups.id" + " join groups_members on groups.id=groups_members.group_id" + " where groups_members.member_id=?", ASSIGNED_RESOURCE_MAPPER, member.getId());
        resources.removeIf(r1 -> resources.stream().anyMatch(r2 -> r2.getEnrichedResource().equals(r1.getEnrichedResource()) && r2.getStatus().isMoreImportantThan(r1.getStatus())));
        return resources;
    } catch (EmptyResultDataAccessException e) {
        return new ArrayList<>();
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) JdbcPerunTemplate(org.springframework.jdbc.core.JdbcPerunTemplate) Arrays(java.util.Arrays) ResourceTag(cz.metacentrum.perun.core.api.ResourceTag) Vo(cz.metacentrum.perun.core.api.Vo) ServiceNotAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceNotAssignedException) LoggerFactory(org.slf4j.LoggerFactory) GroupResourceAssignment(cz.metacentrum.perun.core.api.GroupResourceAssignment) Array(java.sql.Array) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) ResultSet(java.sql.ResultSet) Map(java.util.Map) Role(cz.metacentrum.perun.core.api.Role) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource) MemberGroupStatus(cz.metacentrum.perun.core.api.MemberGroupStatus) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) Attribute(cz.metacentrum.perun.core.api.Attribute) Facility(cz.metacentrum.perun.core.api.Facility) GroupResourceStatus(cz.metacentrum.perun.core.api.GroupResourceStatus) PreparedStatementCallback(org.springframework.jdbc.core.PreparedStatementCallback) BeansUtils(cz.metacentrum.perun.core.api.BeansUtils) ResourceAlreadyRemovedException(cz.metacentrum.perun.core.api.exceptions.ResourceAlreadyRemovedException) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) User(cz.metacentrum.perun.core.api.User) List(java.util.List) RowMapper(org.springframework.jdbc.core.RowMapper) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Service(cz.metacentrum.perun.core.api.Service) Resource(cz.metacentrum.perun.core.api.Resource) PerunSession(cz.metacentrum.perun.core.api.PerunSession) ObjectUtils.isEmpty(org.apache.commons.lang3.ObjectUtils.isEmpty) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) HashMap(java.util.HashMap) Group(cz.metacentrum.perun.core.api.Group) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SQLException(java.sql.SQLException) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) DataSource(javax.sql.DataSource) AuthzResolverBlImpl(cz.metacentrum.perun.core.blImpl.AuthzResolverBlImpl) BanOnResource(cz.metacentrum.perun.core.api.BanOnResource) MEMBER_MAPPER(cz.metacentrum.perun.core.impl.MembersManagerImpl.MEMBER_MAPPER) RichResource(cz.metacentrum.perun.core.api.RichResource) ServiceAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.ServiceAlreadyAssignedException) Member(cz.metacentrum.perun.core.api.Member) Logger(org.slf4j.Logger) DatabaseManagerBl(cz.metacentrum.perun.core.bl.DatabaseManagerBl) ResourceNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceNotExistsException) BanNotExistsException(cz.metacentrum.perun.core.api.exceptions.BanNotExistsException) EnrichedResource(cz.metacentrum.perun.core.api.EnrichedResource) ResourcesManagerImplApi(cz.metacentrum.perun.core.implApi.ResourcesManagerImplApi) Status(cz.metacentrum.perun.core.api.Status) ResourceTagNotExistsException(cz.metacentrum.perun.core.api.exceptions.ResourceTagNotExistsException) ResultSetExtractor(org.springframework.jdbc.core.ResultSetExtractor) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AssignedResource(cz.metacentrum.perun.core.api.AssignedResource)

Example 93 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project dhis2-core by dhis2.

the class AttributeOptionComboLoader method loadCategoryOptionCombo.

/**
 * Fetches a {@see CategoryOptionCombo} by "id" (based on the provided
 * IdScheme)
 *
 * The {@see CategoryOptionCombo} contains tha associated
 * {@see CategoryCombo} and all the associated {@see CategoryOption}
 *
 * @param idScheme a {@see IdScheme}
 * @param id the {@see CategoryOptionCombo} id to use
 * @return a {@see CategoryOptionCombo} or null
 */
private CategoryOptionCombo loadCategoryOptionCombo(IdScheme idScheme, String id) {
    String key = "categoryoptioncomboid";
    StringSubstitutor sub = new StringSubstitutor(ImmutableMap.<String, String>builder().put("key", key).put("resolvedScheme", Objects.requireNonNull(resolveId(idScheme, key, id))).build());
    try {
        return jdbcTemplate.queryForObject(sub.replace(SQL_GET_CATEGORYOPTIONCOMBO), (rs, i) -> bind(key, rs));
    } catch (EmptyResultDataAccessException e) {
        return null;
    }
}
Also used : StringSubstitutor(org.apache.commons.text.StringSubstitutor) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

Example 94 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 95 with EmptyResultDataAccessException

use of org.springframework.dao.EmptyResultDataAccessException in project cas by apereo.

the class JdbcPasswordManagementService method findEmail.

@Override
public String findEmail(final PasswordManagementQuery query) {
    val queryFindEmail = properties.getJdbc().getSqlFindEmail();
    if (StringUtils.isBlank(queryFindEmail)) {
        LOGGER.debug("No SQL query is defined to retrieve email addresses");
        return null;
    }
    try {
        return this.transactionTemplate.execute(action -> {
            val email = this.jdbcTemplate.queryForObject(queryFindEmail, String.class, query.getUsername());
            if (StringUtils.isNotBlank(email) && EmailValidator.getInstance().isValid(email)) {
                return email;
            }
            LOGGER.debug("Username [{}] not found when searching for email", query.getUsername());
            return null;
        });
    } catch (final EmptyResultDataAccessException e) {
        LOGGER.debug("Username [{}] not found when searching for email", query.getUsername());
        return null;
    }
}
Also used : lombok.val(lombok.val) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException)

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