|
7 | 7 | importjava.io.UnsupportedEncodingException; |
8 | 8 | importjava.util.List; |
9 | 9 |
|
10 | | -importcom.brightcove.castlabs.client.request.LinkAccountToSubMerchantRequest; |
| 10 | +importcom.brightcove.castlabs.client.request.*; |
| 11 | +importcom.brightcove.castlabs.client.response.ListAccountsResponse; |
11 | 12 | importcom.fasterxml.jackson.core.JsonProcessingException; |
12 | 13 | importcom.google.common.collect.Lists; |
13 | 14 | importorg.apache.commons.io.IOUtils; |
|
19 | 20 | importorg.apache.http.client.config.RequestConfig; |
20 | 21 | importorg.apache.http.client.entity.UrlEncodedFormEntity; |
21 | 22 | importorg.apache.http.client.methods.CloseableHttpResponse; |
| 23 | +importorg.apache.http.client.methods.HttpGet; |
22 | 24 | importorg.apache.http.client.methods.HttpPost; |
23 | 25 | importorg.apache.http.entity.StringEntity; |
24 | 26 | importorg.apache.http.impl.client.CloseableHttpClient; |
25 | 27 | importorg.apache.http.impl.client.HttpClients; |
26 | 28 | importorg.apache.http.message.BasicNameValuePair; |
27 | 29 |
|
28 | | -importcom.brightcove.castlabs.client.request.IngestKeysRequest; |
29 | 30 | importcom.brightcove.castlabs.client.response.IngestAssetsResponse; |
30 | | -importcom.brightcove.castlabs.client.request.AddSubMerchantAccountRequest; |
31 | 31 | importcom.brightcove.castlabs.client.response.AddSubMerchantAccountResponse; |
32 | 32 | importcom.fasterxml.jackson.databind.DeserializationFeature; |
33 | 33 | importcom.fasterxml.jackson.databind.ObjectMapper; |
@@ -267,6 +267,135 @@ public void linkAccountToSubMerchant(final LinkAccountToSubMerchantRequest reque |
267 | 267 | } |
268 | 268 | } |
269 | 269 |
|
| 270 | +/** |
| 271 | + * Update Account Authorization Setting |
| 272 | + * |
| 273 | + * @param request Request parameters to pass to Castlabs |
| 274 | + * @param merchantUuid UUID for the merchant |
| 275 | + * @throws CastlabsException error reported by Castlabs |
| 276 | + * @throws IOException network error while communicating with Castlabs REST API |
| 277 | + */ |
| 278 | +publicvoidupdateAuthorizationSettings(finalUpdateAuthorizationSettingsRequestrequest,finalStringmerchantUuid) |
| 279 | +throwsIOException,CastlabsException { |
| 280 | + |
| 281 | +finalStringuri =this.getUrlWithTicket(this.ingestionBaseUrl +"frontend/rest/config/v1/" +merchantUuid +"/auth/settings"); |
| 282 | +finalHttpPosthttpRequest =createHttpPostRequest(uri,request); |
| 283 | + |
| 284 | +finalCloseableHttpClienthttpclient =HttpClients.createDefault(); |
| 285 | +try (finalCloseableHttpResponsehttpResponse =httpclient.execute(httpRequest)) { |
| 286 | +finalintstatusCode =httpResponse.getStatusLine().getStatusCode(); |
| 287 | + |
| 288 | +if (statusCode !=HttpStatus.SC_NO_CONTENT) { |
| 289 | +finalHttpEntityresponseEntity =httpResponse.getEntity(); |
| 290 | + |
| 291 | +StringresponseBody =""; |
| 292 | +if (responseEntity !=null) { |
| 293 | +responseBody =IOUtils.toString(responseEntity.getContent()); |
| 294 | + } |
| 295 | + |
| 296 | +thrownewCastlabsException("Unexpected status code from Castlabs: " +statusCode +". Response body: " +responseBody); |
| 297 | + } |
| 298 | + } |
| 299 | + } |
| 300 | + |
| 301 | +/** |
| 302 | + * Add a Shared Secret to the Castlabs Account |
| 303 | + * |
| 304 | + * @param request Request parameters to pass to Castlabs |
| 305 | + * @param merchantUuid UUID for the merchant |
| 306 | + * @throws CastlabsException error reported by Castlabs |
| 307 | + * @throws IOException network error while communicating with Castlabs REST API |
| 308 | + */ |
| 309 | +publicvoidaddSharedSecret(finalSharedSecretRequestrequest,finalStringmerchantUuid) |
| 310 | +throwsIOException,CastlabsException { |
| 311 | + |
| 312 | +finalStringuri =this.getUrlWithTicket(this.ingestionBaseUrl +"frontend/rest/config/v1/" +merchantUuid +"/upfront/secret/add"); |
| 313 | +finalHttpPosthttpRequest =createHttpPostRequest(uri,request); |
| 314 | + |
| 315 | +finalCloseableHttpClienthttpclient =HttpClients.createDefault(); |
| 316 | +try (finalCloseableHttpResponsehttpResponse =httpclient.execute(httpRequest)) { |
| 317 | +finalintstatusCode =httpResponse.getStatusLine().getStatusCode(); |
| 318 | + |
| 319 | +if (statusCode !=HttpStatus.SC_OK) { |
| 320 | +finalHttpEntityresponseEntity =httpResponse.getEntity(); |
| 321 | + |
| 322 | +StringresponseBody =""; |
| 323 | +if (responseEntity !=null) { |
| 324 | +responseBody =IOUtils.toString(responseEntity.getContent()); |
| 325 | + } |
| 326 | + |
| 327 | +thrownewCastlabsException("Unexpected status code from Castlabs: " +statusCode +". Response body: " +responseBody); |
| 328 | + } |
| 329 | + } |
| 330 | + } |
| 331 | + |
| 332 | +/** |
| 333 | + * Add Fairplay configuration to the Castlabs Account |
| 334 | + * |
| 335 | + * @param request Request parameters to pass to Castlabs |
| 336 | + * @param merchantUuid UUID for the merchant |
| 337 | + * @throws CastlabsException error reported by Castlabs |
| 338 | + * @throws IOException network error while communicating with Castlabs REST API |
| 339 | + */ |
| 340 | +publicvoidsetFairplayConfiguration(finalFairplayRequestrequest,finalStringmerchantUuid) |
| 341 | +throwsIOException,CastlabsException { |
| 342 | + |
| 343 | +finalStringuri =this.getUrlWithTicket(this.ingestionBaseUrl +"frontend/rest/config/v1/" +merchantUuid +"/drm/fairplay"); |
| 344 | +finalHttpPosthttpRequest =createHttpPostRequest(uri,request); |
| 345 | + |
| 346 | +finalCloseableHttpClienthttpclient =HttpClients.createDefault(); |
| 347 | +try (finalCloseableHttpResponsehttpResponse =httpclient.execute(httpRequest)) { |
| 348 | +finalintstatusCode =httpResponse.getStatusLine().getStatusCode(); |
| 349 | + |
| 350 | +if (statusCode !=HttpStatus.SC_OK) { |
| 351 | +finalHttpEntityresponseEntity =httpResponse.getEntity(); |
| 352 | + |
| 353 | +StringresponseBody =""; |
| 354 | +if (responseEntity !=null) { |
| 355 | +responseBody =IOUtils.toString(responseEntity.getContent()); |
| 356 | + } |
| 357 | + |
| 358 | +thrownewCastlabsException("Unexpected status code from Castlabs: " +statusCode +". Response body: " +responseBody); |
| 359 | + } |
| 360 | + } |
| 361 | + } |
| 362 | + |
| 363 | +/** |
| 364 | + * List accounts available to a merchant |
| 365 | + * |
| 366 | + * @param merchantUuid UUID for the merchant |
| 367 | + * @return response from Castlabs |
| 368 | + * @throws CastlabsException error reported by Castlabs |
| 369 | + * @throws IOException network error while communicating with Castlabs REST API |
| 370 | + */ |
| 371 | +publicListAccountsResponselistAccounts(finalStringmerchantUuid) |
| 372 | +throwsIOException,CastlabsException { |
| 373 | + |
| 374 | +finalStringuri =this.getUrlWithTicket(this.ingestionBaseUrl +"frontend/rest/config/v1/" +merchantUuid +"/account/list"); |
| 375 | +finalHttpGethttpRequest =newHttpGet(uri); |
| 376 | + |
| 377 | +finalCloseableHttpClienthttpclient =HttpClients.createDefault(); |
| 378 | +try (finalCloseableHttpResponsehttpResponse =httpclient.execute(httpRequest)) { |
| 379 | +finalintstatusCode =httpResponse.getStatusLine().getStatusCode(); |
| 380 | +finalHttpEntityresponseEntity =httpResponse.getEntity(); |
| 381 | +if (responseEntity ==null) { |
| 382 | +thrownewCastlabsException("Empty response entity from Castlabs. HTTP Status: " +httpResponse.getStatusLine().getStatusCode()); |
| 383 | + } |
| 384 | + |
| 385 | +finalStringresponseBody =IOUtils.toString(responseEntity.getContent()); |
| 386 | +if (StringUtils.isBlank(responseBody)) { |
| 387 | +thrownewCastlabsException("Empty response entity from Castlabs. HTTP Status: " +httpResponse.getStatusLine().getStatusCode()); |
| 388 | + } |
| 389 | + |
| 390 | +if (statusCode !=HttpStatus.SC_OK) { |
| 391 | +thrownewCastlabsException("Unexpected status code from Castlabs: " +statusCode +". Response body: " +responseBody); |
| 392 | + } |
| 393 | + |
| 394 | +finalListAccountsResponseresponse =objectMapper.readValue(responseBody,ListAccountsResponse.class); |
| 395 | +returnresponse; |
| 396 | + } |
| 397 | + } |
| 398 | + |
270 | 399 | privateHttpPostcreateHttpPostRequest(finalStringuri,finalObjectbody)throwsJsonProcessingException,UnsupportedEncodingException { |
271 | 400 | finalHttpPostrequest =newHttpPost(uri); |
272 | 401 | request.addHeader("Content-Type","application/json"); |
|