Search in sources :

Example 1 with WorkEntity

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

the class WorkDaoTest method testAddWork.

@Test
@Rollback(true)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void testAddWork() {
    String title = "New Work";
    String subtitle = "Subtitle";
    String citation = "Test citation";
    String description = "Description for new work";
    String url = "http://work.com";
    WorkEntity work = new WorkEntity();
    work.setCitation(citation);
    work.setCitationType(CitationType.FORMATTED_UNSPECIFIED);
    work.setDescription(description);
    work.setTitle(title);
    work.setSubtitle(subtitle);
    work.setWorkType(WorkType.BOOK);
    work.setWorkUrl(url);
    ProfileEntity profile = new ProfileEntity(USER_ORCID);
    work.setProfile(profile);
    work.setSourceId(USER_ORCID);
    work.setAddedToProfileDate(new Date());
    assertNull(work.getId());
    try {
        work = workDao.addWork(work);
    } catch (Exception e) {
        fail();
    }
    assertNotNull(work.getId());
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with WorkEntity

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

the class Jaxb2JpaAdapterImpl method getWorkEntity.

public WorkEntity getWorkEntity(OrcidWork orcidWork, WorkEntity workEntity) {
    if (orcidWork != null) {
        if (workEntity == null) {
            String putCode = orcidWork.getPutCode();
            if (StringUtils.isNotBlank(putCode) && !"-1".equals(putCode)) {
                throw new IllegalArgumentException("Invalid put-code was supplied: " + putCode);
            }
            workEntity = new WorkEntity();
        } else {
            workEntity.clean();
        }
        Citation workCitation = orcidWork.getWorkCitation();
        if (workCitation != null && StringUtils.isNotBlank(workCitation.getCitation()) && workCitation.getWorkCitationType() != null) {
            workEntity.setCitation(workCitation.getCitation());
            workEntity.setCitationType(CitationType.fromValue(workCitation.getWorkCitationType().value()));
        }
        // New way of doing work contributors
        workEntity.setContributorsJson(getWorkContributorsJson(orcidWork.getWorkContributors()));
        workEntity.setDescription(orcidWork.getShortDescription() != null ? orcidWork.getShortDescription() : null);
        // New way of doing work external ids
        workEntity.setExternalIdentifiersJson(getWorkExternalIdsJson(orcidWork));
        workEntity.setPublicationDate(getWorkPublicationDate(orcidWork));
        WorkTitle workTitle = orcidWork.getWorkTitle();
        if (workTitle != null) {
            workEntity.setSubtitle(workTitle.getSubtitle() != null ? workTitle.getSubtitle().getContent() : null);
            workEntity.setTitle(workTitle.getTitle() != null ? workTitle.getTitle().getContent().trim() : null);
            TranslatedTitle translatedTitle = workTitle.getTranslatedTitle();
            if (translatedTitle != null) {
                workEntity.setTranslatedTitle(StringUtils.isEmpty(translatedTitle.getContent()) ? null : translatedTitle.getContent());
                workEntity.setTranslatedTitleLanguageCode(StringUtils.isEmpty(translatedTitle.getLanguageCode()) ? null : translatedTitle.getLanguageCode());
            }
        }
        workEntity.setJournalTitle(orcidWork.getJournalTitle() != null ? orcidWork.getJournalTitle().getContent() : null);
        workEntity.setLanguageCode(orcidWork.getLanguageCode() != null ? orcidWork.getLanguageCode() : null);
        if (orcidWork.getCountry() != null && orcidWork.getCountry().getValue() != null) {
            workEntity.setIso2Country(org.orcid.jaxb.model.common_v2.Iso3166Country.fromValue(orcidWork.getCountry().getValue().value()));
        }
        workEntity.setWorkUrl(orcidWork.getUrl() != null ? orcidWork.getUrl().getValue() : null);
        if (orcidWork.getWorkType() != null) {
            workEntity.setWorkType(org.orcid.jaxb.model.record_v2.WorkType.fromValue(orcidWork.getWorkType().value()));
        }
        if (orcidWork.getVisibility() != null) {
            workEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.fromValue(orcidWork.getVisibility().value()));
        } else {
            workEntity.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
        }
        workEntity.setAddedToProfileDate(new Date());
        //Set source
        setSource(orcidWork.getSource(), workEntity);
        if (workEntity.getDisplayIndex() == null) {
            workEntity.setDisplayIndex(0L);
        }
        return workEntity;
    }
    return null;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) TranslatedTitle(org.orcid.jaxb.model.message.TranslatedTitle) WorkTitle(org.orcid.jaxb.model.message.WorkTitle) Citation(org.orcid.jaxb.model.message.Citation) 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)

Example 3 with WorkEntity

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

the class WorkManagerTest method displayIndexIsSetTo_1_FromUI.

@Test
public void displayIndexIsSetTo_1_FromUI() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Work w1 = getWork("fromUI-1");
    w1 = workManager.createWork(claimedOrcid, w1, false);
    WorkEntity w = workDao.find(w1.getPutCode());
    assertNotNull(w1);
    assertEquals(Long.valueOf(1), 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 4 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 5 with WorkEntity

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

the class JpaJaxbWorkAdapterTest method fromProfileWorkEntityToWorkSummaryTest.

@Test
public void fromProfileWorkEntityToWorkSummaryTest() {
    WorkEntity work = getWorkEntity();
    assertNotNull(work);
    WorkSummary ws = jpaJaxbWorkAdapter.toWorkSummary(work);
    assertNotNull(ws);
    assertEquals(Long.valueOf(12345), ws.getPutCode());
    assertEquals(Visibility.LIMITED.value(), ws.getVisibility().value());
    assertEquals("1234567890", ws.getDisplayIndex());
    assertNotNull(ws.getExternalIdentifiers());
    assertNotNull(ws.getExternalIdentifiers().getExternalIdentifier());
    assertEquals(1, ws.getExternalIdentifiers().getExternalIdentifier().size());
    ExternalID workExtId = ws.getExternalIdentifiers().getExternalIdentifier().get(0);
    assertNotNull(workExtId.getValue());
    assertEquals("123", workExtId.getValue());
    assertNotNull(workExtId.getType());
    assertEquals(org.orcid.jaxb.model.message.WorkExternalIdentifierType.AGR.value(), workExtId.getType());
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) WorkSummary(org.orcid.jaxb.model.record.summary_v2.WorkSummary) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) 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