001package com.box.sdkgen.managers.listcollaborations;
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.collaborations.Collaborations;
015import com.box.sdkgen.schemas.collaborationsoffsetpaginated.CollaborationsOffsetPaginated;
016import com.box.sdkgen.serialization.json.JsonManager;
017import java.util.Map;
018
019public class ListCollaborationsManager {
020
021  public Authentication auth;
022
023  public NetworkSession networkSession;
024
025  public ListCollaborationsManager() {
026    this.networkSession = new NetworkSession();
027  }
028
029  protected ListCollaborationsManager(Builder builder) {
030    this.auth = builder.auth;
031    this.networkSession = builder.networkSession;
032  }
033
034  /**
035   * Retrieves a list of pending and active collaborations for a file. This returns all the users
036   * that have access to the file or have been invited to the file.
037   *
038   * @param fileId The unique identifier that represents a file.
039   *     <p>The ID for any file can be determined by visiting a file in the web application and
040   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
041   *     `file_id` is `123`. Example: "12345"
042   */
043  public Collaborations getFileCollaborations(String fileId) {
044    return getFileCollaborations(
045        fileId, new GetFileCollaborationsQueryParams(), new GetFileCollaborationsHeaders());
046  }
047
048  /**
049   * Retrieves a list of pending and active collaborations for a file. This returns all the users
050   * that have access to the file or have been invited to the file.
051   *
052   * @param fileId The unique identifier that represents a file.
053   *     <p>The ID for any file can be determined by visiting a file in the web application and
054   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
055   *     `file_id` is `123`. Example: "12345"
056   * @param queryParams Query parameters of getFileCollaborations method
057   */
058  public Collaborations getFileCollaborations(
059      String fileId, GetFileCollaborationsQueryParams queryParams) {
060    return getFileCollaborations(fileId, queryParams, new GetFileCollaborationsHeaders());
061  }
062
063  /**
064   * Retrieves a list of pending and active collaborations for a file. This returns all the users
065   * that have access to the file or have been invited to the file.
066   *
067   * @param fileId The unique identifier that represents a file.
068   *     <p>The ID for any file can be determined by visiting a file in the web application and
069   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
070   *     `file_id` is `123`. Example: "12345"
071   * @param headers Headers of getFileCollaborations method
072   */
073  public Collaborations getFileCollaborations(String fileId, GetFileCollaborationsHeaders headers) {
074    return getFileCollaborations(fileId, new GetFileCollaborationsQueryParams(), headers);
075  }
076
077  /**
078   * Retrieves a list of pending and active collaborations for a file. This returns all the users
079   * that have access to the file or have been invited to the file.
080   *
081   * @param fileId The unique identifier that represents a file.
082   *     <p>The ID for any file can be determined by visiting a file in the web application and
083   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
084   *     `file_id` is `123`. Example: "12345"
085   * @param queryParams Query parameters of getFileCollaborations method
086   * @param headers Headers of getFileCollaborations method
087   */
088  public Collaborations getFileCollaborations(
089      String fileId,
090      GetFileCollaborationsQueryParams queryParams,
091      GetFileCollaborationsHeaders headers) {
092    Map<String, String> queryParamsMap =
093        prepareParams(
094            mapOf(
095                entryOf("fields", convertToString(queryParams.getFields())),
096                entryOf("limit", convertToString(queryParams.getLimit())),
097                entryOf("marker", convertToString(queryParams.getMarker()))));
098    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
099    FetchResponse response =
100        this.networkSession
101            .getNetworkClient()
102            .fetch(
103                new FetchOptions.Builder(
104                        String.join(
105                            "",
106                            this.networkSession.getBaseUrls().getBaseUrl(),
107                            "/2.0/files/",
108                            convertToString(fileId),
109                            "/collaborations"),
110                        "GET")
111                    .params(queryParamsMap)
112                    .headers(headersMap)
113                    .responseFormat(ResponseFormat.JSON)
114                    .auth(this.auth)
115                    .networkSession(this.networkSession)
116                    .build());
117    return JsonManager.deserialize(response.getData(), Collaborations.class);
118  }
119
120  /**
121   * Retrieves a list of pending and active collaborations for a folder. This returns all the users
122   * that have access to the folder or have been invited to the folder.
123   *
124   * @param folderId The unique identifier that represent a folder.
125   *     <p>The ID for any folder can be determined by visiting this folder in the web application
126   *     and copying the ID from the URL. For example, for the URL
127   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`. Example: "12345"
128   */
129  public Collaborations getFolderCollaborations(String folderId) {
130    return getFolderCollaborations(
131        folderId, new GetFolderCollaborationsQueryParams(), new GetFolderCollaborationsHeaders());
132  }
133
134  /**
135   * Retrieves a list of pending and active collaborations for a folder. This returns all the users
136   * that have access to the folder or have been invited to the folder.
137   *
138   * @param folderId The unique identifier that represent a folder.
139   *     <p>The ID for any folder can be determined by visiting this folder in the web application
140   *     and copying the ID from the URL. For example, for the URL
141   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`. Example: "12345"
142   * @param queryParams Query parameters of getFolderCollaborations method
143   */
144  public Collaborations getFolderCollaborations(
145      String folderId, GetFolderCollaborationsQueryParams queryParams) {
146    return getFolderCollaborations(folderId, queryParams, new GetFolderCollaborationsHeaders());
147  }
148
149  /**
150   * Retrieves a list of pending and active collaborations for a folder. This returns all the users
151   * that have access to the folder or have been invited to the folder.
152   *
153   * @param folderId The unique identifier that represent a folder.
154   *     <p>The ID for any folder can be determined by visiting this folder in the web application
155   *     and copying the ID from the URL. For example, for the URL
156   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`. Example: "12345"
157   * @param headers Headers of getFolderCollaborations method
158   */
159  public Collaborations getFolderCollaborations(
160      String folderId, GetFolderCollaborationsHeaders headers) {
161    return getFolderCollaborations(folderId, new GetFolderCollaborationsQueryParams(), headers);
162  }
163
164  /**
165   * Retrieves a list of pending and active collaborations for a folder. This returns all the users
166   * that have access to the folder or have been invited to the folder.
167   *
168   * @param folderId The unique identifier that represent a folder.
169   *     <p>The ID for any folder can be determined by visiting this folder in the web application
170   *     and copying the ID from the URL. For example, for the URL
171   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`. Example: "12345"
172   * @param queryParams Query parameters of getFolderCollaborations method
173   * @param headers Headers of getFolderCollaborations method
174   */
175  public Collaborations getFolderCollaborations(
176      String folderId,
177      GetFolderCollaborationsQueryParams queryParams,
178      GetFolderCollaborationsHeaders headers) {
179    Map<String, String> queryParamsMap =
180        prepareParams(
181            mapOf(
182                entryOf("fields", convertToString(queryParams.getFields())),
183                entryOf("limit", convertToString(queryParams.getLimit())),
184                entryOf("marker", convertToString(queryParams.getMarker()))));
185    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
186    FetchResponse response =
187        this.networkSession
188            .getNetworkClient()
189            .fetch(
190                new FetchOptions.Builder(
191                        String.join(
192                            "",
193                            this.networkSession.getBaseUrls().getBaseUrl(),
194                            "/2.0/folders/",
195                            convertToString(folderId),
196                            "/collaborations"),
197                        "GET")
198                    .params(queryParamsMap)
199                    .headers(headersMap)
200                    .responseFormat(ResponseFormat.JSON)
201                    .auth(this.auth)
202                    .networkSession(this.networkSession)
203                    .build());
204    return JsonManager.deserialize(response.getData(), Collaborations.class);
205  }
206
207  /**
208   * Retrieves all pending collaboration invites for this user.
209   *
210   * @param queryParams Query parameters of getCollaborations method
211   */
212  public CollaborationsOffsetPaginated getCollaborations(GetCollaborationsQueryParams queryParams) {
213    return getCollaborations(queryParams, new GetCollaborationsHeaders());
214  }
215
216  /**
217   * Retrieves all pending collaboration invites for this user.
218   *
219   * @param queryParams Query parameters of getCollaborations method
220   * @param headers Headers of getCollaborations method
221   */
222  public CollaborationsOffsetPaginated getCollaborations(
223      GetCollaborationsQueryParams queryParams, GetCollaborationsHeaders headers) {
224    Map<String, String> queryParamsMap =
225        prepareParams(
226            mapOf(
227                entryOf("status", convertToString(queryParams.getStatus())),
228                entryOf("fields", convertToString(queryParams.getFields())),
229                entryOf("offset", convertToString(queryParams.getOffset())),
230                entryOf("limit", convertToString(queryParams.getLimit()))));
231    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
232    FetchResponse response =
233        this.networkSession
234            .getNetworkClient()
235            .fetch(
236                new FetchOptions.Builder(
237                        String.join(
238                            "",
239                            this.networkSession.getBaseUrls().getBaseUrl(),
240                            "/2.0/collaborations"),
241                        "GET")
242                    .params(queryParamsMap)
243                    .headers(headersMap)
244                    .responseFormat(ResponseFormat.JSON)
245                    .auth(this.auth)
246                    .networkSession(this.networkSession)
247                    .build());
248    return JsonManager.deserialize(response.getData(), CollaborationsOffsetPaginated.class);
249  }
250
251  /**
252   * Retrieves all the collaborations for a group. The user must have admin permissions to inspect
253   * enterprise's groups.
254   *
255   * <p>Each collaboration object has details on which files or folders the group has access to and
256   * with what role.
257   *
258   * @param groupId The ID of the group. Example: "57645"
259   */
260  public CollaborationsOffsetPaginated getGroupCollaborations(String groupId) {
261    return getGroupCollaborations(
262        groupId, new GetGroupCollaborationsQueryParams(), new GetGroupCollaborationsHeaders());
263  }
264
265  /**
266   * Retrieves all the collaborations for a group. The user must have admin permissions to inspect
267   * enterprise's groups.
268   *
269   * <p>Each collaboration object has details on which files or folders the group has access to and
270   * with what role.
271   *
272   * @param groupId The ID of the group. Example: "57645"
273   * @param queryParams Query parameters of getGroupCollaborations method
274   */
275  public CollaborationsOffsetPaginated getGroupCollaborations(
276      String groupId, GetGroupCollaborationsQueryParams queryParams) {
277    return getGroupCollaborations(groupId, queryParams, new GetGroupCollaborationsHeaders());
278  }
279
280  /**
281   * Retrieves all the collaborations for a group. The user must have admin permissions to inspect
282   * enterprise's groups.
283   *
284   * <p>Each collaboration object has details on which files or folders the group has access to and
285   * with what role.
286   *
287   * @param groupId The ID of the group. Example: "57645"
288   * @param headers Headers of getGroupCollaborations method
289   */
290  public CollaborationsOffsetPaginated getGroupCollaborations(
291      String groupId, GetGroupCollaborationsHeaders headers) {
292    return getGroupCollaborations(groupId, new GetGroupCollaborationsQueryParams(), headers);
293  }
294
295  /**
296   * Retrieves all the collaborations for a group. The user must have admin permissions to inspect
297   * enterprise's groups.
298   *
299   * <p>Each collaboration object has details on which files or folders the group has access to and
300   * with what role.
301   *
302   * @param groupId The ID of the group. Example: "57645"
303   * @param queryParams Query parameters of getGroupCollaborations method
304   * @param headers Headers of getGroupCollaborations method
305   */
306  public CollaborationsOffsetPaginated getGroupCollaborations(
307      String groupId,
308      GetGroupCollaborationsQueryParams queryParams,
309      GetGroupCollaborationsHeaders headers) {
310    Map<String, String> queryParamsMap =
311        prepareParams(
312            mapOf(
313                entryOf("limit", convertToString(queryParams.getLimit())),
314                entryOf("offset", convertToString(queryParams.getOffset()))));
315    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
316    FetchResponse response =
317        this.networkSession
318            .getNetworkClient()
319            .fetch(
320                new FetchOptions.Builder(
321                        String.join(
322                            "",
323                            this.networkSession.getBaseUrls().getBaseUrl(),
324                            "/2.0/groups/",
325                            convertToString(groupId),
326                            "/collaborations"),
327                        "GET")
328                    .params(queryParamsMap)
329                    .headers(headersMap)
330                    .responseFormat(ResponseFormat.JSON)
331                    .auth(this.auth)
332                    .networkSession(this.networkSession)
333                    .build());
334    return JsonManager.deserialize(response.getData(), CollaborationsOffsetPaginated.class);
335  }
336
337  public Authentication getAuth() {
338    return auth;
339  }
340
341  public NetworkSession getNetworkSession() {
342    return networkSession;
343  }
344
345  public static class Builder {
346
347    protected Authentication auth;
348
349    protected NetworkSession networkSession;
350
351    public Builder() {}
352
353    public Builder auth(Authentication auth) {
354      this.auth = auth;
355      return this;
356    }
357
358    public Builder networkSession(NetworkSession networkSession) {
359      this.networkSession = networkSession;
360      return this;
361    }
362
363    public ListCollaborationsManager build() {
364      if (this.networkSession == null) {
365        this.networkSession = new NetworkSession();
366      }
367      return new ListCollaborationsManager(this);
368    }
369  }
370}