Search in sources :

Example 66 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class DefaultQueryItemLocator method getQueryItemFromDimension.

@Override
public QueryItem getQueryItemFromDimension(String dimension, Program program, EventOutputType type) {
    checkNotNull(program, "Program can not be null");
    LegendSet legendSet = getLegendSet(dimension);
    return getDataElement(dimension, program, legendSet, type).orElseGet(() -> getTrackedEntityAttribute(dimension, program, legendSet).orElseGet(() -> getProgramIndicator(dimension, program, legendSet).orElseThrow(() -> new IllegalQueryException(new ErrorMessage(ErrorCode.E7224, dimension)))));
}
Also used : LegendSet(org.hisp.dhis.legend.LegendSet) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 67 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class DefaultQueryItemLocator method getRepeatableStageParams.

private static RepeatableStageParams getRepeatableStageParams(String dimension) {
    try {
        RepeatableStageParams repeatableStageParams = RepeatableStageParamsHelper.getRepeatableStageParams(dimension);
        repeatableStageParams.setDimension(dimension);
        return repeatableStageParams;
    } catch (InvalidRepeatableStageParamsException e) {
        ErrorMessage errorMessage = new ErrorMessage(dimension, ErrorCode.E1101);
        throw new IllegalQueryException(errorMessage);
    }
}
Also used : InvalidRepeatableStageParamsException(org.hisp.dhis.common.exception.InvalidRepeatableStageParamsException) RepeatableStageParams(org.hisp.dhis.common.RepeatableStageParams) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 68 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class AnalyticsUtils method getDebugDataSql.

/**
 * Returns an SQL statement for retrieving raw data values for an aggregate
 * query.
 *
 * @param params the data query parameters.
 * @return an SQL statement.
 */
public static String getDebugDataSql(DataQueryParams params) {
    List<DimensionalItemObject> dataElements = new ArrayList<>(NameableObjectUtils.getCopyNullSafe(params.getDataElements()));
    dataElements.addAll(NameableObjectUtils.getCopyNullSafe(params.getFilterDataElements()));
    List<DimensionalItemObject> periods = new ArrayList<>(NameableObjectUtils.getCopyNullSafe(params.getPeriods()));
    periods.addAll(NameableObjectUtils.getCopyNullSafe(params.getFilterPeriods()));
    List<DimensionalItemObject> orgUnits = new ArrayList<>(NameableObjectUtils.getCopyNullSafe(params.getOrganisationUnits()));
    orgUnits.addAll(NameableObjectUtils.getCopyNullSafe(params.getFilterOrganisationUnits()));
    if (dataElements.isEmpty() || periods.isEmpty() || orgUnits.isEmpty()) {
        throw new IllegalQueryException(ErrorCode.E7400);
    }
    String sql = "select de.name as de_name, de.uid as de_uid, de.dataelementid as de_id, " + "pe.startdate as start_date, pe.enddate as end_date, pt.name as pt_name, " + "ou.name as ou_name, ou.uid as ou_uid, ou.organisationunitid as ou_id, " + "coc.name as coc_name, coc.uid as coc_uid, coc.categoryoptioncomboid as coc_id, " + "aoc.name as aoc_name, aoc.uid as aoc_uid, aoc.categoryoptioncomboid as aoc_id, dv.value as datavalue " + "from datavalue dv " + "inner join dataelement de on dv.dataelementid = de.dataelementid " + "inner join period pe on dv.periodid = pe.periodid " + "inner join periodtype pt on pe.periodtypeid = pt.periodtypeid " + "inner join organisationunit ou on dv.sourceid = ou.organisationunitid " + "inner join categoryoptioncombo coc on dv.categoryoptioncomboid = coc.categoryoptioncomboid " + "inner join categoryoptioncombo aoc on dv.attributeoptioncomboid = aoc.categoryoptioncomboid " + "where dv.dataelementid in (" + StringUtils.join(IdentifiableObjectUtils.getIdentifiers(dataElements), ",") + ") " + "and (";
    for (DimensionalItemObject period : periods) {
        Period pe = (Period) period;
        sql += "(pe.startdate >= '" + getMediumDateString(pe.getStartDate()) + "' and pe.enddate <= '" + getMediumDateString(pe.getEndDate()) + "') or ";
    }
    sql = TextUtils.removeLastOr(sql) + ") and (";
    for (DimensionalItemObject orgUnit : orgUnits) {
        OrganisationUnit ou = (OrganisationUnit) orgUnit;
        int level = ou.getLevel();
        sql += "(dv.sourceid in (select organisationunitid from _orgunitstructure where idlevel" + level + " = " + ou.getId() + ")) or ";
    }
    sql = TextUtils.removeLastOr(sql) + ") ";
    sql += "and dv.deleted is false " + "limit 100000";
    return sql;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataDimensionalItemObject(org.hisp.dhis.common.DataDimensionalItemObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString)

Example 69 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class RelationshipTypeJoinGenerator method addRelationshipWhereClause.

private static String addRelationshipWhereClause(Long relationshipTypeId, RelationshipEntity relationshipEntity) {
    String sql = new StringSubstitutor(ImmutableMap.<String, Long>builder().put("relationshipid", relationshipTypeId).build()).replace(RELATIONSHIP_JOIN);
    sql += " AND ";
    switch(relationshipEntity) {
        case TRACKED_ENTITY_INSTANCE:
            return sql + "tei.uid = ax.tei ";
        case PROGRAM_STAGE_INSTANCE:
            return sql + "psi.uid = ax.psi ";
        case PROGRAM_INSTANCE:
            return sql + "pi.uid = ax.pi ";
        default:
            throw new IllegalQueryException(new ErrorMessage(ErrorCode.E7227, relationshipEntity.name()));
    }
}
Also used : StringSubstitutor(org.apache.commons.text.StringSubstitutor) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 70 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class EventQueryValidatorTest method assertValidatonError.

/**
 * Asserts whether the given error code is thrown by the query validator for
 * the given query.
 *
 * @param errorCode the {@link ErrorCode}.
 * @param params the {@link DataQueryParams}.
 */
private void assertValidatonError(final ErrorCode errorCode, final EventQueryParams params) {
    IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> queryValidator.validate(params));
    assertEquals(errorCode, ex.getErrorCode());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException)

Aggregations

IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)98 Test (org.junit.jupiter.api.Test)26 ErrorMessage (org.hisp.dhis.feedback.ErrorMessage)22 HashSet (java.util.HashSet)17 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)17 User (org.hisp.dhis.user.User)14 QueryItem (org.hisp.dhis.common.QueryItem)13 ArrayList (java.util.ArrayList)12 Date (java.util.Date)11 Program (org.hisp.dhis.program.Program)11 QueryFilter (org.hisp.dhis.common.QueryFilter)10 TrackedEntityInstanceCriteria (org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria)10 Transactional (org.springframework.transaction.annotation.Transactional)10 QueryOperator (org.hisp.dhis.common.QueryOperator)9 List (java.util.List)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 DataElement (org.hisp.dhis.dataelement.DataElement)8 DhisWebSpringTest (org.hisp.dhis.webapi.DhisWebSpringTest)7 Map (java.util.Map)6 Set (java.util.Set)6