001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2012-2015 ForgeRock AS.
015 */
016
017package org.forgerock.json.resource;
018
019import java.util.List;
020import java.util.Map;
021
022import org.forgerock.http.routing.Version;
023import org.forgerock.json.JsonPointer;
024import org.forgerock.json.JsonValue;
025import org.forgerock.util.i18n.PreferredLocales;
026
027/**
028 * An implementation specific action, or operation, upon a JSON resource.
029 */
030public interface ActionRequest extends Request {
031    /**
032     * The name of the action which is reserved for performing "create" operations.
033     */
034    String ACTION_ID_CREATE = "create";
035
036    /**
037     * The name of the field which contains the action ID in the JSON representation.
038     */
039    String FIELD_ACTION = "action";
040
041    /**
042     * The name of the field which contains the action content in the JSON representation.
043     */
044    String FIELD_CONTENT = "content";
045
046
047    @Override
048    <R, P> R accept(final RequestVisitor<R, P> v, final P p);
049
050
051    @Override
052    ActionRequest addField(JsonPointer... fields);
053
054
055    @Override
056    ActionRequest addField(String... fields);
057
058    /**
059     * Returns the ID of the action to be performed by this action request.
060     *
061     * @return The ID of the action to be performed by this action request.
062     */
063    String getAction();
064
065    /**
066     * Returns the ID of the action to be performed by this action request as a enum constant of the specified enum
067     * type.  The action ID string and enum constants are compared, ignoring case considerations.
068     *
069     * @param <T>
070     *         the enum type sub-class.
071     * @param type
072     *         the enum type to match constants with the value.
073     * @return the enum constant represented by the Id of the action to be performed by this action request.
074     * @throws IllegalArgumentException
075     *         if {@code type} does not represent an enum type, or if the ID does not match any of the enum's
076     *         constants.
077     * @throws NullPointerException
078     *         if {@code type} is {@code null}.
079     */
080    <T extends Enum<T>> T getActionAsEnum(Class<T> type);
081
082
083    @Override
084    String getAdditionalParameter(String name);
085
086
087    @Override
088    Map<String, String> getAdditionalParameters();
089
090    /**
091     * Returns the content of this action request. The structure of the content is defined by the action.
092     *
093     * @return The content of this action request.
094     */
095    JsonValue getContent();
096
097    @Override
098    List<JsonPointer> getFields();
099
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}