Search in sources :

Example 11 with WorkEntity

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

the class WorkManagerTest method displayIndexIsSetTo_0_FromAPI.

@Test
public void displayIndexIsSetTo_0_FromAPI() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Work w1 = getWork("fromAPI-1");
    w1 = workManager.createWork(claimedOrcid, w1, true);
    WorkEntity w = workDao.find(w1.getPutCode());
    assertNotNull(w1);
    assertEquals(Long.valueOf(0), w.getDisplayIndex());
}
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 12 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 13 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 14 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)

Example 15 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.setProfile(new ProfileEntity("0000-0000-0000-0001"));
    work.setVisibility(Visibility.LIMITED);
    work.setDisplayIndex(1234567890L);
    work.setClientSourceId("APP-5555555555555555");
    work.setCitation("work:citation");
    work.setCitationType(CitationType.BIBTEX);
    work.setDateCreated(date);
    work.setDescription("work:description");
    work.setId(12345L);
    work.setIso2Country(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(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) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

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