Search in sources :

Example 1 with Email

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());
}
Also used : Response(javax.ws.rs.core.Response) Email(org.orcid.jaxb.model.message.Email) GivenNames(org.orcid.jaxb.model.message.GivenNames) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) URI(java.net.URI) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 2 with Email

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());
}
Also used : Response(javax.ws.rs.core.Response) Email(org.orcid.jaxb.model.message.Email) GivenNames(org.orcid.jaxb.model.message.GivenNames) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) URI(java.net.URI) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 3 with Email

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);
}
Also used : Email(org.orcid.jaxb.model.message.Email) ContactDetails(org.orcid.jaxb.model.message.ContactDetails) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ArrayList(java.util.ArrayList) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 4 with Email

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);
}
Also used : Email(org.orcid.jaxb.model.message.Email) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 5 with Email

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);
    }
}
Also used : Email(org.orcid.jaxb.model.message.Email) ProfileEventEntity(org.orcid.persistence.jpa.entities.ProfileEventEntity) HashMap(java.util.HashMap) Source(org.orcid.jaxb.model.message.Source) MessageSource(org.springframework.context.MessageSource)

Aggregations

Email (org.orcid.jaxb.model.message.Email)45 ContactDetails (org.orcid.jaxb.model.message.ContactDetails)22 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)20 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)20 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)18 Test (org.junit.Test)17 PersonalDetails (org.orcid.jaxb.model.message.PersonalDetails)14 GivenNames (org.orcid.jaxb.model.message.GivenNames)12 FamilyName (org.orcid.jaxb.model.message.FamilyName)11 DBUnitTest (org.orcid.test.DBUnitTest)10 ArrayList (java.util.ArrayList)8 Address (org.orcid.jaxb.model.message.Address)7 Biography (org.orcid.jaxb.model.message.Biography)7 CreditName (org.orcid.jaxb.model.message.CreditName)7 ExternalIdentifiers (org.orcid.jaxb.model.message.ExternalIdentifiers)7 OrcidHistory (org.orcid.jaxb.model.message.OrcidHistory)7 ExternalIdentifier (org.orcid.jaxb.model.message.ExternalIdentifier)6 Keyword (org.orcid.jaxb.model.message.Keyword)6 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)6 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)6