use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class WorksTest method createViewUpdateAndDeleteWork.
@Test
public void createViewUpdateAndDeleteWork() throws JSONException, InterruptedException, URISyntaxException {
changeDefaultUserVisibility(webDriver, org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
long time = System.currentTimeMillis();
Work workToCreate = (Work) unmarshallFromPath("/record_2.0_rc3/samples/work-2.0_rc3.xml", Work.class);
workToCreate.setPutCode(null);
workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId = new ExternalID();
wExtId.setValue("Work Id " + time);
wExtId.setType("agr");
wExtId.setRelationship(Relationship.SELF);
wExtId.setUrl(new Url("http://test.orcid.org/" + time));
workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV2ApiClient.createWorkXml(this.getUser1OrcidId(), workToCreate, 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_rc3/" + this.getUser1OrcidId() + "/work/\\d+"));
ClientResponse getResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Work gotWork = getResponse.getEntity(Work.class);
assertEquals("common:title", gotWork.getWorkTitle().getTitle().getContent());
assertEquals("work:citation-value", gotWork.getWorkCitation().getCitation());
assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotWork.getWorkCitation().getWorkCitationType());
gotWork.getWorkTitle().getTitle().setContent("updated title");
//Save the original visibility
Visibility originalVisibility = gotWork.getVisibility();
Visibility updatedVisibility = Visibility.PRIVATE.equals(originalVisibility) ? Visibility.LIMITED : Visibility.PRIVATE;
//Verify you cant update the visibility
gotWork.setVisibility(updatedVisibility);
ClientResponse putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
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
gotWork.setVisibility(originalVisibility);
putResponse = memberV2ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV2ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
assertEquals("updated title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
assertEquals("work:citation-value", gotAfterUpdateWork.getWorkCitation().getCitation());
assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotAfterUpdateWork.getWorkCitation().getWorkCitationType());
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class PublicAPISecurityManagerV2Test method getAddressesElement.
private Addresses getAddressesElement(Visibility... vs) {
Addresses elements = new Addresses();
for (Visibility v : vs) {
Address element = new Address();
element.setVisibility(v);
if (elements.getAddress() == null) {
elements.setAddress(new ArrayList<Address>());
}
elements.getAddress().add(element);
}
return elements;
}
use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class PublicAPISecurityManagerV2Test method getPersonElement.
private Person getPersonElement() {
Visibility[] vs = { Visibility.PUBLIC, Visibility.PUBLIC, Visibility.PUBLIC };
Person p = new Person();
p.setAddresses(getAddressesElement(vs));
p.setEmails(getEmailsElement(vs));
p.setExternalIdentifiers(getPersonExternalIdentifiersElement(vs));
p.setKeywords(getKeywordsElement(vs));
p.setOtherNames(getOtherNamesElement(vs));
p.setResearcherUrls(getResearcherUrlsElement(vs));
Name name = new Name();
name.setVisibility(Visibility.PUBLIC);
p.setName(name);
Biography b = new Biography();
b.setVisibility(Visibility.PUBLIC);
b.setContent("Biography test");
p.setBiography(b);
return p;
}
use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class PublicAPISecurityManagerV2Test method getEmployments.
private Employments getEmployments(Visibility... vs) {
Employments e = new Employments();
for (Visibility v : vs) {
EmploymentSummary s = new EmploymentSummary();
s.setVisibility(v);
e.getSummaries().add(s);
}
return e;
}
use of org.orcid.jaxb.model.common_rc3.Visibility in project ORCID-Source by ORCID.
the class PublicAPISecurityManagerV2Test method getEmailsElement.
private Emails getEmailsElement(Visibility... vs) {
Emails elements = new Emails();
for (Visibility v : vs) {
Email element = new Email();
element.setVisibility(v);
if (elements.getEmails() == null) {
elements.setEmails(new ArrayList<Email>());
}
elements.getEmails().add(element);
}
return elements;
}
Aggregations