use of org.orcid.jaxb.model.v3.dev1.error.OrcidError 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.getV3OrcidError(e);
filteredElements.add(error);
}
}
workBulk.setBulk(filteredElements);
}
use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class WorkManagerTest method testFindWorkBulkInvalidPutCodes.
@Test
public void testFindWorkBulkInvalidPutCodes() {
String putCodes = "11,12,13,invalid";
WorkBulk workBulk = workManager.findWorkBulk("0000-0000-0000-0003", putCodes);
assertNotNull(workBulk);
assertNotNull(workBulk.getBulk());
assertEquals(4, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof Work);
assertTrue(workBulk.getBulk().get(2) instanceof Work);
assertTrue(workBulk.getBulk().get(3) instanceof OrcidError);
}
use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class OrcidSecurityManager_WorkBulkTest method testLimitedWorkBulkReadPublicTokenMixedSources.
@Test
public void testLimitedWorkBulkReadPublicTokenMixedSources() {
WorkBulk workBulk = new WorkBulk();
workBulk.setBulk(Arrays.asList(createWork(Visibility.PUBLIC, CLIENT_1), createWork(Visibility.LIMITED, CLIENT_2)));
SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.READ_PUBLIC);
orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
assertNotNull(workBulk);
assertEquals(2, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof Work);
assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
}
use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class OrcidSecurityManager_WorkBulkTest method testLimitedWorkBulkReadPublicTokenNoSource.
@Test
public void testLimitedWorkBulkReadPublicTokenNoSource() {
WorkBulk workBulk = new WorkBulk();
workBulk.setBulk(Arrays.asList(createWork(Visibility.LIMITED, null), createWork(Visibility.LIMITED, null)));
SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_2, ScopePathType.READ_PUBLIC);
orcidSecurityManager.checkAndFilter(ORCID_1, workBulk, ScopePathType.ORCID_WORKS_READ_LIMITED);
assertNotNull(workBulk);
assertEquals(2, workBulk.getBulk().size());
assertTrue(workBulk.getBulk().get(0) instanceof OrcidError);
assertTrue(workBulk.getBulk().get(1) instanceof OrcidError);
}
use of org.orcid.jaxb.model.v3.dev1.error.OrcidError in project ORCID-Source by ORCID.
the class MemberV3ApiServiceDelegatorImpl method createWorks.
@Override
public Response createWorks(String orcid, WorkBulk works) {
orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.ORCID_WORKS_CREATE, ScopePathType.ORCID_WORKS_UPDATE);
if (works != null) {
for (int i = 0; i < works.getBulk().size(); i++) {
if (Work.class.isAssignableFrom(works.getBulk().get(i).getClass())) {
Work work = (Work) works.getBulk().get(i);
try {
schemaValidator.validate(work);
clearSource(work);
} catch (WebApplicationException e) {
OrcidError error = orcidCoreExceptionMapper.getOrcidErrorV3Dev1(9001, 400, e);
works.getBulk().remove(i);
works.getBulk().add(i, error);
}
}
}
}
works = workManager.createWorks(orcid, works);
sourceUtils.setSourceName(works);
return Response.ok(works).build();
}
Aggregations