001/* 002 * Copyright 2013 Box, Inc. All rights reserved. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.nuxeo.box.api.marshalling.dao; 017 018import com.fasterxml.jackson.annotation.JsonInclude; 019import com.fasterxml.jackson.annotation.JsonProperty; 020import com.fasterxml.jackson.annotation.JsonTypeInfo; 021import org.nuxeo.box.api.utils.ISO8601DateParser; 022 023import java.text.ParseException; 024import java.util.Date; 025import java.util.Map; 026 027/** 028 * Data for collaboration. 029 */ 030@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = BoxCollaboration.class) 031public class BoxCollaboration extends BoxTypedObject { 032 033 public static final String FIELD_CREATED_BY = "created_by"; 034 035 public static final String FIELD_EXPIRES_AT = "expires_at"; 036 037 public static final String FIELD_ACCESSIBLE_BY = "accessible_by"; 038 039 public static final String FIELD_STATUS = "status"; 040 041 public static final String FIELD_ACKNOWLEGED_AT = "acknowledged_at"; 042 043 public static final String FIELD_FOLDER = "item"; 044 045 public static final String FIELD_ROLE = "role"; 046 047 /** 048 * Collaboration invitation is accepted. 049 */ 050 public static final String STATUS_ACCEPTED = "accepted"; 051 052 /** 053 * Collaboration invitation is pending. 054 */ 055 public static final String STATUS_PENDING = "pending"; 056 057 /** 058 * Collaboration invitation is rejected. 059 */ 060 public static final String STATUS_REJECTED = "rejected"; 061 062 /** 063 * Constructor. 064 */ 065 public BoxCollaboration() { 066 setType(BoxResourceType.COLLABORATION.toString()); 067 } 068 069 /** 070 * Copy constructor, this does deep copy for all the fields. 071 * 072 * @param obj 073 */ 074 public BoxCollaboration(BoxCollaboration obj) { 075 super(obj); 076 } 077 078 /** 079 * Instantiate the object from a map. Each entry in the map reflects to a field. 080 * 081 * @param map 082 */ 083 public BoxCollaboration(Map<String, Object> map) { 084 super(map); 085 } 086 087 /** 088 * Get the user creating this collaboration. 089 * 090 * @return the created_by 091 */ 092 @JsonInclude(JsonInclude.Include.ALWAYS) 093 @JsonProperty(FIELD_CREATED_BY) 094 public BoxUser getCreatedBy() { 095 return (BoxUser) getValue(FIELD_CREATED_BY); 096 } 097 098 /** 099 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}. 100 * 101 * @param createdBy the created_by to set 102 */ 103 @JsonProperty(FIELD_CREATED_BY) 104 private void setCreatedBy(BoxUser createdBy) { 105 put(FIELD_CREATED_BY, createdBy); 106 } 107 108 /** 109 * Get the user this collaboration applies to. 110 * 111 * @return the accessible_by 112 */ 113 @JsonInclude(JsonInclude.Include.ALWAYS) 114 @JsonProperty(FIELD_ACCESSIBLE_BY) 115 public BoxUser getAccessibleBy() { 116 return (BoxUser) getValue(FIELD_ACCESSIBLE_BY); 117 } 118 119 /** 120 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}. 121 * 122 * @param accessibleBy the accessible_by to set 123 */ 124 @JsonProperty(FIELD_ACCESSIBLE_BY) 125 private void setAccessibleBy(BoxUser accessibleBy) { 126 put(FIELD_ACCESSIBLE_BY, accessibleBy); 127 } 128 129 /** 130 * Get the time this collaboration expires. This returns a String and can be parsed into {@link java.util.Date} by 131 * 132 * @return the expires_at 133 */ 134 @JsonInclude(JsonInclude.Include.ALWAYS) 135 @JsonProperty(FIELD_EXPIRES_AT) 136 public String getExpiresAt() { 137 return (String) getValue(FIELD_EXPIRES_AT); 138 } 139 140 /** 141 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}. 142 * 143 * @param expiresAt the expires_at to set 144 */ 145 @JsonProperty(FIELD_EXPIRES_AT) 146 private void setExpiresAt(String expiresAt) { 147 put(FIELD_EXPIRES_AT, expiresAt); 148 } 149 150 /** 151 * Get the time this collaboration expires. 152 * 153 * @return Date representation of the expires_at value. Null if there was no expires_at or if it could not be parsed 154 * as an ISO8601 date. 155 * @throws java.text.ParseException 156 */ 157 public Date dateExpiresAt() throws ParseException { 158 return ISO8601DateParser.parseSilently(getExpiresAt()); 159 } 160 161 /** 162 * Get the status of this collaboration. Can be STATUS_ACCEPTED, link STATUS_PENDING or STATUS_REJECTED 163 * 164 * @return the status 165 */ 166 @JsonInclude(JsonInclude.Include.ALWAYS) 167 @JsonProperty(FIELD_STATUS) 168 public String getStatus() { 169 return (String) getValue(FIELD_STATUS); 170 } 171 172 /** 173 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}. 174 * 175 * @param status the status to set 176 */ 177 @JsonProperty(FIELD_STATUS) 178 private void setStatus(String status) { 179 put(FIELD_STATUS, status); 180 } 181 182 /** 183 * Get the role/permission. This is a role/permission String defined in CollaborationRole 184 * 185 * @return the role/permission 186 */ 187 @JsonProperty(FIELD_ROLE) 188 public String getRole() { 189 return (String) getValue(FIELD_ROLE); 190 } 191 192 /** 193 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}. 194 * 195 * @param role the role to set 196 */ 197 @JsonProperty(FIELD_ROLE) 198 private void setRole(String role) { 199 put(FIELD_ROLE, role); 200 } 201 202 /** 203 * Get the time when the status of this collaboration was changed. This returns a String and can be parsed into 204 * {@link java.util.Date} by 205 * 206 * @return the acknowledged_at 207 */ 208 @JsonInclude(JsonInclude.Include.ALWAYS) 209 @JsonProperty(FIELD_ACKNOWLEGED_AT) 210 public String getAcknowledgedAt() { 211 return (String) getValue(FIELD_ACKNOWLEGED_AT); 212 } 213 214 /** 215 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}. 216 * 217 * @param acknowledgedAt the acknowledged_at to set 218 */ 219 @JsonProperty(FIELD_ACKNOWLEGED_AT) 220 private void setAcknowledgedAt(String acknowledgedAt) { 221 put(FIELD_ACKNOWLEGED_AT, acknowledgedAt); 222 } 223 224 /** 225 * Get the folder this collaboration is related to. 226 * 227 * @return item the folder this collaboration is related to 228 */ 229 @JsonProperty(FIELD_FOLDER) 230 public BoxFolder getFolder() { 231 return (BoxFolder) getValue(FIELD_FOLDER); 232 } 233 234 /** 235 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}. 236 * 237 * @param item the item to set 238 */ 239 @JsonProperty(FIELD_FOLDER) 240 private void setFolder(BoxFolder item) { 241 put(FIELD_FOLDER, item); 242 } 243}