private static void validateMessageFeatureId(final String expectedFeatureId, final Message<?> message, final DittoHeaders dittoHeaders) { final Optional<String> messageFeatureIdOptional = message.getFeatureId(); if (!messageFeatureIdOptional.isPresent()) { final String msgPattern = "The Message did not contain a feature ID at all! Expected was feature ID <{0}>."; throw FeatureIdInvalidException.newBuilder() .message(MessageFormat.format(msgPattern, expectedFeatureId)) .dittoHeaders(dittoHeaders) .build(); } final String messageFeatureId = messageFeatureIdOptional.get(); if (!messageFeatureId.equals(expectedFeatureId)) { final String msgPattern = "The Message contained feature ID <{0}>. Expected was feature ID <{1}>."; throw FeatureIdInvalidException.newBuilder() .message(MessageFormat.format(msgPattern, messageFeatureId, expectedFeatureId)) .dittoHeaders(dittoHeaders) .build(); } }
/** * Constructs a new {@code FeatureIdInvalidException} object with the given exception message. * * @param message detail message. This message can be later retrieved by the {@link #getMessage()} method. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new FeatureIdInvalidException. * @throws NullPointerException if {@code dittoHeaders} is {@code null}. */ public static FeatureIdInvalidException fromMessage(@Nullable final String message, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(message) .build(); }
/** * Constructs a new {@code FeatureIdInvalidException} object with the exception message extracted from the * given JSON object. * * @param jsonObject the JSON to read the {@link JsonFields#MESSAGE} field from. * @param dittoHeaders the headers of the command which resulted in this exception. * @return the new FeatureIdInvalidException. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the * {@link JsonFields#MESSAGE} field. */ public static FeatureIdInvalidException fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(readMessage(jsonObject)) .description(readDescription(jsonObject).orElse(DEFAULT_DESCRIPTION)) .href(readHRef(jsonObject).orElse(null)) .build(); }
private static void validateMessageFeatureId(final String expectedFeatureId, final Message<?> message, final DittoHeaders dittoHeaders) { final Optional<String> messageFeatureIdOptional = message.getFeatureId(); if (!messageFeatureIdOptional.isPresent()) { final String msgPattern = "The Message did not contain a feature ID at all! Expected was feature ID <{0}>."; throw FeatureIdInvalidException.newBuilder() .message(MessageFormat.format(msgPattern, expectedFeatureId)) .dittoHeaders(dittoHeaders) .build(); } final String messageFeatureId = messageFeatureIdOptional.get(); if (!messageFeatureId.equals(expectedFeatureId)) { final String msgPattern = "The Message contained feature ID <{0}>. Expected was feature ID <{1}>."; throw FeatureIdInvalidException.newBuilder() .message(MessageFormat.format(msgPattern, messageFeatureId, expectedFeatureId)) .dittoHeaders(dittoHeaders) .build(); } }
/** * A mutable builder for a {@code FeatureIdInvalidException}. * * @return the builder. */ public static Builder newBuilder() { return new Builder(); }
private Builder() { message(MESSAGE_TEMPLATE); description(DEFAULT_DESCRIPTION); }