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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations