Search in sources :

Example 96 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class TrackedEntityCriteriaMapper method getQueryFilter.

/**
 * Creates a QueryFilter from the given query string. Query is on format
 * {operator}:{filter-value}. Only the filter-value is mandatory. The EQ
 * QueryOperator is used as operator if not specified.
 */
private QueryFilter getQueryFilter(String query) {
    if (query == null || query.isEmpty()) {
        return null;
    }
    if (!query.contains(DimensionalObject.DIMENSION_NAME_SEP)) {
        return new QueryFilter(QueryOperator.EQ, query);
    } else {
        String[] split = query.split(DimensionalObject.DIMENSION_NAME_SEP);
        if (split.length != 2) {
            throw new IllegalQueryException("Query has invalid format: " + query);
        }
        QueryOperator op = QueryOperator.fromString(split[0]);
        return new QueryFilter(op, split[1]);
    }
}
Also used : QueryFilter(org.hisp.dhis.common.QueryFilter) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) QueryOperator(org.hisp.dhis.common.QueryOperator)

Example 97 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class OrderValidatorTest method testCheckOrderParamsWhenOrderingValueIsInvalid.

@Test
void testCheckOrderParamsWhenOrderingValueIsInvalid() {
    // Given
    final Set<String> orderings = new HashSet<>(singletonList("name:invalidOrdering"));
    // When throws
    final IllegalQueryException thrown = assertThrows(IllegalQueryException.class, () -> checkOrderParams(orderings));
    // Then
    assertThat(thrown.getMessage(), containsString("Order not supported: `invalidOrdering`"));
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 98 with IllegalQueryException

use of org.hisp.dhis.common.IllegalQueryException in project dhis2-core by dhis2.

the class DataItemQueryControllerTest method testGetWhenAclIsInvalid.

@Test
void testGetWhenAclIsInvalid() {
    // Given
    final Map<String, String> anyUrlParameters = new HashMap<>();
    final OrderParams anyOrderParams = new OrderParams();
    final User anyUser = new User();
    final Set<Class<? extends BaseIdentifiableObject>> targetEntities = new HashSet<>(singletonList(Indicator.class));
    final boolean invalidAcl = false;
    // When
    when(dataItemServiceFacade.extractTargetEntities(anySet())).thenReturn(targetEntities);
    when(aclService.canRead(anyUser, Indicator.class)).thenReturn(invalidAcl);
    final IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> dataItemQueryController.getJson(anyUrlParameters, anyOrderParams, anyUser));
    assertThat(ex.getMessage(), containsString("does not have read access for object"));
}
Also used : User(org.hisp.dhis.user.User) BaseIdentifiableObject(org.hisp.dhis.common.BaseIdentifiableObject) HashMap(java.util.HashMap) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) OrderParams(org.hisp.dhis.dxf2.common.OrderParams) Indicator(org.hisp.dhis.indicator.Indicator) HashSet(java.util.HashSet) 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