use of org.orcid.jaxb.model.v3.dev1.record.PeerReview in project ORCID-Source by ORCID.
the class JSONPeerReviewWorkExternalIdentifierConverterV3Test method getPeerReview.
private PeerReview getPeerReview() throws JAXBException {
JAXBContext context = JAXBContext.newInstance(new Class[] { PeerReview.class });
Unmarshaller unmarshaller = context.createUnmarshaller();
String name = "/record_3.0_dev1/samples/read_samples/peer-review-full-3.0_dev1.xml";
InputStream inputStream = getClass().getResourceAsStream(name);
return (PeerReview) unmarshaller.unmarshal(inputStream);
}
use of org.orcid.jaxb.model.v3.dev1.record.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 = Visibility.fromValue(existingEntity.getVisibility().value());
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(org.orcid.jaxb.model.common_v2.Visibility.fromValue(originalVisibility.value()));
// 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.v3.dev1.record.PeerReview in project ORCID-Source by ORCID.
the class ActivityManagerImpl method pubPeerReviewsMap.
public LinkedHashMap<Long, PeerReview> pubPeerReviewsMap(String orcid) {
List<PeerReview> peerReviews = peerReviewManager.findPeerReviews(orcid);
LinkedHashMap<Long, PeerReview> peerReviewMap = new LinkedHashMap<>();
if (peerReviews != null) {
if (!peerReviews.isEmpty()) {
for (PeerReview peerReview : peerReviews) {
if (peerReview.getVisibility().equals(Visibility.PUBLIC)) {
peerReviewMap.put(peerReview.getPutCode(), peerReview);
}
}
}
}
return peerReviewMap;
}
use of org.orcid.jaxb.model.v3.dev1.record.PeerReview in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_GeneralTest method testOrcidProfileCreate_CANT_UpdateOnClaimedAccounts.
@Test
public void testOrcidProfileCreate_CANT_UpdateOnClaimedAccounts() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
Response response = serviceDelegator.viewAddress(ORCID, 9L);
assertNotNull(response);
Address a = (Address) response.getEntity();
assertNotNull(a);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updateAddress(ORCID, a.getPutCode(), a);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
response = serviceDelegator.viewEducation(ORCID, 20L);
assertNotNull(response);
Education edu = (Education) response.getEntity();
assertNotNull(edu);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updateEducation(ORCID, edu.getPutCode(), edu);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
response = serviceDelegator.viewEmployment(ORCID, 17L);
assertNotNull(response);
Employment emp = (Employment) response.getEntity();
assertNotNull(emp);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updateEmployment(ORCID, emp.getPutCode(), emp);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
response = serviceDelegator.viewExternalIdentifier(ORCID, 13L);
assertNotNull(response);
PersonExternalIdentifier extId = (PersonExternalIdentifier) response.getEntity();
assertNotNull(extId);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updateExternalIdentifier(ORCID, extId.getPutCode(), extId);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
response = serviceDelegator.viewFunding(ORCID, 10L);
assertNotNull(response);
Funding f = (Funding) response.getEntity();
assertNotNull(f);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updateFunding(ORCID, f.getPutCode(), f);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
response = serviceDelegator.viewKeyword(ORCID, 9L);
assertNotNull(response);
Keyword k = (Keyword) response.getEntity();
assertNotNull(k);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updateKeyword(ORCID, k.getPutCode(), k);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
response = serviceDelegator.viewOtherName(ORCID, 13L);
assertNotNull(response);
OtherName o = (OtherName) response.getEntity();
assertNotNull(o);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updateOtherName(ORCID, o.getPutCode(), o);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
response = serviceDelegator.viewPeerReview(ORCID, 9L);
assertNotNull(response);
PeerReview p = (PeerReview) response.getEntity();
assertNotNull(p);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updatePeerReview(ORCID, p.getPutCode(), p);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
response = serviceDelegator.viewResearcherUrl(ORCID, 13L);
assertNotNull(response);
ResearcherUrl r = (ResearcherUrl) response.getEntity();
assertNotNull(r);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updateResearcherUrl(ORCID, r.getPutCode(), r);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
response = serviceDelegator.viewWork(ORCID, 11L);
assertNotNull(response);
Work w = (Work) response.getEntity();
assertNotNull(w);
try {
SecurityContextTestUtils.setUpSecurityContextForClientOnly();
serviceDelegator.updateWork(ORCID, w.getPutCode(), w);
fail();
} catch (IllegalStateException e) {
assertEquals("Non client credential scope found in client request", e.getMessage());
}
}
use of org.orcid.jaxb.model.v3.dev1.record.PeerReview in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegator_PeerReviewsTest method testAddPeerReviewDuplicateFails.
@Test(expected = OrcidDuplicatedActivityException.class)
public void testAddPeerReviewDuplicateFails() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewPeerReview("4444-4444-4444-4447", 6L);
assertNotNull(response);
PeerReview peerReview = (PeerReview) response.getEntity();
assertNotNull(peerReview);
peerReview.setUrl(new Url("http://updated.com/url"));
peerReview.getSubjectName().getTitle().setContent("Updated Title");
// disambiguated org is required in API v3
DisambiguatedOrganization disambiguatedOrg = new DisambiguatedOrganization();
disambiguatedOrg.setDisambiguatedOrganizationIdentifier("some-org");
disambiguatedOrg.setDisambiguationSource("FUNDREF");
peerReview.getOrganization().setDisambiguatedOrganization(disambiguatedOrg);
peerReview.setPutCode(null);
response = serviceDelegator.createPeerReview("4444-4444-4444-4447", peerReview);
}
Aggregations