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;
}
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);
}
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;
}
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);
}
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;
}
Aggregations