Search in sources :

Example 6 with ErrorMessage

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());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with ErrorMessage

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());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with ErrorMessage

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());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) Test(org.junit.jupiter.api.Test)

Example 9 with ErrorMessage

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;
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ValueType.fromString(org.hisp.dhis.common.ValueType.fromString) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 10 with ErrorMessage

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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Aggregations

ErrorMessage (org.hisp.dhis.feedback.ErrorMessage)34 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)22 Test (org.junit.jupiter.api.Test)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)7 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)5 DateTime (org.joda.time.DateTime)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 ArrayList (java.util.ArrayList)3 ValueType.fromString (org.hisp.dhis.common.ValueType.fromString)3 DataElement (org.hisp.dhis.dataelement.DataElement)3 Date (java.util.Date)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1