View Javadoc
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   * An implementation specific action, or operation, upon a JSON resource.
29   */
30  public interface ActionRequest extends Request {
31      /**
32       * The name of the action which is reserved for performing "create" operations.
33       */
34      String ACTION_ID_CREATE = "create";
35  
36      /**
37       * The name of the field which contains the action ID in the JSON representation.
38       */
39      String FIELD_ACTION = "action";
40  
41      /**
42       * The name of the field which contains the action content in the JSON representation.
43       */
44      String FIELD_CONTENT = "content";
45  
46  
47      @Override
48      <R, P> R accept(final RequestVisitor<R, P> v, final P p);
49  
50  
51      @Override
52      ActionRequest addField(JsonPointer... fields);
53  
54  
55      @Override
56      ActionRequest addField(String... fields);
57  
58      /**
59       * Returns the ID of the action to be performed by this action request.
60       *
61       * @return The ID of the action to be performed by this action request.
62       */
63      String getAction();
64  
65      /**
66       * Returns the ID of the action to be performed by this action request as a enum constant of the specified enum
67       * type.  The action ID string and enum constants are compared, ignoring case considerations.
68       *
69       * @param <T>
70       *         the enum type sub-class.
71       * @param type
72       *         the enum type to match constants with the value.
73       * @return the enum constant represented by the Id of the action to be performed by this action request.
74       * @throws IllegalArgumentException
75       *         if {@code type} does not represent an enum type, or if the ID does not match any of the enum's
76       *         constants.
77       * @throws NullPointerException
78       *         if {@code type} is {@code null}.
79       */
80      <T extends Enum<T>> T getActionAsEnum(Class<T> type);
81  
82  
83      @Override
84      String getAdditionalParameter(String name);
85  
86  
87      @Override
88      Map<String, String> getAdditionalParameters();
89  
90      /**
91       * Returns the content of this action request. The structure of the content is defined by the action.
92       *
93       * @return The content of this action request.
94       */
95      JsonValue getContent();
96  
97      @Override
98      List<JsonPointer> getFields();
99  
100 
101     @Override
102     PreferredLocales getPreferredLocales();
103 
104 
105     @Override
106     RequestType getRequestType();
107 
108 
109     @Override
110     String getResourcePath();
111 
112 
113     @Override
114     ResourcePath getResourcePathObject();
115 
116 
117     @Override
118     Version getResourceVersion();
119 
120     /**
121      * Sets the ID of the action to be performed by this action request.
122      *
123      * @param id
124      *         The ID of the action to be performed by this action request.
125      * @return This action request.
126      * @throws UnsupportedOperationException
127      *         If this action request does not permit changes to the action ID.
128      */
129     ActionRequest setAction(String id);
130 
131 
132     @Override
133     ActionRequest setAdditionalParameter(String name, String value) throws BadRequestException;
134 
135     /**
136      * Sets the content of this action request. The structure of the content is defined by the action.
137      *
138      * @param content
139      *         The content of this action request.
140      * @return This action request.
141      * @throws UnsupportedOperationException
142      *         If this action request does not permit changes to the content.
143      */
144     ActionRequest setContent(JsonValue content);
145 
146 
147     @Override
148     ActionRequest setPreferredLocales(PreferredLocales preferredLocales);
149 
150 
151     @Override
152     ActionRequest setResourcePath(ResourcePath path);
153 
154 
155     @Override
156     ActionRequest setResourcePath(String path);
157 
158 
159     @Override
160     ActionRequest setResourceVersion(Version resourceVersion);
161 
162 
163     @Override
164     JsonValue toJsonValue();
165 }