use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class JpaQueryUtilsTest method createSelectOrderExpression.
@Test
void createSelectOrderExpression() {
final Property property1 = new Property();
property1.setName("value1");
property1.setSimple(true);
property1.setPersisted(true);
property1.setKlass(String.class);
final Property property2 = new Property();
property2.setName("value2");
property2.setSimple(true);
property2.setPersisted(false);
final Property property3 = new Property();
property3.setName("value3");
property3.setSimple(true);
property3.setKlass(Integer.class);
property3.setPersisted(true);
final Property property4 = new Property();
property4.setName("value4");
property4.setSimple(true);
property4.setPersisted(true);
property4.setKlass(String.class);
final Property property5 = new Property();
property5.setName("value5");
property5.setSimple(true);
property5.setPersisted(true);
Assertions.assertEquals("lower(value1),lower(value4)", JpaQueryUtils.createSelectOrderExpression(Arrays.asList(new Order(property1, Direction.ASCENDING).ignoreCase(), new Order(property2, Direction.ASCENDING), new Order(property3, Direction.ASCENDING).ignoreCase(), new Order(property4, Direction.ASCENDING).ignoreCase(), new Order(property5, Direction.DESCENDING)), null));
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class JpaQueryUtilsTest method createOrderExpressionSingle.
@Test
void createOrderExpressionSingle() {
final Property property1 = new Property();
property1.setName("value1");
property1.setSimple(true);
property1.setPersisted(true);
Assertions.assertEquals("value1 asc", JpaQueryUtils.createOrderExpression(Collections.singletonList(new Order(property1, Direction.ASCENDING)), null));
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class PeriodTypeObjectBundleHook method preCreate.
@Override
public void preCreate(IdentifiableObject object, ObjectBundle bundle) {
Schema schema = schemaService.getDynamicSchema(HibernateProxyUtils.getRealClass(object));
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());
periodType = periodService.reloadPeriodType(periodType);
ReflectionUtils.invokeMethod(object, property.getSetterMethod(), periodType);
}
}
}
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class DefaultCollectionService method addCollectionItems.
@Override
@Transactional
public TypeReport addCollectionItems(IdentifiableObject object, String propertyName, Collection<? extends IdentifiableObject> objects) throws Exception {
Property property = validateUpdate(object, propertyName, "Only identifiable object collections can be added to.");
Collection<String> itemCodes = getItemCodes(objects);
if (itemCodes.isEmpty()) {
return TypeReport.empty(property.getItemKlass());
}
TypeReport report = new TypeReport(property.getItemKlass());
manager.refresh(object);
if (property.isOwner()) {
addOwnedCollectionItems(object, property, itemCodes, report);
} else {
addNonOwnedCollectionItems(object, property, itemCodes, report);
}
dbmsManager.clearSession();
cacheManager.clearCache();
return report;
}
use of org.hisp.dhis.schema.Property in project dhis2-core by dhis2.
the class EmbeddedObjectObjectBundleHook method preCreate.
@Override
public void preCreate(IdentifiableObject object, ObjectBundle bundle) {
Schema schema = schemaService.getDynamicSchema(HibernateProxyUtils.getRealClass(object));
if (schema == null || schema.getEmbeddedObjectProperties().isEmpty()) {
return;
}
Collection<Property> properties = schema.getEmbeddedObjectProperties().values();
handleEmbeddedObjects(object, bundle, properties);
}
Aggregations