Search in sources :

Example 16 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class JpaJaxbEntityAdapterToProfileEntityTest method testReligiousTextConvertedFromBible.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Rollback(true)
public void testReligiousTextConvertedFromBible() throws Exception {
    OrcidMessage orcidMessage = getOrcidMessage(ORCID_INTERNAL_FULL_XML);
    List<OrcidWork> currentOrcidWorks = orcidMessage.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork();
    assertTrue(currentOrcidWorks.size() == 1);
    currentOrcidWorks.get(0).setWorkType(WorkType.DATA_SET);
    ProfileEntity profileEntity = adapter.toProfileEntity(orcidMessage.getOrcidProfile());
    List<WorkEntity> works = new ArrayList<WorkEntity>(profileEntity.getWorks());
    assertEquals(1, works.size());
    assertTrue(works.get(0).getWorkType().equals(org.orcid.jaxb.model.record_v2.WorkType.DATA_SET));
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ArrayList(java.util.ArrayList) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class JpaJaxbEntityAdapterToProfileEntityTest method testToProfileEntity.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Rollback(true)
public void testToProfileEntity() throws JAXBException {
    OrcidMessage orcidMessage = getOrcidMessage(ORCID_PROTECTED_FULL_XML);
    ProfileEntity profileEntity = adapter.toProfileEntity(orcidMessage.getOrcidProfile());
    assertNotNull(profileEntity);
    profileDao.persist(profileEntity);
    ProfileEntity retrievedProfileEntity = profileDao.find(orcidMessage.getOrcidProfile().getOrcidIdentifier().getPath());
    assertNotNull(retrievedProfileEntity);
    assertEquals("Josiah", retrievedProfileEntity.getRecordNameEntity().getGivenNames());
    // Check all email visibility and values
    Set<EmailEntity> emails = profileEntity.getEmails();
    assertNotNull(emails);
    assertEquals(2, emails.size());
    Map<String, EmailEntity> emailMap = EmailEntity.mapById(emails);
    EmailEntity primaryEmail = emailMap.get("josiah_carberry@brown.edu");
    assertNotNull(primaryEmail);
    assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, primaryEmail.getVisibility());
    assertTrue(primaryEmail.getPrimary());
    assertTrue(primaryEmail.getCurrent());
    assertTrue(primaryEmail.getVerified());
    assertEquals("4444-4444-4444-4446", primaryEmail.getElementSourceId());
    EmailEntity nonPrimaryEmail1 = emailMap.get("josiah_carberry_1@brown.edu");
    assertNotNull(nonPrimaryEmail1);
    assertEquals(org.orcid.jaxb.model.common_v2.Visibility.LIMITED, nonPrimaryEmail1.getVisibility());
    assertFalse(nonPrimaryEmail1.getPrimary());
    assertTrue(nonPrimaryEmail1.getCurrent());
    assertFalse(nonPrimaryEmail1.getVerified());
    assertEquals("4444-4444-4444-4446", nonPrimaryEmail1.getElementSourceId());
    Set<WorkEntity> workEntities = profileEntity.getWorks();
    assertEquals(3, workEntities.size());
    for (WorkEntity workEntity : workEntities) {
        String contributorsJson = workEntity.getContributorsJson();
        if ("Work title 1".equals(workEntity.getTitle())) {
            assertEquals("Journal Title # 1", workEntity.getJournalTitle());
            assertNotNull(contributorsJson);
            assertTrue(contributorsJson.startsWith("{\"contributor\":[{\""));
            Map<String, Object> mappedJson = JsonUtils.<HashMap>readObjectFromJsonString(contributorsJson, HashMap.class);
            List<Map<String, Object>> contributorsList = (List<Map<String, Object>>) mappedJson.get("contributor");
            Map<String, Object> contributor0 = contributorsList.get(0);
            assertEquals(4, contributor0.keySet().size());
            Map<String, Object> contributorOrcid0 = (Map<String, Object>) contributor0.get("contributorOrcid");
            assertEquals("http://orcid.org/4444-4444-4444-4446", contributorOrcid0.get("uri"));
            assertEquals("4444-4444-4444-4446", contributorOrcid0.get("path"));
            assertEquals("orcid.org", contributorOrcid0.get("host"));
            assertTrue(contributorOrcid0.containsKey("value"));
            assertNull(contributorOrcid0.get("value"));
            assertTrue(contributorOrcid0.containsKey("valueAsString"));
            assertNull(contributorOrcid0.get("valueAsString"));
            assertTrue(contributor0.containsKey("creditName"));
            assertNull(contributor0.get("creditName"));
            assertTrue(contributor0.containsKey("contributorEmail"));
            assertNull(contributor0.get("contributorEmail"));
            Map<String, Object> contributorAttributes0 = (Map<String, Object>) contributor0.get("contributorAttributes");
            assertNotNull(contributorAttributes0);
            assertEquals("FIRST", contributorAttributes0.get("contributorSequence"));
            assertEquals("AUTHOR", contributorAttributes0.get("contributorRole"));
            Map<String, Object> contributor1 = contributorsList.get(1);
            assertEquals(4, contributor1.keySet().size());
            assertTrue(contributor1.containsKey("contributorOrcid"));
            assertNull(contributor1.get("contributorOrcid"));
            assertEquals("John W. Spaeth", ((Map<String, Object>) contributor1.get("creditName")).get("content"));
            assertEquals("PUBLIC", ((Map<String, Object>) contributor1.get("creditName")).get("visibility"));
            assertTrue(contributor1.containsKey("contributorEmail"));
            assertNull(contributor1.get("contributorEmail"));
            assertTrue(contributor1.containsKey("contributorAttributes"));
            assertNull(contributor1.get("contributorAttributes"));
        } else if (workEntity.getTitle().equals("Work title 2")) {
            assertNull(contributorsJson);
            assertEquals("Journal Title # 2", workEntity.getJournalTitle());
        } else {
            assertNull(contributorsJson);
            assertNull(workEntity.getJournalTitle());
        }
    }
    assertEquals(2, profileEntity.getProfileFunding().size());
    for (ProfileFundingEntity profileGrantEntity : profileEntity.getProfileFunding()) {
        assertNotNull(profileGrantEntity.getContributorsJson());
    }
    assertNull(profileEntity.getGivenPermissionBy());
}
Also used : HashMap(java.util.HashMap) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class WorkManagerTest method testAddMultipleModifiesIndexingStatus.

