/** * Constructs a new {@code ThingIdInvalidException} 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 ThingIdInvalidException. * @throws NullPointerException if {@code dittoHeaders} is {@code null}. */ public static ThingIdInvalidException fromMessage(@Nullable final String message, final DittoHeaders dittoHeaders) { return new Builder() .dittoHeaders(dittoHeaders) .message(message) .build(); }
private void validateThingId(final String thingIdFromMessage, final DittoHeaders dittoHeaders) { final Validator thingIdValidator = IdValidator.newInstance(thingId, THING_ID_REGEX); if (!thingIdValidator.isValid()) { throw ThingIdInvalidException.newBuilder(thingId).dittoHeaders(dittoHeaders).build(); } if (!thingId.equals(thingIdFromMessage)) { final String descTemplate = "It does not match the 'thingId' from the Message the command" + " transports (<{0}>). Please ensure that they are equal."; throw ThingIdInvalidException.newBuilder(thingId) .description(MessageFormat.format(descTemplate, thingIdFromMessage)) .dittoHeaders(dittoHeaders).build(); } }
private void validateThingId(final String thingIdFromMessage, final DittoHeaders dittoHeaders) { final Validator thingIdValidator = IdValidator.newInstance(thingId, THING_ID_REGEX); if (!thingIdValidator.isValid()) { throw ThingIdInvalidException.newBuilder(thingId).dittoHeaders(dittoHeaders).build(); } if (!thingId.equals(thingIdFromMessage)) { final String descTemplate = "It does not match the 'thingId' from the Message the command" + " transports (<{0}>). Please ensure that they are equal."; throw ThingIdInvalidException.newBuilder(thingId) .description(MessageFormat.format(descTemplate, thingIdFromMessage)) .dittoHeaders(dittoHeaders).build(); } }
/** * Constructs a new {@code ThingIdInvalidException} 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 ThingIdInvalidException. * @throws org.eclipse.ditto.json.JsonMissingFieldException if the {@code jsonObject} does not have the {@link * JsonFields#MESSAGE} field. */ public static ThingIdInvalidException 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(); }