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.JsonProperty;
019import com.fasterxml.jackson.annotation.JsonTypeInfo;
020
021import java.util.Map;
022
023/**
024 * Box folder.
025 */
026@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = BoxFolder.class)
027public class BoxFolder extends BoxItem {
028
029    public static final String FIELD_FOLDER_UPLOAD_EMAIL = "folder_upload_email";
030
031    public static final String FIELD_ITEM_COLLECTION = "item_collection";
032
033    public static final String FIELD_HAS_COLLABORATIONS = "has_collaborations";
034
035    /**
036     * Constructor.
037     */
038    public BoxFolder() {
039        setType(BoxResourceType.FOLDER.toString());
040    }
041
042    /**
043     * Copy constructor, this does deep copy for all the fields.
044     *
045     * @param obj
046     */
047    public BoxFolder(BoxFolder obj) {
048        super(obj);
049    }
050
051    /**
052     * Instantiate the object from a map. Each entry in the map reflects to a field.
053     *
054     * @param map
055     */
056    public BoxFolder(Map<String, Object> map) {
057        super(map);
058    }
059
060    /**
061     * This is folder specific field, get the email that can be used to upload file into the folder.
062     *
063     * @return email
064     */
065    @JsonProperty(FIELD_FOLDER_UPLOAD_EMAIL)
066    public BoxEmail getFolderUploadEmail() {
067        return (BoxEmail) getValue(FIELD_FOLDER_UPLOAD_EMAIL);
068    }
069
070    /**
071     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}
072     *
073     * @param folderUploadEmail
074     */
075    @JsonProperty(FIELD_FOLDER_UPLOAD_EMAIL)
076    protected void setFolderUploadEmail(BoxEmail folderUploadEmail) {
077        put(FIELD_FOLDER_UPLOAD_EMAIL, folderUploadEmail);
078    }
079
080    /**
081     * Getter.Get the items(files, subfolders, web links...) under this box folder.
082     *
083     * @return collection of children items.
084     */
085    @JsonProperty(FIELD_ITEM_COLLECTION)
086    public BoxCollection getItemCollection() {
087        return (BoxCollection) getValue(FIELD_ITEM_COLLECTION);
088    }
089
090    /**
091     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}
092     *
093     * @param itemCollection children item.
094     */
095    @JsonProperty(FIELD_ITEM_COLLECTION)
096    protected void setItemCollection(BoxCollection itemCollection) {
097        put(FIELD_ITEM_COLLECTION, itemCollection);
098    }
099
100    /**
101     * Getter.Get whether this box folder has collaborations.
102     *
103     * @return whether this box folder has collaborations
104     */
105    @JsonProperty(FIELD_HAS_COLLABORATIONS)
106    public Boolean hasCollaborations() {
107        return (Boolean) getValue(FIELD_HAS_COLLABORATIONS);
108    }
109
110    public boolean hasCollaborations(boolean defaultValue) {
111        Boolean hasCollabs = hasCollaborations();
112        return hasCollabs != null ? hasCollabs : defaultValue;
113    }
114
115    /**
116     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}
117     *
118     * @param hasCollaborations whether folder has collaborations.
119     */
120    @JsonProperty(FIELD_HAS_COLLABORATIONS)
121    protected void setHasCollaborations(Boolean hasCollaborations) {
122        put(FIELD_HAS_COLLABORATIONS, hasCollaborations);
123    }
124}