use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.
the class WorksTest method testCreateBulkWork.
@Test
public void testCreateBulkWork() throws InterruptedException, JSONException {
String accessToken = getAccessToken();
WorkBulk bulk = createBulk(10, null);
ClientResponse postResponse = memberV2ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
bulk = postResponse.getEntity(WorkBulk.class);
assertNotNull(bulk);
assertNotNull(bulk.getBulk());
//All elements might be ok
for (BulkElement element : bulk.getBulk()) {
assertTrue(Work.class.isAssignableFrom(element.getClass()));
Work work = (Work) element;
//Remove the work
memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
}
}
use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.
the class WorksTest method testThreeWithInvalidTypeAllOthersAreFine.
@Test
public void testThreeWithInvalidTypeAllOthersAreFine() throws InterruptedException, JSONException {
String accessToken = getAccessToken();
WorkBulk bulk = createBulk(10, null);
//Work 3: no type
Work work3 = (Work) bulk.getBulk().get(3);
work3.setWorkType(null);
bulk.getBulk().set(3, work3);
//Work 5: empty title
Work work5 = (Work) bulk.getBulk().get(5);
work5.getWorkTitle().getTitle().setContent(null);
bulk.getBulk().set(5, work5);
//Work 7: translated title language code empty
Work work7 = (Work) bulk.getBulk().get(7);
work7.getWorkTitle().getTranslatedTitle().setLanguageCode(null);
bulk.getBulk().set(7, work7);
ClientResponse postResponse = memberV2ApiClient.createWorksJson(this.getUser1OrcidId(), bulk, accessToken);
assertNotNull(postResponse);
assertEquals(Response.Status.OK.getStatusCode(), postResponse.getStatus());
bulk = postResponse.getEntity(WorkBulk.class);
assertNotNull(bulk);
assertNotNull(bulk.getBulk());
for (int i = 0; i < bulk.getBulk().size(); i++) {
BulkElement element = bulk.getBulk().get(i);
if (i == 3 || i == 5 || i == 7) {
assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
OrcidError error = (OrcidError) element;
switch(i) {
case 3:
assertEquals(Integer.valueOf(9037), error.getErrorCode());
assertTrue(error.getDeveloperMessage().startsWith("Invalid work type"));
break;
case 5:
assertEquals(Integer.valueOf(9022), error.getErrorCode());
break;
case 7:
assertEquals(Integer.valueOf(9037), error.getErrorCode());
assertTrue(error.getDeveloperMessage().startsWith("Invalid translated title"));
break;
}
} else {
assertTrue(Work.class.isAssignableFrom(element.getClass()));
Work work = (Work) element;
assertNotNull(work.getPutCode());
memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
}
}
}
use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.
the class PublicV2ApiServiceDelegatorImpl method viewBulkWorks.
@Override
public Response viewBulkWorks(String orcid, String putCodes) {
ProfileEntity profileEntity = profileEntityManagerReadOnly.findByOrcid(orcid);
if (profileEntity == null) {
throw new OrcidNoResultException("No such profile: " + orcid);
}
WorkBulk workBulk = workManagerReadOnly.findWorkBulk(orcid, putCodes, profileEntity.getLastModified().getTime());
publicAPISecurityManagerV2.filter(workBulk);
ActivityUtils.cleanEmptyFields(workBulk);
sourceUtils.setSourceName(workBulk);
return Response.ok(workBulk).build();
}
use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testCreateWorksWithBulkAllOK.
@Test
public void testCreateWorksWithBulkAllOK() {
Long time = System.currentTimeMillis();
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED, ScopePathType.ACTIVITIES_UPDATE);
WorkBulk bulk = new WorkBulk();
for (int i = 0; i < 5; i++) {
Work work = new Work();
WorkTitle title = new WorkTitle();
title.setTitle(new Title("Bulk work " + i + " " + time));
work.setWorkTitle(title);
ExternalIDs extIds = new ExternalIDs();
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
extId.setType("doi");
extId.setUrl(new Url("http://doi/" + i + "/" + time));
extId.setValue("doi-" + i + "-" + time);
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
work.setWorkType(WorkType.BOOK);
bulk.getBulk().add(work);
}
Response response = serviceDelegator.createWorks(ORCID, bulk);
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
bulk = (WorkBulk) response.getEntity();
assertNotNull(bulk);
assertEquals(5, bulk.getBulk().size());
for (int i = 0; i < 5; i++) {
assertTrue(Work.class.isAssignableFrom(bulk.getBulk().get(i).getClass()));
Work w = (Work) bulk.getBulk().get(i);
Utils.verifyLastModified(w.getLastModifiedDate());
assertNotNull(w.getPutCode());
assertTrue(0L < w.getPutCode());
assertEquals("Bulk work " + i + " " + time, w.getWorkTitle().getTitle().getContent());
assertNotNull(w.getExternalIdentifiers().getExternalIdentifier());
assertEquals("doi-" + i + "-" + time, w.getExternalIdentifiers().getExternalIdentifier().get(0).getValue());
Response r = serviceDelegator.viewWork(ORCID, w.getPutCode());
assertNotNull(r);
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
assertEquals("Bulk work " + i + " " + time, ((Work) r.getEntity()).getWorkTitle().getTitle().getContent());
// Delete the work
r = serviceDelegator.deleteWork(ORCID, w.getPutCode());
assertNotNull(r);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), r.getStatus());
}
}
use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegator_WorksTest method testViewBulkWorks.
@Test
public void testViewBulkWorks() {
SecurityContextTestUtils.setUpSecurityContext(ORCID, ScopePathType.READ_LIMITED);
Response response = serviceDelegator.viewBulkWorks(ORCID, "11,12,13,16");
WorkBulk workBulk = (WorkBulk) response.getEntity();
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(4, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof Work);
// private work but matching source
assertTrue(workBulk.getBulk().get(2) instanceof Work);
// private work not matching source
assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
Aggregations