001package com.box.sdkgen.managers.appitemassociations;
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.appitemassociations.AppItemAssociations;
015import com.box.sdkgen.serialization.json.JsonManager;
016import java.util.Map;
017
018public class AppItemAssociationsManager {
019
020  public Authentication auth;
021
022  public NetworkSession networkSession;
023
024  public AppItemAssociationsManager() {
025    this.networkSession = new NetworkSession();
026  }
027
028  protected AppItemAssociationsManager(Builder builder) {
029    this.auth = builder.auth;
030    this.networkSession = builder.networkSession;
031  }
032
033  /**
034   * **This is a beta feature, which means that its availability might be limited.** Returns all app
035   * items the file is associated with. This includes app items associated with ancestors of the
036   * file. Assuming the context user has access to the file, the type/ids are revealed even if the
037   * context user does not have **View** permission on the app item.
038   *
039   * @param fileId The unique identifier that represents a file.
040   *     <p>The ID for any file can be determined by visiting a file in the web application and
041   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
042   *     `file_id` is `123`. Example: "12345"
043   */
044  public AppItemAssociations getFileAppItemAssociations(String fileId) {
045    return getFileAppItemAssociations(
046        fileId,
047        new GetFileAppItemAssociationsQueryParams(),
048        new GetFileAppItemAssociationsHeaders());
049  }
050
051  /**
052   * **This is a beta feature, which means that its availability might be limited.** Returns all app
053   * items the file is associated with. This includes app items associated with ancestors of the
054   * file. Assuming the context user has access to the file, the type/ids are revealed even if the
055   * context user does not have **View** permission on the app item.
056   *
057   * @param fileId The unique identifier that represents a file.
058   *     <p>The ID for any file can be determined by visiting a file in the web application and
059   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
060   *     `file_id` is `123`. Example: "12345"
061   * @param queryParams Query parameters of getFileAppItemAssociations method
062   */
063  public AppItemAssociations getFileAppItemAssociations(
064      String fileId, GetFileAppItemAssociationsQueryParams queryParams) {
065    return getFileAppItemAssociations(fileId, queryParams, new GetFileAppItemAssociationsHeaders());
066  }
067
068  /**
069   * **This is a beta feature, which means that its availability might be limited.** Returns all app
070   * items the file is associated with. This includes app items associated with ancestors of the
071   * file. Assuming the context user has access to the file, the type/ids are revealed even if the
072   * context user does not have **View** permission on the app item.
073   *
074   * @param fileId The unique identifier that represents a file.
075   *     <p>The ID for any file can be determined by visiting a file in the web application and
076   *     copying the ID from the URL. For example, for the URL `https://*.app.box.com/files/123` the
077   *     `file_id` is `123`. Example: "12345"
078   * @param headers Headers of getFileAppItemAssociations method
079   */
080  public AppItemAssociations getFileAppItemAssociations(
081      String fileId, GetFileAppItemAssociationsHeaders headers) {
082    return getFileAppItemAssociations(fileId, new GetFileAppItemAssociationsQueryParams(), headers);
083  }
084
085  /**
086   * **This is a beta feature, which means that its availability might be limited.** Returns all app
087   * items the file is associated with. This includes app items associated with ancestors of the
088   * file. Assuming the context user has access to the file, the type/ids are revealed even if the
089   * context user does not have **View** permission on the app item.
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 queryParams Query parameters of getFileAppItemAssociations method
096   * @param headers Headers of getFileAppItemAssociations method
097   */
098  public AppItemAssociations getFileAppItemAssociations(
099      String fileId,
100      GetFileAppItemAssociationsQueryParams queryParams,
101      GetFileAppItemAssociationsHeaders headers) {
102    Map<String, String> queryParamsMap =
103        prepareParams(
104            mapOf(
105                entryOf("limit", convertToString(queryParams.getLimit())),
106                entryOf("marker", convertToString(queryParams.getMarker())),
107                entryOf("application_type", convertToString(queryParams.getApplicationType()))));
108    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
109    FetchResponse response =
110        this.networkSession
111            .getNetworkClient()
112            .fetch(
113                new FetchOptions.Builder(
114                        String.join(
115                            "",
116                            this.networkSession.getBaseUrls().getBaseUrl(),
117                            "/2.0/files/",
118                            convertToString(fileId),
119                            "/app_item_associations"),
120                        "GET")
121                    .params(queryParamsMap)
122                    .headers(headersMap)
123                    .responseFormat(ResponseFormat.JSON)
124                    .auth(this.auth)
125                    .networkSession(this.networkSession)
126                    .build());
127    return JsonManager.deserialize(response.getData(), AppItemAssociations.class);
128  }
129
130  /**
131   * **This is a beta feature, which means that its availability might be limited.** Returns all app
132   * items the folder is associated with. This includes app items associated with ancestors of the
133   * folder. Assuming the context user has access to the folder, the type/ids are revealed even if
134   * the context user does not have **View** permission on the app item.
135   *
136   * @param folderId The unique identifier that represent a folder.
137   *     <p>The ID for any folder can be determined by visiting this folder in the web application
138   *     and copying the ID from the URL. For example, for the URL
139   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
140   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
141   */
142  public AppItemAssociations getFolderAppItemAssociations(String folderId) {
143    return getFolderAppItemAssociations(
144        folderId,
145        new GetFolderAppItemAssociationsQueryParams(),
146        new GetFolderAppItemAssociationsHeaders());
147  }
148
149  /**
150   * **This is a beta feature, which means that its availability might be limited.** Returns all app
151   * items the folder is associated with. This includes app items associated with ancestors of the
152   * folder. Assuming the context user has access to the folder, the type/ids are revealed even if
153   * the context user does not have **View** permission on the app item.
154   *
155   * @param folderId The unique identifier that represent a folder.
156   *     <p>The ID for any folder can be determined by visiting this folder in the web application
157   *     and copying the ID from the URL. For example, for the URL
158   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
159   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
160   * @param queryParams Query parameters of getFolderAppItemAssociations method
161   */
162  public AppItemAssociations getFolderAppItemAssociations(
163      String folderId, GetFolderAppItemAssociationsQueryParams queryParams) {
164    return getFolderAppItemAssociations(
165        folderId, queryParams, new GetFolderAppItemAssociationsHeaders());
166  }
167
168  /**
169   * **This is a beta feature, which means that its availability might be limited.** Returns all app
170   * items the folder is associated with. This includes app items associated with ancestors of the
171   * folder. Assuming the context user has access to the folder, the type/ids are revealed even if
172   * the context user does not have **View** permission on the app item.
173   *
174   * @param folderId The unique identifier that represent a folder.
175   *     <p>The ID for any folder can be determined by visiting this folder in the web application
176   *     and copying the ID from the URL. For example, for the URL
177   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
178   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
179   * @param headers Headers of getFolderAppItemAssociations method
180   */
181  public AppItemAssociations getFolderAppItemAssociations(
182      String folderId, GetFolderAppItemAssociationsHeaders headers) {
183    return getFolderAppItemAssociations(
184        folderId, new GetFolderAppItemAssociationsQueryParams(), headers);
185  }
186
187  /**
188   * **This is a beta feature, which means that its availability might be limited.** Returns all app
189   * items the folder is associated with. This includes app items associated with ancestors of the
190   * folder. Assuming the context user has access to the folder, the type/ids are revealed even if
191   * the context user does not have **View** permission on the app item.
192   *
193   * @param folderId The unique identifier that represent a folder.
194   *     <p>The ID for any folder can be determined by visiting this folder in the web application
195   *     and copying the ID from the URL. For example, for the URL
196   *     `https://*.app.box.com/folder/123` the `folder_id` is `123`.
197   *     <p>The root folder of a Box account is always represented by the ID `0`. Example: "12345"
198   * @param queryParams Query parameters of getFolderAppItemAssociations method
199   * @param headers Headers of getFolderAppItemAssociations method
200   */
201  public AppItemAssociations getFolderAppItemAssociations(
202      String folderId,
203      GetFolderAppItemAssociationsQueryParams queryParams,
204      GetFolderAppItemAssociationsHeaders headers) {
205    Map<String, String> queryParamsMap =
206        prepareParams(
207            mapOf(
208                entryOf("limit", convertToString(queryParams.getLimit())),
209                entryOf("marker", convertToString(queryParams.getMarker())),
210                entryOf("application_type", convertToString(queryParams.getApplicationType()))));
211    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
212    FetchResponse response =
213        this.networkSession
214            .getNetworkClient()
215            .fetch(
216                new FetchOptions.Builder(
217                        String.join(
218                            "",
219                            this.networkSession.getBaseUrls().getBaseUrl(),
220                            "/2.0/folders/",
221                            convertToString(folderId),
222                            "/app_item_associations"),
223                        "GET")
224                    .params(queryParamsMap)
225                    .headers(headersMap)
226                    .responseFormat(ResponseFormat.JSON)
227                    .auth(this.auth)
228                    .networkSession(this.networkSession)
229                    .build());
230    return JsonManager.deserialize(response.getData(), AppItemAssociations.class);
231  }
232
233  public Authentication getAuth() {
234    return auth;
235  }
236
237  public NetworkSession getNetworkSession() {
238    return networkSession;
239  }
240
241  public static class Builder {
242
243    protected Authentication auth;
244
245    protected NetworkSession networkSession;
246
247    public Builder() {}
248
249    public Builder auth(Authentication auth) {
250      this.auth = auth;
251      return this;
252    }
253
254    public Builder networkSession(NetworkSession networkSession) {
255      this.networkSession = networkSession;
256      return this;
257    }
258
259    public AppItemAssociationsManager build() {
260      if (this.networkSession == null) {
261        this.networkSession = new NetworkSession();
262      }
263      return new AppItemAssociationsManager(this);
264    }
265  }
266}