package com.lemans.ds.media import com.lemans.services.Auditable import groovy.transform.ToString @ToString(includeNames = true) class Media extends Auditable { static final Integer DS_SOURCE = 0 static final String NOT_CLIENT_SETTABLE = 'not.clientSettable' Integer id Integer mediaTypeId Integer mimeTypeId Integer mediaClassificationId Integer source = DS_SOURCE String fileName = UUID.randomUUID() String mediaUrl String originalFileName String extension String title String description Date effectiveDate Integer languageId static constraints = { mimeTypeId nullable: true fileName nullable: true, maxSize: 250, validator: { value, Media media, errors -> if (media.originalFileName && !value) { rejectBlankField('fileName', errors) } } mediaUrl blank: false, maxSize: 255 originalFileName maxSize: 250, validator: { value, Media media, errors -> if (media.extension && !value) { rejectBlankField('originalFileName', errors) } } // NOTE: extension is effectively required for Media Files but not Links - i.e. it's needed for file location extension nullable: true, maxSize: 7 description nullable: true, maxSize: 100 title nullable: true, maxSize: 100 effectiveDate nullable: true mediaClassificationId nullable: true languageId nullable: true } static mapping = { table 'Media' id column: 'mediaId' mediaTypeId updateable: true mimeTypeId updateable: true source updateable: false mediaUrl updateable: true fileName updateable: true originalFileName updateable: true extension updateable: true title updateable: true } private static void rejectBlankField(String field, errors) { errors.rejectValue(field, 'blank', [field] as Object[], '{0} is required') } private static final Map IMMUTABLE_PROPERTIES = [ mediaUrl: 'Media Url', fileName: 'File Name', source: 'Source' ].asImmutable() @Override protected Map immutables() { Media.IMMUTABLE_PROPERTIES } }