Search in sources :

Example 61 with IllegalQueryException

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

the class InputUtils method getAttributeOptionComboInternal.

private CategoryOptionCombo getAttributeOptionComboInternal(String cc, String cp, boolean skipFallback) {
    Set<String> opts = TextUtils.splitToArray(cp, TextUtils.SEMICOLON);
    if ((cc == null && opts != null || (cc != null && opts == null))) {
        throw new IllegalQueryException("Both or none of category combination and category options must be present");
    }
    CategoryCombo categoryCombo = null;
    if (cc != null && (categoryCombo = idObjectManager.get(CategoryCombo.class, cc)) == null) {
        throw new IllegalQueryException("Illegal category combo identifier: " + cc);
    }
    if (categoryCombo == null) {
        if (skipFallback) {
            return null;
        }
        categoryCombo = categoryService.getDefaultCategoryCombo();
    }
    return getAttributeOptionCombo(categoryCombo, opts, null, IdScheme.UID);
}
Also used : CategoryCombo(org.hisp.dhis.category.CategoryCombo) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException)

Example 62 with IllegalQueryException

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

the class DefaultEventDataQueryService method getCoordinateField.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private String getCoordinateField(String coordinateField, String defaultEventCoordinateField) {
    if (coordinateField == null || EventQueryParams.EVENT_COORDINATE_FIELD.equals(coordinateField)) {
        return defaultEventCoordinateField;
    }
    if (EventQueryParams.ENROLLMENT_COORDINATE_FIELD.equals(coordinateField)) {
        return "pigeometry";
    }
    DataElement dataElement = dataElementService.getDataElement(coordinateField);
    if (dataElement != null) {
        return getCoordinateFieldOrFail(dataElement.getValueType(), coordinateField, ErrorCode.E7219);
    }
    TrackedEntityAttribute attribute = attributeService.getTrackedEntityAttribute(coordinateField);
    if (attribute != null) {
        return getCoordinateFieldOrFail(attribute.getValueType(), coordinateField, ErrorCode.E7220);
    }
    throw new IllegalQueryException(new ErrorMessage(ErrorCode.E7221, coordinateField));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 63 with IllegalQueryException

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

the class QueryValidatorTest method assertValidatonError.

/**
 * Asserts whether the given error code is thrown by the query validator for
 * the given query.
 *
 * @param errorCode the {@link ErrorCode}.
 * @param params the {@link DataQueryParams}.
 */
private void assertValidatonError(final ErrorCode errorCode, final DataQueryParams params) {
    IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> queryValidator.validate(params));
    assertEquals(errorCode, ex.getErrorCode());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException)

Example 64 with IllegalQueryException

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

the class DatastoreQuery method parseFields.

/**
 * Parses the fields URL parameter form to a list of {@link Field}s.
 *
 * In text form fields can describe nested fields in two forms:
 *
 * <pre>
 *   root[child]
 *   root[child1,child2]
 *   root[level1[level2]
 * </pre>
 *
 * which is similar to the second form using dot
 *
 * <pre>
 *   root.child
 *   root.child1,root.child2
 *   root.level1.level2
 * </pre>
 *
 * E leaf in this text form can be given an alias in round braces:
 *
 * <pre>
 *   root(alias)
 *   root[child(alias)]
 * </pre>
 *
 * @param fields a comma separated list of fields
 * @return the object form of the text representation given if valid
 * @throws IllegalQueryException in case the provided text form is not valid
 */
public static List<Field> parseFields(String fields) {
    final List<Field> flat = new ArrayList<>();
    final int len = fields.length();
    String parentPath = "";
    int start = 0;
    while (start < len) {
        int end = findNameEnd(fields, start);
        String field = fields.substring(start, end);
        start = end + 1;
        if (end >= len) {
            addNonEmptyTo(flat, parentPath, field);
            return flat;
        }
        char next = fields.charAt(end);
        if (next == ',') {
            addNonEmptyTo(flat, parentPath, field);
        } else if (next == '[') {
            parentPath += field + ".";
        } else if (next == ']') {
            addNonEmptyTo(flat, parentPath, field);
            parentPath = parentPath.substring(0, parentPath.lastIndexOf('.', parentPath.length() - 2) + 1);
        } else {
            throw new IllegalQueryException(new ErrorMessage(ErrorCode.E7651, end, next));
        }
    }
    return flat;
}
Also used : ArrayList(java.util.ArrayList) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ToString(lombok.ToString) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 65 with IllegalQueryException

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

the class OrgUnitMergeServiceTest method testSourceOrgUnitNotFound.

@Test
void testSourceOrgUnitNotFound() {
    OrgUnitMergeQuery query = new OrgUnitMergeQuery();
    query.setSources(Lists.newArrayList(BASE_OU_UID + 'A', BASE_OU_UID + 'X'));
    query.setTarget(BASE_OU_UID + 'C');
    IllegalQueryException ex = assertThrows(IllegalQueryException.class, () -> service.getFromQuery(query));
    assertEquals(ErrorCode.E1503, ex.getErrorCode());
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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