Search in sources :

Example 1 with CantBeSubmittedException

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");
}
Also used : User(cz.metacentrum.perun.core.api.User) CantBeSubmittedException(cz.metacentrum.perun.registrar.exceptions.CantBeSubmittedException) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl)

Example 2 with CantBeSubmittedException

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) CantBeSubmittedException(cz.metacentrum.perun.registrar.exceptions.CantBeSubmittedException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

CantBeSubmittedException (cz.metacentrum.perun.registrar.exceptions.CantBeSubmittedException)2 Attribute (cz.metacentrum.perun.core.api.Attribute)1 User (cz.metacentrum.perun.core.api.User)1 AttributesManagerBl (cz.metacentrum.perun.core.bl.AttributesManagerBl)1 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)1 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 LocalDateTime (java.time.LocalDateTime)1 Date (java.util.Date)1