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);
}
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));
}
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());
}
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;
}
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());
}
Aggregations