Index: grails-app/controllers/com/lemans/ds/catalog/CatalogProductController.groovy =================================================================== diff -u -radf4fbe3994e8e6a6496a9e8a85ef3fc61ba952b -r27aa741dd7c870bbe092155412de4e67ebf5c67e --- grails-app/controllers/com/lemans/ds/catalog/CatalogProductController.groovy (.../CatalogProductController.groovy) (revision adf4fbe3994e8e6a6496a9e8a85ef3fc61ba952b) +++ grails-app/controllers/com/lemans/ds/catalog/CatalogProductController.groovy (.../CatalogProductController.groovy) (revision 27aa741dd7c870bbe092155412de4e67ebf5c67e) @@ -28,15 +28,14 @@ if (errors) { renderErrors(errors) } else { - CatalogProduct catalogProduct = catalogProductManagerService.createCatalogProductAssociation(values, auditUserName) - if(catalogProduct.hasErrors()) { - errors.addAll(catalogProduct.errors.getAllErrors()*.defaultMessage?.flatten()) - renderErrors(errors) - } else { - renderObject catalogProduct + List catalogProducts = catalogProductManagerService.bulkCreateCatalogProductAssociation(catalogInstanceId, values.productIds, auditUserName) + def response = catalogProducts.collect { cp -> + cp.hasErrors() ? + [productId: cp.productId, catalogInstanceId: cp.catalogInstanceId, errors: cp.errors.getAllErrors()*.defaultMessage] + : cp } + renderMany(response) } - } def remove(Integer catalogInstanceId, Integer productId) { @@ -49,8 +48,8 @@ if (!values.catalogInstanceId) { errors << 'catalogInstanceId is required' } - if (!values.productId) { - errors << 'productId is required' + if (!values.productIds) { + errors << 'productIds are required' } errors } Index: grails-app/services/com/lemans/ds/catalog/CatalogProductManagerService.groovy =================================================================== diff -u -radf4fbe3994e8e6a6496a9e8a85ef3fc61ba952b -r27aa741dd7c870bbe092155412de4e67ebf5c67e --- grails-app/services/com/lemans/ds/catalog/CatalogProductManagerService.groovy (.../CatalogProductManagerService.groovy) (revision adf4fbe3994e8e6a6496a9e8a85ef3fc61ba952b) +++ grails-app/services/com/lemans/ds/catalog/CatalogProductManagerService.groovy (.../CatalogProductManagerService.groovy) (revision 27aa741dd7c870bbe092155412de4e67ebf5c67e) @@ -24,6 +24,10 @@ dqx(criteria).executeFrom('dbo.CatalogProduct', clauses(criteria)) } + List bulkCreateCatalogProductAssociation(Integer catalogInstanceId, List productIds, String username) { + productIds.collect {productId -> createCatalogProductAssociation([catalogInstanceId: catalogInstanceId, productId: productId], username)} + } + CatalogProduct createCatalogProductAssociation(Map values, String username) { CatalogProduct catalogProduct = new CatalogProduct() applyValuesToDomain(values, catalogProduct)