use of org.orcid.jaxb.model.record_v2.PeerReview in project ORCID-Source by ORCID.
the class PeerReviewManagerImpl method createPeerReview.
@Override
public PeerReview createPeerReview(String orcid, PeerReview peerReview, boolean isApiRequest) {
SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
// If request comes from the API, perform the validations
if (isApiRequest) {
// Validate it have at least one ext id
activityValidator.validatePeerReview(peerReview, sourceEntity, true, isApiRequest, null);
List<PeerReviewEntity> peerReviews = peerReviewDao.getByUser(orcid);
// duplicates
if (!sourceEntity.getSourceId().equals(orcid)) {
if (peerReviews != null) {
for (PeerReviewEntity entity : peerReviews) {
PeerReview existing = jpaJaxbPeerReviewAdapter.toPeerReview(entity);
activityValidator.checkExternalIdentifiersForDuplicates(peerReview.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
}
}
} else {
//check vocab of external identifiers
externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
}
validateGroupId(peerReview);
}
PeerReviewEntity entity = jpaJaxbPeerReviewAdapter.toPeerReviewEntity(peerReview);
// Updates the give organization with the latest organization from
// database
OrgEntity updatedOrganization = orgManager.getOrgEntity(peerReview);
entity.setOrg(updatedOrganization);
//Set the source
if (sourceEntity.getSourceProfile() != null) {
entity.setSourceId(sourceEntity.getSourceProfile().getId());
}
if (sourceEntity.getSourceClient() != null) {
entity.setClientSourceId(sourceEntity.getSourceClient().getId());
}
ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
entity.setProfile(profile);
setIncomingPrivacy(entity, profile);
DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(entity, isApiRequest);
peerReviewDao.persist(entity);
peerReviewDao.flush();
notificationManager.sendAmendEmail(orcid, AmendedSection.PEER_REVIEW, createItem(entity));
return jpaJaxbPeerReviewAdapter.toPeerReview(entity);
}
use of org.orcid.jaxb.model.record_v2.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_v2.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_v2.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_v2.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());
}
Aggregations