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]);
}
}
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`"));
}
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"));
}
Aggregations