Search in sources :

Example 81 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.

the class OrcidInfo method groupEmails.

private Map<String, List<Email>> groupEmails(Emails emails) {
    if (emails == null || emails.getEmails() == null) {
        return null;
    }
    Map<String, List<Email>> groups = new TreeMap<String, List<Email>>();
    for (Email e : emails.getEmails()) {
        if (groups.containsKey(e.getEmail())) {
            groups.get(e.getEmail()).add(e);
        } else {
            List<Email> list = new ArrayList<Email>();
            list.add(e);
            groups.put(e.getEmail(), list);
        }
    }
    return groups;
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 82 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.

the class EmailManagerImpl method addEmail.

@Override
@Transactional
public void addEmail(HttpServletRequest request, String orcid, Email email) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    String sourceId = sourceEntity.getSourceProfile() == null ? null : sourceEntity.getSourceProfile().getId();
    String clientSourceId = sourceEntity.getSourceClient() == null ? null : sourceEntity.getSourceClient().getId();
    Email currentPrimaryEmail = findPrimaryEmail(orcid);
    // Create the new email
    emailDao.addEmail(orcid, email.getEmail(), email.getVisibility(), sourceId, clientSourceId);
    // if primary email changed send notification.
    if (email.isPrimary() && !StringUtils.equals(currentPrimaryEmail.getEmail(), email.getEmail())) {
        request.getSession().setAttribute(EmailConstants.CHECK_EMAIL_VALIDATED, false);
        notificationManager.sendEmailAddressChangedNotification(orcid, email.getEmail(), currentPrimaryEmail.getEmail());
    }
    // send verifcation email for new address
    notificationManager.sendVerificationEmail(orcid, email.getEmail());
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 83 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.

the class EmailManagerImpl method updateEmails.

@Override
@Transactional
public void updateEmails(HttpServletRequest request, String orcid, Emails emails) {
    Email currentPrimaryEmail = findPrimaryEmail(orcid);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        protected void doInTransactionWithoutResult(TransactionStatus status) {
            boolean primaryFound = false;
            Email newPrimaryEmail = null;
            if (emails != null && !emails.getEmails().isEmpty()) {
                for (Email email : emails.getEmails()) {
                    emailDao.updateEmail(orcid, email.getEmail(), email.isCurrent(), email.getVisibility());
                    if (email.isPrimary()) {
                        if (primaryFound) {
                            throw new IllegalArgumentException("More than one primary email specified");
                        } else {
                            primaryFound = true;
                            newPrimaryEmail = email;
                        }
                        emailDao.updatePrimary(orcid, email.getEmail());
                    }
                }
            }
            if (!StringUtils.equals(currentPrimaryEmail.getEmail(), newPrimaryEmail.getEmail())) {
                notificationManager.sendEmailAddressChangedNotification(orcid, newPrimaryEmail.getEmail(), currentPrimaryEmail.getEmail());
                if (!newPrimaryEmail.isVerified()) {
                    notificationManager.sendVerificationEmail(orcid, newPrimaryEmail.getEmail());
                    request.getSession().setAttribute(EmailConstants.CHECK_EMAIL_VALIDATED, false);
                }
            }
        }
    });
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) TransactionStatus(org.springframework.transaction.TransactionStatus) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Transactional(org.springframework.transaction.annotation.Transactional)

Example 84 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.

the class PublicProfileControllerTest method testViewClaimedUserWhenIsLongEnough.

