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-2016 ForgeRock AS.
15   */
16  
17  package org.forgerock.json.resource;
18  
19  import static org.forgerock.util.promise.Promises.*;
20  
21  import org.forgerock.services.context.Context;
22  import org.forgerock.util.promise.Promise;
23  
24  class InterfaceCollectionInstance implements RequestHandler {
25      private final CollectionResourceProvider provider;
26  
27      InterfaceCollectionInstance(CollectionResourceProvider provider) {
28          this.provider = provider;
29      }
30  
31      @Override
32      public Promise<ActionResponse, ResourceException> handleAction(final Context context,
33              final ActionRequest request) {
34          return provider.actionInstance(Resources.parentOf(context), Resources.idOf(context), request);
35      }
36  
37      @Override
38      public final Promise<ResourceResponse, ResourceException> handleCreate(final Context context,
39              final CreateRequest request) {
40          // TODO: i18n
41          return newExceptionPromise(Resources.newBadRequestException(
42                  "The resource instance %s cannot be created", request.getResourcePath()));
43      }
44  
45      @Override
46      public Promise<ResourceResponse, ResourceException> handleDelete(final Context context,
47              final DeleteRequest request) {
48          return provider.deleteInstance(Resources.parentOf(context), Resources.idOf(context), request);
49      }
50  
51      @Override
52      public Promise<ResourceResponse, ResourceException> handlePatch(final Context context,
53              final PatchRequest request) {
54          return provider.patchInstance(Resources.parentOf(context), Resources.idOf(context), request);
55      }
56  
57      @Override
58      public final Promise<QueryResponse, ResourceException> handleQuery(final Context context,
59              final QueryRequest request, QueryResourceHandler handler) {
60          // TODO: i18n
61          return newExceptionPromise(Resources.newBadRequestException(
62                  "The resource instance %s cannot be queried", request.getResourcePath()));
63      }
64  
65      @Override
66      public Promise<ResourceResponse, ResourceException> handleRead(final Context context,
67              final ReadRequest request) {
68          return provider.readInstance(Resources.parentOf(context), Resources.idOf(context), request);
69      }
70  
71      @Override
72      public Promise<ResourceResponse, ResourceException> handleUpdate(final Context context,
73              final UpdateRequest request) {
74          return provider.updateInstance(Resources.parentOf(context), Resources.idOf(context), request);
75      }
76  
77  }