Search in sources :

Example 66 with EmptyResultDataAccessException

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

the class MembersManagerImpl method getMembersByUsers.

@Override
public List<Member> getMembersByUsers(PerunSession sess, List<User> users, Vo vo) {
    // If usersIds is empty, we can immediatelly return empty results
    if (users.size() == 0) {
        return new ArrayList<>();
    }
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    Set<Integer> usersIds = new HashSet<>();
    for (User user : users) {
        usersIds.add(user.getId());
    }
    parameters.addValue("ids", usersIds);
    parameters.addValue("vo", vo.getId());
    try {
        return this.namedParameterJdbcTemplate.query("SELECT " + memberMappingSelectQuery + " FROM members WHERE members.user_id IN ( :ids ) AND members.vo_id=:vo", parameters, MEMBER_MAPPER);
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) 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 67 with EmptyResultDataAccessException

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

the class AttributesManagerImpl method getRequiredAttributes.

@Override
public List<Attribute> getRequiredAttributes(PerunSession sess, List<Service> services, Group group) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    List<String> namespace = new ArrayList<>();
    namespace.add(AttributesManager.NS_GROUP_ATTR_CORE);
    namespace.add(AttributesManager.NS_GROUP_ATTR_DEF);
    namespace.add(AttributesManager.NS_GROUP_ATTR_OPT);
    namespace.add(AttributesManager.NS_GROUP_ATTR_VIRT);
    parameters.addValue("serviceIds", services.stream().map(Service::getId).collect(Collectors.toList()));
    parameters.addValue("groupId", group.getId());
    parameters.addValue("namespaces", namespace);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("grp") + " from attr_names " + "join service_required_attrs on id=service_required_attrs.attr_id and service_required_attrs.service_id in (:serviceIds) " + "left join      group_attr_values    grp   on      id=grp.attr_id    and  group_id=:groupId " + "where namespace in (:namespaces)", parameters, new SingleBeanAttributeRowMapper<>(sess, this, group));
    } catch (EmptyResultDataAccessException ex) {
        return new ArrayList<>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ArrayList(java.util.ArrayList) Service(cz.metacentrum.perun.core.api.Service) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 68 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, Resource resource, Group group, List<String> attrNames) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("gId", group.getId());
    parameters.addValue("rId", resource.getId());
    parameters.addValue("nSO", AttributesManager.NS_GROUP_RESOURCE_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_GROUP_RESOURCE_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("grp_res") + " from attr_names " + "left join group_resource_attr_values grp_res on id=grp_res.attr_id and group_id=:gId and resource_id=:rId " + "where namespace in ( :nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new GroupResourceAttributeRowMapper(sess, this, group, resource));
    } 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 69 with EmptyResultDataAccessException

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

the class AttributesManagerImpl method getEntitylessStringAttributeMapping.

@Override
public Map<String, String> getEntitylessStringAttributeMapping(PerunSession sess, String attributeName) throws AttributeNotExistsException {
    try {
        Map<String, String> map = new HashMap<>();
        jdbc.query("select subject, attr_value " + " from attr_names join entityless_attr_values on id=attr_id " + " where type='java.lang.String' and attr_name=?", rs -> {
            map.put(rs.getString(1), rs.getString(2));
        }, attributeName);
        return map;
    } catch (EmptyResultDataAccessException ex) {
        throw new AttributeNotExistsException("Attribute name: \"" + attributeName + "\"", ex);
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 70 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, Resource resource, List<String> attrNames) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("rId", resource.getId());
    parameters.addValue("nSC", AttributesManager.NS_RESOURCE_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_RESOURCE_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_RESOURCE_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_RESOURCE_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("resattr") + " from attr_names " + "left join resource_attr_values resattr on id=resattr.attr_id and resource_id=:rId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new SingleBeanAttributeRowMapper<>(sess, this, resource));
    } 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)

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