/** * Returns an instance of {@code PurgeNamespaceResponse} which indicates a successful namespace purge. * * @param namespace the namespace the returned response relates to. * @param resourceType type of the {@code Resource} represented by the returned response. * @param dittoHeaders the headers of the command which caused the returned response. * @return a response for a successful namespace purge. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code namespace} or {@code resourceType} is empty. */ public static PurgeNamespaceResponse successful(final CharSequence namespace, final CharSequence resourceType, final DittoHeaders dittoHeaders) { return new PurgeNamespaceResponse(namespace, resourceType, true, dittoHeaders); }
/** * Returns an instance of {@code PurgeNamespaceResponse} which indicates that a namespace purge failed. * * @param namespace the namespace the returned response relates to. * @param resourceType type of the {@code Resource} represented by the returned response. * @param dittoHeaders the headers of the command which caused the returned response. * @return a response for a failed namespace purge. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code namespace} or {@code resourceType} is empty. */ public static PurgeNamespaceResponse failed(final CharSequence namespace, final CharSequence resourceType, final DittoHeaders dittoHeaders) { return new PurgeNamespaceResponse(namespace, resourceType, false, dittoHeaders); }
@Override public PurgeNamespaceResponse setDittoHeaders(final DittoHeaders dittoHeaders) { if (Objects.equals(getDittoHeaders(), dittoHeaders)) { return this; } return new PurgeNamespaceResponse(getNamespace(), getResourceType(), isSuccessful(), dittoHeaders); }
/** * Creates a new {@code PurgeNamespaceResponse} from the given JSON object. * * @param jsonObject the JSON object of which the PurgeNamespaceResponse is to be created. * @param headers the headers. * @return the deserialized response. * @throws NullPointerException if any argument is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} was not in the expected format. * @throws org.eclipse.ditto.json.JsonMissingFieldException if {@code jsonObject} did not contain * <ul> * <li>{@link org.eclipse.ditto.signals.commands.namespaces.NamespaceCommandResponse.JsonFields#NAMESPACE},</li> * <li>{@link org.eclipse.ditto.signals.commands.namespaces.NamespaceCommandResponse.JsonFields#RESOURCE_TYPE} or</li> * <li>{@link JsonFields#SUCCESSFUL}.</li> * </ul> */ public static PurgeNamespaceResponse fromJson(final JsonObject jsonObject, final DittoHeaders headers) { return new CommandResponseJsonDeserializer<PurgeNamespaceResponse>(TYPE, jsonObject).deserialize(statusCode -> { final String namespace = jsonObject.getValueOrThrow(NamespaceCommandResponse.JsonFields.NAMESPACE); final String resourceType = jsonObject.getValueOrThrow(NamespaceCommandResponse.JsonFields.RESOURCE_TYPE); final Boolean isSuccessful = jsonObject.getValueOrThrow(JsonFields.SUCCESSFUL); return new PurgeNamespaceResponse(namespace, resourceType, isSuccessful, headers); }); }