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