Search in sources :

Example 1 with Type

use of org.olat.portfolio.manager.EPMapPolicy.Type in project OpenOLAT by OpenOLAT.

the class EPShareListController method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    boolean allOk = true;
    // process all form-input fields and update data-model
    secureListBox();
    String genericError = null;
    for (EPSharePolicyWrapper policyWrapper : policyWrappers) {
        Type type = policyWrapper.getType();
        if (type == null) {
            // tutor implicit rule
            continue;
        }
        TextElement mailEl = policyWrapper.getMailEl();
        if (mailEl != null) {
            String mail = mailEl.getValue();
            if (StringHelper.containsNonWhitespace(mail)) {
                if (MailHelper.isValidEmailAddress(mail)) {
                    SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
                    List<Identity> shareWithIdentities = userManager.findIdentitiesByEmail(Collections.singletonList(mail));
                    if (isAtLeastOneInSecurityGroup(shareWithIdentities, allUsers)) {
                        mailEl.setErrorKey("error.invitation.mail.used", new String[] { mail });
                        allOk &= false;
                    }
                } else {
                    mailEl.setErrorKey("map.share.with.mail.error", null);
                    allOk &= false;
                }
            } else if (type.equals(Type.invitation)) {
                genericError = translate("map.share.error.invite");
                allOk &= false;
            }
        } else if (type.equals(Type.group)) {
            List<BusinessGroup> groups = policyWrapper.getGroups();
            if (groups.size() == 0) {
                genericError = translate("map.share.error.group");
                allOk &= false;
            }
        } else if (type.equals(Type.user)) {
            List<Identity> idents = policyWrapper.getIdentities();
            if (idents.size() == 0) {
                genericError = translate("map.share.error.user");
                allOk &= false;
            }
        }
        if ((policyWrapper.getFromChooser() != null && policyWrapper.getFromChooser().hasError()) || (policyWrapper.getToChooser() != null && policyWrapper.getToChooser().hasError())) {
            genericError = translate("map.share.date.invalid");
            allOk &= false;
        }
        if (policyWrapper.getFrom() != null && policyWrapper.getTo() != null && policyWrapper.getFrom().after(policyWrapper.getTo())) {
            // show invalid date warning
            policyWrapper.getFromChooser().setErrorKey("from.date.behind.to", null);
            policyWrapper.getFromChooser().showError(true);
            genericError = translate("from.date.behind.to");
            allOk &= false;
        }
        StaticTextElement errTextEl = policyWrapper.getErrorEl();
        if (genericError != null && errTextEl != null) {
            errTextEl.setValue(genericError);
        }
    }
    return allOk && super.validateFormLogic(ureq);
}
Also used : Type(org.olat.portfolio.manager.EPMapPolicy.Type) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) ContactList(org.olat.core.util.mail.ContactList) List(java.util.List) ArrayList(java.util.ArrayList) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity)

Example 2 with Type

use of org.olat.portfolio.manager.EPMapPolicy.Type in project openolat by klemens.

the class EPShareListController method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    boolean allOk = true;
    // process all form-input fields and update data-model
    secureListBox();
    String genericError = null;
    for (EPSharePolicyWrapper policyWrapper : policyWrappers) {
        Type type = policyWrapper.getType();
        if (type == null) {
            // tutor implicit rule
            continue;
        }
        TextElement mailEl = policyWrapper.getMailEl();
        if (mailEl != null) {
            String mail = mailEl.getValue();
            if (StringHelper.containsNonWhitespace(mail)) {
                if (MailHelper.isValidEmailAddress(mail)) {
                    SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
                    List<Identity> shareWithIdentities = userManager.findIdentitiesByEmail(Collections.singletonList(mail));
                    if (isAtLeastOneInSecurityGroup(shareWithIdentities, allUsers)) {
                        mailEl.setErrorKey("error.invitation.mail.used", new String[] { mail });
                        allOk &= false;
                    }
                } else {
                    mailEl.setErrorKey("map.share.with.mail.error", null);
                    allOk &= false;
                }
            } else if (type.equals(Type.invitation)) {
                genericError = translate("map.share.error.invite");
                allOk &= false;
            }
        } else if (type.equals(Type.group)) {
            List<BusinessGroup> groups = policyWrapper.getGroups();
            if (groups.size() == 0) {
                genericError = translate("map.share.error.group");
                allOk &= false;
            }
        } else if (type.equals(Type.user)) {
            List<Identity> idents = policyWrapper.getIdentities();
            if (idents.size() == 0) {
                genericError = translate("map.share.error.user");
                allOk &= false;
            }
        }
        if ((policyWrapper.getFromChooser() != null && policyWrapper.getFromChooser().hasError()) || (policyWrapper.getToChooser() != null && policyWrapper.getToChooser().hasError())) {
            genericError = translate("map.share.date.invalid");
            allOk &= false;
        }
        if (policyWrapper.getFrom() != null && policyWrapper.getTo() != null && policyWrapper.getFrom().after(policyWrapper.getTo())) {
            // show invalid date warning
            policyWrapper.getFromChooser().setErrorKey("from.date.behind.to", null);
            policyWrapper.getFromChooser().showError(true);
            genericError = translate("from.date.behind.to");
            allOk &= false;
        }
        StaticTextElement errTextEl = policyWrapper.getErrorEl();
        if (genericError != null && errTextEl != null) {
            errTextEl.setValue(genericError);
        }
    }
    return allOk && super.validateFormLogic(ureq);
}
Also used : Type(org.olat.portfolio.manager.EPMapPolicy.Type) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) TextElement(org.olat.core.gui.components.form.flexible.elements.TextElement) ContactList(org.olat.core.util.mail.ContactList) List(java.util.List) ArrayList(java.util.ArrayList) StaticTextElement(org.olat.core.gui.components.form.flexible.elements.StaticTextElement) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 SecurityGroup (org.olat.basesecurity.SecurityGroup)2 StaticTextElement (org.olat.core.gui.components.form.flexible.elements.StaticTextElement)2 TextElement (org.olat.core.gui.components.form.flexible.elements.TextElement)2 Identity (org.olat.core.id.Identity)2 ContactList (org.olat.core.util.mail.ContactList)2 Type (org.olat.portfolio.manager.EPMapPolicy.Type)2