001    /*
002     * SonarQube, open source software quality management tool.
003     * Copyright (C) 2008-2014 SonarSource
004     * mailto:contact AT sonarsource DOT com
005     *
006     * SonarQube 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     * SonarQube 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 License
017     * along with this program; if not, write to the Free Software Foundation,
018     * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019     */
020    package org.sonar.api.design;
021    
022    import org.apache.commons.lang.builder.EqualsBuilder;
023    import org.apache.commons.lang.builder.HashCodeBuilder;
024    import org.apache.commons.lang.builder.ReflectionToStringBuilder;
025    import org.apache.commons.lang.builder.ToStringStyle;
026    
027    import javax.persistence.*;
028    
029    @Entity
030    @Table(name = "dependencies")
031    public class DependencyDto {
032    
033      @Id
034      @Column(name = "id")
035      @GeneratedValue
036      private Long id;
037    
038      @Column(name = "from_snapshot_id", updatable = true, nullable = false)
039      private Integer fromSnapshotId;
040    
041      @Column(name = "from_resource_id", updatable = true, nullable = false)
042      private Integer fromResourceId;
043    
044      @Column(name = "from_scope", updatable = true, nullable = true)
045      private String fromScope;
046    
047      @Column(name = "to_snapshot_id", updatable = true, nullable = false)
048      private Integer toSnapshotId;
049    
050      @Column(name = "to_resource_id", updatable = true, nullable = false)
051      private Integer toResourceId;
052    
053      @Column(name = "to_scope", updatable = true, nullable = true)
054      private String toScope;
055    
056      @Column(name = "dep_weight", updatable = true, nullable = true)
057      private Integer weight;
058    
059      @Column(name = "dep_usage", updatable = true, nullable = true, length = 30)
060      private String usage;
061    
062      @Column(name = "project_snapshot_id", updatable = true, nullable = false)
063      private Integer projectSnapshotId;
064    
065      @Column(name = "parent_dependency_id", updatable = true, nullable = true)
066      private Long parentDependencyId;
067    
068      public Long getId() {
069        return id;
070      }
071    
072      public void setId(Long id) {
073        this.id = id;
074      }
075    
076      public Integer getFromSnapshotId() {
077        return fromSnapshotId;
078      }
079    
080      public DependencyDto setFromSnapshotId(Integer fromSnapshotId) {
081        this.fromSnapshotId = fromSnapshotId;
082        return this;
083      }
084    
085      public Integer getFromResourceId() {
086        return fromResourceId;
087      }
088    
089      public DependencyDto setFromResourceId(Integer fromResourceId) {
090        this.fromResourceId = fromResourceId;
091        return this;
092      }
093    
094      public Integer getToSnapshotId() {
095        return toSnapshotId;
096      }
097    
098      public DependencyDto setToSnapshotId(Integer toSnapshotId) {
099        this.toSnapshotId = toSnapshotId;
100        return this;
101      }
102    
103      public Integer getToResourceId() {
104        return toResourceId;
105      }
106    
107      public DependencyDto setToResourceId(Integer toResourceId) {
108        this.toResourceId = toResourceId;
109        return this;
110      }
111    
112      public Integer getWeight() {
113        return weight;
114      }
115    
116      public DependencyDto setWeight(Integer weight) {
117        if (weight < 0) {
118          throw new IllegalArgumentException("Dependency weight can not be negative");
119        }
120        this.weight = weight;
121        return this;
122      }
123    
124      public String getFromScope() {
125        return fromScope;
126      }
127    
128      public DependencyDto setFromScope(String fromScope) {
129        this.fromScope = fromScope;
130        return this;
131      }
132    
133      public String getToScope() {
134        return toScope;
135      }
136    
137      public DependencyDto setToScope(String toScope) {
138        this.toScope = toScope;
139        return this;
140      }
141    
142      public String getUsage() {
143        return usage;
144      }
145    
146      public DependencyDto setUsage(String usage) {
147        this.usage = usage;
148        return this;
149      }
150    
151      public Integer getProjectSnapshotId() {
152        return projectSnapshotId;
153      }
154    
155      public DependencyDto setProjectSnapshotId(Integer projectSnapshotId) {
156        this.projectSnapshotId = projectSnapshotId;
157        return this;
158      }
159    
160      public Long getParentDependencyId() {
161        return parentDependencyId;
162      }
163    
164      public DependencyDto setParentDependencyId(Long parentDependencyId) {
165        this.parentDependencyId = parentDependencyId;
166        return this;
167      }
168    
169      @Override
170      public boolean equals(Object obj) {
171        if (!(obj instanceof DependencyDto)) {
172          return false;
173        }
174        if (this == obj) {
175          return true;
176        }
177        DependencyDto other = (DependencyDto) obj;
178        return new EqualsBuilder()
179            .append(fromSnapshotId, other.fromSnapshotId)
180            .append(toSnapshotId, other.toSnapshotId)
181            .isEquals();
182      }
183    
184      @Override
185      public int hashCode() {
186        return new HashCodeBuilder(17, 37)
187            .append(fromSnapshotId)
188            .append(toSnapshotId)
189            .toHashCode();
190      }
191    
192      @Override
193      public String toString() {
194        return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
195      }
196    }