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