private static String normalizeSubject(final String msgSubject) { if (msgSubject.isEmpty() || "/".equals(msgSubject)) { throw SubjectInvalidException.newBuilder(msgSubject).build(); } return msgSubject.charAt(0) == '/' ? msgSubject.substring(1) : msgSubject; }
private Builder(final String subject) { this(); message(MessageFormat.format(MESSAGE_TEMPLATE, subject)); }
/** * Deserialize from a JSON object. * * @param jsonObject the JSON object to deserialize. * @param dittoHeaders the headers. * @return an instance of this class. * @throws NullPointerException if any argument is {@code null}. */ public static SubjectInvalidException fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new Builder() .loadJson(jsonObject) .dittoHeaders(dittoHeaders) .message(readMessage(jsonObject)) .description(readDescription(jsonObject).orElse(DEFAULT_DESCRIPTION)) .href(readHRef(jsonObject).orElse(null)) .build(); }
private Builder() { description(DEFAULT_DESCRIPTION); }
@Override public void validateValue(@Nullable final CharSequence value) { super.validateValue(value); final Validator subjectValidator = IdValidator.newInstance(value, SUBJECT_REGEX); if (!subjectValidator.isValid()) { final String msgTemplate = "The subject <{0}> is invalid because it did not match the pattern <{1}>!"; throw SubjectInvalidException.newBuilder(String.valueOf(value)) .message(() -> MessageFormat.format(msgTemplate, value, SUBJECT_REGEX)) .build(); } } },
/** * A mutable builder for a {@code SubjectInvalidException}. * * @param subject the subject. * @return the builder. */ public static Builder newBuilder(final String subject) { return new Builder(subject); }
/** * Constructs a new {@code SubjectInvalidException} object with the given exception message. * * @param message detail message. This message can be later retrieved by the {@link #getMessage()} method. * @return the new SubjectInvalidException. */ public static SubjectInvalidException fromMessage(final String message) { return new Builder() .message(message) .build(); }