From 6ae4e515399f63e10f2f9f3f26375c27995c6611 Mon Sep 17 00:00:00 2001 From: Praveen Raju <80779423+praju-aot@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:28:50 -0400 Subject: [PATCH] fix: ORV2-2083 - Update Permit template names to generic ones. (#1258) Co-authored-by: John Fletcher --- .../versions/revert/v_24_ddl_revert.sql | 59 +++++++++++++++++ database/mssql/scripts/versions/v_24_ddl.sql | 63 +++++++++++++++++++ .../{v_22_test copy.sh => v_22_test.sh} | 0 database/mssql/test/versions/v_24_1_test.sql | 5 ++ database/mssql/test/versions/v_24_2_test.sql | 5 ++ database/mssql/test/versions/v_24_test.sh | 23 +++++++ dops/src/enum/template-name.enum.ts | 6 +- dops/src/helper/auth.helper.ts | 6 +- .../request/create-generated-document.dto.ts | 2 +- .../src/common/enum/template-name.enum.ts | 6 +- .../src/modules/permit/application.service.ts | 2 +- vehicles/src/modules/permit/permit.service.ts | 4 +- 12 files changed, 170 insertions(+), 11 deletions(-) create mode 100644 database/mssql/scripts/versions/revert/v_24_ddl_revert.sql create mode 100644 database/mssql/scripts/versions/v_24_ddl.sql rename database/mssql/test/versions/{v_22_test copy.sh => v_22_test.sh} (100%) create mode 100644 database/mssql/test/versions/v_24_1_test.sql create mode 100644 database/mssql/test/versions/v_24_2_test.sql create mode 100644 database/mssql/test/versions/v_24_test.sh diff --git a/database/mssql/scripts/versions/revert/v_24_ddl_revert.sql b/database/mssql/scripts/versions/revert/v_24_ddl_revert.sql new file mode 100644 index 000000000..9e4654ec2 --- /dev/null +++ b/database/mssql/scripts/versions/revert/v_24_ddl_revert.sql @@ -0,0 +1,59 @@ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +SET NOCOUNT ON +GO + +SET XACT_ABORT ON +GO +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE +GO +BEGIN TRANSACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +UPDATE [dops].[ORBC_DOCUMENT_TEMPLATE] SET TEMPLATE_NAME='PERMIT_TROS',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE TEMPLATE_NAME='PERMIT' + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT_TEMPLATE] SET TEMPLATE_NAME='PERMIT_TROS_VOID',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE TEMPLATE_NAME='PERMIT_VOID' + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT_TEMPLATE] SET TEMPLATE_NAME='PERMIT_TROS_REVOKED',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE TEMPLATE_NAME='PERMIT_REVOKED' + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT] SET FILE_NAME='tros-template-v1.docx',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE ID IN (SELECT DOCUMENT_ID FROM [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE TEMPLATE_NAME='PERMIT_TROS') + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT] SET FILE_NAME='tros-template-void-template-v1.docx',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE ID IN (SELECT DOCUMENT_ID FROM [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE TEMPLATE_NAME='PERMIT_TROS_VOID') + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT] SET FILE_NAME='tros-template-revoked-template-v1.docx',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE ID IN (SELECT DOCUMENT_ID FROM [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE TEMPLATE_NAME='PERMIT_TROS_REVOKED') + +DECLARE @VersionDescription VARCHAR(255) +SET @VersionDescription = 'Revert the name of permit template documents' + +INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (23, @VersionDescription, getutcdate()) +IF @@ERROR <> 0 SET NOEXEC ON +GO + +COMMIT TRANSACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO +DECLARE @Success AS BIT +SET @Success = 1 +SET NOEXEC OFF +IF (@Success = 1) PRINT 'The database update succeeded' +ELSE BEGIN + IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION + PRINT 'The database update failed' +END +GO + diff --git a/database/mssql/scripts/versions/v_24_ddl.sql b/database/mssql/scripts/versions/v_24_ddl.sql new file mode 100644 index 000000000..cf416ec1b --- /dev/null +++ b/database/mssql/scripts/versions/v_24_ddl.sql @@ -0,0 +1,63 @@ +SET ANSI_NULLS ON +GO +SET QUOTED_IDENTIFIER ON +GO +SET NOCOUNT ON +GO + +SET XACT_ABORT ON +GO +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE +GO +BEGIN TRANSACTION +GO + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT_TEMPLATE] SET TEMPLATE_NAME='PERMIT',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE TEMPLATE_NAME='PERMIT_TROS' + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT_TEMPLATE] SET TEMPLATE_NAME='PERMIT_VOID',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE TEMPLATE_NAME='PERMIT_TROS_VOID' + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT_TEMPLATE] SET TEMPLATE_NAME='PERMIT_REVOKED',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE TEMPLATE_NAME='PERMIT_TROS_REVOKED' + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT] SET FILE_NAME='permit-template-v1.docx',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE ID IN (SELECT DOCUMENT_ID FROM [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE TEMPLATE_NAME='PERMIT') + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT] SET FILE_NAME='permit-template-void-template-v1.docx',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE ID IN (SELECT DOCUMENT_ID FROM [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE TEMPLATE_NAME='PERMIT_VOID') + +IF @@ERROR <> 0 SET NOEXEC ON +GO +UPDATE [dops].[ORBC_DOCUMENT] SET FILE_NAME='permit-template-revoked-template-v1.docx',DB_LAST_UPDATE_TIMESTAMP=GETUTCDATE() WHERE ID IN (SELECT DOCUMENT_ID FROM [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE TEMPLATE_NAME='PERMIT_REVOKED') + + + +IF @@ERROR <> 0 SET NOEXEC ON +GO + +DECLARE @VersionDescription VARCHAR(255) +SET @VersionDescription = 'Update the name of permit template documents' + +INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (24, @VersionDescription, '$(UPDATE_SCRIPT)', '$(REVERT_SCRIPT)', getutcdate()) +IF @@ERROR <> 0 SET NOEXEC ON +GO + +COMMIT TRANSACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO +DECLARE @Success AS BIT +SET @Success = 1 +SET NOEXEC OFF +IF (@Success = 1) PRINT 'The database update succeeded' +ELSE BEGIN + IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION + PRINT 'The database update failed' +END +GO diff --git a/database/mssql/test/versions/v_22_test copy.sh b/database/mssql/test/versions/v_22_test.sh similarity index 100% rename from database/mssql/test/versions/v_22_test copy.sh rename to database/mssql/test/versions/v_22_test.sh diff --git a/database/mssql/test/versions/v_24_1_test.sql b/database/mssql/test/versions/v_24_1_test.sql new file mode 100644 index 000000000..b37e3933b --- /dev/null +++ b/database/mssql/test/versions/v_24_1_test.sql @@ -0,0 +1,5 @@ +-- Test that the permit template names have been updated correctly +SET NOCOUNT ON + +SELECT COUNT(*) FROM $(DB_NAME).[dops].[ORBC_DOCUMENT_TEMPLATE] +WHERE TEMPLATE_NAME IN ('PERMIT','PERMIT_VOID','PERMIT_REVOKED') \ No newline at end of file diff --git a/database/mssql/test/versions/v_24_2_test.sql b/database/mssql/test/versions/v_24_2_test.sql new file mode 100644 index 000000000..5c42d2f22 --- /dev/null +++ b/database/mssql/test/versions/v_24_2_test.sql @@ -0,0 +1,5 @@ +-- Test that the template file names have been updated correctly +SET NOCOUNT ON + +SELECT COUNT(*) FROM $(DB_NAME).[dops].[ORBC_DOCUMENT] +WHERE FILE_NAME IN ('permit-template-v1.docx','permit-template-void-template-v1.docx','permit-template-revoked-template-v1.docx') \ No newline at end of file diff --git a/database/mssql/test/versions/v_24_test.sh b/database/mssql/test/versions/v_24_test.sh new file mode 100644 index 000000000..03e0d89f1 --- /dev/null +++ b/database/mssql/test/versions/v_24_test.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Retrieve arguments +source ${SCRIPT_DIR}/utility/getopt.sh +USAGE="-u USER -p PASS -s SERVER -d DATABASE" +parse_options "${USAGE}" ${@} + +# All database tests for database version 24 are run from this shell script. +# TESTS_DIR variable set by the calling test-runner script. + +TEST_24_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_24_1_test.sql | xargs) +if [[ $TEST_24_1_RESULT -eq 3 ]]; then + echo "Test 24.1 passed: Template names updated correctly" +else + echo "******** Test 24.1 failed: Template names not updated correctly" +fi + +TEST_24_2_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_24_2_test.sql | xargs) +if [[ $TEST_24_2_RESULT -eq 3 ]]; then + echo "Test 24.2 passed: File names updated correctly" +else + echo "******** Test 24.2 failed: File names not updated correctly" +fi diff --git a/dops/src/enum/template-name.enum.ts b/dops/src/enum/template-name.enum.ts index 8c87ffbcd..dbab6861b 100644 --- a/dops/src/enum/template-name.enum.ts +++ b/dops/src/enum/template-name.enum.ts @@ -1,6 +1,6 @@ export enum TemplateName { - PERMIT_TROS = 'PERMIT_TROS', + PERMIT = 'PERMIT', PAYMENT_RECEIPT = 'PAYMENT_RECEIPT', - PERMIT_TROS_VOID = 'PERMIT_TROS_VOID', - PERMIT_TROS_REVOKED = 'PERMIT_TROS_REVOKED', + PERMIT_VOID = 'PERMIT_VOID', + PERMIT_REVOKED = 'PERMIT_REVOKED', } diff --git a/dops/src/helper/auth.helper.ts b/dops/src/helper/auth.helper.ts index a49ecc834..093e0e087 100644 --- a/dops/src/helper/auth.helper.ts +++ b/dops/src/helper/auth.helper.ts @@ -3,7 +3,11 @@ import { Directory } from '../enum/directory.enum'; import { IDP } from '../enum/idp.enum'; import { Role } from '../enum/roles.enum'; import { IUserJWT } from '../interface/user-jwt.interface'; -import { UserAuthGroup, ClientUserAuthGroup, IDIRUserAuthGroup } from '../enum/user-auth-group.enum'; +import { + UserAuthGroup, + ClientUserAuthGroup, + IDIRUserAuthGroup, +} from '../enum/user-auth-group.enum'; /** * Determines the directory type based on the identity provider of the user. diff --git a/dops/src/modules/dgen/dto/request/create-generated-document.dto.ts b/dops/src/modules/dgen/dto/request/create-generated-document.dto.ts index e7616a394..48a0ac665 100644 --- a/dops/src/modules/dgen/dto/request/create-generated-document.dto.ts +++ b/dops/src/modules/dgen/dto/request/create-generated-document.dto.ts @@ -8,7 +8,7 @@ export class CreateGeneratedDocumentDto { @AutoMap() @ApiProperty({ enum: TemplateName, - example: TemplateName.PERMIT_TROS, + example: TemplateName.PERMIT, description: 'The template that will be used to render the document.', }) @IsEnum(TemplateName) diff --git a/vehicles/src/common/enum/template-name.enum.ts b/vehicles/src/common/enum/template-name.enum.ts index 8c87ffbcd..dbab6861b 100644 --- a/vehicles/src/common/enum/template-name.enum.ts +++ b/vehicles/src/common/enum/template-name.enum.ts @@ -1,6 +1,6 @@ export enum TemplateName { - PERMIT_TROS = 'PERMIT_TROS', + PERMIT = 'PERMIT', PAYMENT_RECEIPT = 'PAYMENT_RECEIPT', - PERMIT_TROS_VOID = 'PERMIT_TROS_VOID', - PERMIT_TROS_REVOKED = 'PERMIT_TROS_REVOKED', + PERMIT_VOID = 'PERMIT_VOID', + PERMIT_REVOKED = 'PERMIT_REVOKED', } diff --git a/vehicles/src/modules/permit/application.service.ts b/vehicles/src/modules/permit/application.service.ts index 09ebd9b91..c9e07ad0c 100644 --- a/vehicles/src/modules/permit/application.service.ts +++ b/vehicles/src/modules/permit/application.service.ts @@ -508,7 +508,7 @@ export class ApplicationService { await queryRunner.startTransaction(); try { let dopsRequestData: DopsGeneratedDocument = { - templateName: TemplateName.PERMIT_TROS, + templateName: TemplateName.PERMIT, generatedDocumentFileName: permitDataForTemplate.permitNumber, templateData: permitDataForTemplate, documentsToMerge: permitDataForTemplate.permitData.commodities.map( diff --git a/vehicles/src/modules/permit/permit.service.ts b/vehicles/src/modules/permit/permit.service.ts index 80001d956..4025a5f41 100644 --- a/vehicles/src/modules/permit/permit.service.ts +++ b/vehicles/src/modules/permit/permit.service.ts @@ -660,8 +660,8 @@ export class PermitService { let dopsRequestData: DopsGeneratedDocument = { templateName: voidPermitDto.status == ApplicationStatus.VOIDED - ? TemplateName.PERMIT_TROS_VOID - : TemplateName.PERMIT_TROS_REVOKED, + ? TemplateName.PERMIT_VOID + : TemplateName.PERMIT_REVOKED, generatedDocumentFileName: permitDataForTemplate.permitNumber, templateData: permitDataForTemplate, documentsToMerge: permitDataForTemplate.permitData.commodities.map(