|
16 | 16 |
|
17 | 17 | package com.linecorp.centraldogma.common;
|
18 | 18 |
|
| 19 | +import static com.google.common.base.Preconditions.checkArgument; |
19 | 20 | import static com.linecorp.centraldogma.internal.Util.validateDirPath;
|
20 | 21 | import static com.linecorp.centraldogma.internal.Util.validateFilePath;
|
21 | 22 | import static java.util.Objects.requireNonNull;
|
|
36 | 37 | import com.fasterxml.jackson.annotation.JsonProperty;
|
37 | 38 | import com.fasterxml.jackson.databind.JsonNode;
|
38 | 39 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
| 40 | +import com.google.common.collect.ImmutableList; |
| 41 | +import com.google.common.collect.Iterables; |
39 | 42 |
|
| 43 | +import com.linecorp.centraldogma.common.jsonpatch.JsonPatchOperation; |
40 | 44 | import com.linecorp.centraldogma.internal.Jackson;
|
41 | 45 | import com.linecorp.centraldogma.internal.Util;
|
42 | 46 | import com.linecorp.centraldogma.internal.jsonpatch.JsonPatch;
|
@@ -223,6 +227,43 @@ static Change<JsonNode> ofJsonPatch(String path, @Nullable JsonNode oldJsonNode,
|
223 | 227 | JsonPatch.generate(oldJsonNode, newJsonNode, ReplaceMode.SAFE).toJson());
|
224 | 228 | }
|
225 | 229 |
|
| 230 | + /** |
| 231 | + * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}. |
| 232 | + * |
| 233 | + * @param path the path of the file |
| 234 | + * @param jsonPatch the patch in <a href="https://tools.ietf.org/html/rfc6902">JSON patch format</a> |
| 235 | + */ |
| 236 | + static Change<JsonNode> ofJsonPatch(String path, JsonPatchOperation jsonPatch) { |
| 237 | + requireNonNull(path, "path"); |
| 238 | + requireNonNull(jsonPatch, "jsonPatch"); |
| 239 | + return new DefaultChange<>(path, ChangeType.APPLY_JSON_PATCH, jsonPatch.toJsonNode()); |
| 240 | + } |
| 241 | + |
| 242 | + /** |
| 243 | + * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}. |
| 244 | + * |
| 245 | + * @param path the path of the file |
| 246 | + * @param jsonPatches the list of patches in <a href="https://tools.ietf.org/html/rfc6902">JSON patch format</a> |
| 247 | + */ |
| 248 | + static Change<JsonNode> ofJsonPatch(String path, JsonPatchOperation... jsonPatches) { |
| 249 | + requireNonNull(jsonPatches, "jsonPatches"); |
| 250 | + return ofJsonPatch(path, ImmutableList.copyOf(jsonPatches)); |
| 251 | + } |
| 252 | + |
| 253 | + /** |
| 254 | + * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}. |
| 255 | + * |
| 256 | + * @param path the path of the file |
| 257 | + * @param jsonPatches the list of patches in <a href="https://tools.ietf.org/html/rfc6902">JSON patch format</a> |
| 258 | + */ |
| 259 | + static Change<JsonNode> ofJsonPatch(String path, Iterable<? extends JsonPatchOperation> jsonPatches) { |
| 260 | + requireNonNull(path, "path"); |
| 261 | + requireNonNull(jsonPatches, "jsonPatches"); |
| 262 | + checkArgument(!Iterables.isEmpty(jsonPatches), "jsonPatches cannot be empty"); |
| 263 | + return new DefaultChange<>(path, ChangeType.APPLY_JSON_PATCH, |
| 264 | + JsonPatchOperation.asJsonArray(jsonPatches)); |
| 265 | + } |
| 266 | + |
226 | 267 | /**
|
227 | 268 | * Returns a newly-created {@link Change} whose type is {@link ChangeType#APPLY_JSON_PATCH}.
|
228 | 269 | *
|
|
0 commit comments