Search in sources :

Example 76 with Schema

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;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) User(org.hisp.dhis.user.User) Schema(org.hisp.dhis.schema.Schema) ArrayList(java.util.ArrayList) Property(org.hisp.dhis.schema.Property)

Example 77 with Schema

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;
}
Also used : Authority(org.hisp.dhis.security.Authority) Schema(org.hisp.dhis.schema.Schema)

Example 78 with 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;
}
Also used : Authority(org.hisp.dhis.security.Authority) Schema(org.hisp.dhis.schema.Schema)

Example 79 with 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;
}
Also used : Schema(org.hisp.dhis.schema.Schema)

Example 80 with 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;
}
Also used : Authority(org.hisp.dhis.security.Authority) Schema(org.hisp.dhis.schema.Schema)

Aggregations

Schema (org.hisp.dhis.schema.Schema)149 Authority (org.hisp.dhis.security.Authority)65 Property (org.hisp.dhis.schema.Property)29 ArrayList (java.util.ArrayList)20 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)20 Test (org.junit.Test)16 Collection (java.util.Collection)14 List (java.util.List)13 HashMap (java.util.HashMap)12 DhisSpringTest (org.hisp.dhis.DhisSpringTest)12 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)12 Map (java.util.Map)10 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)10 User (org.hisp.dhis.user.User)10 AnalyticalObject (org.hisp.dhis.common.AnalyticalObject)9 BaseAnalyticalObject (org.hisp.dhis.common.BaseAnalyticalObject)9 UserCredentials (org.hisp.dhis.user.UserCredentials)9 HashSet (java.util.HashSet)8 Set (java.util.Set)8 Log (org.apache.commons.logging.Log)8