use of org.orcid.jaxb.model.message.OrcidWorks 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.OrcidWorks 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.OrcidWorks in project ORCID-Source by ORCID.
the class T2OrcidApiServiceDelegatorTest method testAddWorks.
@Test
public void testAddWorks() {
SecurityContextTestUtils.setUpSecurityContext();
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion("1.2_rc6");
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
orcidProfile.setOrcidIdentifier(new OrcidIdentifier("4444-4444-4444-4441"));
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
OrcidWorks orcidWorks = new OrcidWorks();
orcidActivities.setOrcidWorks(orcidWorks);
Response response = t2OrcidApiServiceDelegator.addWorks(mockedUriInfo, "4444-4444-4444-4441", orcidMessage);
assertNotNull(response);
assertEquals(201, response.getStatus());
}
use of org.orcid.jaxb.model.message.OrcidWorks in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method dedupeWorks.
private void dedupeWorks(OrcidProfile orcidProfile) {
OrcidActivities orcidActivities = orcidProfile.getOrcidActivities();
if (orcidActivities != null) {
OrcidWorks orcidWorks = orcidActivities.getOrcidWorks();
if (orcidWorks != null) {
OrcidWorks dedupedOrcidWorks = dedupeWorks(orcidWorks);
orcidActivities.setOrcidWorks(dedupedOrcidWorks);
}
}
}
use of org.orcid.jaxb.model.message.OrcidWorks in project ORCID-Source by ORCID.
the class OrcidMessageUtil method setSourceName.
public void setSourceName(OrcidProfile orcidProfile) {
if (orcidProfile != null) {
if (orcidProfile.getOrcidActivities() != null) {
OrcidActivities orcidActivities = orcidProfile.getOrcidActivities();
if (orcidActivities.getAffiliations() != null) {
Affiliations affs = orcidActivities.getAffiliations();
List<Affiliation> affList = affs.getAffiliation();
if (affList != null) {
for (Affiliation aff : affList) {
setSourceName(aff);
}
}
}
if (orcidActivities.getFundings() != null) {
FundingList fundingList = orcidActivities.getFundings();
List<Funding> fundings = fundingList.getFundings();
if (fundings != null) {
for (Funding funding : fundings) {
setSourceName(funding);
}
}
}
if (orcidActivities.getOrcidWorks() != null) {
OrcidWorks orcidWorks = orcidActivities.getOrcidWorks();
List<OrcidWork> works = orcidWorks.getOrcidWork();
if (works != null) {
for (OrcidWork work : works) {
setSourceName(work);
}
}
}
}
if (orcidProfile.getOrcidBio() != null) {
OrcidBio orcidBio = orcidProfile.getOrcidBio();
if (orcidBio.getContactDetails() != null) {
Address address = orcidBio.getContactDetails().getAddress();
if (address != null) {
setSourceName(address);
}
}
if (orcidBio.getExternalIdentifiers() != null) {
ExternalIdentifiers extIds = orcidBio.getExternalIdentifiers();
List<ExternalIdentifier> extIdsList = extIds.getExternalIdentifier();
if (extIdsList != null) {
for (ExternalIdentifier extId : extIdsList) {
setSourceName(extId);
}
}
}
if (orcidBio.getKeywords() != null) {
Keywords keywords = orcidBio.getKeywords();
List<Keyword> keywordList = keywords.getKeyword();
if (keywordList != null) {
for (Keyword keyword : keywordList) {
setSourceName(keyword);
}
}
}
if (orcidBio.getPersonalDetails() != null) {
OtherNames otherNames = orcidBio.getPersonalDetails().getOtherNames();
if (otherNames != null) {
List<OtherName> otherNameList = otherNames.getOtherName();
if (otherNameList != null) {
for (OtherName otherName : otherNameList) {
setSourceName(otherName);
}
}
}
}
if (orcidBio.getResearcherUrls() != null) {
ResearcherUrls rUrls = orcidBio.getResearcherUrls();
List<ResearcherUrl> rUrlList = rUrls.getResearcherUrl();
if (rUrlList != null) {
for (ResearcherUrl rUrl : rUrlList) {
setSourceName(rUrl);
}
}
}
}
}
}
Aggregations