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