Search in sources :

Example 76 with OrcidWork

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);
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ActivitiesVisibilityDefault(org.orcid.jaxb.model.message.ActivitiesVisibilityDefault) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Test(org.junit.Test)

Example 77 with OrcidWork

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());
}
Also used : OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Test(org.junit.Test)

Example 78 with OrcidWork

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());
}
Also used : OrcidSearchResult(org.orcid.jaxb.model.message.OrcidSearchResult) OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Funding(org.orcid.jaxb.model.message.Funding) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 79 with OrcidWork

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());
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) WorkContributors(org.orcid.jaxb.model.message.WorkContributors) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) Contributor(org.orcid.jaxb.model.message.Contributor) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 80 with OrcidWork

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);
            }
        }
    }
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) ApplicationException(org.orcid.core.exception.ApplicationException) HashMap(java.util.HashMap) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ApplicationException(org.orcid.core.exception.ApplicationException) CompletionDate(org.orcid.jaxb.model.message.CompletionDate) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) FuzzyDate(org.orcid.jaxb.model.message.FuzzyDate) PublicationDate(org.orcid.jaxb.model.message.PublicationDate) DeactivationDate(org.orcid.jaxb.model.message.DeactivationDate)

Aggregations

OrcidWork (org.orcid.jaxb.model.message.OrcidWork)81 Test (org.junit.Test)44 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)42 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)32 Transactional (org.springframework.transaction.annotation.Transactional)26 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)24 Title (org.orcid.jaxb.model.message.Title)23 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)20 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)18 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)16 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)16 Source (org.orcid.jaxb.model.message.Source)14 Rollback (org.springframework.test.annotation.Rollback)13 ArrayList (java.util.ArrayList)12 Funding (org.orcid.jaxb.model.message.Funding)12 WorkExternalIdentifierId (org.orcid.jaxb.model.message.WorkExternalIdentifierId)12 BaseTest (org.orcid.core.BaseTest)11 Contributor (org.orcid.jaxb.model.message.Contributor)11 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)11 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)10