Search in sources :

Example 16 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class DefaultSchemaValidator method validateInteger.

private List<? extends ErrorReport> validateInteger(Class<?> klass, Object propertyObject, Property property) {
    List<ErrorReport> errorReports = new ArrayList<>();
    if (!Integer.class.isInstance(propertyObject)) {
        return errorReports;
    }
    Integer value = (Integer) propertyObject;
    if (!GenericValidator.isInRange(value, property.getMin(), property.getMax())) {
        errorReports.add(new ErrorReport(klass, ErrorCode.E4008, property.getName(), property.getMin(), property.getMax(), value).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
    }
    return errorReports;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ArrayList(java.util.ArrayList)

Example 17 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class AclServiceTest method testUpdatePrivateProgram.

@Test
public void testUpdatePrivateProgram() {
    User user = createUser("user1", "F_PROGRAM_PRIVATE_ADD", "F_PROGRAMSTAGE_ADD");
    Program program = createProgram('A');
    program.setUser(user);
    program.setPublicAccess(AccessStringHelper.DEFAULT);
    manager.save(program);
    Access access = aclService.getAccess(program, user);
    assertTrue(access.isRead());
    assertTrue(access.isWrite());
    assertTrue(access.isUpdate());
    assertFalse(access.isDelete());
    assertTrue(access.isManage());
    List<ErrorReport> errorReports = aclService.verifySharing(program, user);
    assertTrue(errorReports.isEmpty());
    manager.update(program);
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) UserGroupAccess(org.hisp.dhis.user.UserGroupAccess) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 18 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class ObjectBundleReportTest method createTypeReport.

private TypeReport createTypeReport(Class<?> mainKlass, Class<?> errorKlass) {
    ObjectReport objectReport0 = new ObjectReport(mainKlass, 0);
    ObjectReport objectReport1 = new ObjectReport(mainKlass, 1);
    ObjectReport objectReport2 = new ObjectReport(mainKlass, 2);
    objectReport0.addErrorReport(new ErrorReport(errorKlass, ErrorCode.E3000, "admin", errorKlass.getSimpleName()));
    objectReport1.addErrorReport(new ErrorReport(errorKlass, ErrorCode.E3000, "admin", errorKlass.getSimpleName()));
    objectReport2.addErrorReport(new ErrorReport(errorKlass, ErrorCode.E3000, "admin", errorKlass.getSimpleName()));
    TypeReport typeReport = new TypeReport(mainKlass);
    typeReport.addObjectReport(objectReport0);
    typeReport.addObjectReport(objectReport1);
    typeReport.addObjectReport(objectReport2);
    return typeReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) TypeReport(org.hisp.dhis.feedback.TypeReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport)

Example 19 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class SchemaController method validateSchema.

@RequestMapping(value = "/{type}", method = { RequestMethod.POST, RequestMethod.PUT }, consumes = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
public void validateSchema(@PathVariable String type, HttpServletRequest request, HttpServletResponse response) throws IOException {
    Schema schema = getSchemaFromType(type);
    if (schema == null) {
        throw new HttpClientErrorException(HttpStatus.NOT_FOUND, "Type " + type + " does not exist.");
    }
    Object object = renderService.fromJson(request.getInputStream(), schema.getKlass());
    List<ErrorReport> validationViolations = schemaValidator.validate(object);
    WebMessage webMessage = WebMessageUtils.errorReports(validationViolations);
    webMessageService.send(webMessage, response, request);
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Schema(org.hisp.dhis.schema.Schema) WebMessage(org.hisp.dhis.dxf2.webmessage.WebMessage) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with ErrorReport

use of org.hisp.dhis.feedback.ErrorReport in project dhis2-core by dhis2.

the class DefaultSchemaValidator method validateFloat.

private List<? extends ErrorReport> validateFloat(Class<?> klass, Object propertyObject, Property property) {
    List<ErrorReport> errorReports = new ArrayList<>();
    if (!Float.class.isInstance(propertyObject)) {
        return errorReports;
    }
    Float value = (Float) propertyObject;
    if (!GenericValidator.isInRange(value, property.getMin(), property.getMax())) {
        errorReports.add(new ErrorReport(klass, ErrorCode.E4008, property.getName(), property.getMin(), property.getMax(), value).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
    }
    return errorReports;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ArrayList(java.util.ArrayList)

Aggregations

ErrorReport (org.hisp.dhis.feedback.ErrorReport)30 ObjectReport (org.hisp.dhis.feedback.ObjectReport)17 ArrayList (java.util.ArrayList)15 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)14 PreheatErrorReport (org.hisp.dhis.preheat.PreheatErrorReport)14 TypeReport (org.hisp.dhis.feedback.TypeReport)13 User (org.hisp.dhis.user.User)8 Schema (org.hisp.dhis.schema.Schema)5 List (java.util.List)4 ErrorCode (org.hisp.dhis.feedback.ErrorCode)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DhisSpringTest (org.hisp.dhis.DhisSpringTest)3 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)3 Test (org.junit.Test)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2