use of org.hisp.dhis.jsonpatch.BulkPatchParameters in project dhis2-core by dhis2.
the class BulkPatchManagerTest method testApplyPatchesOk.
@Test
void testApplyPatchesOk() throws IOException {
final BulkJsonPatches bulkJsonPatch = loadPatch("bulk_sharing_patches.json", BulkJsonPatches.class);
BulkPatchParameters patchParameters = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = patchManager.applyPatches(bulkJsonPatch, patchParameters);
assertEquals(3, patchedObjects.size());
assertFalse(aclService.canRead(userA, dataSetA));
assertFalse(aclService.canRead(userB, dataSetA));
IdentifiableObject patchedDataElementA = patchedObjects.stream().filter(de -> de.getUid().equals(dataElementA.getUid())).findFirst().get();
IdentifiableObject patchedDataElementB = patchedObjects.stream().filter(de -> de.getUid().equals(dataElementB.getUid())).findFirst().get();
IdentifiableObject patchedDataSetA = patchedObjects.stream().filter(de -> de.getUid().equals(dataSetA.getUid())).findFirst().get();
assertTrue(aclService.canRead(userA, patchedDataElementA));
assertTrue(aclService.canRead(userB, patchedDataElementB));
assertTrue(aclService.canRead(userA, patchedDataSetA));
assertTrue(aclService.canRead(userB, patchedDataSetA));
assertFalse(aclService.canRead(userC, patchedDataElementA));
assertFalse(aclService.canRead(userC, patchedDataSetA));
}
use of org.hisp.dhis.jsonpatch.BulkPatchParameters in project dhis2-core by dhis2.
the class BulkPatchManagerTest method testApplyPatchNotShareableSchema.
@Test
void testApplyPatchNotShareableSchema() throws IOException {
final BulkJsonPatch bulkJsonPatch = loadPatch("bulk_sharing_patch_not_shareable.json", BulkJsonPatch.class);
BulkPatchParameters patchParameters = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = patchManager.applyPatch(bulkJsonPatch, patchParameters);
assertEquals(0, patchedObjects.size());
assertEquals(2, patchParameters.getErrorReportsCount());
assertEquals(1, patchParameters.getErrorReportsCount(ErrorCode.E3019));
assertEquals(1, patchParameters.getErrorReportsCount(ErrorCode.E4014));
}
use of org.hisp.dhis.jsonpatch.BulkPatchParameters in project dhis2-core by dhis2.
the class MetadataImportExportController method bulkSharing.
@ResponseBody
@PatchMapping(value = "sharing", consumes = "application/json-patch+json", produces = APPLICATION_JSON_VALUE)
public WebMessage bulkSharing(@RequestParam(required = false, defaultValue = "false") boolean atomic, HttpServletRequest request) throws IOException {
final BulkJsonPatches bulkJsonPatches = jsonMapper.readValue(request.getInputStream(), BulkJsonPatches.class);
BulkPatchParameters patchParams = BulkPatchParameters.builder().validators(BulkPatchValidatorFactory.SHARING).build();
List<IdentifiableObject> patchedObjects = bulkPatchManager.applyPatches(bulkJsonPatches, 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 importParams = metadataImportService.getParamsFromMap(parameterValuesMap);
importParams.setUser(currentUserService.getCurrentUser()).setImportStrategy(ImportStrategy.UPDATE).setAtomicMode(atomic ? AtomicMode.ALL : AtomicMode.NONE).addObjects(patchedObjects);
ImportReport importReport = metadataImportService.importMetadata(importParams);
if (patchParams.hasErrorReports()) {
importReport.addTypeReports(patchParams.getTypeReports());
importReport.setStatus(importReport.getStatus() == Status.OK ? Status.WARNING : importReport.getStatus());
}
return importReport(importReport);
}
Aggregations