use of org.orcid.jaxb.model.record.bulk.BulkElement in project ORCID-Source by ORCID.
the class PublicAPISecurityManagerV2Impl method filter.
@Override
public void filter(WorkBulk workBulk) {
if (workBulk != null && workBulk.getBulk() != null) {
List<BulkElement> filtered = new ArrayList<>();
for (int i = 0; i < workBulk.getBulk().size(); i++) {
BulkElement bulkElement = workBulk.getBulk().get(i);
if (bulkElement instanceof OrcidError) {
filtered.add(bulkElement);
} else {
try {
checkIsPublic((Work) bulkElement);
filtered.add(bulkElement);
} catch (OrcidNonPublicElementException e) {
filtered.add(orcidCoreExceptionMapper.getOrcidError(e));
}
}
}
workBulk.setBulk(filtered);
}
}
use of org.orcid.jaxb.model.record.bulk.BulkElement in project ORCID-Source by ORCID.
the class WorkManagerTest method testCreateWorksWithBulkAllErrors.
@Test
public void testCreateWorksWithBulkAllErrors() {
String orcid = "0000-0000-0000-0003";
when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
// Set up data:
// Create one work with a DOI doi-1 so we can create a duplicate
Work work = new Work();
WorkTitle workTitle = new WorkTitle();
workTitle.setTitle(new Title("work #1"));
work.setWorkTitle(workTitle);
ExternalIDs extIds = new ExternalIDs();
ExternalID extId = new ExternalID();
extId.setRelationship(Relationship.SELF);
extId.setType("doi");
extId.setUrl(new Url("http://doi/1"));
extId.setValue("doi-1");
extIds.getExternalIdentifier().add(extId);
work.setWorkExternalIdentifiers(extIds);
work.setWorkType(WorkType.BOOK);
Work newWork = workManager.createWork(orcid, work, true);
Long putCode = newWork.getPutCode();
WorkBulk bulk = new WorkBulk();
// Work # 1: No ext ids
Work work1 = getWork("work # 1 " + System.currentTimeMillis());
work1.getExternalIdentifiers().getExternalIdentifier().clear();
// Work # 2: No title
Work work2 = getWork("work # 2 " + System.currentTimeMillis());
work2.getWorkTitle().getTitle().setContent(null);
// Work # 3: No work type
Work work3 = getWork("work # 3 " + System.currentTimeMillis());
work3.setWorkType(null);
// Work # 4: Ext id already exists
Work work4 = getWork("work # 4 " + System.currentTimeMillis());
work4.getExternalIdentifiers().getExternalIdentifier().add(extId);
bulk.getBulk().add(work1);
bulk.getBulk().add(work2);
bulk.getBulk().add(work3);
bulk.getBulk().add(work4);
bulk = workManager.createWorks(orcid, bulk);
assertNotNull(bulk);
assertEquals(4, bulk.getBulk().size());
for (int i = 0; i < bulk.getBulk().size(); i++) {
BulkElement element = bulk.getBulk().get(i);
assertTrue(OrcidError.class.isAssignableFrom(element.getClass()));
OrcidError error = (OrcidError) element;
switch(i) {
case 0:
assertEquals(Integer.valueOf(9023), error.getErrorCode());
break;
case 1:
assertEquals(Integer.valueOf(9022), error.getErrorCode());
break;
case 2:
assertEquals(Integer.valueOf(9037), error.getErrorCode());
break;
case 3:
assertEquals(Integer.valueOf(9021), error.getErrorCode());
break;
}
}
// Delete the work
assertTrue(workManager.checkSourceAndRemoveWork(orcid, putCode));
}
use of org.orcid.jaxb.model.record.bulk.BulkElement 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 = memberV2_1ApiClient.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(9001), error.getErrorCode());
assertTrue(error.getDeveloperMessage().endsWith("\"http://www.orcid.org/ns/work\":type}' is expected.)"));
break;
case 5:
assertEquals(Integer.valueOf(9001), error.getErrorCode());
assertTrue(error.getDeveloperMessage().contains("Object must have some value in its @XmlValue field: org.orcid.jaxb.model.common_v2.Title"));
break;
case 7:
assertEquals(Integer.valueOf(9001), error.getErrorCode());
assertTrue(error.getDeveloperMessage().endsWith("Attribute 'language-code' must appear on element 'common:translated-title'.)"));
break;
}
} else {
assertTrue(Work.class.isAssignableFrom(element.getClass()));
Work work = (Work) element;
assertNotNull(work.getPutCode());
memberV2_1ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
}
}
}
use of org.orcid.jaxb.model.record.bulk.BulkElement 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 = 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());
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(9001), error.getErrorCode());
assertTrue(error.getDeveloperMessage().endsWith("\"http://www.orcid.org/ns/work\":type}' is expected.)"));
break;
case 5:
assertEquals(Integer.valueOf(9001), error.getErrorCode());
assertTrue(error.getDeveloperMessage().contains("Object must have some value in its @XmlValue field: org.orcid.jaxb.model.v3.dev1.common.Title"));
break;
case 7:
assertEquals(Integer.valueOf(9001), error.getErrorCode());
assertTrue(error.getDeveloperMessage().endsWith("Attribute 'language-code' must appear on element 'common:translated-title'.)"));
break;
}
} else {
assertTrue(Work.class.isAssignableFrom(element.getClass()));
Work work = (Work) element;
assertNotNull(work.getPutCode());
memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
}
}
}
use of org.orcid.jaxb.model.record.bulk.BulkElement 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 = 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());
// All elements might be ok
for (BulkElement element : bulk.getBulk()) {
assertTrue(Work.class.isAssignableFrom(element.getClass()));
Work work = (Work) element;
// Remove the work
memberV3Dev1ApiClient.deleteWorkXml(this.getUser1OrcidId(), work.getPutCode(), accessToken);
}
}
Aggregations