use of cz.metacentrum.perun.registrar.exceptions.CantBeSubmittedException in project perun by CESNET.
the class ElixirBonaFideStatus method canBeSubmitted.
/**
* Validate if the user meets criteria for applying to group.
*/
@Override
public void canBeSubmitted(PerunSession session, Application.AppType appType, Map<String, String> params) throws PerunException {
User user = session.getPerunPrincipal().getUser();
if (user == null) {
throw new CantBeSubmittedException("This module can be set only for registration to Group.");
}
AttributesManagerBl am = ((PerunBl) session.getPerun()).getAttributesManagerBl();
Attribute affiliations = am.getAttribute(session, user, A_U_D_userEduPersonScopedAffiliations);
if (affiliations.getValue() != null) {
List<String> val = affiliations.valueAsList();
for (String affiliation : val) {
if (affiliation.startsWith("faculty@")) {
return;
}
}
}
Attribute rems = am.getAttribute(session, user, A_U_D_userBonaFideStatusRems);
if (rems.getValue() != null) {
return;
}
throw new CantBeSubmittedException("User does not meet the criteria for applying for Bona Fide Status");
}
use of cz.metacentrum.perun.registrar.exceptions.CantBeSubmittedException in project perun by CESNET.
the class Du method canBeSubmitted.
@Override
public void canBeSubmitted(PerunSession session, Application.AppType appType, Map<String, String> params) throws PerunException {
String eligibleString = params.get("isCesnetEligibleLastSeen");
if (eligibleString != null && !eligibleString.isEmpty()) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
df.setLenient(false);
try {
// get eligible date + 1 year
Date eligibleDate = df.parse(eligibleString);
LocalDateTime timeInOneYear = LocalDateTime.ofInstant(eligibleDate.toInstant(), ZoneId.systemDefault()).plusYears(1);
// compare
if (LocalDateTime.now().isBefore(timeInOneYear)) {
return;
}
} catch (ParseException e) {
log.warn("Unable to parse date to determine, if user is eligible for CESNET services.", e);
}
}
throw new CantBeSubmittedException("User is not eligible for CESNET services. You must log-in using verified academic identity (at least once a year) in order to access CESNET services.", "NOT_ELIGIBLE", null, null);
}
Aggregations