/
BlockNamespaceResponse.java
94 lines (80 loc) · 3.95 KB
/
BlockNamespaceResponse.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.signals.commands.namespaces;
import javax.annotation.Nullable;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.model.base.common.HttpStatusCode;
import org.eclipse.ditto.model.base.headers.DittoHeaders;
import org.eclipse.ditto.model.base.json.JsonParsableCommandResponse;
import org.eclipse.ditto.signals.commands.base.CommandResponseJsonDeserializer;
/**
* Response to {@link BlockNamespace}.
*/
@JsonParsableCommandResponse(type = BlockNamespaceResponse.TYPE)
public final class BlockNamespaceResponse extends AbstractNamespaceCommandResponse<BlockNamespaceResponse> {
/**
* The type of the {@code BlockNamespaceResponse}.
*/
public static final String TYPE = TYPE_PREFIX + BlockNamespace.NAME;
private BlockNamespaceResponse(final CharSequence namespace, final CharSequence resourceType,
final DittoHeaders dittoHeaders) {
super(namespace, resourceType, TYPE, HttpStatusCode.OK, dittoHeaders);
}
/**
* Returns an instance of {@code BlockNamespaceResponse}.
*
* @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 the instance.
* @throws NullPointerException if any argument is {@code null}.
* @throws IllegalArgumentException if {@code namespace} or {@code resourceType} is empty.
*/
public static BlockNamespaceResponse getInstance(final CharSequence namespace, final CharSequence resourceType,
final DittoHeaders dittoHeaders) {
return new BlockNamespaceResponse(namespace, resourceType, dittoHeaders);
}
/**
* Creates a new {@code BlockNamespaceResponse} from the given JSON object.
*
* @param jsonObject the JSON object of which the BlockNamespaceResponse 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} or</li>
* <li>{@link org.eclipse.ditto.signals.commands.namespaces.NamespaceCommandResponse.JsonFields#RESOURCE_TYPE}.</li>
* </ul>
*/
public static BlockNamespaceResponse fromJson(final JsonObject jsonObject, final DittoHeaders headers) {
return new CommandResponseJsonDeserializer<BlockNamespaceResponse>(TYPE, jsonObject).deserialize(statusCode -> {
final String namespace = jsonObject.getValueOrThrow(NamespaceCommandResponse.JsonFields.NAMESPACE);
final String resourceType = jsonObject.getValueOrThrow(NamespaceCommandResponse.JsonFields.RESOURCE_TYPE);
return new BlockNamespaceResponse(namespace, resourceType, headers);
});
}
@Override
public BlockNamespaceResponse setDittoHeaders(final DittoHeaders dittoHeaders) {
return new BlockNamespaceResponse(getNamespace(), getResourceType(), dittoHeaders);
}
@Override
protected boolean canEqual(@Nullable final Object other) {
return other instanceof BlockNamespaceResponse;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + super.toString() + "]";
}
}