Search in sources :

Example 1 with Owner

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);
}
Also used : Owner(org.hisp.dhis.gist.GistQuery.Owner)

Example 2 with Owner

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);
}
Also used : Owner(org.hisp.dhis.gist.GistQuery.Owner)

Example 3 with Owner

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++;
    }
}
Also used : Owner(org.hisp.dhis.gist.GistQuery.Owner) GistLogic.isCollectionSizeFilter(org.hisp.dhis.gist.GistLogic.isCollectionSizeFilter) Filter(org.hisp.dhis.gist.GistQuery.Filter) GistLogic.isStringLengthFilter(org.hisp.dhis.gist.GistLogic.isStringLengthFilter) Comparison(org.hisp.dhis.gist.GistQuery.Comparison) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject)

Example 4 with Owner

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();
}
Also used : Owner(org.hisp.dhis.gist.GistQuery.Owner) Schema(org.hisp.dhis.schema.Schema) UriBuilder(org.springframework.web.util.UriBuilder)

Example 5 with Owner

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

Aggregations

Owner (org.hisp.dhis.gist.GistQuery.Owner)5 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)1 GistLogic.isCollectionSizeFilter (org.hisp.dhis.gist.GistLogic.isCollectionSizeFilter)1 GistLogic.isStringLengthFilter (org.hisp.dhis.gist.GistLogic.isStringLengthFilter)1 Comparison (org.hisp.dhis.gist.GistQuery.Comparison)1 Filter (org.hisp.dhis.gist.GistQuery.Filter)1 Property (org.hisp.dhis.schema.Property)1 Schema (org.hisp.dhis.schema.Schema)1 UriBuilder (org.springframework.web.util.UriBuilder)1