use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class DefaultQueryParser method parse.
@Override
public Query parse(Class<?> klass, List<String> filters, Junction.Type rootJunction) throws QueryParserException {
Schema schema = schemaService.getDynamicSchema(klass);
Query query = Query.from(schema, rootJunction);
Junction junction = query.getRootJunction();
for (String filter : filters) {
String[] split = filter.split(":");
if (!(split.length >= 2)) {
throw new QueryParserException("Invalid filter => " + filter);
}
if (split.length >= 3) {
int index = split[0].length() + ":".length() + split[1].length() + ":".length();
junction.add(getRestriction(schema, split[0], split[1], filter.substring(index)));
} else {
junction.add(getRestriction(schema, split[0], split[1], null));
}
}
return query;
}
use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class InMemoryQueryEngine method getValue.
private Object getValue(Query query, Object object, String path) {
String[] paths = path.split("\\.");
Schema currentSchema = query.getSchema();
for (int i = 0; i < paths.length; i++) {
Property property = currentSchema.getProperty(paths[i]);
if (property == null) {
throw new QueryException("No property found for path " + path);
}
if (property.isCollection()) {
currentSchema = schemaService.getDynamicSchema(property.getItemKlass());
} else {
currentSchema = schemaService.getDynamicSchema(property.getKlass());
}
object = collect(object, property);
if (i == (paths.length - 1)) {
if (property.isCollection()) {
return Lists.newArrayList(object);
}
return object;
}
}
throw new QueryException("No values found for path " + path);
}
use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class QueryTest method createSchema.
private Schema createSchema() {
Schema schema = new Schema(DataElement.class, "dataElement", "dataElements");
schema.addProperty(createProperty(String.class, "id", true, true));
schema.addProperty(createProperty(String.class, "name", true, true));
schema.addProperty(createProperty(String.class, "code", true, true));
schema.addProperty(createProperty(Date.class, "created", true, true));
schema.addProperty(createProperty(Date.class, "lastUpdated", true, true));
schema.addProperty(createProperty(Integer.class, "int", true, true));
schema.addProperty(createProperty(Long.class, "long", true, true));
schema.addProperty(createProperty(Float.class, "float", true, true));
schema.addProperty(createProperty(Double.class, "double", true, true));
return schema;
}
use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class QueryServiceTest method sortNameDesc.
@Test
public void sortNameDesc() {
Schema schema = schemaService.getDynamicSchema(DataElement.class);
Query query = Query.from(schema);
query.addOrder(new Order(schema.getProperty("name"), Direction.DESCENDING));
List<? extends IdentifiableObject> objects = queryService.query(query);
assertEquals(6, objects.size());
assertEquals("deabcdefghF", objects.get(0).getUid());
assertEquals("deabcdefghE", objects.get(1).getUid());
assertEquals("deabcdefghD", objects.get(2).getUid());
assertEquals("deabcdefghC", objects.get(3).getUid());
assertEquals("deabcdefghB", objects.get(4).getUid());
assertEquals("deabcdefghA", objects.get(5).getUid());
}
use of org.hisp.dhis.schema.Schema in project dhis2-core by dhis2.
the class QueryServiceTest method sortCreatedAsc.
@Test
public void sortCreatedAsc() {
Schema schema = schemaService.getDynamicSchema(DataElement.class);
Query query = Query.from(schema);
query.addOrder(new Order(schema.getProperty("created"), Direction.ASCENDING));
List<? extends IdentifiableObject> objects = queryService.query(query);
assertEquals(6, objects.size());
assertEquals("deabcdefghA", objects.get(0).getUid());
assertEquals("deabcdefghB", objects.get(1).getUid());
assertEquals("deabcdefghC", objects.get(2).getUid());
assertEquals("deabcdefghD", objects.get(3).getUid());
assertEquals("deabcdefghE", objects.get(4).getUid());
assertEquals("deabcdefghF", objects.get(5).getUid());
}
Aggregations