use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class MemberV2Test method testTokenWorksOnlyForTheScopeItWasIssued.
@SuppressWarnings({ "deprecation", "rawtypes" })
@Test
public void testTokenWorksOnlyForTheScopeItWasIssued() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
List<String> scopes = getScopes(ScopePathType.FUNDING_CREATE, ScopePathType.FUNDING_UPDATE);
String accessToken = getAccessToken(scopes);
Work work1 = (Work) unmarshallFromPath("/record_2.0_rc3/samples/work-2.0_rc3.xml", Work.class);
work1.setPutCode(null);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.record_rc3.WorkTitle title1 = new org.orcid.jaxb.model.record_rc3.WorkTitle();
title1.setTitle(new Title("Work # 1"));
work1.setWorkTitle(title1);
ExternalID wExtId1 = new ExternalID();
wExtId1.setValue("Work Id " + time);
wExtId1.setType(WorkExternalIdentifierType.AGR.value());
wExtId1.setRelationship(Relationship.SELF);
wExtId1.setUrl(new Url("http://orcid.org/work#1"));
work1.getExternalIdentifiers().getExternalIdentifier().clear();
work1.getExternalIdentifiers().getExternalIdentifier().add(wExtId1);
//Add the work
ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), postResponse.getStatus());
Funding funding = (Funding) unmarshallFromPath("/record_2.0_rc3/samples/funding-2.0_rc3.xml", Funding.class);
funding.setPutCode(null);
funding.setVisibility(Visibility.PUBLIC);
funding.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID fExtId = new ExternalID();
fExtId.setType(FundingExternalIdentifierType.GRANT_NUMBER.value());
fExtId.setValue("Funding Id " + time);
fExtId.setRelationship(Relationship.SELF);
funding.getExternalIdentifiers().getExternalIdentifier().add(fExtId);
//Add the funding
postResponse = memberV2ApiClient.createFundingXml(this.getUser1OrcidId(), funding, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
// Delete funding
Map map = postResponse.getMetadata();
assertNotNull(map);
assertTrue(map.containsKey("Location"));
List resultWithPutCode = (List) map.get("Location");
String location = resultWithPutCode.get(0).toString();
Long putCode = Long.valueOf(location.substring(location.lastIndexOf('/') + 1));
ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), putCode, accessToken);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class MemberV2Test method testAddPeerReviewWithInvalidGroupingId.
@Test
public void testAddPeerReviewWithInvalidGroupingId() throws JSONException, InterruptedException, URISyntaxException {
PeerReview peerReview = (PeerReview) unmarshallFromPath("/record_2.0_rc4/samples/peer-review-2.0_rc4.xml", PeerReview.class);
peerReview.setPutCode(null);
peerReview.setGroupId("Invalid group id " + System.currentTimeMillis());
peerReview.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID pExtId = new ExternalID();
pExtId.setValue("Work Id " + System.currentTimeMillis());
pExtId.setType(WorkExternalIdentifierType.AGR.value());
pExtId.setRelationship(Relationship.SELF);
peerReview.getExternalIdentifiers().getExternalIdentifier().add(pExtId);
String accessToken = getAccessToken();
//Pattern not valid
ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
//Null group id
peerReview.setGroupId(null);
postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
//Empty group id
peerReview.setGroupId("");
postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
//Invalid group id
peerReview.setGroupId("orcid-generated:" + peerReview.getGroupId());
postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReview, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), postResponse.getStatus());
}
use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class PublicV2ApiServiceDelegatorImpl method viewWork.
@Override
public Response viewWork(String orcid, Long putCode) {
long lastModifiedTime = getLastModifiedTime(orcid);
Work w = workManagerReadOnly.getWork(orcid, putCode, lastModifiedTime);
publicAPISecurityManagerV2.checkIsPublic(w);
ActivityUtils.cleanEmptyFields(w);
ActivityUtils.setPathToActivity(w, orcid);
sourceUtilsReadOnly.setSourceName(w);
contributorUtilsReadOnly.filterContributorPrivateData(w);
return Response.ok(w).build();
}
use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testUpdateWorkLeavingVisibilityNullTest.
@Test
public void testUpdateWorkLeavingVisibilityNullTest() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewWork("4444-4444-4444-4447", 10L);
assertNotNull(response);
Work work = (Work) response.getEntity();
assertNotNull(work);
assertEquals(Visibility.PUBLIC, work.getVisibility());
work.setVisibility(null);
response = serviceDelegator.updateWork("4444-4444-4444-4447", 10L, work);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
work = (Work) response.getEntity();
assertNotNull(work);
Utils.verifyLastModified(work.getLastModifiedDate());
assertEquals(Visibility.PUBLIC, work.getVisibility());
}
use of org.orcid.jaxb.model.record_rc4.Work in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testDeleteWork.
@Test(expected = NoResultException.class)
public void testDeleteWork() {
SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4447", ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
Response response = serviceDelegator.viewWork("4444-4444-4444-4447", 9L);
assertNotNull(response);
Work work = (Work) response.getEntity();
assertNotNull(work);
response = serviceDelegator.deleteWork("4444-4444-4444-4447", 9L);
assertNotNull(response);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
serviceDelegator.viewWork("4444-4444-4444-4447", 9L);
}
Aggregations