Search in sources :

Example 96 with Work

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

the class ValidateV2RC3Identifiers method testWork.

/**
 * <common:external-ids>
 *                <common:external-id>
 *                        <common:external-id-type>agr</common:external-id-type>
 *                        <common:external-id-value>work:external-identifier-id</common:external-id-value>
 *                        <common:external-id-url>http://orcid.org</common:external-id-url>
 *                        <common:external-id-relationship>self</common:external-id-relationship>
 *                </common:external-id>
 *        </common:external-ids>
 *
 * @throws SAXException
 * @throws IOException
 * @throws JAXBException
 * @throws ParserConfigurationException
 */
@Test
public void testWork() throws SAXException, IOException, JAXBException, ParserConfigurationException {
    Work work = unmarshallFromPath("/record_2.0_rc3/samples/work-2.0_rc3.xml", Work.class);
    ExternalID id = work.getExternalIdentifiers().getExternalIdentifier().get(0);
    assertEquals("agr", id.getType());
    assertEquals("work:external-identifier-id", id.getValue());
    assertEquals(new Url("http://orcid.org"), id.getUrl());
    assertEquals(Relationship.SELF, id.getRelationship());
    Validator validator = getValidator("work");
    validator.validate(marshall(Work.class, work));
    validator.validate(marshallToDOM(Work.class, work));
    work = unmarshallFromPath("/record_2.0_rc3/samples/work-full-2.0_rc3.xml", Work.class);
    id = work.getExternalIdentifiers().getExternalIdentifier().get(0);
    assertEquals("agr", id.getType());
    assertEquals("work:external-identifier-id", id.getValue());
    assertEquals(new Url("http://orcid.org"), id.getUrl());
    assertEquals(Relationship.SELF, id.getRelationship());
    validator.validate(marshall(Work.class, work));
    validator.validate(marshallToDOM(Work.class, work));
}
Also used : ExternalID(org.orcid.jaxb.model.record_rc3.ExternalID) Work(org.orcid.jaxb.model.record_rc3.Work) Url(org.orcid.jaxb.model.common_rc3.Url) Validator(javax.xml.validation.Validator) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 97 with Work

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

the class ValidateV2RC4Identifiers method testPeerReview.

/**
 * Test both types of identifier here
 *
 * @throws SAXException
 * @throws IOException
 * @throws JAXBException
 * @throws ParserConfigurationException
 */
@Test
public void testPeerReview() throws SAXException, IOException, JAXBException, ParserConfigurationException {
    PeerReview peerReview = unmarshallFromPath("/record_2.0_rc4/samples/peer-review-2.0_rc4.xml", PeerReview.class);
    ExternalID id = peerReview.getExternalIdentifiers().getExternalIdentifier().get(0);
    assertEquals("source-work-id", id.getType());
    assertEquals("work:external-identifier-id", id.getValue());
    assertEquals(new Url("http://orcid.org"), id.getUrl());
    assertEquals(Relationship.SELF, id.getRelationship());
    ExternalID subjectid = peerReview.getSubjectExternalIdentifier();
    assertEquals("doi", subjectid.getType());
    assertEquals("peer-review:subject-external-identifier-id", subjectid.getValue());
    assertEquals(new Url("http://orcid.org"), subjectid.getUrl());
    assertEquals(Relationship.SELF, subjectid.getRelationship());
    Validator validator = getValidator("peer-review");
    validator.validate(marshall(PeerReview.class, peerReview));
    validator.validate(marshallToDOM(PeerReview.class, peerReview));
    // do the full record too
    peerReview = unmarshallFromPath("/record_2.0_rc4/samples/peer-review-full-2.0_rc4.xml", PeerReview.class);
    id = peerReview.getExternalIdentifiers().getExternalIdentifier().get(0);
    assertEquals("source-work-id", id.getType());
    assertEquals("work:external-identifier-id", id.getValue());
    assertEquals(new Url("http://orcid.org"), id.getUrl());
    assertEquals(Relationship.SELF, id.getRelationship());
    subjectid = peerReview.getSubjectExternalIdentifier();
    assertEquals("doi", subjectid.getType());
    assertEquals("peer-review:subject-external-identifier-id", subjectid.getValue());
    assertEquals(new Url("http://orcid.org"), subjectid.getUrl());
    assertEquals(Relationship.SELF, subjectid.getRelationship());
}
Also used : ExternalID(org.orcid.jaxb.model.record_rc4.ExternalID) PeerReview(org.orcid.jaxb.model.record_rc4.PeerReview) Url(org.orcid.jaxb.model.common_rc4.Url) Validator(javax.xml.validation.Validator) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 98 with Work

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

