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, Date date, Integer resourceId) {
067 this.name = name;
068 this.description = description;
069 this.category = category;
070 this.date = date;
071 this.resourceId = resourceId;
072 }
073
074 public Event(String name, String description, String category, Snapshot snapshot) {
075 this.name = name;
076 this.description = description;
077 this.category = category;
078 setSnapshot(snapshot);
079 }
080
081 public String getName() {
082 return name;
083 }
084
085 public void setName(String name) {
086 this.name = name;
087 }
088
089 public String getDescription() {
090 return description;
091 }
092
093 public void setDescription(String description) {
094 this.description = description;
095 }
096
097 public String getCategory() {
098 return category;
099 }
100
101 public void setCategory(String category) {
102 this.category = category;
103 }
104
105 public boolean isVersionCategory() {
106 return CATEGORY_VERSION.equalsIgnoreCase(category);
107 }
108
109 public Date getDate() {
110 return date;
111 }
112
113 public void setDate(Date date) {
114 this.date = date;
115 }
116
117 public Snapshot getSnapshot() {
118 return snapshot;
119 }
120
121 public Date getCreatedAt() {
122 return createdAt;
123 }
124
125 public void setCreatedAt(Date createdAt) {
126 this.createdAt = createdAt;
127 }
128
129 public final void setSnapshot(Snapshot snapshot) {
130 this.snapshot = snapshot;
131 if (snapshot != null) {
132 this.date = snapshot.getCreatedAt();
133 this.resourceId = snapshot.getResourceId();
134 }
135 }
136
137 public Integer getResourceId() {
138 return resourceId;
139 }
140
141 public Event setResourceId(Integer resourceId) {
142 this.resourceId = resourceId;
143 return this;
144 }
145
146 public String getData() {
147 return data;
148 }
149
150 public Event setData(String data) {
151 this.data = data;
152 return this;
153 }
154
155 @Override
156 public String toString() {
157 return new ToStringBuilder(this)
158 .append("name", name)
159 .append("categ", category)
160 .append("date", date)
161 .append("snapshot", snapshot)
162 .append("resource", resourceId)
163 .toString();
164 }
165
166 public boolean isLinkedToSnapshot() {
167 return snapshot != null;
168 }
169 }