BrightSide Workbench Full Report + Source Code
DossierVersion.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.dossier.entity;
19 
20 import java.util.Date;
21 import java.util.List;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.ManyToOne;
28 import javax.persistence.Temporal;
29 import javax.persistence.TemporalType;
30 import org.turro.string.Strings;
31 import org.turro.dossier.db.DossierPU;
32 import org.turro.elephant.util.DateFormats;
33 import org.turro.jpa.entity.IDaoEntity;
34 import org.turro.util.Chars;
35 import org.turro.version.Version;
36 
41 @Entity
42 public class DossierVersion implements java.io.Serializable, IDaoEntity, Comparable<DossierVersion> {
43 
44  @Id
45  @GeneratedValue(strategy= GenerationType.IDENTITY)
46  @Column(name="IDENTIFIER")
47  private Long id;
48 
49  private String versionId;
50 
51  @ManyToOne
52  private Dossier dossier;
53 
54  @Temporal(TemporalType.DATE)
55  private Date releaseDate;
56 
57  private boolean active;
58 
59  public boolean isActive() {
60  return active;
61  }
62 
63  public void setActive(boolean active) {
64  this.active = active;
65  }
66 
67  public Dossier getDossier() {
68  return dossier;
69  }
70 
71  public void setDossier(Dossier dossier) {
72  this.dossier = dossier;
73  }
74 
75  public Long getId() {
76  return id;
77  }
78 
79  public void setId(Long id) {
80  this.id = id;
81  }
82 
83  public Date getReleaseDate() {
84  return releaseDate;
85  }
86 
87  public void setReleaseDate(Date releaseDate) {
88  this.releaseDate = releaseDate;
89  }
90 
91  public String getVersionId() {
92  return versionId;
93  }
94 
95  public void setVersionId(String versionId) {
96  this.versionId = versionId;
97  }
98 
99  /* IDaoEntity */
100 
101  @Override
102  public Object entityId() {
103  return id;
104  }
105 
106  @Override
107  public boolean isEmpty() {
108  return Strings.isBlank(versionId) ||
109  releaseDate == null;
110  }
111 
112  /* Helpers */
113 
114  public String getVersionString() {
115  return "[" + versionId + Chars.forward().spaced().toString() + DateFormats.format(releaseDate, true) + "]";
116  }
117 
118  private transient Long issueCount;
119  private transient DossierVersionStatus currentStatus;
120 
121  public long getIssues() {
122  if(issueCount == null) {
123  issueCount = (Long) new DossierPU().getSingleResult(
124  "select count(issue) from Issue issue " +
125  "where issue.version = ?",
126  new Object[] { this }
127  );
128  }
129  return issueCount;
130  }
131 
133  if(currentStatus == null) {
134  long stoppers = (Long) new DossierPU().getSingleResult(
135  "select count(issue) from Issue issue " +
136  "where issue.version = ? " +
137  "and issue.status <> ? " +
138  "and issue.priority = ?",
140  );
141  if(stoppers > 0) {
142  currentStatus = DossierVersionStatus.VERSION_STOPPED;
143  } else {
144  long problematic = (Long) new DossierPU().getSingleResult(
145  "select count(issue) from Issue issue " +
146  "where issue.version = ? " +
147  "and issue.status <> ? " +
148  "and issue.priority = ?",
150  );
151  if(problematic > 0) {
153  } else {
154  long onWork = (Long) new DossierPU().getSingleResult(
155  "select count(issue) from Issue issue " +
156  "where issue.version = ? " +
157  "and issue.status <> ?",
158  new Object[] { this, IssueStatus.STATUS_CLOSED }
159  );
160  if(onWork > 0) {
161  currentStatus = DossierVersionStatus.VERSION_ONWORK;
162  } else {
163  currentStatus = DossierVersionStatus.VERSION_READY;
164  }
165  }
166  }
167  }
168  return currentStatus;
169  }
170 
171  public List<String> getByStatus(DossierVersionStatus status) {
172  if(DossierVersionStatus.VERSION_STOPPED.equals(status)) {
173  return new DossierPU().getResultList(
174  "select concat('/issue/', id) from Issue issue " +
175  "where issue.version = ? " +
176  "and issue.status <> ? " +
177  "and issue.priority = ?",
179  );
180  } else if(DossierVersionStatus.VERSION_NOTRECOMMENDED.equals(status)) {
181  return new DossierPU().getResultList(
182  "select concat('/issue/', id) from Issue issue " +
183  "where issue.version = ? " +
184  "and issue.status <> ? " +
185  "and issue.priority = ?",
187  );
188  }
189  return null;
190  }
191 
192  @Override
193  public int compareTo(DossierVersion o) {
194  return new Version(versionId).compareTo(new Version(o != null ? o.versionId : null));
195  }
196 
197 }
List< String > getByStatus(DossierVersionStatus status)
static final String format(Date d, boolean dateOnly)
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380