use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class EventQueryValidatorTest method validateErrorClusterSize.
@Test
void validateErrorClusterSize() {
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 6, 1, 0, 0).toDate()).withEndDate(new DateTime(2012, 3, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouB)).withCoordinateField(deE.getUid()).withClusterSize(-3L).build();
ErrorMessage error = queryValidator.validateForErrorMessage(params);
assertEquals(ErrorCode.E7212, error.getErrorCode());
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class EventQueryValidatorTest method validateErrorNoStartEndDatePeriods.
@Test
void validateErrorNoStartEndDatePeriods() {
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withOrganisationUnits(Lists.newArrayList(ouB)).build();
ErrorMessage error = queryValidator.validateForErrorMessage(params);
assertEquals(ErrorCode.E7205, error.getErrorCode());
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class QueryValidatorTest method validateErrorReportingRatesAndDataElementGroupSetAsDimensions.
@Test
void validateErrorReportingRatesAndDataElementGroupSetAsDimensions() {
DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA, ouB))).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(rrA, inA))).addDimension(new BaseDimensionalObject(dgsA.getDimension(), DimensionType.DATA_ELEMENT_GROUP_SET, getList(deA))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA, peB))).build();
ErrorMessage error = queryValidator.validateForErrorMessage(params);
assertEquals(ErrorCode.E7112, error.getErrorCode());
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class FilteringHelper method extractValueTypeFromEqualFilter.
/**
* This method will return the respective ValueType from the filter
* provided.
*
* @param filter should have the format of "valueType:eq:NUMBER", where
* NUMBER represents the ValueType. It could be any value represented
* by {@link ValueType}
* @return the respective value type associated with the given filter
* @throws IllegalQueryException if the filter points to a non supported
* value type
*/
private static String extractValueTypeFromEqualFilter(final String filter) {
final byte VALUE_TYPE = 2;
String valueType = null;
if (filterHasPrefix(filter, VALUE_TYPE_EQUAL.getCombination())) {
final String[] array = filter.split(":");
final boolean hasValueType = array.length == 3;
if (hasValueType) {
valueType = getValueTypeOrThrow(array[VALUE_TYPE]);
} else {
throw new IllegalQueryException(new ErrorMessage(E2014, filter));
}
}
return valueType;
}
use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.
the class DataValidator method getAndValidateOrganisationUnit.
/**
* Retrieves and verifies an organisation unit.
*
* @param uid the organisation unit identifier.
* @return the {@link OrganisationUnit}.
* @throws IllegalQueryException if the validation fails.
*/
public OrganisationUnit getAndValidateOrganisationUnit(final String uid) {
final OrganisationUnit organisationUnit = idObjectManager.get(OrganisationUnit.class, uid);
if (organisationUnit == null) {
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E1102, uid));
}
final boolean isInHierarchy = organisationUnitService.isInUserHierarchyCached(organisationUnit);
if (!isInHierarchy) {
throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2020, uid));
}
return organisationUnit;
}
Aggregations