use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class AbstractEventService 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 AbstractEventService method saveEvent.
private ImportSummary saveEvent(Program program, ProgramInstance programInstance, ProgramStage programStage, ProgramStageInstance programStageInstance, OrganisationUnit organisationUnit, Event event, User user, ImportOptions importOptions) {
Assert.notNull(program, "Program cannot be null");
Assert.notNull(programInstance, "Program instance cannot be null");
Assert.notNull(programStage, "Program stage cannot be null");
ImportSummary importSummary = new ImportSummary(event.getEvent());
if (importOptions == null) {
importOptions = new ImportOptions();
}
boolean existingEvent = programStageInstance != null;
boolean dryRun = importOptions.isDryRun();
// = new Date();
Date executionDate = null;
if (event.getEventDate() != null) {
executionDate = DateUtils.parseDate(event.getEventDate());
}
Date dueDate = new Date();
if (event.getDueDate() != null) {
dueDate = DateUtils.parseDate(event.getDueDate());
}
String storedBy = getStoredBy(event, importSummary, user);
String completedBy = getCompletedBy(event, importSummary, user);
DataElementCategoryOptionCombo aoc = null;
if ((event.getAttributeCategoryOptions() != null && program.getCategoryCombo() != null) || event.getAttributeOptionCombo() != null) {
IdScheme idScheme = importOptions.getIdSchemes().getCategoryOptionIdScheme();
try {
aoc = inputUtils.getAttributeOptionCombo(program.getCategoryCombo(), event.getAttributeCategoryOptions(), event.getAttributeOptionCombo(), idScheme);
} catch (IllegalQueryException ex) {
importSummary.getConflicts().add(new ImportConflict(ex.getMessage(), event.getAttributeCategoryOptions()));
}
} else {
aoc = categoryService.getDefaultDataElementCategoryOptionCombo();
}
if (!dryRun) {
if (programStageInstance == null) {
programStageInstance = createProgramStageInstance(event, programStage, programInstance, organisationUnit, dueDate, executionDate, event.getStatus().getValue(), event.getCoordinate(), completedBy, event.getEvent(), aoc, importOptions);
} else {
updateProgramStageInstance(event, programStage, programInstance, organisationUnit, dueDate, executionDate, event.getStatus().getValue(), event.getCoordinate(), completedBy, programStageInstance, aoc, importOptions);
}
updateTrackedEntityInstance(programStageInstance);
saveTrackedEntityComment(programStageInstance, event, storedBy);
importSummary.setReference(programStageInstance.getUid());
}
Map<String, TrackedEntityDataValue> dataElementValueMap = Maps.newHashMap();
if (existingEvent) {
dataElementValueMap = getDataElementDataValueMap(dataValueService.getTrackedEntityDataValues(programStageInstance));
}
for (DataValue dataValue : event.getDataValues()) {
DataElement dataElement;
if (dataElementValueMap.containsKey(dataValue.getDataElement())) {
dataElement = dataElementValueMap.get(dataValue.getDataElement()).getDataElement();
} else {
dataElement = getDataElement(importOptions.getIdSchemes().getDataElementIdScheme(), dataValue.getDataElement());
}
if (dataElement != null) {
if (validateDataValue(dataElement, dataValue.getValue(), importSummary)) {
String dataValueStoredBy = dataValue.getStoredBy() != null ? dataValue.getStoredBy() : storedBy;
if (!dryRun) {
TrackedEntityDataValue existingDataValue = dataElementValueMap.get(dataValue.getDataElement());
saveDataValue(programStageInstance, dataValueStoredBy, dataElement, dataValue.getValue(), dataValue.getProvidedElsewhere(), existingDataValue, importSummary);
}
}
} else {
importSummary.getConflicts().add(new ImportConflict("dataElement", dataValue.getDataElement() + " is not a valid data element"));
importSummary.getImportCount().incrementIgnored();
}
}
importSummary.setStatus(importSummary.getConflicts().isEmpty() ? ImportStatus.SUCCESS : ImportStatus.WARNING);
return importSummary;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DefaultProgramInstanceService method getFromUrl.
@Override
public ProgramInstanceQueryParams getFromUrl(Set<String> ou, OrganisationUnitSelectionMode ouMode, Date lastUpdated, String program, ProgramStatus programStatus, Date programStartDate, Date programEndDate, String trackedEntity, String trackedEntityInstance, Boolean followUp, Integer page, Integer pageSize, boolean totalPages, boolean skipPaging) {
ProgramInstanceQueryParams params = new ProgramInstanceQueryParams();
if (ou != null) {
for (String orgUnit : ou) {
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(orgUnit);
if (organisationUnit == null) {
throw new IllegalQueryException("Organisation unit does not exist: " + 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);
}
TrackedEntity te = trackedEntity != null ? trackedEntityService.getTrackedEntity(trackedEntity) : null;
if (trackedEntity != 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.setProgramStartDate(programStartDate);
params.setProgramEndDate(programEndDate);
params.setTrackedEntity(te);
params.setTrackedEntityInstance(tei);
params.setOrganisationUnitMode(ouMode);
params.setPage(page);
params.setPageSize(pageSize);
params.setTotalPages(totalPages);
params.setSkipPaging(skipPaging);
return params;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class InputUtils method getAttributeOptionCombo.
/**
* Validates and retrieves the attribute option combo. 409 conflict as
* status code along with a textual message will be set on the response in
* case of invalid input.
*
* @param categoryCombo the category combo.
* @param opts list of category option uid.
* @param attributeOptionCombo the explicit attribute option combo
* identifier.
* @return the attribute option combo identified from the given input, or
* null if the input was invalid.
*/
public DataElementCategoryOptionCombo getAttributeOptionCombo(DataElementCategoryCombo categoryCombo, Set<String> opts, String attributeOptionCombo, IdScheme idScheme) {
if (categoryCombo == null) {
throw new IllegalQueryException("Illegal category combo");
}
// ---------------------------------------------------------------------
// Attribute category options validation
// ---------------------------------------------------------------------
DataElementCategoryOptionCombo attrOptCombo = null;
if (opts != null) {
Set<DataElementCategoryOption> categoryOptions = new HashSet<>();
for (String uid : opts) {
DataElementCategoryOption categoryOption = idObjectManager.getObject(DataElementCategoryOption.class, idScheme, uid);
if (categoryOption == null) {
throw new IllegalQueryException("Illegal category option identifier: " + uid);
}
categoryOptions.add(categoryOption);
}
attrOptCombo = categoryService.getDataElementCategoryOptionCombo(categoryCombo, categoryOptions);
if (attrOptCombo == null) {
throw new IllegalQueryException("Attribute option combo does not exist for given category combo and category options");
}
} else if (attributeOptionCombo != null) {
attrOptCombo = categoryService.getDataElementCategoryOptionCombo(attributeOptionCombo);
}
if (attrOptCombo == null) {
attrOptCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
}
if (attrOptCombo == null) {
throw new IllegalQueryException("Default attribute option combo does not exist");
}
return attrOptCombo;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DefaultResourceTableService method createAllSqlViews.
// -------------------------------------------------------------------------
// SQL Views. Each view is created/dropped in separate transactions so that
// process continues even if individual operations fail.
// -------------------------------------------------------------------------
@Override
public void createAllSqlViews() {
List<SqlView> views = new ArrayList<>(sqlViewService.getAllSqlViewsNoAcl());
Collections.sort(views);
for (SqlView view : views) {
if (!view.isQuery()) {
try {
sqlViewService.createViewTable(view);
} catch (IllegalQueryException ex) {
log.warn(String.format("Ignoring SQL view which failed validation: %s, %s, message: %s", view.getUid(), view.getName(), ex.getMessage()));
}
}
}
}
Aggregations