use of cz.metacentrum.perun.core.api.exceptions.NamespaceRulesNotExistsException in project perun by CESNET.
the class MembersManagerBlImpl method setEmailForUser.
/**
* Sets preferred email for the given user. If the given email is null, a default namespace email
* from configuration is used. If the namespace is also null, a defaul 'no-reply@perun-aai.org' is used.
*
* @param sess session
* @param user user to whom is the email set
* @param inputEmail email to be set
* @param namespace namespace used to get default email
* @return the actual email that was set
* @throws WrongAttributeValueException
* @throws WrongReferenceAttributeValueException
*/
private String setEmailForUser(PerunSession sess, User user, String inputEmail, String namespace) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
String email = inputEmail;
if (email == null) {
if (isNotBlank(namespace)) {
try {
var rules = getNamespaceRules(namespace);
email = rules.getDefaultEmail();
} catch (NamespaceRulesNotExistsException e) {
log.warn("No rules found for namespace: '{}'", namespace, e);
email = DEFAULT_NO_REPLY_EMAIL;
}
} else {
email = DEFAULT_NO_REPLY_EMAIL;
}
}
if (!Utils.emailPattern.matcher(email).matches()) {
throw new InternalErrorException("Email has an invalid format: " + email);
}
try {
Attribute mailAttr = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, A_U_PREF_MAIL);
mailAttr.setValue(email);
getPerunBl().getAttributesManagerBl().setAttribute(sess, user, mailAttr);
} catch (WrongAttributeAssignmentException | AttributeNotExistsException e) {
throw new InternalErrorException(e);
}
return email;
}
Aggregations