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 Copyrighted [year] [name of copyright owner]". 013 * 014 * Copyright 2012-2015 ForgeRock AS. 015 */ 016 017package org.forgerock.json.resource; 018 019import org.forgerock.services.context.Context; 020import org.forgerock.util.promise.Promise; 021 022/** 023 * An implementation interface for resource providers which exposes a collection 024 * of resource instances. The resource collection supports the following 025 * operations: 026 * <ul> 027 * <li>action 028 * <li>create - with an optional client provided resource ID as part of the 029 * request itself 030 * <li>query 031 * </ul> 032 * Whereas resource instances within the collection support the following 033 * operations: 034 * <ul> 035 * <li>action 036 * <li>delete 037 * <li>patch 038 * <li>read 039 * <li>update 040 * </ul> 041 * <p> 042 * <b>NOTE:</b> field filtering alters the structure of a JSON resource and MUST 043 * only be performed once while processing a request. It is therefore the 044 * responsibility of front-end implementations (e.g. HTTP listeners, Servlets, 045 * etc) to perform field filtering. Request handler and resource provider 046 * implementations SHOULD NOT filter fields, but MAY choose to optimise their 047 * processing in order to return a resource containing only the fields targeted 048 * by the field filters. 049 */ 050public interface CollectionResourceProvider { 051 052 /** 053 * Performs the provided 054 * {@link RequestHandler#handleAction(Context, ActionRequest) action} 055 * against the resource collection. 056 * 057 * @param context 058 * The request server context. 059 * @param request 060 * The action request. 061 * @return A {@code Promise} containing the result of the operation. 062 * @see RequestHandler#handleAction(Context, ActionRequest) 063 */ 064 Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request); 065 066 /** 067 * Performs the provided 068 * {@link RequestHandler#handleAction(Context, ActionRequest) 069 * action} against a resource within the collection. 070 * 071 * @param context 072 * The request server context. 073 * @param resourceId 074 * The ID of the targeted resource within the collection. 075 * @param request 076 * The action request. 077 * @return A {@code Promise} containing the result of the operation. 078 * @see RequestHandler#handleAction(Context, ActionRequest) 079 */ 080 Promise<ActionResponse, ResourceException> actionInstance(Context context, String resourceId, 081 ActionRequest request); 082 083 /** 084 * {@link RequestHandler#handleCreate(Context, CreateRequest) 085 * Adds} a new resource instance to the collection. 086 * <p> 087 * Create requests are targeted at the collection itself and may include a 088 * user-provided resource ID for the new resource as part of the request 089 * itself. The user-provider resource ID may be accessed using the method 090 * {@link CreateRequest#getNewResourceId()}. 091 * 092 * @param context 093 * The request server context. 094 * @param request 095 * The create request. 096 * @return A {@code Promise} containing the result of the operation. 097 * @see RequestHandler#handleCreate(Context, CreateRequest) 098 * @see CreateRequest#getNewResourceId() 099 */ 100 Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request); 101 102 /** 103 * {@link RequestHandler#handleDelete(Context, DeleteRequest) 104 * Removes} a resource instance from the collection. 105 * 106 * @param context 107 * The request server context. 108 * @param resourceId 109 * The ID of the targeted resource within the collection. 110 * @param request 111 * The delete request. 112 * @return A {@code Promise} containing the result of the operation. 113 * @see RequestHandler#handleDelete(Context, DeleteRequest) 114 */ 115 Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String resourceId, 116 DeleteRequest request); 117 118 /** 119 * {@link RequestHandler#handlePatch(Context, PatchRequest) 120 * Patches} an existing resource within the collection. 121 * 122 * @param context 123 * The request server context. 124 * @param resourceId 125 * The ID of the targeted resource within the collection. 126 * @param request 127 * The patch request. 128 * @return A {@code Promise} containing the result of the operation. 129 * @see RequestHandler#handlePatch(Context, PatchRequest) 130 */ 131 Promise<ResourceResponse, ResourceException> patchInstance(Context context, String resourceId, 132 PatchRequest request); 133 134 /** 135 * {@link RequestHandler#handleQuery(Context, QueryRequest, QueryResourceHandler) 136 * Searches} the collection for all resources which match the query request 137 * criteria. 138 * <p> 139 * Implementations must invoke 140 * {@link QueryResourceHandler#handleResource(ResourceResponse)} for each resource 141 * which matches the query criteria. Once all matching resources have been 142 * returned implementations are required to return either a 143 * {@link QueryResponse} if the query has completed successfully, or 144 * {@link ResourceException} if the query did not complete successfully 145 * (even if some matching resources were returned). 146 * 147 * @param context 148 * The request server context. 149 * @param request 150 * The query request. 151 * @param handler 152 * The query resource handler to be notified for each matching 153 * resource. 154 * @return A {@code Promise} containing the result of the operation. 155 * @see RequestHandler#handleQuery(Context, QueryRequest, QueryResourceHandler) 156 */ 157 Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request, 158 QueryResourceHandler handler); 159 160 /** 161 * {@link RequestHandler#handleRead(Context, ReadRequest) 162 * Reads} an existing resource within the collection. 163 * 164 * @param context 165 * The request server context. 166 * @param resourceId 167 * The ID of the targeted resource within the collection. 168 * @param request 169 * The read request. 170 * @return A {@code Promise} containing the result of the operation. 171 * @see RequestHandler#handleRead(Context, ReadRequest) 172 */ 173 Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId, 174 ReadRequest request); 175 176 /** 177 * {@link RequestHandler#handleUpdate(Context, UpdateRequest) 178 * Updates} an existing resource within the collection. 179 * 180 * @param context 181 * The request server context. 182 * @param resourceId 183 * The ID of the targeted resource within the collection. 184 * @param request 185 * The update request. 186 * @return A {@code Promise} containing the result of the operation. 187 * @see RequestHandler#handleUpdate(Context, UpdateRequest) 188 */ 189 Promise<ResourceResponse, ResourceException> updateInstance(Context context, String resourceId, 190 UpdateRequest request); 191}