use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class PerunNotifRegexDaoImpl method getPerunNotifRegexById.
@Override
public PerunNotifRegex getPerunNotifRegexById(int id) {
logger.debug("Loading regex from db by id: {}", id);
PerunNotifRegex regex = null;
try {
regex = this.getJdbcTemplate().queryForObject("SELECT * from pn_regex where id = ?", new Object[] { id }, PerunNotifRegex.PERUN_NOTIF_REGEX);
} catch (EmptyResultDataAccessException ex) {
logger.debug("Regex with id: {}, not found.", id);
return null;
}
logger.debug("Regex with id: {}, loaded from db. Loading objects.", id);
List<PerunNotifObject> objects = this.getJdbcTemplate().query("SELECT * from pn_object object JOIN pn_regex_object bind ON object.id = bind.object_id WHERE bind.regex_id = ?", new Object[] { regex.getId() }, PerunNotifObject.PERUN_NOTIF_OBJECT);
regex.addObjects(objects);
logger.debug("Objects loaded result: {}", regex);
return regex;
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class UsersManagerImpl method findUsersByName.
@Override
public List<User> findUsersByName(PerunSession sess, String searchString) {
if (searchString == null || searchString.isEmpty()) {
return new ArrayList<>();
}
// Convert to lowercase
searchString = searchString.toLowerCase();
log.trace("Search string '{}' converted into lower-cased", searchString);
// remove spaces from the search string
searchString = searchString.replaceAll(" ", "");
log.debug("Searching users by name using searchString '{}'", searchString);
// the searchString is already lower cased
try {
return jdbc.query("select " + userMappingSelectQuery + " from users " + "where strpos(lower(" + Compatibility.convertToAscii("COALESCE(users.first_name,'') || COALESCE(users.middle_name,'') || COALESCE(users.last_name,'')") + ")," + Compatibility.convertToAscii("?") + ") > 0", USER_MAPPER, searchString);
} 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 UsersManagerImpl method isLoginReserved.
@Override
public boolean isLoginReserved(PerunSession sess, String namespace, String login, boolean ignoreCase) {
Utils.notNull(namespace, "loginNamespace");
Utils.notNull(login, "userLogin");
try {
int numberOfExistences = 0;
if (ignoreCase) {
numberOfExistences = jdbc.queryForInt("select count(1) from application_reserved_logins where namespace=? and lower(login)=lower(?)", namespace, login);
} else {
numberOfExistences = jdbc.queryForInt("select count(1) from application_reserved_logins where namespace=? and login=?", namespace, login);
}
if (numberOfExistences == 1) {
return true;
} else if (numberOfExistences > 1) {
throw new ConsistencyErrorException("Login " + login + " in namespace " + namespace + " is reserved more than once.");
}
return false;
} catch (EmptyResultDataAccessException ex) {
return false;
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of org.springframework.dao.EmptyResultDataAccessException in project perun by CESNET.
the class UsersManagerImpl method getUsersByAttributeValue.
@Override
public List<User> getUsersByAttributeValue(PerunSession sess, AttributeDefinition attributeDefinition, String attributeValue) {
String value = "";
String operator = "=";
if (attributeDefinition.getType().equals(String.class.getName())) {
value = attributeValue.trim();
operator = "=";
} else if (attributeDefinition.getType().equals(Integer.class.getName())) {
value = attributeValue.trim();
operator = "=";
} else if (attributeDefinition.getType().equals(Boolean.class.getName())) {
value = attributeValue.trim();
operator = "=";
} else if (attributeDefinition.getType().equals(ArrayList.class.getName())) {
value = "%" + attributeValue.trim() + "%";
operator = "like";
} else if (attributeDefinition.getType().equals(LinkedHashMap.class.getName())) {
value = "%" + attributeValue.trim() + "%";
operator = "like";
}
String query = "select " + userMappingSelectQuery + " from users, user_attr_values where " + " user_attr_values.attr_value " + operator + " :value and users.id=user_attr_values.user_id and user_attr_values.attr_id=:attr_id";
MapSqlParameterSource namedParams = new MapSqlParameterSource();
namedParams.addValue("value", value);
namedParams.addValue("attr_id", attributeDefinition.getId());
try {
return namedParameterJdbcTemplate.query(query, namedParams, USER_MAPPER);
} 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 VosManagerImpl method getAdmins.
@Override
public List<User> getAdmins(PerunSession sess, Vo vo, String role) {
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=?)", UsersManagerImpl.USER_MAPPER, vo.getId(), role.toLowerCase()));
// admins through a group
List<Group> listOfGroupAdmins = getAdminGroups(sess, vo, role);
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);
}
}
Aggregations