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 * Comment.
025 */
026@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = BoxComment.class)
027public class BoxComment extends BoxTypedObject {
028
029    public static final String FIELD_IS_REPLY_COMMENT = "is_reply_comment";
030
031    public static final String FIELD_MESSAGE = "message";
032
033    public static final String FIELD_CREATED_BY = "created_by";
034
035    public static final String FIELD_ITEM = "item";
036
037    /**
038     * Constructor.
039     */
040    public BoxComment() {
041        setType(BoxResourceType.COMMENT.toString());
042    }
043
044    /**
045     * Copy constructor, this does deep copy for all the fields.
046     *
047     * @param obj
048     */
049    public BoxComment(BoxComment obj) {
050        super(obj);
051    }
052
053    /**
054     * Instantiate the object from a map. Each entry in the map reflects to a field.
055     *
056     * @param map
057     */
058    public BoxComment(Map<String, Object> map) {
059        super(map);
060    }
061
062    /**
063     * Whether this is a comment replying another comment.
064     *
065     * @return Whether this is a comment replying another comment.
066     */
067    @JsonProperty(FIELD_IS_REPLY_COMMENT)
068    public Boolean isReplyComment() {
069        return (Boolean) getValue(FIELD_IS_REPLY_COMMENT);
070    }
071
072    /**
073     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}
074     *
075     * @param isReplyComment whether it's reply comment
076     */
077    @JsonProperty(FIELD_IS_REPLY_COMMENT)
078    private void setIsReplyComment(Boolean isReplyComment) {
079        put(FIELD_IS_REPLY_COMMENT, isReplyComment);
080    }
081
082    /**
083     * Get the comment String.
084     *
085     * @return The comment String.
086     */
087    @JsonProperty(FIELD_MESSAGE)
088    public String getMessage() {
089        return (String) getValue(FIELD_MESSAGE);
090    }
091
092    /**
093     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}
094     *
095     * @param message the comment String.
096     */
097    @JsonProperty(FIELD_MESSAGE)
098    private void setMessage(String message) {
099        put(FIELD_MESSAGE, message);
100    }
101
102    /**
103     * Get the user creating this comment.
104     *
105     * @return the user creating this comment
106     */
107    @JsonProperty(FIELD_CREATED_BY)
108    public BoxUser getCreatedBy() {
109        return (BoxUser) getValue(FIELD_CREATED_BY);
110    }
111
112    /**
113     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}
114     *
115     * @param createdBy user creating this comment
116     */
117    @JsonProperty(FIELD_CREATED_BY)
118    private void setCreatedBy(BoxUser createdBy) {
119        put(FIELD_CREATED_BY, createdBy);
120    }
121
122    /**
123     * Get the object being commented.
124     *
125     * @return the object being commented
126     */
127    @JsonProperty(FIELD_ITEM)
128    public BoxTypedObject getItem() {
129        return (BoxTypedObject) getValue(FIELD_ITEM);
130    }
131
132    /**
133     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}
134     *
135     * @param item the object commented
136     */
137    @JsonProperty(FIELD_ITEM)
138    private void setItem(BoxTypedObject item) {
139        put(FIELD_ITEM, item);
140    }
141}