public SimpleErrorCollection(ErrorCollection errorCollection) { this(Maps.newHashMap(errorCollection.getErrors()), Lists.newLinkedList(errorCollection.getErrorMessages()), Sets.newHashSet(errorCollection.getReasons())); }
private String toString(ErrorCollection errorCollection) { return String.format("[ErrorMessages: {%s}, Errors: {%s}, Reasons: {%s}]", errorCollection.getErrorMessages() == null ? "null" : join(errorCollection.getErrorMessages(), ','), errorCollection.getErrors() == null ? "null" : join(errorCollection.getErrors().entrySet(), ','), errorCollection.getReasons() == null ? "null" : join(errorCollection.getReasons(), ',')); } }
@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(); }
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; }
private String toString(final ErrorCollection collection) { return String.format("Errors: [%s, %s, %s]", collection.getErrors(), collection.getErrorMessages(), collection.getReasons()); } }
/** * Given a list of errors generate a http response * * @param errors generated * @return http response for the worst error */ @Override public Response generateFieldErrorResponse(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.getErrors()).build(); }
@Override protected boolean matchesSafely(final ServiceOutcome<?> serviceOutcome) { final ErrorCollection outcomeCollection = serviceOutcome.getErrorCollection(); return outcomeCollection.getReasons().equals(errorCollection.getReasons()) && outcomeCollection.getErrors().equals(errorCollection.getErrors()) && equalsIgnoreOrder(outcomeCollection.getErrorMessages(), errorCollection.getErrorMessages()); }
private static Response.ResponseBuilder forCollection(ErrorCollection collection, Reason defaultReason) { if (!collection.hasAnyErrors()) { throw new IllegalArgumentException("collection has no errors."); } if (defaultReason == null) { throw new IllegalArgumentException("defaultReason is null"); } Reason worstReason = Reason.getWorstReason(collection.getReasons()); if (worstReason == null) { worstReason = defaultReason; } return Response.status(worstReason.getHttpStatusCode()).entity(of(collection)); }
private Response error(final com.atlassian.jira.util.ErrorCollection errorCollection) { com.atlassian.jira.util.ErrorCollection.Reason reason = com.atlassian.jira.util.ErrorCollection.Reason.getWorstReason(errorCollection.getReasons()); return status(reason.getHttpStatusCode()).entity(ErrorCollection.of(errorCollection)).cacheControl(never()).build(); }
private Response error(final com.atlassian.jira.util.ErrorCollection errorCollection) { Reason reason = Reason.getWorstReason(errorCollection.getReasons()); return status(reason.getHttpStatusCode()) .entity(ErrorCollection.of(errorCollection)) .cacheControl(never()) .build(); }
private static Response responseError(ServiceOutcome<?> outcome) { final ErrorCollection errorCollection = outcome.getErrorCollection(); Reason reason = getWorstReason(errorCollection.getReasons()); if (reason == null) { reason = SERVER_ERROR; } return Response.status(reason.getHttpStatusCode()) .entity(com.atlassian.jira.rest.api.util.ErrorCollection.of(errorCollection)) .cacheControl(never()) .build(); }
private static Response forCollection(ErrorCollection collection, ErrorCollection.Reason defaultReason) { if (!collection.hasAnyErrors()) { throw new IllegalArgumentException("collection has no errors."); } if (defaultReason == null) { throw new IllegalArgumentException("defaultReason is null"); } ErrorCollection.Reason worstReason = ErrorCollection.Reason.getWorstReason(collection.getReasons()); if (worstReason == null) { worstReason = defaultReason; } return build(Response.status(worstReason.getHttpStatusCode()) .entity(com.atlassian.jira.rest.api.util.ErrorCollection.of(collection))); }
/** * Adds all the errors and error messages that are in the given error collection to this error collection. * * @param errorCollection an ErrorCollection * @return this */ public ErrorCollection addErrorCollection(com.atlassian.jira.util.ErrorCollection errorCollection) { errorMessages.addAll(Assertions.notNull(errorCollection).getErrorMessages()); errors.putAll(errorCollection.getErrors()); reason(com.atlassian.jira.util.ErrorCollection.Reason.getWorstReason(errorCollection.getReasons())); return this; }
/** * Generate a generic error response given errors. * * @param errors to generate response with * @return http response. */ private Response createErrorResponse(final ErrorCollection errors) { ErrorCollection.Reason worstReason = ErrorCollection.Reason.getWorstReason(errors.getReasons()); int errorCode = 500; if (worstReason != null) { errorCode = worstReason.getHttpStatusCode(); } return createErrorResponse(errors, errorCode); }
public void addErrorCollection(ErrorCollection errors) { addErrorMessages(errors.getErrorMessages()); addErrors(errors.getErrors()); addReasons(errors.getReasons()); }
@Override public void addErrorCollection(ErrorCollection errors) { addErrorMessages(errors.getErrorMessages()); addErrors(errors.getErrors()); addReasons(errors.getReasons()); }
private ErrorCollection buildAllErrors(final Iterable<ErrorCollection> errorCollections) { final SimpleErrorCollection allErrors = new SimpleErrorCollection(); for (ErrorCollection errorCollection : errorCollections) { allErrors.addErrorMessages(errorCollection.getErrorMessages()); allErrors.addErrors(errorCollection.getErrors()); allErrors.addReasons(errorCollection.getReasons()); } return allErrors; }
if (outcome.getErrorCollection().getReasons().contains(ErrorCollection.Reason.VALIDATION_FAILED))
private Project getProjectByIdOrKey(String projectIdOrKey) { final ProjectService.GetProjectResult result = projectFinder.getGetProjectForActionByIdOrKey(authContext.getUser(), projectIdOrKey, ProjectAction.EDIT_PROJECT_CONFIG); if (result.getErrorCollection().hasAnyErrors()) { final ErrorCollection errors = ErrorCollection.of(result.getErrorCollection()); if (result.getErrorCollection().getReasons().contains(com.atlassian.jira.util.ErrorCollection.Reason.FORBIDDEN)) { throw new NotAuthorisedWebException(errors); } else { throw new NotFoundWebException(errors); } } return result.getProject(); }
errors.addReasons(errorCollection.getReasons());