use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class DefaultSchemaValidator method validate.
@Override
public List<ErrorReport> validate(Object object, boolean persisted) {
List<ErrorReport> errorReports = new ArrayList<>();
if (object == null) {
return errorReports;
}
Schema schema = schemaService.getDynamicSchema(object.getClass());
if (schema == null) {
return errorReports;
}
Class<?> klass = object.getClass();
for (Property property : schema.getProperties()) {
if (persisted && !property.isPersisted()) {
continue;
}
Object value = ReflectionUtils.invokeMethod(object, property.getGetterMethod());
if (value == null) {
if (property.isRequired() && !Preheat.isDefaultClass(property.getKlass())) {
errorReports.add(new ErrorReport(klass, ErrorCode.E4000, property.getName()).setErrorKlass(property.getKlass()).setErrorProperty(property.getName()));
}
continue;
}
errorReports.addAll(validateString(klass, value, property));
errorReports.addAll(validateCollection(klass, value, property));
errorReports.addAll(validateInteger(klass, value, property));
errorReports.addAll(validateFloat(klass, value, property));
errorReports.addAll(validateDouble(klass, value, property));
}
if (User.class.isInstance(object)) {
User user = (User) object;
if (user.getUserCredentials() != null) {
errorReports.addAll(validate(user.getUserCredentials(), persisted));
}
}
return errorReports;
}
use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class ProgramSchemaDescriptor method getSchema.
@Override
public Schema getSchema() {
Schema schema = new Schema(Program.class, SINGULAR, PLURAL);
schema.setRelativeApiEndpoint(API_ENDPOINT);
schema.setOrder(1520);
schema.getAuthorities().add(new Authority(AuthorityType.CREATE_PUBLIC, Lists.newArrayList("F_PROGRAM_PUBLIC_ADD")));
schema.getAuthorities().add(new Authority(AuthorityType.CREATE_PRIVATE, Lists.newArrayList("F_PROGRAM_PRIVATE_ADD")));
schema.getAuthorities().add(new Authority(AuthorityType.DELETE, Lists.newArrayList("F_PROGRAM_DELETE")));
return schema;
}
use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class ProgramStageSchemaDescriptor method getSchema.
@Override
public Schema getSchema() {
Schema schema = new Schema(ProgramStage.class, SINGULAR, PLURAL);
schema.setRelativeApiEndpoint(API_ENDPOINT);
schema.setOrder(1509);
schema.getAuthorities().add(new Authority(AuthorityType.CREATE, Lists.newArrayList("F_PROGRAMSTAGE_ADD")));
schema.getAuthorities().add(new Authority(AuthorityType.DELETE, Lists.newArrayList("F_PROGRAMSTAGE_DELETE")));
return schema;
}
use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class ProgramStageSectionSchemaDescriptor method getSchema.
@Override
public Schema getSchema() {
Schema schema = new Schema(ProgramStageSection.class, SINGULAR, PLURAL);
schema.setRelativeApiEndpoint(API_ENDPOINT);
schema.setOrder(1508);
return schema;
}
use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class SectionSchemaDescriptor method getSchema.
@Override
public Schema getSchema() {
Schema schema = new Schema(Section.class, SINGULAR, PLURAL);
schema.setRelativeApiEndpoint(API_ENDPOINT);
schema.setOrder(1320);
schema.getAuthorities().add(new Authority(AuthorityType.CREATE, Lists.newArrayList("F_SECTION_ADD")));
schema.getAuthorities().add(new Authority(AuthorityType.DELETE, Lists.newArrayList("F_SECTION_DELETE")));
return schema;
}
Aggregations