use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class EnrollmentCriteriaMapper method getFromUrl.
/**
* Returns a ProgramInstanceQueryParams based on the given input.
*
* @param ou the set of organisation unit identifiers.
* @param ouMode the OrganisationUnitSelectionMode.
* @param lastUpdated the last updated for PI.
* @param lastUpdatedDuration the last updated duration filter.
* @param program the Program identifier.
* @param programStatus the ProgramStatus in the given program.
* @param programStartDate the start date for enrollment in the given
* Program.
* @param programEndDate the end date for enrollment in the given Program.
* @param trackedEntityType the TrackedEntityType uid.
* @param trackedEntityInstance the TrackedEntityInstance uid.
* @param followUp indicates follow up status in the given Program.
* @param page the page number.
* @param pageSize the page size.
* @param totalPages indicates whether to include the total number of pages.
* @param skipPaging whether to skip paging.
* @param includeDeleted whether to include soft deleted ones
* @return a ProgramInstanceQueryParams.
*/
@Transactional(readOnly = true)
public ProgramInstanceQueryParams getFromUrl(Set<String> ou, OrganisationUnitSelectionMode ouMode, Date lastUpdated, String lastUpdatedDuration, String program, ProgramStatus programStatus, Date programStartDate, Date programEndDate, String trackedEntityType, String trackedEntityInstance, Boolean followUp, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging, boolean includeDeleted, List<OrderCriteria> orderCriteria) {
ProgramInstanceQueryParams params = new ProgramInstanceQueryParams();
Set<OrganisationUnit> possibleSearchOrgUnits = new HashSet<>();
User user = currentUserService.getCurrentUser();
if (user != null) {
possibleSearchOrgUnits = user.getTeiSearchOrganisationUnitsWithFallback();
}
if (ou != null) {
for (String orgUnit : ou) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(orgUnit);
if (organisationUnit == null) {
throw new IllegalQueryException("Organisation unit does not exist: " + orgUnit);
}
if (!organisationUnitService.isInUserHierarchy(organisationUnit.getUid(), possibleSearchOrgUnits)) {
throw new IllegalQueryException("Organisation unit is not part of the search scope: " + orgUnit);
}
params.getOrganisationUnits().add(organisationUnit);
}
}
Program pr = program != null ? programService.getProgram(program) : null;
if (program != null && pr == null) {
throw new IllegalQueryException("Program does not exist: " + program);
}
TrackedEntityType te = trackedEntityType != null ? trackedEntityTypeService.getTrackedEntityType(trackedEntityType) : null;
if (trackedEntityType != null && te == null) {
throw new IllegalQueryException("Tracked entity does not exist: " + program);
}
TrackedEntityInstance tei = trackedEntityInstance != null ? trackedEntityInstanceService.getTrackedEntityInstance(trackedEntityInstance) : null;
if (trackedEntityInstance != null && tei == null) {
throw new IllegalQueryException("Tracked entity instance does not exist: " + program);
}
params.setProgram(pr);
params.setProgramStatus(programStatus);
params.setFollowUp(followUp);
params.setLastUpdated(lastUpdated);
params.setLastUpdatedDuration(lastUpdatedDuration);
params.setProgramStartDate(programStartDate);
params.setProgramEndDate(programEndDate);
params.setTrackedEntityType(te);
params.setTrackedEntityInstanceUid(Optional.ofNullable(tei).map(BaseIdentifiableObject::getUid).orElse(null));
params.setOrganisationUnitMode(ouMode);
params.setPage(page);
params.setPageSize(pageSize);
params.setTotalPages(totalPages);
params.setSkipPaging(skipPaging);
params.setIncludeDeleted(includeDeleted);
params.setUser(user);
params.setOrder(toOrderParams(orderCriteria));
return params;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class RequestToSearchParamsMapper method getQueryItem.
private QueryItem getQueryItem(String item) {
String[] split = item.split(DimensionalObject.DIMENSION_NAME_SEP);
if (split == null || split.length % 2 != 1) {
throw new IllegalQueryException("Query item or filter is invalid: " + item);
}
QueryItem queryItem = getItem(split[0]);
if (split.length > 1) {
for (int i = 1; i < split.length; i += 2) {
QueryOperator operator = QueryOperator.fromString(split[i]);
queryItem.getFilters().add(new QueryFilter(operator, split[i + 1]));
}
}
return queryItem;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DefaultFollowupAnalysisService method validationError.
private IllegalQueryException validationError(ErrorCode error, Object... args) {
ErrorMessage message = new ErrorMessage(error, args);
log.warn(String.format("Followup analysis request validation failed, code: '%s', message: '%s'", error, message.getMessage()));
return new IllegalQueryException(message);
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class MinMaxOutlierDetectionManager method getOutlierValues.
/**
* Returns a list of outlier data values based on min-max values for the
* given request.
*
* @param request the {@link OutlierDetectionRequest}.
* @return a list of {@link OutlierValue}.
*/
public List<OutlierValue> getOutlierValues(OutlierDetectionRequest request) {
final String ouPathClause = getOrgUnitPathClause(request.getOrgUnits());
// @formatter:off
final String sql = "select de.uid as de_uid, ou.uid as ou_uid, coc.uid as coc_uid, aoc.uid as aoc_uid, " + "de.name as de_name, ou.name as ou_name, coc.name as coc_name, aoc.name as aoc_name, " + "pe.startdate as pe_start_date, pt.name as pt_name, " + "dv.value::double precision as value, dv.followup as follow_up, " + "least(abs(dv.value::double precision - mm.minimumvalue), " + "abs(dv.value::double precision - mm.maximumvalue)) as bound_abs_dev, " + "mm.minimumvalue as lower_bound, " + "mm.maximumvalue as upper_bound " + "from datavalue dv " + "inner join dataelement de on dv.dataelementid = de.dataelementid " + "inner join categoryoptioncombo coc on dv.categoryoptioncomboid = coc.categoryoptioncomboid " + "inner join categoryoptioncombo aoc on dv.attributeoptioncomboid = aoc.categoryoptioncomboid " + "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 " + // Min-max value join
"inner join minmaxdataelement mm on (dv.dataelementid = mm.dataelementid " + "and dv.sourceid = mm.sourceid and dv.categoryoptioncomboid = mm.categoryoptioncomboid) " + "where dv.dataelementid in (:data_element_ids) " + "and pe.startdate >= :start_date " + "and pe.enddate <= :end_date " + "and " + ouPathClause + " " + "and dv.deleted is false " + // Filter for values outside the min-max range
"and (dv.value::double precision < mm.minimumvalue or dv.value::double precision > mm.maximumvalue) " + // Order and limit
"order by bound_abs_dev desc " + "limit :max_results;";
// @formatter:on
final SqlParameterSource params = new MapSqlParameterSource().addValue("data_element_ids", request.getDataElementIds()).addValue("start_date", request.getStartDate()).addValue("end_date", request.getEndDate()).addValue("max_results", request.getMaxResults());
final Calendar calendar = PeriodType.getCalendar();
try {
return jdbcTemplate.query(sql, params, getRowMapper(calendar));
} catch (DataIntegrityViolationException ex) {
// Casting non-numeric data to double, catching exception is faster
// than filtering
log.error(ErrorCode.E2208.getMessage(), ex);
throw new IllegalQueryException(ErrorCode.E2208);
}
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class UserLookupController method lookUpFeedbackRecipients.
@GetMapping(value = "/feedbackRecipients")
public UserLookups lookUpFeedbackRecipients(@RequestParam String query) {
UserGroup feedbackRecipients = config.getConfiguration().getFeedbackRecipients();
if (feedbackRecipients == null) {
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E6200));
}
UserQueryParams params = new UserQueryParams().setQuery(query).setUserGroups(Sets.newHashSet(feedbackRecipients)).setCanSeeOwnUserAuthorityGroups(true).setMax(25);
List<UserLookup> users = userService.getUsers(params).stream().map(UserLookup::fromUser).collect(Collectors.toList());
return new UserLookups(users);
}
Aggregations