001package com.box.sdk; 002 003import com.eclipsesource.json.Json; 004import com.eclipsesource.json.JsonArray; 005import com.eclipsesource.json.JsonObject; 006import com.eclipsesource.json.JsonValue; 007import java.net.URL; 008import java.util.ArrayList; 009import java.util.Date; 010import java.util.List; 011 012/** 013 * Represents a retention policy. 014 * A retention policy blocks permanent deletion of content for a specified amount of time. 015 * Admins can create retention policies and then later assign them to specific folders or their entire enterprise. 016 * 017 * @see <a href="https://developer.box.com/reference/resources/retention-policy/">Box retention policy</a> 018 * 019 * <p>Unless otherwise noted, the methods in this class can throw an unchecked {@link BoxAPIException} (unchecked 020 * meaning that the compiler won't force you to handle it) if an error occurs. If you wish to implement custom error 021 * handling for errors related to the Box REST API, you should capture this exception explicitly.</p> 022 */ 023@BoxResourceType("retention_policy") 024public class BoxRetentionPolicy extends BoxResource { 025 /** 026 * The URL template used for operation with retention policies. 027 */ 028 public static final URLTemplate RETENTION_POLICIES_URL_TEMPLATE = new URLTemplate("retention_policies"); 029 030 /** 031 * The URL template used for operation with retention policy with given ID. 032 */ 033 public static final URLTemplate POLICY_URL_TEMPLATE = new URLTemplate("retention_policies/%s"); 034 035 /** 036 * The URL template used for operation with retention policy assignments. 037 */ 038 public static final URLTemplate ASSIGNMENTS_URL_TEMPLATE = new URLTemplate("retention_policies/%s/assignments"); 039 040 /** 041 * Will cause the content retained by the policy to be permanently deleted. 042 */ 043 public static final String ACTION_PERMANENTLY_DELETE = "permanently_delete"; 044 045 /** 046 * Will lift the retention policy from the content, allowing it to be deleted by users. 047 */ 048 public static final String ACTION_REMOVE_RETENTION = "remove_retention"; 049 050 /** 051 * Status corresponding to active retention policy. 052 */ 053 public static final String STATUS_ACTIVE = "active"; 054 055 /** 056 * Status corresponding to retired retention policy. 057 */ 058 public static final String STATUS_RETIRED = "retired"; 059 060 /** 061 * The default limit of entries per response. 062 */ 063 private static final int DEFAULT_LIMIT = 100; 064 065 /** 066 * Constructs a retention policy for a resource with a given ID. 067 * 068 * @param api the API connection to be used by the resource. 069 * @param id the ID of the resource. 070 */ 071 public BoxRetentionPolicy(BoxAPIConnection api, String id) { 072 super(api, id); 073 } 074 075 /** 076 * Used to create a new indefinite retention policy. 077 * 078 * @param api the API connection to be used by the created user. 079 * @param name the name of the retention policy. 080 * @return the created retention policy's info. 081 */ 082 public static BoxRetentionPolicy.Info createIndefinitePolicy(BoxAPIConnection api, String name) { 083 return createRetentionPolicy( 084 api, name, BoxRetentionPolicyType.Indefinite, 0, BoxRetentionPolicyAction.RemoveRetention 085 ); 086 } 087 088 /** 089 * Used to create a new indefinite retention policy with optional parameters. 090 * 091 * @param api the API connection to be used by the created user. 092 * @param name the name of the retention policy. 093 * @param optionalParams the optional parameters. 094 * @return the created retention policy's info. 095 */ 096 public static BoxRetentionPolicy.Info createIndefinitePolicy( 097 BoxAPIConnection api, String name, RetentionPolicyParams optionalParams 098 ) { 099 return createRetentionPolicy( 100 api, name, BoxRetentionPolicyType.Indefinite, 0, BoxRetentionPolicyAction.RemoveRetention, optionalParams 101 ); 102 } 103 104 /** 105 * Used to create a new finite retention policy. 106 * 107 * @param api the API connection to be used by the created user. 108 * @param name the name of the retention policy. 109 * @param length the duration in days that the retention policy will be active for after being assigned to content. 110 * @param action the disposition action can be "permanently_delete" or "remove_retention". 111 * @return the created retention policy's info. 112 * @deprecated Use {@link BoxRetentionPolicy#createFinitePolicy(BoxAPIConnection, String, int, BoxRetentionPolicyAction)} 113 */ 114 @Deprecated 115 public static BoxRetentionPolicy.Info createFinitePolicy(BoxAPIConnection api, 116 String name, 117 int length, 118 String action) { 119 return createRetentionPolicy( 120 api, name, BoxRetentionPolicyType.Finite, length, BoxRetentionPolicyAction.valueOf(action) 121 ); 122 } 123 124 /** 125 * Used to create a new finite retention policy. 126 * 127 * @param api the API connection to be used by the created user. 128 * @param name the name of the retention policy. 129 * @param length the duration in days that the retention policy will be active for after being assigned to content. 130 * @param action the disposition action can be "permanently_delete" or "remove_retention". 131 * @return the created retention policy's info. 132 */ 133 public static BoxRetentionPolicy.Info createFinitePolicy(BoxAPIConnection api, 134 String name, 135 int length, 136 BoxRetentionPolicyAction action) { 137 return createRetentionPolicy(api, name, BoxRetentionPolicyType.Finite, length, action); 138 } 139 140 /** 141 * Used to create a new finite retention policy with optional parameters. 142 * 143 * @param api the API connection to be used by the created user. 144 * @param name the name of the retention policy. 145 * @param length the duration in days that the retention policy will be active for after being assigned to content. 146 * @param action the disposition action can be "permanently_delete" or "remove_retention". 147 * @param optionalParams the optional parameters. 148 * @return the created retention policy's info. 149 * @deprecated Use {@link BoxRetentionPolicy#createFinitePolicy(BoxAPIConnection, String, int, BoxRetentionPolicyAction, RetentionPolicyParams)} 150 */ 151 @Deprecated 152 public static BoxRetentionPolicy.Info createFinitePolicy( 153 BoxAPIConnection api, 154 String name, 155 int length, 156 String action, 157 RetentionPolicyParams optionalParams 158 ) { 159 return createRetentionPolicy( 160 api, name, BoxRetentionPolicyType.Finite, length, BoxRetentionPolicyAction.valueOf(action), optionalParams 161 ); 162 } 163 164 /** 165 * Used to create a new finite retention policy with optional parameters. 166 * 167 * @param api the API connection to be used by the created user. 168 * @param name the name of the retention policy. 169 * @param length the duration in days that the retention policy will be active for after being assigned to content. 170 * @param action the disposition action can be "permanently_delete" or "remove_retention". 171 * @param optionalParams the optional parameters. 172 * @return the created retention policy's info. 173 */ 174 public static BoxRetentionPolicy.Info createFinitePolicy( 175 BoxAPIConnection api, 176 String name, 177 int length, 178 BoxRetentionPolicyAction action, 179 RetentionPolicyParams optionalParams 180 ) { 181 return createRetentionPolicy(api, name, BoxRetentionPolicyType.Finite, length, action, optionalParams); 182 } 183 184 /** 185 * Used to create a new retention policy. 186 * 187 * @param api the API connection to be used by the created user. 188 * @param name the name of the retention policy. 189 * @param type the type of the retention policy. Can be "finite" or "indefinite". 190 * @param length the duration in days that the retention policy will be active for after being assigned to content. 191 * @param action the disposition action can be "permanently_delete" or "remove_retention". 192 * @return the created retention policy's info. 193 */ 194 private static BoxRetentionPolicy.Info createRetentionPolicy(BoxAPIConnection api, 195 String name, 196 BoxRetentionPolicyType type, 197 int length, 198 BoxRetentionPolicyAction action) { 199 return createRetentionPolicy(api, name, type, length, action, null); 200 } 201 202 /** 203 * Used to create a new retention policy with optional parameters. 204 * 205 * @param api the API connection to be used by the created user. 206 * @param name the name of the retention policy. 207 * @param type the type of the retention policy. Can be "finite" or "indefinite". 208 * @param length the duration in days that the retention policy will be active for after being assigned to content. 209 * @param action the disposition action can be "permanently_delete" or "remove_retention". 210 * @param optionalParams the optional parameters. 211 * @return the created retention policy's info. 212 */ 213 private static BoxRetentionPolicy.Info createRetentionPolicy( 214 BoxAPIConnection api, 215 String name, 216 BoxRetentionPolicyType type, 217 int length, 218 BoxRetentionPolicyAction action, 219 RetentionPolicyParams optionalParams 220 ) { 221 URL url = RETENTION_POLICIES_URL_TEMPLATE.build(api.getBaseURL()); 222 BoxJSONRequest request = new BoxJSONRequest(api, url, "POST"); 223 JsonObject requestJSON = new JsonObject() 224 .add("policy_name", name) 225 .add("policy_type", type.value) 226 .add("disposition_action", action.value); 227 if (type != BoxRetentionPolicyType.Indefinite) { 228 requestJSON.add("retention_length", length); 229 } 230 if (optionalParams != null) { 231 requestJSON.add("can_owner_extend_retention", optionalParams.getCanOwnerExtendRetention()); 232 requestJSON.add("are_owners_notified", optionalParams.getAreOwnersNotified()); 233 requestJSON.add("description", optionalParams.getDescription()); 234 235 List<BoxUser.Info> customNotificationRecipients = optionalParams.getCustomNotificationRecipients(); 236 if (customNotificationRecipients.size() > 0) { 237 JsonArray users = new JsonArray(); 238 for (BoxUser.Info user : customNotificationRecipients) { 239 JsonObject userJSON = new JsonObject() 240 .add("type", "user") 241 .add("id", user.getID()); 242 users.add(userJSON); 243 } 244 requestJSON.add("custom_notification_recipients", users); 245 } 246 } 247 request.setBody(requestJSON.toString()); 248 BoxJSONResponse response = (BoxJSONResponse) request.send(); 249 JsonObject responseJSON = Json.parse(response.getJSON()).asObject(); 250 BoxRetentionPolicy createdPolicy = new BoxRetentionPolicy(api, responseJSON.get("id").asString()); 251 return createdPolicy.new Info(responseJSON); 252 } 253 254 /** 255 * Returns all the retention policies. 256 * 257 * @param api the API connection to be used by the resource. 258 * @param fields the fields to retrieve. 259 * @return an iterable with all the retention policies. 260 */ 261 public static Iterable<BoxRetentionPolicy.Info> getAll(final BoxAPIConnection api, String... fields) { 262 return getAll(null, null, null, DEFAULT_LIMIT, api, fields); 263 } 264 265 /** 266 * Returns all the retention policies with specified filters. 267 * 268 * @param name a name to filter the retention policies by. A trailing partial match search is performed. 269 * Set to null if no name filtering is required. 270 * @param type a policy type to filter the retention policies by. Set to null if no type filtering is required. 271 * @param userID a user id to filter the retention policies by. Set to null if no type filtering is required. 272 * @param limit the limit of items per single response. The default value is 100. 273 * @param api the API connection to be used by the resource. 274 * @param fields the fields to retrieve. 275 * @return an iterable with all the retention policies met search conditions. 276 */ 277 public static Iterable<BoxRetentionPolicy.Info> getAll( 278 String name, String type, String userID, int limit, final BoxAPIConnection api, String... fields) { 279 QueryStringBuilder queryString = new QueryStringBuilder(); 280 if (name != null) { 281 queryString.appendParam("policy_name", name); 282 } 283 if (type != null) { 284 queryString.appendParam("policy_type", type); 285 } 286 if (userID != null) { 287 queryString.appendParam("created_by_user_id", userID); 288 } 289 if (fields.length > 0) { 290 queryString.appendParam("fields", fields); 291 } 292 URL url = RETENTION_POLICIES_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), queryString.toString()); 293 return new BoxResourceIterable<BoxRetentionPolicy.Info>(api, url, limit) { 294 295 @Override 296 protected BoxRetentionPolicy.Info factory(JsonObject jsonObject) { 297 BoxRetentionPolicy policy = new BoxRetentionPolicy(api, jsonObject.get("id").asString()); 298 return policy.new Info(jsonObject); 299 } 300 301 }; 302 } 303 304 /** 305 * Returns iterable with all folder assignments of this retention policy. 306 * 307 * @param fields the fields to retrieve. 308 * @return an iterable containing all folder assignments. 309 */ 310 public Iterable<BoxRetentionPolicyAssignment.Info> getFolderAssignments(String... fields) { 311 return this.getFolderAssignments(DEFAULT_LIMIT, fields); 312 } 313 314 /** 315 * Returns iterable with all folder assignments of this retention policy. 316 * 317 * @param limit the limit of entries per response. The default value is 100. 318 * @param fields the fields to retrieve. 319 * @return an iterable containing all folder assignments. 320 */ 321 public Iterable<BoxRetentionPolicyAssignment.Info> getFolderAssignments(int limit, String... fields) { 322 return this.getAssignments(BoxRetentionPolicyAssignment.TYPE_FOLDER, limit, fields); 323 } 324 325 /** 326 * Returns iterable with all enterprise assignments of this retention policy. 327 * 328 * @param fields the fields to retrieve. 329 * @return an iterable containing all enterprise assignments. 330 */ 331 public Iterable<BoxRetentionPolicyAssignment.Info> getEnterpriseAssignments(String... fields) { 332 return this.getEnterpriseAssignments(DEFAULT_LIMIT, fields); 333 } 334 335 /** 336 * Returns iterable with all enterprise assignments of this retention policy. 337 * 338 * @param limit the limit of entries per response. The default value is 100. 339 * @param fields the fields to retrieve. 340 * @return an iterable containing all enterprise assignments. 341 */ 342 public Iterable<BoxRetentionPolicyAssignment.Info> getEnterpriseAssignments(int limit, String... fields) { 343 return this.getAssignments(BoxRetentionPolicyAssignment.TYPE_ENTERPRISE, limit, fields); 344 } 345 346 /** 347 * Returns iterable with all assignments of this retention policy. 348 * 349 * @param fields the fields to retrieve. 350 * @return an iterable containing all assignments. 351 */ 352 public Iterable<BoxRetentionPolicyAssignment.Info> getAllAssignments(String... fields) { 353 return this.getAllAssignments(DEFAULT_LIMIT, fields); 354 } 355 356 /** 357 * Returns iterable with all assignments of this retention policy. 358 * 359 * @param limit the limit of entries per response. The default value is 100. 360 * @param fields the fields to retrieve. 361 * @return an iterable containing all assignments. 362 */ 363 public Iterable<BoxRetentionPolicyAssignment.Info> getAllAssignments(int limit, String... fields) { 364 return this.getAssignments(null, limit, fields); 365 } 366 367 /** 368 * Returns iterable with all assignments of given type of this retention policy. 369 * 370 * @param type the type of the retention policy assignment to retrieve. Can either be "folder" or "enterprise". 371 * @param limit the limit of entries per response. The default value is 100. 372 * @param fields the fields to retrieve. 373 * @return an iterable containing all assignments of given type. 374 */ 375 private Iterable<BoxRetentionPolicyAssignment.Info> getAssignments(String type, int limit, String... fields) { 376 QueryStringBuilder queryString = new QueryStringBuilder(); 377 if (type != null) { 378 queryString.appendParam("type", type); 379 } 380 if (fields.length > 0) { 381 queryString.appendParam("fields", fields); 382 } 383 URL url = ASSIGNMENTS_URL_TEMPLATE.buildWithQuery(getAPI().getBaseURL(), queryString.toString(), getID()); 384 return new BoxResourceIterable<BoxRetentionPolicyAssignment.Info>(getAPI(), url, limit) { 385 386 @Override 387 protected BoxRetentionPolicyAssignment.Info factory(JsonObject jsonObject) { 388 BoxRetentionPolicyAssignment assignment 389 = new BoxRetentionPolicyAssignment(getAPI(), jsonObject.get("id").asString()); 390 return assignment.new Info(jsonObject); 391 } 392 393 }; 394 } 395 396 /** 397 * Assigns this retention policy to folder. 398 * 399 * @param folder the folder to assign policy to. 400 * @return info about created assignment. 401 */ 402 public BoxRetentionPolicyAssignment.Info assignTo(BoxFolder folder) { 403 return BoxRetentionPolicyAssignment.createAssignmentToFolder(this.getAPI(), this.getID(), folder.getID()); 404 } 405 406 /** 407 * Assigns this retention policy to the current enterprise. 408 * 409 * @return info about created assignment. 410 */ 411 public BoxRetentionPolicyAssignment.Info assignToEnterprise() { 412 return BoxRetentionPolicyAssignment.createAssignmentToEnterprise(this.getAPI(), this.getID()); 413 } 414 415 /** 416 * Assigns this retention policy to a metadata template, optionally with certain field values. 417 * 418 * @param templateID the ID of the metadata template to apply to. 419 * @param fieldFilters optional field value filters. 420 * @return info about the created assignment. 421 */ 422 public BoxRetentionPolicyAssignment.Info assignToMetadataTemplate(String templateID, 423 MetadataFieldFilter... fieldFilters) { 424 return assignToMetadataTemplate(templateID, null, fieldFilters); 425 } 426 427 /** 428 * Assigns this retention policy to a metadata template, optionally with certain field values. 429 * 430 * @param templateID the ID of the metadata template to apply to. 431 * @param startDateField the date the retention policy assignment begins. This field can be a date field's metadata attribute key id. 432 * @param fieldFilters optional field value filters. 433 * @return info about the created assignment. 434 */ 435 public BoxRetentionPolicyAssignment.Info assignToMetadataTemplate(String templateID, 436 String startDateField, 437 MetadataFieldFilter... fieldFilters) { 438 return BoxRetentionPolicyAssignment.createAssignmentToMetadata(this.getAPI(), this.getID(), templateID, 439 startDateField, fieldFilters); 440 } 441 442 /** 443 * Updates the information about this retention policy with any info fields that have been modified locally. 444 * 445 * @param info the updated info. 446 */ 447 public void updateInfo(BoxRetentionPolicy.Info info) { 448 URL url = POLICY_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); 449 BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT"); 450 request.setBody(info.getPendingChanges()); 451 BoxJSONResponse response = (BoxJSONResponse) request.send(); 452 JsonObject responseJSON = Json.parse(response.getJSON()).asObject(); 453 info.update(responseJSON); 454 } 455 456 /** 457 * Returns information about this retention policy. 458 * 459 * @param fields the fields to retrieve. 460 * @return information about this retention policy. 461 */ 462 public BoxRetentionPolicy.Info getInfo(String... fields) { 463 QueryStringBuilder builder = new QueryStringBuilder(); 464 if (fields.length > 0) { 465 builder.appendParam("fields", fields); 466 } 467 URL url = POLICY_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), builder.toString(), this.getID()); 468 BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET"); 469 BoxJSONResponse response = (BoxJSONResponse) request.send(); 470 JsonObject responseJSON = Json.parse(response.getJSON()).asObject(); 471 return new Info(responseJSON); 472 } 473 474 /** 475 * Contains information about the retention policy. 476 */ 477 public class Info extends BoxResource.Info { 478 479 /** 480 * @see #getPolicyName() 481 */ 482 private String policyName; 483 484 /** 485 * @see #getPolicyType() 486 */ 487 private String policyType; 488 489 /** 490 * @see #getRetentionLength() 491 */ 492 private int retentionLength; 493 494 /** 495 * @see #getDispositionAction() 496 */ 497 private String dispositionAction; 498 499 /** 500 * @see #getStatus() 501 */ 502 private String status; 503 504 /** 505 * @see #getCreatedBy() 506 */ 507 private BoxUser.Info createdBy; 508 509 /** 510 * @see #getCreatedAt() 511 */ 512 private Date createdAt; 513 514 /** 515 * @see #getModifiedAt() 516 */ 517 private Date modifiedAt; 518 519 /** 520 * @see #getCanOwnerExtendRetention() 521 */ 522 private boolean canOwnerExtendRetention; 523 524 /** 525 * @see #getAreOwnersNotified() 526 */ 527 private boolean areOwnersNotified; 528 529 /** 530 * @see #getDescription() 531 */ 532 private String description; 533 534 private List<BoxUser.Info> customNotificationRecipients; 535 536 /** 537 * Constructs an empty Info object. 538 */ 539 public Info() { 540 super(); 541 } 542 543 /** 544 * Constructs an Info object by parsing information from a JSON string. 545 * 546 * @param json the JSON string to parse. 547 */ 548 public Info(String json) { 549 super(json); 550 } 551 552 /** 553 * Constructs an Info object using an already parsed JSON object. 554 * 555 * @param jsonObject the parsed JSON object. 556 */ 557 Info(JsonObject jsonObject) { 558 super(jsonObject); 559 } 560 561 /** 562 * {@inheritDoc} 563 */ 564 @Override 565 public BoxResource getResource() { 566 return BoxRetentionPolicy.this; 567 } 568 569 /** 570 * Gets the name given to the retention policy. 571 * 572 * @return name given to the retention policy. 573 */ 574 public String getPolicyName() { 575 return this.policyName; 576 } 577 578 /** 579 * Update the policy name to a new value. 580 * 581 * @param policyName the new policy name. 582 */ 583 public void setPolicyName(String policyName) { 584 this.policyName = policyName; 585 this.addPendingChange("policy_name", policyName); 586 } 587 588 /** 589 * Gets the type of the retention policy. 590 * A retention policy type can either be "finite", 591 * where a specific amount of time to retain the content is known upfront, 592 * or "indefinite", where the amount of time to retain the content is still unknown. 593 * 594 * @return the type of the retention policy. 595 */ 596 public String getPolicyType() { 597 return this.policyType; 598 } 599 600 /** 601 * Gets the length of the retention policy. This length specifies the duration 602 * in days that the retention policy will be active for after being assigned to content. 603 * 604 * @return the length of the retention policy. 605 */ 606 public int getRetentionLength() { 607 return this.retentionLength; 608 } 609 610 /** 611 * Gets the disposition action of the retention policy. 612 * This action can be "permanently_delete", or "remove_retention". 613 * 614 * @return the disposition action of the retention policy. 615 */ 616 public String getDispositionAction() { 617 return this.dispositionAction; 618 } 619 620 /** 621 * Set the action to take when retention period ends. 622 * 623 * @param dispositionAction the new action. 624 */ 625 public void setDispositionAction(String dispositionAction) { 626 this.dispositionAction = dispositionAction; 627 this.addPendingChange("disposition_action", dispositionAction); 628 } 629 630 /** 631 * Gets the status of the retention policy. 632 * The status can be "active" or "retired". 633 * 634 * @return the status of the retention policy. 635 */ 636 public String getStatus() { 637 return this.status; 638 } 639 640 /** 641 * Set the policy status. 642 * 643 * @param status the new status value. 644 */ 645 public void setStatus(String status) { 646 this.status = status; 647 this.addPendingChange("status", status); 648 } 649 650 /** 651 * Gets info about the user created the retention policy. 652 * 653 * @return info about the user created the retention policy. 654 */ 655 public BoxUser.Info getCreatedBy() { 656 return this.createdBy; 657 } 658 659 /** 660 * Gets the time that the retention policy was created. 661 * 662 * @return the time that the retention policy was created. 663 */ 664 public Date getCreatedAt() { 665 return this.createdAt; 666 } 667 668 /** 669 * Gets the time that the retention policy was last modified. 670 * 671 * @return the time that the retention policy was last modified. 672 */ 673 public Date getModifiedAt() { 674 return this.modifiedAt; 675 } 676 677 /** 678 * Gets the flag to denote that the owner of a retained file can extend the retention when near expiration. 679 * 680 * @return the boolean flag. 681 */ 682 public boolean getCanOwnerExtendRetention() { 683 return this.canOwnerExtendRetention; 684 } 685 686 /** 687 * Gets the flag to denote that owners and co-owners of a retained file will get notified when near expiration. 688 * 689 * @return the boolean flag. 690 */ 691 public boolean getAreOwnersNotified() { 692 return this.areOwnersNotified; 693 } 694 695 /** 696 * Gets the additional text desription of the retention policy. 697 * 698 * @return the additional text desription of the retention policy 699 */ 700 public String getDescription() { 701 return this.description; 702 } 703 704 /** 705 * Set the additional text desription of the retention policy. 706 * 707 * @param description the new text desription of the retention policy 708 */ 709 public void setDescription(String description) { 710 this.description = description; 711 this.addPendingChange("description", description); 712 } 713 714 /** 715 * Gets the list of users to be notified of a retained file when near expiration. 716 * 717 * @return the list of users to be notified. 718 */ 719 public List<BoxUser.Info> getCustomNotificationRecipients() { 720 return this.customNotificationRecipients; 721 } 722 723 /** 724 * {@inheritDoc} 725 */ 726 @Override 727 void parseJSONMember(JsonObject.Member member) { 728 super.parseJSONMember(member); 729 String memberName = member.getName(); 730 JsonValue value = member.getValue(); 731 try { 732 if (memberName.equals("policy_name")) { 733 this.policyName = value.asString(); 734 } else if (memberName.equals("policy_type")) { 735 this.policyType = value.asString(); 736 } else if (memberName.equals("retention_length")) { 737 int intVal; 738 if (value.asString().equals(BoxRetentionPolicyType.Indefinite.value)) { 739 intVal = -1; 740 } else { 741 intVal = Integer.parseInt(value.asString()); 742 } 743 744 this.retentionLength = intVal; 745 } else if (memberName.equals("disposition_action")) { 746 this.dispositionAction = value.asString(); 747 } else if (memberName.equals("status")) { 748 this.status = value.asString(); 749 } else if (memberName.equals("created_by")) { 750 JsonObject userJSON = value.asObject(); 751 if (this.createdBy == null) { 752 String userID = userJSON.get("id").asString(); 753 BoxUser user = new BoxUser(getAPI(), userID); 754 this.createdBy = user.new Info(userJSON); 755 } else { 756 this.createdBy.update(userJSON); 757 } 758 } else if (memberName.equals("created_at")) { 759 this.createdAt = BoxDateFormat.parse(value.asString()); 760 } else if (memberName.equals("modified_at")) { 761 this.modifiedAt = BoxDateFormat.parse(value.asString()); 762 } else if (memberName.equals("can_owner_extend_retention")) { 763 this.canOwnerExtendRetention = value.asBoolean(); 764 } else if (memberName.equals("are_owners_notified")) { 765 this.areOwnersNotified = value.asBoolean(); 766 } else if (memberName.equals("description")) { 767 this.description = value.asString(); 768 } else if (memberName.equals("custom_notification_recipients")) { 769 List<BoxUser.Info> recipients = new ArrayList<BoxUser.Info>(); 770 for (JsonValue userJSON : value.asArray()) { 771 String userID = userJSON.asObject().get("id").asString(); 772 BoxUser user = new BoxUser(getAPI(), userID); 773 recipients.add(user.new Info(userJSON.asObject())); 774 } 775 this.customNotificationRecipients = recipients; 776 } 777 } catch (Exception e) { 778 throw new BoxDeserializationException(memberName, value.toString(), e); 779 } 780 } 781 } 782 783 private enum BoxRetentionPolicyType { 784 /** 785 * Type for finite retention policies. Finite retention policies has the duration. 786 */ 787 Finite("finite"), 788 /** 789 * Type for indefinite retention policies. Indefinite retention policies can have only 790 * {@link BoxRetentionPolicyAction#RemoveRetention} assigned action. 791 */ 792 Indefinite("indefinite"); 793 794 private final String value; 795 796 BoxRetentionPolicyType(String value) { 797 this.value = value; 798 } 799 } 800 801 /** 802 * The disposition action of the retention policy. 803 */ 804 public enum BoxRetentionPolicyAction { 805 /** 806 * Will cause the content retained by the policy to be permanently deleted. 807 */ 808 PermanentlyDelete("permanently_delete"), 809 810 /** 811 * Will lift the retention policy from the content, allowing it to be deleted by users. 812 */ 813 RemoveRetention("remove_retention"); 814 815 private final String value; 816 817 BoxRetentionPolicyAction(String value) { 818 this.value = value; 819 } 820 } 821}