Search in sources :

Example 66 with Emails

use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.

the class OrcidSecurityManager_PersonTest method testPerson_When_AllPrivate_NoSource_ReadPublicToken.

@Test
public void testPerson_When_AllPrivate_NoSource_ReadPublicToken() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.READ_PUBLIC);
    Name name = createName(Visibility.PRIVATE);
    Biography bio = createBiography(Visibility.PRIVATE);
    Address a1 = createAddress(Visibility.PRIVATE, CLIENT_2);
    Address a2 = createAddress(Visibility.PRIVATE, CLIENT_2);
    Address a3 = createAddress(Visibility.PRIVATE, CLIENT_2);
    Addresses addresses = new Addresses();
    addresses.setAddress(new ArrayList<Address>(Arrays.asList(a1, a2, a3)));
    Email e1 = createEmail(Visibility.PRIVATE, CLIENT_2);
    Email e2 = createEmail(Visibility.PRIVATE, CLIENT_2);
    Email e3 = createEmail(Visibility.PRIVATE, CLIENT_2);
    Emails emails = new Emails();
    emails.setEmails(new ArrayList<Email>(Arrays.asList(e1, e2, e3)));
    Keyword k1 = createKeyword(Visibility.PRIVATE, CLIENT_2);
    Keyword k2 = createKeyword(Visibility.PRIVATE, CLIENT_2);
    Keyword k3 = createKeyword(Visibility.PRIVATE, CLIENT_2);
    Keywords keywords = new Keywords();
    keywords.setKeywords(new ArrayList<Keyword>(Arrays.asList(k1, k2, k3)));
    OtherName o1 = createOtherName(Visibility.PRIVATE, CLIENT_2);
    OtherName o2 = createOtherName(Visibility.PRIVATE, CLIENT_2);
    OtherName o3 = createOtherName(Visibility.PRIVATE, CLIENT_2);
    OtherNames otherNames = new OtherNames();
    otherNames.setOtherNames(new ArrayList<OtherName>(Arrays.asList(o1, o2, o3)));
    PersonExternalIdentifier ext1 = createPersonExternalIdentifier(Visibility.PRIVATE, CLIENT_2);
    PersonExternalIdentifier ext2 = createPersonExternalIdentifier(Visibility.PRIVATE, CLIENT_2);
    PersonExternalIdentifier ext3 = createPersonExternalIdentifier(Visibility.PRIVATE, CLIENT_2);
    PersonExternalIdentifiers extIds = new PersonExternalIdentifiers();
    extIds.setExternalIdentifiers(new ArrayList<PersonExternalIdentifier>(Arrays.asList(ext1, ext2, ext3)));
    ResearcherUrl r1 = createResearcherUrl(Visibility.PRIVATE, CLIENT_2);
    ResearcherUrl r2 = createResearcherUrl(Visibility.PRIVATE, CLIENT_2);
    ResearcherUrl r3 = createResearcherUrl(Visibility.PRIVATE, CLIENT_2);
    ResearcherUrls researcherUrls = new ResearcherUrls();
    researcherUrls.setResearcherUrls(new ArrayList<ResearcherUrl>(Arrays.asList(r1, r2, r3)));
    Person p = new Person();
    p.setBiography(bio);
    p.setName(name);
    p.setAddresses(addresses);
    p.setEmails(emails);
    p.setExternalIdentifiers(extIds);
    p.setKeywords(keywords);
    p.setOtherNames(otherNames);
    p.setResearcherUrls(researcherUrls);
    orcidSecurityManager.checkAndFilter(ORCID_1, p);
    assertNotNull(p);
    assertNull(p.getName());
    assertNull(p.getBiography());
    // Check addresses
    assertEquals(0, p.getAddresses().getAddress().size());
    // Check emails
    assertEquals(0, p.getEmails().getEmails().size());
    // Check ext ids
    assertEquals(0, p.getExternalIdentifiers().getExternalIdentifiers().size());
    // Check keywords
    assertEquals(0, p.getKeywords().getKeywords().size());
    // Check other names
    assertEquals(0, p.getOtherNames().getOtherNames().size());
    // Check researcher urls
    assertEquals(0, p.getResearcherUrls().getResearcherUrls().size());
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) Keywords(org.orcid.jaxb.model.v3.dev1.record.Keywords) Address(org.orcid.jaxb.model.v3.dev1.record.Address) Keyword(org.orcid.jaxb.model.v3.dev1.record.Keyword) OtherNames(org.orcid.jaxb.model.v3.dev1.record.OtherNames) OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) PersonExternalIdentifier(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier) OtherName(org.orcid.jaxb.model.v3.dev1.record.OtherName) Name(org.orcid.jaxb.model.v3.dev1.record.Name) Addresses(org.orcid.jaxb.model.v3.dev1.record.Addresses) PersonExternalIdentifiers(org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers) Biography(org.orcid.jaxb.model.v3.dev1.record.Biography) ResearcherUrls(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl) Emails(org.orcid.jaxb.model.v3.dev1.record.Emails) Person(org.orcid.jaxb.model.v3.dev1.record.Person) Test(org.junit.Test)

Example 67 with Emails

use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.

the class EmailManagerTest method getEmailsTest.

