use of org.orcid.jaxb.model.message.SendChangeNotifications in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendAmendEmail.
@Override
public void sendAmendEmail(OrcidProfile amendedProfile, AmendedSection amendedSection, Collection<Item> items) {
String amenderOrcid = sourceManager.retrieveSourceOrcid();
if (amenderOrcid == null) {
LOGGER.debug("Not sending amend email, because amender is null: {}", amendedProfile);
return;
}
if (amenderOrcid.equals(amendedProfile.getOrcidIdentifier().getPath())) {
LOGGER.debug("Not sending amend email, because self edited: {}", amendedProfile);
return;
}
SendChangeNotifications sendChangeNotifications = amendedProfile.getOrcidInternal().getPreferences().getSendChangeNotifications();
if (sendChangeNotifications == null || !sendChangeNotifications.isValue()) {
LOGGER.debug("Not sending amend email, because option to send change notifications not set to true: {}", amendedProfile);
return;
}
if (OrcidType.ADMIN.equals(profileDao.retrieveOrcidType(amenderOrcid))) {
LOGGER.debug("Not sending amend email, because modified by admin ({}): {}", amenderOrcid, amendedProfile);
return;
}
String subject = getSubject("email.subject.amend", amendedProfile);
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("emailName", deriveEmailFriendlyName(amendedProfile));
templateParams.put("orcid", amendedProfile.getOrcidIdentifier().getPath());
templateParams.put("amenderName", extractAmenderName(amendedProfile, amenderOrcid));
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
templateParams.put("subject", subject);
addMessageParams(templateParams, amendedProfile);
// 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 = profileEntityCacheManager.retrieve(amendedProfile.getOrcidIdentifier().getPath()).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(amendedProfile.getOrcidIdentifier().getPath(), notification);
} else {
String email = amendedProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue();
mailGunManager.sendEmail(AMEND_NOTIFY_ORCID_ORG, email, subject, body, html);
}
}
use of org.orcid.jaxb.model.message.SendChangeNotifications in project ORCID-Source by ORCID.
the class OrcidProfileManagerImplTest method testPrimaryAddressDontChangeOnClaimedRecords.
@Test
@Transactional
@Rollback(true)
public void testPrimaryAddressDontChangeOnClaimedRecords() {
OrcidProfile profile = createBasicProfile();
String orcidIdentifier = null;
profile.setOrcidIdentifier(orcidIdentifier);
setBio(profile, Visibility.PUBLIC);
String email = profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue();
profile = orcidProfileManager.createOrcidProfile(profile, true, false);
assertNotNull(profile);
assertNotNull(profile.getOrcidIdentifier());
assertFalse(PojoUtil.isEmpty(profile.getOrcidIdentifier().getPath()));
profile = orcidProfileManager.retrieveOrcidProfile(profile.getOrcidIdentifier().getPath());
assertNotNull(profile);
assertNotNull(profile.getOrcidBio());
assertNotNull(profile.getOrcidBio().getBiography());
assertEquals("This is my biography", profile.getOrcidBio().getBiography().getContent());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getBiography().getVisibility());
assertNotNull(profile.getOrcidBio().getContactDetails());
assertNotNull(profile.getOrcidBio().getContactDetails().getAddress());
assertNotNull(profile.getOrcidBio().getContactDetails().getAddress().getCountry());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getVisibility());
assertEquals(Iso3166Country.US, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getValue());
assertNotNull(profile.getOrcidBio().getContactDetails().getEmail());
assertEquals(1, profile.getOrcidBio().getContactDetails().getEmail().size());
assertNotNull(profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
assertEquals(email, profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
assertNotNull(profile.getOrcidBio().getExternalIdentifiers());
assertNotNull(profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getExternalIdentifiers().getVisibility());
assertEquals(1, profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
assertEquals("common-name", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
assertEquals("ext-id-reference", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdReference().getContent());
assertEquals("http://orcid.org/ext-id", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdUrl().getValue());
assertNotNull(profile.getOrcidBio().getKeywords());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getKeywords().getVisibility());
assertEquals(1, profile.getOrcidBio().getKeywords().getKeyword().size());
assertEquals("k1", profile.getOrcidBio().getKeywords().getKeyword().get(0).getContent());
assertNotNull(profile.getOrcidBio().getPersonalDetails());
assertNotNull(profile.getOrcidBio().getPersonalDetails().getOtherNames());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility());
assertEquals(1, profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().size());
assertEquals("o1", profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
assertNotNull(profile.getOrcidBio().getResearcherUrls());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getResearcherUrls().getVisibility());
assertEquals(1, profile.getOrcidBio().getResearcherUrls().getResearcherUrl().size());
assertEquals("http://orcid.org/researcher-url-1", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
assertEquals("url-name-1", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrlName().getContent());
ProfileEntity profileEntity = profileDao.find(profile.getOrcidIdentifier().getPath());
assertNotNull(profileEntity);
assertNotNull(profileEntity.getAddresses());
assertEquals(1, profileEntity.getAddresses().size());
assertEquals(org.orcid.jaxb.model.common_v2.Iso3166Country.US, profileEntity.getAddresses().iterator().next().getIso2Country());
//Update all values
profile.getOrcidBio().getBiography().setContent("This is my biography # 2");
profile.getOrcidBio().getContactDetails().getAddress().setCountry(new Country(Iso3166Country.CR));
profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setSource(null);
profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdCommonName(new ExternalIdCommonName("common-name-2"));
profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdReference(new ExternalIdReference("ext-id-reference-2"));
profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdUrl(new ExternalIdUrl("http://orcid.org/ext-id-2"));
profile.getOrcidBio().getKeywords().getKeyword().get(0).setSource(null);
profile.getOrcidBio().getKeywords().getKeyword().get(0).setContent("k2");
profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).setSource(null);
profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).setContent("o2");
profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setSource(null);
profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setUrl(new Url("http://orcid.org/researcher-url-2"));
profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setUrlName(new UrlName("url-name-2"));
orcidProfileManager.updateOrcidBio(profile);
//Everything should be updated but the primary address that was already set
profile = orcidProfileManager.retrieveOrcidProfile(profile.getOrcidIdentifier().getPath());
assertNotNull(profile);
assertNotNull(profile.getOrcidBio());
assertNotNull(profile.getOrcidBio().getBiography());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getBiography().getVisibility());
assertEquals("This is my biography # 2", profile.getOrcidBio().getBiography().getContent());
assertNotNull(profile.getOrcidBio().getContactDetails());
assertNotNull(profile.getOrcidBio().getContactDetails().getAddress());
assertNotNull(profile.getOrcidBio().getContactDetails().getAddress().getCountry());
assertNotNull(profile.getOrcidBio().getContactDetails().getEmail());
assertEquals(1, profile.getOrcidBio().getContactDetails().getEmail().size());
assertNotNull(profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
assertEquals(email, profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
assertNotNull(profile.getOrcidBio().getExternalIdentifiers());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getExternalIdentifiers().getVisibility());
assertNotNull(profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
assertEquals(1, profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
assertEquals("common-name-2", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
assertEquals("ext-id-reference-2", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdReference().getContent());
assertEquals("http://orcid.org/ext-id-2", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdUrl().getValue());
assertNotNull(profile.getOrcidBio().getKeywords());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getKeywords().getVisibility());
assertEquals(1, profile.getOrcidBio().getKeywords().getKeyword().size());
assertEquals("k2", profile.getOrcidBio().getKeywords().getKeyword().get(0).getContent());
assertNotNull(profile.getOrcidBio().getPersonalDetails());
assertNotNull(profile.getOrcidBio().getPersonalDetails().getOtherNames());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility());
assertEquals(1, profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().size());
assertEquals("o2", profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
assertNotNull(profile.getOrcidBio().getResearcherUrls());
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getResearcherUrls().getVisibility());
assertEquals(1, profile.getOrcidBio().getResearcherUrls().getResearcherUrl().size());
assertEquals("http://orcid.org/researcher-url-2", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
assertEquals("url-name-2", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrlName().getContent());
//Primary address should remain
assertEquals(Iso3166Country.US, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getValue());
profileEntity = profileDao.find(profile.getOrcidIdentifier().getPath());
assertNotNull(profileEntity);
assertNotNull(profileEntity.getAddresses());
assertEquals(2, profileEntity.getAddresses().size());
Iterator<AddressEntity> it = profileEntity.getAddresses().iterator();
while (it.hasNext()) {
assertThat(it.next().getIso2Country(), anyOf(is(org.orcid.jaxb.model.common_v2.Iso3166Country.US), is(org.orcid.jaxb.model.common_v2.Iso3166Country.CR)));
}
//Claim the record
OrcidHistory orcidHistory = new OrcidHistory();
orcidHistory.setClaimed(new Claimed(true));
orcidHistory.setCreationMethod(CreationMethod.DIRECT);
orcidHistory.setSubmissionDate(new SubmissionDate(DateUtils.convertToXMLGregorianCalendar(new Date())));
profile.setOrcidHistory(orcidHistory);
Preferences preferences = new Preferences();
preferences.setSendChangeNotifications(new SendChangeNotifications(true));
preferences.setSendOrcidNews(new SendOrcidNews(true));
//Default visibility for user will be LIMITED
preferences.setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
preferences.setNotificationsEnabled(DefaultPreferences.NOTIFICATIONS_ENABLED);
preferences.setSendEmailFrequencyDays(DefaultPreferences.SEND_EMAIL_FREQUENCY_DAYS);
preferences.setSendMemberUpdateRequests(DefaultPreferences.SEND_MEMBER_UPDATE_REQUESTS);
OrcidInternal internal = new OrcidInternal();
internal.setPreferences(preferences);
profile.setOrcidInternal(internal);
orcidProfileManager.updateOrcidProfile(profile);
//Everything should be updated but the address, because the record is claimed
profile.getOrcidBio().getBiography().setContent("This is my biography # 3");
profile.getOrcidBio().getContactDetails().getAddress().setCountry(new Country(Iso3166Country.PE));
profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setSource(null);
profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdCommonName(new ExternalIdCommonName("common-name-3"));
profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdReference(new ExternalIdReference("ext-id-reference-3"));
profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).setExternalIdUrl(new ExternalIdUrl("http://orcid.org/ext-id-3"));
profile.getOrcidBio().getKeywords().getKeyword().get(0).setSource(null);
profile.getOrcidBio().getKeywords().getKeyword().get(0).setContent("k3");
profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).setSource(null);
profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).setContent("o3");
profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setSource(null);
profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setUrl(new Url("http://orcid.org/researcher-url-3"));
profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).setUrlName(new UrlName("url-name-3"));
orcidProfileManager.updateOrcidBio(profile);
profile = orcidProfileManager.retrieveOrcidProfile(profile.getOrcidIdentifier().getPath());
assertNotNull(profile);
assertNotNull(profile.getOrcidBio());
assertNotNull(profile.getOrcidBio().getBiography());
assertEquals(Visibility.LIMITED, profile.getOrcidBio().getBiography().getVisibility());
assertEquals("This is my biography # 3", profile.getOrcidBio().getBiography().getContent());
assertNotNull(profile.getOrcidBio().getContactDetails());
assertNotNull(profile.getOrcidBio().getContactDetails().getAddress());
assertNotNull(profile.getOrcidBio().getContactDetails().getAddress().getCountry());
assertNotNull(profile.getOrcidBio().getContactDetails().getEmail());
assertEquals(1, profile.getOrcidBio().getContactDetails().getEmail().size());
assertNotNull(profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
assertEquals(email, profile.getOrcidBio().getContactDetails().getEmail().get(0).getValue());
assertNotNull(profile.getOrcidBio().getExternalIdentifiers());
assertEquals(Visibility.LIMITED, profile.getOrcidBio().getExternalIdentifiers().getVisibility());
assertNotNull(profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier());
assertEquals(1, profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().size());
assertEquals("common-name-3", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdCommonName().getContent());
assertEquals("ext-id-reference-3", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdReference().getContent());
assertEquals("http://orcid.org/ext-id-3", profile.getOrcidBio().getExternalIdentifiers().getExternalIdentifier().get(0).getExternalIdUrl().getValue());
assertNotNull(profile.getOrcidBio().getKeywords());
assertEquals(Visibility.LIMITED, profile.getOrcidBio().getKeywords().getVisibility());
assertEquals(1, profile.getOrcidBio().getKeywords().getKeyword().size());
assertEquals("k3", profile.getOrcidBio().getKeywords().getKeyword().get(0).getContent());
assertNotNull(profile.getOrcidBio().getPersonalDetails());
assertNotNull(profile.getOrcidBio().getPersonalDetails().getOtherNames());
assertEquals(Visibility.LIMITED, profile.getOrcidBio().getPersonalDetails().getOtherNames().getVisibility());
assertEquals(1, profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().size());
assertEquals("o3", profile.getOrcidBio().getPersonalDetails().getOtherNames().getOtherName().get(0).getContent());
assertNotNull(profile.getOrcidBio().getResearcherUrls());
assertEquals(Visibility.LIMITED, profile.getOrcidBio().getResearcherUrls().getVisibility());
assertEquals(1, profile.getOrcidBio().getResearcherUrls().getResearcherUrl().size());
assertEquals("http://orcid.org/researcher-url-3", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
assertEquals("url-name-3", profile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrlName().getContent());
profileEntity = profileDao.find(profile.getOrcidIdentifier().getPath());
assertNotNull(profileEntity);
assertNotNull(profileEntity.getAddresses());
assertEquals(3, profileEntity.getAddresses().size());
it = profileEntity.getAddresses().iterator();
while (it.hasNext()) {
assertThat(it.next().getIso2Country(), anyOf(is(org.orcid.jaxb.model.common_v2.Iso3166Country.US), is(org.orcid.jaxb.model.common_v2.Iso3166Country.CR), is(org.orcid.jaxb.model.common_v2.Iso3166Country.PE)));
}
//Primary address should remain
assertEquals(Visibility.PUBLIC, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getVisibility());
assertEquals(Iso3166Country.US, profile.getOrcidBio().getContactDetails().getAddress().getCountry().getValue());
}
Aggregations