private String toString(final ErrorCollection collection) { return String.format("Errors: [%s, %s, %s]", collection.getErrors(), collection.getErrorMessages(), collection.getReasons()); } }
private static void throwForFirstError(ErrorCollection collection) throws AttachmentException { if (collection.hasAnyErrors()) { String message = getFirstElement(collection.getErrorMessages()); if (message == null) { message = getFirstElement(collection.getErrors().values()); } throw new AttachmentException(message); } }
private ErrorCollection convertAllDelegatedUserErrorsToMessages(ErrorCollection errorCollection) { final ErrorCollection errors = new SimpleErrorCollection(); errors.addErrorMessages(errorCollection.getErrorMessages()); String delegatedUserError = errorCollection.getErrors().get(ShareTypeValidator.DELEGATED_ERROR_KEY); if (StringUtils.isNotBlank(delegatedUserError)) { errors.addErrorMessage(delegatedUserError); } return errors; }
private void populateErrorCollection(final ErrorCollection collectionToBeAddedTo, final ErrorCollection collectionContainingErrors) { if (collectionContainingErrors.hasAnyErrors()) { collectionToBeAddedTo.addErrorCollection(collectionContainingErrors); } } }
private static String getFirstErrorMessage(final ErrorCollection collection) { final Iterable<String> allErrors = Iterables.concat( collection.getErrorMessages(), mapValues(collection.getErrors())); final String firstErrorMessage = Iterables.getFirst(allErrors, null); return Preconditions.checkNotNull(firstErrorMessage, "Expected to find error message but cannot find one!"); }
@Override public Boolean apply(final E input) { ErrorCollection permissionCheckResults = permissionFunction.apply(user, input); if (permissionCheckResults.hasAnyErrors()) { errorCollection.addErrorCollection(permissionCheckResults); } return !permissionCheckResults.hasAnyErrors(); } }
public Builder addErrorMessage(final String message, final ErrorCollection.Reason reason) { errors.addErrorMessage(message, reason); return this; }
/** * Asserts that the given ErrorCollection contains the given field-specific error. * * @param errorCollection ErrorCollection under test. * @param fieldName The field name that we expected the error for. * @param expectedErrorMessage The expected error message. */ public static void assertFieldError(final ErrorCollection errorCollection, final String fieldName, final String expectedErrorMessage) { assertThat("Error for field " + fieldName, errorCollection.getErrors().get(fieldName), is(expectedErrorMessage)); assertTrue("hasAnyErrors()", errorCollection.hasAnyErrors()); }
protected static void verifyNotBlank(ErrorCollection errors, I18nHelper i18n, String field, String value) { if (StringUtils.isBlank(value)) { errors.addError(field, i18n.getText(MSG_IS_REQUIRED, field), VALIDATION_FAILED); } }
@Override public AddUserToApplicationValidationResult validateAddUserToApplication(ApplicationUser loggedInUser, ApplicationUser user, ApplicationKey applicationKey) { final ErrorCollection errors = new SimpleErrorCollection(); if(loggedInUser == null || !isAdministrator(loggedInUser)) { errors.addErrorMessage(getI18nBean(loggedInUser).getText("admin.errors.users.add.user.to.application.no.permission")); return new AddUserToApplicationValidationResult(errors); } final Collection<String> applicationKeyErrors = applicationHelper.validateApplicationKeys(user, ImmutableSet.of(applicationKey)); errors.addErrorMessages(applicationKeyErrors); if (errors.hasAnyErrors()) { return new AddUserToApplicationValidationResult(errors); } return new AddUserToApplicationValidationResult(user, applicationRoleManager.getDefaultGroups(applicationKey)); }
protected void transferErrorToMessages(ErrorCollection errorCollection) { final Iterator<Map.Entry<String, String>> iterator = errorCollection.getErrors().entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<String, String> entry = iterator.next(); errorCollection.addErrorMessage(entry.getKey() + ": " + entry.getValue()); } }
@Override public DeleteIssueLinkValidationResult validateDelete(ApplicationUser user, Issue issue, IssueLink issueLink) { final ErrorCollection errors = validateIssuePermission(user, issue, Permissions.LINK_ISSUE, "admin.errors.issues.no.permission.to.delete.links"); validateLinkingEnabled(user, errors); if (issueLink == null) { errors.addErrorMessage(beanFactory.getInstance(user).getText("admin.errors.issues.cannot.find.link"), Reason.NOT_FOUND); } return new DeleteIssueLinkValidationResult(errors, errors.hasAnyErrors() ? null : issueLink, user); }
@Override public Response generateErrorResponse(final ErrorCollection errors) { ErrorCollection.Reason worstReason = ErrorCollection.Reason.getWorstReason(errors.getReasons()); int errorCode = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(); if (worstReason != null) { errorCode = worstReason.getHttpStatusCode(); } return Response.status(errorCode).entity(errors.getErrorMessages()).build(); }
void performBackup(final String filename) throws Exception { final com.atlassian.jira.bc.dataimport.ExportService exportService = ComponentAccessor.getComponent(com.atlassian.jira.bc.dataimport.ExportService.class); final JiraAuthenticationContext authenticationContext = ComponentAccessor.getComponent(JiraAuthenticationContext.class); final ServiceOutcome<Void> outcome = exportService.export(authenticationContext.getUser(), filename, TaskProgressSink.NULL_SINK); if (!outcome.isValid()) { throw new AtlassianCoreException(Joiner.on("\n").join(outcome.getErrorCollection().getErrorMessages())); } }
private Errors addErrorCollection(ErrorCollection collection) { errors.addErrorCollection(collection); return this; }
public void validateCommentProperties(Map<String, Object> properties, ErrorCollection errorCollection) { try { final ImmutableMap<String, JSONObject> commentProperties = getCommentPropertiesFromParameters(properties); for (Map.Entry<String, JSONObject> property : commentProperties.entrySet()) { EntityPropertyService.PropertyInput propertyInput = new EntityPropertyService.PropertyInput(property.getValue().toString(), property.getKey()); errorCollection.addErrorCollection(commentPropertyService.validatePropertyInput(propertyInput)); } } catch (JSONException e) { errorCollection.addErrorMessage(i18nFactory.getInstance(authenticationContext.getUser()).getText("jira.properties.service.invalid.json", properties.get(PARAM_COMMENT_PROPERTY))); } }
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); } }
private boolean isValidForCreate(final RemoteIssueLinkResult result) { // The result is still valid if there is only a NOT_FOUND error, as the remote issue link not existing is not an error in this case if (!result.isValid()) { if (result.getErrorCollection().getReasons().contains(Reason.NOT_FOUND) && result.getErrorCollection().getReasons().size() == 1) { return true; } // Errors other than NOT_FOUND return false; } // No errors return true; }
public ErrorMatcher addErrorMessages(final Collection<String> errorMessages) { errorCollection.addErrorMessages(errorMessages); return this; }
private static Response createError(final Response.Status status, final com.atlassian.jira.util.ErrorCollection collection) { String message = getFirst(collection.getErrorMessages(), null); if (message == null) { message = getFirst(collection.getErrors().values(), null); } return createError(status, message); }