001package com.box.sdkgen.managers.legalholdpolicyassignments;
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.filesonhold.FilesOnHold;
015import com.box.sdkgen.schemas.legalholdpolicyassignment.LegalHoldPolicyAssignment;
016import com.box.sdkgen.schemas.legalholdpolicyassignments.LegalHoldPolicyAssignments;
017import com.box.sdkgen.serialization.json.JsonManager;
018import java.util.Map;
019
020public class LegalHoldPolicyAssignmentsManager {
021
022  public Authentication auth;
023
024  public NetworkSession networkSession;
025
026  public LegalHoldPolicyAssignmentsManager() {
027    this.networkSession = new NetworkSession();
028  }
029
030  protected LegalHoldPolicyAssignmentsManager(Builder builder) {
031    this.auth = builder.auth;
032    this.networkSession = builder.networkSession;
033  }
034
035  /**
036   * Retrieves a list of items a legal hold policy has been assigned to.
037   *
038   * @param queryParams Query parameters of getLegalHoldPolicyAssignments method
039   */
040  public LegalHoldPolicyAssignments getLegalHoldPolicyAssignments(
041      GetLegalHoldPolicyAssignmentsQueryParams queryParams) {
042    return getLegalHoldPolicyAssignments(queryParams, new GetLegalHoldPolicyAssignmentsHeaders());
043  }
044
045  /**
046   * Retrieves a list of items a legal hold policy has been assigned to.
047   *
048   * @param queryParams Query parameters of getLegalHoldPolicyAssignments method
049   * @param headers Headers of getLegalHoldPolicyAssignments method
050   */
051  public LegalHoldPolicyAssignments getLegalHoldPolicyAssignments(
052      GetLegalHoldPolicyAssignmentsQueryParams queryParams,
053      GetLegalHoldPolicyAssignmentsHeaders headers) {
054    Map<String, String> queryParamsMap =
055        prepareParams(
056            mapOf(
057                entryOf("policy_id", convertToString(queryParams.getPolicyId())),
058                entryOf("assign_to_type", convertToString(queryParams.getAssignToType())),
059                entryOf("assign_to_id", convertToString(queryParams.getAssignToId())),
060                entryOf("marker", convertToString(queryParams.getMarker())),
061                entryOf("limit", convertToString(queryParams.getLimit())),
062                entryOf("fields", convertToString(queryParams.getFields()))));
063    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
064    FetchResponse response =
065        this.networkSession
066            .getNetworkClient()
067            .fetch(
068                new FetchOptions.Builder(
069                        String.join(
070                            "",
071                            this.networkSession.getBaseUrls().getBaseUrl(),
072                            "/2.0/legal_hold_policy_assignments"),
073                        "GET")
074                    .params(queryParamsMap)
075                    .headers(headersMap)
076                    .responseFormat(ResponseFormat.JSON)
077                    .auth(this.auth)
078                    .networkSession(this.networkSession)
079                    .build());
080    return JsonManager.deserialize(response.getData(), LegalHoldPolicyAssignments.class);
081  }
082
083  /**
084   * Assign a legal hold to an item type of: file, file version, folder, user, ownership, or
085   * interactions.
086   *
087   * @param requestBody Request body of createLegalHoldPolicyAssignment method
088   */
089  public LegalHoldPolicyAssignment createLegalHoldPolicyAssignment(
090      CreateLegalHoldPolicyAssignmentRequestBody requestBody) {
091    return createLegalHoldPolicyAssignment(
092        requestBody, new CreateLegalHoldPolicyAssignmentHeaders());
093  }
094
095  /**
096   * Assign a legal hold to an item type of: file, file version, folder, user, ownership, or
097   * interactions.
098   *
099   * @param requestBody Request body of createLegalHoldPolicyAssignment method
100   * @param headers Headers of createLegalHoldPolicyAssignment method
101   */
102  public LegalHoldPolicyAssignment createLegalHoldPolicyAssignment(
103      CreateLegalHoldPolicyAssignmentRequestBody requestBody,
104      CreateLegalHoldPolicyAssignmentHeaders headers) {
105    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
106    FetchResponse response =
107        this.networkSession
108            .getNetworkClient()
109            .fetch(
110                new FetchOptions.Builder(
111                        String.join(
112                            "",
113                            this.networkSession.getBaseUrls().getBaseUrl(),
114                            "/2.0/legal_hold_policy_assignments"),
115                        "POST")
116                    .headers(headersMap)
117                    .data(JsonManager.serialize(requestBody))
118                    .contentType("application/json")
119                    .responseFormat(ResponseFormat.JSON)
120                    .auth(this.auth)
121                    .networkSession(this.networkSession)
122                    .build());
123    return JsonManager.deserialize(response.getData(), LegalHoldPolicyAssignment.class);
124  }
125
126  /**
127   * Retrieve a legal hold policy assignment.
128   *
129   * @param legalHoldPolicyAssignmentId The ID of the legal hold policy assignment. Example:
130   *     "753465"
131   */
132  public LegalHoldPolicyAssignment getLegalHoldPolicyAssignmentById(
133      String legalHoldPolicyAssignmentId) {
134    return getLegalHoldPolicyAssignmentById(
135        legalHoldPolicyAssignmentId, new GetLegalHoldPolicyAssignmentByIdHeaders());
136  }
137
138  /**
139   * Retrieve a legal hold policy assignment.
140   *
141   * @param legalHoldPolicyAssignmentId The ID of the legal hold policy assignment. Example:
142   *     "753465"
143   * @param headers Headers of getLegalHoldPolicyAssignmentById method
144   */
145  public LegalHoldPolicyAssignment getLegalHoldPolicyAssignmentById(
146      String legalHoldPolicyAssignmentId, GetLegalHoldPolicyAssignmentByIdHeaders 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/legal_hold_policy_assignments/",
157                            convertToString(legalHoldPolicyAssignmentId)),
158                        "GET")
159                    .headers(headersMap)
160                    .responseFormat(ResponseFormat.JSON)
161                    .auth(this.auth)
162                    .networkSession(this.networkSession)
163                    .build());
164    return JsonManager.deserialize(response.getData(), LegalHoldPolicyAssignment.class);
165  }
166
167  /**
168   * Remove a legal hold from an item.
169   *
170   * <p>This is an asynchronous process. The policy will not be fully removed yet when the response
171   * returns.
172   *
173   * @param legalHoldPolicyAssignmentId The ID of the legal hold policy assignment. Example:
174   *     "753465"
175   */
176  public void deleteLegalHoldPolicyAssignmentById(String legalHoldPolicyAssignmentId) {
177    deleteLegalHoldPolicyAssignmentById(
178        legalHoldPolicyAssignmentId, new DeleteLegalHoldPolicyAssignmentByIdHeaders());
179  }
180
181  /**
182   * Remove a legal hold from an item.
183   *
184   * <p>This is an asynchronous process. The policy will not be fully removed yet when the response
185   * returns.
186   *
187   * @param legalHoldPolicyAssignmentId The ID of the legal hold policy assignment. Example:
188   *     "753465"
189   * @param headers Headers of deleteLegalHoldPolicyAssignmentById method
190   */
191  public void deleteLegalHoldPolicyAssignmentById(
192      String legalHoldPolicyAssignmentId, DeleteLegalHoldPolicyAssignmentByIdHeaders headers) {
193    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
194    FetchResponse response =
195        this.networkSession
196            .getNetworkClient()
197            .fetch(
198                new FetchOptions.Builder(
199                        String.join(
200                            "",
201                            this.networkSession.getBaseUrls().getBaseUrl(),
202                            "/2.0/legal_hold_policy_assignments/",
203                            convertToString(legalHoldPolicyAssignmentId)),
204                        "DELETE")
205                    .headers(headersMap)
206                    .responseFormat(ResponseFormat.NO_CONTENT)
207                    .auth(this.auth)
208                    .networkSession(this.networkSession)
209                    .build());
210  }
211
212  /**
213   * Get a list of files with current file versions for a legal hold assignment.
214   *
215   * <p>In some cases you may want to get previous file versions instead. In these cases, use the
216   * `GET /legal_hold_policy_assignments/:id/file_versions_on_hold` API instead to return any
217   * previous versions of a file for this legal hold policy assignment.
218   *
219   * <p>Due to ongoing re-architecture efforts this API might not return all file versions held for
220   * this policy ID. Instead, this API will only return the latest file version held in the newly
221   * developed architecture. The `GET /file_version_legal_holds` API can be used to fetch current
222   * and past versions of files held within the legacy architecture.
223   *
224   * <p>This endpoint does not support returning any content that is on hold due to a Custodian
225   * collaborating on a Hub.
226   *
227   * <p>The `GET /legal_hold_policy_assignments?policy_id={id}` API can be used to find a list of
228   * policy assignments for a given policy ID.
229   *
230   * @param legalHoldPolicyAssignmentId The ID of the legal hold policy assignment. Example:
231   *     "753465"
232   */
233  public FilesOnHold getLegalHoldPolicyAssignmentFileOnHold(String legalHoldPolicyAssignmentId) {
234    return getLegalHoldPolicyAssignmentFileOnHold(
235        legalHoldPolicyAssignmentId,
236        new GetLegalHoldPolicyAssignmentFileOnHoldQueryParams(),
237        new GetLegalHoldPolicyAssignmentFileOnHoldHeaders());
238  }
239
240  /**
241   * Get a list of files with current file versions for a legal hold assignment.
242   *
243   * <p>In some cases you may want to get previous file versions instead. In these cases, use the
244   * `GET /legal_hold_policy_assignments/:id/file_versions_on_hold` API instead to return any
245   * previous versions of a file for this legal hold policy assignment.
246   *
247   * <p>Due to ongoing re-architecture efforts this API might not return all file versions held for
248   * this policy ID. Instead, this API will only return the latest file version held in the newly
249   * developed architecture. The `GET /file_version_legal_holds` API can be used to fetch current
250   * and past versions of files held within the legacy architecture.
251   *
252   * <p>This endpoint does not support returning any content that is on hold due to a Custodian
253   * collaborating on a Hub.
254   *
255   * <p>The `GET /legal_hold_policy_assignments?policy_id={id}` API can be used to find a list of
256   * policy assignments for a given policy ID.
257   *
258   * @param legalHoldPolicyAssignmentId The ID of the legal hold policy assignment. Example:
259   *     "753465"
260   * @param queryParams Query parameters of getLegalHoldPolicyAssignmentFileOnHold method
261   */
262  public FilesOnHold getLegalHoldPolicyAssignmentFileOnHold(
263      String legalHoldPolicyAssignmentId,
264      GetLegalHoldPolicyAssignmentFileOnHoldQueryParams queryParams) {
265    return getLegalHoldPolicyAssignmentFileOnHold(
266        legalHoldPolicyAssignmentId,
267        queryParams,
268        new GetLegalHoldPolicyAssignmentFileOnHoldHeaders());
269  }
270
271  /**
272   * Get a list of files with current file versions for a legal hold assignment.
273   *
274   * <p>In some cases you may want to get previous file versions instead. In these cases, use the
275   * `GET /legal_hold_policy_assignments/:id/file_versions_on_hold` API instead to return any
276   * previous versions of a file for this legal hold policy assignment.
277   *
278   * <p>Due to ongoing re-architecture efforts this API might not return all file versions held for
279   * this policy ID. Instead, this API will only return the latest file version held in the newly
280   * developed architecture. The `GET /file_version_legal_holds` API can be used to fetch current
281   * and past versions of files held within the legacy architecture.
282   *
283   * <p>This endpoint does not support returning any content that is on hold due to a Custodian
284   * collaborating on a Hub.
285   *
286   * <p>The `GET /legal_hold_policy_assignments?policy_id={id}` API can be used to find a list of
287   * policy assignments for a given policy ID.
288   *
289   * @param legalHoldPolicyAssignmentId The ID of the legal hold policy assignment. Example:
290   *     "753465"
291   * @param headers Headers of getLegalHoldPolicyAssignmentFileOnHold method
292   */
293  public FilesOnHold getLegalHoldPolicyAssignmentFileOnHold(
294      String legalHoldPolicyAssignmentId, GetLegalHoldPolicyAssignmentFileOnHoldHeaders headers) {
295    return getLegalHoldPolicyAssignmentFileOnHold(
296        legalHoldPolicyAssignmentId,
297        new GetLegalHoldPolicyAssignmentFileOnHoldQueryParams(),
298        headers);
299  }
300
301  /**
302   * Get a list of files with current file versions for a legal hold assignment.
303   *
304   * <p>In some cases you may want to get previous file versions instead. In these cases, use the
305   * `GET /legal_hold_policy_assignments/:id/file_versions_on_hold` API instead to return any
306   * previous versions of a file for this legal hold policy assignment.
307   *
308   * <p>Due to ongoing re-architecture efforts this API might not return all file versions held for
309   * this policy ID. Instead, this API will only return the latest file version held in the newly
310   * developed architecture. The `GET /file_version_legal_holds` API can be used to fetch current
311   * and past versions of files held within the legacy architecture.
312   *
313   * <p>This endpoint does not support returning any content that is on hold due to a Custodian
314   * collaborating on a Hub.
315   *
316   * <p>The `GET /legal_hold_policy_assignments?policy_id={id}` API can be used to find a list of
317   * policy assignments for a given policy ID.
318   *
319   * @param legalHoldPolicyAssignmentId The ID of the legal hold policy assignment. Example:
320   *     "753465"
321   * @param queryParams Query parameters of getLegalHoldPolicyAssignmentFileOnHold method
322   * @param headers Headers of getLegalHoldPolicyAssignmentFileOnHold method
323   */
324  public FilesOnHold getLegalHoldPolicyAssignmentFileOnHold(
325      String legalHoldPolicyAssignmentId,
326      GetLegalHoldPolicyAssignmentFileOnHoldQueryParams queryParams,
327      GetLegalHoldPolicyAssignmentFileOnHoldHeaders headers) {
328    Map<String, String> queryParamsMap =
329        prepareParams(
330            mapOf(
331                entryOf("marker", convertToString(queryParams.getMarker())),
332                entryOf("limit", convertToString(queryParams.getLimit())),
333                entryOf("fields", convertToString(queryParams.getFields()))));
334    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
335    FetchResponse response =
336        this.networkSession
337            .getNetworkClient()
338            .fetch(
339                new FetchOptions.Builder(
340                        String.join(
341                            "",
342                            this.networkSession.getBaseUrls().getBaseUrl(),
343                            "/2.0/legal_hold_policy_assignments/",
344                            convertToString(legalHoldPolicyAssignmentId),
345                            "/files_on_hold"),
346                        "GET")
347                    .params(queryParamsMap)
348                    .headers(headersMap)
349                    .responseFormat(ResponseFormat.JSON)
350                    .auth(this.auth)
351                    .networkSession(this.networkSession)
352                    .build());
353    return JsonManager.deserialize(response.getData(), FilesOnHold.class);
354  }
355
356  public Authentication getAuth() {
357    return auth;
358  }
359
360  public NetworkSession getNetworkSession() {
361    return networkSession;
362  }
363
364  public static class Builder {
365
366    protected Authentication auth;
367
368    protected NetworkSession networkSession;
369
370    public Builder() {}
371
372    public Builder auth(Authentication auth) {
373      this.auth = auth;
374      return this;
375    }
376
377    public Builder networkSession(NetworkSession networkSession) {
378      this.networkSession = networkSession;
379      return this;
380    }
381
382    public LegalHoldPolicyAssignmentsManager build() {
383      if (this.networkSession == null) {
384        this.networkSession = new NetworkSession();
385      }
386      return new LegalHoldPolicyAssignmentsManager(this);
387    }
388  }
389}