001package com.box.sdkgen.managers.folderwatermarks; 002 003import static com.box.sdkgen.internal.utils.UtilsManager.convertToString; 004import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; 005import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps; 006import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams; 007 008import com.box.sdkgen.networking.auth.Authentication; 009import com.box.sdkgen.networking.fetchoptions.FetchOptions; 010import com.box.sdkgen.networking.fetchoptions.ResponseFormat; 011import com.box.sdkgen.networking.fetchresponse.FetchResponse; 012import com.box.sdkgen.networking.network.NetworkSession; 013import com.box.sdkgen.schemas.watermark.Watermark; 014import com.box.sdkgen.serialization.json.JsonManager; 015import java.util.Map; 016 017public class FolderWatermarksManager { 018 019 public Authentication auth; 020 021 public NetworkSession networkSession; 022 023 public FolderWatermarksManager() { 024 this.networkSession = new NetworkSession(); 025 } 026 027 protected FolderWatermarksManager(Builder builder) { 028 this.auth = builder.auth; 029 this.networkSession = builder.networkSession; 030 } 031 032 /** 033 * Retrieve the watermark for a folder. 034 * 035 * @param folderId The unique identifier that represent a folder. 036 * <p>The ID for any folder can be determined by visiting this folder in the web application 037 * and copying the ID from the URL. For example, for the URL 038 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 039 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 040 */ 041 public Watermark getFolderWatermark(String folderId) { 042 return getFolderWatermark(folderId, new GetFolderWatermarkHeaders()); 043 } 044 045 /** 046 * Retrieve the watermark for a folder. 047 * 048 * @param folderId The unique identifier that represent a folder. 049 * <p>The ID for any folder can be determined by visiting this folder in the web application 050 * and copying the ID from the URL. For example, for the URL 051 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 052 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 053 * @param headers Headers of getFolderWatermark method 054 */ 055 public Watermark getFolderWatermark(String folderId, GetFolderWatermarkHeaders headers) { 056 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 057 FetchResponse response = 058 this.networkSession 059 .getNetworkClient() 060 .fetch( 061 new FetchOptions.Builder( 062 String.join( 063 "", 064 this.networkSession.getBaseUrls().getBaseUrl(), 065 "/2.0/folders/", 066 convertToString(folderId), 067 "/watermark"), 068 "GET") 069 .headers(headersMap) 070 .responseFormat(ResponseFormat.JSON) 071 .auth(this.auth) 072 .networkSession(this.networkSession) 073 .build()); 074 return JsonManager.deserialize(response.getData(), Watermark.class); 075 } 076 077 /** 078 * Applies or update a watermark on a folder. 079 * 080 * @param folderId The unique identifier that represent a folder. 081 * <p>The ID for any folder can be determined by visiting this folder in the web application 082 * and copying the ID from the URL. For example, for the URL 083 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 084 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 085 * @param requestBody Request body of updateFolderWatermark method 086 */ 087 public Watermark updateFolderWatermark( 088 String folderId, UpdateFolderWatermarkRequestBody requestBody) { 089 return updateFolderWatermark(folderId, requestBody, new UpdateFolderWatermarkHeaders()); 090 } 091 092 /** 093 * Applies or update a watermark on a folder. 094 * 095 * @param folderId The unique identifier that represent a folder. 096 * <p>The ID for any folder can be determined by visiting this folder in the web application 097 * and copying the ID from the URL. For example, for the URL 098 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 099 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 100 * @param requestBody Request body of updateFolderWatermark method 101 * @param headers Headers of updateFolderWatermark method 102 */ 103 public Watermark updateFolderWatermark( 104 String folderId, 105 UpdateFolderWatermarkRequestBody requestBody, 106 UpdateFolderWatermarkHeaders headers) { 107 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 108 FetchResponse response = 109 this.networkSession 110 .getNetworkClient() 111 .fetch( 112 new FetchOptions.Builder( 113 String.join( 114 "", 115 this.networkSession.getBaseUrls().getBaseUrl(), 116 "/2.0/folders/", 117 convertToString(folderId), 118 "/watermark"), 119 "PUT") 120 .headers(headersMap) 121 .data(JsonManager.serialize(requestBody)) 122 .contentType("application/json") 123 .responseFormat(ResponseFormat.JSON) 124 .auth(this.auth) 125 .networkSession(this.networkSession) 126 .build()); 127 return JsonManager.deserialize(response.getData(), Watermark.class); 128 } 129 130 /** 131 * Removes the watermark from a folder. 132 * 133 * @param folderId The unique identifier that represent a folder. 134 * <p>The ID for any folder can be determined by visiting this folder in the web application 135 * and copying the ID from the URL. For example, for the URL 136 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 137 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 138 */ 139 public void deleteFolderWatermark(String folderId) { 140 deleteFolderWatermark(folderId, new DeleteFolderWatermarkHeaders()); 141 } 142 143 /** 144 * Removes the watermark from a folder. 145 * 146 * @param folderId The unique identifier that represent a folder. 147 * <p>The ID for any folder can be determined by visiting this folder in the web application 148 * and copying the ID from the URL. For example, for the URL 149 * `https://*.app.box.com/folder/123` the `folder_id` is `123`. 150 * <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345" 151 * @param headers Headers of deleteFolderWatermark method 152 */ 153 public void deleteFolderWatermark(String folderId, DeleteFolderWatermarkHeaders headers) { 154 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 155 FetchResponse response = 156 this.networkSession 157 .getNetworkClient() 158 .fetch( 159 new FetchOptions.Builder( 160 String.join( 161 "", 162 this.networkSession.getBaseUrls().getBaseUrl(), 163 "/2.0/folders/", 164 convertToString(folderId), 165 "/watermark"), 166 "DELETE") 167 .headers(headersMap) 168 .responseFormat(ResponseFormat.NO_CONTENT) 169 .auth(this.auth) 170 .networkSession(this.networkSession) 171 .build()); 172 } 173 174 public Authentication getAuth() { 175 return auth; 176 } 177 178 public NetworkSession getNetworkSession() { 179 return networkSession; 180 } 181 182 public static class Builder { 183 184 protected Authentication auth; 185 186 protected NetworkSession networkSession; 187 188 public Builder() {} 189 190 public Builder auth(Authentication auth) { 191 this.auth = auth; 192 return this; 193 } 194 195 public Builder networkSession(NetworkSession networkSession) { 196 this.networkSession = networkSession; 197 return this; 198 } 199 200 public FolderWatermarksManager build() { 201 if (this.networkSession == null) { 202 this.networkSession = new NetworkSession(); 203 } 204 return new FolderWatermarksManager(this); 205 } 206 } 207}