Search in sources :

Example 36 with Emails

use of org.orcid.jaxb.model.record_rc3.Emails in project ORCID-Source by ORCID.

the class ManageProfileControllerTest method initMocks.

@Before
public void initMocks() throws Exception {
    controller = new ManageProfileController();
    MockitoAnnotations.initMocks(this);
    SecurityContextHolder.getContext().setAuthentication(getAuthentication(USER_ORCID));
    TargetProxyHelper.injectIntoProxy(controller, "profileEntityCacheManager", mockProfileEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(controller, "encryptionManager", mockEncryptionManager);
    TargetProxyHelper.injectIntoProxy(controller, "emailManager", mockEmailManager);
    TargetProxyHelper.injectIntoProxy(controller, "localeManager", mockLocaleManager);
    TargetProxyHelper.injectIntoProxy(controller, "profileEntityManager", mockProfileEntityManager);
    TargetProxyHelper.injectIntoProxy(controller, "givenPermissionToManager", mockGivenPermissionToManager);
    TargetProxyHelper.injectIntoProxy(controller, "orcidSecurityManager", mockOrcidSecurityManager);
    when(mockOrcidSecurityManager.isPasswordConfirmationRequired()).thenReturn(true);
    when(mockEncryptionManager.hashMatches(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    when(mockEncryptionManager.hashMatches(Mockito.eq("invalid password"), Mockito.anyString())).thenReturn(false);
    when(mockProfileEntityManager.deprecateProfile(Mockito.anyString(), Mockito.anyString())).thenReturn(false);
    when(mockProfileEntityManager.deprecateProfile(Mockito.eq(DEPRECATED_USER_ORCID), Mockito.eq(USER_ORCID))).thenReturn(true);
    when(mockLocaleManager.resolveMessage(Mockito.anyString(), Mockito.any())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArgument(0);
        }
    });
    when(mockProfileEntityCacheManager.retrieve(Mockito.anyString())).then(new Answer<ProfileEntity>() {

        @Override
        public ProfileEntity answer(InvocationOnMock invocation) throws Throwable {
            ProfileEntity entity = new ProfileEntity();
            entity.setId(invocation.getArgument(0));
            Set<GivenPermissionToEntity> givenPermissionTo = new HashSet<GivenPermissionToEntity>();
            IntStream.range(0, 2).forEachOrdered(i -> {
                GivenPermissionToEntity e1 = new GivenPermissionToEntity();
                e1.setId(Long.valueOf(i));
                Date now = new Date();
                e1.setApprovalDate(now);
                e1.setDateCreated(now);
                e1.setGiver(invocation.getArgument(0));
                ProfileSummaryEntity ps = new ProfileSummaryEntity();
                RecordNameEntity recordName = new RecordNameEntity();
                recordName.setVisibility(Visibility.PUBLIC);
                if (i == 0) {
                    ps.setId("0000-0000-0000-0004");
                    recordName.setCreditName("Credit Name");
                } else {
                    ps.setId("0000-0000-0000-0005");
                    recordName.setFamilyName("Family Name");
                    recordName.setGivenNames("Given Names");
                }
                ps.setRecordNameEntity(recordName);
                e1.setReceiver(ps);
                givenPermissionTo.add(e1);
            });
            entity.setGivenPermissionTo(givenPermissionTo);
            EmailEntity email1 = new EmailEntity();
            email1.setId(invocation.getArgument(0) + "_1@test.orcid.org");
            email1.setVerified(true);
            email1.setCurrent(true);
            email1.setDateCreated(new Date());
            email1.setLastModified(new Date());
            email1.setPrimary(true);
            email1.setVisibility(Visibility.PUBLIC);
            EmailEntity email2 = new EmailEntity();
            email2.setId(invocation.getArgument(0) + "_2@test.orcid.org");
            email2.setVerified(true);
            email2.setCurrent(false);
            email2.setDateCreated(new Date());
            email2.setLastModified(new Date());
            email2.setPrimary(false);
            email2.setVisibility(Visibility.PUBLIC);
            Set<EmailEntity> emails = new HashSet<EmailEntity>();
            emails.add(email1);
            emails.add(email2);
            entity.setEmails(emails);
            entity.setRecordNameEntity(getRecordName(invocation.getArgument(0)));
            entity.setEncryptedPassword("password");
            return entity;
        }
    });
    when(mockEmailManager.getEmails(Mockito.anyString(), Mockito.anyLong())).thenAnswer(new Answer<Emails>() {

        @Override
        public Emails answer(InvocationOnMock invocation) throws Throwable {
            Emails emails = new Emails();
            Email email1 = new Email();
            email1.setEmail(invocation.getArgument(0) + "_1@test.orcid.org");
            email1.setVisibility(Visibility.PUBLIC);
            emails.getEmails().add(email1);
            Email email2 = new Email();
            email2.setEmail(invocation.getArgument(0) + "_2@test.orcid.org");
            email2.setVisibility(Visibility.PUBLIC);
            emails.getEmails().add(email2);
            return emails;
        }
    });
    when(mockEmailManager.findCaseInsensitive(Mockito.anyString())).thenAnswer(new Answer<EmailEntity>() {

        @Override
        public EmailEntity answer(InvocationOnMock invocation) throws Throwable {
            String emailString = invocation.getArgument(0);
            String orcidString = emailString.substring(0, (emailString.indexOf("_")));
            EmailEntity email = new EmailEntity();
            email.setId(emailString);
            email.setVisibility(Visibility.PUBLIC);
            ProfileEntity entity = new ProfileEntity(orcidString);
            entity.setEncryptedPassword("password");
            entity.setRecordNameEntity(getRecordName(orcidString));
            email.setProfile(entity);
            return email;
        }
    });
}
Also used : Arrays(java.util.Arrays) TargetProxyHelper(org.orcid.test.TargetProxyHelper) ProfileSummaryEntity(org.orcid.persistence.jpa.entities.ProfileSummaryEntity) Date(java.util.Date) DelegateForm(org.orcid.pojo.DelegateForm) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) StringUtils(org.apache.commons.lang3.StringUtils) NamesForm(org.orcid.pojo.ajaxForm.NamesForm) MockitoAnnotations(org.mockito.MockitoAnnotations) ManageDelegate(org.orcid.pojo.ManageDelegate) OrcidType(org.orcid.jaxb.model.message.OrcidType) ProfileEntityCacheManager(org.orcid.core.manager.ProfileEntityCacheManager) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) BiographyForm(org.orcid.pojo.ajaxForm.BiographyForm) EncryptionManager(org.orcid.core.manager.EncryptionManager) Set(java.util.Set) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) LocaleManager(org.orcid.core.locale.LocaleManager) Text(org.orcid.pojo.ajaxForm.Text) List(java.util.List) OrcidWebRole(org.orcid.core.security.OrcidWebRole) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) Biography(org.orcid.jaxb.model.record_v2.Biography) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) IntStream(java.util.stream.IntStream) NoSuchRequestHandlingMethodException(org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException) Mock(org.mockito.Mock) FamilyName(org.orcid.jaxb.model.record_v2.FamilyName) EmailManager(org.orcid.core.manager.EmailManager) CreditName(org.orcid.jaxb.model.common_v2.CreditName) HashSet(java.util.HashSet) GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OrcidSecurityManager(org.orcid.core.manager.OrcidSecurityManager) SecurityQuestion(org.orcid.pojo.SecurityQuestion) Before(org.junit.Before) OrcidProfileUserDetails(org.orcid.core.oauth.OrcidProfileUserDetails) DeprecateProfile(org.orcid.pojo.DeprecateProfile) GivenNames(org.orcid.jaxb.model.record_v2.GivenNames) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) BiographyManager(org.orcid.core.manager.BiographyManager) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Assert.assertNull(org.junit.Assert.assertNull) RecordNameManager(org.orcid.core.manager.RecordNameManager) Email(org.orcid.jaxb.model.record_v2.Email) Emails(org.orcid.jaxb.model.record_v2.Emails) GivenPermissionToManager(org.orcid.core.manager.GivenPermissionToManager) Name(org.orcid.jaxb.model.record_v2.Name) Assert.assertEquals(org.junit.Assert.assertEquals) ProfileEntityManager(org.orcid.core.manager.ProfileEntityManager) ProfileSummaryEntity(org.orcid.persistence.jpa.entities.ProfileSummaryEntity) Set(java.util.Set) HashSet(java.util.HashSet) Email(org.orcid.jaxb.model.record_v2.Email) GivenPermissionToEntity(org.orcid.persistence.jpa.entities.GivenPermissionToEntity) RecordNameEntity(org.orcid.persistence.jpa.entities.RecordNameEntity) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Emails(org.orcid.jaxb.model.record_v2.Emails) Before(org.junit.Before)

