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 Copyrighted [year] [name of copyright owner]".
13   *
14   * Copyright 2012-2015 ForgeRock AS.
15   */
16  
17  package org.forgerock.json.resource;
18  
19  import org.forgerock.services.context.Context;
20  import org.forgerock.util.promise.Promise;
21  
22  /**
23   * An implementation interface for resource providers which exposes a single
24   * permanent resource instance. A singleton resource may support the following
25   * operations:
26   * <ul>
27   * <li>action
28   * <li>patch
29   * <li>read
30   * <li>update
31   * </ul>
32   * More specifically, a singleton resource cannot be created, deleted, or
33   * queried and may only support a limited sub-set of actions.
34   * <p>
35   * <b>NOTE:</b> field filtering alters the structure of a JSON resource and MUST
36   * only be performed once while processing a request. It is therefore the
37   * responsibility of front-end implementations (e.g. HTTP listeners, Servlets,
38   * etc) to perform field filtering. Request handler and resource provider
39   * implementations SHOULD NOT filter fields, but MAY choose to optimise their
40   * processing in order to return a resource containing only the fields targeted
41   * by the field filters.
42   */
43  public interface SingletonResourceProvider {
44  
45      /**
46       * Performs the provided
47       * {@link RequestHandler#handleAction(Context, ActionRequest)
48       * action} against the single resource instance.
49       *
50       * @param context
51       *            The request server context.
52       * @param request
53       *            The action request.
54       * @return A {@code Promise} containing the result of the operation.
55       * @see RequestHandler#handleAction(Context, ActionRequest)
56       */
57      Promise<ActionResponse, ResourceException> actionInstance(Context context, ActionRequest request);
58  
59      /**
60       * {@link RequestHandler#handlePatch(Context, PatchRequest)
61       * Patches} the single resource instance.
62       *
63       * @param context
64       *            The request server context.
65       * @param request
66       *            The patch request.
67       * @return A {@code Promise} containing the result of the operation.
68       * @see RequestHandler#handlePatch(Context, PatchRequest)
69       */
70      Promise<ResourceResponse, ResourceException> patchInstance(Context context, PatchRequest request);
71  
72      /**
73       * {@link RequestHandler#handleRead(Context, ReadRequest)
74       * Reads} the single resource instance.
75       *
76       * @param context
77       *            The request server context.
78       * @param request
79       *            The read request.
80       * @return A {@code Promise} containing the result of the operation.
81       * @see RequestHandler#handleRead(Context, ReadRequest)
82       */
83      Promise<ResourceResponse, ResourceException> readInstance(Context context, ReadRequest request);
84  
85      /**
86       * {@link RequestHandler#handleUpdate(Context, UpdateRequest)
87       * Updates} the single resource instance.
88       *
89       * @param context
90       *            The request server context.
91       * @param request
92       *            The update request.
93       * @return A {@code Promise} containing the result of the operation.
94       * @see RequestHandler#handleUpdate(Context, UpdateRequest)
95       */
96      Promise<ResourceResponse, ResourceException> updateInstance(Context context, UpdateRequest request);
97  }