Last change
on this file since 613 was
182,
checked in by gav, 15 years ago
|
Add support for inventory item Pictures and Images.
Add new PersonService, refactor CreateDataService and TaskService to suite.
|
File size:
1.2 KB
|
Rev | Line | |
---|
[182] | 1 | class Image implements Comparable { |
---|
| 2 | |
---|
| 3 | Picture picture |
---|
| 4 | Integer size |
---|
| 5 | byte[] data |
---|
| 6 | String contentType |
---|
| 7 | Integer width |
---|
| 8 | Integer height |
---|
| 9 | Date dateCreated = new Date() |
---|
| 10 | Date lastUpdated = new Date() |
---|
| 11 | |
---|
| 12 | static belongsTo = [ Picture ] |
---|
| 13 | |
---|
| 14 | static mapping = { |
---|
| 15 | picture index: 'images_index', unique: true |
---|
| 16 | size index: 'images_index', unique: true |
---|
| 17 | data type: 'binary' |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | static constraints = { |
---|
| 21 | data(maxSize: MAX_SIZE) |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | static final Integer MAX_SIZE = 10 * 1024 * 1024 |
---|
| 25 | |
---|
| 26 | static final Integer Original = 1 |
---|
| 27 | static final Integer Large = 2 |
---|
| 28 | static final Integer Medium = 3 |
---|
| 29 | static final Integer Small = 4 |
---|
| 30 | |
---|
| 31 | static final Integer[] Widths = [ 0, 0, 500, 250, 100 ] |
---|
| 32 | static final Integer[] Heights = [ 0, 0, 500, 250, 100 ] |
---|
| 33 | |
---|
| 34 | static final String[] Names = [ '', 'Original', 'Large', 'Medium', 'Small' ] |
---|
| 35 | |
---|
| 36 | int compareTo(obj) { |
---|
| 37 | size.compareTo(obj.size) |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | String filename() { |
---|
| 41 | Image.filename(picture.id, size) |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | static String filename(long id, int size) { |
---|
| 45 | if (size == Original) { |
---|
| 46 | return "${id}-${Names[size]}.jpg" |
---|
| 47 | } |
---|
| 48 | else { |
---|
| 49 | return "${id}-${Names[size]}.png" |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.