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