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