use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class VosManagerImpl method getAdmins.
@Deprecated
@Override
public List<User> getAdmins(PerunSession sess, Vo vo) {
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.vo_id=? and authz.role_id=(select id from roles where name='voadmin')", UsersManagerImpl.USER_MAPPER, vo.getId()));
// admins through a group
List<Group> listOfGroupAdmins = getAdminGroups(sess, vo);
for (Group group : 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, group.getId()));
}
return new ArrayList(setOfAdmins);
} 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 ResourcesManagerImpl method getAssignedResourcesWithStatus.
@Override
public List<AssignedResource> getAssignedResourcesWithStatus(PerunSession sess, Member member) {
try {
List<AssignedResource> resources = jdbc.query("select distinct " + assignedResourceMappingSelectQuery + " from resources" + " join (SELECT group_id, resource_id, NULL as source_group_id, auto_assign_subgroups FROM groups_resources" + " UNION" + " SELECT group_id, resource_id, source_group_id, true as auto_assign_subgroups FROM groups_resources_automatic)" + " groups_resources_automatic on groups_resources_automatic.resource_id = resources.id" + " join groups_resources_state on groups_resources_automatic.resource_id=groups_resources_state.resource_id and groups_resources_automatic.group_id=groups_resources_state.group_id" + " join facilities on resources.facility_id=facilities.id" + " join groups on groups_resources_state.group_id=groups.id" + " join groups_members on groups.id=groups_members.group_id" + " where groups_members.member_id=?", ASSIGNED_RESOURCE_MAPPER, member.getId());
resources.removeIf(r1 -> resources.stream().anyMatch(r2 -> r2.getEnrichedResource().equals(r1.getEnrichedResource()) && r2.getStatus().isMoreImportantThan(r1.getStatus())));
return resources;
} catch (EmptyResultDataAccessException e) {
return new ArrayList<>();
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project dhis2-core by dhis2.
the class AttributeOptionComboLoader method loadCategoryOptionCombo.
/**
* Fetches a {@see CategoryOptionCombo} by "id" (based on the provided
* IdScheme)
*
* The {@see CategoryOptionCombo} contains tha associated
* {@see CategoryCombo} and all the associated {@see CategoryOption}
*
* @param idScheme a {@see IdScheme}
* @param id the {@see CategoryOptionCombo} id to use
* @return a {@see CategoryOptionCombo} or null
*/
private CategoryOptionCombo loadCategoryOptionCombo(IdScheme idScheme, String id) {
String key = "categoryoptioncomboid";
StringSubstitutor sub = new StringSubstitutor(ImmutableMap.<String, String>builder().put("key", key).put("resolvedScheme", Objects.requireNonNull(resolveId(idScheme, key, id))).build());
try {
return jdbcTemplate.queryForObject(sub.replace(SQL_GET_CATEGORYOPTIONCOMBO), (rs, i) -> bind(key, rs));
} catch (EmptyResultDataAccessException e) {
return null;
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.
the class UserRepository method findUserByNickname.
public User findUserByNickname(String nickname) {
String query = "SELECT * FROM User WHERE nickname = ?";
List<User> resultUser;
try {
resultUser = jdbcTemplate.query(query, (rs, rowNum) -> {
User user = new User();
user.setId(rs.getLong("id"));
user.setEmail(rs.getString("email"));
user.setPassword(rs.getString("password"));
user.setNickname(rs.getString("nickname"));
return user;
}, nickname);
} catch (EmptyResultDataAccessException e) {
log.error(e.getMessage());
return null;
}
return resultUser.size() > 0 ? resultUser.get(0) : null;
}
use of org.springframework.dao.EmptyResultDataAccessException in project cas by apereo.
the class JdbcPasswordManagementService method findEmail.
@Override
public String findEmail(final PasswordManagementQuery query) {
val queryFindEmail = properties.getJdbc().getSqlFindEmail();
if (StringUtils.isBlank(queryFindEmail)) {
LOGGER.debug("No SQL query is defined to retrieve email addresses");
return null;
}
try {
return this.transactionTemplate.execute(action -> {
val email = this.jdbcTemplate.queryForObject(queryFindEmail, String.class, query.getUsername());
if (StringUtils.isNotBlank(email) && EmailValidator.getInstance().isValid(email)) {
return email;
}
LOGGER.debug("Username [{}] not found when searching for email", query.getUsername());
return null;
});
} catch (final EmptyResultDataAccessException e) {
LOGGER.debug("Username [{}] not found when searching for email", query.getUsername());
return null;
}
}
Aggregations