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