@Test
public void getEmailsTest() {
    Emails emails = emailManager.getEmails("0000-0000-0000-0003");
    assertNotNull(emails);
    assertNotNull(emails.getEmails());
    assertEquals(5, emails.getEmails().size());
    boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false;
    for (Email email : emails.getEmails()) {
        if (email.getEmail().equals("public_0000-0000-0000-0003@test.orcid.org")) {
            found1 = true;
        } else if (email.getEmail().equals("limited_0000-0000-0000-0003@test.orcid.org")) {
            found2 = true;
        } else if (email.getEmail().equals("private_0000-0000-0000-0003@test.orcid.org")) {
            found3 = true;
        } else if (email.getEmail().equals("self_limited_0000-0000-0000-0003@test.orcid.org")) {
            found4 = true;
        } else if (email.getEmail().equals("self_private_0000-0000-0000-0003@test.orcid.org")) {
            found5 = true;
        } else {
            fail("Invalid email found: " + email.getEmail());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
    assertTrue(found5);
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) Emails(org.orcid.jaxb.model.v3.dev1.record.Emails) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 68 with Emails

use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.

the class EmailManagerTest method moveEmailToOtherAccountTest.

@Test
public void moveEmailToOtherAccountTest() {
    String email = "public@email.com";
    String from = "4444-4444-4444-4441";
    String to = "4444-4444-4444-4499";
    ProfileEntity destinationBefore = profileDao.find(to);
    Date beforeLastModified = destinationBefore.getLastModified();
    Map<String, String> map = emailManager.findOricdIdsByCommaSeparatedEmails(email);
    assertNotNull(map);
    assertEquals(from, map.get(email));
    emailManager.moveEmailToOtherAccount(email, from, to);
    ProfileEntity destinationAfter = profileDao.find(to);
    Date afterLastModified = destinationAfter.getLastModified();
    assertFalse(beforeLastModified.equals(afterLastModified));
    assertTrue(afterLastModified.getTime() > beforeLastModified.getTime());
    // Assert the email was moved
    map = emailManager.findOricdIdsByCommaSeparatedEmails(email);
    assertNotNull(map);
    assertEquals(to, map.get(email));
    // Assert the email is not anymore in the from record
    Emails emails = emailManager.getEmails(from);
    for (Email e : emails.getEmails()) {
        assertFalse(email.equals(e.getEmail()));
    }
    // Assert the email belongs to the to record
    emails = emailManager.getEmails(to);
    boolean found = false;
    for (Email e : emails.getEmails()) {
        if (email.equals(e.getEmail())) {
            found = true;
        }
    }
    assertTrue(found);
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) Emails(org.orcid.jaxb.model.v3.dev1.record.Emails) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 69 with Emails

use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.

the class EmailManagerTest method getPublicEmailsTest.

@Test
public void getPublicEmailsTest() {
    Emails emails = emailManager.getPublicEmails("0000-0000-0000-0003");
    assertNotNull(emails);
    assertNotNull(emails.getEmails());
    assertEquals(1, emails.getEmails().size());
    assertEquals("public_0000-0000-0000-0003@test.orcid.org", emails.getEmails().get(0).getEmail());
}
Also used : Emails(org.orcid.jaxb.model.v3.dev1.record.Emails) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 70 with Emails

use of org.orcid.jaxb.model.v3.dev1.record.Emails in project ORCID-Source by ORCID.

the class MemberV3ApiServiceDelegatorImpl method viewEmails.

@Override
public Response viewEmails(String orcid) {
    Emails emails = null;
    try {
        // return all emails if client has /email/read-private scope
        orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.EMAIL_READ_PRIVATE);
        emails = emailManagerReadOnly.getEmails(orcid);
        // Lets copy the list so we don't modify the cached collection
        List<Email> filteredList = new ArrayList<Email>(emails.getEmails());
        emails = new Emails();
        emails.setEmails(filteredList);
    } catch (OrcidAccessControlException e) {
        emails = emailManagerReadOnly.getEmails(orcid);
        // Lets copy the list so we don't modify the cached collection
        List<Email> filteredList = new ArrayList<Email>(emails.getEmails());
        emails = new Emails();
        emails.setEmails(filteredList);
        // Filter just in case client doesn't have the /email/read-private
        // scope
        orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED);
    }
    ElementUtils.setPathToEmail(emails, orcid);
    Api3_0_Dev1LastModifiedDatesHelper.calculateLastModified(emails);
    sourceUtils.setSourceName(emails);
    return Response.ok(emails).build();
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Emails(org.orcid.jaxb.model.v3.dev1.record.Emails) OrcidAccessControlException(org.orcid.core.exception.OrcidAccessControlException)

Aggregations

Email (org.orcid.jaxb.model.v3.dev1.record.Email)59 Emails (org.orcid.jaxb.model.v3.dev1.record.Emails)56 Test (org.junit.Test)54 Address (org.orcid.jaxb.model.v3.dev1.record.Address)33 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)32 Keyword (org.orcid.jaxb.model.v3.dev1.record.Keyword)32 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)32 OtherNames (org.orcid.jaxb.model.v3.dev1.record.OtherNames)32 Person (org.orcid.jaxb.model.v3.dev1.record.Person)32 PersonExternalIdentifier (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifier)32 ResearcherUrl (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrl)32 Addresses (org.orcid.jaxb.model.v3.dev1.record.Addresses)31 Keywords (org.orcid.jaxb.model.v3.dev1.record.Keywords)31 PersonExternalIdentifiers (org.orcid.jaxb.model.v3.dev1.record.PersonExternalIdentifiers)31 ResearcherUrls (org.orcid.jaxb.model.v3.dev1.record.ResearcherUrls)31 Name (org.orcid.jaxb.model.v3.dev1.record.Name)27 Record (org.orcid.jaxb.model.v3.dev1.record.Record)15 ArrayList (java.util.ArrayList)13 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)13 DistinctionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.DistinctionSummary)13