use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl_NonTransactionalTest method testAddOrcidWorkToUnclaimedProfile.
@Test
public void testAddOrcidWorkToUnclaimedProfile() {
String orcid = "0000-0000-0000-0003";
OrcidProfile profile1 = createBasicProfile();
profile1.setOrcidIdentifier(orcid);
profile1.getOrcidInternal().getPreferences().setActivitiesVisibilityDefault(new ActivitiesVisibilityDefault(Visibility.PUBLIC));
orcidProfileManager.createOrcidProfile(profile1, false, false);
OrcidProfile profile2 = new OrcidProfile();
profile2.setOrcidIdentifier(orcid);
OrcidWorks orcidWorks = new OrcidWorks();
profile2.setOrcidWorks(orcidWorks);
OrcidWork work1 = createWork1();
work1.setVisibility(Visibility.PUBLIC);
orcidWorks.getOrcidWork().add(work1);
OrcidWork work2 = createWork2();
work2.setVisibility(Visibility.LIMITED);
orcidWorks.getOrcidWork().add(work2);
OrcidWork work3 = createWork3();
work3.setVisibility(Visibility.PRIVATE);
orcidWorks.getOrcidWork().add(work3);
orcidProfileManager.addOrcidWorks(profile2);
OrcidProfile resultProfile = orcidProfileManager.retrieveOrcidProfile(orcid);
assertEquals(3, resultProfile.retrieveOrcidWorks().getOrcidWork().size());
for (OrcidWork work : resultProfile.retrieveOrcidWorks().getOrcidWork()) {
if ("Test Title".equals(work.getWorkTitle().getTitle().getContent())) {
assertEquals(Visibility.PUBLIC, work.getVisibility());
} else if ("Test Title # 2".equals(work.getWorkTitle().getTitle().getContent())) {
assertEquals(Visibility.LIMITED, work.getVisibility());
} else if ("Test Title # 2".equals(work.getWorkTitle().getTitle().getContent())) {
assertEquals(Visibility.PRIVATE, work.getVisibility());
}
}
workManager.removeAllWorks(orcid);
orcidProfileManager.deleteProfile(orcid);
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl_NonTransactionalTest method testOrcidWorksHashCodeAndEquals.
@Test
public void testOrcidWorksHashCodeAndEquals() {
OrcidWork workA = createWork1();
OrcidWork workB = createWork1();
assertEquals(workA, workB);
assertEquals(workA.hashCode(), workB.hashCode());
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class OrcidSearchManagerImplTest method orcidRetrievalAllDataPresentInDb.
@Test
@Rollback
public void orcidRetrievalAllDataPresentInDb() throws Exception {
when(mockSolrDao.findByOrcid("1434")).thenReturn(getOrcidSolrResult("5678", new Float(37.2)));
when(mockOrcidProfileCacheManager.retrievePublicBio("5678")).thenReturn(getOrcidProfileAllIndexFieldsPopulated());
String orcid = "1434";
// demonstrate that the mapping from solr (profile 1234) and dao (5678)
// are truly seperate - the search results only return a subset of the
// full orcid
// because we want to keep the payload down.
OrcidMessage retrievedOrcidMessage = orcidSearchManager.findOrcidSearchResultsById(orcid);
assertNotNull(retrievedOrcidMessage);
assertTrue(retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().size() == 1);
OrcidSearchResult result = retrievedOrcidMessage.getOrcidSearchResults().getOrcidSearchResult().get(0);
assertTrue(new Float(37.2).compareTo(result.getRelevancyScore().getValue()) == 0);
OrcidProfile retrievedProfile = result.getOrcidProfile();
assertEquals("5678", retrievedProfile.getOrcidIdentifier().getPath());
OrcidBio orcidBio = retrievedProfile.getOrcidBio();
assertEquals("Logan", orcidBio.getPersonalDetails().getFamilyName().getContent());
assertEquals("Donald Edward", orcidBio.getPersonalDetails().getGivenNames().getContent());
assertEquals("Stanley Higgins", orcidBio.getPersonalDetails().getCreditName().getContent());
List<String> otherNames = orcidBio.getPersonalDetails().getOtherNames().getOtherNamesAsStrings();
assertTrue(otherNames.contains("Edward Bass"));
assertTrue(otherNames.contains("Gareth Dove"));
OrcidWorks orcidWorks = retrievedProfile.retrieveOrcidWorks();
OrcidWork orcidWork1 = orcidWorks.getOrcidWork().get(0);
OrcidWork orcidWork2 = orcidWorks.getOrcidWork().get(1);
assertTrue(orcidWork1.getWorkExternalIdentifiers().getWorkExternalIdentifier().size() == 1);
assertEquals("work1-doi1", orcidWork1.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().getContent());
assertTrue(orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().size() == 2);
assertEquals("work2-doi1", orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(0).getWorkExternalIdentifierId().getContent());
assertEquals("work2-doi2", orcidWork2.getWorkExternalIdentifiers().getWorkExternalIdentifier().get(1).getWorkExternalIdentifierId().getContent());
List<Funding> fundings = retrievedProfile.retrieveFundings().getFundings();
Funding funding1 = fundings.get(0);
Funding funding2 = fundings.get(1);
// check returns a reduced payload
assertNotNull(funding1.getTitle());
assertNotNull(funding1.getTitle().getTitle());
assertEquals("grant1", funding1.getTitle().getTitle().getContent());
assertEquals("Grant 1 - a short description", funding1.getDescription());
assertNull(funding1.getPutCode());
assertNotNull(funding2.getTitle());
assertNotNull(funding2.getTitle().getTitle());
assertEquals("grant2", funding2.getTitle().getTitle().getContent());
assertEquals("Grant 2 - a short description", funding2.getDescription());
assertNull(funding2.getPutCode());
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class JpaJaxbEntityAdapterToOrcidProfileTest method testToOrcidProfileWithNewWayOfDoingWorkContributors.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testToOrcidProfileWithNewWayOfDoingWorkContributors() {
ProfileEntity profileEntity = profileDao.find("4444-4444-4444-4445");
long start = System.currentTimeMillis();
OrcidProfile orcidProfile = adapter.toOrcidProfile(profileEntity, LoadOptions.ALL);
System.out.println("Took: " + Long.toString(System.currentTimeMillis() - start));
List<OrcidWork> worksList = orcidProfile.getOrcidActivities().getOrcidWorks().getOrcidWork();
assertEquals(1, worksList.size());
OrcidWork orcidWork = worksList.get(0);
WorkContributors contributors = orcidWork.getWorkContributors();
assertNotNull(contributors);
List<Contributor> contributorList = contributors.getContributor();
assertEquals(1, contributorList.size());
Contributor contributor = contributorList.get(0);
assertEquals("Jason Contributor", contributor.getCreditName().getContent());
}
use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setWorks.
@Override
@Deprecated
public void setWorks(ProfileEntity profileEntity, OrcidWorks orcidWorks) {
String orcid = profileEntity.getId();
// Get the existing works
List<WorkEntity> existingWorks = workDao.getWorksByOrcidId(orcid);
Map<Long, WorkEntity> existingWorksMap = new HashMap<Long, WorkEntity>();
// Iterate over the existing list of works and delete the ones that are not in the orcidWorks list
for (WorkEntity entity : existingWorks) {
boolean deleteMe = true;
if (orcidWorks != null && orcidWorks.getOrcidWork() != null) {
for (OrcidWork orcidWork : orcidWorks.getOrcidWork()) {
if (!PojoUtil.isEmpty(orcidWork.getPutCode()) && entity.getId().equals(Long.valueOf(orcidWork.getPutCode()))) {
deleteMe = false;
break;
}
}
}
if (deleteMe) {
try {
workDao.remove(entity.getId());
} catch (Exception e) {
throw new ApplicationException("Unable to delete work with id " + entity.getId(), e);
}
} else {
existingWorksMap.put(entity.getId(), entity);
}
}
// Iterate over the list of orcidWorks and update the ones that have a put code and insert the ones that doesnt have any put code
if (orcidWorks != null && orcidWorks.getOrcidWork() != null) {
for (OrcidWork orcidWork : orcidWorks.getOrcidWork()) {
if (!PojoUtil.isEmpty(orcidWork.getPutCode())) {
if (orcidWork.isModified()) {
WorkEntity updatedEntity = getWorkEntity(orcid, orcidWork, existingWorksMap.get(Long.valueOf(orcidWork.getPutCode())));
updatedEntity.setLastModified(new Date());
workDao.merge(updatedEntity);
}
} else {
WorkEntity newEntity = getWorkEntity(orcid, orcidWork, null);
Date now = new Date();
newEntity.setDateCreated(now);
newEntity.setLastModified(now);
workDao.persist(newEntity);
}
}
}
}
Aggregations