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);
}
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);
}
});
}
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());
}
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;
}
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());
}
Aggregations