@Test
public void testViewClaimedUserWhenIsLongEnough() {
    //Update the submission date so it is long enough
    ProfileEntity profileEntity = profileDao.find(unclaimedUserOrcid);
    profileEntity.setSubmissionDate(DateUtils.addDays(new Date(), -10));
    profileDao.merge(profileEntity);
    profileDao.flush();
    ModelAndView mav = publicProfileController.publicPreview(request, 1, 0, 15, unclaimedUserOrcid);
    assertEquals("public_profile_v3", mav.getViewName());
    Map<String, Object> model = mav.getModel();
    assertNotNull(model);
    assertTrue(model.containsKey("isPublicProfile"));
    assertTrue(model.containsKey("effectiveUserOrcid"));
    assertEquals(unclaimedUserOrcid, model.get("effectiveUserOrcid"));
    assertTrue(!model.containsKey("biography"));
    assertFalse(model.containsKey("displayName"));
    assertFalse(model.containsKey("title"));
    assertTrue(model.containsKey("publicGroupedOtherNames"));
    Map<String, List<OtherName>> groupedOtherNames = (Map<String, List<OtherName>>) model.get("publicGroupedOtherNames");
    assertNotNull(groupedOtherNames);
    assertEquals(1, groupedOtherNames.keySet().size());
    List<OtherName> publicOtherNames = groupedOtherNames.get("PUBLIC");
    assertEquals(1, publicOtherNames.size());
    assertEquals(Long.valueOf(18), publicOtherNames.get(0).getPutCode());
    assertEquals("PUBLIC", publicOtherNames.get(0).getContent());
    assertEquals(Visibility.PUBLIC, publicOtherNames.get(0).getVisibility());
    assertTrue(model.containsKey("publicGroupedAddresses"));
    Map<String, List<Address>> groupedAddresses = (Map<String, List<Address>>) model.get("publicGroupedAddresses");
    assertNotNull(groupedAddresses);
    assertEquals(1, groupedAddresses.keySet().size());
    assertTrue(groupedAddresses.containsKey("US"));
    List<Address> publicAddresses = groupedAddresses.get("US");
    assertEquals(1, publicAddresses.size());
    assertEquals(Long.valueOf(14), publicAddresses.get(0).getPutCode());
    assertEquals(Iso3166Country.US, publicAddresses.get(0).getCountry().getValue());
    assertEquals(Visibility.PUBLIC, publicAddresses.get(0).getVisibility());
    assertTrue(model.containsKey("publicGroupedKeywords"));
    Map<String, List<Keyword>> groupedKeywords = (Map<String, List<Keyword>>) model.get("publicGroupedKeywords");
    assertNotNull(groupedKeywords);
    assertEquals(1, groupedKeywords.keySet().size());
    List<Keyword> publicKeywords = groupedKeywords.get("PUBLIC");
    assertEquals(Long.valueOf(14), publicKeywords.get(0).getPutCode());
    assertEquals("PUBLIC", publicKeywords.get(0).getContent());
    assertEquals(Visibility.PUBLIC, publicKeywords.get(0).getVisibility());
    assertTrue(model.containsKey("publicGroupedResearcherUrls"));
    Map<String, List<ResearcherUrl>> rUrls = (Map<String, List<ResearcherUrl>>) model.get("publicGroupedResearcherUrls");
    assertNotNull(rUrls);
    assertEquals(1, rUrls.keySet().size());
    assertTrue(rUrls.containsKey("http://www.researcherurl.com?id=18"));
    List<ResearcherUrl> publicResearchUrls = rUrls.get("http://www.researcherurl.com?id=18");
    assertEquals(Long.valueOf(18), publicResearchUrls.get(0).getPutCode());
    assertEquals("public", publicResearchUrls.get(0).getUrlName());
    assertEquals(Visibility.PUBLIC, publicResearchUrls.get(0).getVisibility());
    assertTrue(model.containsKey("publicGroupedEmails"));
    Map<String, List<Email>> emails = (Map<String, List<Email>>) model.get("publicGroupedEmails");
    assertNotNull(emails);
    assertEquals(1, emails.keySet().size());
    List<Email> groupedEmails = emails.get("public_0000-0000-0000-0001@test.orcid.org");
    assertEquals("public_0000-0000-0000-0001@test.orcid.org", groupedEmails.get(0).getEmail());
    assertEquals(Visibility.PUBLIC, groupedEmails.get(0).getVisibility());
    assertTrue(model.containsKey("publicGroupedPersonExternalIdentifiers"));
    Map<String, List<PersonExternalIdentifier>> extIds = (Map<String, List<PersonExternalIdentifier>>) model.get("publicGroupedPersonExternalIdentifiers");
    assertNotNull(extIds);
    assertEquals(1, extIds.keySet().size());
    assertTrue(extIds.containsKey("public:public"));
    List<PersonExternalIdentifier> publicExternalIdentifiers = extIds.get("public:public");
    assertEquals(Long.valueOf(18), publicExternalIdentifiers.get(0).getPutCode());
    assertEquals("http://ext-id/self/public", publicExternalIdentifiers.get(0).getUrl().getValue());
    assertEquals(Visibility.PUBLIC, publicExternalIdentifiers.get(0).getVisibility());
    assertTrue(model.containsKey("isProfileEmpty"));
    Boolean isProfileEmpty = (Boolean) model.get("isProfileEmpty");
    assertTrue(isProfileEmpty);
    assertFalse(model.containsKey("noIndex"));
    //Update the submission date so it is not long enough
    profileEntity = profileDao.find(unclaimedUserOrcid);
    profileEntity.setSubmissionDate(new Date());
    profileDao.merge(profileEntity);
    profileDao.flush();
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) Address(org.orcid.jaxb.model.record_v2.Address) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) Keyword(org.orcid.jaxb.model.record_v2.Keyword) OtherName(org.orcid.jaxb.model.record_v2.OtherName) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) HashMap(java.util.HashMap) Map(java.util.Map) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 85 with Email

