Search in sources :

Example 31 with WorkEntity

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

the class JpaJaxbWorkAdapterTest method fromProfileWorkEntityToWorkTest.

@Test
public void fromProfileWorkEntityToWorkTest() {
    // Set base url to https to ensure source URI is converted to http
    orcidUrlManager.setBaseUrl("https://testserver.orcid.org");
    WorkEntity work = getWorkEntity();
    assertNotNull(work);
    Work w = jpaJaxbWorkAdapter.toWork(work);
    assertNotNull(w);
    assertNotNull(w.getCreatedDate());
    assertEquals(DateUtils.convertToDate("2015-06-05T10:15:20"), DateUtils.convertToDate(w.getCreatedDate().getValue()));
    assertNotNull(w.getLastModifiedDate());
    assertEquals(DateUtils.convertToDate("2015-06-05T10:15:20"), DateUtils.convertToDate(w.getLastModifiedDate().getValue()));
    assertEquals(Iso3166Country.CR.value(), w.getCountry().getValue().value());
    assertEquals("work:citation", w.getWorkCitation().getCitation());
    assertEquals("work:description", w.getShortDescription());
    assertEquals("work:journalTitle", w.getJournalTitle().getContent());
    assertEquals(CitationType.BIBTEX.value(), w.getWorkCitation().getWorkCitationType().value());
    assertEquals(Long.valueOf(12345), w.getPutCode());
    assertEquals(Visibility.LIMITED.value(), w.getVisibility().value());
    assertEquals("work:title", w.getWorkTitle().getTitle().getContent());
    assertEquals("work:subtitle", w.getWorkTitle().getSubtitle().getContent());
    assertEquals("work:translatedTitle", w.getWorkTitle().getTranslatedTitle().getContent());
    assertEquals("ES", w.getWorkTitle().getTranslatedTitle().getLanguageCode());
    assertEquals(WorkType.ARTISTIC_PERFORMANCE.value(), w.getWorkType().value());
    assertNotNull(w.getWorkExternalIdentifiers());
    assertNotNull(w.getWorkExternalIdentifiers().getExternalIdentifier());
    assertEquals(1, w.getWorkExternalIdentifiers().getExternalIdentifier().size());
    ExternalID workExtId = w.getWorkExternalIdentifiers().getExternalIdentifier().get(0);
    assertNotNull(workExtId.getValue());
    assertEquals("123", workExtId.getValue());
    assertNotNull(workExtId.getType());
    assertEquals(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value(), workExtId.getType());
    String sourcePath = w.getSource().retrieveSourcePath();
    assertNotNull(sourcePath);
    assertEquals("APP-5555555555555555", sourcePath);
    // Identifier URIs should always be http, event if base url is https
    assertEquals("https://testserver.orcid.org/client/APP-5555555555555555", w.getSource().retriveSourceUri());
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Test(org.junit.Test)

Example 32 with WorkEntity

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

the class JpaJaxbWorkAdapterTest method getWorkEntity.

private WorkEntity getWorkEntity() {
    Date date = DateUtils.convertToDate("2015-06-05T10:15:20");
    WorkEntity work = new WorkEntity();
    work.setDateCreated(date);
    work.setLastModified(date);
    work.setOrcid("0000-0000-0000-0001");
    work.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
    work.setDisplayIndex(1234567890L);
    work.setClientSourceId("APP-5555555555555555");
    work.setCitation("work:citation");
    work.setCitationType(org.orcid.jaxb.model.record_v2.CitationType.BIBTEX);
    work.setDateCreated(date);
    work.setDescription("work:description");
    work.setId(12345L);
    work.setIso2Country(org.orcid.jaxb.model.common_v2.Iso3166Country.CR);
    work.setJournalTitle("work:journalTitle");
    work.setLanguageCode("EN");
    work.setLastModified(date);
    work.setPublicationDate(new PublicationDateEntity(2000, 1, 1));
    work.setSubtitle("work:subtitle");
    work.setTitle("work:title");
    work.setTranslatedTitle("work:translatedTitle");
    work.setTranslatedTitleLanguageCode("ES");
    work.setWorkType(org.orcid.jaxb.model.record_v2.WorkType.ARTISTIC_PERFORMANCE);
    work.setWorkUrl("work:url");
    work.setContributorsJson("{\"contributor\":[]}");
    work.setExternalIdentifiersJson("{\"workExternalIdentifier\":[{\"workExternalIdentifierType\":\"AGR\",\"workExternalIdentifierId\":{\"content\":\"123\"}}]}");
    return work;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) PublicationDateEntity(org.orcid.persistence.jpa.entities.PublicationDateEntity) Date(java.util.Date)

Example 33 with WorkEntity

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

the class Jaxb2JpaAdapterImpl method getWorkEntities.

private SortedSet<WorkEntity> getWorkEntities(ProfileEntity profileEntity, OrcidWorks orcidWorks) {
    SortedSet<WorkEntity> existingWorkEntities = profileEntity.getWorks();
    Map<String, WorkEntity> existingWorkEntitiesMap = createWorkEntitiesMap(existingWorkEntities);
    SortedSet<WorkEntity> workEntities = null;
    if (existingWorkEntities == null) {
        workEntities = new TreeSet<WorkEntity>();
    } else {
        // To allow for orphan deletion
        existingWorkEntities.clear();
        workEntities = existingWorkEntities;
    }
    if (orcidWorks != null && orcidWorks.getOrcidWork() != null && !orcidWorks.getOrcidWork().isEmpty()) {
        List<OrcidWork> orcidWorkList = orcidWorks.getOrcidWork();
        for (OrcidWork orcidWork : orcidWorkList) {
            WorkEntity workEntity = getWorkEntity(orcidWork, existingWorkEntitiesMap.get(orcidWork.getPutCode()));
            if (workEntity != null) {
                workEntity.setProfile(profileEntity);
                workEntities.add(workEntity);
            }
        }
    }
    return workEntities;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidWork(org.orcid.jaxb.model.message.OrcidWork)

Example 34 with WorkEntity

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

the class OrcidProfileManagerImpl method checkForAlreadyExistingWorks.

private void checkForAlreadyExistingWorks(OrcidWorks existingOrcidWorks, List<OrcidWork> updatedOrcidWorksList) {
    if (existingOrcidWorks != null) {
        Set<OrcidWork> existingOrcidWorksSet = new HashSet<>();
        for (OrcidWork existingWork : existingOrcidWorks.getOrcidWork()) {
            existingOrcidWorksSet.add(existingWork);
        }
        for (Iterator<OrcidWork> updatedWorkIterator = updatedOrcidWorksList.iterator(); updatedWorkIterator.hasNext(); ) {
            OrcidWork updatedWork = updatedWorkIterator.next();
            for (OrcidWork orcidWork : existingOrcidWorksSet) {
                if (orcidWork.isDuplicated(updatedWork)) {
                    // Update the existing work
                    long workId = Long.valueOf(orcidWork.getPutCode());
                    WorkEntity workEntity = workDao.find(workId);
                    workEntity.clean();
                    workEntity = jaxb2JpaAdapter.getWorkEntity(updatedWork, workEntity);
                    workDao.persist(workEntity);
                    // Since it was already updated, remove it from the list
                    // of updated works
                    updatedWorkIterator.remove();
                    break;
                }
            }
        }
    }
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 35 with WorkEntity

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

the class JpaJaxbWorkAdapterTest method fromProfileWorkEntityToWorkTest.

@Test
public void fromProfileWorkEntityToWorkTest() {
    // Set base url to https to ensure source URI is converted to http
    orcidUrlManager.setBaseUrl("https://testserver.orcid.org");
    WorkEntity work = getWorkEntity();
    assertNotNull(work);
    Work w = jpaJaxbWorkAdapter.toWork(work);
    assertNotNull(w);
    assertNotNull(w.getCreatedDate());
    assertEquals(DateUtils.convertToDate("2015-06-05T10:15:20"), DateUtils.convertToDate(w.getCreatedDate().getValue()));
    assertNotNull(w.getLastModifiedDate());
    assertEquals(DateUtils.convertToDate("2015-06-05T10:15:20"), DateUtils.convertToDate(w.getLastModifiedDate().getValue()));
    assertEquals(org.orcid.jaxb.model.common_v2.Iso3166Country.CR.value(), w.getCountry().getValue().value());
    assertEquals("work:citation", w.getWorkCitation().getCitation());
    assertEquals("work:description", w.getShortDescription());
    assertEquals("work:journalTitle", w.getJournalTitle().getContent());
    assertEquals(CitationType.BIBTEX.value(), w.getWorkCitation().getWorkCitationType().value());
    assertEquals(Long.valueOf(12345), w.getPutCode());
    assertEquals(Visibility.LIMITED.value(), w.getVisibility().value());
    assertEquals("work:title", w.getWorkTitle().getTitle().getContent());
    assertEquals("work:subtitle", w.getWorkTitle().getSubtitle().getContent());
    assertEquals("work:translatedTitle", w.getWorkTitle().getTranslatedTitle().getContent());
    assertEquals("ES", w.getWorkTitle().getTranslatedTitle().getLanguageCode());
    assertEquals(WorkType.ARTISTIC_PERFORMANCE.value(), w.getWorkType().value());
    assertNotNull(w.getWorkExternalIdentifiers());
    assertNotNull(w.getWorkExternalIdentifiers().getExternalIdentifier());
    assertEquals(1, w.getWorkExternalIdentifiers().getExternalIdentifier().size());
    ExternalID workExtId = w.getWorkExternalIdentifiers().getExternalIdentifier().get(0);
    assertNotNull(workExtId.getValue());
    assertEquals("123", workExtId.getValue());
    assertNotNull(workExtId.getType());
    assertEquals(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value(), workExtId.getType());
    String sourcePath = w.getSource().retrieveSourcePath();
    assertNotNull(sourcePath);
    assertEquals("APP-5555555555555555", sourcePath);
    // Identifier URIs should always be http, event if base url is https
    assertEquals("http://testserver.orcid.org/client/APP-5555555555555555", w.getSource().retriveSourceUri());
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Aggregations

WorkEntity (org.orcid.persistence.jpa.entities.WorkEntity)57 Test (org.junit.Test)22 MinimizedWorkEntity (org.orcid.persistence.jpa.entities.MinimizedWorkEntity)20 Date (java.util.Date)15 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)12 Work (org.orcid.jaxb.model.v3.dev1.record.Work)10 Transactional (org.springframework.transaction.annotation.Transactional)10 Work (org.orcid.jaxb.model.record_v2.Work)9 ArrayList (java.util.ArrayList)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)8 BaseTest (org.orcid.core.BaseTest)7 ExceedMaxNumberOfElementsException (org.orcid.core.exception.ExceedMaxNumberOfElementsException)6 OrcidWork (org.orcid.jaxb.model.message.OrcidWork)6 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)6 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)6 PublicationDateEntity (org.orcid.persistence.jpa.entities.PublicationDateEntity)6 DBUnitTest (org.orcid.test.DBUnitTest)5 HashMap (java.util.HashMap)4 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)4 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)4