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;
}
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;
}
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));
}
}
}
}
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);
}
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);
}
Aggregations