/** * A mutable builder for a {@code MessageNotSendableException}. * * @param thingId the ID of the Thing for which a message should be sent. * @return the builder. */ public static Builder newBuilder(@Nullable final String thingId) { return new Builder(thingId); }
private Builder(@Nullable 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 MessageSendNotAllowedException 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); }
private void rejectMessageCommand(final MessageCommand command, final ActorRef sender) { final MessageSendNotAllowedException error = MessageSendNotAllowedException.newBuilder(command.getThingId()) .dittoHeaders(command.getDittoHeaders()) .build(); log(command).info( "The command <{}> was not forwarded due to insufficient rights {}: {} - AuthorizationSubjects: {}", command.getType(), error.getClass().getSimpleName(), error.getMessage(), command.getDittoHeaders().getAuthorizationSubjects()); replyToSender(error, sender); }
/** * Constructs a new {@code MessageNotSendableException} 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 MessageSendNotAllowedException fromMessage(@Nullable final String message) { return new Builder() .message(message) .build(); }