protected static void verifyNotNull(ErrorCollection errors, I18nHelper i18n, String field, Object value) { if (value == null) { errors.addError(field, i18n.getText(MSG_IS_REQUIRED, field), VALIDATION_FAILED); } }
public String asString(String fieldName, ErrorCollection errors) { if (isString()) { return (String) data; } else { errors.addError(fieldName, "expected a string", ErrorCollection.Reason.VALIDATION_FAILED); return null; } }
private static String asObjectWithProperty(Object o, String propertyname, String fieldName, boolean expected, ErrorCollection errors) { Object value = propertyFromObject(o, propertyname, fieldName, expected, errors); if (value != null && !(value instanceof String)) { errors.addError(fieldName, String.format("expected '%s' property to be a string", propertyname), ErrorCollection.Reason.VALIDATION_FAILED); return null; } return (String) value; } private static Object propertyFromObject(Object o, String propertyname, String fieldName, boolean expected, ErrorCollection errors)
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); } }
void addErrorKey(String fieldName, String key, String errorValue, ErrorCollection.Reason reason) { simpleErrorCollection.addError(fieldName, key, reason); if (errorCollection != null) { errorCollection.addError(fieldName, componentService.translateKeyToMessage(key, errorValue), reason); } }
private void transferErrorMessages(ErrorCollection errorCollection, Collection<String> errorMessages) { for (String errMsg : errorMessages) { errorCollection.addError(getId(), errMsg); } }
protected void validateChangedValue(@Nonnull final String fieldId, @Nonnull final ChangedValue value, @Nonnull final ErrorCollection errorCollection, @Nonnull final I18nHelper i18nBean) { if (isBlank(value.getName())) { errorCollection.addError(fieldId, i18nBean.getText("jira.auditing.service.field.must.be.set", "name")); } }
@Override protected Collection<String> handleRemoveOperation(IssueContext issueCtx, Issue issue, String fieldId, Collection<String> currentFieldValue, JsonData operationValue, ErrorCollection errors) { if (!operationValue.isString()) { errors.addError(IssueFieldConstants.LABELS, i18nHelper.getText("rest.operation.must.be.string"), ErrorCollection.Reason.VALIDATION_FAILED); return currentFieldValue; } return copyOf(filter(currentFieldValue, not(equalTo(operationValue.asString())))); }
public String asObjectWithProperty(String propertyname, String fieldName, boolean expected, ErrorCollection errors) { if (isObject()) { return asObjectWithProperty(data, propertyname, fieldName, expected, errors); } else { errors.addError(fieldName, "data was not an object", ErrorCollection.Reason.VALIDATION_FAILED); return null; } }
private Option<ErrorCollection> errorCollection(final String field, final String text, final ErrorCollection.Reason reason) { final ErrorCollection errorCollection = new SimpleErrorCollection(); errorCollection.addError(field, text, reason); return some(errorCollection); }
/** * Convenience method for adding internationalized errors to the error collection * * @param context jira service context * @param fieldName field name * @param i18nKey message key */ protected void addI18nError(JiraServiceContext context, String fieldName, String i18nKey) { context.getErrorCollection().addError(fieldName, getText(i18nKey)); }
private void validateProjectLead(final Option<ApplicationUser> lead, final ErrorCollection errorCollection, final I18nHelper i18nBean) { if (lead.isEmpty()) { errorCollection.addError(PROJECT_LEAD, i18nBean.getText("admin.errors.must.specify.project.lead")); } }
@Override protected String handleSetOperation(IssueContext issueCtx, Issue issue, String fieldId, String currentFieldValue, JsonData operationValue, ErrorCollection errors) { if (!operationValue.isString()) { errors.addError(IssueFieldConstants.SUMMARY, i18nHelper.getText("rest.operation.must.be.string"), ErrorCollection.Reason.VALIDATION_FAILED); } return operationValue.asString(); } }
public void validateParams(final ApplicationUser user, SearchContext searchContext, FieldValuesHolder fieldValuesHolder, I18nHelper i18nHelper, ErrorCollection errors) { final String query = (String) fieldValuesHolder.get(id); if (StringUtils.isNotBlank(query)) { final MessageSet validationResult = textQueryValidator.validate(createQueryParser(), query, id, null, true, i18nHelper); for (final String errorMessage : validationResult.getErrorMessages()) { errors.addError(id, errorMessage); } } }
@Override protected String handleSetOperation(IssueContext issueCtx, Issue issue, String fieldId, String currentFieldValue, JsonData operationValue, ErrorCollection errors) { if (!operationValue.isString()) { errors.addError(IssueFieldConstants.DESCRIPTION, i18nHelper.getText("rest.operation.must.be.string"), ErrorCollection.Reason.VALIDATION_FAILED); } return operationValue.asString(); }
public void validateFromParams(CustomFieldParams relevantParams, ErrorCollection errorCollectionToAddTo, FieldConfig config) { try { getValueFromCustomFieldParams(relevantParams); } catch (FieldValidationException e) { errorCollectionToAddTo.addError(config.getCustomField().getId(), e.getMessage(), Reason.VALIDATION_FAILED); } }
@Override public void validateFromParams(final CustomFieldParams relevantParams, final ErrorCollection errorCollectionToAddTo, final FieldConfig config) { try { getValueFromCustomFieldParams(relevantParams); } catch (FieldValidationException e) { errorCollectionToAddTo.addError(config.getCustomField().getId(), e.getMessage(), Reason.VALIDATION_FAILED); } }
@Override protected String handleSetOperation(IssueContext issueCtx, Issue issue, String fieldId, String currentFieldValue, JsonData operationValue, ErrorCollection errors) { if (!operationValue.isNull() && !operationValue.isString()) { errors.addError(IssueFieldConstants.DUE_DATE, i18nHelper.getText("rest.operation.must.be.string"), ErrorCollection.Reason.VALIDATION_FAILED); } return operationValue.asString(); }
@Override public void apply(final Pair<String, ErrorCollection.Reason> error) { errors.addError(nameFieldName, authenticationContext.getI18nHelper().getText(error.first()), error.second()); } });
@Override public DeleteUserValidationResult validateDeleteUser(final ApplicationUser loggedInUser, final String username) { final I18nHelper i18nBean = getI18nBean(loggedInUser); final ErrorCollection errors = new SimpleErrorCollection(); if (username == null || username.length() == 0) { errors.addError("username", i18nBean.getText("admin.errors.users.cannot.delete.due.to.invalid.username")); return new DeleteUserValidationResult(errors); } return validateDeleteUser(loggedInUser, userManager.getUserByName(username)); }