public ErrorMatcher addReason(final ErrorCollection.Reason reason) { errorCollection.addReason(reason); return this; }
private Errors addError(String key, ErrorCollection.Reason reason, String tr, Object...args) { errors.addError(key, context.getI18nHelper().getText(tr, args)); errors.addReason(reason); return this; }
/** * JRA-4429 (prevent invalid characters) */ public static void checkInvalidCharacters(final String fieldValue, final String fieldName, final ErrorCollection errorCollection) { if (fieldValue.indexOf('<') != -1) { errorCollection.addError(fieldName, getI18nBean().getText("admin.errors.invalid.character", "'<'")); errorCollection.addReason(ErrorCollection.Reason.VALIDATION_FAILED); } if (fieldValue.indexOf('&') != -1) { errorCollection.addError(fieldName, getI18nBean().getText("admin.errors.invalid.character", "'&'")); errorCollection.addReason(ErrorCollection.Reason.VALIDATION_FAILED); } // JRA-5733 - '"' is also invalid if (fieldValue.indexOf('"') != -1) { errorCollection.addError(fieldName, getI18nBean().getText("admin.errors.invalid.character", "'\"'")); errorCollection.addReason(ErrorCollection.Reason.VALIDATION_FAILED); } }
/** * Convenience method that returns a new ServiceOutcomeImpl instance containing the provided error message, and no * return value. * * @param <T> the type of the returned value * @param reason for the error. * @param errorMessage the error message to include in the ServiceOutcomeImpl * @return a new ServiceOutcomeImpl */ public static <T> ServiceOutcomeImpl<T> error(String errorMessage, ErrorCollection.Reason reason) { ErrorCollection errors = new SimpleErrorCollection(); errors.addErrorMessage(errorMessage); if (reason != null) { errors.addReason(reason); } return new ServiceOutcomeImpl<T>(errors); }
private void addError(final JiraServiceContext jiraServiceContext, final String msgKey, final Reason reason) { final ErrorCollection errorCollection = jiraServiceContext.getErrorCollection(); errorCollection.addErrorMessage(getI18nBean().getText(msgKey)); errorCollection.addReason(reason); } }
/** * Validate jql, filterId and statType so they are not blank or missing. * * @param jql parameter to check * @param filterId parameter to check * @param statType parameter to check * @return any errors in parameter format */ private ErrorCollection validParameters(@Nullable final String jql, @Nullable Long filterId, @Nullable final String statType) { ErrorCollection errors = new SimpleErrorCollection(); if (jql == null && filterId == null) { errors.addErrorMessage(authenticationContext.getI18nHelper().getText("rest.missing.field", SEARCH_JQL)); errors.addErrorMessage(authenticationContext.getI18nHelper().getText("rest.missing.field", FILTER_ID)); errors.addReason(ErrorCollection.Reason.VALIDATION_FAILED); } if (StringUtils.isBlank(statType)) { errors.addErrorMessage(authenticationContext.getI18nHelper().getText("rest.missing.field", STAT_TYPE)); errors.addReason(ErrorCollection.Reason.VALIDATION_FAILED); } return errors; }
/** * Validate jql, filterId and statType so they are not blank or missing. * @param jql parameter to check * @param filterId parameter to check * @param statType parameter to check * @return any errors in parameter format */ private ErrorCollection validParameters(@Nullable final String jql, @Nullable Long filterId, @Nullable final String statType) { ErrorCollection errors = new SimpleErrorCollection(); if (jql == null && filterId == null) { errors.addErrorMessage(authenticationContext.getI18nHelper().getText("rest.missing.field", SEARCH_JQL)); errors.addErrorMessage(authenticationContext.getI18nHelper().getText("rest.missing.field", FILTER_ID)); errors.addReason(ErrorCollection.Reason.VALIDATION_FAILED); } if (com.atlassian.gzipfilter.org.apache.commons.lang.StringUtils.isBlank(statType)) { errors.addErrorMessage(authenticationContext.getI18nHelper().getText("rest.missing.field", STAT_TYPE)); errors.addReason(ErrorCollection.Reason.VALIDATION_FAILED); } return errors; } }
/** * Get the statistic display name for a statistic. * @param statType name for the statistic * @return either an error or the display name of the stat */ @Nonnull private Either<ErrorCollection, String> getStatDisplayName(@Nonnull final String statType) { final ErrorCollection errors = new SimpleErrorCollection(); final String statTypeDisplayName = statisticTypesProvider.getDisplayName(statType); if (StringUtils.isBlank(statTypeDisplayName)) { errors.addErrorMessage(authenticationContext.getI18nHelper().getText("gadget.common.invalid.stat.type", statType)); errors.addReason(ErrorCollection.Reason.VALIDATION_FAILED); return Either.left(errors); } return Either.right(statTypeDisplayName); }
@Override @Nonnull public Either<Query, ErrorCollection> getQuery(@Nullable final ApplicationUser user, @Nonnull final String jql) { final ErrorCollection errors = new SimpleErrorCollection(); final SearchService.ParseResult parseResult = searchService.parseQuery(user, jql); if (!parseResult.isValid()) { errors.addErrorMessages(parseResult.getErrors().getErrorMessages()); errors.addReason(ErrorCollection.Reason.VALIDATION_FAILED); return Either.right(errors); } final Query jqlQuery = parseResult.getQuery(); MessageSet messages = searchService.validateQuery(user, jqlQuery); if (messages.hasAnyErrors()) { errors.addErrorMessages(messages.getErrorMessages()); errors.addReason(ErrorCollection.Reason.VALIDATION_FAILED); return Either.right(errors); } return Either.left(jqlQuery); } }
private Issue checkIssuePermission(ErrorCollection errorCollection, Issue issue) { if (issue == null) { errorCollection.addErrorMessage(authContext.getI18nHelper().getText("issue.does.not.exist.title"), ErrorCollection.Reason.NOT_FOUND); return null; } final ApplicationUser user = authContext.getUser(); if (!permissionManager.hasPermission(Permissions.BROWSE, issue, user)) { errorCollection.addErrorMessage(authContext.getI18nHelper().getText("admin.errors.issues.no.permission.to.see")); if (isAnonymous(user)) { errorCollection.addErrorMessage(authContext.getI18nHelper().getText("login.required.title"), ErrorCollection.Reason.NOT_LOGGED_IN); } else { errorCollection.addReason(ErrorCollection.Reason.FORBIDDEN); } return null; } else { return issue; } } }
/** * Perform a one dimensional search for a filter with a certain id * * @param filterId The id of the filter whose results we want. * @param statType The statistic type to groups search results by. * @return Errors or the result of the jql query. An error will be returned if a filter with this `filterId` cannot * be found. */ private Either<OneDimensionalStatisticsResultBean, ErrorCollection> oneDimensionalSearchForFilter(final Long filterId, final String statType) { final JiraServiceContextImpl jiraServiceContext = new JiraServiceContextImpl(authenticationContext.getLoggedInUser()); final SearchRequest filter = searchRequestService.getFilter(jiraServiceContext, filterId); if (filter == null) { ErrorCollection errors = new SimpleErrorCollection(); errors.addErrorMessage(authenticationContext.getI18nHelper().getText("rest.error.generating.response", FILTER_ID)); errors.addReason(ErrorCollection.Reason.NOT_FOUND); return Either.right(errors); } Either<OneDimensionalStatisticsResultBean, ErrorCollection> searchResult = oneDimensionalSearchWithJql(filterId, searchService.getJqlString(filter.getQuery()), statType); // Construct a new statistics result so that we can change the filter's name from 'JQL Query' to the actual filter name. if (searchResult.isLeft()) { final OneDimensionalStatisticsResultBean oldResult = searchResult.left().get(); final StatisticsSearchResultBean newBean = new StatisticsSearchResultBean(oldResult.getIssueCount(), oldResult.getResults()); final OneDimensionalStatisticsResultBean newResult = new OneDimensionalStatisticsResultBean(filter.getName(), oldResult.getFilterUrl(), oldResult.getStatType(), newBean); return Either.left(newResult); } return searchResult; }