Index: grails-app/controllers/com/lemans/ds/studioorder/StudioOrderPartController.groovy =================================================================== diff -u -r14b18d52e3a36938dbab85edd7f01c1fe3f29a26 -r5e4675576d308ef361b7db42ec0df5d4ac5d64fa --- grails-app/controllers/com/lemans/ds/studioorder/StudioOrderPartController.groovy (.../StudioOrderPartController.groovy) (revision 14b18d52e3a36938dbab85edd7f01c1fe3f29a26) +++ grails-app/controllers/com/lemans/ds/studioorder/StudioOrderPartController.groovy (.../StudioOrderPartController.groovy) (revision 5e4675576d308ef361b7db42ec0df5d4ac5d64fa) @@ -18,9 +18,8 @@ } def performActions(Integer studioOrderId) { - Map values = request.JSON - Map data = studioOrderPartManagerService.performActions(values + [studioOrderId: studioOrderId], auditUserName) - if (data?.messages && values.action != 'create') { + Map data = studioOrderPartManagerService.performActions(request.JSON + [studioOrderId: studioOrderId], auditUserName) + if (data?.messages) { response.status = 400 render toJson(data) } else { Index: grails-app/services/com/lemans/ds/studioorder/StudioOrderPartManagerService.groovy =================================================================== diff -u -r14b18d52e3a36938dbab85edd7f01c1fe3f29a26 -r5e4675576d308ef361b7db42ec0df5d4ac5d64fa --- grails-app/services/com/lemans/ds/studioorder/StudioOrderPartManagerService.groovy (.../StudioOrderPartManagerService.groovy) (revision 14b18d52e3a36938dbab85edd7f01c1fe3f29a26) +++ grails-app/services/com/lemans/ds/studioorder/StudioOrderPartManagerService.groovy (.../StudioOrderPartManagerService.groovy) (revision 5e4675576d308ef361b7db42ec0df5d4ac5d64fa) @@ -76,42 +76,43 @@ stmt.addBatch([studioOrderId: values.studioOrderId, partNumber: partNumber, now: now, username: username]) } } + Map result = [:] + List success = [] List failures = [] - Set existingCurrentOrder = existingStudioOrderParts.findAll{it.studioOrderId == values.studioOrderId}*.partNumber - Set existingOpenOrder = existingStudioOrderParts.findAll{it.statusId == 14200}*.partNumber - Set existingSubmittedOrder = existingStudioOrderParts.findAll{it.statusId == 14201}*.partNumber - Set dbErrors = [] - + existingStudioOrderParts.each {studioOrderPart-> + if(failures.find{it.partNumber == studioOrderPart.partNumber}) { + return; + } + Map error = [ + partNumber: studioOrderPart.partNumber, + status: "failed" + ] + if(studioOrderPart.studioOrderId == values.studioOrderId) { + error.message = "Part is already in the current order" + } else if(studioOrderPart.statusId == 14200) { + error.message = "Part is in existing open orders" + } else if(studioOrderPart.statusId == 14201) { + error.message = "Part is in existing submitted orders" + } + failures.push(error) + } newPartNumbers.eachWithIndex{String partNumber, Integer index-> if(updateCounts[index] != 1) { - dbErrors.add(partNumber) + failures.push([ + partNumber: partNumber, + status: "failed", + message: "Error in inserting" + ]) + } else { + success.push([ + partNumber: partNumber, + status: "success" + ]) } } - if(existingCurrentOrder) { - failures.push([ - type: "error", - text: "The following Part(s) failed as they are in already in current order: ${existingCurrentOrder.join(",")}" - ]) - } - if(existingOpenOrder) { - failures.push([ - type: "error", - text: "The following Part(s) failed as they are in existing open orders: ${existingOpenOrder.join(",")}" - ]) - } - if(existingSubmittedOrder) { - failures.push([ - type: "error", - text: "The following Part(s) failed as they are in existing submitted orders: ${existingSubmittedOrder.join(",")}" - ]) - } - if(dbErrors) { - failures.push([ - type: "error", - text: "The following Part(s) failed while saving: ${dbErrors.join(",")}" - ]) - } - [messages: failures] + result.failures = failures + result.success = success + [results: result] } Map updateParts(Map values, String username) {