Example 37 with Emails

use of org.orcid.jaxb.model.record_rc3.Emails in project ORCID-Source by ORCID.

the class SourceUtils method setSourceName.

public void setSourceName(Person person) {
    if (person == null) {
        return;
    }
    if (person.getAddresses() != null) {
        Addresses addresses = person.getAddresses();
        setSourceName(addresses);
    }
    if (person.getEmails() != null) {
        Emails emails = person.getEmails();
        setSourceName(emails);
    }
    if (person.getExternalIdentifiers() != null) {
        PersonExternalIdentifiers extIds = person.getExternalIdentifiers();
        setSourceName(extIds);
    }
    if (person.getKeywords() != null) {
        Keywords keywords = person.getKeywords();
        setSourceName(keywords);
    }
    if (person.getOtherNames() != null) {
        OtherNames otherNames = person.getOtherNames();
        setSourceName(otherNames);
    }
    if (person.getResearcherUrls() != null) {
        ResearcherUrls researcherUrls = person.getResearcherUrls();
        setSourceName(researcherUrls);
    }
}
Also used : Addresses(org.orcid.jaxb.model.record_v2.Addresses) Keywords(org.orcid.jaxb.model.record_v2.Keywords) PersonExternalIdentifiers(org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers) OtherNames(org.orcid.jaxb.model.record_v2.OtherNames) ResearcherUrls(org.orcid.jaxb.model.record_v2.ResearcherUrls) Emails(org.orcid.jaxb.model.record_v2.Emails)

