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