001package com.box.sdkgen.schemas.appitemassociation; 002 003import com.box.sdkgen.internal.NullableFieldTracker; 004import com.box.sdkgen.internal.SerializableObject; 005import com.box.sdkgen.schemas.appitem.AppItem; 006import com.box.sdkgen.schemas.appitemassociateditem.AppItemAssociatedItem; 007import com.box.sdkgen.schemas.filebase.FileBase; 008import com.box.sdkgen.schemas.folderbase.FolderBase; 009import com.box.sdkgen.schemas.weblinkbase.WebLinkBase; 010import com.box.sdkgen.serialization.json.EnumWrapper; 011import com.fasterxml.jackson.annotation.JsonFilter; 012import com.fasterxml.jackson.annotation.JsonProperty; 013import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 014import com.fasterxml.jackson.databind.annotation.JsonSerialize; 015import java.util.Objects; 016 017/** 018 * An app item association represents an association between a file or folder and an app item. 019 * Associations between a folder and an app item cascade down to all descendants of the folder. 020 */ 021@JsonFilter("nullablePropertyFilter") 022public class AppItemAssociation extends SerializableObject { 023 024 /** The unique identifier for this app item association. */ 025 protected final String id; 026 027 /** The value will always be `app_item_association`. */ 028 @JsonDeserialize( 029 using = AppItemAssociationTypeField.AppItemAssociationTypeFieldDeserializer.class) 030 @JsonSerialize(using = AppItemAssociationTypeField.AppItemAssociationTypeFieldSerializer.class) 031 protected EnumWrapper<AppItemAssociationTypeField> type; 032 033 @JsonProperty("app_item") 034 protected final AppItem appItem; 035 036 protected final AppItemAssociatedItem item; 037 038 public AppItemAssociation(String id, AppItem appItem, FileBase item) { 039 super(); 040 this.id = id; 041 this.appItem = appItem; 042 this.item = new AppItemAssociatedItem(item); 043 this.type = 044 new EnumWrapper<AppItemAssociationTypeField>( 045 AppItemAssociationTypeField.APP_ITEM_ASSOCIATION); 046 } 047 048 public AppItemAssociation(String id, AppItem appItem, FolderBase item) { 049 super(); 050 this.id = id; 051 this.appItem = appItem; 052 this.item = new AppItemAssociatedItem(item); 053 this.type = 054 new EnumWrapper<AppItemAssociationTypeField>( 055 AppItemAssociationTypeField.APP_ITEM_ASSOCIATION); 056 } 057 058 public AppItemAssociation(String id, AppItem appItem, WebLinkBase item) { 059 super(); 060 this.id = id; 061 this.appItem = appItem; 062 this.item = new AppItemAssociatedItem(item); 063 this.type = 064 new EnumWrapper<AppItemAssociationTypeField>( 065 AppItemAssociationTypeField.APP_ITEM_ASSOCIATION); 066 } 067 068 public AppItemAssociation( 069 @JsonProperty("id") String id, 070 @JsonProperty("app_item") AppItem appItem, 071 @JsonProperty("item") AppItemAssociatedItem item) { 072 super(); 073 this.id = id; 074 this.appItem = appItem; 075 this.item = item; 076 this.type = 077 new EnumWrapper<AppItemAssociationTypeField>( 078 AppItemAssociationTypeField.APP_ITEM_ASSOCIATION); 079 } 080 081 protected AppItemAssociation(Builder builder) { 082 super(); 083 this.id = builder.id; 084 this.type = builder.type; 085 this.appItem = builder.appItem; 086 this.item = builder.item; 087 markNullableFieldsAsSet(builder.getExplicitlySetNullableFields()); 088 } 089 090 public String getId() { 091 return id; 092 } 093 094 public EnumWrapper<AppItemAssociationTypeField> getType() { 095 return type; 096 } 097 098 public AppItem getAppItem() { 099 return appItem; 100 } 101 102 public AppItemAssociatedItem getItem() { 103 return item; 104 } 105 106 @Override 107 public boolean equals(Object o) { 108 if (this == o) { 109 return true; 110 } 111 if (o == null || getClass() != o.getClass()) { 112 return false; 113 } 114 AppItemAssociation casted = (AppItemAssociation) o; 115 return Objects.equals(id, casted.id) 116 && Objects.equals(type, casted.type) 117 && Objects.equals(appItem, casted.appItem) 118 && Objects.equals(item, casted.item); 119 } 120 121 @Override 122 public int hashCode() { 123 return Objects.hash(id, type, appItem, item); 124 } 125 126 @Override 127 public String toString() { 128 return "AppItemAssociation{" 129 + "id='" 130 + id 131 + '\'' 132 + ", " 133 + "type='" 134 + type 135 + '\'' 136 + ", " 137 + "appItem='" 138 + appItem 139 + '\'' 140 + ", " 141 + "item='" 142 + item 143 + '\'' 144 + "}"; 145 } 146 147 public static class Builder extends NullableFieldTracker { 148 149 protected final String id; 150 151 protected EnumWrapper<AppItemAssociationTypeField> type; 152 153 protected final AppItem appItem; 154 155 protected final AppItemAssociatedItem item; 156 157 public Builder(String id, AppItem appItem, FileBase item) { 158 super(); 159 this.id = id; 160 this.appItem = appItem; 161 this.item = new AppItemAssociatedItem(item); 162 } 163 164 public Builder(String id, AppItem appItem, FolderBase item) { 165 super(); 166 this.id = id; 167 this.appItem = appItem; 168 this.item = new AppItemAssociatedItem(item); 169 } 170 171 public Builder(String id, AppItem appItem, WebLinkBase item) { 172 super(); 173 this.id = id; 174 this.appItem = appItem; 175 this.item = new AppItemAssociatedItem(item); 176 } 177 178 public Builder(String id, AppItem appItem, AppItemAssociatedItem item) { 179 super(); 180 this.id = id; 181 this.appItem = appItem; 182 this.item = item; 183 } 184 185 public Builder type(AppItemAssociationTypeField type) { 186 this.type = new EnumWrapper<AppItemAssociationTypeField>(type); 187 return this; 188 } 189 190 public Builder type(EnumWrapper<AppItemAssociationTypeField> type) { 191 this.type = type; 192 return this; 193 } 194 195 public AppItemAssociation build() { 196 if (this.type == null) { 197 this.type = 198 new EnumWrapper<AppItemAssociationTypeField>( 199 AppItemAssociationTypeField.APP_ITEM_ASSOCIATION); 200 } 201 return new AppItemAssociation(this); 202 } 203 } 204}