Changeset 405 for trunk/grails-app/services
- Timestamp:
- Feb 23, 2010, 10:14:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/InventoryItemService.groovy
r226 r405 11 11 * @param params The incoming params as normally passed to the show view 12 12 * primarily including the id of the inventoryItem. 13 * @returns A map containing result.error=true (if any error) and result.inventoryItemInstance (if available) 14 * and 13 * @returns A map containing result.error, if any error, otherwise result.inventoryItemInstance. 15 14 */ 16 def prepareShowData(params) {15 def show(params) { 17 16 def result = [:] 18 19 def fail = { Object[] args -> 20 if(args.size() == 2) result.errors = [args[0], args[1]] 21 result.error = true 17 def fail = { Map m -> 18 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 22 19 return result 23 20 } 21 22 result.inventoryItemInstance = InventoryItem.get( params.id ) 23 24 if(!result.inventoryItemInstance) 25 return fail(code:"default.not.found") 24 26 25 27 result.showTab = [:] … … 35 37 } 36 38 37 result.inventoryItemInstance = InventoryItem.get( params.id )38 39 if(!result.inventoryItemInstance)40 return fail("inventoryItem", "inventoryItem.notFound")41 42 39 def p = [:] 43 40 p.max = result.inventoryMovementListMax = 10 … … 47 44 result.inventoryMovementListTotal = InventoryMovement.countByInventoryItem(result.inventoryItemInstance) 48 45 49 // Success 46 // Success. 50 47 return result 51 48 52 } // end prepareShowData() 49 } // end show() 50 51 def delete(params) { 52 def result = [:] 53 def fail = { Map m -> 54 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 55 return result 56 } 57 58 result.inventoryItemInstance = InventoryItem.get(params.id) 59 60 if(!result.inventoryItemInstance) 61 return fail(code:"default.not.found") 62 63 try { 64 result.inventoryItemInstance.delete(flush:true) 65 return result //Success. 66 } 67 catch(org.springframework.dao.DataIntegrityViolationException e) { 68 return fail(code:"default.delete.failure") 69 } 70 71 } 72 73 def edit(params) { 74 def result = [:] 75 def fail = { Map m -> 76 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 77 return result 78 } 79 80 result.inventoryItemInstance = InventoryItem.get(params.id) 81 82 if(!result.inventoryItemInstance) 83 return fail(code:"default.not.found") 84 85 // Success. 86 return result 87 } 88 89 def update(params) { 90 InventoryItem.withTransaction { status -> 91 def result = [:] 92 93 def fail = { Map m -> 94 status.setRollbackOnly() 95 if(result.inventoryItemInstance && m.field) 96 result.inventoryItemInstance.errors.rejectValue(m.field, m.code) 97 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 98 return result 99 } 100 101 result.inventoryItemInstance = InventoryItem.get(params.id) 102 103 if(!result.inventoryItemInstance) 104 return fail(code:"default.not.found") 105 106 // Optimistic locking check. 107 if(params.version) { 108 if(result.inventoryItemInstance.version > params.version.toLong()) 109 return fail(field:"version", code:"default.optimistic.locking.failure") 110 } 111 112 result.inventoryItemInstance.properties = params 113 114 if(result.inventoryItemInstance.hasErrors() || !result.inventoryItemInstance.save()) 115 return fail(code:"default.update.failure") 116 117 // Success. 118 return result 119 120 } //end withTransaction 121 } // end update() 122 123 def create(params) { 124 def result = [:] 125 def fail = { Map m -> 126 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 127 return result 128 } 129 130 result.inventoryItemInstance = new InventoryItem() 131 result.inventoryItemInstance.properties = params 132 133 // success 134 return result 135 } 136 137 def save(params) { 138 InventoryItem.withTransaction { status -> 139 def result = [:] 140 141 def fail = { Map m -> 142 status.setRollbackOnly() 143 if(result.inventoryItemInstance && m.field) 144 result.inventoryItemInstance.errors.rejectValue(m.field, m.code) 145 result.error = [ code: m.code, args: ["InventoryItem", params.id] ] 146 return result 147 } 148 149 result.inventoryItemInstance = new InventoryItem(params) 150 151 if(result.inventoryItemInstance.hasErrors() || !result.inventoryItemInstance.save()) 152 return fail(code:"default.create.failure") 153 154 // success 155 return result 156 157 } //end withTransaction 158 } 159 53 160 54 161 } // end class
Note: See TracChangeset
for help on using the changeset viewer.