Search in sources :

Example 91 with Property

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));
}
Also used : Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test)

Example 92 with Property

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));
}
Also used : Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test)

Example 93 with Property

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

Example 94 with Property

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;
}
Also used : TypeReport(org.hisp.dhis.feedback.TypeReport) Property(org.hisp.dhis.schema.Property) Transactional(org.springframework.transaction.annotation.Transactional)

Example 95 with Property

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

Aggregations

Property (org.hisp.dhis.schema.Property)126 Schema (org.hisp.dhis.schema.Schema)69 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)36 ArrayList (java.util.ArrayList)32 HashMap (java.util.HashMap)26 Collection (java.util.Collection)21 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)21 List (java.util.List)20 Map (java.util.Map)16 Test (org.junit.jupiter.api.Test)16 Attribute (org.hisp.dhis.attribute.Attribute)14 ReflectionUtils (org.hisp.dhis.system.util.ReflectionUtils)14 Collectors (java.util.stream.Collectors)13 User (org.hisp.dhis.user.User)13 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)12 EmbeddedObject (org.hisp.dhis.common.EmbeddedObject)12 SimpleNode (org.hisp.dhis.node.types.SimpleNode)12 Query (org.hisp.dhis.query.Query)12 SchemaService (org.hisp.dhis.schema.SchemaService)12 Transactional (org.springframework.transaction.annotation.Transactional)12