the class ValidateV2RC4Identifiers method testWork.

/**
 * <common:external-ids>
 *                <common:external-id>
 *                        <common:external-id-type>agr</common:external-id-type>
 *                        <common:external-id-value>work:external-identifier-id</common:external-id-value>
 *                        <common:external-id-url>http://orcid.org</common:external-id-url>
 *                        <common:external-id-relationship>self</common:external-id-relationship>
 *                </common:external-id>
 *        </common:external-ids>
 *
 * @throws SAXException
 * @throws IOException
 * @throws JAXBException
 * @throws ParserConfigurationException
 */
@Test
public void testWork() throws SAXException, IOException, JAXBException, ParserConfigurationException {
    Work work = unmarshallFromPath("/record_2.0_rc4/samples/work-2.0_rc4.xml", Work.class);
    ExternalID id = work.getExternalIdentifiers().getExternalIdentifier().get(0);
    assertEquals("agr", id.getType());
    assertEquals("work:external-identifier-id", id.getValue());
    assertEquals(new Url("http://orcid.org"), id.getUrl());
    assertEquals(Relationship.SELF, id.getRelationship());
    Validator validator = getValidator("work");
    validator.validate(marshall(Work.class, work));
    validator.validate(marshallToDOM(Work.class, work));
    work = unmarshallFromPath("/record_2.0_rc4/samples/work-full-2.0_rc4.xml", Work.class);
    id = work.getExternalIdentifiers().getExternalIdentifier().get(0);
    assertEquals("agr", id.getType());
    assertEquals("work:external-identifier-id", id.getValue());
    assertEquals(new Url("http://orcid.org"), id.getUrl());
    assertEquals(Relationship.SELF, id.getRelationship());
    validator.validate(marshall(Work.class, work));
    validator.validate(marshallToDOM(Work.class, work));
}
Also used : ExternalID(org.orcid.jaxb.model.record_rc4.ExternalID) Work(org.orcid.jaxb.model.record_rc4.Work) Url(org.orcid.jaxb.model.common_rc4.Url) Validator(javax.xml.validation.Validator) MarshallingTest(org.orcid.jaxb.model.notification.custom.MarshallingTest) Test(org.junit.Test)

Example 99 with Work

use of org.orcid.jaxb.model.record_rc4.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)) {
            List<Work> existingWorks = this.findWorks(orcid);
            if (existingWorks != null) {
                if ((existingWorks.size() + 1) > this.maxNumOfActivities) {
                    throw new ExceedMaxNumberOfElementsException();
                }
                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.setOrcid(orcid);
    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, createItemList(workEntity));
    return jpaJaxbWorkAdapter.toWork(workEntity);
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ExceedMaxNumberOfElementsException(org.orcid.core.exception.ExceedMaxNumberOfElementsException) 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 100 with Work

use of org.orcid.jaxb.model.record_rc4.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());
        List<Work> existingWorks = this.findWorks(orcid);
        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, createItemList(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)

Aggregations

Test (org.junit.Test)153 Work (org.orcid.jaxb.model.record_v2.Work)151 ClientResponse (com.sun.jersey.api.client.ClientResponse)53 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)35 WorkBulk (org.orcid.jaxb.model.record_v2.WorkBulk)26 DBUnitTest (org.orcid.test.DBUnitTest)25 Response (javax.ws.rs.core.Response)24 Title (org.orcid.jaxb.model.common_v2.Title)24 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)23 Url (org.orcid.jaxb.model.common_v2.Url)22 OrcidError (org.orcid.jaxb.model.error_v2.OrcidError)22 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)17 ArrayList (java.util.ArrayList)16 BaseTest (org.orcid.core.BaseTest)16 BulkElement (org.orcid.jaxb.model.record.bulk.BulkElement)16 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)15 Work (org.orcid.jaxb.model.record_rc1.Work)12 Work (org.orcid.jaxb.model.record_rc3.Work)11 ExternalID (org.orcid.jaxb.model.record_rc4.ExternalID)11 Work (org.orcid.jaxb.model.record_rc4.Work)11