@Test
public void testAddMultipleModifiesIndexingStatus() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Work w1 = getWork("extId1");
    w1 = workManager.createWork(claimedOrcid, w1, true);
    Work w2 = getWork("extId2");
    w2 = workManager.createWork(claimedOrcid, w2, true);
    Work w3 = getWork("extId3");
    w3 = workManager.createWork(claimedOrcid, w3, true);
    WorkEntity entity1 = workDao.find(w1.getPutCode());
    WorkEntity entity2 = workDao.find(w2.getPutCode());
    WorkEntity entity3 = workDao.find(w3.getPutCode());
    assertNotNull(entity1.getDisplayIndex());
    assertNotNull(entity2.getDisplayIndex());
    assertNotNull(entity3.getDisplayIndex());
    assertEquals(Long.valueOf(0), entity3.getDisplayIndex());
    //Rollback all changes
    workDao.remove(entity1.getId());
    workDao.remove(entity2.getId());
    workDao.remove(entity3.getId());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 19 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class WorkDaoImpl method editWork.

@Override
@Transactional
public WorkEntity editWork(WorkEntity updatedWork) {
    WorkEntity workToUpdate = this.find(updatedWork.getId());
    mergeWork(workToUpdate, updatedWork);
    workToUpdate = this.merge(workToUpdate);
    return workToUpdate;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with WorkEntity

use of org.orcid.persistence.jpa.entities.WorkEntity in project ORCID-Source by ORCID.

the class WorkManagerReadOnlyImpl method findWorkBulk.

@Override
public WorkBulk findWorkBulk(String orcid, String putCodesAsString, long profileLastModified) {
    List<BulkElement> works = new ArrayList<>();
    String[] putCodes = getPutCodeArray(putCodesAsString);
    for (String putCode : putCodes) {
        try {
            Long id = Long.valueOf(putCode);
            WorkEntity workEntity = workEntityCacheManager.retrieveFullWork(orcid, id, profileLastModified);
            works.add(jpaJaxbWorkAdapter.toWork(workEntity));
        } catch (Exception e) {
            works.add(orcidCoreExceptionMapper.getOrcidError(new PutCodeFormatException("'" + putCode + "' is not a valid put code")));
        }
    }
    WorkBulk bulk = new WorkBulk();
    bulk.setBulk(works);
    return bulk;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) MinimizedWorkEntity(org.orcid.persistence.jpa.entities.MinimizedWorkEntity) PutCodeFormatException(org.orcid.core.exception.PutCodeFormatException) BulkElement(org.orcid.jaxb.model.record_v2.BulkElement) WorkBulk(org.orcid.jaxb.model.record_v2.WorkBulk) ArrayList(java.util.ArrayList) ExceedMaxNumberOfPutCodesException(org.orcid.core.exception.ExceedMaxNumberOfPutCodesException) PutCodeFormatException(org.orcid.core.exception.PutCodeFormatException)

Aggregations

WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)27 Test (org.junit.Test)10 Work (org.orcid.jaxb.model.record_v2.Work)9 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)8 Transactional (org.springframework.transaction.annotation.Transactional)7 Date (java.util.Date)6 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)6 ArrayList (java.util.ArrayList)4 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)4 MinimizedWorkEntity (org.orcid.persistence.jpa.entities.MinimizedWorkEntity)4 DBUnitTest (org.orcid.test.DBUnitTest)4 HashSet (java.util.HashSet)3 BaseTest (org.orcid.core.BaseTest)3 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)3 Rollback (org.springframework.test.annotation.Rollback)3 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 OrcidDuplicatedActivityException (org.orcid.core.exception.OrcidDuplicatedActivityException)2 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)2 Item (org.orcid.jaxb.model.notification.permission_v2.Item)2