use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DataValidator method validateAndNormalizeDataValue.
/**
* Validates if the given data value is valid for the given DataElement, and
* normalize it if the dataValue is a boolean type.
*
* @param dataValue the data value.
* @param dataElement the {@link DataElement}.
* @return the normalized boolean or the same dataValue provided.
* @throws IllegalQueryException if the validation fails.
*/
public String validateAndNormalizeDataValue(final String dataValue, final DataElement dataElement) {
final String normalizedBoolean = normalizeBoolean(dataValue, dataElement.getValueType());
final String valueValid = dataValueIsValid(normalizedBoolean, dataElement);
if (valueValid != null) {
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2030, dataElement.getValueType()));
}
return normalizedBoolean;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DataValueController method setDataValueFollowUp.
// ---------------------------------------------------------------------
// Follow-up
// ---------------------------------------------------------------------
@PutMapping(value = "/followup")
@ResponseStatus(value = HttpStatus.OK)
public void setDataValueFollowUp(@RequestBody DataValueFollowUpRequest request) {
if (request == null || request.getFollowup() == null) {
throw new IllegalQueryException(ErrorCode.E2033);
}
DataValue dataValue = dataValueValidation.getAndValidateDataValue(request);
dataValue.setFollowup(request.getFollowup());
dataValueService.updateDataValue(dataValue);
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DataValueController method setDataValuesFollowUp.
@PutMapping(value = "/followups")
@ResponseStatus(value = HttpStatus.OK)
public void setDataValuesFollowUp(@RequestBody DataValuesFollowUpRequest request) {
List<DataValueFollowUpRequest> values = request == null ? null : request.getValues();
if (values == null || values.isEmpty() || values.stream().anyMatch(e -> e.getFollowup() == null)) {
throw new IllegalQueryException(ErrorCode.E2033);
}
List<DataValue> dataValues = new ArrayList<>();
for (DataValueFollowUpRequest e : values) {
DataValue dataValue = dataValueValidation.getAndValidateDataValue(e);
dataValue.setFollowup(e.getFollowup());
}
dataValueService.updateDataValues(dataValues);
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class FilteringHelper method extractEntityFromEqualFilter.
/**
* This method will return the respective BaseDimensionalItemObject class
* from the filter provided.
*
* @param filter should have the format of "dimensionItemType:eq:INDICATOR",
* where INDICATOR represents the BaseDimensionalItemObject. It could
* be any value represented by
* {@link org.hisp.dhis.common.DataDimensionItemType}
* @return the respective class associated with the given filter
* @throws IllegalQueryException if the filter points to a non supported
* class/entity
*/
public static Class<? extends BaseIdentifiableObject> extractEntityFromEqualFilter(final String filter) {
final byte DIMENSION_TYPE = 2;
Class<? extends BaseIdentifiableObject> entity = null;
if (filterHasPrefix(filter, DIMENSION_TYPE_EQUAL.getCombination())) {
final String[] dimensionFilterPair = filter.split(":");
final boolean hasDimensionType = dimensionFilterPair.length == 3;
if (hasDimensionType) {
entity = entityClassFromString(dimensionFilterPair[DIMENSION_TYPE]);
} else {
throw new IllegalQueryException(new ErrorMessage(E2014, filter));
}
}
return entity;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class RequestToSearchParamsMapper method map.
public EventSearchParams map(String program, String programStage, ProgramStatus programStatus, Boolean followUp, String orgUnit, OrganisationUnitSelectionMode orgUnitSelectionMode, String trackedEntityInstance, Date startDate, Date endDate, Date dueDateStart, Date dueDateEnd, Date lastUpdatedStartDate, Date lastUpdatedEndDate, String lastUpdatedDuration, EventStatus status, CategoryOptionCombo attributeOptionCombo, IdSchemes idSchemes, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging, List<OrderParam> orders, List<OrderParam> gridOrders, boolean includeAttributes, Set<String> events, Set<String> programInstances, Boolean skipEventId, AssignedUserSelectionMode assignedUserSelectionMode, Set<String> assignedUsers, Set<String> filters, Set<String> dataElements, boolean includeAllDataElements, boolean includeDeleted) {
User user = currentUserService.getCurrentUser();
EventSearchParams params = new EventSearchParams();
Program pr = programService.getProgram(program);
if (!StringUtils.isEmpty(program) && pr == null) {
throw new IllegalQueryException("Program is specified but does not exist: " + program);
}
ProgramStage ps = programStageService.getProgramStage(programStage);
if (!StringUtils.isEmpty(programStage) && ps == null) {
throw new IllegalQueryException("Program stage is specified but does not exist: " + programStage);
}
OrganisationUnit ou = organisationUnitService.getOrganisationUnit(orgUnit);
if (!StringUtils.isEmpty(orgUnit) && ou == null) {
throw new IllegalQueryException("Org unit is specified but does not exist: " + orgUnit);
}
if (pr != null && !user.isSuper() && !aclService.canDataRead(user, pr)) {
throw new IllegalQueryException("User has no access to program: " + pr.getUid());
}
if (ps != null && !user.isSuper() && !aclService.canDataRead(user, ps)) {
throw new IllegalQueryException("User has no access to program stage: " + ps.getUid());
}
TrackedEntityInstance tei = entityInstanceService.getTrackedEntityInstance(trackedEntityInstance);
if (!StringUtils.isEmpty(trackedEntityInstance) && tei == null) {
throw new IllegalQueryException("Tracked entity instance is specified but does not exist: " + trackedEntityInstance);
}
if (attributeOptionCombo != null && !user.isSuper() && !aclService.canDataRead(user, attributeOptionCombo)) {
throw new IllegalQueryException("User has no access to attribute category option combo: " + attributeOptionCombo.getUid());
}
if (!CollectionUtils.isEmpty(events) && !CollectionUtils.isEmpty(filters)) {
throw new IllegalQueryException("Event UIDs and filters can not be specified at the same time");
}
if (events == null) {
events = new HashSet<>();
}
if (filters != null) {
if (!StringUtils.isEmpty(programStage) && ps == null) {
throw new IllegalQueryException("ProgramStage needs to be specified for event filtering to work");
}
for (String filter : filters) {
QueryItem item = getQueryItem(filter);
params.getFilters().add(item);
}
}
if (dataElements != null) {
for (String de : dataElements) {
QueryItem dataElement = getQueryItem(de);
params.getDataElements().add(dataElement);
}
}
if (assignedUserSelectionMode != null && assignedUsers != null && !assignedUsers.isEmpty() && !assignedUserSelectionMode.equals(AssignedUserSelectionMode.PROVIDED)) {
throw new IllegalQueryException("Assigned User uid(s) cannot be specified if selectionMode is not PROVIDED");
}
if (assignedUsers != null) {
assignedUsers = assignedUsers.stream().filter(CodeGenerator::isValidUid).collect(Collectors.toSet());
}
if (programInstances != null) {
programInstances = programInstances.stream().filter(CodeGenerator::isValidUid).collect(Collectors.toSet());
}
return params.setProgram(pr).setProgramStage(ps).setOrgUnit(ou).setTrackedEntityInstance(tei).setProgramStatus(programStatus).setFollowUp(followUp).setOrgUnitSelectionMode(orgUnitSelectionMode).setAssignedUserSelectionMode(assignedUserSelectionMode).setAssignedUsers(assignedUsers).setStartDate(startDate).setEndDate(endDate).setDueDateStart(dueDateStart).setDueDateEnd(dueDateEnd).setLastUpdatedStartDate(lastUpdatedStartDate).setLastUpdatedEndDate(lastUpdatedEndDate).setLastUpdatedDuration(lastUpdatedDuration).setEventStatus(status).setCategoryOptionCombo(attributeOptionCombo).setIdSchemes(idSchemes).setPage(page).setPageSize(pageSize).setTotalPages(totalPages).setSkipPaging(skipPaging).setSkipEventId(skipEventId).setIncludeAttributes(includeAttributes).setIncludeAllDataElements(includeAllDataElements).setOrders(orders).setGridOrders(gridOrders).setEvents(events).setProgramInstances(programInstances).setIncludeDeleted(includeDeleted);
}
Aggregations