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 update a JSON resource by applying a set of changes to its existing content. See the documentation for 029 * {@link PatchOperation} for more details regarding the various types of patch operation, and their semantics. 030 */ 031public interface PatchRequest extends Request { 032 033 /** 034 * The name of the field which contains the patch content in the JSON representation. 035 */ 036 String FIELD_PATCH = "patch"; 037 038 /** 039 * The name of the field which contains the patch operations in the JSON representation. 040 */ 041 String FIELD_PATCH_OPERATIONS = "patchOperations"; 042 043 /** 044 * The name of the field which contains the resource version in the JSON representation. 045 */ 046 String FIELD_REVISION = "revision"; 047 048 049 @Override 050 <R, P> R accept(final RequestVisitor<R, P> v, final P p); 051 052 053 @Override 054 PatchRequest addField(JsonPointer... fields); 055 056 057 @Override 058 PatchRequest addField(String... fields); 059 060 /** 061 * Adds one or more patch operations which should be performed against the targeted resource. 062 * 063 * @param operations 064 * One or more patch operations which should be performed against the targeted resource. 065 * @return This patch request. 066 * @throws UnsupportedOperationException 067 * If this patch request does not permit changes to the patch operations. 068 */ 069 PatchRequest addPatchOperation(PatchOperation... operations); 070 071 /** 072 * Adds a single patch operation which should be performed against the targeted resource. 073 * 074 * @param operation 075 * The type of patch operation to be performed. 076 * @param field 077 * The field targeted by the patch operation. 078 * @param value 079 * The possibly {@code null} value for the patch operation. 080 * @return This patch request. 081 * @throws UnsupportedOperationException 082 * If this patch request does not permit changes to the patch operations. 083 */ 084 PatchRequest addPatchOperation(String operation, String field, JsonValue value); 085 086 087 @Override 088 String getAdditionalParameter(String name); 089 090 091 @Override 092 Map<String, String> getAdditionalParameters(); 093 094 095 @Override 096 List<JsonPointer> getFields(); 097 098 /** 099 * Returns the list of patch operations which should be performed against the targeted resource. 100 * 101 * @return The list of patch operations which should be performed against the targeted resource (never null). 102 */ 103 List<PatchOperation> getPatchOperations(); 104 105 106 @Override 107 PreferredLocales getPreferredLocales(); 108 109 110 @Override 111 RequestType getRequestType(); 112 113 @Override 114 String getResourcePath(); 115 116 @Override 117 ResourcePath getResourcePathObject(); 118 119 @Override 120 Version getResourceVersion(); 121 122 /** 123 * Returns the expected version information associated with the JSON resource to be patched. Version information can 124 * be used in order to implement multi-version concurrency control (MVCC). 125 * <p> 126 * The returned version information may be {@code null} indicating that the client does not care if the resource has 127 * been modified concurrently. If the version information is non-{@code null}, and it does not match the current 128 * version of the targeted JSON resource, then the patch request will be rejected by the provider. 129 * 130 * @return The expected version information associated with the JSON resource to be patched. 131 */ 132 String getRevision(); 133 134 @Override 135 PatchRequest setAdditionalParameter(String name, String value) throws BadRequestException; 136 137 @Override 138 PatchRequest setPreferredLocales(PreferredLocales preferredLocales); 139 140 @Override 141 PatchRequest setResourcePath(ResourcePath path); 142 143 @Override 144 PatchRequest setResourcePath(String path); 145 146 @Override 147 PatchRequest setResourceVersion(Version resourceVersion); 148 149 /** 150 * Sets the expected version information associated with the JSON resource to be patched. Version information can be 151 * used in order to implement multi-version concurrency control (MVCC). 152 * <p> 153 * The provided version information may be {@code null} indicating that the client does not care if the resource has 154 * been modified concurrently. If the version information is non-{@code null}, and it does not match the current 155 * version of the targeted JSON resource, then the patch request will be rejected by the provider. 156 * 157 * @param version 158 * The expected version information associated with the JSON resource to be patched. 159 * @return This patch request. 160 * @throws UnsupportedOperationException 161 * If this patch request does not permit changes to the version information. 162 */ 163 PatchRequest setRevision(String version); 164 165 @Override 166 JsonValue toJsonValue(); 167}