Index: grails-app/controllers/com/lemans/ds/studioorder/StudioOrderPartController.groovy =================================================================== diff -u -r486da419c2d3173a16d116730e03f7adcb3ee9d4 -r8c08a8dcd612d496ee5cf723f48b385f0f157f42 --- grails-app/controllers/com/lemans/ds/studioorder/StudioOrderPartController.groovy (.../StudioOrderPartController.groovy) (revision 486da419c2d3173a16d116730e03f7adcb3ee9d4) +++ grails-app/controllers/com/lemans/ds/studioorder/StudioOrderPartController.groovy (.../StudioOrderPartController.groovy) (revision 8c08a8dcd612d496ee5cf723f48b385f0f157f42) @@ -18,8 +18,9 @@ } def performActions(Integer studioOrderId) { - Map data = studioOrderPartManagerService.performActions(request.JSON + [studioOrderId: studioOrderId], auditUserName) - if (data?.messages) { + Map values = request.JSON + Map data = studioOrderPartManagerService.performActions(values + [studioOrderId: studioOrderId], auditUserName) + if (data?.messages && values.action != 'create') { response.status = 400 render toJson(data) } else { Index: grails-app/services/com/lemans/ds/studioorder/StudioOrderPartManagerService.groovy =================================================================== diff -u -rfc8d9891ce2214ee2e25a1cb47dfe71c7276559f -r8c08a8dcd612d496ee5cf723f48b385f0f157f42 --- grails-app/services/com/lemans/ds/studioorder/StudioOrderPartManagerService.groovy (.../StudioOrderPartManagerService.groovy) (revision fc8d9891ce2214ee2e25a1cb47dfe71c7276559f) +++ grails-app/services/com/lemans/ds/studioorder/StudioOrderPartManagerService.groovy (.../StudioOrderPartManagerService.groovy) (revision 8c08a8dcd612d496ee5cf723f48b385f0f157f42) @@ -76,43 +76,42 @@ stmt.addBatch([studioOrderId: values.studioOrderId, partNumber: partNumber, now: now, username: username]) } } - Map result = [:] - List success = [] List failures = [] - 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) - } + 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 = [] + newPartNumbers.eachWithIndex{String partNumber, Integer index-> if(updateCounts[index] != 1) { - failures.push([ - partNumber: partNumber, - status: "failed", - message: "Error in inserting" - ]) - } else { - success.push([ - partNumber: partNumber, - status: "success" - ]) + dbErrors.add(partNumber) } } - result.failures = failures - result.success = success - [results: result] + 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] } Map updateParts(Map values, String username) {