Search in sources :

Example 11 with ErrorMessage

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

the class DataValidator method validateAndSetAssigned.

/**
 * Validates if the given file resource uid has a valid FileResource
 * associated with.
 *
 * @param fileResourceUid the uid of the FileResource.
 * @param valueType
 * @param valueTypeOptions
 * @return a valid FileResource.
 * @throws WebMessageException if any validation fails.
 */
public FileResource validateAndSetAssigned(final String fileResourceUid, ValueType valueType, ValueTypeOptions valueTypeOptions) throws WebMessageException {
    Preconditions.checkNotNull(fileResourceUid);
    final FileResource fileResource = fileResourceService.getFileResource(fileResourceUid);
    if (fileResource == null || fileResource.getDomain() != DATA_VALUE) {
        throw new WebMessageException(notFound(FileResource.class, fileResourceUid));
    }
    if (fileResource.isAssigned()) {
        throw new IllegalQueryException(ErrorCode.E2026);
    }
    if (valueType != null && valueTypeOptions != null) {
        String validationResult = dataValueIsValid(fileResource, valueType, valueTypeOptions);
        if (validationResult != null) {
            fileResourceService.deleteFileResource(fileResource);
            throw new IllegalQueryException(new ErrorMessage(ErrorCode.E2027, validationResult));
        }
    }
    fileResource.setAssigned(true);
    return fileResource;
}
Also used : WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) FileResource(org.hisp.dhis.fileresource.FileResource) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) DateUtils.getMediumDateString(org.hisp.dhis.util.DateUtils.getMediumDateString) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 12 with ErrorMessage

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

the class FilteringHelper method extractValueFromFilter.

/**
 * Extracts the actual value, from the set of filters, that matches the
 * given combination.
 *
 * ie.: from a list of filters: "dimensionItemType:eq:INDICATOR",
 * "name:ilike:john", extract the value from the combination NAME_ILIKE(
 * "name:ilike:" ). This will return "john".
 *
 * @param filters
 * @param filterCombination
 * @return the value extracted from the respective filter combination
 */
public static String extractValueFromFilter(final Set<String> filters, final Filter.Combination filterCombination) {
    final byte FILTER_VALUE = 2;
    if (CollectionUtils.isNotEmpty(filters)) {
        for (final String filter : filters) {
            if (filterHasPrefix(filter, filterCombination.getCombination())) {
                final String[] array = filter.split(":");
                final boolean hasValue = array.length == 3;
                if (hasValue) {
                    return array[FILTER_VALUE];
                } else {
                    throw new IllegalQueryException(new ErrorMessage(E2014, filter));
                }
            }
        }
    }
    return EMPTY;
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ValueType.fromString(org.hisp.dhis.common.ValueType.fromString) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 13 with ErrorMessage

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

the class OrderValidator method checkOrderParams.

/**
 * Checks if the given set o filters are valid, and contains only filter
 * names and operators supported.
 *
 * @param orderParams a set containing elements in the format
 *        "attributeName:asc"
 * @throws IllegalQueryException if the set contains a non-supported name or
 *         operator, or contains invalid syntax.
 */
public static void checkOrderParams(final Set<String> orderParams) {
    if (isNotEmpty(orderParams)) {
        for (final String orderParam : orderParams) {
            final String[] orderAttributeValuePair = orderParam.split(":");
            final String orderAttributeName = trimToEmpty(orderAttributeValuePair[ORDERING_ATTRIBUTE_NAME]);
            final String orderValue = trimToEmpty(orderAttributeValuePair[ORDERING_VALUE]);
            final boolean filterHasCorrectForm = orderAttributeValuePair.length == 2;
            if (filterHasCorrectForm) {
                // attributes are allowed.
                if (!getNames().contains(orderAttributeName)) {
                    throw new IllegalQueryException(new ErrorMessage(E2037, orderAttributeName));
                }
                // allowed.
                if (!getValues().contains(orderValue)) {
                    throw new IllegalQueryException(new ErrorMessage(E2037, orderValue));
                }
            } else {
                throw new IllegalQueryException(new ErrorMessage(E2015, orderParam));
            }
        }
    }
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 14 with ErrorMessage

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

the class DefaultFollowupAnalysisService method validationError.

private IllegalQueryException validationError(ErrorCode error, Object... args) {
    ErrorMessage message = new ErrorMessage(error, args);
    log.warn(String.format("Followup analysis request validation failed, code: '%s', message: '%s'", error, message.getMessage()));
    return new IllegalQueryException(message);
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage)

Example 15 with ErrorMessage

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

the class UserLookupController method lookUpFeedbackRecipients.

@GetMapping(value = "/feedbackRecipients")
public UserLookups lookUpFeedbackRecipients(@RequestParam String query) {
    UserGroup feedbackRecipients = config.getConfiguration().getFeedbackRecipients();
    if (feedbackRecipients == null) {
        throw new IllegalQueryException(new ErrorMessage(ErrorCode.E6200));
    }
    UserQueryParams params = new UserQueryParams().setQuery(query).setUserGroups(Sets.newHashSet(feedbackRecipients)).setCanSeeOwnUserAuthorityGroups(true).setMax(25);
    List<UserLookup> users = userService.getUsers(params).stream().map(UserLookup::fromUser).collect(Collectors.toList());
    return new UserLookups(users);
}
Also used : IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) UserLookup(org.hisp.dhis.webapi.webdomain.user.UserLookup) UserLookups(org.hisp.dhis.webapi.webdomain.user.UserLookups) ErrorMessage(org.hisp.dhis.feedback.ErrorMessage) UserQueryParams(org.hisp.dhis.user.UserQueryParams) UserGroup(org.hisp.dhis.user.UserGroup) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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