001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2011 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.api.batch;
021
022 import org.apache.commons.lang.builder.ToStringBuilder;
023 import org.sonar.api.database.BaseIdentifiable;
024 import org.sonar.api.database.model.Snapshot;
025
026 import java.util.Date;
027
028 import javax.persistence.*;
029
030 /**
031 * @since 1.10
032 */
033 @Entity
034 @Table(name = "events")
035 public class Event extends BaseIdentifiable {
036 public static final String CATEGORY_VERSION = "Version";
037 public static final String CATEGORY_ALERT = "Alert";
038
039 @Column(name = "name", updatable = true, nullable = true, length = 50)
040 private String name;
041
042 @Column(name = "description", updatable = true, nullable = true, length = 3072)
043 private String description;
044
045 @Column(name = "category", updatable = true, nullable = true, length = 50)
046 private String category;
047
048 @Column(name = "event_date", updatable = true, nullable = false)
049 private Date date;
050
051 @Column(name = "created_at", updatable = true, nullable = true)
052 private Date createdAt;
053
054 @ManyToOne(fetch = FetchType.LAZY)
055 @JoinColumn(name = "snapshot_id", updatable = true, nullable = true)
056 private Snapshot snapshot;
057
058 @Column(name = "resource_id", updatable = true, nullable = true)
059 private Integer resourceId;
060
061 @Column(name = "data", updatable = true, nullable = true, length = 4000)
062 private String data;
063
064 public Event() {
065 }
066
067 public Event(String name, String description, String category) {
068 this.name = name;
069 this.description = description;
070 this.category = category;
071 }
072
073 /**
074 * @deprecated in 2.5
075 */
076 @Deprecated
077 public Event(String name, String description, String category, Date date, Integer resourceId) {
078 this.name = name;
079 this.description = description;
080 this.category = category;
081 this.date = date;
082 this.resourceId = resourceId;
083 }
084
085 /**
086 * @deprecated in 2.5
087 */
088 @Deprecated
089 public Event(String name, String description, String category, Snapshot snapshot) {
090 this.name = name;
091 this.description = description;
092 this.category = category;
093 setSnapshot(snapshot);
094 }
095
096 public String getName() {
097 return name;
098 }
099
100 public void setName(String name) {
101 this.name = name;
102 }
103
104 public String getDescription() {
105 return description;
106 }
107
108 public void setDescription(String description) {
109 this.description = description;
110 }
111
112 public String getCategory() {
113 return category;
114 }
115
116 public void setCategory(String category) {
117 this.category = category;
118 }
119
120 public boolean isVersionCategory() {
121 return CATEGORY_VERSION.equalsIgnoreCase(category);
122 }
123
124 public Date getDate() {
125 return date;
126 }
127
128 public void setDate(Date date) {
129 this.date = date;
130 }
131
132 public Snapshot getSnapshot() {
133 return snapshot;
134 }
135
136 public Date getCreatedAt() {
137 return createdAt;
138 }
139
140 public void setCreatedAt(Date createdAt) {
141 this.createdAt = createdAt;
142 }
143
144 public final void setSnapshot(Snapshot snapshot) {
145 this.snapshot = snapshot;
146 if (snapshot != null) {
147 this.date = snapshot.getCreatedAt();
148 this.resourceId = snapshot.getResourceId();
149 }
150 }
151
152 public Integer getResourceId() {
153 return resourceId;
154 }
155
156 public Event setResourceId(Integer resourceId) {
157 this.resourceId = resourceId;
158 return this;
159 }
160
161 public String getData() {
162 return data;
163 }
164
165 public Event setData(String data) {
166 this.data = data;
167 return this;
168 }
169
170 @Override
171 public String toString() {
172 return new ToStringBuilder(this)
173 .append("name", name)
174 .append("categ", category)
175 .append("date", date)
176 .append("snapshot", snapshot)
177 .append("resource", resourceId)
178 .toString();
179 }
180
181 public boolean isLinkedToSnapshot() {
182 return snapshot != null;
183 }
184 }