Search in sources :

Example 51 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class UserImportController method createMailTemplateForNewIdentity.

private MailTemplate createMailTemplateForNewIdentity(Identity identity, TransientIdentity transientIdentity) {
    // get some data about the actor and fetch the translated subject / body via i18n module
    String[] bodyArgs = new String[] { // {0}
    identity.getName(), // {1}
    identity.getUser().getProperty(UserConstants.FIRSTNAME, null), // {2}
    identity.getUser().getProperty(UserConstants.LASTNAME, null), // {3}
    UserManager.getInstance().getUserDisplayEmail(identity, getLocale()), // {4}
    Settings.getServerContextPathURI(), // {5}
    transientIdentity.getPassword() };
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
    Translator translator = Util.createPackageTranslator(UserImportController.class, locale);
    String subject = translator.translate("mail.new.identity.subject");
    String body = translator.translate("mail.new.identity.text", bodyArgs);
    // create a mail template which all these data
    MailTemplate mailTempl = new MailTemplate(subject, body, null) {

        @Override
        public void putVariablesInMailContext(VelocityContext context, Identity identity) {
            // Put user variables into velocity context
            User user = identity.getUser();
            context.put("firstname", user.getProperty(UserConstants.FIRSTNAME, null));
            context.put("lastname", user.getProperty(UserConstants.LASTNAME, null));
            // the email of the user, needs to stay named 'login'
            context.put("login", user.getProperty(UserConstants.EMAIL, null));
        }
    };
    return mailTempl;
}
Also used : Locale(java.util.Locale) User(org.olat.core.id.User) Translator(org.olat.core.gui.translator.Translator) VelocityContext(org.apache.velocity.VelocityContext) MailTemplate(org.olat.core.util.mail.MailTemplate) Identity(org.olat.core.id.Identity)

Example 52 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class UserImportController method processGroupAdditionForAllIdents.

private void processGroupAdditionForAllIdents(List<Identity> allIdents, List<Long> tutorGroups, List<Long> partGroups, boolean sendmail) {
    Collection<Identity> identities = getIdentities(allIdents);
    List<BusinessGroupMembershipChange> changes = new ArrayList<BusinessGroupMembershipChange>();
    for (Identity identity : identities) {
        if (tutorGroups != null && !tutorGroups.isEmpty()) {
            for (Long tutorGroupKey : tutorGroups) {
                BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(identity, tutorGroupKey);
                change.setTutor(Boolean.TRUE);
                changes.add(change);
            }
        }
        if (partGroups != null && !partGroups.isEmpty()) {
            for (Long partGroupKey : partGroups) {
                BusinessGroupMembershipChange change = new BusinessGroupMembershipChange(identity, partGroupKey);
                change.setParticipant(Boolean.TRUE);
                changes.add(change);
            }
        }
    }
    MailPackage mailing = new MailPackage(sendmail);
    businessGroupService.updateMemberships(getIdentity(), changes, mailing);
    DBFactory.getInstance().commit();
}
Also used : BusinessGroupMembershipChange(org.olat.group.model.BusinessGroupMembershipChange) MailPackage(org.olat.core.util.mail.MailPackage) ArrayList(java.util.ArrayList) Identity(org.olat.core.id.Identity)

Example 53 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class UserImportController method loadEmail.

private String loadEmail(Identity updatedIdentity) {
    String email = null;
    Identity oldIdentity = BaseSecurityManager.getInstance().loadIdentityByKey(updatedIdentity.getKey());
    if (oldIdentity != null) {
        email = oldIdentity.getUser().getEmail();
    }
    return email;
}
Also used : Identity(org.olat.core.id.Identity)

Example 54 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class UserDeletionManager method sendUserDeleteEmailTo.

/**
 * Send 'delete'- emails to a list of identities. The delete email is an announcement for the user-deletion.
 *
 * @param selectedIdentities
 * @return String with warning message (e.g. email-address not valid, could not send email).
 *         If there is no warning, the return String is empty ("").
 */
