Search in sources :

Example 21 with PeerReview

use of org.orcid.jaxb.model.record_rc4.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, System.currentTimeMillis());
        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, createItem(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 22 with PeerReview

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

the class SourceInActivitiesTest method sourceDoesntChange_PeerReview_Test.

@Test
public void sourceDoesntChange_PeerReview_Test() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    PeerReview peerReview1 = getPeerReview(userOrcid);
    assertNotNull(peerReview1);
    assertNotNull(peerReview1.getSubjectName());
    assertNotNull(peerReview1.getSubjectName().getTitle());
    assertFalse(PojoUtil.isEmpty(peerReview1.getSubjectName().getTitle().getContent()));
    assertEquals(userOrcid, peerReview1.retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    PeerReview peerReview2 = getPeerReview(userOrcid);
    assertNotNull(peerReview2);
    assertNotNull(peerReview2.getSubjectName());
    assertNotNull(peerReview2.getSubjectName().getTitle());
    assertFalse(PojoUtil.isEmpty(peerReview2.getSubjectName().getTitle().getContent()));
    assertEquals(CLIENT_1_ID, peerReview2.retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
    PeerReview peerReview3 = getPeerReview(userOrcid);
    assertNotNull(peerReview3);
    assertNotNull(peerReview3.getSubjectName());
    assertNotNull(peerReview3.getSubjectName().getTitle());
    assertFalse(PojoUtil.isEmpty(peerReview3.getSubjectName().getTitle().getContent()));
    assertEquals(CLIENT_2_ID, peerReview3.retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    PeerReview peerReview4 = getPeerReview(userOrcid);
    assertNotNull(peerReview4);
    assertNotNull(peerReview4.getSubjectName());
    assertNotNull(peerReview4.getSubjectName().getTitle());
    assertFalse(PojoUtil.isEmpty(peerReview4.getSubjectName().getTitle().getContent()));
    assertEquals(userOrcid, peerReview4.retrieveSourcePath());
    PeerReview fromDb1 = peerReviewManager.getPeerReview(userOrcid, peerReview1.getPutCode());
    assertNotNull(fromDb1);
    assertEquals(userOrcid, fromDb1.retrieveSourcePath());
    PeerReview fromDb2 = peerReviewManager.getPeerReview(userOrcid, peerReview2.getPutCode());
    assertNotNull(fromDb2);
    assertEquals(CLIENT_1_ID, fromDb2.retrieveSourcePath());
    PeerReview fromDb3 = peerReviewManager.getPeerReview(userOrcid, peerReview3.getPutCode());
    assertNotNull(fromDb3);
    assertEquals(CLIENT_2_ID, fromDb3.retrieveSourcePath());
    PeerReview fromDb4 = peerReviewManager.getPeerReview(userOrcid, peerReview4.getPutCode());
    assertNotNull(fromDb4);
    assertEquals(userOrcid, fromDb4.retrieveSourcePath());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test)

Example 23 with PeerReview

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

the class SourceInActivitiesTest method getPeerReview.

private PeerReview getPeerReview(String userOrcid) {
    PeerReview peerReview = new PeerReview();
    peerReview.setOrganization(getOrganization());
    peerReview.setType(PeerReviewType.EVALUATION);
    WorkTitle workTitle = new WorkTitle();
    workTitle.setTitle(new Title("Title " + System.currentTimeMillis()));
    ExternalIDs workExtIds = new ExternalIDs();
    ExternalID workExtId = new ExternalID();
    workExtId.setValue("ID");
    workExtId.setType(WorkExternalIdentifierType.AGR.value());
    workExtIds.getExternalIdentifier().add(workExtId);
    peerReview.setSubjectName(workTitle);
    peerReview.setSubjectExternalIdentifier(workExtId);
    peerReview.setSubjectType(WorkType.ARTISTIC_PERFORMANCE);
    peerReview.setExternalIdentifiers(workExtIds);
    peerReview.setRole(Role.CHAIR);
    peerReview = peerReviewManager.createPeerReview(userOrcid, peerReview, false);
    return peerReviewManager.getPeerReview(userOrcid, peerReview.getPutCode());
}
Also used : ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Title(org.orcid.jaxb.model.common_v2.Title) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview)

Example 24 with PeerReview

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

the class PeerReviewManagerTest method testAddPeerReviewToClaimedRecordPreserveUserDefaultVisibility.

@Test
public void testAddPeerReviewToClaimedRecordPreserveUserDefaultVisibility() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    PeerReview peer = getPeerReview(null);
    peer = peerReviewManager.createPeerReview(claimedOrcid, peer, true);
    peer = peerReviewManager.getPeerReview(claimedOrcid, peer.getPutCode());
    assertNotNull(peer);
    assertEquals(Visibility.LIMITED, peer.getVisibility());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 25 with PeerReview

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

the class PeerReviewManagerTest method testAddPeerReviewToUnclaimedRecordPreservePeerReviewVisibility.

@Test
public void testAddPeerReviewToUnclaimedRecordPreservePeerReviewVisibility() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    PeerReview peer = getPeerReview(null);
    peer = peerReviewManager.createPeerReview(unclaimedOrcid, peer, true);
    peer = peerReviewManager.getPeerReview(unclaimedOrcid, peer.getPutCode());
    assertNotNull(peer);
    assertEquals(Visibility.PUBLIC, peer.getVisibility());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

Test (org.junit.Test)71 PeerReview (org.orcid.jaxb.model.record_v2.PeerReview)68 ClientResponse (com.sun.jersey.api.client.ClientResponse)35 Response (javax.ws.rs.core.Response)17 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)17 DBUnitTest (org.orcid.test.DBUnitTest)17 Url (org.orcid.jaxb.model.common_v2.Url)11 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)10 ArrayList (java.util.ArrayList)9 PeerReview (org.orcid.jaxb.model.record_rc1.PeerReview)9 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)8 BaseTest (org.orcid.core.BaseTest)6 Title (org.orcid.jaxb.model.common_v2.Title)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 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)6 Funding (org.orcid.jaxb.model.record_v2.Funding)6 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)6