Skip to content

Commit 3dc33bb

Browse files
TD-4394: Publishing catalogues needs to update referencing catalogues
1 parent 0908c4f commit 3dc33bb

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@
543543
<Build Include="Stored Procedures\Resources\GetScormContentServerDetailsForLHExternalReference.sql" />
544544
<None Include="Scripts\Post-Deploy\Scripts\Content_Referencing_DataSetup.sql" />
545545
<None Include="Scripts\Pre-Deploy\Scripts\Content Referencing Initialise.sql" />
546+
<Build Include="Stored Procedures\Hierarchy\HierarchyNewNodePathForReferedCatalogue.sql" />
546547
</ItemGroup>
547548
<ItemGroup>
548549
<None Include="Scripts\Pre-Deploy\Scripts\Card5766_AuthorTableChanges.PreDeployment.sql" />

WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
-- 03-06-2024 DB Publish NodePathDisplayVersion records.
1919
-- 13-06-2024 DB Publish ResourceReferenceDisplayVersion records.
2020
-- 26-07-2024 SA Remove references to be implemented
21+
-- 21-08-2024 SS Publishing catalogues needs to update referencing catalogues
2122
-------------------------------------------------------------------------------
2223
CREATE PROCEDURE [hierarchy].[HierarchyEditPublish]
2324
(
@@ -572,7 +573,11 @@ BEGIN
572573
AND np.CatalogueNodeId != np.NodeId
573574
AND hed.NodeId IS NULL
574575

576+
----------------------------------------------------------
577+
-- NodePath: generate new NodePath/s for refered Catalogues
578+
----------------------------------------------------------
575579

580+
EXEC [hierarchy].[HierarchyNewNodePathForReferedCatalogue] @HierarchyEditId,@AmendUserId,@AmendDate
576581
----------------------------------------------------------
577582
-- NodePathNode
578583
----------------------------------------------------------
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
-------------------------------------------------------------------------------
2+
-- Author Sarathlal
3+
-- Created 21-08-2024
4+
-- Purpose Publishing catalogues needs to update referencing catalogues
5+
--
6+
-- Modification History
7+
-- 21-08-2024 SS Initial version
8+
-------------------------------------------------------------------------------
9+
CREATE PROCEDURE [hierarchy].[HierarchyNewNodePathForReferedCatalogue]
10+
(
11+
@HierarchyEditId INT,
12+
@AmendUserId INT,
13+
@AmendDate datetimeoffset(7)
14+
)
15+
16+
AS
17+
18+
BEGIN
19+
BEGIN TRY
20+
21+
BEGIN TRAN
22+
DECLARE @NodePathId int
23+
DECLARE @PrimaryCatalogueNodeId int
24+
DECLARE @NodeId int
25+
DECLARE @ParentNodeId int
26+
DECLARE @NewNodePath as NVARCHAR(256)
27+
DECLARE @DisplayOrder int
28+
DECLARE @NewNodePathCursor as CURSOR
29+
SET @NewNodePathCursor = CURSOR FORWARD_ONLY FOR
30+
SELECT
31+
PrimaryCatalogueNodeId,
32+
ParentNodeId,
33+
NodeId,
34+
hed.NewNodePath,
35+
DisplayOrder,
36+
NodePathId
37+
FROM
38+
hierarchy.HierarchyEditDetail hed
39+
WHERE
40+
HierarchyEditId = @HierarchyEditId
41+
AND
42+
(
43+
HierarchyEditDetailTypeId = 4 -- Node Link
44+
OR
45+
HierarchyEditDetailTypeId = 3 -- Folder Node
46+
)
47+
AND (
48+
HierarchyEditDetailOperationId = 1 -- Add
49+
OR
50+
HierarchyEditDetailOperationId = 2 -- Edit
51+
)
52+
AND NodeLinkId IS NULL
53+
AND [Deleted] = 0
54+
OPEN @NewNodePathCursor;
55+
FETCH NEXT FROM @NewNodePathCursor INTO @PrimaryCatalogueNodeId,@ParentNodeId,@NodeId,@NewNodePath,@DisplayOrder,@NodePathId;
56+
WHILE @@FETCH_STATUS = 0
57+
BEGIN
58+
IF NOT EXISTS (SELECT 1 FROM hierarchy.NodePath WHERE NodeId=@NodeId AND NodePath=NodePath+'\'+CAST(@NodeId AS VARCHAR(100)))
59+
BEGIN
60+
INSERT INTO hierarchy.NodePath (NodeId, NodePath, CatalogueNodeId, IsActive, Deleted, CreateUserId, CreateDate, AmendUserId, AmendDate)
61+
SELECT @NodeId,NP.NodePath+'\'+CAST(@NodeId AS VARCHAR(100)),NP.CatalogueNodeId,1,0,@AmendUserId,@AmendDate,@AmendUserId,@AmendDate FROM
62+
hub.[fn_Split](@NewNodePath, '\') nodeInPath
63+
INNER JOIN hierarchy.NodePath NP ON NP.NodeId=nodeInPath.value AND CatalogueNodeId!=@PrimaryCatalogueNodeId
64+
WHERE nodeInPath.value=@ParentNodeId
65+
66+
END
67+
68+
69+
FETCH NEXT FROM @NewNodePathCursor INTO @PrimaryCatalogueNodeId,@ParentNodeId,@NodeId,@NewNodePath,@DisplayOrder,@NodePathId;
70+
71+
END
72+
73+
CLOSE @NewNodePathCursor;
74+
DEALLOCATE @NewNodePathCursor;
75+
COMMIT
76+
77+
END TRY
78+
BEGIN CATCH
79+
DECLARE @ErrorMessage NVARCHAR(4000);
80+
DECLARE @ErrorSeverity INT;
81+
DECLARE @ErrorState INT;
82+
83+
SELECT
84+
@ErrorMessage = ERROR_MESSAGE(),
85+
@ErrorSeverity = ERROR_SEVERITY(),
86+
@ErrorState = ERROR_STATE();
87+
88+
IF @@TRANCOUNT > 0
89+
ROLLBACK TRAN;
90+
91+
RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState);
92+
93+
END CATCH
94+
END
95+
GO

0 commit comments

Comments
 (0)