Search in sources :

Example 41 with Record

use of org.orcid.jaxb.model.record_v2.Record in project ORCID-Source by ORCID.

the class PublicV2ApiServiceDelegatorTest method testFindRecord.

@Test
public void testFindRecord() {
    Response response = serviceDelegator.viewRecord(ORCID);
    assertNotNull(response);
    Record record = (Record) response.getEntity();
    validateRecord(record);
}
Also used : Response(javax.ws.rs.core.Response) Record(org.orcid.jaxb.model.record_v2.Record) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 42 with Record

use of org.orcid.jaxb.model.record_v2.Record in project ORCID-Source by ORCID.

the class WorksController method getWorkInfo.

/**
     * Returns a blank work
     */
@RequestMapping(value = "/getWorkInfo.json", method = RequestMethod.GET)
@ResponseBody
public WorkForm getWorkInfo(@RequestParam(value = "workId") Long workId) {
    Map<String, String> countries = retrieveIsoCountries();
    Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
    if (workId == null)
        return null;
    long lastModifiedTime = profileEntityManager.getLastModified(getEffectiveUserOrcid());
    Work work = workManager.getWork(this.getEffectiveUserOrcid(), workId, lastModifiedTime);
    if (work != null) {
        WorkForm workForm = WorkForm.valueOf(work);
        if (workForm.getPublicationDate() == null) {
            initializePublicationDate(workForm);
        } else {
            if (workForm.getPublicationDate().getDay() == null) {
                workForm.getPublicationDate().setDay(new String());
            }
            if (workForm.getPublicationDate().getMonth() == null) {
                workForm.getPublicationDate().setMonth(new String());
            }
            if (workForm.getPublicationDate().getYear() == null) {
                workForm.getPublicationDate().setYear(new String());
            }
        }
        // Set country name
        if (!PojoUtil.isEmpty(workForm.getCountryCode())) {
            Text countryName = Text.valueOf(countries.get(workForm.getCountryCode().getValue()));
            workForm.setCountryName(countryName);
        }
        // Set language name
        if (!PojoUtil.isEmpty(workForm.getLanguageCode())) {
            Text languageName = Text.valueOf(languages.get(workForm.getLanguageCode().getValue()));
            workForm.setLanguageName(languageName);
        }
        // Set translated title language name
        if (!(workForm.getTranslatedTitle() == null) && !StringUtils.isEmpty(workForm.getTranslatedTitle().getLanguageCode())) {
            String languageName = languages.get(workForm.getTranslatedTitle().getLanguageCode());
            workForm.getTranslatedTitle().setLanguageName(languageName);
        }
        if (workForm.getContributors() != null) {
            for (Contributor contributor : workForm.getContributors()) {
                if (!PojoUtil.isEmpty(contributor.getOrcid())) {
                    String contributorOrcid = contributor.getOrcid().getValue();
                    if (profileEntityManager.orcidExists(contributorOrcid)) {
                        // contributor is an ORCID user - visibility of user's name in record must be taken into account 
                        ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
                        String publicContributorCreditName = cacheManager.getPublicCreditName(profileEntity);
                        contributor.setCreditName(Text.valueOf(publicContributorCreditName));
                    }
                }
            }
        }
        return workForm;
    }
    return null;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) Work(org.orcid.jaxb.model.record_v2.Work) Contributor(org.orcid.pojo.ajaxForm.Contributor) Text(org.orcid.pojo.ajaxForm.Text) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 43 with Record

use of org.orcid.jaxb.model.record_v2.Record in project ORCID-Source by ORCID.

the class MemberV2ApiServiceDelegator_ReadRecordTest method testViewRecordWrongScope.

@Test
public void testViewRecordWrongScope() {
    SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_PUBLIC);
    Response response = serviceDelegator.viewRecord(ORCID);
    // Verify everything inside is public
    Record record = (Record) response.getEntity();
    assertNotNull(record);
    assertEquals("/0000-0000-0000-0003", record.getPath());
    assertEquals("/0000-0000-0000-0003/activities", record.getActivitiesSummary().getPath());
    Utils.assertIsPublicOrSource(record.getActivitiesSummary(), SecurityContextTestUtils.DEFAULT_CLIENT_ID);
    assertEquals("/0000-0000-0000-0003/person", record.getPerson().getPath());
    Utils.assertIsPublicOrSource(record.getPerson(), SecurityContextTestUtils.DEFAULT_CLIENT_ID);
}
Also used : Response(javax.ws.rs.core.Response) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) Record(org.orcid.jaxb.model.record_v2.Record) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 44 with Record

use of org.orcid.jaxb.model.record_v2.Record 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, System.currentTimeMillis());
    for (Email e : emails.getEmails()) {
        assertFalse(email.equals(e.getEmail()));
    }
    //Assert the email belongs to the to record
    emails = emailManager.getEmails(to, System.currentTimeMillis());
    boolean found = false;
    for (Email e : emails.getEmails()) {
        if (email.equals(e.getEmail())) {
            found = true;
        }
    }
    assertTrue(found);
}
Also used : Email(org.orcid.jaxb.model.record_v2.Email) Emails(org.orcid.jaxb.model.record_v2.Emails) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 45 with Record

use of org.orcid.jaxb.model.record_v2.Record 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_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

Test (org.junit.Test)63 Record (org.orcid.jaxb.model.record_v2.Record)49 ActivitiesSummary (org.orcid.jaxb.model.record.summary_v2.ActivitiesSummary)23 Email (org.orcid.jaxb.model.record_v2.Email)22 PersonExternalIdentifier (org.orcid.jaxb.model.record_v2.PersonExternalIdentifier)21 Address (org.orcid.jaxb.model.record_v2.Address)20 Keyword (org.orcid.jaxb.model.record_v2.Keyword)20 Person (org.orcid.jaxb.model.record_v2.Person)20 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)20 Record (nikita.model.noark5.v4.Record)19 EducationSummary (org.orcid.jaxb.model.record.summary_v2.EducationSummary)19 EmploymentSummary (org.orcid.jaxb.model.record.summary_v2.EmploymentSummary)19 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)19 WorkSummary (org.orcid.jaxb.model.record.summary_v2.WorkSummary)19 OtherName (org.orcid.jaxb.model.record_v2.OtherName)18 Biography (org.orcid.jaxb.model.record_v2.Biography)17 Emails (org.orcid.jaxb.model.record_v2.Emails)17 Name (org.orcid.jaxb.model.record_v2.Name)17 OtherNames (org.orcid.jaxb.model.record_v2.OtherNames)17 PeerReviewSummary (org.orcid.jaxb.model.record.summary_v2.PeerReviewSummary)16