@Override public void addErrorMessages(Collection<String> incomingMessages) { if (incomingMessages != null && !incomingMessages.isEmpty()) { for (final String incomingMessage : incomingMessages) { addErrorMessage(incomingMessage); } } }
@Override public void addErrorMessage(String message, Reason reason) { addErrorMessage(message); addReason(reason); }
void addErrorKey(String key, String errorValue, ErrorCollection.Reason reason) { simpleErrorCollection.addErrorMessage(key, reason); if (errorCollection != null) { errorCollection.addErrorMessage(componentService.translateKeyToMessage(key, errorValue), reason); } }
private static ErrorCollection createErrrorCollectionWithMessage(String message){ final SimpleErrorCollection ec = new SimpleErrorCollection(); ec.addErrorMessage(message); return ec; } }
private void throwError(String message) { final SimpleErrorCollection errorCollection = new SimpleErrorCollection(); errorCollection.addErrorMessage(message); throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity(ErrorCollection.of(errorCollection)).cacheControl(never()).build()); } }
public static ErrorCollectionMatcher hasErrorMessage(final String errorMessage) { SimpleErrorCollection errorCollection = new SimpleErrorCollection(); errorCollection.addErrorMessage(errorMessage); return new ErrorCollectionMatcher(errorCollection, false, false); }
/** * Constructs a new ValidationFailureException with an error message, a collection of errors, and a cause. * * @param message a String containing an error message * @param errors an ErrorCollection containing collection of validation errors * @param throwable the Throwable that caused the validation failure */ public ValidationFailureException(String message, ErrorCollection errors, Throwable throwable) { super(message, throwable); SimpleErrorCollection errorsCopy = new SimpleErrorCollection(); if (message != null) { errorsCopy.addErrorMessage(message); } if (errors != null) { errorsCopy.addErrorCollection(errors); } this.errors = errorsCopy; }
@Override public DeletePropertyValidationResult get() { errorCollection.addErrorMessage(i18n.getText("jira.properties.service.property.does.not.exist", propertyKey), NOT_FOUND); return new DeletePropertyValidationResult(errorCollection, Option.<EntityProperty>none()); } }, new Function<EntityProperty, DeletePropertyValidationResult>()
private <T> ServiceOutcome<T> outcomeForReason(Reason reason, String text) { final SimpleErrorCollection simpleErrorCollection = new SimpleErrorCollection(); simpleErrorCollection.addErrorMessage(text); simpleErrorCollection.addReason(reason); return from(simpleErrorCollection, null); }
private SimpleErrorCollection genericPermissionCheck(ApplicationUser user, String errorMessage){ final SimpleErrorCollection ec = new SimpleErrorCollection(); if (!permissionManager.hasPermission(Permissions.ADMINISTER, user)) { ec.addErrorMessage(i18nHelper.getText(errorMessage)); } return ec; }
private void validateFullUpdate(final CreateUpdateRoleRequestBean updateProjectRoleBean, final SimpleErrorCollection errorCollection) { if (updateProjectRoleBean.getName() == null || updateProjectRoleBean.getDescription() == null) { errorCollection.addErrorMessage( i18n.getText("rest.role.name.and.description.required"), ErrorCollection.Reason.VALIDATION_FAILED); } }
private void validatePartialUpdate(final CreateUpdateRoleRequestBean updateProjectRoleBean, final SimpleErrorCollection errorCollection) { if (updateProjectRoleBean.getName() == null && updateProjectRoleBean.getDescription() == null) { errorCollection.addErrorMessage( i18n.getText("rest.role.name.or.description.required"), ErrorCollection.Reason.VALIDATION_FAILED); } }
@Override public Boolean get() { errorCollection.addErrorMessage(i18n.getText("jira.properties.service.entity.does.not.exist", i18n.getText(entityPropertyHelper.getEntityPropertyType().getI18nKeyForEntityName())), NOT_FOUND); return false; } }, new Function<E, Boolean>()
@Override public ServiceResult removeStatus(ApplicationUser user, final Status status) { ServiceResult validationResult = validateRemoveStatus(user, status); if (!validationResult.isValid()) { return validationResult; } final SimpleErrorCollection ec = new SimpleErrorCollection(); try { statusManager.removeStatus(Preconditions.checkNotNull(status).getId()); } catch (IllegalArgumentException e) { ec.addErrorMessage(e.getLocalizedMessage()); } return new ServiceResultImpl(ec); }
@Nonnull @Override public ServiceOutcome<Options> setOptions(@Nonnull final SetValidateResult validation) { if (!(validation instanceof SetValidateResultImpl)) { throw new IllegalArgumentException("Invalid validation result passed."); } SetValidateResultImpl serviceResult = (SetValidateResultImpl) validation; if (!permissionManager.hasPermission(Permissions.ADMINISTER, serviceResult.caller)) { SimpleErrorCollection collection = new SimpleErrorCollection(); collection.addErrorMessage(i18n(serviceResult.caller).getText("admin.options.need.admin"), ErrorCollection.Reason.FORBIDDEN); return ServiceOutcomeImpl.from(collection, null); } setOptions(serviceResult.config, serviceResult.options); return ServiceOutcomeImpl.ok(optionsManager.getOptions(serviceResult.config)); }
private Long getLongOrBadRequest(final String idOrKey) { try { return Long.parseLong(idOrKey); } catch (NumberFormatException e) { SimpleErrorCollection errorCollection = new SimpleErrorCollection(); errorCollection.addErrorMessage(i18n.getText("jira.properties.service.property.invalid.entity", i18n.getText(entityPropertyType.getI18nKeyForEntityName()))); throw new BadRequestWebException(ErrorCollection.of(errorCollection)); } }
public ServiceResult validateRemoveStatus(ApplicationUser user, final Status status) { final SimpleErrorCollection ec = genericPermissionCheck(user, "admin.errors.not.allowed.to.remove.status"); if (ec.hasAnyErrors()) { return new ServiceResultImpl(ec); } final Status systemStatus = statusManager.getStatus(status.getId()); if (systemStatus == null || !systemStatus.equals(status)) { ec.addErrorMessage(i18nHelper.getText("admin.error.given.status.does.not.exist")); } if (hasAssociatedWorkflows(status)) { ec.addErrorMessage(i18nHelper.getText("admin.error.status.is.associated.with.workflow")); } return new ServiceResultImpl(ec); }
protected SetPropertyValidationResult validateSetProperty(ApplicationUser user, Option<E> entity, PropertyInput propertyInput, EntityPropertyOptions options) { checkNotNull(propertyInput); SimpleErrorCollection errorCollection = new SimpleErrorCollection(); if (checkEntity(entity, user, getEditPermissionFunction(options), errorCollection)) { if (StringUtils.isEmpty(propertyInput.getPropertyValue())) { errorCollection.addErrorMessage(i18n.getText("jira.properties.service.empty.value"), VALIDATION_FAILED); } else { errorCollection.addErrorCollection(validatePropertyInput(propertyInput)); } } Option<EntityPropertyInput> property = errorCollection.hasAnyErrors() ? Option.<EntityPropertyInput>none() : Option.some(createInputForPropertySet(entity.get(), propertyInput)); return new SetPropertyValidationResult(errorCollection, property); }
@Override public SingleIssueLinkResult getIssueLink(Long issueLinkId, ApplicationUser user) { Assertions.notNull("issueLinkId", issueLinkId); IssueLink issueLink = issueLinkManager.getIssueLink(issueLinkId); if (issueLink == null) { SimpleErrorCollection simpleErrorCollection = new SimpleErrorCollection(); simpleErrorCollection.addErrorMessage(beanFactory.getInstance(user).getText("rest.issue.link.not.found", issueLinkId.toString())); return new SingleIssueLinkResult(simpleErrorCollection, null); } MutableIssue sourceIssue = issueManager.getIssueObject(issueLink.getSourceId()); ErrorCollection sourceIssueErrors = validateIssuePermission(user, sourceIssue, Permissions.BROWSE); MutableIssue destinationIssue = issueManager.getIssueObject(issueLink.getDestinationId()); ErrorCollection destinationIssueErrors = validateIssuePermission(user, destinationIssue, Permissions.BROWSE); if (sourceIssueErrors.hasAnyErrors() || destinationIssueErrors.hasAnyErrors()) { sourceIssueErrors.getErrors().putAll(destinationIssueErrors.getErrors()); sourceIssueErrors.getErrorMessages().addAll(destinationIssueErrors.getErrorMessages()); return new SingleIssueLinkResult(sourceIssueErrors, null); } return new SingleIssueLinkResult(new SimpleErrorCollection(), issueLink); }
@Override public IssueResult assign(final ApplicationUser user, AssignValidationResult assignResult) { final MutableIssue issue = assignResult.getIssue(); // update the assignee system field OrderableField field = (OrderableField) fieldManager.getField(IssueFieldConstants.ASSIGNEE); FieldLayoutItem fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue).getFieldLayoutItem(field); field.updateIssue(fieldLayoutItem, issue, EasyMap.build(field.getId(), assignResult.getAssigneeId())); final SimpleErrorCollection errorCollection = new SimpleErrorCollection(); try { issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_ASSIGNED, true); } catch (RuntimeException e) { log.error("There was an exception while trying to update the issue '" + issue.getKey() + "'.", e); errorCollection.addErrorMessage(getI18n(user).getText("admin.errors.issues.exception.occured", issue.getKey())); } return new IssueResult(issue, errorCollection); }