1 /*
2 * The contents of this file are subject to the terms of the Common Development and
3 * Distribution License (the License). You may not use this file except in compliance with the
4 * License.
5 *
6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7 * specific language governing permission and limitations under the License.
8 *
9 * When distributing Covered Software, include this CDDL Header Notice in each file and include
10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11 * Header, with the fields enclosed by brackets [] replaced by your own identifying
12 * information: "Portions Copyright [year] [name of copyright owner]".
13 *
14 * Copyright 2012-2015 ForgeRock AS.
15 */
16
17 package org.forgerock.json.resource;
18
19 import java.util.List;
20 import java.util.Map;
21
22 import org.forgerock.http.routing.Version;
23 import org.forgerock.json.JsonPointer;
24 import org.forgerock.json.JsonValue;
25 import org.forgerock.util.i18n.PreferredLocales;
26
27 /**
28 * A request to update a JSON resource by replacing its existing content with new content.
29 */
30 public interface UpdateRequest extends Request {
31
32 /**
33 * The name of the field which contains the resource content in the JSON representation.
34 */
35 String FIELD_CONTENT = "content";
36
37 /**
38 * The name of the field which contains the resource version in the JSON representation.
39 */
40 String FIELD_REVISION = "revision";
41
42
43 @Override
44 <R, P> R accept(final RequestVisitor<R, P> v, final P p);
45
46
47 @Override
48 UpdateRequest addField(JsonPointer... fields);
49
50
51 @Override
52 UpdateRequest addField(String... fields);
53
54
55 @Override
56 String getAdditionalParameter(String name);
57
58
59 @Override
60 Map<String, String> getAdditionalParameters();
61
62 /**
63 * Returns the content of the JSON resource to be replaced.
64 *
65 * @return The content of the JSON resource to be replaced.
66 */
67 JsonValue getContent();
68
69
70 @Override
71 List<JsonPointer> getFields();
72
73
74 @Override
75 PreferredLocales getPreferredLocales();
76
77
78 @Override
79 RequestType getRequestType();
80
81 @Override
82 String getResourcePath();
83
84 @Override
85 ResourcePath getResourcePathObject();
86
87 @Override
88 Version getResourceVersion();
89
90 /**
91 * Returns the expected version information associated with the JSON resource to be updated. Version information can
92 * be used in order to implement multi-version concurrency control (MVCC).
93 * <p>
94 * The returned version information may be {@code null} indicating that the client does not care if the resource has
95 * been modified concurrently. If the version information is non-{@code null}, and it does not match the current
96 * version of the targeted JSON resource, then the update request will be rejected by the provider.
97 *
98 * @return The expected version information associated with the JSON resource to be updated.
99 */
100 String getRevision();
101
102 @Override
103 UpdateRequest setAdditionalParameter(String name, String value) throws BadRequestException;
104
105 /**
106 * Sets the content of the JSON resource to be replaced.
107 *
108 * @param content
109 * The content of the JSON resource to be replaced.
110 * @return This update request.
111 * @throws UnsupportedOperationException
112 * If this update request does not permit changes to the content.
113 */
114 UpdateRequest setContent(JsonValue content);
115
116
117 @Override
118 UpdateRequest setPreferredLocales(PreferredLocales preferredLocales);
119
120
121 @Override
122 UpdateRequest setResourcePath(String path);
123
124
125 @Override
126 UpdateRequest setResourcePath(ResourcePath path);
127
128
129 @Override
130 UpdateRequest setResourceVersion(Version resourceVersion);
131
132 /**
133 * Sets the expected version information associated with the JSON resource to be updated. Version information can be
134 * used in order to implement multi-version concurrency control (MVCC).
135 * <p>
136 * The provided version information may be {@code null} indicating that the client does not care if the resource has
137 * been modified concurrently. If the version information is non-{@code null}, and it does not match the current
138 * version of the targeted JSON resource, then the update request will be rejected by the provider.
139 *
140 * @param version
141 * The expected version information associated with the JSON resource to be updated.
142 * @return This patch request.
143 * @throws UnsupportedOperationException
144 * If this update request does not permit changes to the version information.
145 */
146 UpdateRequest setRevision(String version);
147
148
149 @Override
150 JsonValue toJsonValue();
151 }