use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class ValidateAddUpdateSqlViewAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
message = null;
if (name == null || name.trim().isEmpty()) {
message = i18n.getString("name_is_null");
return INPUT;
}
if (mode.equals(ADD) && sqlViewService.getSqlView(name) != null) {
message = i18n.getString("name_in_use");
return INPUT;
}
if (sqlquery == null || sqlquery.trim().isEmpty()) {
message = i18n.getString("sqlquery_is_empty");
return INPUT;
}
try {
// Avoid variable check
SqlView sqlView = new SqlView(name, sqlquery, SqlViewType.VIEW);
sqlViewService.validateSqlView(sqlView, null, null);
} catch (IllegalQueryException ex) {
message = ex.getMessage();
return INPUT;
}
if (!query) {
message = sqlViewService.testSqlGrammar(sqlquery);
}
if (message != null) {
return INPUT;
}
return SUCCESS;
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class FilterValidatorTest method testCheckNamesAndOperatorsWhenAttributeIsInvalid.
@Test
void testCheckNamesAndOperatorsWhenAttributeIsInvalid() {
// Given
final Set<String> filters = new HashSet<>(singletonList("invalidAttribute:ilike:aWord"));
// When throws
final IllegalQueryException thrown = assertThrows(IllegalQueryException.class, () -> checkNamesAndOperators(filters));
// Then
assertThat(thrown.getMessage(), containsString("Filter not supported: `invalidAttribute`"));
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class FilterValidatorTest method testCheckNamesAndOperatorsWhenOperationIsInvalid.
@Test
void testCheckNamesAndOperatorsWhenOperationIsInvalid() {
// Given
final Set<String> filters = new HashSet<>(singletonList("name:invalidOperation:aWord"));
// When throws
final IllegalQueryException thrown = assertThrows(IllegalQueryException.class, () -> checkNamesAndOperators(filters));
// Then
assertThat(thrown.getMessage(), containsString("Operator not supported: `invalidOperation`"));
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DataValidatorTest method testGetMissingOrgUnit.
@Test
void testGetMissingOrgUnit() {
final String uid = CodeGenerator.generateUid();
when(idObjectManager.get(OrganisationUnit.class, uid)).thenReturn(null);
IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> dataValidator.getAndValidateOrganisationUnit(uid));
assertEquals(ErrorCode.E1102, ex.getErrorCode());
}
use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.
the class DataValidatorTest method testInvalidPeriod.
@Test
void testInvalidPeriod() {
IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> dataValidator.getAndValidatePeriod("502"));
assertEquals(ErrorCode.E1101, ex.getErrorCode());
}
Aggregations