use of org.orcid.jaxb.model.message.Email in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testReadUnclaimedWhenNotOwnCreation.
@Test
public void testReadUnclaimedWhenNotOwnCreation() {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
OrcidMessage orcidMessage = createStubOrcidMessage();
Email email = new Email("madeupemail2@semantico.com");
email.setPrimary(true);
orcidMessage.getOrcidProfile().getOrcidBio().getContactDetails().getEmail().add(email);
Response createResponse = t2OrcidApiServiceDelegator.createProfile(mockedUriInfo, orcidMessage);
assertNotNull(createResponse);
assertEquals(HttpStatus.SC_CREATED, createResponse.getStatus());
String location = ((URI) createResponse.getMetadata().getFirst("Location")).getPath();
assertNotNull(location);
String orcid = location.substring(1, 20);
SecurityContextTestUtils.setUpSecurityContextForClientOnly("4444-4444-4444-4448");
Response readResponse = t2OrcidApiServiceDelegator.findFullDetails(orcid);
assertNotNull(readResponse);
assertEquals(HttpStatus.SC_OK, readResponse.getStatus());
OrcidMessage retrievedMessage = (OrcidMessage) readResponse.getEntity();
assertEquals(orcid, retrievedMessage.getOrcidProfile().getOrcidIdentifier().getPath());
GivenNames givenNames = retrievedMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames();
assertNotNull(givenNames);
assertEquals("Reserved For Claim", givenNames.getContent());
}
use of org.orcid.jaxb.model.message.Email in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorTest method testReadUnclaimedWhenNotOwnCreation.
@Test
public void testReadUnclaimedWhenNotOwnCreation() {
setUpSecurityContextForClientOnly();
OrcidMessage orcidMessage = createStubOrcidMessage();
Email email = new Email("madeupemail2@semantico.com");
email.setPrimary(true);
orcidMessage.getOrcidProfile().getOrcidBio().getContactDetails().getEmail().add(email);
Response createResponse = t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
assertNotNull(createResponse);
assertEquals(HttpStatus.SC_CREATED, createResponse.getStatus());
String location = ((URI) createResponse.getMetadata().getFirst("Location")).getPath();
assertNotNull(location);
String orcid = location.substring(1, 20);
setUpSecurityContextForClientOnly("4444-4444-4444-4448");
Response readResponse = t2OrcidApiServiceDelegatorLatest.findFullDetails(orcid);
assertNotNull(readResponse);
assertEquals(HttpStatus.SC_OK, readResponse.getStatus());
OrcidMessage retrievedMessage = (OrcidMessage) readResponse.getEntity();
assertEquals(orcid, retrievedMessage.getOrcidProfile().getOrcidIdentifier().getPath());
GivenNames givenNames = retrievedMessage.getOrcidProfile().getOrcidBio().getPersonalDetails().getGivenNames();
assertNotNull(givenNames);
assertEquals("Reserved For Claim", givenNames.getContent());
}
use of org.orcid.jaxb.model.message.Email in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorTest method testCreateBioWithMultiplePrimaryEmails.
@Test(expected = OrcidValidationException.class)
public void testCreateBioWithMultiplePrimaryEmails() {
setUpSecurityContextForClientOnly();
OrcidMessage orcidMessage = createStubOrcidMessage();
ContactDetails contactDetails = orcidMessage.getOrcidProfile().getOrcidBio().getContactDetails();
List<Email> emailList = new ArrayList<>();
String[] emailStrings = new String[] { "madeupemail@semantico.com", "madeupemail2@semantico.com" };
for (String emailString : emailStrings) {
Email email = new Email(emailString);
email.setPrimary(true);
emailList.add(email);
}
contactDetails.getEmail().addAll(emailList);
t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
}
use of org.orcid.jaxb.model.message.Email in project ORCID-Source by ORCID.
the class T2OrcidApiServiceVersionedDelegatorTest method testAttemptCreateWithLaterButOtherwiseValidVersion.
@Test(expected = OrcidValidationException.class)
public void testAttemptCreateWithLaterButOtherwiseValidVersion() {
setUpSecurityContextForClientOnly();
OrcidMessage orcidMessage = createStubOrcidMessage();
orcidMessage.setMessageVersion("1.0.22");
Email email = new Email("madeupemail3@semantico.com");
orcidMessage.getOrcidProfile().getOrcidBio().getContactDetails().getEmail().add(email);
t2OrcidApiServiceDelegatorV2_1.createProfile(mockedUriInfo, orcidMessage);
}
use of org.orcid.jaxb.model.message.Email in project ORCID-Source by ORCID.
the class NotificationManagerImpl method sendClaimReminderEmail.
@Override
public void sendClaimReminderEmail(OrcidProfile orcidProfile, int daysUntilActivation) {
// Create map of template params
Map<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("emailName", deriveEmailFriendlyName(orcidProfile));
String orcid = orcidProfile.getOrcidIdentifier().getPath();
templateParams.put("orcid", orcid);
templateParams.put("subject", getSubject("email.subject.claim_reminder", orcidProfile));
Source source = orcidProfile.getOrcidHistory().getSource();
String creatorName = "";
if (source != null) {
if (source.getSourceName() != null && source.getSourceName().getContent() != null) {
creatorName = source.getSourceName().getContent();
} else {
creatorName = source.retrieveSourcePath();
}
}
templateParams.put("creatorName", creatorName);
templateParams.put("baseUri", orcidUrlManager.getBaseUrl());
templateParams.put("baseUriHttp", orcidUrlManager.getBaseUriHttp());
templateParams.put("daysUntilActivation", daysUntilActivation);
Email primaryEmail = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail();
if (primaryEmail == null) {
LOGGER.info("Cant send claim reminder email if primary email is null: {}", orcid);
return;
}
String verificationUrl = createClaimVerificationUrl(primaryEmail.getValue(), orcidUrlManager.getBaseUrl());
templateParams.put("verificationUrl", verificationUrl);
addMessageParams(templateParams, orcidProfile);
String email = orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue();
// Generate body from template
String body = templateManager.processTemplate("claim_reminder_email.ftl", templateParams);
String htmlBody = templateManager.processTemplate("claim_reminder_email_html.ftl", templateParams);
// Send message
if (apiRecordCreationEmailEnabled) {
mailGunManager.sendEmail(CLAIM_NOTIFY_ORCID_ORG, email, getSubject("email.subject.claim_reminder", orcidProfile), body, htmlBody);
profileEventDao.persist(new ProfileEventEntity(orcid, ProfileEventType.CLAIM_REMINDER_SENT));
} else {
LOGGER.debug("Not sending claim reminder email, because API record creation email option is disabled. Message would have been: {}", body);
}
}
Aggregations