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;
}
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();
}
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;
}
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();
}
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";
}
Aggregations