Index: trunk/grails-app/services/com/lemans/ds/publicationcategory/PublicationCategoryAttributeService.groovy =================================================================== diff -u -r9919 -r9974 --- trunk/grails-app/services/com/lemans/ds/publicationcategory/PublicationCategoryAttributeService.groovy (.../PublicationCategoryAttributeService.groovy) (revision 9919) +++ trunk/grails-app/services/com/lemans/ds/publicationcategory/PublicationCategoryAttributeService.groovy (.../PublicationCategoryAttributeService.groovy) (revision 9974) @@ -11,8 +11,9 @@ * @param id (publicationCategoryId) * @return Map of publicationCategoryAttributes */ - Map findAllAttributes(Integer id) { - dqx([publicationCategoryId: id]).executeFrom('vwPublicationCategoryAttribute', ['publicationCategoryId = :publicationCategoryId']) + Map findAllAttributes(Map criteria) { + criteria.sorting = criteria.sorting ?: 'publicationCategoryId+ASC' + dqx(criteria).executeFrom('vwPublicationCategoryAttribute', ['publicationCategoryId = :publicationCategoryId']) } /** Index: trunk/grails-app/controllers/com/lemans/ds/fitment/PartFitmentController.groovy =================================================================== diff -u -r8683 -r9974 --- trunk/grails-app/controllers/com/lemans/ds/fitment/PartFitmentController.groovy (.../PartFitmentController.groovy) (revision 8683) +++ trunk/grails-app/controllers/com/lemans/ds/fitment/PartFitmentController.groovy (.../PartFitmentController.groovy) (revision 9974) @@ -51,6 +51,9 @@ if (data.errors) { renderErrors(data.errors) } else { List fitments = partFitmentService.findFitmentsByPartNumberAndModelYearIds(values.partNumber, values.modelYearIds) + if (values.positions && fitments) { + partFitmentManagerService.assignFitmentPositions(values.positions, fitments*.partFitmentId, auditUserName) + } values.modelYearId ? renderOne(fitments[0]) : renderList(fitments) } } Index: trunk/grails-app/services/com/lemans/ds/fitment/PartFitmentManagerService.groovy =================================================================== diff -u -r8723 -r9974 --- trunk/grails-app/services/com/lemans/ds/fitment/PartFitmentManagerService.groovy (.../PartFitmentManagerService.groovy) (revision 8723) +++ trunk/grails-app/services/com/lemans/ds/fitment/PartFitmentManagerService.groovy (.../PartFitmentManagerService.groovy) (revision 9974) @@ -77,10 +77,29 @@ deleteFitments(partFitment ?: [], username) } + /** + * Create Fitment position + * + * @param positions + * @param partFitmentIds + * @param username + */ + void assignFitmentPositions(List positions, List partFitmentIds, String username) { + Timestamp now = new Timestamp(new Date().time) + positions.each { Integer position -> + sql().withBatch(50, FITMENT_POSITION_INSERT_SQL) { stmt -> + partFitmentIds.each { Integer fitmentId -> + stmt.addBatch([partFitmentId: fitmentId, positionTypeId: position, now: now, username: username]) + } + } + } + } + private Map deleteFitments(List partFitments, String username) { List partFitmentIds = partFitments*.partFitmentId if (partFitments) { sql().executeUpdate(deleteFitmentsSql(partFitments.size()), [new Timestamp(new Date().time), username] + partFitmentIds) + sql().executeUpdate(deleteFitmentPositionSql(partFitments.size()), [new Timestamp(new Date().time), username] + partFitmentIds) } [errors: []] } @@ -95,4 +114,13 @@ INSERT INTO PartFitment (modelYearId, partNumber, note, dateCreated, createdBy, lastUpdated, lastUpdatedBy) VALUES (:modelYearId, :partNumber, :note, :now, :username, :now, :username) ''' + + private static final String FITMENT_POSITION_INSERT_SQL = ''' +INSERT INTO PartFitmentPosition (partFitmentId, positionTypeId, dateCreated, createdBy, lastUpdated, lastUpdatedBy) +values (:partFitmentId, :positionTypeId, :now, :username, :now, :username) +''' + + private String deleteFitmentPositionSql(Integer count) { + "UPDATE PartFitmentPosition SET dateDeleted = ?, deletedBy = ? WHERE partFitmentId IN (${questionMarks(count)})" + } } Index: trunk/src/integration-test/groovy/com/lemans/ds/fitment/PartFitmentFuncSpec.groovy =================================================================== diff -u -r9865 -r9974 --- trunk/src/integration-test/groovy/com/lemans/ds/fitment/PartFitmentFuncSpec.groovy (.../PartFitmentFuncSpec.groovy) (revision 9865) +++ trunk/src/integration-test/groovy/com/lemans/ds/fitment/PartFitmentFuncSpec.groovy (.../PartFitmentFuncSpec.groovy) (revision 9974) @@ -35,7 +35,7 @@ Integer mYId = 100 path([part: pNum]) ok() - Map json = [modelYearId: mYId] + Map json = [modelYearId: mYId, positions: [22001, 22002, 22003, 22004]] when: post(json) @@ -100,7 +100,8 @@ Integer mYId = 96990 path([part: pNum]) ok() - Map json = [modelYearIds: [mYId, 96991, 96992]] + Map json = [modelYearIds: [mYId, 96991, 96992], + positions: [22001, 22002]] when: post(json) Index: trunk/grails-app/controllers/com/lemans/ds/publicationcategory/PublicationCategoryAttributeController.groovy =================================================================== diff -u -r9916 -r9974 --- trunk/grails-app/controllers/com/lemans/ds/publicationcategory/PublicationCategoryAttributeController.groovy (.../PublicationCategoryAttributeController.groovy) (revision 9916) +++ trunk/grails-app/controllers/com/lemans/ds/publicationcategory/PublicationCategoryAttributeController.groovy (.../PublicationCategoryAttributeController.groovy) (revision 9974) @@ -10,7 +10,8 @@ def publicationCategoryAttributeManagerService def index(Integer categoryId) { - renderPaginated publicationCategoryAttributeService.findAllAttributes(categoryId) + Map criteria = common() + pagination() + [publicationCategoryId: categoryId] + renderPaginated publicationCategoryAttributeService.findAllAttributes(criteria) } def attributeOptions(Integer categoryId) {