use of org.hisp.dhis.jsonpatch.BulkPatchParameters in project dhis2-core by dhis2.
the class BulkPatchManagerTest method testApplyPatchInvalidClassName.
@Test
void testApplyPatchInvalidClassName() throws IOException {
final BulkJsonPatch bulkJsonPatch = loadPatch("bulk_sharing_patch_invalid_class_name.json", BulkJsonPatch.class);
BulkPatchParameters patchParameters = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = patchManager.applyPatch(bulkJsonPatch, patchParameters);
assertEquals(0, patchedObjects.size());
assertEquals(1, patchParameters.getErrorReportsCount());
assertEquals(1, patchParameters.getErrorReportsCount(ErrorCode.E6002));
}
use of org.hisp.dhis.jsonpatch.BulkPatchParameters in project dhis2-core by dhis2.
the class BulkPatchManagerTest method testApplyPatchInvalidUid.
@Test
void testApplyPatchInvalidUid() throws IOException {
final BulkJsonPatch bulkJsonPatch = loadPatch("bulk_sharing_patch_invalid_uid.json", BulkJsonPatch.class);
BulkPatchParameters patchParameters = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = patchManager.applyPatch(bulkJsonPatch, patchParameters);
assertEquals(1, patchedObjects.size());
assertEquals(1, patchParameters.getErrorReportsCount());
assertEquals(1, patchParameters.getErrorReportsCount(ErrorCode.E4014));
assertTrue(aclService.canRead(userA, patchedObjects.get(0)));
assertFalse(aclService.canRead(userC, patchedObjects.get(0)));
}
use of org.hisp.dhis.jsonpatch.BulkPatchParameters in project dhis2-core by dhis2.
the class AbstractCrudController method bulkSharing.
@ResponseBody
@PatchMapping(path = "/sharing", consumes = "application/json-patch+json", produces = APPLICATION_JSON_VALUE)
public WebMessage bulkSharing(@RequestParam(required = false, defaultValue = "false") boolean atomic, HttpServletRequest request) throws Exception {
final BulkJsonPatch bulkJsonPatch = jsonMapper.readValue(request.getInputStream(), BulkJsonPatch.class);
BulkPatchParameters patchParams = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = bulkPatchManager.applyPatch(bulkJsonPatch, patchParams);
if (patchedObjects.isEmpty() || (atomic && patchParams.hasErrorReports())) {
ImportReport importReport = new ImportReport();
importReport.addTypeReports(patchParams.getTypeReports());
importReport.setStatus(Status.ERROR);
return importReport(importReport);
}
Map<String, List<String>> parameterValuesMap = contextService.getParameterValuesMap();
MetadataImportParams params = importService.getParamsFromMap(parameterValuesMap);
params.setUser(currentUserService.getCurrentUser()).setImportStrategy(ImportStrategy.UPDATE).addObjects(patchedObjects);
ImportReport importReport = importService.importMetadata(params);
if (patchParams.hasErrorReports()) {
importReport.addTypeReports(patchParams.getTypeReports());
importReport.setStatus(importReport.getStatus() == Status.OK ? Status.WARNING : importReport.getStatus());
}
return importReport(importReport);
}
use of org.hisp.dhis.jsonpatch.BulkPatchParameters in project dhis2-core by dhis2.
the class BulkPatchManagerTest method testApplyPatchInvalidPath.
@Test
void testApplyPatchInvalidPath() throws IOException {
final BulkJsonPatch bulkJsonPatch = loadPatch("bulk_sharing_patch_invalid_path.json", BulkJsonPatch.class);
BulkPatchParameters patchParameters = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = patchManager.applyPatch(bulkJsonPatch, patchParameters);
assertEquals(0, patchedObjects.size());
assertEquals(1, patchParameters.getErrorReportsCount());
assertEquals(1, patchParameters.getErrorReportsCount(ErrorCode.E4032));
}
use of org.hisp.dhis.jsonpatch.BulkPatchParameters in project dhis2-core by dhis2.
the class BulkPatchManagerTest method testApplyPatchOk.
@Test
void testApplyPatchOk() throws IOException {
final BulkJsonPatch bulkJsonPatch = loadPatch("bulk_sharing_patch.json", BulkJsonPatch.class);
BulkPatchParameters patchParameters = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = patchManager.applyPatch(bulkJsonPatch, patchParameters);
assertEquals(2, patchedObjects.size());
assertTrue(aclService.canRead(userA, patchedObjects.get(0)));
assertTrue(aclService.canRead(userA, patchedObjects.get(1)));
assertFalse(aclService.canRead(userC, patchedObjects.get(0)));
}
Aggregations