use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.

the class PublicProfileControllerTest method testViewValidUser.

@SuppressWarnings("unchecked")
@Test
public void testViewValidUser() {
    ModelAndView mav = publicProfileController.publicPreview(request, 1, 0, 15, userOrcid);
    assertEquals("public_profile_v3", mav.getViewName());
    Map<String, Object> model = mav.getModel();
    assertNotNull(model);
    assertTrue(model.containsKey("isPublicProfile"));
    assertTrue(model.containsKey("effectiveUserOrcid"));
    assertEquals(userOrcid, model.get("effectiveUserOrcid"));
    assertTrue(model.containsKey("biography"));
    Biography biography = (Biography) model.get("biography");
    assertEquals("Biography for 0000-0000-0000-0003", biography.getContent());
    assertTrue(model.containsKey("displayName"));
    String displayName = (String) model.get("displayName");
    assertEquals("Credit Name", displayName);
    assertTrue(model.containsKey("title"));
    assertEquals(localeManager.resolveMessage("layout.public-layout.title", displayName, userOrcid), model.get("title"));
    assertTrue(model.containsKey("publicGroupedOtherNames"));
    Map<String, List<OtherName>> groupedOtherNames = (Map<String, List<OtherName>>) model.get("publicGroupedOtherNames");
    assertNotNull(groupedOtherNames);
    assertEquals(1, groupedOtherNames.keySet().size());
    assertTrue(groupedOtherNames.containsKey("Other Name PUBLIC"));
    List<OtherName> publicOtherNames = groupedOtherNames.get("Other Name PUBLIC");
    assertEquals(1, publicOtherNames.size());
    assertEquals(Long.valueOf(13), publicOtherNames.get(0).getPutCode());
    assertEquals("Other Name PUBLIC", publicOtherNames.get(0).getContent());
    assertEquals(Visibility.PUBLIC, publicOtherNames.get(0).getVisibility());
    assertTrue(model.containsKey("publicGroupedAddresses"));
    Map<String, List<Address>> groupedAddresses = (Map<String, List<Address>>) model.get("publicGroupedAddresses");
    assertNotNull(groupedAddresses);
    assertEquals(1, groupedAddresses.keySet().size());
    assertTrue(groupedAddresses.containsKey("US"));
    List<Address> publicAddresses = groupedAddresses.get("US");
    assertEquals(1, publicAddresses.size());
    assertEquals(Long.valueOf(9), publicAddresses.get(0).getPutCode());
    assertEquals(Iso3166Country.US, publicAddresses.get(0).getCountry().getValue());
    assertEquals(Visibility.PUBLIC, publicAddresses.get(0).getVisibility());
    assertTrue(model.containsKey("countryNames"));
    Map<String, String> countryNames = (Map<String, String>) model.get("countryNames");
    Map<String, String> testCountry = new HashMap<String, String>();
    testCountry.put("US", localeManager.resolveMessage("org.orcid.persistence.jpa.entities.CountryIsoEntity.US"));
    assertEquals(testCountry, countryNames);
    assertTrue(model.containsKey("publicGroupedKeywords"));
    Map<String, List<Keyword>> groupedKeywords = (Map<String, List<Keyword>>) model.get("publicGroupedKeywords");
    assertNotNull(groupedKeywords);
    assertEquals(1, groupedKeywords.keySet().size());
    assertTrue(groupedKeywords.containsKey("PUBLIC"));
    List<Keyword> publicKeywords = groupedKeywords.get("PUBLIC");
    assertEquals(1, publicKeywords.size());
    assertEquals(Long.valueOf(9), publicKeywords.get(0).getPutCode());
    assertEquals("PUBLIC", publicKeywords.get(0).getContent());
    assertEquals(Visibility.PUBLIC, publicKeywords.get(0).getVisibility());
    assertTrue(model.containsKey("publicGroupedResearcherUrls"));
    Map<String, List<ResearcherUrl>> rUrls = (Map<String, List<ResearcherUrl>>) model.get("publicGroupedResearcherUrls");
    assertNotNull(rUrls);
    assertEquals(1, rUrls.keySet().size());
    assertTrue(rUrls.containsKey("http://www.researcherurl.com?id=13"));
    List<ResearcherUrl> publicResearchUrls = rUrls.get("http://www.researcherurl.com?id=13");
    assertEquals(Long.valueOf(13), publicResearchUrls.get(0).getPutCode());
    assertEquals("public_rurl", publicResearchUrls.get(0).getUrlName());
    assertEquals(Visibility.PUBLIC, publicResearchUrls.get(0).getVisibility());
    assertTrue(model.containsKey("publicGroupedEmails"));
    Map<String, List<Email>> emails = (Map<String, List<Email>>) model.get("publicGroupedEmails");
    assertNotNull(emails);
    assertEquals(1, emails.keySet().size());
    assertTrue(emails.containsKey("public_0000-0000-0000-0003@test.orcid.org"));
    List<Email> publicEmails = emails.get("public_0000-0000-0000-0003@test.orcid.org");
    assertEquals("public_0000-0000-0000-0003@test.orcid.org", publicEmails.get(0).getEmail());
    assertEquals(Visibility.PUBLIC, publicEmails.get(0).getVisibility());
    assertTrue(model.containsKey("publicGroupedPersonExternalIdentifiers"));
    Map<String, List<PersonExternalIdentifier>> extIds = (Map<String, List<PersonExternalIdentifier>>) model.get("publicGroupedPersonExternalIdentifiers");
    assertNotNull(extIds);
    assertEquals(1, extIds.keySet().size());
    assertTrue(extIds.containsKey("public_type:public_ref"));
    List<PersonExternalIdentifier> publicExternalIdentifiers = extIds.get("public_type:public_ref");
    assertEquals(Long.valueOf(13), publicExternalIdentifiers.get(0).getPutCode());
    assertEquals("http://ext-id/public_ref", publicExternalIdentifiers.get(0).getUrl().getValue());
    assertEquals(Visibility.PUBLIC, publicExternalIdentifiers.get(0).getVisibility());
    assertTrue(model.containsKey("workIdsJson"));
    assertEquals("[11]", model.get("workIdsJson"));
    assertTrue(model.containsKey("affiliationIdsJson"));
    assertEquals("[17,20]", model.get("affiliationIdsJson"));
    assertTrue(model.containsKey("fundingIdsJson"));
    assertEquals("[10]", model.get("fundingIdsJson"));
    assertTrue(model.containsKey("peerReviewIdsJson"));
    assertEquals("[9]", model.get("peerReviewIdsJson"));
    assertTrue(model.containsKey("isProfileEmpty"));
    Boolean isProfileEmpty = (Boolean) model.get("isProfileEmpty");
    assertFalse(isProfileEmpty);
    assertFalse(model.containsKey("noIndex"));
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) Address(org.orcid.jaxb.model.record_v2.Address) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) Biography(org.orcid.jaxb.model.record_v2.Biography) List(java.util.List) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) Keyword(org.orcid.jaxb.model.record_v2.Keyword) OtherName(org.orcid.jaxb.model.record_v2.OtherName) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) HashMap(java.util.HashMap) Map(java.util.Map) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Email (org.orcid.jaxb.model.record_v2.Email)82 Test (org.junit.Test)79 Emails (org.orcid.jaxb.model.record_v2.Emails)49 Address (org.orcid.jaxb.model.record_v2.Address)41 Keyword (org.orcid.jaxb.model.record_v2.Keyword)41 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)41 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)41 OtherName (org.orcid.jaxb.model.record_v2.OtherName)39 Person (org.orcid.jaxb.model.record_v2.Person)35 Biography (org.orcid.jaxb.model.record_v2.Biography)34 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)33 Addresses (org.orcid.jaxb.model.record_v2.Addresses)31 Keywords (org.orcid.jaxb.model.record_v2.Keywords)31 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)31 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)31 Name (org.orcid.jaxb.model.record_v2.Name)30 Record (org.orcid.jaxb.model.record_v2.Record)19 ArrayList (java.util.ArrayList)18 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)18 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)18