use of org.orcid.jaxb.model.record_v2.WorkBulk 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 = 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());
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
memberV2ApiClient.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());
}
}
}
use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.
the class WorksTest method createBulk.
private WorkBulk createBulk(int size, String extId) {
WorkBulk bulk = new WorkBulk();
Long time = System.currentTimeMillis();
for (int i = 0; i < size; i++) {
if (extId == null) {
bulk.getBulk().add(getWork("Work title #" + i + "-" + time, true, null));
} else {
bulk.getBulk().add(getWork("Work title #" + i + "-" + time, false, String.valueOf(time)));
}
}
return bulk;
}
use of org.orcid.jaxb.model.record_v2.WorkBulk 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 = 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());
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
memberV2ApiClient.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());
}
}
}
use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.
the class PublicV2ApiServiceVersionedDelegatorTest method testViewBulkWorks.
@Test
public void testViewBulkWorks() {
Response response = serviceDelegator.viewBulkWorks("0000-0000-0000-0003", "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 OrcidError);
assertTrue(workBulk.getBulk().get(2) instanceof OrcidError);
assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
use of org.orcid.jaxb.model.record_v2.WorkBulk in project ORCID-Source by ORCID.
the class OrcidSecurityManagerImpl method checkAndFilter.
@Override
public void checkAndFilter(String orcid, WorkBulk workBulk, ScopePathType scopePathType) {
isMyToken(orcid);
List<BulkElement> bulkElements = workBulk.getBulk();
List<BulkElement> filteredElements = new ArrayList<>();
for (int i = 0; i < bulkElements.size(); i++) {
BulkElement element = bulkElements.get(i);
if (element instanceof OrcidError) {
filteredElements.add(element);
continue;
}
try {
checkAndFilter(orcid, (Work) element, scopePathType, true);
filteredElements.add(element);
} catch (Exception e) {
if (e instanceof OrcidUnauthorizedException) {
throw e;
}
OrcidError error = orcidCoreExceptionMapper.getOrcidError(e);
filteredElements.add(error);
}
}
workBulk.setBulk(filteredElements);
}
Aggregations