private Builder(@Nullable final CharSequence policyId) { this(); message(MessageFormat.format(MESSAGE_TEMPLATE, policyId)); }
/** * Returns a Command for creating a new Policy which is passed as argument. * * @param policy the Policy to create. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if any argument is {@code null}. * @throws PolicyIdInvalidException if the {@link Policy}'s ID is not valid. */ public static CreatePolicy of(final Policy policy, final DittoHeaders dittoHeaders) { Objects.requireNonNull(policy, "The Policy must not be null!"); if (!policy.getId().isPresent()) { throw PolicyIdInvalidException.newBuilder("") .message("Policy ID must be present in 'CreatePolicy' payload") .dittoHeaders(dittoHeaders) .build(); } return new CreatePolicy(policy, dittoHeaders); }
/** * Returns a Command for creating a new Policy which is passed as argument. * * @param policy the Policy to create. * @param dittoHeaders the headers of the command. * @return the command. * @throws NullPointerException if any argument is {@code null}. * @throws PolicyIdInvalidException if the {@link Policy}'s ID is not valid. */ public static CreatePolicy of(final Policy policy, final DittoHeaders dittoHeaders) { Objects.requireNonNull(policy, "The Policy must not be null!"); if (!policy.getId().isPresent()) { throw PolicyIdInvalidException.newBuilder("") .message("Policy ID must be present in 'CreatePolicy' payload") .dittoHeaders(dittoHeaders) .build(); } return new CreatePolicy(policy, dittoHeaders); }
/** * Constructs a new {@code PolicyIdInvalidException} 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 PolicyIdInvalidException. * @throws NullPointerException if {@code dittoHeaders} is {@code null}. */ public static PolicyIdInvalidException fromMessage(@Nullable final String message, final DittoHeaders dittoHeaders) { return new Builder() .message(message) .dittoHeaders(dittoHeaders) .build(); }