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 * A request to create a new JSON resource. 029 */ 030public interface CreateRequest extends Request { 031 032 /** 033 * The name of the action which is reserved for performing "create" operations. 034 */ 035 String ACTION_ID_CREATE = CreateRequest.ACTION_ID_CREATE; 036 037 /** 038 * The name of the field which contains the resource content in the JSON representation. 039 */ 040 String FIELD_CONTENT = "content"; 041 042 /** 043 * The name of the field which contains the new resource ID in the JSON representation. 044 */ 045 String FIELD_NEW_RESOURCE_ID = "newResourceId"; 046 047 048 @Override 049 <R, P> R accept(final RequestVisitor<R, P> v, final P p); 050 051 052 @Override 053 CreateRequest addField(JsonPointer... fields); 054 055 056 @Override 057 CreateRequest addField(String... fields); 058 059 060 @Override 061 String getAdditionalParameter(String name); 062 063 064 @Override 065 Map<String, String> getAdditionalParameters(); 066 067 /** 068 * Returns the content of the JSON resource to be created. 069 * 070 * @return The content of the JSON resource to be created. 071 */ 072 JsonValue getContent(); 073 074 075 @Override 076 List<JsonPointer> getFields(); 077 078 /** 079 * Returns the client provided ID of the resource to be created. The new resource ID will be appended to the 080 * resource path in order to obtain the full path of the new resource. 081 * <p> 082 * The new resource ID is optional and should be used in cases where the client wishes to determine the path of the 083 * resource to be created. If the new resource ID is not provided then the server will be responsible for generating 084 * the ID of the new resource. 085 * 086 * @return The client provided ID of the resource to be created, or {@code null} if the server should be responsible 087 * for generating the resource ID. 088 * @see #getResourcePath() 089 */ 090 String getNewResourceId(); 091 092 093 @Override 094 PreferredLocales getPreferredLocales(); 095 096 097 @Override 098 RequestType getRequestType(); 099 100 /** 101 * Returns the path of the JSON resource container beneath which the new resource should be created. 102 * <p> 103 * The path of the newly created resource will be the concatenation of the resource path and either the client 104 * provided resource ID, if provided, or a server generated resource ID. 105 * 106 * @return The path of the JSON resource container beneath which the new resource should be created. 107 * @see #getNewResourceId() 108 */ 109 @Override 110 String getResourcePath(); 111 112 113 @Override 114 ResourcePath getResourcePathObject(); 115 116 117 @Override 118 Version getResourceVersion(); 119 120 121 @Override 122 CreateRequest setAdditionalParameter(String name, String value) throws BadRequestException; 123 124 /** 125 * Sets the content of the JSON resource to be created. 126 * 127 * @param content 128 * The content of the JSON resource to be created. 129 * @return This create request. 130 * @throws UnsupportedOperationException 131 * If this create request does not permit changes to the content. 132 */ 133 CreateRequest setContent(JsonValue content); 134 135 /** 136 * Sets the client provided ID of the resource to be created. The new resource ID will be appended to the resource 137 * path in order to obtain the full path of the new resource. 138 * <p> 139 * The new resource ID is optional and should be used in cases where the client wishes to determine the path of the 140 * resource to be created. If the new resource ID is not provided then the server will be responsible for generating 141 * the ID of the new resource. 142 * 143 * @param id 144 * The client provided ID of the resource to be created, or {@code null} if the server should be responsible 145 * for generating the resource ID. 146 * @return This create request. 147 * @throws UnsupportedOperationException 148 * If this create request does not permit changes to the new resource ID. 149 * @see #setResourcePath(String) 150 */ 151 CreateRequest setNewResourceId(String id); 152 153 154 @Override 155 CreateRequest setPreferredLocales(PreferredLocales preferredLocales); 156 157 /** 158 * Sets the path of the JSON resource container beneath which the new resource should be created. 159 * <p> 160 * The path of the newly created resource will be the concatenation of the resource path and either the client 161 * provided resource ID, if provided, or a server generated resource ID. 162 * 163 * @param path 164 * The path of the JSON resource container beneath which the new resource should be created. 165 * @return This create request. 166 * @throws UnsupportedOperationException 167 * If this create request does not permit changes to the resource path. 168 * @see #setNewResourceId(String) 169 */ 170 @Override 171 CreateRequest setResourcePath(String path); 172 173 174 @Override 175 CreateRequest setResourcePath(ResourcePath path); 176 177 178 @Override 179 CreateRequest setResourceVersion(Version resourceVersion); 180 181 182 @Override 183 JsonValue toJsonValue(); 184}