001package com.box.sdkgen.managers.legalholdpolicies;
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.legalholdpolicies.LegalHoldPolicies;
015import com.box.sdkgen.schemas.legalholdpolicy.LegalHoldPolicy;
016import com.box.sdkgen.serialization.json.JsonManager;
017import java.util.Map;
018
019public class LegalHoldPoliciesManager {
020
021  public Authentication auth;
022
023  public NetworkSession networkSession;
024
025  public LegalHoldPoliciesManager() {
026    this.networkSession = new NetworkSession();
027  }
028
029  protected LegalHoldPoliciesManager(Builder builder) {
030    this.auth = builder.auth;
031    this.networkSession = builder.networkSession;
032  }
033
034  /** Retrieves a list of legal hold policies that belong to an enterprise. */
035  public LegalHoldPolicies getLegalHoldPolicies() {
036    return getLegalHoldPolicies(
037        new GetLegalHoldPoliciesQueryParams(), new GetLegalHoldPoliciesHeaders());
038  }
039
040  /**
041   * Retrieves a list of legal hold policies that belong to an enterprise.
042   *
043   * @param queryParams Query parameters of getLegalHoldPolicies method
044   */
045  public LegalHoldPolicies getLegalHoldPolicies(GetLegalHoldPoliciesQueryParams queryParams) {
046    return getLegalHoldPolicies(queryParams, new GetLegalHoldPoliciesHeaders());
047  }
048
049  /**
050   * Retrieves a list of legal hold policies that belong to an enterprise.
051   *
052   * @param headers Headers of getLegalHoldPolicies method
053   */
054  public LegalHoldPolicies getLegalHoldPolicies(GetLegalHoldPoliciesHeaders headers) {
055    return getLegalHoldPolicies(new GetLegalHoldPoliciesQueryParams(), headers);
056  }
057
058  /**
059   * Retrieves a list of legal hold policies that belong to an enterprise.
060   *
061   * @param queryParams Query parameters of getLegalHoldPolicies method
062   * @param headers Headers of getLegalHoldPolicies method
063   */
064  public LegalHoldPolicies getLegalHoldPolicies(
065      GetLegalHoldPoliciesQueryParams queryParams, GetLegalHoldPoliciesHeaders headers) {
066    Map<String, String> queryParamsMap =
067        prepareParams(
068            mapOf(
069                entryOf("policy_name", convertToString(queryParams.getPolicyName())),
070                entryOf("fields", convertToString(queryParams.getFields())),
071                entryOf("marker", convertToString(queryParams.getMarker())),
072                entryOf("limit", convertToString(queryParams.getLimit()))));
073    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
074    FetchResponse response =
075        this.networkSession
076            .getNetworkClient()
077            .fetch(
078                new FetchOptions.Builder(
079                        String.join(
080                            "",
081                            this.networkSession.getBaseUrls().getBaseUrl(),
082                            "/2.0/legal_hold_policies"),
083                        "GET")
084                    .params(queryParamsMap)
085                    .headers(headersMap)
086                    .responseFormat(ResponseFormat.JSON)
087                    .auth(this.auth)
088                    .networkSession(this.networkSession)
089                    .build());
090    return JsonManager.deserialize(response.getData(), LegalHoldPolicies.class);
091  }
092
093  /**
094   * Create a new legal hold policy.
095   *
096   * @param requestBody Request body of createLegalHoldPolicy method
097   */
098  public LegalHoldPolicy createLegalHoldPolicy(CreateLegalHoldPolicyRequestBody requestBody) {
099    return createLegalHoldPolicy(requestBody, new CreateLegalHoldPolicyHeaders());
100  }
101
102  /**
103   * Create a new legal hold policy.
104   *
105   * @param requestBody Request body of createLegalHoldPolicy method
106   * @param headers Headers of createLegalHoldPolicy method
107   */
108  public LegalHoldPolicy createLegalHoldPolicy(
109      CreateLegalHoldPolicyRequestBody requestBody, CreateLegalHoldPolicyHeaders headers) {
110    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
111    FetchResponse response =
112        this.networkSession
113            .getNetworkClient()
114            .fetch(
115                new FetchOptions.Builder(
116                        String.join(
117                            "",
118                            this.networkSession.getBaseUrls().getBaseUrl(),
119                            "/2.0/legal_hold_policies"),
120                        "POST")
121                    .headers(headersMap)
122                    .data(JsonManager.serialize(requestBody))
123                    .contentType("application/json")
124                    .responseFormat(ResponseFormat.JSON)
125                    .auth(this.auth)
126                    .networkSession(this.networkSession)
127                    .build());
128    return JsonManager.deserialize(response.getData(), LegalHoldPolicy.class);
129  }
130
131  /**
132   * Retrieve a legal hold policy.
133   *
134   * @param legalHoldPolicyId The ID of the legal hold policy. Example: "324432"
135   */
136  public LegalHoldPolicy getLegalHoldPolicyById(String legalHoldPolicyId) {
137    return getLegalHoldPolicyById(legalHoldPolicyId, new GetLegalHoldPolicyByIdHeaders());
138  }
139
140  /**
141   * Retrieve a legal hold policy.
142   *
143   * @param legalHoldPolicyId The ID of the legal hold policy. Example: "324432"
144   * @param headers Headers of getLegalHoldPolicyById method
145   */
146  public LegalHoldPolicy getLegalHoldPolicyById(
147      String legalHoldPolicyId, GetLegalHoldPolicyByIdHeaders headers) {
148    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
149    FetchResponse response =
150        this.networkSession
151            .getNetworkClient()
152            .fetch(
153                new FetchOptions.Builder(
154                        String.join(
155                            "",
156                            this.networkSession.getBaseUrls().getBaseUrl(),
157                            "/2.0/legal_hold_policies/",
158                            convertToString(legalHoldPolicyId)),
159                        "GET")
160                    .headers(headersMap)
161                    .responseFormat(ResponseFormat.JSON)
162                    .auth(this.auth)
163                    .networkSession(this.networkSession)
164                    .build());
165    return JsonManager.deserialize(response.getData(), LegalHoldPolicy.class);
166  }
167
168  /**
169   * Update legal hold policy.
170   *
171   * @param legalHoldPolicyId The ID of the legal hold policy. Example: "324432"
172   */
173  public LegalHoldPolicy updateLegalHoldPolicyById(String legalHoldPolicyId) {
174    return updateLegalHoldPolicyById(
175        legalHoldPolicyId,
176        new UpdateLegalHoldPolicyByIdRequestBody(),
177        new UpdateLegalHoldPolicyByIdHeaders());
178  }
179
180  /**
181   * Update legal hold policy.
182   *
183   * @param legalHoldPolicyId The ID of the legal hold policy. Example: "324432"
184   * @param requestBody Request body of updateLegalHoldPolicyById method
185   */
186  public LegalHoldPolicy updateLegalHoldPolicyById(
187      String legalHoldPolicyId, UpdateLegalHoldPolicyByIdRequestBody requestBody) {
188    return updateLegalHoldPolicyById(
189        legalHoldPolicyId, requestBody, new UpdateLegalHoldPolicyByIdHeaders());
190  }
191
192  /**
193   * Update legal hold policy.
194   *
195   * @param legalHoldPolicyId The ID of the legal hold policy. Example: "324432"
196   * @param headers Headers of updateLegalHoldPolicyById method
197   */
198  public LegalHoldPolicy updateLegalHoldPolicyById(
199      String legalHoldPolicyId, UpdateLegalHoldPolicyByIdHeaders headers) {
200    return updateLegalHoldPolicyById(
201        legalHoldPolicyId, new UpdateLegalHoldPolicyByIdRequestBody(), headers);
202  }
203
204  /**
205   * Update legal hold policy.
206   *
207   * @param legalHoldPolicyId The ID of the legal hold policy. Example: "324432"
208   * @param requestBody Request body of updateLegalHoldPolicyById method
209   * @param headers Headers of updateLegalHoldPolicyById method
210   */
211  public LegalHoldPolicy updateLegalHoldPolicyById(
212      String legalHoldPolicyId,
213      UpdateLegalHoldPolicyByIdRequestBody requestBody,
214      UpdateLegalHoldPolicyByIdHeaders headers) {
215    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
216    FetchResponse response =
217        this.networkSession
218            .getNetworkClient()
219            .fetch(
220                new FetchOptions.Builder(
221                        String.join(
222                            "",
223                            this.networkSession.getBaseUrls().getBaseUrl(),
224                            "/2.0/legal_hold_policies/",
225                            convertToString(legalHoldPolicyId)),
226                        "PUT")
227                    .headers(headersMap)
228                    .data(JsonManager.serialize(requestBody))
229                    .contentType("application/json")
230                    .responseFormat(ResponseFormat.JSON)
231                    .auth(this.auth)
232                    .networkSession(this.networkSession)
233                    .build());
234    return JsonManager.deserialize(response.getData(), LegalHoldPolicy.class);
235  }
236
237  /**
238   * Delete an existing legal hold policy.
239   *
240   * <p>This is an asynchronous process. The policy will not be fully deleted yet when the response
241   * returns.
242   *
243   * @param legalHoldPolicyId The ID of the legal hold policy. Example: "324432"
244   */
245  public void deleteLegalHoldPolicyById(String legalHoldPolicyId) {
246    deleteLegalHoldPolicyById(legalHoldPolicyId, new DeleteLegalHoldPolicyByIdHeaders());
247  }
248
249  /**
250   * Delete an existing legal hold policy.
251   *
252   * <p>This is an asynchronous process. The policy will not be fully deleted yet when the response
253   * returns.
254   *
255   * @param legalHoldPolicyId The ID of the legal hold policy. Example: "324432"
256   * @param headers Headers of deleteLegalHoldPolicyById method
257   */
258  public void deleteLegalHoldPolicyById(
259      String legalHoldPolicyId, DeleteLegalHoldPolicyByIdHeaders headers) {
260    Map<String, String> headersMap = prepareParams(mergeMaps(mapOf(), headers.getExtraHeaders()));
261    FetchResponse response =
262        this.networkSession
263            .getNetworkClient()
264            .fetch(
265                new FetchOptions.Builder(
266                        String.join(
267                            "",
268                            this.networkSession.getBaseUrls().getBaseUrl(),
269                            "/2.0/legal_hold_policies/",
270                            convertToString(legalHoldPolicyId)),
271                        "DELETE")
272                    .headers(headersMap)
273                    .responseFormat(ResponseFormat.NO_CONTENT)
274                    .auth(this.auth)
275                    .networkSession(this.networkSession)
276                    .build());
277  }
278
279  public Authentication getAuth() {
280    return auth;
281  }
282
283  public NetworkSession getNetworkSession() {
284    return networkSession;
285  }
286
287  public static class Builder {
288
289    protected Authentication auth;
290
291    protected NetworkSession networkSession;
292
293    public Builder() {}
294
295    public Builder auth(Authentication auth) {
296      this.auth = auth;
297      return this;
298    }
299
300    public Builder networkSession(NetworkSession networkSession) {
301      this.networkSession = networkSession;
302      return this;
303    }
304
305    public LegalHoldPoliciesManager build() {
306      if (this.networkSession == null) {
307        this.networkSession = new NetworkSession();
308      }
309      return new LegalHoldPoliciesManager(this);
310    }
311  }
312}