use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl_NonTransactionalTest method testAddWorks_duplicatedShouldFail.
@Test(expected = IllegalArgumentException.class)
public void testAddWorks_duplicatedShouldFail() {
OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
assertEquals(1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
OrcidProfile profile2 = new OrcidProfile();
profile2.setOrcidIdentifier(TEST_ORCID);
profile2.setOrcidActivities(new OrcidActivities());
profile2.getOrcidActivities().setOrcidWorks(new OrcidWorks());
profile2.getOrcidActivities().getOrcidWorks().getOrcidWork().clear();
OrcidWorks orcidWorks = profile2.getOrcidActivities().getOrcidWorks();
OrcidWork work1 = createWork1();
work1.getWorkTitle().getTitle().setContent("Updated title");
orcidWorks.getOrcidWork().add(work1);
OrcidWork work2 = createWork2();
orcidWorks.getOrcidWork().add(work2);
OrcidWork work3 = createWork3();
orcidWorks.getOrcidWork().add(work3);
orcidProfileManager.addOrcidWorks(profile2);
fail("Must not allow different works with same ext ids from the same source");
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl_NonTransactionalTest method testCreateRecordWithClient1AddTryToAddExactDuplicate.
@Test
public void testCreateRecordWithClient1AddTryToAddExactDuplicate() {
OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
assertEquals(1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
OrcidWork work1 = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0);
OrcidWork dupWork = createWork1();
profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(dupWork);
orcidProfileManager.addOrcidWorks(profile1);
OrcidProfile updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
assertEquals(1, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
OrcidWork existingWork = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0);
assertEquals(work1.getPutCode(), existingWork.getPutCode());
assertEquals(work1, existingWork);
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl_NonTransactionalTest method testAddWorks.
@Test
public void testAddWorks() {
OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
assertEquals(1, profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
String putCode1 = profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getPutCode();
OrcidProfile profile2 = new OrcidProfile();
profile2.setOrcidIdentifier(TEST_ORCID);
profile2.setOrcidActivities(new OrcidActivities());
profile2.getOrcidActivities().setOrcidWorks(new OrcidWorks());
profile2.getOrcidActivities().getOrcidWorks().getOrcidWork().clear();
OrcidWorks orcidWorks = profile2.getOrcidActivities().getOrcidWorks();
OrcidWork work1 = createWork1();
orcidWorks.getOrcidWork().add(work1);
OrcidWork work2 = createWork2();
orcidWorks.getOrcidWork().add(work2);
OrcidWork work3 = createWork3();
orcidWorks.getOrcidWork().add(work3);
orcidProfileManager.addOrcidWorks(profile2);
// Retry them again and verify that only work2 and work3 where created
// Since work1 is an exact duplicated, it will just be ignored, so, we
// must verify it keep having the same put code
OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
List<OrcidWork> works = resultProfile.retrieveOrcidWorks().getOrcidWork();
assertEquals(3, works.size());
boolean found1 = false;
boolean found2 = false;
boolean found3 = false;
for (OrcidWork work : works) {
// TODO: limited?????
assertEquals(Visibility.PRIVATE, work.getVisibility());
if (work.getWorkTitle().getTitle().getContent().equals("Test Title")) {
assertEquals(putCode1, work.getPutCode());
found1 = true;
} else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 2")) {
found2 = true;
} else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 3")) {
found3 = true;
} else {
fail("Invalid work found " + work.getPutCode());
}
}
assertTrue(found1);
assertTrue(found2);
assertTrue(found3);
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl_NonTransactionalTest method testAddWorkRespectDefaultVisibility.
@Test
public void testAddWorkRespectDefaultVisibility() {
OrcidProfile profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
orcidProfileManager.updatePreferences(TEST_ORCID, profile1.getOrcidInternal().getPreferences());
OrcidWork work2 = createWork2();
work2.setVisibility(Visibility.PUBLIC);
profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
orcidProfileManager.updateOrcidWorks(profile1);
OrcidProfile updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
assertEquals(2, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
assertEquals(Visibility.PRIVATE, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getVisibility());
assertEquals(Visibility.LIMITED, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(1).getVisibility());
profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.PUBLIC));
orcidProfileManager.updatePreferences(TEST_ORCID, profile1.getOrcidInternal().getPreferences());
OrcidWork work3 = createWork3();
work3.setVisibility(Visibility.PRIVATE);
profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
orcidProfileManager.updateOrcidWorks(profile1);
updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
assertEquals(3, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().forEach(work -> {
if (work.getWorkTitle().getTitle().getContent().equals("Test Title")) {
assertEquals(Visibility.PRIVATE, work.getVisibility());
} else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 2")) {
assertEquals(Visibility.LIMITED, work.getVisibility());
} else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 3")) {
assertEquals(Visibility.PUBLIC, work.getVisibility());
} else {
fail("Unknown work " + work.getWorkTitle().getTitle().getContent());
}
});
// Clear all works
workManager.removeAllWorks(TEST_ORCID);
// Start over with addOrcidWorks
profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
profile1.setOrcidActivities(new OrcidActivities());
profile1.getOrcidActivities().setOrcidWorks(new OrcidWorks());
profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.LIMITED));
orcidProfileManager.updatePreferences(TEST_ORCID, profile1.getOrcidInternal().getPreferences());
work2 = createWork2();
work2.setVisibility(Visibility.PUBLIC);
profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work2);
orcidProfileManager.addOrcidWorks(profile1);
updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
assertEquals(1, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
// TODO: public?????
assertEquals(Visibility.LIMITED, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().get(0).getVisibility());
profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.PUBLIC));
orcidProfileManager.updatePreferences(TEST_ORCID, profile1.getOrcidInternal().getPreferences());
work3 = createWork3();
work3.setVisibility(Visibility.PRIVATE);
profile1 = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
profile1.getOrcidActivities().getOrcidWorks().getOrcidWork().add(work3);
orcidProfileManager.addOrcidWorks(profile1);
updatedProfile = orcidProfileManager.retrieveOrcidProfile(TEST_ORCID);
assertEquals(2, updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().size());
updatedProfile.getOrcidActivities().getOrcidWorks().getOrcidWork().forEach(work -> {
if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 2")) {
assertEquals(Visibility.LIMITED, work.getVisibility());
} else if (work.getWorkTitle().getTitle().getContent().equals("Test Title # 3")) {
assertEquals(Visibility.PUBLIC, work.getVisibility());
} else {
fail("Unknown work " + work.getWorkTitle().getTitle().getContent());
}
});
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class PublicationTest method testGetOrcidWork.
@Test
public void testGetOrcidWork() {
String doi = "10.1029\\/2002JD002436";
String title = "5 on chemistry and nitrate aerosol formation in the lower troposphere under photosmog conditions";
String fullCitation = "Riemer, N, 2003, '5 on chemistry and nitrate aerosol formation in the lower troposphere under photosmog conditions', <i>Journal of Geophysical Research<\\/i>, vol. 30, no. D4, p. 1255.";
String coins = "ctx_ver=Z39.88-2004&rft_val_fmt=info:ofi\\/fmt:kev:mtx:journal&rft_id=info:doi\\/10.1029\\/2002JD002436&rtf.genre=journal-article&rtf.spage=1255&rtf.date=2003&rtf.aulast=Riemer&rtf.aufirst=N.&rtf.auinit=N&rtf.atitle=5 on chemistry and nitrate aerosol formation in the lower troposphere under photosmog conditions&rtf.jtitle=Journal of Geophysical Research&rtf.volume=30&rtf.issue=D4";
Publication publication = new Publication();
publication.setDoi(doi);
publication.setTitle(title);
publication.setFullCitation(fullCitation);
publication.setCoins(coins);
OrcidWork orcidWork = publication.getOrcidWork();
assertNotNull(orcidWork);
assertEquals(doi, orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().getContent());
assertEquals(WorkExternalIdentifierType.DOI, orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierType());
assertEquals(title, orcidWork.getWorkTitle().getTitle().getContent());
assertEquals(fullCitation, orcidWork.getWorkCitation().getCitation());
PublicationDate publicationDate = orcidWork.getPublicationDate();
assertNotNull(publicationDate);
assertEquals(null, publicationDate.getDay());
assertEquals(null, publicationDate.getMonth());
assertEquals("2003", publicationDate.getYear().getValue());
assertEquals(1, orcidWork.getWorkContributors().getContributor().size());
Contributor contributor = orcidWork.getWorkContributors().getContributor().get(0);
assertEquals("Riemer N.", contributor.getCreditName().getContent());
assertEquals(ContributorRole.AUTHOR, contributor.getContributorAttributes().getContributorRole());
assertEquals(SequenceType.FIRST, contributor.getContributorAttributes().getContributorSequence());
}
Aggregations