Search in sources :

Example 6 with Contributor

use of org.orcid.jaxb.model.message.Contributor in project ORCID-Source by ORCID.

the class JsonUtilsTest method testWorkContributorsToJsonString.

@Test
public void testWorkContributorsToJsonString() {
    WorkContributors workContributors = new WorkContributors();
    Contributor contributor1 = new Contributor();
    workContributors.getContributor().add(contributor1);
    contributor1.setCreditName(new CreditName("A Contributor"));
    String result = JsonUtils.convertToJsonString(workContributors);
    assertEquals("{\"contributor\":[{\"contributorOrcid\":null,\"creditName\":{\"content\":\"A Contributor\",\"visibility\":null},\"contributorEmail\":null,\"contributorAttributes\":null}]}", result);
}
Also used : WorkContributors(org.orcid.jaxb.model.message.WorkContributors) CreditName(org.orcid.jaxb.model.message.CreditName) Contributor(org.orcid.jaxb.model.message.Contributor) Test(org.junit.Test)

Example 7 with Contributor

use of org.orcid.jaxb.model.message.Contributor in project ORCID-Source by ORCID.

the class CheckAndFixContributorNameVisibility method processOrcid.

private void processOrcid(final String orcid) {
    LOG.info("Checking and fixing profile: {}", orcid);
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            OrcidProfile orcidProfile = orcidProfileManager.retrieveOrcidProfile(orcid);
            OrcidWorks orcidWorks = orcidProfile.retrieveOrcidWorks();
            if (orcidWorks != null) {
                for (OrcidWork orcidWork : orcidWorks.getOrcidWork()) {
                    WorkContributors workContributors = orcidWork.getWorkContributors();
                    if (workContributors != null) {
                        for (Contributor contributor : workContributors.getContributor()) {
                            ContributorOrcid contributorOrcid = contributor.getContributorOrcid();
                            if (contributorOrcid != null) {
                                String orcid = contributorOrcid.getPath();
                                ProfileEntity contributorProfile = profileDao.find(orcid);
                                if (contributorProfile.getRecordNameEntity() != null && contributorProfile.getRecordNameEntity().getVisibility() != null) {
                                    if (!Visibility.PUBLIC.value().equals(contributorProfile.getRecordNameEntity().getVisibility().value())) {
                                        contributor.setCreditName(null);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            orcidProfileManager.updateOrcidProfile(orcidProfile);
        }
    });
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) WorkContributors(org.orcid.jaxb.model.message.WorkContributors) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) TransactionStatus(org.springframework.transaction.TransactionStatus) Contributor(org.orcid.jaxb.model.message.Contributor) ContributorOrcid(org.orcid.jaxb.model.message.ContributorOrcid) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks)

Example 8 with Contributor

use of org.orcid.jaxb.model.message.Contributor in project ORCID-Source by ORCID.

the class OrcidProfileManagerImplTest method testUpdateProfileButRemoveWorkContributor.

@Test
@Transactional
@Rollback(true)
public void testUpdateProfileButRemoveWorkContributor() {
    OrcidProfile profile1 = createBasicProfile();
    profile1 = orcidProfileManager.createOrcidProfile(profile1, false, false);
    List<Contributor> contributors = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getWorkContributors().getContributor();
    assertEquals(2, contributors.size());
    Iterator<Contributor> contributorsIterator = contributors.iterator();
    while (contributorsIterator.hasNext()) {
        if (SequenceType.ADDITIONAL.equals(contributorsIterator.next().getContributorAttributes().getContributorSequence())) {
            contributorsIterator.remove();
        }
    }
    profile1 = orcidProfileManager.updateOrcidProfile(profile1);
    OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
    assertNotNull(resultProfile);
    assertEquals("Will", resultProfile.getOrcidBio().getPersonalDetails().getGivenNames().getContent());
    assertEquals(1, resultProfile.retrieveOrcidWorks().getOrcidWork().size());
    assertEquals(1, resultProfile.getOrcidBio().getResearcherUrls().getResearcherUrl().size());
    assertEquals("http://www.wjrs.co.uk", resultProfile.getOrcidBio().getResearcherUrls().getResearcherUrl().get(0).getUrl().getValue());
    assertEquals(1, resultProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getWorkContributors().getContributor().size());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Contributor(org.orcid.jaxb.model.message.Contributor) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Contributor

use of org.orcid.jaxb.model.message.Contributor in project ORCID-Source by ORCID.

the class OrcidProfileManagerBaseTest method createWork1Contributors.

private WorkContributors createWork1Contributors() {
    WorkContributors workContributors = new WorkContributors();
    Contributor workContributor1 = new Contributor();
    workContributors.getContributor().add(workContributor1);
    workContributor1.setCreditName(new CreditName("Will Simpson"));
    ContributorAttributes contributorAttributes1 = new ContributorAttributes();
    workContributor1.setContributorAttributes(contributorAttributes1);
    contributorAttributes1.setContributorRole(ContributorRole.AUTHOR);
    contributorAttributes1.setContributorSequence(SequenceType.FIRST);
    Contributor workContributor2 = new Contributor();
    workContributors.getContributor().add(workContributor2);
    workContributor2.setCreditName(new CreditName("Josiah Wedgewood"));
    ContributorAttributes contributorAttributes2 = new ContributorAttributes();
    workContributor2.setContributorAttributes(contributorAttributes2);
    contributorAttributes2.setContributorRole(ContributorRole.AUTHOR);
    contributorAttributes2.setContributorSequence(SequenceType.ADDITIONAL);
    return workContributors;
}
Also used : ContributorAttributes(org.orcid.jaxb.model.message.ContributorAttributes) WorkContributors(org.orcid.jaxb.model.message.WorkContributors) CreditName(org.orcid.jaxb.model.message.CreditName) Contributor(org.orcid.jaxb.model.message.Contributor)

Example 10 with Contributor

use of org.orcid.jaxb.model.message.Contributor in project ORCID-Source by ORCID.

the class OrcidProfileManagerContributorVisibilityTest method emailProvidedAndDoesExistInDbButCreditNameAndEmailArePrivate.

@Test
@Transactional
public void emailProvidedAndDoesExistInDbButCreditNameAndEmailArePrivate() {
    // Unmarshall message containing contributor email
    OrcidMessage orcidMessage = unmarshallOrcidMessage("new_work_with_contributor_email_and_name.xml");
    // Change email to one that exists in DB
    orcidMessage.getOrcidProfile().retrieveOrcidWorks().getOrcidWork().get(0).getWorkContributors().getContributor().get(0).getContributorEmail().setValue("otis@reading.com");
    // Add the work
    orcidProfileManager.addOrcidWorks(orcidMessage.getOrcidProfile());
    // Get it back from the API
    OrcidWork retrievedWork = retrieveAddedWorkFromApi();
    Contributor workContributor = retrievedWork.getWorkContributors().getContributor().get(0);
    // Check that the contributor name is not included in the resulting
    // work, because it is private
    assertNull(workContributor.getCreditName());
    // Check that the email is not included in the resulting work, because
    // never want to show email
    assertNull(workContributor.getContributorEmail());
    // Get the contributor directly from the DB so can see stuff not
    // included in the API
    Contributor workContributorDirectFromDb = retrieveWorkContributorEntityDirectlyFromDb(retrievedWork);
    // Check the email is in the DB for later use if needed
    assertEquals("otis@reading.com", workContributorDirectFromDb.getContributorEmail().getValue());
}
Also used : OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Contributor(org.orcid.jaxb.model.message.Contributor) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Contributor (org.orcid.jaxb.model.message.Contributor)15 Test (org.junit.Test)11 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)11 Transactional (org.springframework.transaction.annotation.Transactional)9 BaseTest (org.orcid.core.BaseTest)7 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)7 WorkContributors (org.orcid.jaxb.model.message.WorkContributors)5 CreditName (org.orcid.jaxb.model.message.CreditName)4 ContributorAttributes (org.orcid.jaxb.model.message.ContributorAttributes)3 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)3 ContributorOrcid (org.orcid.jaxb.model.message.ContributorOrcid)2 PublicationDate (org.orcid.jaxb.model.message.PublicationDate)2 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 Citation (org.orcid.jaxb.model.message.Citation)1 CitationType (org.orcid.jaxb.model.message.CitationType)1 ContributorEmail (org.orcid.jaxb.model.message.ContributorEmail)1 ContributorRole (org.orcid.jaxb.model.message.ContributorRole)1 Day (org.orcid.jaxb.model.message.Day)1 Month (org.orcid.jaxb.model.message.Month)1