Search in sources :

Example 61 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class EmbeddedObjectObjectBundleHook method preUpdate.

@Override
public <T extends IdentifiableObject> void preUpdate(T object, T persistedObject, ObjectBundle bundle) {
    Schema schema = schemaService.getDynamicSchema(object.getClass());
    if (schema == null || schema.getEmbeddedObjectProperties().isEmpty()) {
        return;
    }
    Collection<Property> properties = schema.getEmbeddedObjectProperties().values();
    clearEmbeddedObjects(persistedObject, properties);
    handleEmbeddedObjects(object, bundle, properties);
}
Also used : Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property)

Example 62 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class PeriodTypeObjectBundleHook method preUpdate.

@Override
public <T extends IdentifiableObject> void preUpdate(T object, T persistedObject, ObjectBundle bundle) {
    Schema schema = schemaService.getDynamicSchema(object.getClass());
    for (Property property : schema.getPropertyMap().values()) {
        if (PeriodType.class.isAssignableFrom(property.getKlass())) {
            PeriodType periodType = ReflectionUtils.invokeMethod(object, property.getGetterMethod());
            if (periodType != null) {
                periodType = bundle.getPreheat().getPeriodTypeMap().get(periodType.getName());
                ReflectionUtils.invokeMethod(object, property.getSetterMethod(), periodType);
            }
        }
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property)

Example 63 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class PeriodTypeObjectBundleHook method preCreate.

@Override
public <T extends IdentifiableObject> void preCreate(T object, ObjectBundle bundle) {
    Schema schema = schemaService.getDynamicSchema(object.getClass());
    for (Property property : schema.getPropertyMap().values()) {
        if (PeriodType.class.isAssignableFrom(property.getKlass())) {
            PeriodType periodType = ReflectionUtils.invokeMethod(object, property.getGetterMethod());
            if (periodType != null) {
                periodType = bundle.getPreheat().getPeriodTypeMap().get(periodType.getName());
                ReflectionUtils.invokeMethod(object, property.getSetterMethod(), periodType);
            }
        }
    }
}
Also used : PeriodType(org.hisp.dhis.period.PeriodType) Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property)

Example 64 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class HibernateGenericStore method getAllByAttributes.

@Override
@SuppressWarnings("unchecked")
public List<T> getAllByAttributes(List<Attribute> attributes) {
    Schema schema = schemaService.getDynamicSchema(getClazz());
    if (schema == null || !schema.havePersistedProperty("attributeValues") || attributes.isEmpty()) {
        return new ArrayList<>();
    }
    String hql = "select e from " + getClazz().getSimpleName() + "  as e " + "inner join e.attributeValues av inner join av.attribute at where at in (:attributes) )";
    return getQuery(hql).setParameterList("attributes", attributes).list();
}
Also used : Schema(org.hisp.dhis.schema.Schema) ArrayList(java.util.ArrayList)

Example 65 with Schema

use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.

the class HibernateGenericStore method getAttributeValueByAttributes.

@Override
@SuppressWarnings("unchecked")
public List<AttributeValue> getAttributeValueByAttributes(List<Attribute> attributes) {
    Schema schema = schemaService.getDynamicSchema(getClazz());
    if (schema == null || !schema.havePersistedProperty("attributeValues")) {
        return new ArrayList<>();
    }
    String hql = "select av from " + getClazz().getSimpleName() + "  as e " + "inner join e.attributeValues av inner join av.attribute at where at in (:attributes) )";
    return getQuery(hql).setParameterList("attributes", attributes).list();
}
Also used : Schema(org.hisp.dhis.schema.Schema) ArrayList(java.util.ArrayList)

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