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