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