1 package com.melloware.jukes.db.orm;
2
3 import java.io.File;
4 import java.util.Date;
5 import java.util.HashSet;
6 import java.util.Set;
7
8 import org.apache.commons.lang.StringUtils;
9 import org.apache.commons.lang.builder.CompareToBuilder;
10 import org.apache.commons.lang.builder.EqualsBuilder;
11 import org.apache.commons.lang.builder.HashCodeBuilder;
12 import org.apache.commons.lang.builder.ToStringBuilder;
13 import org.apache.commons.lang.builder.ToStringStyle;
14
15 import com.melloware.jukes.db.audit.Auditable;
16
17
18
19
20
21
22
23
24
25
26
27 public final class Disc
28 extends AbstractJukesObject
29 implements Auditable,
30 Comparable {
31
32 public static final String PROPERTYNAME_CREATED_DATE = "createdDate";
33 public static final String PROPERTYNAME_MODIFIED_DATE = "modifiedDate";
34 public static final String PROPERTYNAME_ID = "id";
35 public static final String PROPERTYNAME_LOCATION = "location";
36 public static final String PROPERTYNAME_BITRATE = "bitrate";
37 public static final String PROPERTYNAME_COVER_URL = "coverUrl";
38 public static final String PROPERTYNAME_COVER_SIZE = "coverSize";
39 public static final String PROPERTYNAME_CREATED_USER = "createdUser";
40 public static final String PROPERTYNAME_GENRE = "genre";
41 public static final String PROPERTYNAME_MODIFIED_USER = "modifiedUser";
42 public static final String PROPERTYNAME_NAME = "name";
43 public static final String PROPERTYNAME_YEAR = "year";
44 public static final String PROPERTYNAME_DURATION = "duration";
45 public static final String PROPERTYNAME_DURATION_TIME = "durationTime";
46 public static final String PROPERTYNAME_ARTIST = "artist";
47 public static final String PROPERTYNAME_NOTES = "notes";
48
49 private Artist artist;
50 private Date createdDate;
51 private Date modifiedDate;
52 private File file = null;
53 private Long bitrate;
54 private long coverSize;
55 private long duration;
56 private Long id;
57 private Set tracks;
58 private String coverUrl;
59 private String createdUser;
60 private String durationTime;
61 private String genre;
62 private String location;
63 private String modifiedUser;
64 private String name;
65 private String notes;
66 private String year;
67
68
69 public Disc() {
70 super();
71 }
72
73
74 public Disc(Long id) {
75 this.id = id;
76 }
77
78 public Artist getArtist() {
79 return this.artist;
80 }
81
82
83
84
85
86
87 public Date getAuditDate() {
88 return this.createdDate;
89 }
90
91
92
93
94 public Long getBitrate() {
95 return this.bitrate;
96 }
97
98
99
100
101
102
103 public int getChildCount() {
104 if (childCount == -1) {
105
106 childCount = 10;
107 }
108 return childCount;
109 }
110
111
112
113
114
115
116 public long getCoverSize() {
117 return this.coverSize;
118 }
119
120 public String getCoverUrl() {
121 return this.coverUrl;
122 }
123
124 public Date getCreatedDate() {
125 return this.createdDate;
126 }
127
128 public String getCreatedUser() {
129 return this.createdUser;
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143 public String getDisplayText(final String aFormat) {
144 String display = aFormat;
145 if (StringUtils.isBlank(display)) {
146 display = "%y %d";
147 }
148 String result = "";
149 display = StringUtils.replace(display, "%b", getBitrate().toString());
150 display = StringUtils.replace(display, "%y", getYear());
151 display = StringUtils.replace(display, "%r", getDurationTime());
152 display = StringUtils.replace(display, "%d", getName());
153 display = StringUtils.replace(display, "%D", getName().toUpperCase());
154 result = display;
155
156 return result;
157 }
158
159
160
161
162
163
164 public long getDuration() {
165 return this.duration;
166 }
167
168
169
170
171
172
173 public String getDurationTime() {
174 return this.durationTime;
175 }
176
177 public String getGenre() {
178 return this.genre;
179 }
180
181 public Long getId() {
182 return this.id;
183 }
184
185
186
187
188
189
190 public String getLocation() {
191 return this.location;
192 }
193
194 public Date getModifiedDate() {
195 return this.modifiedDate;
196 }
197
198 public String getModifiedUser() {
199 return this.modifiedUser;
200 }
201
202 public String getName() {
203 return this.name;
204 }
205
206
207
208
209
210
211 public String getNotes() {
212 return this.notes;
213 }
214
215 public Set getTracks() {
216 return this.tracks;
217 }
218
219
220
221
222
223
224 public String getYear() {
225 return this.year;
226 }
227
228 public void setArtist(final Artist artist) {
229 this.artist = artist;
230 }
231
232
233
234
235 public void setBitrate(final Long aBitrate) {
236 final Long old = getBitrate();
237 this.bitrate = aBitrate;
238 firePropertyChange(PROPERTYNAME_BITRATE, old, aBitrate);
239
240 }
241
242
243
244
245
246
247 public void setCoverSize(final long aCoverSize) {
248 final long old = getCoverSize();
249 this.coverSize = aCoverSize;
250 firePropertyChange(PROPERTYNAME_COVER_SIZE, old, aCoverSize);
251 }
252
253 public void setCoverUrl(final String coverUrl) {
254 final String old = getCoverUrl();
255 this.coverUrl = coverUrl;
256 firePropertyChange(PROPERTYNAME_COVER_URL, old, coverUrl);
257 }
258
259 public void setCreatedDate(final Date createdDate) {
260 final Date old = getCreatedDate();
261 this.createdDate = createdDate;
262 firePropertyChange(PROPERTYNAME_CREATED_DATE, old, createdDate);
263 }
264
265 public void setCreatedUser(final String createdUser) {
266 final String old = getCreatedUser();
267 this.createdUser = createdUser;
268 firePropertyChange(PROPERTYNAME_CREATED_USER, old, createdUser);
269 }
270
271
272
273
274
275
276 public void setDuration(final long aDuration) {
277 final long old = getDuration();
278 this.duration = aDuration;
279 firePropertyChange(PROPERTYNAME_DURATION, old, aDuration);
280 }
281
282
283
284
285
286
287 public void setDurationTime(final String aDurationTime) {
288 final String old = getDurationTime();
289 this.durationTime = aDurationTime;
290 firePropertyChange(PROPERTYNAME_DURATION_TIME, old, aDurationTime);
291 }
292
293 public void setGenre(final String genre) {
294 final String old = getGenre();
295 this.genre = genre;
296 firePropertyChange(PROPERTYNAME_GENRE, old, genre);
297 }
298
299 public void setId(final Long id) {
300 final Long old = getId();
301 this.id = id;
302 firePropertyChange(PROPERTYNAME_ID, old, id);
303 }
304
305
306
307
308
309
310 public void setLocation(final String aLocation) {
311 final String old = getLocation();
312 this.location = aLocation;
313 this.file = null;
314 firePropertyChange(PROPERTYNAME_LOCATION, old, aLocation);
315 }
316
317 public void setModifiedDate(final Date modifiedDate) {
318 final Date old = getModifiedDate();
319 this.modifiedDate = modifiedDate;
320 firePropertyChange(PROPERTYNAME_MODIFIED_DATE, old, modifiedDate);
321 }
322
323 public void setModifiedUser(final String modifiedUser) {
324 final String old = getModifiedUser();
325 this.modifiedUser = modifiedUser;
326 firePropertyChange(PROPERTYNAME_MODIFIED_USER, old, modifiedUser);
327 }
328
329 public void setName(final String name) {
330 final String old = getName();
331 this.name = name;
332 firePropertyChange(PROPERTYNAME_NAME, old, name);
333 }
334
335
336
337
338
339
340 public void setNotes(final String aNotes) {
341 final String old = getNotes();
342 this.notes = aNotes;
343 firePropertyChange(PROPERTYNAME_NOTES, old, aNotes);
344 }
345
346 public void setTracks(final Set tracks) {
347 this.tracks = tracks;
348 }
349
350
351
352
353
354
355 public void setYear(final String year) {
356 final String old = getYear();
357 this.year = year;
358 firePropertyChange(PROPERTYNAME_YEAR, old, year);
359 }
360
361
362
363
364 public boolean isValid() {
365 boolean result = false;
366 if (StringUtils.isNotBlank(getLocation())) {
367 if (this.file == null) {
368 this.file = new File(getLocation());
369 }
370 result = this.file.exists();
371 }
372 return result;
373 }
374
375 @SuppressWarnings("unchecked")
376 public void addTrack(final Track track) {
377 if (this.tracks == null) {
378 this.tracks = new HashSet();
379 }
380 this.tracks.add(track);
381 track.setDisc(this);
382 }
383
384
385
386
387 public int compareTo(Object object) {
388 final Disc disc = (Disc)object;
389 final CompareToBuilder builder = new CompareToBuilder();
390 builder.append(this.getName().toUpperCase(), disc.getName().toUpperCase());
391 return builder.toComparison();
392 }
393
394
395
396
397 public boolean equals(Object obj) {
398 if (!(obj instanceof Disc)) {
399 return false;
400 }
401 if (this == obj) {
402 return true;
403 }
404 final Disc rhs = (Disc)obj;
405 final EqualsBuilder builder = new EqualsBuilder();
406 builder.append(artist, rhs.artist);
407 builder.append(name, rhs.name);
408 return builder.isEquals();
409 }
410
411
412
413
414 public int hashCode() {
415 return new HashCodeBuilder(17, 37).append(artist).append(name).toHashCode();
416 }
417
418
419
420
421 public String toString() {
422 final ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);
423 builder.append("id", id);
424 builder.append("name", name);
425 builder.append("year", year);
426 builder.append("genre", genre);
427 builder.append("bitrate", bitrate);
428 builder.append("coverUrl", coverUrl);
429 builder.append("location", location);
430 return builder.toString();
431 }
432
433 }