use of org.hisp.dhis.gist.GistQuery.Owner in project dhis2-core by dhis2.
the class GistBuilder method buildCountHQL.
public String buildCountHQL() {
String userFilters = createFiltersHQL();
String accessFilters = createAccessFilterHQL(context, "e");
String elementTable = query.getElementType().getSimpleName();
Owner owner = query.getOwner();
if (owner == null) {
return String.format("select count(*) from %s e where (%s) and (%s)", elementTable, userFilters, accessFilters);
}
String ownerTable = owner.getType().getSimpleName();
String collectionName = context.switchedTo(owner.getType()).resolveMandatory(owner.getCollectionProperty()).getFieldName();
if (!query.isInverse()) {
return String.format("select count(*) from %s o left join o.%s as e where o.uid = :OwnerId and (%s) and (%s)", ownerTable, collectionName, userFilters, accessFilters);
}
return String.format("select count(*) from %s o, %s e where o.uid = :OwnerId and e not in elements(o.%s) and (%s) and (%s)", ownerTable, elementTable, collectionName, userFilters, accessFilters);
}
use of org.hisp.dhis.gist.GistQuery.Owner in project dhis2-core by dhis2.
the class GistBuilder method buildFetchHQL.
/*
* HQL query building...
*/
public String buildFetchHQL() {
String fields = createFieldsHQL();
String accessFilters = createAccessFilterHQL(context, "e");
String userFilters = createFiltersHQL();
String orders = createOrdersHQL();
String elementTable = query.getElementType().getSimpleName();
Owner owner = query.getOwner();
if (owner == null) {
return String.format("select %s from %s e where (%s) and (%s) order by %s", fields, elementTable, userFilters, accessFilters, orders);
}
String ownerTable = owner.getType().getSimpleName();
String collectionName = context.switchedTo(owner.getType()).resolveMandatory(owner.getCollectionProperty()).getFieldName();
if (!query.isInverse()) {
return String.format("select %s from %s o left join o.%s as e where o.uid = :OwnerId and (%s) and (%s) order by %s", fields, ownerTable, collectionName, userFilters, accessFilters, orders);
}
return String.format("select %s from %s o, %s e where o.uid = :OwnerId and e not in elements(o.%s) and (%s) and (%s) order by %s", fields, ownerTable, elementTable, collectionName, userFilters, accessFilters, orders);
}
use of org.hisp.dhis.gist.GistQuery.Owner in project dhis2-core by dhis2.
the class GistBuilder method addCountParameters.
public void addCountParameters(BiConsumer<String, Object> dest, BiFunction<String, Class<?>, Object> argumentParser) {
Owner owner = query.getOwner();
if (owner != null) {
dest.accept("OwnerId", owner.getId());
}
int i = 0;
for (Filter filter : query.getFilters()) {
Comparison operator = filter.getOperator();
if (!operator.isUnary() && !operator.isAccessCompare()) {
Object value = filter.isAttribute() ? filter.getValue()[0] : getParameterValue(context.resolveMandatory(filter.getPropertyPath()), filter, argumentParser);
dest.accept("f_" + i, operator.isStringCompare() ? completeLikeExpression(operator, stringParameterValue(operator, value)) : value);
}
i++;
}
}
use of org.hisp.dhis.gist.GistQuery.Owner in project dhis2-core by dhis2.
the class GistPager method computeBaseURL.
public static URI computeBaseURL(GistQuery query, Map<String, String[]> params, Function<Class<?>, Schema> schemaByType) {
UriBuilder url = UriComponentsBuilder.fromUriString(query.getEndpointRoot());
Owner owner = query.getOwner();
if (owner != null) {
Schema o = schemaByType.apply(owner.getType());
url.pathSegment(o.getRelativeApiEndpoint().substring(1), owner.getId(), o.getProperty(owner.getCollectionProperty()).key(), "gist");
} else {
Schema s = schemaByType.apply(query.getElementType());
url.pathSegment(s.getRelativeApiEndpoint().substring(1), "gist");
}
params.forEach(url::queryParam);
return url.build();
}
use of org.hisp.dhis.gist.GistQuery.Owner in project dhis2-core by dhis2.
the class GistValidator method validateOwnerCollection.
private void validateOwnerCollection() {
Owner owner = query.getOwner();
if (owner == null || owner.getCollectionProperty() == null) {
return;
}
Property collection = context.switchedTo(owner.getType()).resolveMandatory(owner.getCollectionProperty());
if (!collection.isCollection() || !collection.isPersisted()) {
throw createIllegalProperty(collection, "Property `%s` is not a persisted collection member.");
}
}
Aggregations