Search in sources :

Example 51 with PeerReview

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

the class PeerReviewManagerImpl method updatePeerReview.

@Override
public PeerReview updatePeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
    PeerReviewEntity existingEntity = peerReviewDao.getPeerReview(orcid, peerReview.getPutCode());
    Visibility originalVisibility = existingEntity.getVisibility();
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    // Save the original source
    String existingSourceId = existingEntity.getSourceId();
    String existingClientSourceId = existingEntity.getClientSourceId();
    // If request comes from the API perform validations
    if (isApiRequest) {
        activityValidator.validatePeerReview(peerReview, sourceEntity, false, isApiRequest, originalVisibility);
        validateGroupId(peerReview);
        List<PeerReview> existingReviews = this.findPeerReviews(orcid);
        for (PeerReview existing : existingReviews) {
            // Dont compare the updated peer review with the DB version
            if (!existing.getPutCode().equals(peerReview.getPutCode())) {
                activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceManager.retrieveSourceEntity());
            }
        }
    } else {
        // check vocab of external identifiers
        externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
        externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
    }
    PeerReviewEntity updatedEntity = new PeerReviewEntity();
    orcidSecurityManager.checkSource(existingEntity);
    jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview, updatedEntity);
    updatedEntity.setProfile(new ProfileEntity(orcid));
    updatedEntity.setVisibility(originalVisibility);
    // Be sure it doesn't overwrite the source
    updatedEntity.setSourceId(existingSourceId);
    updatedEntity.setClientSourceId(existingClientSourceId);
    OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
    updatedEntity.setOrg(updatedOrganization);
    updatedEntity = peerReviewDao.merge(updatedEntity);
    peerReviewDao.flush();
    notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItemList(updatedEntity));
    return jpaJaxbPeerReviewAdapter.toPeerReview(updatedEntity);
}
Also used : PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 52 with PeerReview

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

the class JpaJaxbPeerReviewAdapterTest method testToOrgAffiliationRelationEntity.

@Test
public void testToOrgAffiliationRelationEntity() throws JAXBException {
    PeerReview e = getPeerReview(true);
    assertNotNull(e);
    PeerReviewEntity pe = jpaJaxbPeerReviewAdapter.toPeerReviewEntity(e);
    assertNotNull(pe);
    // General info
    assertEquals(Long.valueOf(12345), pe.getId());
    assertEquals(Visibility.PRIVATE.value(), pe.getVisibility().value());
    assertEquals("{\"workExternalIdentifier\":[{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"SOURCE_WORK_ID\",\"workExternalIdentifierId\":{\"content\":\"work:external-identifier-id\"}}]}", pe.getExternalIdentifiersJson());
    assertEquals("reviewer", pe.getRole().value());
    assertEquals("review", pe.getType().value());
    assertEquals("peer-review:url", pe.getUrl());
    // Dates
    assertEquals(Integer.valueOf(2), pe.getCompletionDate().getDay());
    assertEquals(Integer.valueOf(2), pe.getCompletionDate().getMonth());
    assertEquals(Integer.valueOf(1848), pe.getCompletionDate().getYear());
    // Source
    assertNull(pe.getSourceId());
    assertNull(pe.getClientSourceId());
    assertNull(pe.getElementSourceId());
    // Check org values
    assertEquals("common:name", pe.getOrg().getName());
    assertEquals("common:city", pe.getOrg().getCity());
    assertEquals("common:region", pe.getOrg().getRegion());
    assertEquals(Iso3166Country.AF.value(), pe.getOrg().getCountry().value());
    assertEquals("common:disambiguated-organization-identifier", pe.getOrg().getOrgDisambiguated().getSourceId());
    assertEquals("common:disambiguation-source", pe.getOrg().getOrgDisambiguated().getSourceType());
    // Check subject
    assertEquals("{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"DOI\",\"workExternalIdentifierId\":{\"content\":\"peer-review:subject-external-identifier-id\"}}", pe.getSubjectExternalIdentifiersJson());
    assertEquals("peer-review:subject-container-name", pe.getSubjectContainerName());
    assertEquals("peer-review:subject-name", pe.getSubjectName());
    assertEquals("peer-review:subject-translated-name", pe.getSubjectTranslatedName());
    assertEquals("en", pe.getSubjectTranslatedNameLanguageCode());
    assertEquals("peer-review:subject-url", pe.getSubjectUrl());
    assertEquals(WorkType.JOURNAL_ARTICLE, pe.getSubjectType());
    // Check group id
    assertEquals("orcid-generated:12345", pe.getGroupId());
}
Also used : PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 53 with PeerReview

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

