001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2009 SonarSource SA
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 javax.persistence.*;
027 import java.util.Date;
028
029 /**
030 * @since 1.10
031 */
032 @Entity
033 @Table(name = "events")
034 public class Event extends BaseIdentifiable {
035 public static final String CATEGORY_VERSION = "Version";
036 public static final String CATEGORY_ALERT = "Alert";
037
038 @Column(name = "name", updatable = true, nullable = true, length = 50)
039 private String name;
040
041 @Column(name = "description", updatable = true, nullable = true, length = 3072)
042 private String description;
043
044 @Column(name = "category", updatable = true, nullable = true, length = 50)
045 private String category;
046
047 @Column(name = "event_date", updatable = true, nullable = false)
048 private Date date;
049
050 @Column(name = "created_at", updatable = true, nullable = true)
051 private Date createdAt;
052
053 @ManyToOne(fetch = FetchType.LAZY)
054 @JoinColumn(name = "snapshot_id", updatable = true, nullable = true)
055 private Snapshot snapshot;
056
057 @Column(name = "resource_id", updatable = true, nullable = true)
058 private Integer resourceId;
059
060 @Column(name = "data", updatable = true, nullable = true, length = 4000)
061 private String data;
062
063 public Event() {
064 }
065
066 public Event(String name, String description, String category) {
067 this.name = name;
068 this.description = description;
069 this.category = category;
070 }
071
072 @Deprecated
073 public Event(String name, String description, String category, Date date, Integer resourceId) {
074 this.name = name;
075 this.description = description;
076 this.category = category;
077 this.date = date;
078 this.resourceId = resourceId;
079 }
080
081 @Deprecated
082 public Event(String name, String description, String category, Snapshot snapshot) {
083 this.name = name;
084 this.description = description;
085 this.category = category;
086 setSnapshot(snapshot);
087 }
088
089 public String getName() {
090 return name;
091 }
092
093 public void setName(String name) {
094 this.name = name;
095 }
096
097 public String getDescription() {
098 return description;
099 }
100
101 public void setDescription(String description) {
102 this.description = description;
103 }
104
105 public String getCategory() {
106 return category;
107 }
108
109 public void setCategory(String category) {
110 this.category = category;
111 }
112
113 public boolean isVersionCategory() {
114 return CATEGORY_VERSION.equalsIgnoreCase(category);
115 }
116
117 public Date getDate() {
118 return date;
119 }
120
121 public void setDate(Date date) {
122 this.date = date;
123 }
124
125 public Snapshot getSnapshot() {
126 return snapshot;
127 }
128
129 public Date getCreatedAt() {
130 return createdAt;
131 }
132
133 public void setCreatedAt(Date createdAt) {
134 this.createdAt = createdAt;
135 }
136
137 public final void setSnapshot(Snapshot snapshot) {
138 this.snapshot = snapshot;
139 if (snapshot != null) {
140 this.date = snapshot.getCreatedAt();
141 this.resourceId = snapshot.getResourceId();
142 }
143 }
144
145 public Integer getResourceId() {
146 return resourceId;
147 }
148
149 public Event setResourceId(Integer resourceId) {
150 this.resourceId = resourceId;
151 return this;
152 }
153
154 public String getData() {
155 return data;
156 }
157
158 public Event setData(String data) {
159 this.data = data;
160 return this;
161 }
162
163 @Override
164 public String toString() {
165 return new ToStringBuilder(this)
166 .append("name", name)
167 .append("categ", category)
168 .append("date", date)
169 .append("snapshot", snapshot)
170 .append("resource", resourceId)
171 .toString();
172 }
173
174 public boolean isLinkedToSnapshot() {
175 return snapshot != null;
176 }
177 }