use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class AttributesManagerImpl method getAttributes.
@Override
public List<Attribute> getAttributes(PerunSession sess, Vo vo, List<String> attrNames) {
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 SingleBeanAttributeRowMapper<>(sess, this, vo));
} 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, UserExtSource ues, List<String> attrNames) {
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 user_ext_source_id=:uesId " + "where namespace in ( :nSC,:nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new SingleBeanAttributeRowMapper<>(sess, this, ues));
} 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 GroupsManagerImpl method getGroupMembers.
@Override
public List<Member> getGroupMembers(PerunSession sess, Group group, List<Status> statuses, boolean excludeStatus) {
try {
MapSqlParameterSource parameters = new MapSqlParameterSource();
List<Integer> statusesCodes = new ArrayList<>();
for (Status status : statuses) {
statusesCodes.add(status.getCode());
}
parameters.addValue("statuses", statusesCodes);
parameters.addValue("group_id", group.getId());
if (excludeStatus) {
// Exclude members with one of the status
return this.namedParameterJdbcTemplate.query("select " + MembersManagerImpl.groupsMembersMappingSelectQuery + " from groups_members join members on members.id=groups_members.member_id " + "where groups_members.group_id=:group_id and members.status not in (:statuses)", parameters, MembersManagerImpl.MEMBER_MAPPER_WITH_GROUP);
} else {
// Include members with one of the status
return this.namedParameterJdbcTemplate.query("select " + MembersManagerImpl.groupsMembersMappingSelectQuery + " from groups_members join members on members.id=groups_members.member_id " + "where groups_members.group_id=:group_id and members.status in (:statuses)", parameters, MembersManagerImpl.MEMBER_MAPPER_WITH_GROUP);
}
} catch (EmptyResultDataAccessException e) {
return new ArrayList<>();
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class GroupsManagerImpl method getAdmins.
@Override
public List<User> getAdmins(PerunSession sess, Group group) {
try {
// direct admins
Set<User> setOfAdmins = new HashSet<>(jdbc.query("select " + UsersManagerImpl.userMappingSelectQuery + " from authz join users on authz.user_id=users.id " + "where authz.group_id=? and authz.role_id=(select id from roles where name='groupadmin')", UsersManagerImpl.USER_MAPPER, group.getId()));
// admins through a group
List<Group> listOfGroupAdmins = getGroupAdmins(sess, group);
for (Group authorizedGroup : listOfGroupAdmins) {
setOfAdmins.addAll(jdbc.query("select " + UsersManagerImpl.userMappingSelectQuery + " from users join members on users.id=members.user_id " + "join groups_members on groups_members.member_id=members.id where groups_members.group_id=?", UsersManagerImpl.USER_MAPPER, authorizedGroup.getId()));
}
return new ArrayList(setOfAdmins);
} catch (EmptyResultDataAccessException e) {
return new ArrayList<>();
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class DatabaseManagerImpl method updateDatabaseVersion.
@Override
public void updateDatabaseVersion(List<DBVersion> dbVersions) {
Collections.reverse(dbVersions);
for (DBVersion v : dbVersions) {
log.debug("Executing update commands of version " + v.getVersion());
List<String> successfulCommands = new ArrayList<>();
for (String c : v.getCommands()) {
try {
jdbc.execute(c);
log.debug("Command executed: " + c);
successfulCommands.add(c);
} catch (EmptyResultDataAccessException ex) {
log.error("Update unsuccessful. All versions before " + v.getVersion() + " were successfully executed. " + "Error executing command in version " + v.getVersion() + ": " + c, ex);
log.error("Successful commands from " + v.getVersion() + ": " + successfulCommands);
throw new ConsistencyErrorException("Update unsuccessful. Error executing command in version " + v.getVersion() + ": " + c, ex);
} catch (RuntimeException ex) {
log.error("Update unsuccessful. All versions before " + v.getVersion() + " were successfully executed. " + "Error executing command in version " + v.getVersion() + ": " + c, ex);
log.error("Successful commands from " + v.getVersion() + ": " + successfulCommands);
throw new InternalErrorException("Update unsuccessful. Error executing command in version " + v.getVersion() + ": " + c, ex);
}
}
}
}
Aggregations