Search in sources :

Example 46 with Property

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

the class JpaQueryUtilsTest method createOrderExpression.

@Test
void createOrderExpression() {
    final Property property1 = new Property();
    property1.setName("value1");
    property1.setSimple(true);
    property1.setPersisted(true);
    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("value1 asc,value3 asc,lower(value4) asc,value5 desc", JpaQueryUtils.createOrderExpression(Arrays.asList(new Order(property1, Direction.ASCENDING), 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 47 with Property

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

the class JpaQueryUtilsTest method createSelectOrderExpressionAlias.

@Test
void createSelectOrderExpressionAlias() {
    final Property property1 = new Property();
    property1.setName("value1");
    property1.setSimple(true);
    property1.setKlass(String.class);
    property1.setPersisted(true);
    Assertions.assertEquals("lower(x.value1)", JpaQueryUtils.createSelectOrderExpression(Collections.singletonList(new Order(property1, Direction.ASCENDING).ignoreCase()), "x"));
}
Also used : Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test)

Example 48 with Property

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

the class JpaQueryUtilsTest method createOrderExpressionNoPersistent.

@Test
void createOrderExpressionNoPersistent() {
    final Property property = new Property();
    property.setName("valueTest");
    property.setSimple(true);
    property.setPersisted(false);
    Assertions.assertNull(JpaQueryUtils.createOrderExpression(Collections.singletonList(new Order(property, Direction.ASCENDING)), null));
}
Also used : Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test)

Example 49 with Property

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

the class JpaQueryUtilsTest method createSelectOrderExpressionNoPersistent.

@Test
void createSelectOrderExpressionNoPersistent() {
    final Property property = new Property();
    property.setName("valueTest");
    property.setSimple(true);
    property.setPersisted(false);
    Assertions.assertNull(JpaQueryUtils.createSelectOrderExpression(Collections.singletonList(new Order(property, Direction.ASCENDING)), null));
}
Also used : Property(org.hisp.dhis.schema.Property) Test(org.junit.jupiter.api.Test)

Example 50 with Property

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

the class DefaultFieldFilterServiceTest method toCollectionNodeSkipSharingOwner.

@Test
void toCollectionNodeSkipSharingOwner() throws Exception {
    final Attribute attribute = new Attribute();
    final Map<String, Property> propertyMap = new HashMap<>();
    addProperty(propertyMap, attribute, "dataElementAttribute");
    Property p = addProperty(propertyMap, attribute, "dataSetAttribute");
    p.setOwner(true);
    p.setPersisted(true);
    addProperty(propertyMap, attribute, "user");
    addProperty(propertyMap, attribute, "publicAccess");
    addProperty(propertyMap, attribute, "userGroupAccesses");
    addProperty(propertyMap, attribute, "userAccesses");
    addProperty(propertyMap, attribute, "externalAccess");
    final Schema rootSchema = new Schema(Attribute.class, "attribute", "attributes");
    rootSchema.setPropertyMap(propertyMap);
    Mockito.when(schemaService.getDynamicSchema(Mockito.eq(Attribute.class))).thenReturn(rootSchema);
    final Schema booleanSchema = new Schema(boolean.class, "boolean", "booleans");
    Mockito.when(schemaService.getDynamicSchema(Mockito.eq(boolean.class))).thenReturn(booleanSchema);
    final FieldFilterParams params = new FieldFilterParams(Collections.singletonList(attribute), Collections.singletonList(":owner"), Defaults.INCLUDE, true);
    CollectionNode node = service.toCollectionNode(Attribute.class, params);
    Assertions.assertEquals(1, node.getChildren().size());
    Set<String> names = extractNodeNames(node.getChildren().get(0).getChildren());
    Assertions.assertFalse(names.contains("dataElementAttribute"));
    Assertions.assertTrue(names.contains("dataSetAttribute"));
    Assertions.assertFalse(names.contains("user"));
    Assertions.assertFalse(names.contains("publicAccess"));
    Assertions.assertFalse(names.contains("userGroupAccesses"));
    Assertions.assertFalse(names.contains("userAccesses"));
    Assertions.assertFalse(names.contains("externalAccess"));
}
Also used : Attribute(org.hisp.dhis.attribute.Attribute) HashMap(java.util.HashMap) Schema(org.hisp.dhis.schema.Schema) Property(org.hisp.dhis.schema.Property) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Test(org.junit.jupiter.api.Test)

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