generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ORV2-2693 Add STOS permit templates to OnRouteBC (#1612)
- Loading branch information
Showing
10 changed files
with
197 additions
and
16 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
database/mssql/scripts/versions/revert/v_43_ddl_revert.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
SET ANSI_NULLS ON | ||
GO | ||
SET QUOTED_IDENTIFIER ON | ||
GO | ||
SET NOCOUNT ON | ||
GO | ||
|
||
SET XACT_ABORT ON | ||
|
||
BEGIN TRY | ||
BEGIN TRANSACTION | ||
|
||
DELETE [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE DOCUMENT_ID IN (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-template-v1.docx') | ||
DELETE [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE DOCUMENT_ID IN (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-void-template-v1.docx') | ||
DELETE [dops].[ORBC_DOCUMENT_TEMPLATE] WHERE DOCUMENT_ID IN (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-revoked-template-v1.docx') | ||
DELETE [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-template-v1.docx' | ||
DELETE [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-void-template-v1.docx' | ||
DELETE [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-revoked-template-v1.docx' | ||
COMMIT | ||
END TRY | ||
|
||
BEGIN CATCH | ||
IF @@TRANCOUNT > 0 | ||
ROLLBACK; | ||
THROW | ||
END CATCH | ||
|
||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = 'Revert STOS templates' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [RELEASE_DATE]) VALUES (42, @VersionDescription, getutcdate()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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 | ||
INSERT [dops].[ORBC_DOCUMENT] ( [S3_OBJECT_ID], [S3_VERSION_ID], [S3_LOCATION], [OBJECT_MIME_TYPE], [FILE_NAME], [DMS_VERSION_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'273C4D93-544E-471B-ACB6-D79E51BE78DA', NULL, N'https://moti-int.objectstore.gov.bc.ca/tran_api_orbc_docs_dev/tran_api_orbc_docs_dev%40moti-int.objectstore.gov.bc.ca/273c4d93-544e-471b-acb6-d79e51be78da', N'application/vnd.openxmlformats-officedocument.wordprocessingml.document',N'stos-template-v1.docx',1, 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE()) | ||
|
||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
INSERT [dops].[ORBC_DOCUMENT] ( [S3_OBJECT_ID], [S3_VERSION_ID], [S3_LOCATION], [OBJECT_MIME_TYPE], [FILE_NAME], [DMS_VERSION_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'E28B476E-361E-45A8-A9A5-384C7F4CB8D8', NULL, N'https://moti-int.objectstore.gov.bc.ca/tran_api_orbc_docs_dev/tran_api_orbc_docs_dev%40moti-int.objectstore.gov.bc.ca/e28b476e-361e-45a8-a9a5-384c7f4cb8d8', N'application/vnd.openxmlformats-officedocument.wordprocessingml.document',N'stos-void-template-v1.docx',1, 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE()) | ||
|
||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
INSERT [dops].[ORBC_DOCUMENT] ( [S3_OBJECT_ID], [S3_VERSION_ID], [S3_LOCATION], [OBJECT_MIME_TYPE], [FILE_NAME], [DMS_VERSION_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'F5BAD4DC-A1AE-4ABF-98DC-17874871F882', NULL, N'https://moti-int.objectstore.gov.bc.ca/tran_api_orbc_docs_dev/tran_api_orbc_docs_dev%40moti-int.objectstore.gov.bc.ca/f5bad4dc-a1ae-4abf-98dc-17874871f882', N'application/vnd.openxmlformats-officedocument.wordprocessingml.document',N'stos-revoked-template-v1.docx',1, 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE()) | ||
|
||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
INSERT [dops].[ORBC_DOCUMENT_TEMPLATE] ( [TEMPLATE_NAME], [TEMPLATE_VERSION], [DOCUMENT_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'PERMIT_STOS', 1, (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-template-v1.docx'), 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE()) | ||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
INSERT [dops].[ORBC_DOCUMENT_TEMPLATE] ( [TEMPLATE_NAME], [TEMPLATE_VERSION], [DOCUMENT_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'PERMIT_STOS_VOID', 1, (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-void-template-v1.docx'), 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE()) | ||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
INSERT [dops].[ORBC_DOCUMENT_TEMPLATE] ( [TEMPLATE_NAME], [TEMPLATE_VERSION], [DOCUMENT_ID], [CONCURRENCY_CONTROL_NUMBER], [DB_CREATE_USERID], [DB_CREATE_TIMESTAMP], [DB_LAST_UPDATE_USERID], [DB_LAST_UPDATE_TIMESTAMP]) VALUES ( N'PERMIT_STOS_REVOKED', 1, (SELECT ID FROM [dops].[ORBC_DOCUMENT] WHERE FILE_NAME='stos-revoked-template-v1.docx'), 1, N'dops', GETUTCDATE(), N'dops', GETUTCDATE()) | ||
|
||
IF @@ERROR <> 0 SET NOEXEC ON | ||
GO | ||
|
||
DECLARE @VersionDescription VARCHAR(255) | ||
SET @VersionDescription = 'STOS permit templates.' | ||
|
||
INSERT [dbo].[ORBC_SYS_VERSION] ([VERSION_ID], [DESCRIPTION], [UPDATE_SCRIPT], [REVERT_SCRIPT], [RELEASE_DATE]) VALUES (43, @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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- Test that the permit template have been configured correctly | ||
SET NOCOUNT ON | ||
|
||
SELECT COUNT(*) FROM $(DB_NAME).[dops].[ORBC_DOCUMENT_TEMPLATE] | ||
WHERE TEMPLATE_NAME IN ('PERMIT','PERMIT_STOS_VOID','PERMIT_STOS_REVOKED') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
-- Test that the permit template have been configured correctly | ||
SET NOCOUNT ON | ||
|
||
SELECT COUNT(*) FROM $(DB_NAME).[dops].[ORBC_DOCUMENT] | ||
WHERE ID IN (SELECT DOCUMENT_ID FROM $(DB_NAME).[dops].[ORBC_DOCUMENT_TEMPLATE] | ||
WHERE TEMPLATE_NAME IN ('PERMIT','PERMIT_STOS_VOID','PERMIT_STOS_REVOKED')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/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 43 are run from this shell script. | ||
# TESTS_DIR variable set by the calling test-runner script. | ||
|
||
TEST_43_1_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_43_1_test.sql | xargs) | ||
if [[ $TEST_43_1_RESULT -eq 3 ]]; then | ||
echo "Test 43.1 passed: STOS templates setup successfully in ORBC_DOCUMENT_TEMPLATE" | ||
else | ||
echo "******** Test 43.1 failed: Failed to setup STOS permit templates" | ||
fi | ||
|
||
|
||
TEST_43_2_RESULT=$(/opt/mssql-tools/bin/sqlcmd -U ${USER} -P "${PASS}" -S ${SERVER} -v DB_NAME=${DATABASE} -h -1 -i ${TESTS_DIR}/v_43_2_test.sql | xargs) | ||
if [[ $TEST_43_2_RESULT -eq 3 ]]; then | ||
echo "Test 43.2 passed: STOS templates setup successfully in ORBC_DOCUMENT" | ||
else | ||
echo "******** Test 43.2 failed: Failed to setup STOS permit templates" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,18 @@ | ||
import { ApplicationStatus } from './application-status.enum'; | ||
import { PermitType } from './permit-type.enum'; | ||
|
||
export enum TemplateName { | ||
PERMIT = 'PERMIT', | ||
PAYMENT_RECEIPT = 'PAYMENT_RECEIPT', | ||
PERMIT_VOID = 'PERMIT_VOID', | ||
PERMIT_REVOKED = 'PERMIT_REVOKED', | ||
PERMIT_STOS = 'PERMIT_STOS', | ||
PERMIT_STOS_VOID = 'PERMIT_STOS_VOID', | ||
PERMIT_STOS_REVOKED = 'PERMIT_STOS_REVOKED', | ||
} | ||
|
||
export type PermitTemplateMapping = { | ||
[K in ApplicationStatus]?: { | ||
[T in PermitType | 'default']?: TemplateName; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { InternalServerErrorException } from '@nestjs/common'; | ||
import { ApplicationStatus } from '../enum/application-status.enum'; | ||
import { PermitType } from '../enum/permit-type.enum'; | ||
import { | ||
PermitTemplateMapping, | ||
TemplateName, | ||
} from '../enum/template-name.enum'; | ||
|
||
/** | ||
* Returns the appropriate template name based on the provided application status and permit type. | ||
* Throws an error if the combination of status and type does not yield a valid template. | ||
* | ||
* @param {ApplicationStatus} status - The status of the application for which the template is required. | ||
* @param {PermitType} type - The type of permit for which the template is required. | ||
* @returns {TemplateName} - The template name corresponding to the status and type provided. | ||
* @throws {InternalServerErrorException} - If no valid template is found for the given status. | ||
*/ | ||
export const getPermitTemplateName = ( | ||
status: ApplicationStatus, | ||
type: PermitType, | ||
): TemplateName => { | ||
const templateMapping: PermitTemplateMapping = { | ||
[ApplicationStatus.ISSUED]: { | ||
[PermitType.SINGLE_TRIP_OVERSIZE]: TemplateName.PERMIT_STOS, | ||
default: TemplateName.PERMIT, | ||
}, | ||
[ApplicationStatus.VOIDED]: { | ||
[PermitType.SINGLE_TRIP_OVERSIZE]: TemplateName.PERMIT_STOS_VOID, | ||
default: TemplateName.PERMIT_VOID, | ||
}, | ||
[ApplicationStatus.REVOKED]: { | ||
[PermitType.SINGLE_TRIP_OVERSIZE]: TemplateName.PERMIT_STOS_REVOKED, | ||
default: TemplateName.PERMIT_REVOKED, | ||
}, | ||
}; | ||
|
||
const template = | ||
templateMapping[status]?.[type] || templateMapping[status]?.default; | ||
if (!template) { | ||
throw new InternalServerErrorException( | ||
'Invalid status for document generation', | ||
); | ||
} | ||
return template; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters