Search in sources :

Example 31 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.

the class AttributesManagerImpl method getRequiredAttributes.

public List<Attribute> getRequiredAttributes(PerunSession sess, Resource resource, List<Integer> serviceIds) throws InternalErrorException {
    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);
        MapSqlParameterSource parameters = new MapSqlParameterSource();
        parameters.addValue("serviceIds", serviceIds);
        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 AttributeRowMapper(sess, this, resource));
    } catch (EmptyResultDataAccessException ex) {
        log.debug("None required attributes found for resource: {} and services with id {} ", resource, serviceIds);
        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 32 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.

the class AttributesManagerImpl method getAttributes.

public List<Attribute> getAttributes(PerunSession sess, UserExtSource ues, List<String> attrNames) throws InternalErrorException {
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("uesId", ues.getId());
    parameters.addValue("nSC", AttributesManager.NS_UES_ATTR_CORE);
    parameters.addValue("nSO", AttributesManager.NS_UES_ATTR_OPT);
    parameters.addValue("nSD", AttributesManager.NS_UES_ATTR_DEF);
    parameters.addValue("nSV", AttributesManager.NS_UES_ATTR_VIRT);
    parameters.addValue("attrNames", attrNames);
    try {
        return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("ues") + " from attr_names " + "left join user_ext_source_attr_values ues on id=ues.attr_id and ues_id=:uesId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, ues));
    } 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 33 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource 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 34 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project perun by CESNET.

the class ResourcesManagerImpl method getResourcesByIds.

public List<Resource> getResourcesByIds(PerunSession sess, List<Integer> resourcesIds) throws InternalErrorException {
    if (resourcesIds.size() == 0) {
        return new ArrayList<Resource>();
    }
    MapSqlParameterSource parameters = new MapSqlParameterSource();
    parameters.addValue("ids", resourcesIds);
    try {
        return this.namedParameterJdbcTemplate.query("select " + resourceMappingSelectQuery + "  from resources where resources.id in ( :ids )", parameters, RESOURCE_MAPPER);
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 35 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource 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

MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)51 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)20 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)15 Attribute (cz.metacentrum.perun.core.api.Attribute)10 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)9 ConsistencyErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException)9 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)9 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)6 SimpleJdbcInsert (org.springframework.jdbc.core.simple.SimpleJdbcInsert)4 Member (cz.metacentrum.perun.core.api.Member)3 HashMap (java.util.HashMap)3 SqlOutParameter (org.springframework.jdbc.core.SqlOutParameter)3 SqlParameter (org.springframework.jdbc.core.SqlParameter)3 ParsedSql (org.springframework.jdbc.core.namedparam.ParsedSql)3 User (cz.metacentrum.perun.core.api.User)2 IOException (java.io.IOException)2 ResultSet (java.sql.ResultSet)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2