001package com.box.sdk; 002 003import java.net.MalformedURLException; 004import java.net.URL; 005import java.text.ParseException; 006import java.util.Date; 007 008import com.eclipsesource.json.JsonObject; 009import com.eclipsesource.json.JsonValue; 010 011/** 012 * Represents an individual recent item. 013 * 014 * <p>Unless otherwise noted, the methods in this class can throw an unchecked {@link BoxAPIException} (unchecked 015 * meaning that the compiler won't force you to handle it) if an error occurs. If you wish to implement custom error 016 * handling for errors related to the Box REST API, you should capture this exception explicitly.* 017 */ 018public class BoxRecentItem extends BoxJSONObject { 019 private String type; 020 private String interactionType; 021 private BoxItem.Info item; 022 private Date interactedAt; 023 private URL interactionSharedLink; 024 private BoxAPIConnection api; 025 026 /** 027 * Construct a BoxRecentItem. 028 * @param jsonObject the parsed JSON object. 029 * @param api the API connection to be used to fetch interacted item 030 */ 031 public BoxRecentItem(JsonObject jsonObject, BoxAPIConnection api) { 032 super(jsonObject); 033 this.api = api; 034 } 035 036 @Override 037 protected void parseJSONMember(JsonObject.Member member) { 038 super.parseJSONMember(member); 039 040 String memberName = member.getName(); 041 JsonValue value = member.getValue(); 042 try { 043 if (memberName.equals("type")) { 044 this.type = value.asString(); 045 } else if (memberName.equals("interaction_type")) { 046 this.interactionType = value.asString(); 047 } else if (memberName.equals("item")) { 048 String id = value.asObject().get("id").asString(); 049 this.item = new BoxFile(this.api, id).new Info(value.asObject()); 050 } else if (memberName.equals("interacted_at")) { 051 this.interactedAt = BoxDateFormat.parse(value.asString()); 052 } else if (memberName.equals("interaction_shared_link")) { 053 this.interactionSharedLink = new URL(value.asString()); 054 } 055 } catch (ParseException e) { 056 assert false : "A ParseException indicates a bug in the SDK."; 057 } catch (MalformedURLException e) { 058 assert false : "A ParseException indicates a bug in the SDK."; 059 } 060 } 061 062 /** 063 * Get item type. 064 * @return type of item 065 */ 066 public String getType() { 067 return this.type; 068 } 069 070 /** 071 * Get interaction type. 072 * @return interaction type 073 */ 074 public String getInteractionType() { 075 return this.interactionType; 076 } 077 078 /** 079 * Get the item which was interacted with. 080 * @return box item 081 */ 082 public BoxItem.Info getItem() { 083 return this.item; 084 } 085 086 /** 087 * Get the interaction date. 088 * @return interaction date 089 */ 090 public Date getInteractedAt() { 091 return this.interactedAt; 092 } 093 094 /** 095 * Get the shared link, if the item was accessed through a shared link. 096 * @return shared link 097 */ 098 public URL getInteractionSharedLink() { 099 return this.interactionSharedLink; 100 } 101 102}