Search in sources :

Example 81 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, User user, Facility facility, List<String> attrNames) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("uId", user.getId());
    parameters.addValue("fId", facility.getId());
    parameters.addValue("nSO", AttributesManager.NS_USER_FACILITY_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_USER_FACILITY_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_USER_FACILITY_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("user_fac") + " from attr_names " + "left join user_facility_attr_values user_fac on id=user_fac.attr_id and user_id=:uId and facility_id=:fId " + "where namespace in ( :nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new UserFacilityAttributeRowMapper(sess, this, user, facility));
    } 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 82 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, Resource resource, List<Integer> serviceIds) {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("serviceIds", serviceIds);
    try {
        List<String> namespace = new ArrayList<>();
        namespace.add(AttributesManager.NS_RESOURCE_ATTR_DEF);
        namespace.add(AttributesManager.NS_RESOURCE_ATTR_CORE);
        namespace.add(AttributesManager.NS_RESOURCE_ATTR_OPT);
        namespace.add(AttributesManager.NS_RESOURCE_ATTR_VIRT);
        parameters.addValue("resourceId", resource.getId());
        parameters.addValue("namespace", namespace);
        return this.namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("resource_attr_values") + " from attr_names " + "join service_required_attrs on id=service_required_attrs.attr_id and service_required_attrs.service_id in (:serviceIds) " + "left join resource_attr_values on id=resource_attr_values.attr_id and resource_attr_values.resource_id=:resourceId " + "where namespace in (:namespace)", parameters, new SingleBeanAttributeRowMapper<>(sess, this, resource));
    } catch (EmptyResultDataAccessException ex) {
        log.debug("None required attributes found for resource: {} and services with id {}.", resource, serviceIds);
        return new ArrayList<>();
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : 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 83 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, Resource resource, Group group) {
    try {
        MapSqlParameterSource parameters = new MapSqlParameterSource();
        List<String> namespace = new ArrayList<>();
        namespace.add(AttributesManager.NS_GROUP_RESOURCE_ATTR_DEF);
        namespace.add(AttributesManager.NS_GROUP_RESOURCE_ATTR_OPT);
        namespace.add(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT);
        parameters.addValue("serviceIds", services.stream().map(Service::getId).collect(Collectors.toList()));
        parameters.addValue("groupId", group.getId());
        parameters.addValue("resourceId", resource.getId());
        parameters.addValue("namespaces", namespace);
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("grp_res") + " 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_resource_attr_values     grp_res     on id=grp_res.attr_id     and   group_id=:groupId and resource_id=:resourceId " + "where namespace in (:namespaces)", 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) 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 84 with EmptyResultDataAccessException

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

the class PerunNotifObjectDaoImpl method getPerunNotifObjectById.

@Override
public PerunNotifObject getPerunNotifObjectById(int id) {
    logger.debug("Getting PerunNotifObject from db by id: {}", id);
    try {
        PerunNotifObject object = this.getJdbcTemplate().queryForObject("SELECT * FROM pn_object object where object.id = ?", new Object[] { id }, PerunNotifObject.PERUN_NOTIF_OBJECT);
        logger.debug("PerunNotifObject retrieved from db: {}", object);
        return object;
    } catch (EmptyResultDataAccessException ex) {
        logger.debug("PerunNotifObject with id: {} not found.", id);
        return null;
    }
}
Also used : EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) PerunNotifObject(cz.metacentrum.perun.notif.entities.PerunNotifObject)

Example 85 with EmptyResultDataAccessException

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

the class PerunNotifObjectDaoImpl method isObjectRelation.

@Override
public boolean isObjectRelation(int templateId, Integer objectId) {
    logger.debug("IsObjectRelation for templateId: {}, objectId: {}", Arrays.asList(templateId, objectId));
    try {
        SqlRowSet rowSet = this.getJdbcTemplate().queryForRowSet("select * from pn_regex_object where regex_id = ? AND object_id = ?", templateId, objectId);
        logger.debug("Relation between templateId: {} and objectId: {}, found.", Arrays.asList(templateId, objectId));
        return rowSet.next();
    } catch (EmptyResultDataAccessException ex) {
        // This exception signals empty row
        logger.debug("Relation between templateId: {}, and objectId: {}, not found", Arrays.asList(templateId, objectId));
        return false;
    }
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) 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