001package com.box.sdkgen.managers.fileversionlegalholds;
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.fileversionlegalhold.FileVersionLegalHold;
015import com.box.sdkgen.schemas.fileversionlegalholds.FileVersionLegalHolds;
016import com.box.sdkgen.serialization.json.JsonManager;
017import java.util.Map;
018
019public class FileVersionLegalHoldsManager {
020
021  public Authentication auth;
022
023  public NetworkSession networkSession;
024
025  public FileVersionLegalHoldsManager() {
026    this.networkSession = new NetworkSession();
027  }
028
029  protected FileVersionLegalHoldsManager(Builder builder) {
030    this.auth = builder.auth;
031    this.networkSession = builder.networkSession;
032  }
033
034  /**
035   * Retrieves information about the legal hold policies assigned to a file version.
036   *
037   * @param fileVersionLegalHoldId The ID of the file version legal hold. Example: "2348213"
038   */
039  public FileVersionLegalHold getFileVersionLegalHoldById(String fileVersionLegalHoldId) {
040    return getFileVersionLegalHoldById(
041        fileVersionLegalHoldId, new GetFileVersionLegalHoldByIdHeaders());
042  }
043
044  /**
045   * Retrieves information about the legal hold policies assigned to a file version.
046   *
047   * @param fileVersionLegalHoldId The ID of the file version legal hold. Example: "2348213"
048   * @param headers Headers of getFileVersionLegalHoldById method
049   */
050  public FileVersionLegalHold getFileVersionLegalHoldById(
051      String fileVersionLegalHoldId, GetFileVersionLegalHoldByIdHeaders headers) {
052    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
053    FetchResponse response =
054        this.networkSession
055            .getNetworkClient()
056            .fetch(
057                new FetchOptions.Builder(
058                        String.join(
059                            "",
060                            this.networkSession.getBaseUrls().getBaseUrl(),
061                            "/2.0/file_version_legal_holds/",
062                            convertToString(fileVersionLegalHoldId)),
063                        "GET")
064                    .headers(headersMap)
065                    .responseFormat(ResponseFormat.JSON)
066                    .auth(this.auth)
067                    .networkSession(this.networkSession)
068                    .build());
069    return JsonManager.deserialize(response.getData(), FileVersionLegalHold.class);
070  }
071
072  /**
073   * Get a list of file versions on legal hold for a legal hold assignment.
074   *
075   * <p>Due to ongoing re-architecture efforts this API might not return all file versions for this
076   * policy ID.
077   *
078   * <p>Instead, this API will only return file versions held in the legacy architecture. Two new
079   * endpoints will available to request any file versions held in the new architecture.
080   *
081   * <p>For file versions held in the new architecture, the `GET
082   * /legal_hold_policy_assignments/:id/file_versions_on_hold` API can be used to return all past
083   * file versions available for this policy assignment, and the `GET
084   * /legal_hold_policy_assignments/:id/files_on_hold` API can be used to return any current
085   * (latest) versions of a file under legal hold.
086   *
087   * <p>The `GET /legal_hold_policy_assignments?policy_id={id}` API can be used to find a list of
088   * policy assignments for a given policy ID.
089   *
090   * <p>Once the re-architecture is completed this API will be deprecated.
091   *
092   * @param queryParams Query parameters of getFileVersionLegalHolds method
093   */
094  public FileVersionLegalHolds getFileVersionLegalHolds(
095      GetFileVersionLegalHoldsQueryParams queryParams) {
096    return getFileVersionLegalHolds(queryParams, new GetFileVersionLegalHoldsHeaders());
097  }
098
099  /**
100   * Get a list of file versions on legal hold for a legal hold assignment.
101   *
102   * <p>Due to ongoing re-architecture efforts this API might not return all file versions for this
103   * policy ID.
104   *
105   * <p>Instead, this API will only return file versions held in the legacy architecture. Two new
106   * endpoints will available to request any file versions held in the new architecture.
107   *
108   * <p>For file versions held in the new architecture, the `GET
109   * /legal_hold_policy_assignments/:id/file_versions_on_hold` API can be used to return all past
110   * file versions available for this policy assignment, and the `GET
111   * /legal_hold_policy_assignments/:id/files_on_hold` API can be used to return any current
112   * (latest) versions of a file under legal hold.
113   *
114   * <p>The `GET /legal_hold_policy_assignments?policy_id={id}` API can be used to find a list of
115   * policy assignments for a given policy ID.
116   *
117   * <p>Once the re-architecture is completed this API will be deprecated.
118   *
119   * @param queryParams Query parameters of getFileVersionLegalHolds method
120   * @param headers Headers of getFileVersionLegalHolds method
121   */
122  public FileVersionLegalHolds getFileVersionLegalHolds(
123      GetFileVersionLegalHoldsQueryParams queryParams, GetFileVersionLegalHoldsHeaders headers) {
124    Map<String, String> queryParamsMap =
125        prepareParams(
126            mapOf(
127                entryOf("policy_id", convertToString(queryParams.getPolicyId())),
128                entryOf("marker", convertToString(queryParams.getMarker())),
129                entryOf("limit", convertToString(queryParams.getLimit()))));
130    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
131    FetchResponse response =
132        this.networkSession
133            .getNetworkClient()
134            .fetch(
135                new FetchOptions.Builder(
136                        String.join(
137                            "",
138                            this.networkSession.getBaseUrls().getBaseUrl(),
139                            "/2.0/file_version_legal_holds"),
140                        "GET")
141                    .params(queryParamsMap)
142                    .headers(headersMap)
143                    .responseFormat(ResponseFormat.JSON)
144                    .auth(this.auth)
145                    .networkSession(this.networkSession)
146                    .build());
147    return JsonManager.deserialize(response.getData(), FileVersionLegalHolds.class);
148  }
149
150  public Authentication getAuth() {
151    return auth;
152  }
153
154  public NetworkSession getNetworkSession() {
155    return networkSession;
156  }
157
158  public static class Builder {
159
160    protected Authentication auth;
161
162    protected NetworkSession networkSession;
163
164    public Builder() {}
165
166    public Builder auth(Authentication auth) {
167      this.auth = auth;
168      return this;
169    }
170
171    public Builder networkSession(NetworkSession networkSession) {
172      this.networkSession = networkSession;
173      return this;
174    }
175
176    public FileVersionLegalHoldsManager build() {
177      if (this.networkSession == null) {
178        this.networkSession = new NetworkSession();
179      }
180      return new FileVersionLegalHoldsManager(this);
181    }
182  }
183}