Search in sources :

Example 51 with IllegalQueryException

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;
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException)

Example 52 with IllegalQueryException

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`"));
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Test(org.junit.jupiter.api.Test)

Example 53 with IllegalQueryException

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`"));
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) HashSet(java.util.HashSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Test(org.junit.jupiter.api.Test)

Example 54 with IllegalQueryException

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());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Test(org.junit.jupiter.api.Test)

Example 55 with IllegalQueryException

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());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Test(org.junit.jupiter.api.Test)

Aggregations

IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)98 Test (org.junit.jupiter.api.Test)26 ErrorMessage (org.hisp.dhis.feedback.ErrorMessage)22 HashSet (java.util.HashSet)17 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)17 User (org.hisp.dhis.user.User)14 QueryItem (org.hisp.dhis.common.QueryItem)13 ArrayList (java.util.ArrayList)12 Date (java.util.Date)11 Program (org.hisp.dhis.program.Program)11 QueryFilter (org.hisp.dhis.common.QueryFilter)10 TrackedEntityInstanceCriteria (org.hisp.dhis.webapi.controller.event.webrequest.TrackedEntityInstanceCriteria)10 Transactional (org.springframework.transaction.annotation.Transactional)10 QueryOperator (org.hisp.dhis.common.QueryOperator)9 List (java.util.List)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 DataElement (org.hisp.dhis.dataelement.DataElement)8 DhisWebSpringTest (org.hisp.dhis.webapi.DhisWebSpringTest)7 Map (java.util.Map)6 Set (java.util.Set)6