the class PeerReviewManagerTest method testAddMultipleModifiesIndexingStatus.

@Test
public void testAddMultipleModifiesIndexingStatus() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    PeerReview p1 = getPeerReview("extId1");
    p1 = peerReviewManager.createPeerReview(claimedOrcid, p1, true);
    PeerReview p2 = getPeerReview("extId2");
    p2 = peerReviewManager.createPeerReview(claimedOrcid, p2, true);
    PeerReview p3 = getPeerReview("extId3");
    p3 = peerReviewManager.createPeerReview(claimedOrcid, p3, true);
    PeerReviewEntity entity1 = peerReviewDao.find(p1.getPutCode());
    PeerReviewEntity entity2 = peerReviewDao.find(p2.getPutCode());
    PeerReviewEntity entity3 = peerReviewDao.find(p3.getPutCode());
    assertNotNull(entity1.getDisplayIndex());
    assertNotNull(entity2.getDisplayIndex());
    assertNotNull(entity3.getDisplayIndex());
    assertEquals(Long.valueOf(0), entity3.getDisplayIndex());
    // Rollback all changes
    peerReviewDao.remove(entity1.getId());
    peerReviewDao.remove(entity2.getId());
    peerReviewDao.remove(entity3.getId());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 54 with PeerReview

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

the class PeerReviewManagerTest method displayIndexIsSetTo_1_FromUI.

@Test
public void displayIndexIsSetTo_1_FromUI() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    PeerReview p1 = getPeerReview("fromUI-1");
    p1 = peerReviewManager.createPeerReview(claimedOrcid, p1, false);
    PeerReviewEntity p = peerReviewDao.find(p1.getPutCode());
    assertNotNull(p);
    assertEquals(Long.valueOf(1), p.getDisplayIndex());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 55 with PeerReview

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

the class JpaJaxbPeerReviewAdapterTest method getPeerReview.

private PeerReview getPeerReview(boolean full) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(new Class[] { PeerReview.class });
    Unmarshaller unmarshaller = context.createUnmarshaller();
    String name = "/record_2.0/samples/read_samples/peer-review-2.0.xml";
    if (full) {
        name = "/record_2.0/samples/read_samples/peer-review-full-2.0.xml";
    }
    InputStream inputStream = getClass().getResourceAsStream(name);
    return (PeerReview) unmarshaller.unmarshal(inputStream);
}
Also used : InputStream(java.io.InputStream) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview)

Aggregations

Test (org.junit.Test)72 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)66 ClientResponse (com.sun.jersey.api.client.ClientResponse)35 Response (javax.ws.rs.core.Response)17 DBUnitTest (org.orcid.test.DBUnitTest)17 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)16 Url (org.orcid.jaxb.model.common_v2.Url)10 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)10 PeerReview (org.orcid.jaxb.model.record_rc1.PeerReview)9 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)8 ArrayList (java.util.ArrayList)7 BaseTest (org.orcid.core.BaseTest)6 WorkExternalIdentifier (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifier)6 WorkExternalIdentifierId (org.orcid.jaxb.model.record_rc1.WorkExternalIdentifierId)6 PeerReview (org.orcid.jaxb.model.record_rc3.PeerReview)6 PeerReview (org.orcid.jaxb.model.record_rc4.PeerReview)6 Funding (org.orcid.jaxb.model.record_v2.Funding)6 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)6 Title (org.orcid.jaxb.model.common_v2.Title)5 Education (org.orcid.jaxb.model.record_v2.Education)5