public String sendUserDeleteEmailTo(List<Identity> selectedIdentities, MailTemplate template, boolean isTemplateChanged, String keyEmailSubject, String keyEmailBody, Identity sender, Translator pT) {
    StringBuilder buf = new StringBuilder();
    if (template != null) {
        template.addToContext("responseTo", deletionModule.getEmailResponseTo());
        for (Iterator<Identity> iter = selectedIdentities.iterator(); iter.hasNext(); ) {
            Identity identity = iter.next();
            if (!isTemplateChanged) {
                // Email template has NOT changed => take translated version of subject and body text
                Translator identityTranslator = Util.createPackageTranslator(SelectionController.class, I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage()));
                template.setSubjectTemplate(identityTranslator.translate(keyEmailSubject));
                template.setBodyTemplate(identityTranslator.translate(keyEmailBody));
            }
            template.putVariablesInMailContext(template.getContext(), identity);
            logDebug(" Try to send Delete-email to identity=" + identity.getName() + " with email=" + identity.getUser().getProperty(UserConstants.EMAIL, null));
            MailerResult result = new MailerResult();
            MailBundle bundle = mailManager.makeMailBundle(null, identity, template, null, null, result);
            if (bundle != null) {
                mailManager.sendMessage(bundle);
            }
            if (template.getCpfrom()) {
                MailBundle ccBundle = mailManager.makeMailBundle(null, sender, template, sender, null, result);
                if (ccBundle != null) {
                    mailManager.sendMessage(ccBundle);
                }
            }
            if (result.getReturnCode() != MailerResult.OK) {
                buf.append(pT.translate("email.error.send.failed", new String[] { identity.getUser().getProperty(UserConstants.EMAIL, null), identity.getName() })).append("\n");
            }
            logAudit("User-Deletion: Delete-email send to identity=" + identity.getName() + " with email=" + identity.getUser().getProperty(UserConstants.EMAIL, null));
            markSendEmailEvent(identity);
        }
    } else {
        // no template => User decides to sending no delete-email, mark only in lifecycle table 'sendEmail'
        for (Iterator<Identity> iter = selectedIdentities.iterator(); iter.hasNext(); ) {
            Identity identity = iter.next();
            logAudit("User-Deletion: Move in 'Email sent' section without sending email, identity=" + identity.getName());
            markSendEmailEvent(identity);
        }
    }
    return buf.toString();
}
Also used : Translator(org.olat.core.gui.translator.Translator) MailerResult(org.olat.core.util.mail.MailerResult) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 55 with Identity

use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.

the class ExtendedIdentitiesTableDataModel method getValueAt.

/**
 * @see org.olat.core.gui.components.table.TableDataModel#getValueAt(int, int)
 */
@Override
public final Object getValueAt(int row, int col) {
    Identity identity = getObject(row);
    User user = identity.getUser();
    int offSet = isAdministrativeUser ? 1 : 0;
    if (col == 0 && isAdministrativeUser) {
        return identity.getName();
    }
    if (col >= offSet && col < userPropertyHandlers.size() + offSet) {
        // get user property for this column
        UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(col - offSet);
        String value = userPropertyHandler.getUserProperty(user, getLocale());
        return (value == null ? "n/a" : value);
    }
    if (col == userPropertyHandlers.size() + offSet) {
        return identity.getLastLogin();
    }
    if (col == userPropertyHandlers.size() + offSet + 1) {
        return user.getCreationDate();
    }
    return "error";
}
Also used : User(org.olat.core.id.User) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

Identity (org.olat.core.id.Identity)3749 Test (org.junit.Test)1956 RepositoryEntry (org.olat.repository.RepositoryEntry)898 BusinessGroup (org.olat.group.BusinessGroup)560 ArrayList (java.util.ArrayList)550 Date (java.util.Date)312 URI (java.net.URI)272 ICourse (org.olat.course.ICourse)266 HttpResponse (org.apache.http.HttpResponse)260 File (java.io.File)211 AssessmentManager (org.olat.course.assessment.AssessmentManager)210 Path (javax.ws.rs.Path)182 OLATResource (org.olat.resource.OLATResource)172 OLATResourceable (org.olat.core.id.OLATResourceable)156 Roles (org.olat.core.id.Roles)154 HashMap (java.util.HashMap)151 RestSecurityHelper.getIdentity (org.olat.restapi.security.RestSecurityHelper.getIdentity)142 HashSet (java.util.HashSet)136 List (java.util.List)132 Produces (javax.ws.rs.Produces)130