use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorksTest method getWork.
private Work getWork(String title, boolean randomExtId, String extIdValue) {
Long time = System.currentTimeMillis();
Work work = new Work();
WorkTitle workTitle = new WorkTitle();
Title wTitle = new Title(title);
workTitle.setTranslatedTitle(new TranslatedTitle(title, "en"));
workTitle.setTitle(wTitle);
work.setWorkTitle(workTitle);
work.setWorkType(WorkType.BOOK);
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
if (randomExtId) {
extId.setValue("work-ext-id-" + (Math.random() * 1000) + "-" + time);
} else {
extId.setValue("work-ext-id-" + extIdValue);
}
extId.setType("doi");
ExternalIDs extIds = new ExternalIDs();
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
return work;
}
use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorksTest method testUpdateWorkWithProfileCreationTokenWhenClaimedAndNotSource.
@Test
public void testUpdateWorkWithProfileCreationTokenWhenClaimedAndNotSource() throws JSONException, InterruptedException, URISyntaxException {
long time = System.currentTimeMillis();
Work workToCreate = (Work) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/work-3.0_dev1.xml", Work.class);
workToCreate.setPutCode(null);
workToCreate.setSource(null);
workToCreate.setVisibility(Visibility.PUBLIC);
workToCreate.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId = new ExternalID();
wExtId.setValue("Work Id " + time);
wExtId.setType(WorkExternalIdentifierType.AGR.value());
wExtId.setRelationship(Relationship.SELF);
workToCreate.getExternalIdentifiers().getExternalIdentifier().add(wExtId);
String accessToken = getAccessToken();
ClientResponse postResponse = memberV3Dev1ApiClient.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(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/work/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getResponse.getStatus());
Work gotWork = getResponse.getEntity(Work.class);
assertEquals("common:title", gotWork.getWorkTitle().getTitle().getContent());
gotWork.getWorkTitle().getTitle().setContent("updated title");
String profileCreateToken = oauthHelper.getClientCredentialsAccessToken(this.getClient2ClientId(), this.getClient2ClientSecret(), ScopePathType.ORCID_PROFILE_CREATE);
ClientResponse putResponse = memberV3Dev1ApiClient.updateLocationXml(postResponse.getLocation(), profileCreateToken, gotWork);
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClient.viewLocationXml(postResponse.getLocation(), accessToken);
assertEquals(Response.Status.OK.getStatusCode(), getAfterUpdateResponse.getStatus());
Work gotAfterUpdateWork = getAfterUpdateResponse.getEntity(Work.class);
assertEquals("common:title", gotAfterUpdateWork.getWorkTitle().getTitle().getContent());
ClientResponse deleteResponse = memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorksTest method createViewUpdateAndDeleteWork.
@Test
public void createViewUpdateAndDeleteWork() throws JSONException, InterruptedException, URISyntaxException {
showMyOrcidPage();
changeDefaultUserVisibility(webDriver, org.orcid.jaxb.model.v3.dev1.common.Visibility.PUBLIC.name());
long time = System.currentTimeMillis();
Work workToCreate = (Work) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/work-3.0_dev1.xml", Work.class);
workToCreate.setPutCode(null);
workToCreate.setSource(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 = memberV3Dev1ApiClient.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(".*/v3.0_dev1/" + this.getUser1OrcidId() + "/work/\\d+"));
ClientResponse getResponse = memberV3Dev1ApiClient.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", 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 = memberV3Dev1ApiClient.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 = memberV3Dev1ApiClient.updateLocationXml(postResponse.getLocation(), accessToken, gotWork);
assertEquals(Response.Status.OK.getStatusCode(), putResponse.getStatus());
ClientResponse getAfterUpdateResponse = memberV3Dev1ApiClient.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", gotAfterUpdateWork.getWorkCitation().getCitation());
assertEquals(CitationType.FORMATTED_UNSPECIFIED, gotAfterUpdateWork.getWorkCitation().getWorkCitationType());
ClientResponse deleteResponse = memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), gotWork.getPutCode(), accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorksTest method testGroupingNormalized.
@Test
public void testGroupingNormalized() throws InterruptedException, JSONException {
long time = System.currentTimeMillis();
String accessTokenForClient1 = getAccessToken();
String accessTokenForClient2 = getAccessToken(getUser1OrcidId(), getUser1Password(), getScopes(ScopePathType.ACTIVITIES_UPDATE, ScopePathType.ACTIVITIES_READ_LIMITED), getClient2ClientId(), getClient2ClientSecret(), getClient2RedirectUri());
// should result in two groups
Work work1 = (Work) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/work-3.0_dev1.xml", Work.class);
work1.setPutCode(null);
work1.setSource(null);
work1.setVisibility(Visibility.PUBLIC);
work1.getExternalIdentifiers().getExternalIdentifier().clear();
org.orcid.jaxb.model.v3.dev1.record.WorkTitle title1 = new org.orcid.jaxb.model.v3.dev1.record.WorkTitle();
title1.setTitle(new Title("Work # 1" + time));
work1.setWorkTitle(title1);
ExternalID wExtId1 = new ExternalID();
wExtId1.setValue("VALUE" + 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);
Work work2 = (Work) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/work-3.0_dev1.xml", Work.class);
work2.setPutCode(null);
work2.setSource(null);
work2.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.v3.dev1.record.WorkTitle title2 = new org.orcid.jaxb.model.v3.dev1.record.WorkTitle();
title2.setTitle(new Title("Work # 2" + time));
work2.setWorkTitle(title2);
work2.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId2 = new ExternalID();
wExtId2.setValue("value" + time);
wExtId2.setType(WorkExternalIdentifierType.AGR.value());
wExtId2.setRelationship(Relationship.SELF);
wExtId2.setUrl(new Url("http://orcid.org/work#2"));
work2.getExternalIdentifiers().getExternalIdentifier().clear();
work2.getExternalIdentifiers().getExternalIdentifier().add(wExtId2);
Work work3 = (Work) unmarshallFromPath("/record_3.0_dev1/samples/read_samples/work-3.0_dev1.xml", Work.class);
work3.setPutCode(null);
work3.setSource(null);
work3.setVisibility(Visibility.PUBLIC);
org.orcid.jaxb.model.v3.dev1.record.WorkTitle title3 = new org.orcid.jaxb.model.v3.dev1.record.WorkTitle();
title3.setTitle(new Title("Work # 3" + time));
work3.setWorkTitle(title3);
work3.getExternalIdentifiers().getExternalIdentifier().clear();
ExternalID wExtId3 = new ExternalID();
wExtId3.setValue("OtherValue" + time);
wExtId3.setType(WorkExternalIdentifierType.AGR.value());
wExtId3.setRelationship(Relationship.SELF);
wExtId3.setUrl(new Url("http://orcid.org/work#3"));
work3.getExternalIdentifiers().getExternalIdentifier().clear();
work3.getExternalIdentifiers().getExternalIdentifier().add(wExtId3);
// Add the three works
ClientResponse postResponse = memberV3Dev1ApiClient.createWorkXml(this.getUser1OrcidId(), work1, accessTokenForClient1);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode1 = getPutCodeFromResponse(postResponse);
postResponse = memberV3Dev1ApiClient.createWorkXml(this.getUser1OrcidId(), work2, accessTokenForClient2);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode2 = getPutCodeFromResponse(postResponse);
postResponse = memberV3Dev1ApiClient.createWorkXml(this.getUser1OrcidId(), work3, accessTokenForClient2);
assertNotNull(postResponse);
assertEquals(Response.Status.CREATED.getStatusCode(), postResponse.getStatus());
Long putCode3 = getPutCodeFromResponse(postResponse);
ClientResponse activitiesResponse = memberV3Dev1ApiClient.viewActivities(this.getUser1OrcidId(), accessTokenForClient1);
assertEquals(Response.Status.OK.getStatusCode(), activitiesResponse.getStatus());
ActivitiesSummary activities = activitiesResponse.getEntity(ActivitiesSummary.class);
assertNotNull(activities);
assertFalse(activities.getWorks().getWorkGroup().isEmpty());
WorkGroup work1Group = null;
WorkGroup work2Group = null;
WorkGroup work3Group = null;
boolean work1found = false;
boolean work2found = false;
boolean work3found = false;
for (WorkGroup group : activities.getWorks().getWorkGroup()) {
for (ExternalID id : group.getIdentifiers().getExternalIdentifier()) {
// If it is the ID is the one we are looking for
if (id.getNormalized().getValue().equals("value" + time)) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 1" + time).equals(title)) {
work1found = true;
work1Group = group;
assertEquals(2, group.getActivities().size());
} else if (("Work # 2" + time).equals(title)) {
work2found = true;
work2Group = group;
assertEquals(2, group.getActivities().size());
} else
fail();
}
} else if (id.getNormalized().getValue().equals("othervalue" + time)) {
for (WorkSummary summary : group.getWorkSummary()) {
String title = summary.getTitle().getTitle().getContent();
if (("Work # 3" + time).equals(title)) {
work3found = true;
work3Group = group;
assertEquals(1, group.getActivities().size());
} else
fail();
}
}
}
}
assertTrue(work1found);
assertTrue(work2found);
assertTrue(work3found);
// Check that work # 1 and Work # 2 are in the same work
assertEquals(work1Group, work2Group);
// Check that work # 3 is not in the same group than group # 1
assertThat(work3Group, not(work1Group));
// Remove all created works
ClientResponse deleteResponse = memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode1, accessTokenForClient1);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode2, accessTokenForClient2);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), putCode3, accessTokenForClient2);
assertNotNull(deleteResponse);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.v3.dev1.record.Work in project ORCID-Source by ORCID.
the class WorksTest method testCreateBulkWithAllErrors.
@Test
public void testCreateBulkWithAllErrors() throws InterruptedException, JSONException {
String accessToken = getAccessToken();
WorkBulk bulk = createBulk(10, "existing-ext-id-" + System.currentTimeMillis());
ClientResponse postResponse = memberV3Dev1ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
bulk = postResponse.getEntity(WorkBulk.class);
assertNotNull(bulk);
assertNotNull(bulk.getBulk());
boolean first = true;
// All elements might be ok
for (BulkElement element : bulk.getBulk()) {
if (first) {
assertTrue(Work.class.isAssignableFrom(element.getClass()));
Work work = (Work) element;
// Remove the work
memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
first = false;
} else {
assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
OrcidError error = (OrcidError) element;
assertEquals(Integer.valueOf(9021), error.getErrorCode());
}
}
}
Aggregations