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;
019
020import java.util.Map;
021
022public class BoxEvent extends BoxItem {
023
024    // Json fields.
025    public final static String FIELD_EVENT_TYPE = "event_type";
026
027    public final static String FIELD_SOURCE = "source";
028
029    public final static String FIELD_EVENT_ID = "event_id";
030
031    // Event types.
032    public static final String EVENT_TYPE_ITEM_CREATE = "ITEM_CREATE";
033
034    public static final String EVENT_TYPE_ITEM_UPLOAD = "ITEM_UPLOAD";
035
036    public static final String EVENT_TYPE_COMMENT_CREATE = "COMMENT_CREATE";
037
038    public static final String EVENT_TYPE_ITEM_DOWNLOAD = "ITEM_DOWNLOAD";
039
040    public static final String EVENT_TYPE_ITEM_PREVIEW = "ITEM_PREVIEW";
041
042    public static final String EVENT_TYPE_ITEM_MOVE = "ITEM_MOVE";
043
044    public static final String EVENT_TYPE_ITEM_COPY = "ITEM_COPY";
045
046    public static final String EVENT_TYPE_TASK_ASSIGNMENT_CREATE = "TASK_ASSIGNMENT_CREATE";
047
048    public static final String EVENT_TYPE_LOCK_CREATE = "LOCK_CREATE";
049
050    public static final String EVENT_TYPE_LOCK_DESTROY = "LOCK_DESTROY";
051
052    public static final String EVENT_TYPE_ITEM_TRASH = "ITEM_TRASH";
053
054    public static final String EVENT_TYPE_ITEM_UNDELETE_VIA_TRASH = "ITEM_UNDELETE_VIA_TRASH";
055
056    public static final String EVENT_TYPE_COLLAB_ADD_COLLABORATOR = "COLLAB_ADD_COLLABORATOR";
057
058    public static final String EVENT_TYPE_COLLAB_INVITE_COLLABORATOR = "COLLAB_INVITE_COLLABORATOR";
059
060    public static final String EVENT_TYPE_ITEM_SYNC = "ITEM_SYNC";
061
062    public static final String EVENT_TYPE_ITEM_UNSYNC = "ITEM_UNSYNC";
063
064    public static final String EVENT_TYPE_ITEM_RENAME = "ITEM_RENAME";
065
066    public static final String EVENT_TYPE_ITEM_SHARED_CREATE = "ITEM_SHARED_CREATE";
067
068    public static final String EVENT_TYPE_ITEM_SHARED_UNSHARE = "ITEM_SHARED_UNSHARE";
069
070    public static final String EVENT_TYPE_ITEM_SHARED = "ITEM_SHARED";
071
072    public static final String EVENT_TYPE_TAG_ITEM_CREATE = "TAG_ITEM_CREATE";
073
074    public static final String EVENT_TYPE_ADD_LOGIN_ACTIVITY_DEVICE = "ADD_LOGIN_ACTIVITY_DEVICE";
075
076    /**
077     * Constructor.
078     */
079    public BoxEvent() {
080        setType(BoxResourceType.EVENT.toString());
081    }
082
083    /**
084     * Copy constructor, this does deep copy for all the fields.
085     *
086     * @param obj
087     */
088    public BoxEvent(BoxEvent obj) {
089        super(obj);
090    }
091
092    /**
093     * Instantiate the object from a map. Each entry in the map reflects to a field.
094     *
095     * @param map
096     */
097    public BoxEvent(Map<String, Object> map) {
098        super(map);
099    }
100
101    /**
102     * Get event id.
103     *
104     * @return event id.
105     */
106    @Override
107    @JsonProperty(FIELD_EVENT_ID)
108    public String getId() {
109        return (String) getValue(FIELD_EVENT_ID);
110    }
111
112    /**
113     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}
114     *
115     * @param eventId Event id.
116     */
117    @JsonProperty(FIELD_EVENT_ID)
118    private void setId(String eventId) {
119        put(FIELD_EVENT_ID, eventId);
120    }
121
122    /**
123     * Get event type.
124     *
125     * @return event type.
126     */
127    @JsonProperty(FIELD_EVENT_TYPE)
128    public String getEventType() {
129        return (String) getValue(FIELD_EVENT_TYPE);
130    }
131
132    /**
133     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}
134     *
135     * @param eventType Event type. See http://developers.box.com/docs/#events
136     */
137    @JsonProperty(FIELD_EVENT_TYPE)
138    private void setEventType(String eventType) {
139        put(FIELD_EVENT_TYPE, eventType);
140    }
141
142    /**
143     * Get the source item for this event.
144     *
145     * @return source item of this event.
146     */
147    @JsonProperty(FIELD_SOURCE)
148    public BoxTypedObject getSource() {
149        return (BoxTypedObject) getValue(FIELD_SOURCE);
150    }
151
152    /**
153     * Set the source item for this event.
154     *
155     * @param sourceItem source item for this event.
156     */
157    @JsonProperty(FIELD_SOURCE)
158    private void setSource(BoxTypedObject sourceItem) {
159        put(FIELD_SOURCE, sourceItem);
160    }
161
162}