Ignore:
Timestamp:
Jan 21, 2010, 11:25:46 AM (10 years ago)
Author:
gav
Message:

Move asset copy and create functions into AssetService.
Repair create links in AssetTreeTagLib.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/AssetService.groovy

    r278 r284  
    22
    33    boolean transactional = false
     4
     5    def create(params) {
     6        def result = [:]
     7        def fail = { Map m ->
     8            result.error = [ code: m.code, args: ["Asset", params.id] ]
     9            return result
     10        }
     11
     12        result.assetInstance = new Asset()
     13        result.assetInstance.properties = params
     14
     15        // success
     16        return result
     17    }
     18
     19    def copy(params) {
     20        def result = [:]
     21        def fail = { Map m ->
     22            result.error = [ code: m.code, args: ["Asset", params.id] ]
     23            return result
     24        }
     25
     26        result.assetToCopy = Asset.get(params.assetToCopy?.id)
     27
     28        if(!result.assetToCopy)
     29            return fail(code: "asset.copy.asset.required")
     30
     31        result.assetInstance = new Asset(name: result.assetToCopy.name,
     32                                                            description: result.assetToCopy.description,
     33                                                            section: result.assetToCopy.section)
     34
     35        result.assetInstance.properties = params
     36
     37        // success
     38        return result
     39    }
     40
     41    def save(params) {
     42        def result = [:]
     43        def fail = { Map m ->
     44            if(result.assetInstance && m.field)
     45                result.assetInstance.errors.rejectValue(m.field, m.code)
     46            result.error = [ code: m.code, args: ["Asset", params.id] ]
     47            return result
     48        }
     49
     50        result.assetInstance = new Asset(params)
     51
     52        if(result.assetInstance.hasErrors() || !result.assetInstance.save(flush: true))
     53            return fail(code:"default.create.failure")
     54
     55        // success
     56        return result
     57    }
    458
    559    def saveCopy(params) {
Note: See TracChangeset for help on using the changeset viewer.