Search in sources :

Example 1 with BulkPatchValidateParams

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;
}
Also used : IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ErrorReport(org.hisp.dhis.feedback.ErrorReport) SchemaService(org.hisp.dhis.schema.SchemaService) JsonPatchException(org.hisp.dhis.commons.jackson.jsonpatch.JsonPatchException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TypeReport(org.hisp.dhis.feedback.TypeReport) JsonPatch(org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch) List(java.util.List) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Service(org.springframework.stereotype.Service) ErrorCode(org.hisp.dhis.feedback.ErrorCode) Schema(org.hisp.dhis.schema.Schema) BulkPatchValidateParams(org.hisp.dhis.jsonpatch.validator.BulkPatchValidateParams) AllArgsConstructor(lombok.AllArgsConstructor) ObjectReport(org.hisp.dhis.feedback.ObjectReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) BulkPatchValidateParams(org.hisp.dhis.jsonpatch.validator.BulkPatchValidateParams) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 AllArgsConstructor (lombok.AllArgsConstructor)1 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 IdentifiableObjectManager (org.hisp.dhis.common.IdentifiableObjectManager)1 JsonPatch (org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch)1 JsonPatchException (org.hisp.dhis.commons.jackson.jsonpatch.JsonPatchException)1 ErrorCode (org.hisp.dhis.feedback.ErrorCode)1 ErrorReport (org.hisp.dhis.feedback.ErrorReport)1 ObjectReport (org.hisp.dhis.feedback.ObjectReport)1 TypeReport (org.hisp.dhis.feedback.TypeReport)1 BulkPatchValidateParams (org.hisp.dhis.jsonpatch.validator.BulkPatchValidateParams)1 Schema (org.hisp.dhis.schema.Schema)1 SchemaService (org.hisp.dhis.schema.SchemaService)1 Service (org.springframework.stereotype.Service)1