001package com.box.sdkgen.managers.collaborationallowlistentries; 002 003import static com.box.sdkgen.internal.utils.UtilsManager.convertToString; 004import static com.box.sdkgen.internal.utils.UtilsManager.entryOf; 005import static com.box.sdkgen.internal.utils.UtilsManager.mapOf; 006import static com.box.sdkgen.internal.utils.UtilsManager.mergeMaps; 007import static com.box.sdkgen.internal.utils.UtilsManager.prepareParams; 008 009import com.box.sdkgen.networking.auth.Authentication; 010import com.box.sdkgen.networking.fetchoptions.FetchOptions; 011import com.box.sdkgen.networking.fetchoptions.ResponseFormat; 012import com.box.sdkgen.networking.fetchresponse.FetchResponse; 013import com.box.sdkgen.networking.network.NetworkSession; 014import com.box.sdkgen.schemas.collaborationallowlistentries.CollaborationAllowlistEntries; 015import com.box.sdkgen.schemas.collaborationallowlistentry.CollaborationAllowlistEntry; 016import com.box.sdkgen.serialization.json.JsonManager; 017import java.util.Map; 018 019public class CollaborationAllowlistEntriesManager { 020 021 public Authentication auth; 022 023 public NetworkSession networkSession; 024 025 public CollaborationAllowlistEntriesManager() { 026 this.networkSession = new NetworkSession(); 027 } 028 029 protected CollaborationAllowlistEntriesManager(Builder builder) { 030 this.auth = builder.auth; 031 this.networkSession = builder.networkSession; 032 } 033 034 /** 035 * Returns the list domains that have been deemed safe to create collaborations for within the 036 * current enterprise. 037 */ 038 public CollaborationAllowlistEntries getCollaborationWhitelistEntries() { 039 return getCollaborationWhitelistEntries( 040 new GetCollaborationWhitelistEntriesQueryParams(), 041 new GetCollaborationWhitelistEntriesHeaders()); 042 } 043 044 /** 045 * Returns the list domains that have been deemed safe to create collaborations for within the 046 * current enterprise. 047 * 048 * @param queryParams Query parameters of getCollaborationWhitelistEntries method 049 */ 050 public CollaborationAllowlistEntries getCollaborationWhitelistEntries( 051 GetCollaborationWhitelistEntriesQueryParams queryParams) { 052 return getCollaborationWhitelistEntries( 053 queryParams, new GetCollaborationWhitelistEntriesHeaders()); 054 } 055 056 /** 057 * Returns the list domains that have been deemed safe to create collaborations for within the 058 * current enterprise. 059 * 060 * @param headers Headers of getCollaborationWhitelistEntries method 061 */ 062 public CollaborationAllowlistEntries getCollaborationWhitelistEntries( 063 GetCollaborationWhitelistEntriesHeaders headers) { 064 return getCollaborationWhitelistEntries( 065 new GetCollaborationWhitelistEntriesQueryParams(), headers); 066 } 067 068 /** 069 * Returns the list domains that have been deemed safe to create collaborations for within the 070 * current enterprise. 071 * 072 * @param queryParams Query parameters of getCollaborationWhitelistEntries method 073 * @param headers Headers of getCollaborationWhitelistEntries method 074 */ 075 public CollaborationAllowlistEntries getCollaborationWhitelistEntries( 076 GetCollaborationWhitelistEntriesQueryParams queryParams, 077 GetCollaborationWhitelistEntriesHeaders headers) { 078 Map<String, String> queryParamsMap = 079 prepareParams( 080 mapOf( 081 entryOf("marker", convertToString(queryParams.getMarker())), 082 entryOf("limit", convertToString(queryParams.getLimit())))); 083 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 084 FetchResponse response = 085 this.networkSession 086 .getNetworkClient() 087 .fetch( 088 new FetchOptions.Builder( 089 String.join( 090 "", 091 this.networkSession.getBaseUrls().getBaseUrl(), 092 "/2.0/collaboration_whitelist_entries"), 093 "GET") 094 .params(queryParamsMap) 095 .headers(headersMap) 096 .responseFormat(ResponseFormat.JSON) 097 .auth(this.auth) 098 .networkSession(this.networkSession) 099 .build()); 100 return JsonManager.deserialize(response.getData(), CollaborationAllowlistEntries.class); 101 } 102 103 /** 104 * Creates a new entry in the list of allowed domains to allow collaboration for. 105 * 106 * @param requestBody Request body of createCollaborationWhitelistEntry method 107 */ 108 public CollaborationAllowlistEntry createCollaborationWhitelistEntry( 109 CreateCollaborationWhitelistEntryRequestBody requestBody) { 110 return createCollaborationWhitelistEntry( 111 requestBody, new CreateCollaborationWhitelistEntryHeaders()); 112 } 113 114 /** 115 * Creates a new entry in the list of allowed domains to allow collaboration for. 116 * 117 * @param requestBody Request body of createCollaborationWhitelistEntry method 118 * @param headers Headers of createCollaborationWhitelistEntry method 119 */ 120 public CollaborationAllowlistEntry createCollaborationWhitelistEntry( 121 CreateCollaborationWhitelistEntryRequestBody requestBody, 122 CreateCollaborationWhitelistEntryHeaders headers) { 123 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 124 FetchResponse response = 125 this.networkSession 126 .getNetworkClient() 127 .fetch( 128 new FetchOptions.Builder( 129 String.join( 130 "", 131 this.networkSession.getBaseUrls().getBaseUrl(), 132 "/2.0/collaboration_whitelist_entries"), 133 "POST") 134 .headers(headersMap) 135 .data(JsonManager.serialize(requestBody)) 136 .contentType("application/json") 137 .responseFormat(ResponseFormat.JSON) 138 .auth(this.auth) 139 .networkSession(this.networkSession) 140 .build()); 141 return JsonManager.deserialize(response.getData(), CollaborationAllowlistEntry.class); 142 } 143 144 /** 145 * Returns a domain that has been deemed safe to create collaborations for within the current 146 * enterprise. 147 * 148 * @param collaborationWhitelistEntryId The ID of the entry in the list. Example: "213123" 149 */ 150 public CollaborationAllowlistEntry getCollaborationWhitelistEntryById( 151 String collaborationWhitelistEntryId) { 152 return getCollaborationWhitelistEntryById( 153 collaborationWhitelistEntryId, new GetCollaborationWhitelistEntryByIdHeaders()); 154 } 155 156 /** 157 * Returns a domain that has been deemed safe to create collaborations for within the current 158 * enterprise. 159 * 160 * @param collaborationWhitelistEntryId The ID of the entry in the list. Example: "213123" 161 * @param headers Headers of getCollaborationWhitelistEntryById method 162 */ 163 public CollaborationAllowlistEntry getCollaborationWhitelistEntryById( 164 String collaborationWhitelistEntryId, GetCollaborationWhitelistEntryByIdHeaders headers) { 165 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 166 FetchResponse response = 167 this.networkSession 168 .getNetworkClient() 169 .fetch( 170 new FetchOptions.Builder( 171 String.join( 172 "", 173 this.networkSession.getBaseUrls().getBaseUrl(), 174 "/2.0/collaboration_whitelist_entries/", 175 convertToString(collaborationWhitelistEntryId)), 176 "GET") 177 .headers(headersMap) 178 .responseFormat(ResponseFormat.JSON) 179 .auth(this.auth) 180 .networkSession(this.networkSession) 181 .build()); 182 return JsonManager.deserialize(response.getData(), CollaborationAllowlistEntry.class); 183 } 184 185 /** 186 * Removes a domain from the list of domains that have been deemed safe to create collaborations 187 * for within the current enterprise. 188 * 189 * @param collaborationWhitelistEntryId The ID of the entry in the list. Example: "213123" 190 */ 191 public void deleteCollaborationWhitelistEntryById(String collaborationWhitelistEntryId) { 192 deleteCollaborationWhitelistEntryById( 193 collaborationWhitelistEntryId, new DeleteCollaborationWhitelistEntryByIdHeaders()); 194 } 195 196 /** 197 * Removes a domain from the list of domains that have been deemed safe to create collaborations 198 * for within the current enterprise. 199 * 200 * @param collaborationWhitelistEntryId The ID of the entry in the list. Example: "213123" 201 * @param headers Headers of deleteCollaborationWhitelistEntryById method 202 */ 203 public void deleteCollaborationWhitelistEntryById( 204 String collaborationWhitelistEntryId, DeleteCollaborationWhitelistEntryByIdHeaders headers) { 205 Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders())); 206 FetchResponse response = 207 this.networkSession 208 .getNetworkClient() 209 .fetch( 210 new FetchOptions.Builder( 211 String.join( 212 "", 213 this.networkSession.getBaseUrls().getBaseUrl(), 214 "/2.0/collaboration_whitelist_entries/", 215 convertToString(collaborationWhitelistEntryId)), 216 "DELETE") 217 .headers(headersMap) 218 .responseFormat(ResponseFormat.NO_CONTENT) 219 .auth(this.auth) 220 .networkSession(this.networkSession) 221 .build()); 222 } 223 224 public Authentication getAuth() { 225 return auth; 226 } 227 228 public NetworkSession getNetworkSession() { 229 return networkSession; 230 } 231 232 public static class Builder { 233 234 protected Authentication auth; 235 236 protected NetworkSession networkSession; 237 238 public Builder() {} 239 240 public Builder auth(Authentication auth) { 241 this.auth = auth; 242 return this; 243 } 244 245 public Builder networkSession(NetworkSession networkSession) { 246 this.networkSession = networkSession; 247 return this; 248 } 249 250 public CollaborationAllowlistEntriesManager build() { 251 if (this.networkSession == null) { 252 this.networkSession = new NetworkSession(); 253 } 254 return new CollaborationAllowlistEntriesManager(this); 255 } 256 } 257}