Search in sources :

Example 31 with ErrorMessage

use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.

the class DataValidator method validateOrganisationUnitPeriod.

/**
 * Validates the OrganisationUnit dates against the given period.
 *
 * @param organisationUnit the {@link OrganisationUnit} and its dates.
 * @param period the {@link Period} to be checked.
 * @throws IllegalQueryException if the validation fails.
 */
public void validateOrganisationUnitPeriod(final OrganisationUnit organisationUnit, final Period period) {
    final Date openingDate = organisationUnit.getOpeningDate();
    final Date closedDate = organisationUnit.getClosedDate();
    final Date startDate = period.getStartDate();
    final Date endDate = period.getEndDate();
    if ((closedDate != null && closedDate.before(startDate)) || openingDate.after(endDate)) {
        throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2019, organisationUnit.getUid()));
    }
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) Date(java.util.Date)

Example 32 with ErrorMessage

use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.

the class DataValidator method validateAndNormalizeDataValue.

/**
 * Validates if the given data value is valid for the given DataElement, and
 * normalize it if the dataValue is a boolean type.
 *
 * @param dataValue the data value.
 * @param dataElement the {@link DataElement}.
 * @return the normalized boolean or the same dataValue provided.
 * @throws IllegalQueryException if the validation fails.
 */
public String validateAndNormalizeDataValue(final String dataValue, final DataElement dataElement) {
    final String normalizedBoolean = normalizeBoolean(dataValue, dataElement.getValueType());
    final String valueValid = dataValueIsValid(normalizedBoolean, dataElement);
    if (valueValid != null) {
        throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2030, dataElement.getValueType()));
    }
    return normalizedBoolean;
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 33 with ErrorMessage

use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.

the class FilteringHelper method extractEntityFromEqualFilter.

/**
 * This method will return the respective BaseDimensionalItemObject class
 * from the filter provided.
 *
 * @param filter should have the format of "dimensionItemType:eq:INDICATOR",
 *        where INDICATOR represents the BaseDimensionalItemObject. It could
 *        be any value represented by
 *        {@link org.hisp.dhis.common.DataDimensionItemType}
 * @return the respective class associated with the given filter
 * @throws IllegalQueryException if the filter points to a non supported
 *         class/entity
 */
public static Class<? extends BaseIdentifiableObject> extractEntityFromEqualFilter(final String filter) {
    final byte DIMENSION_TYPE = 2;
    Class<? extends BaseIdentifiableObject> entity = null;
    if (filterHasPrefix(filter, DIMENSION_TYPE_EQUAL.getCombination())) {
        final String[] dimensionFilterPair = filter.split(":");
        final boolean hasDimensionType = dimensionFilterPair.length == 3;
        if (hasDimensionType) {
            entity = entityClassFromString(dimensionFilterPair[DIMENSION_TYPE]);
        } else {
            throw new IllegalQueryException(new ErrorMessage(E2014, filter));
        }
    }
    return entity;
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ValueType.fromString(org.hisp.dhis.common.ValueType.fromString) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 34 with ErrorMessage

use of org.hisp.dhis.feedback.ErrorMessage in project dhis2-core by dhis2.

the class JobConfigurationController method executeJobConfiguration.

@PostMapping(value = "{uid}/execute", produces = { APPLICATION_JSON_VALUE, "application/javascript" })
public ObjectReport executeJobConfiguration(@PathVariable("uid") String uid) throws WebMessageException {
    JobConfiguration jobConfiguration = jobConfigurationService.getJobConfigurationByUid(uid);
    checkConfigurable(jobConfiguration, HttpStatus.FORBIDDEN, "Job %s is a system job that cannot be executed.");
    ObjectReport objectReport = new ObjectReport(JobConfiguration.class, 0);
    boolean success = schedulingManager.executeNow(jobConfiguration);
    if (!success) {
        objectReport.addErrorReport(new ErrorReport(JobConfiguration.class, new ErrorMessage(ErrorCode.E7006, jobConfiguration.getName())));
    }
    return objectReport;
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) JobConfiguration(org.hisp.dhis.scheduling.JobConfiguration) PostMapping(org.springframework.web.bind.annotation.PostMapping)

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