use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class DefaultCompleteDataSetRegistrationExchangeService method validate.
public void validate(ExportParams params) throws IllegalQueryException {
ErrorMessage error = null;
if (params == null) {
throw new IllegalQueryException(ErrorCode.E2000);
}
if (params.getDataSets().isEmpty()) {
error = new ErrorMessage(ErrorCode.E2013);
}
if (!params.hasPeriods() && !params.hasStartEndDate() && !params.hasCreated() && !params.hasCreatedDuration()) {
error = new ErrorMessage(ErrorCode.E2002);
}
if (params.hasPeriods() && params.hasStartEndDate()) {
error = new ErrorMessage(ErrorCode.E2003);
}
if (params.hasStartEndDate() && params.getStartDate().after(params.getEndDate())) {
error = new ErrorMessage(ErrorCode.E2004);
}
if (params.hasCreatedDuration() && DateUtils.getDuration(params.getCreatedDuration()) == null) {
error = new ErrorMessage(ErrorCode.E2005);
}
if (!params.hasOrganisationUnits() && !params.hasOrganisationUnitGroups()) {
error = new ErrorMessage(ErrorCode.E2006);
}
if (params.isIncludeChildren() && params.hasOrganisationUnitGroups()) {
error = new ErrorMessage(ErrorCode.E2007);
}
if (params.isIncludeChildren() && !params.hasOrganisationUnits()) {
error = new ErrorMessage(ErrorCode.E2008);
}
if (params.hasLimit() && params.getLimit() < 0) {
error = new ErrorMessage(ErrorCode.E2009);
}
if (error != null) {
log.warn(String.format("Complete data set registration validation failed, code: '%s', message: '%s'", error.getErrorCode(), error.getMessage()));
throw new IllegalQueryException(error);
}
limitToValidIdSchemes(params);
}
use of org.hisp.dhis.feedback.ErrorMessage 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.feedback.ErrorMessage in project dhis2-core by dhis2.
the class QueryValidatorTest method validateErrorSingleIndicatorAsFilter.
@Test
void validateErrorSingleIndicatorAsFilter() {
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).addFilter(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA, inA))).build();
ErrorMessage error = queryValidator.validateForErrorMessage(params);
assertEquals(ErrorCode.E7108, error.getErrorCode());
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class QueryValidatorTest method validateErrorMultipleIndicatorsFilter.
@Test
void validateErrorMultipleIndicatorsFilter() {
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).addFilter(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(inA, inB))).build();
ErrorMessage error = queryValidator.validateForErrorMessage(params);
assertEquals(ErrorCode.E7108, error.getErrorCode());
}
use of org.hisp.dhis.feedback.ErrorMessage 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;
}
Aggregations