
Untitled
By: a guest on
Mar 19th, 2012 | syntax:
Groovy | size: 1.47 KB | hits: 46 | expires: Never
package pl.grooper.offer
import pl.grooper.offer.images.OfferMiniature;
import pl.grooper.offer.images.OfferPicture;
import pl.grooper.security.User
import org.springframework.beans.factory.annotation.Value
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
class Offer implements Serializable{
/**
* name of this offer
*/
String name
/**
* when was this offer created in system
*/
Date dateCreated
/**
* when does this offer end
*/
Date dateExpired
Category category
String description
OfferMiniature miniature
List pictures
static hasMany = [
pictures: OfferPicture
]
static mapping = {
description type:'text'
pictures cascade: 'all-delete-orphan'
}
static constraints = {
name blank: false, maxSize: 50
description blank: false, maxSize: 50000
pictures nullable: true, maxSize: 3
miniature nullable: true
}
/**
* owner - user who created this offer
*/
static belongsTo = [
owner : User
]
/**
*
* @return description in a readable format
*/
def getDesc() {
def desc = "${name} ${description}"
(desc.size() > 50) ? desc.subSequence(0,50) : desc
}
String toString() {
return name
}
def cleanHtml() {
description = Jsoup.clean(description, Whitelist.basic())
}
def beforeInsert = {
cleanHtml()
}
def beforeUpdate() {
if (isDirty('description')) {
cleanHtml()
}
}
}