use of org.hisp.dhis.jsonpatch.validator.BulkPatchValidateParams in project dhis2-core by dhis2.
the class BulkPatchValidatorService method checkPatchObject.
/**
* Validate given ID and {@link JsonPatch} by using
* {@link org.hisp.dhis.jsonpatch.validator.BulkPatchValidator} from given
* {@link BulkPatchParameters}.
* <p>
* The valid {@link IdentifiableObject} and {@link JsonPatch} will be added
* to given {@link PatchBundle}
*
* @return {@link ObjectReport} contains {@link ErrorReport} if any.
*/
private ObjectReport checkPatchObject(Schema schema, String id, JsonPatch jsonPatch, BulkPatchParameters patchParams, PatchBundle bundle) {
ObjectReport objectReport = new ObjectReport(schema.getKlass(), 0, id);
IdentifiableObject entity = manager.get((Class<? extends IdentifiableObject>) schema.getKlass(), id);
BulkPatchValidateParams bulkPatchValidateParams = BulkPatchValidateParams.builder().schema(schema).jsonPatch(jsonPatch).id(id).entity(entity).build();
patchParams.getValidators().forEach(validator -> validator.validate(bulkPatchValidateParams, error -> objectReport.addErrorReport(error)));
if (objectReport.hasErrorReports()) {
return objectReport;
}
bundle.addEntity(id, entity, jsonPatch);
return objectReport;
}
Aggregations