use of org.orcid.jaxb.model.error_rc1.OrcidError in project ORCID-Source by ORCID.
the class PublicV2Test method checkLimitedEmployment.
public void checkLimitedEmployment(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
Employment employmentToCreate = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
employmentToCreate.setPutCode(null);
employmentToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(getUser1OrcidId(), employmentToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String path = postResponse.getLocation().getPath();
String putCode = path.substring(path.lastIndexOf('/') + 1, path.length());
ClientResponse response = publicV2ApiClient.viewEmploymentXml(getUser1OrcidId(), putCode);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
OrcidError result = response.getEntity(OrcidError.class);
assertNotNull(result);
assertEquals(new Integer(9039), result.getErrorCode());
assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
response = publicV2ApiClient.viewEmploymentSummaryXml(getUser1OrcidId(), putCode);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
result = response.getEntity(OrcidError.class);
assertNotNull(result);
assertEquals(new Integer(9039), result.getErrorCode());
assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
}
use of org.orcid.jaxb.model.error_rc1.OrcidError in project ORCID-Source by ORCID.
the class PublicV2Test method checkLimitedWork.
public void checkLimitedWork(String readPublicToken) throws JSONException, InterruptedException, URISyntaxException {
changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.LIMITED);
Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
workToCreate.setPutCode(null);
workToCreate.setVisibility(org.orcid.jaxb.model.common_rc1.Visibility.LIMITED);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createWorkXml(getUser1OrcidId(), workToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String path = postResponse.getLocation().getPath();
String putCode = path.substring(path.lastIndexOf('/') + 1, path.length());
ClientResponse response = null;
if (readPublicToken != null) {
response = publicV2ApiClient.viewWorkXml(getUser1OrcidId(), putCode, readPublicToken);
} else {
response = publicV2ApiClient.viewWorkXml(getUser1OrcidId(), putCode);
}
assertNotNull(response);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
OrcidError result = response.getEntity(OrcidError.class);
assertNotNull(result);
assertEquals(new Integer(9039), result.getErrorCode());
assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
response = null;
if (readPublicToken != null) {
response = publicV2ApiClient.viewWorkSummaryXml(getUser1OrcidId(), putCode, readPublicToken);
} else {
response = publicV2ApiClient.viewWorkSummaryXml(getUser1OrcidId(), putCode);
}
assertNotNull(response);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus());
result = response.getEntity(OrcidError.class);
assertNotNull(result);
assertEquals(new Integer(9039), result.getErrorCode());
assertEquals("403 Forbidden: The item is not public and cannot be accessed with the Public API.", result.getDeveloperMessage());
}
use of org.orcid.jaxb.model.error_rc1.OrcidError in project ORCID-Source by ORCID.
the class VerifyOrcidBeforeFetchElementTest method testEmployment.
@Test
public void testEmployment() throws InterruptedException, JSONException, URISyntaxException {
Employment employment = (Employment) unmarshallFromPath("/record_2.0_rc1/samples/employment-2.0_rc1.xml", Employment.class);
employment.setPutCode(null);
employment.setVisibility(Visibility.PUBLIC);
String user1AccessToken = getAccessToken();
// Create an employment
ClientResponse postResponse = memberV2ApiClient.createEmploymentXml(getUser1OrcidId(), employment, user1AccessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc1/" + getUser1OrcidId() + "/employment/\\d+"));
// Fetch it with the owner
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), user1AccessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Employment gotEmployment = getResponse.getEntity(Employment.class);
assertEquals("affiliation:department-name", gotEmployment.getDepartmentName());
assertEquals("affiliation:role-title", gotEmployment.getRoleTitle());
// Try to fetch it with other user orcid
// Using the members API
String user2AccessToken = getAccessToken(getUser2OrcidId(), getUser2Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE), getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
ClientResponse user2GetResponse = memberV2ApiClient.viewEmploymentXml(getUser2OrcidId(), gotEmployment.getPutCode(), user2AccessToken);
assertNotNull(user2GetResponse);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
OrcidError error = user2GetResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9016), error.getErrorCode());
// Using the public API
user2GetResponse = publicV2ApiClient.viewEmploymentXml(getUser2OrcidId(), String.valueOf(gotEmployment.getPutCode()));
assertNotNull(user2GetResponse);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
error = user2GetResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9016), error.getErrorCode());
// Delete it
ClientResponse deletedResponse = memberV2ApiClient.deleteEducationXml(getUser1OrcidId(), gotEmployment.getPutCode(), user1AccessToken);
assertNotNull(deletedResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deletedResponse.getStatus());
}
use of org.orcid.jaxb.model.error_rc1.OrcidError in project ORCID-Source by ORCID.
the class VerifyOrcidBeforeFetchElementTest method testWork.
@Test
public void testWork() throws InterruptedException, JSONException, URISyntaxException {
long time = System.currentTimeMillis();
Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc1/samples/work-2.0_rc1.xml", Work.class);
workToCreate.setPutCode(null);
workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
WorkExternalIdentifier wExtId = new WorkExternalIdentifier();
wExtId.setWorkExternalIdentifierId(new WorkExternalIdentifierId("Work Id " + time));
wExtId.setWorkExternalIdentifierType(WorkExternalIdentifierType.AGR);
wExtId.setRelationship(Relationship.PART_OF);
workToCreate.getExternalIdentifiers().getWorkExternalIdentifier().add(wExtId);
String user1AccessToken = getAccessToken();
// Create a work
ClientResponse postResponse = memberV2ApiClient.createWorkXml(getUser1OrcidId(), workToCreate, user1AccessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc1/" + getUser1OrcidId() + "/work/\\d+"));
// Fetch it with the owner
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), user1AccessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Work gotWork = getResponse.getEntity(Work.class);
assertEquals("Current treatment of left main coronary artery disease", gotWork.getWorkTitle().getTitle().getContent());
String user2AccessToken = getAccessToken(getUser2OrcidId(), getUser2Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE), getClient1ClientId(), getClient1ClientSecret(), getClient1RedirectUri());
// Try to fetch it with other user orcid
// Using the members API
ClientResponse user2GetResponse = memberV2ApiClient.viewWorkXml(getUser2OrcidId(), gotWork.getPutCode(), user2AccessToken);
assertNotNull(user2GetResponse);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
OrcidError error = user2GetResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9016), error.getErrorCode());
// Using the public API
user2GetResponse = publicV2ApiClient.viewWorkXml(getUser2OrcidId(), String.valueOf(gotWork.getPutCode()));
assertNotNull(user2GetResponse);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), user2GetResponse.getStatus());
error = user2GetResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9016), error.getErrorCode());
// Delete it
ClientResponse deletedResponse = memberV2ApiClient.deleteWorkXml(getUser1OrcidId(), gotWork.getPutCode(), user1AccessToken);
assertNotNull(deletedResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deletedResponse.getStatus());
}
use of org.orcid.jaxb.model.error_rc1.OrcidError in project ORCID-Source by ORCID.
the class MemberV2Test method createViewUpdateAndDeletePeerReview.
@Test
public void createViewUpdateAndDeletePeerReview() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
PeerReview peerReviewToCreate = (PeerReview) unmarshallFromPath("/record_2.0_rc2/samples/peer-review-2.0_rc2.xml", PeerReview.class);
peerReviewToCreate.setPutCode(null);
peerReviewToCreate.setGroupId(groupRecords.get(0).getGroupId());
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId = new ExternalID();
wExtId.setValue("Work Id " + time);
wExtId.setType(WorkExternalIdentifierType.AGR.value());
wExtId.setRelationship(Relationship.SELF);
peerReviewToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createPeerReviewXml(this.getUser1OrcidId(), peerReviewToCreate, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
String locationPath = postResponse.getLocation().getPath();
assertTrue("Location header path should match pattern, but was " + locationPath, locationPath.matches(".*/v2.0_rc2/" + this.getUser1OrcidId() + "/peer-review/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
PeerReview gotPeerReview = getResponse.getEntity(PeerReview.class);
assertEquals("peer-review:url", gotPeerReview.getUrl().getValue());
assertEquals("peer-review:subject-name", gotPeerReview.getSubjectName().getTitle().getContent());
assertEquals(groupRecords.get(0).getGroupId(), gotPeerReview.getGroupId());
//Save the original visibility
Visibility originalVisibility = gotPeerReview.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
//Verify you cant update the visibility
gotPeerReview.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
OrcidError error = putResponse.getEntity(OrcidError.class);
assertNotNull(error);
assertEquals(Integer.valueOf(9035), error.getErrorCode());
//Set the visibility again to the initial one
gotPeerReview.setVisibility(originalVisibility);
gotPeerReview.getSubjectName().getTitle().setContent("updated title");
putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotPeerReview);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
PeerReview gotAfterUpdateWork = getAfterUpdateResponse.getEntity(PeerReview.class);
assertEquals("updated title", gotAfterUpdateWork.getSubjectName().getTitle().getContent());
assertEquals(groupRecords.get(0).getGroupId(), gotAfterUpdateWork.getGroupId());
ClientResponse deleteResponse = memberV2ApiClient.deletePeerReviewXml(this.getUser1OrcidId(), gotAfterUpdateWork.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Aggregations