Search in sources :

Example 86 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class WorkManagerImpl method updateWork.

@Override
@Transactional
public Work updateWork(String orcid, Work work, boolean isApiRequest) {
    WorkEntity workEntity = workDao.getWork(orcid, work.getPutCode());
    Visibility originalVisibility = workEntity.getVisibility();
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    //Save the original source
    String existingSourceId = workEntity.getSourceId();
    String existingClientSourceId = workEntity.getClientSourceId();
    if (isApiRequest) {
        activityValidator.validateWork(work, sourceEntity, false, isApiRequest, workEntity.getVisibility());
        long lastModifiedTime = getLastModified(orcid);
        List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
        for (Work existing : existingWorks) {
            // Dont compare the updated peer review with the DB version
            if (!existing.getPutCode().equals(work.getPutCode())) {
                activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
            }
        }
    } else {
        //validate external ID vocab
        externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
    }
    orcidSecurityManager.checkSource(workEntity);
    jpaJaxbWorkAdapter.toWorkEntity(work, workEntity);
    workEntity.setVisibility(originalVisibility);
    //Be sure it doesn't overwrite the source
    workEntity.setSourceId(existingSourceId);
    workEntity.setClientSourceId(existingClientSourceId);
    workDao.merge(workEntity);
    workDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItem(workEntity));
    return jpaJaxbWorkAdapter.toWork(workEntity);
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.record_v2.Work) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Transactional(org.springframework.transaction.annotation.Transactional)

Example 87 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class WorkManagerImpl method createWork.

@Override
@Transactional
public Work createWork(String orcid, Work work, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    if (isApiRequest) {
        activityValidator.validateWork(work, sourceEntity, true, isApiRequest, null);
        // duplicates
        if (!sourceEntity.getSourceId().equals(orcid)) {
            long lastModifiedTime = getLastModified(orcid);
            List<Work> existingWorks = this.findWorks(orcid, lastModifiedTime);
            if (existingWorks != null) {
                for (Work existing : existingWorks) {
                    activityValidator.checkExternalIdentifiersForDuplicates(work.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
                }
            }
        }
    } else {
        // validate external ID vocab
        externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
    }
    WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work);
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    workEntity.setProfile(profile);
    workEntity.setAddedToProfileDate(new Date());
    // Set source id 
    if (sourceEntity.getSourceProfile() != null) {
        workEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        workEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    setIncomingWorkPrivacy(workEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(workEntity, isApiRequest);
    workDao.persist(workEntity);
    workDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.WORK, createItem(workEntity));
    return jpaJaxbWorkAdapter.toWork(workEntity);
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Work(org.orcid.jaxb.model.record_v2.Work) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 88 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class JpaJaxbWorkAdapterTest method testToWorkEntity.

@Test
public void testToWorkEntity() throws JAXBException {
    Work work = getWork(true);
    assertNotNull(work);
    WorkEntity workEntity = jpaJaxbWorkAdapter.toWorkEntity(work);
    assertNotNull(workEntity);
    assertEquals(Visibility.PRIVATE, workEntity.getVisibility());
    assertNotNull(workEntity);
    assertEquals(123, workEntity.getId().longValue());
    assertEquals("common:title", workEntity.getTitle());
    assertTrue(PojoUtil.isEmpty(workEntity.getSubtitle()));
    assertEquals("common:translated-title", workEntity.getTranslatedTitle());
    assertEquals("en", workEntity.getTranslatedTitleLanguageCode());
    assertEquals("work:short-description", workEntity.getDescription());
    assertEquals(CitationType.FORMATTED_UNSPECIFIED, workEntity.getCitationType());
    assertEquals(WorkType.ARTISTIC_PERFORMANCE, workEntity.getWorkType());
    PublicationDateEntity publicationDateEntity = workEntity.getPublicationDate();
    assertNotNull(publicationDateEntity);
    assertEquals(1848, publicationDateEntity.getYear().intValue());
    assertEquals(02, publicationDateEntity.getMonth().intValue());
    assertEquals(02, publicationDateEntity.getDay().intValue());
    assertEquals("{\"workExternalIdentifier\":[{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"AGR\",\"workExternalIdentifierId\":{\"content\":\"work:external-identifier-id\"}}]}", workEntity.getExternalIdentifiersJson());
    assertEquals("http://tempuri.org", workEntity.getWorkUrl());
    assertEquals("{\"contributor\":[{\"contributorOrcid\":{\"uri\":\"http://orcid.org/8888-8888-8888-8880\",\"path\":\"8888-8888-8888-8880\",\"host\":\"orcid.org\"},\"creditName\":{\"content\":\"work:credit-name\"},\"contributorEmail\":{\"value\":\"work@contributor.email\"},\"contributorAttributes\":{\"contributorSequence\":\"FIRST\",\"contributorRole\":\"AUTHOR\"}}]}", workEntity.getContributorsJson());
    assertEquals("en", workEntity.getLanguageCode());
    assertEquals(Iso3166Country.AF, workEntity.getIso2Country());
    // Source
    assertNull(workEntity.getSourceId());
    assertNull(workEntity.getClientSourceId());
    assertNull(workEntity.getElementSourceId());
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) PublicationDateEntity(org.orcid.persistence.jpa.entities.PublicationDateEntity) Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Example 89 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class OrcidSecurityManagerTestBase method createWork.

protected Work createWork(Visibility v, String sourceId) {
    Work work = new Work();
    work.setVisibility(v);
    setSource(work, sourceId);
    return work;
}
Also used : Work(org.orcid.jaxb.model.record_v2.Work)

Example 90 with Work

use of org.orcid.jaxb.model.record_rc2.Work in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateWork_emptyContributorEmailTest.

@Test(expected = OrcidValidationException.class)
public void validateWork_emptyContributorEmailTest() {
    Work work = getWork();
    work.getWorkContributors().getContributor().get(0).getContributorEmail().setValue("");
    activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
}
Also used : Work(org.orcid.jaxb.model.record_v2.Work) Test(org.junit.Test)

Aggregations

Work (org.orcid.jaxb.model.record_v2.Work)150 Test (org.junit.Test)147 ClientResponse (com.sun.jersey.api.client.ClientResponse)52 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)33 DBUnitTest (org.orcid.test.DBUnitTest)24 Response (javax.ws.rs.core.Response)23 Title (org.orcid.jaxb.model.common_v2.Title)22 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)22 Url (org.orcid.jaxb.model.common_v2.Url)21 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)21 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)19 ArrayList (java.util.ArrayList)16 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)16 BaseTest (org.orcid.core.BaseTest)14 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)13 Work (org.orcid.jaxb.model.record_rc1.Work)12 Work (org.orcid.jaxb.model.record_rc3.Work)11 Work (org.orcid.jaxb.model.record_rc4.Work)11 Funding (org.orcid.jaxb.model.record_v2.Funding)11 BulkElement (org.orcid.jaxb.model.record_v2.BulkElement)9