use of org.hisp.dhis.period.PeriodType 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.period.PeriodType 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.period.PeriodType in project dhis2-core by dhis2.
the class ValidationRuleObjectBundleHook method preUpdate.
@Override
public void preUpdate(IdentifiableObject object, IdentifiableObject persistedObject, ObjectBundle bundle) {
if (!ValidationRule.class.isInstance(object)) {
return;
}
ValidationRule validationRule = (ValidationRule) object;
if (validationRule.getPeriodType() != null) {
PeriodType periodType = bundle.getPreheat().getPeriodTypeMap().get(validationRule.getPeriodType().getName());
validationRule.setPeriodType(periodType);
}
}
use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.
the class QueryPlannerUtils method getAggregationTypeDataElementMap.
/**
* Creates a mapping between the aggregation type and data element for the
* given data elements and period type.
*
* @param params the data query parameters.
*/
public static ListMap<AggregationType, DimensionalItemObject> getAggregationTypeDataElementMap(DataQueryParams params) {
List<DimensionalItemObject> dataElements = params.getDataElements();
PeriodType aggregationPeriodType = PeriodType.getPeriodTypeByName(params.getPeriodType());
ListMap<AggregationType, DimensionalItemObject> map = new ListMap<>();
for (DimensionalItemObject element : dataElements) {
DataElement de = (DataElement) element;
AggregationType type = ObjectUtils.firstNonNull(params.getAggregationType(), de.getAggregationType());
AggregationType aggregationType = getAggregationType(de.getValueType(), type, aggregationPeriodType, de.getPeriodType());
map.putValue(aggregationType, de);
}
return map;
}
use of org.hisp.dhis.period.PeriodType in project dhis2-core by dhis2.
the class UniqueArrayListTest method testAdd.
@Test
public void testAdd() {
List<Period> list = new UniqueArrayList<>();
PeriodType periodType = new MonthlyPeriodType();
Period peA = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
// Duplicate
Period peB = periodType.createPeriod(new DateTime(2000, 1, 1, 0, 0).toDate());
Period peC = periodType.createPeriod(new DateTime(2000, 2, 1, 0, 0).toDate());
list.add(peA);
list.add(peB);
list.add(peC);
assertEquals(2, list.size());
assertTrue(list.contains(peA));
assertTrue(list.contains(peB));
assertTrue(list.contains(peC));
}
Aggregations