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);
}
}
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);
}
}
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);
}
}
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;
}
}
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;
}
}
Aggregations