Example 38 with Emails

use of org.orcid.jaxb.model.record_rc3.Emails in project ORCID-Source by ORCID.

the class RecordTest method testViewRecordFromPublicAPI.

@Test
public void testViewRecordFromPublicAPI() {
    ClientResponse response = publicV2ApiClient.viewRecordXML(getUser1OrcidId());
    assertNotNull(response);
    assertEquals("invalid " + response, 200, response.getStatus());
    Record record = response.getEntity(Record.class);
    assertNotNull(record);
    assertNotNull(record.getOrcidIdentifier());
    assertEquals(getUser1OrcidId(), record.getOrcidIdentifier().getPath());
    //Check the visibility of every activity that exists
    if (record.getActivitiesSummary() != null) {
        if (record.getActivitiesSummary() != null) {
            //Educations
            if (record.getActivitiesSummary().getEducations() != null) {
                Educations e = record.getActivitiesSummary().getEducations();
                if (e.getSummaries() != null) {
                    for (EducationSummary s : e.getSummaries()) {
                        assertNotNull(s.getSource());
                        assertEquals(Visibility.PUBLIC, s.getVisibility());
                    }
                }
            }
            //Employments
            if (record.getActivitiesSummary().getEmployments() != null) {
                Employments e = record.getActivitiesSummary().getEmployments();
                if (e.getSummaries() != null) {
                    for (EmploymentSummary s : e.getSummaries()) {
                        assertNotNull(s.getSource());
                        assertEquals(Visibility.PUBLIC, s.getVisibility());
                    }
                }
            }
            //Fundings
            if (record.getActivitiesSummary().getFundings() != null) {
                Fundings f = record.getActivitiesSummary().getFundings();
                List<FundingGroup> groups = f.getFundingGroup();
                if (groups != null) {
                    for (FundingGroup fGroup : groups) {
                        List<FundingSummary> summaries = fGroup.getFundingSummary();
                        if (summaries != null) {
                            for (FundingSummary s : summaries) {
                                assertNotNull(s.getSource());
                                assertEquals(Visibility.PUBLIC, s.getVisibility());
                            }
                        }
                    }
                }
            }
            //PeerReviews
            if (record.getActivitiesSummary().getPeerReviews() != null) {
                PeerReviews p = record.getActivitiesSummary().getPeerReviews();
                List<PeerReviewGroup> groups = p.getPeerReviewGroup();
                if (groups != null) {
                    for (PeerReviewGroup pGroup : groups) {
                        List<PeerReviewSummary> summaries = pGroup.getPeerReviewSummary();
                        if (summaries != null) {
                            for (PeerReviewSummary s : summaries) {
                                assertNotNull(s.getSource());
                                assertEquals(Visibility.PUBLIC, s.getVisibility());
                            }
                        }
                    }
                }
            }
            //Works
            if (record.getActivitiesSummary().getWorks() != null) {
                Works w = record.getActivitiesSummary().getWorks();
                List<WorkGroup> groups = w.getWorkGroup();
                if (groups != null) {
                    for (WorkGroup wGroup : groups) {
                        List<WorkSummary> summaries = wGroup.getWorkSummary();
                        if (summaries != null) {
                            for (WorkSummary s : summaries) {
                                assertNotNull(s.getSource());
                                assertEquals(Visibility.PUBLIC, s.getVisibility());
                            }
                        }
                    }
                }
            }
        }
    }
    //Check the visibility of every biography elements that exists
    if (record.getPerson() != null) {
        //Address
        if (record.getPerson().getAddresses() != null) {
            Addresses addresses = record.getPerson().getAddresses();
            List<Address> list = addresses.getAddress();
            if (list != null) {
                for (Address o : list) {
                    assertNotNull(o.getSource());
                    assertEquals(Visibility.PUBLIC, o.getVisibility());
                }
            }
        }
        //Biography
        if (record.getPerson().getBiography() != null) {
            Biography b = record.getPerson().getBiography();
            if (b != null) {
                assertNotNull(b.getVisibility());
                assertEquals(Visibility.PUBLIC, b.getVisibility());
            }
        }
        //Emails
        if (record.getPerson().getEmails() != null) {
            Emails emails = record.getPerson().getEmails();
            List<Email> list = emails.getEmails();
            if (list != null) {
                for (Email e : list) {
                    assertNotNull(e.getVisibility());
                    assertEquals(Visibility.PUBLIC, e.getVisibility());
                }
            }
        }
        //External identifiers
        if (record.getPerson().getExternalIdentifiers() != null) {
            PersonExternalIdentifiers extIds = record.getPerson().getExternalIdentifiers();
            List<PersonExternalIdentifier> list = extIds.getExternalIdentifiers();
            if (list != null) {
                for (PersonExternalIdentifier e : list) {
                    assertEquals(Visibility.PUBLIC, e.getVisibility());
                }
            }
        }
        //Keywords
        if (record.getPerson().getKeywords() != null) {
            Keywords keywords = record.getPerson().getKeywords();
            List<Keyword> list = keywords.getKeywords();
            if (list != null) {
                for (Keyword e : list) {
                    assertEquals(Visibility.PUBLIC, e.getVisibility());
                }
            }
        }
        //Name
        if (record.getPerson().getName() != null) {
            Name name = record.getPerson().getName();
            assertEquals(Visibility.PUBLIC, name.getVisibility());
        }
        //Other names
        if (record.getPerson().getOtherNames() != null) {
            OtherNames otherNames = record.getPerson().getOtherNames();
            List<OtherName> list = otherNames.getOtherNames();
            if (list != null) {
                for (OtherName e : list) {
                    assertEquals(Visibility.PUBLIC, e.getVisibility());
                }
            }
        }
        //Researcher urls
        if (record.getPerson().getResearcherUrls() != null) {
            ResearcherUrls rUrls = record.getPerson().getResearcherUrls();
            List<ResearcherUrl> list = rUrls.getResearcherUrls();
            if (list != null) {
                for (ResearcherUrl e : list) {
                    assertEquals(Visibility.PUBLIC, e.getVisibility());
                }
            }
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Email(org.orcid.jaxb.model.record_rc2.Email) Keywords(org.orcid.jaxb.model.record_rc2.Keywords) Address(org.orcid.jaxb.model.record_rc2.Address) Fundings(org.orcid.jaxb.model.record.summary_rc2.Fundings) OtherNames(org.orcid.jaxb.model.record_rc2.OtherNames) PeerReviews(org.orcid.jaxb.model.record.summary_rc2.PeerReviews) Name(org.orcid.jaxb.model.record_rc2.Name) OtherName(org.orcid.jaxb.model.record_rc2.OtherName) Addresses(org.orcid.jaxb.model.record_rc2.Addresses) WorkGroup(org.orcid.jaxb.model.record.summary_rc2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_rc2.WorkSummary) FundingSummary(org.orcid.jaxb.model.record.summary_rc2.FundingSummary) Biography(org.orcid.jaxb.model.record_rc2.Biography) ResearcherUrls(org.orcid.jaxb.model.record_rc2.ResearcherUrls) Record(org.orcid.jaxb.model.record_rc2.Record) ResearcherUrl(org.orcid.jaxb.model.record_rc2.ResearcherUrl) Emails(org.orcid.jaxb.model.record_rc2.Emails) Works(org.orcid.jaxb.model.record.summary_rc2.Works) PeerReviewGroup(org.orcid.jaxb.model.record.summary_rc2.PeerReviewGroup) Keyword(org.orcid.jaxb.model.record_rc2.Keyword) OtherName(org.orcid.jaxb.model.record_rc2.OtherName) PersonExternalIdentifier(org.orcid.jaxb.model.record_rc2.PersonExternalIdentifier) FundingGroup(org.orcid.jaxb.model.record.summary_rc2.FundingGroup) Employments(org.orcid.jaxb.model.record.summary_rc2.Employments) PersonExternalIdentifiers(org.orcid.jaxb.model.record_rc2.PersonExternalIdentifiers) EducationSummary(org.orcid.jaxb.model.record.summary_rc2.EducationSummary) PeerReviewSummary(org.orcid.jaxb.model.record.summary_rc2.PeerReviewSummary) Educations(org.orcid.jaxb.model.record.summary_rc2.Educations) EmploymentSummary(org.orcid.jaxb.model.record.summary_rc2.EmploymentSummary) Test(org.junit.Test)

Example 39 with Emails

use of org.orcid.jaxb.model.record_rc3.Emails in project ORCID-Source by ORCID.

the class RecordTest method testViewRecordFromMemberAPI.

@Test
public void testViewRecordFromMemberAPI() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    ClientResponse response = memberV2ApiClient.viewRecord(getUser1OrcidId(), accessToken);
    assertNotNull(response);
    assertEquals("invalid " + response, 200, response.getStatus());
    Record record = response.getEntity(Record.class);
    assertNotNull(record);
    assertNotNull(record.getOrcidIdentifier());
    assertEquals(getUser1OrcidId(), record.getOrcidIdentifier().getPath());
    //Check the visibility of every activity that exists
    if (record.getActivitiesSummary() != null) {
        //Educations
        if (record.getActivitiesSummary().getEducations() != null) {
            Educations e = record.getActivitiesSummary().getEducations();
            if (e.getSummaries() != null) {
                for (EducationSummary s : e.getSummaries()) {
                    assertNotNull(s.getSource());
                    assertNotNull(s.getVisibility());
                    Visibility v = s.getVisibility();
                    //If the visibility is PRIVATE the client should be the owner
                    if (Visibility.PRIVATE.equals(v)) {
                        assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Employments
        if (record.getActivitiesSummary().getEmployments() != null) {
            Employments e = record.getActivitiesSummary().getEmployments();
            if (e.getSummaries() != null) {
                for (EmploymentSummary s : e.getSummaries()) {
                    assertNotNull(s.getSource());
                    assertNotNull(s.getVisibility());
                    Visibility v = s.getVisibility();
                    //If the visibility is PRIVATE the client should be the owner
                    if (Visibility.PRIVATE.equals(v)) {
                        assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Fundings
        if (record.getActivitiesSummary().getFundings() != null) {
            Fundings f = record.getActivitiesSummary().getFundings();
            List<FundingGroup> groups = f.getFundingGroup();
            if (groups != null) {
                for (FundingGroup fGroup : groups) {
                    List<FundingSummary> summaries = fGroup.getFundingSummary();
                    if (summaries != null) {
                        for (FundingSummary s : summaries) {
                            assertNotNull(s.getSource());
                            assertNotNull(s.getVisibility());
                            Visibility v = s.getVisibility();
                            //If the visibility is PRIVATE the client should be the owner
                            if (Visibility.PRIVATE.equals(v)) {
                                assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                            }
                        }
                    }
                }
            }
        }
        //PeerReviews
        if (record.getActivitiesSummary().getPeerReviews() != null) {
            PeerReviews p = record.getActivitiesSummary().getPeerReviews();
            List<PeerReviewGroup> groups = p.getPeerReviewGroup();
            if (groups != null) {
                for (PeerReviewGroup pGroup : groups) {
                    List<PeerReviewSummary> summaries = pGroup.getPeerReviewSummary();
                    if (summaries != null) {
                        for (PeerReviewSummary s : summaries) {
                            assertNotNull(s.getSource());
                            assertNotNull(s.getVisibility());
                            Visibility v = s.getVisibility();
                            //If the visibility is PRIVATE the client should be the owner
                            if (Visibility.PRIVATE.equals(v)) {
                                assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                            }
                        }
                    }
                }
            }
        }
        //Works
        if (record.getActivitiesSummary().getWorks() != null) {
            Works w = record.getActivitiesSummary().getWorks();
            List<WorkGroup> groups = w.getWorkGroup();
            if (groups != null) {
                for (WorkGroup wGroup : groups) {
                    List<WorkSummary> summaries = wGroup.getWorkSummary();
                    if (summaries != null) {
                        for (WorkSummary s : summaries) {
                            assertNotNull(s.getSource());
                            assertNotNull(s.getVisibility());
                            Visibility v = s.getVisibility();
                            //If the visibility is PRIVATE the client should be the owner
                            if (Visibility.PRIVATE.equals(v)) {
                                assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                            }
                        }
                    }
                }
            }
        }
    }
    //Check the visibility of every biography elements that exists
    if (record.getPerson() != null) {
        //Address
        if (record.getPerson().getAddresses() != null) {
            Addresses addresses = record.getPerson().getAddresses();
            List<Address> list = addresses.getAddress();
            if (list != null) {
                for (Address o : list) {
                    assertNotNull(o.getSource());
                    assertNotNull(o.getVisibility());
                    Visibility v = o.getVisibility();
                    //If the visibility is PRIVATE the client should be the owner
                    if (Visibility.PRIVATE.equals(v)) {
                        assertEquals(getClient1ClientId(), o.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Biography
        if (record.getPerson().getBiography() != null) {
            Biography b = record.getPerson().getBiography();
            if (b != null) {
                assertNotNull(b.getVisibility());
                if (Visibility.PRIVATE.equals(b.getVisibility())) {
                    fail("Visibility is private");
                }
            }
        }
        //Emails
        if (record.getPerson().getEmails() != null) {
            Emails emails = record.getPerson().getEmails();
            List<Email> list = emails.getEmails();
            if (list != null) {
                for (Email e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        fail("Email " + e.getEmail() + " is private");
                    }
                }
            }
        }
        //External identifiers
        if (record.getPerson().getExternalIdentifiers() != null) {
            PersonExternalIdentifiers extIds = record.getPerson().getExternalIdentifiers();
            List<PersonExternalIdentifier> list = extIds.getExternalIdentifiers();
            if (list != null) {
                for (PersonExternalIdentifier e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        assertEquals(getClient1ClientId(), e.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Keywords
        if (record.getPerson().getKeywords() != null) {
            Keywords keywords = record.getPerson().getKeywords();
            List<Keyword> list = keywords.getKeywords();
            if (list != null) {
                for (Keyword e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        assertEquals(getClient1ClientId(), e.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Name
        if (record.getPerson().getName() != null) {
            Name name = record.getPerson().getName();
            if (Visibility.PRIVATE.equals(name.getVisibility())) {
                fail("Name is private");
            }
        }
        //Other names
        if (record.getPerson().getOtherNames() != null) {
            OtherNames otherNames = record.getPerson().getOtherNames();
            List<OtherName> list = otherNames.getOtherNames();
            if (list != null) {
                for (OtherName e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        assertEquals(getClient1ClientId(), e.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Researcher urls
        if (record.getPerson().getResearcherUrls() != null) {
            ResearcherUrls rUrls = record.getPerson().getResearcherUrls();
            List<ResearcherUrl> list = rUrls.getResearcherUrls();
            if (list != null) {
                for (ResearcherUrl e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        assertEquals(getClient1ClientId(), e.getSource().retrieveSourcePath());
                    }
                }
            }
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Email(org.orcid.jaxb.model.record_rc2.Email) Keywords(org.orcid.jaxb.model.record_rc2.Keywords) Address(org.orcid.jaxb.model.record_rc2.Address) Fundings(org.orcid.jaxb.model.record.summary_rc2.Fundings) OtherNames(org.orcid.jaxb.model.record_rc2.OtherNames) PeerReviews(org.orcid.jaxb.model.record.summary_rc2.PeerReviews) Name(org.orcid.jaxb.model.record_rc2.Name) OtherName(org.orcid.jaxb.model.record_rc2.OtherName) Addresses(org.orcid.jaxb.model.record_rc2.Addresses) WorkGroup(org.orcid.jaxb.model.record.summary_rc2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_rc2.WorkSummary) FundingSummary(org.orcid.jaxb.model.record.summary_rc2.FundingSummary) Biography(org.orcid.jaxb.model.record_rc2.Biography) ResearcherUrls(org.orcid.jaxb.model.record_rc2.ResearcherUrls) Record(org.orcid.jaxb.model.record_rc2.Record) ResearcherUrl(org.orcid.jaxb.model.record_rc2.ResearcherUrl) Emails(org.orcid.jaxb.model.record_rc2.Emails) Works(org.orcid.jaxb.model.record.summary_rc2.Works) PeerReviewGroup(org.orcid.jaxb.model.record.summary_rc2.PeerReviewGroup) Keyword(org.orcid.jaxb.model.record_rc2.Keyword) OtherName(org.orcid.jaxb.model.record_rc2.OtherName) PersonExternalIdentifier(org.orcid.jaxb.model.record_rc2.PersonExternalIdentifier) FundingGroup(org.orcid.jaxb.model.record.summary_rc2.FundingGroup) Employments(org.orcid.jaxb.model.record.summary_rc2.Employments) PersonExternalIdentifiers(org.orcid.jaxb.model.record_rc2.PersonExternalIdentifiers) EducationSummary(org.orcid.jaxb.model.record.summary_rc2.EducationSummary) PeerReviewSummary(org.orcid.jaxb.model.record.summary_rc2.PeerReviewSummary) Educations(org.orcid.jaxb.model.record.summary_rc2.Educations) EmploymentSummary(org.orcid.jaxb.model.record.summary_rc2.EmploymentSummary) Visibility(org.orcid.jaxb.model.common_rc2.Visibility) Test(org.junit.Test)

Example 40 with Emails

use of org.orcid.jaxb.model.record_rc3.Emails in project ORCID-Source by ORCID.

the class RecordTest method testViewRecordFromMemberAPI.

@Test
public void testViewRecordFromMemberAPI() throws InterruptedException, JSONException {
    String accessToken = getAccessToken();
    assertNotNull(accessToken);
    ClientResponse response = memberV2_1ApiClient.viewRecord(getUser1OrcidId(), accessToken);
    assertNotNull(response);
    assertEquals("invalid " + response, 200, response.getStatus());
    Record record = response.getEntity(Record.class);
    assertNotNull(record);
    assertNotNull(record.getOrcidIdentifier());
    assertEquals(getUser1OrcidId(), record.getOrcidIdentifier().getPath());
    //Check the visibility of every activity that exists
    if (record.getActivitiesSummary() != null) {
        //Educations
        if (record.getActivitiesSummary().getEducations() != null) {
            Educations e = record.getActivitiesSummary().getEducations();
            if (e.getSummaries() != null) {
                for (EducationSummary s : e.getSummaries()) {
                    assertNotNull(s.getSource());
                    assertNotNull(s.getVisibility());
                    Visibility v = s.getVisibility();
                    //If the visibility is PRIVATE the client should be the owner
                    if (Visibility.PRIVATE.equals(v)) {
                        assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Employments
        if (record.getActivitiesSummary().getEmployments() != null) {
            Employments e = record.getActivitiesSummary().getEmployments();
            if (e.getSummaries() != null) {
                for (EmploymentSummary s : e.getSummaries()) {
                    assertNotNull(s.getSource());
                    assertNotNull(s.getVisibility());
                    Visibility v = s.getVisibility();
                    //If the visibility is PRIVATE the client should be the owner
                    if (Visibility.PRIVATE.equals(v)) {
                        assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Fundings
        if (record.getActivitiesSummary().getFundings() != null) {
            Fundings f = record.getActivitiesSummary().getFundings();
            List<FundingGroup> groups = f.getFundingGroup();
            if (groups != null) {
                for (FundingGroup fGroup : groups) {
                    List<FundingSummary> summaries = fGroup.getFundingSummary();
                    if (summaries != null) {
                        for (FundingSummary s : summaries) {
                            assertNotNull(s.getSource());
                            assertNotNull(s.getVisibility());
                            Visibility v = s.getVisibility();
                            //If the visibility is PRIVATE the client should be the owner
                            if (Visibility.PRIVATE.equals(v)) {
                                assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                            }
                        }
                    }
                }
            }
        }
        //PeerReviews
        if (record.getActivitiesSummary().getPeerReviews() != null) {
            PeerReviews p = record.getActivitiesSummary().getPeerReviews();
            List<PeerReviewGroup> groups = p.getPeerReviewGroup();
            if (groups != null) {
                for (PeerReviewGroup pGroup : groups) {
                    List<PeerReviewSummary> summaries = pGroup.getPeerReviewSummary();
                    if (summaries != null) {
                        for (PeerReviewSummary s : summaries) {
                            assertNotNull(s.getSource());
                            assertNotNull(s.getVisibility());
                            Visibility v = s.getVisibility();
                            //If the visibility is PRIVATE the client should be the owner
                            if (Visibility.PRIVATE.equals(v)) {
                                assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                            }
                        }
                    }
                }
            }
        }
        //Works
        if (record.getActivitiesSummary().getWorks() != null) {
            Works w = record.getActivitiesSummary().getWorks();
            List<WorkGroup> groups = w.getWorkGroup();
            if (groups != null) {
                for (WorkGroup wGroup : groups) {
                    List<WorkSummary> summaries = wGroup.getWorkSummary();
                    if (summaries != null) {
                        for (WorkSummary s : summaries) {
                            assertNotNull(s.getSource());
                            assertNotNull(s.getVisibility());
                            Visibility v = s.getVisibility();
                            //If the visibility is PRIVATE the client should be the owner
                            if (Visibility.PRIVATE.equals(v)) {
                                assertEquals(getClient1ClientId(), s.getSource().retrieveSourcePath());
                            }
                        }
                    }
                }
            }
        }
    }
    //Check the visibility of every biography elements that exists
    if (record.getPerson() != null) {
        //Address
        if (record.getPerson().getAddresses() != null) {
            Addresses addresses = record.getPerson().getAddresses();
            List<Address> list = addresses.getAddress();
            if (list != null) {
                for (Address o : list) {
                    assertNotNull(o.getSource());
                    assertNotNull(o.getVisibility());
                    Visibility v = o.getVisibility();
                    //If the visibility is PRIVATE the client should be the owner
                    if (Visibility.PRIVATE.equals(v)) {
                        assertEquals(getClient1ClientId(), o.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Biography
        if (record.getPerson().getBiography() != null) {
            Biography b = record.getPerson().getBiography();
            if (b != null) {
                assertNotNull(b.getVisibility());
                if (Visibility.PRIVATE.equals(b.getVisibility())) {
                    fail("Visibility is private");
                }
            }
        }
        //Emails
        if (record.getPerson().getEmails() != null) {
            Emails emails = record.getPerson().getEmails();
            List<Email> list = emails.getEmails();
            if (list != null) {
                for (Email e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        fail("Email " + e.getEmail() + " is private");
                    }
                }
            }
        }
        //External identifiers
        if (record.getPerson().getExternalIdentifiers() != null) {
            PersonExternalIdentifiers extIds = record.getPerson().getExternalIdentifiers();
            List<PersonExternalIdentifier> list = extIds.getExternalIdentifiers();
            if (list != null) {
                for (PersonExternalIdentifier e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        assertEquals(getClient1ClientId(), e.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Keywords
        if (record.getPerson().getKeywords() != null) {
            Keywords keywords = record.getPerson().getKeywords();
            List<Keyword> list = keywords.getKeywords();
            if (list != null) {
                for (Keyword e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        assertEquals(getClient1ClientId(), e.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Name
        if (record.getPerson().getName() != null) {
            Name name = record.getPerson().getName();
            if (Visibility.PRIVATE.equals(name.getVisibility())) {
                fail("Name is private");
            }
        }
        //Other names
        if (record.getPerson().getOtherNames() != null) {
            OtherNames otherNames = record.getPerson().getOtherNames();
            List<OtherName> list = otherNames.getOtherNames();
            if (list != null) {
                for (OtherName e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        assertEquals(getClient1ClientId(), e.getSource().retrieveSourcePath());
                    }
                }
            }
        }
        //Researcher urls
        if (record.getPerson().getResearcherUrls() != null) {
            ResearcherUrls rUrls = record.getPerson().getResearcherUrls();
            List<ResearcherUrl> list = rUrls.getResearcherUrls();
            if (list != null) {
                for (ResearcherUrl e : list) {
                    assertNotNull(e.getVisibility());
                    if (Visibility.PRIVATE.equals(e.getVisibility())) {
                        assertEquals(getClient1ClientId(), e.getSource().retrieveSourcePath());
                    }
                }
            }
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Email(org.orcid.jaxb.model.record_v2.Email) Keywords(org.orcid.jaxb.model.record_v2.Keywords) Address(org.orcid.jaxb.model.record_v2.Address) Fundings(org.orcid.jaxb.model.record.summary_v2.Fundings) OtherNames(org.orcid.jaxb.model.record_v2.OtherNames) PeerReviews(org.orcid.jaxb.model.record.summary_v2.PeerReviews) OtherName(org.orcid.jaxb.model.record_v2.OtherName) Name(org.orcid.jaxb.model.record_v2.Name) Addresses(org.orcid.jaxb.model.record_v2.Addresses) WorkGroup(org.orcid.jaxb.model.record.summary_v2.WorkGroup) WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) FundingSummary(org.orcid.jaxb.model.record.summary_v2.FundingSummary) Biography(org.orcid.jaxb.model.record_v2.Biography) ResearcherUrls(org.orcid.jaxb.model.record_v2.ResearcherUrls) Record(org.orcid.jaxb.model.record_v2.Record) ResearcherUrl(org.orcid.jaxb.model.record_v2.ResearcherUrl) Emails(org.orcid.jaxb.model.record_v2.Emails) Works(org.orcid.jaxb.model.record.summary_v2.Works) PeerReviewGroup(org.orcid.jaxb.model.record.summary_v2.PeerReviewGroup) Keyword(org.orcid.jaxb.model.record_v2.Keyword) OtherName(org.orcid.jaxb.model.record_v2.OtherName) PersonExternalIdentifier(org.orcid.jaxb.model.record_v2.PersonExternalIdentifier) FundingGroup(org.orcid.jaxb.model.record.summary_v2.FundingGroup) Employments(org.orcid.jaxb.model.record.summary_v2.Employments) PersonExternalIdentifiers(org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers) EducationSummary(org.orcid.jaxb.model.record.summary_v2.EducationSummary) PeerReviewSummary(org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary) Educations(org.orcid.jaxb.model.record.summary_v2.Educations) EmploymentSummary(org.orcid.jaxb.model.record.summary_v2.EmploymentSummary) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Test(org.junit.Test)

Aggregations

Emails (org.orcid.jaxb.model.record_v2.Emails)61 Test (org.junit.Test)60 Email (org.orcid.jaxb.model.record_v2.Email)49 Addresses (org.orcid.jaxb.model.record_v2.Addresses)33 Keywords (org.orcid.jaxb.model.record_v2.Keywords)33 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)33 PersonExternalIdentifiers (org.orcid.jaxb.model.record_v2.PersonExternalIdentifiers)33 ResearcherUrls (org.orcid.jaxb.model.record_v2.ResearcherUrls)33 Address (org.orcid.jaxb.model.record_v2.Address)32 Biography (org.orcid.jaxb.model.record_v2.Biography)32 OtherName (org.orcid.jaxb.model.record_v2.OtherName)32 Keyword (org.orcid.jaxb.model.record_v2.Keyword)31 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)31 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)31 Person (org.orcid.jaxb.model.record_v2.Person)30 Name (org.orcid.jaxb.model.record_v2.Name)29 Record (org.orcid.jaxb.model.record_v2.Record)16 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)15 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)15 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)15