use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.
the class EmailManagerTest method verifySetCurrentAndPrimaryTest.
@Test
public void verifySetCurrentAndPrimaryTest() {
String email = "public_0000-0000-0000-0004@test.orcid.org";
String orcid = "0000-0000-0000-0004";
Emails emails = emailManager.getEmails(orcid);
Email element = null;
for (Email e : emails.getEmails()) {
if (email.equals(e.getEmail())) {
element = e;
break;
}
}
assertNotNull(element);
assertFalse(element.isCurrent());
assertFalse(element.isPrimary());
assertFalse(element.isVerified());
emailManager.verifySetCurrentAndPrimary(orcid, email);
emails = emailManager.getEmails(orcid);
element = null;
for (Email e : emails.getEmails()) {
if (email.equals(e.getEmail())) {
element = e;
break;
}
}
assertNotNull(element);
assertTrue(element.isCurrent());
assertTrue(element.isPrimary());
assertTrue(element.isVerified());
}
use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.
the class OrcidSecurityManagerTestBase method createEmail.
protected Email createEmail(Visibility v, String sourceId) {
Email email = new Email();
email.setEmail("test-email-" + System.currentTimeMillis() + "@test.orcid.org");
email.setVisibility(v);
setSource(email, sourceId);
return email;
}
use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.
the class MembersManagerImpl method getMember.
@Override
@Transactional
public Member getMember(String memberId) {
Member member = new Member();
String orcid = memberId;
if (!OrcidStringUtils.isValidOrcid(memberId)) {
Map<String, String> ids = emailManager.findOricdIdsByCommaSeparatedEmails(memberId);
// Check if it is using the email
if (ids != null && ids.containsKey(memberId)) {
orcid = ids.get(memberId);
} else {
// Check if can find it by name
try {
orcid = profileEntityManager.findByCreditName(memberId);
} catch (Exception e) {
member.getErrors().add(getMessage("manage_member.email_not_found"));
orcid = null;
}
}
}
if (PojoUtil.isEmpty(orcid)) {
member.getErrors().add(getMessage("manage_member.email_not_found"));
} else {
if (profileEntityManager.orcidExists(orcid)) {
MemberType groupType = profileEntityManager.getGroupType(orcid);
if (groupType != null) {
ProfileEntity memberProfile = profileDao.find(orcid);
member = Member.fromProfileEntity(memberProfile);
Set<Client> clients = clientManagerReadOnly.getClients(orcid);
List<org.orcid.pojo.ajaxForm.Client> clientsList = new ArrayList<org.orcid.pojo.ajaxForm.Client>();
clients.forEach(c -> {
clientsList.add(org.orcid.pojo.ajaxForm.Client.fromModelObject(c));
});
member.setClients(clientsList);
} else {
member.getErrors().add(getMessage("manage_members.orcid_is_not_a_member"));
}
} else {
member.getErrors().add(getMessage("manage_members.orcid_doesnt_exists"));
}
}
return member;
}
use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendAmendEmail.
@Override
public void sendAmendEmail(String userOrcid, AmendedSection amendedSection, Collection<Item> items) {
String amenderOrcid = sourceManager.retrieveSourceOrcid();
ProfileEntity record = profileEntityCacheManager.retrieve(userOrcid);
Locale locale = getUserLocaleFromProfileEntity(record);
if (amenderOrcid == null) {
LOGGER.info("Not sending amend email to {} because amender is null", userOrcid);
return;
}
if (amenderOrcid.equals(userOrcid)) {
LOGGER.debug("Not sending amend email, because self edited: {}", userOrcid);
return;
}
Boolean sendChangeNotifications = record.getSendChangeNotifications();
if (sendChangeNotifications == null || !sendChangeNotifications) {
LOGGER.debug("Not sending amend email, because option to send change notifications is disabled: {}", userOrcid);
return;
}
org.orcid.jaxb.model.common_v2.OrcidType amenderType = profileDao.retrieveOrcidType(amenderOrcid);
if (amenderType != null && OrcidType.ADMIN.equals(OrcidType.fromValue(amenderType.value()))) {
LOGGER.debug("Not sending amend email, because modified by admin ({}): {}", amenderOrcid, userOrcid);
return;
}
String subject = getSubject("email.subject.amend", locale);
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("emailName", deriveEmailFriendlyName(record));
templateParams.put("orcid", userOrcid);
templateParams.put("amenderName", extractAmenderName(userOrcid, amenderOrcid));
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
templateParams.put("subject", subject);
addMessageParams(templateParams, locale);
// Generate body from template
String body = templateManager.processTemplate("amend_email.ftl", templateParams);
// Generate html from template
String html = templateManager.processTemplate("amend_email_html.ftl", templateParams);
boolean notificationsEnabled = record.getEnableNotifications();
if (notificationsEnabled) {
NotificationAmended notification = new NotificationAmended();
notification.setNotificationType(NotificationType.AMENDED);
notification.setAmendedSection(amendedSection);
if (items != null) {
notification.setItems(new Items(new ArrayList<>(items)));
}
createNotification(userOrcid, notification);
} else {
String primaryEmail = emailManager.findPrimaryEmail(userOrcid).getEmail();
mailGunManager.sendEmail(AMEND_NOTIFY_ORCID_ORG, primaryEmail, subject, body, html);
}
}
use of org.orcid.jaxb.model.v3.dev1.record.Email in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendDelegationRequestEmail.
@Override
public void sendDelegationRequestEmail(String managedOrcid, String trustedOrcid, String link) {
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
templateParams.put("link", link);
ProfileEntity managedEntity = profileEntityCacheManager.retrieve(managedOrcid);
ProfileEntity trustedEntity = profileEntityCacheManager.retrieve(trustedOrcid);
String emailNameForDelegate = deriveEmailFriendlyName(managedEntity);
String trustedOrcidName = deriveEmailFriendlyName(trustedEntity);
templateParams.put("emailNameForDelegate", emailNameForDelegate);
templateParams.put("trustedOrcidName", trustedOrcidName);
templateParams.put("trustedOrcidValue", trustedOrcid);
templateParams.put("managedOrcidValue", managedOrcid);
String primaryEmail = emailManager.findPrimaryEmail(managedOrcid).getEmail();
if (primaryEmail == null) {
LOGGER.info("Cant send admin delegate email if primary email is null: {}", managedOrcid);
return;
}
org.orcid.jaxb.model.common_v2.Locale locale = managedEntity.getLocale();
Locale userLocale = LocaleUtils.toLocale("en");
if (locale != null) {
userLocale = LocaleUtils.toLocale(locale.value());
}
addMessageParams(templateParams, userLocale);
String htmlBody = templateManager.processTemplate("admin_delegate_request_html.ftl", templateParams);
// Send message
if (apiRecordCreationEmailEnabled) {
String subject = messages.getMessage("email.subject.admin_as_delegate", new Object[] { trustedOrcidName }, userLocale);
boolean notificationsEnabled = trustedEntity != null ? trustedEntity.getEnableNotifications() : false;
if (notificationsEnabled) {
NotificationCustom notification = new NotificationCustom();
notification.setNotificationType(NotificationType.CUSTOM);
notification.setSubject(subject);
notification.setBodyHtml(htmlBody);
createNotification(managedOrcid, notification);
} else {
mailGunManager.sendEmail(DELEGATE_NOTIFY_ORCID_ORG, primaryEmail, subject, null, htmlBody);
}
profileEventDao.persist(new ProfileEventEntity(managedOrcid, ProfileEventType.ADMIN_PROFILE_DELEGATION_REQUEST));
} else {
LOGGER.debug("Not sending admin delegate email, because API record creation email option is disabled. Message would have been: {}", htmlBody);
}
}
Aggregations