From 7c7496634515c63245f618749423b5ca78111c36 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Wed, 28 Aug 2024 17:28:59 +0100 Subject: [PATCH 1/3] Td-4584: Adding content to, or re-aranging content within, a referenced path does not update all references --- .../contentStructureState.ts | 1 + .../contentStructureState.ts | 11 ++++- .../Hierarchy/HierarchyEditMoveNode.sql | 42 ++++++++++++++++++- .../Hierarchy/HierarchyEditMoveResource.sql | 40 ++++++++++++++++++ .../Hierarchy/HierarchyEditPublish.sql | 19 ++------- 5 files changed, 94 insertions(+), 19 deletions(-) diff --git a/AdminUI/LearningHub.Nhs.AdminUI/Scripts/vuesrc/content-structure/contentStructureState.ts b/AdminUI/LearningHub.Nhs.AdminUI/Scripts/vuesrc/content-structure/contentStructureState.ts index df00e9665..2490eeacb 100644 --- a/AdminUI/LearningHub.Nhs.AdminUI/Scripts/vuesrc/content-structure/contentStructureState.ts +++ b/AdminUI/LearningHub.Nhs.AdminUI/Scripts/vuesrc/content-structure/contentStructureState.ts @@ -457,6 +457,7 @@ const actions = >{ await refreshNodeContents(payload.destinationNode, true).then(async x => { await refreshNodeContents(state.editingTreeNode.parent, true).then(y => { }); + refreshHierarchyEdit(state); state.rootNode.children.forEach(async (child) => { if (child.nodeId != null) { await refreshNodeContents(child, false); diff --git a/LearningHub.Nhs.WebUI/Scripts/vuesrc/content-structure-admin/contentStructureState.ts b/LearningHub.Nhs.WebUI/Scripts/vuesrc/content-structure-admin/contentStructureState.ts index 14ee33ef9..c67b26b5f 100644 --- a/LearningHub.Nhs.WebUI/Scripts/vuesrc/content-structure-admin/contentStructureState.ts +++ b/LearningHub.Nhs.WebUI/Scripts/vuesrc/content-structure-admin/contentStructureState.ts @@ -454,6 +454,12 @@ const actions = >{ await refreshNodeContents(payload.destinationNode, true).then(async x => { await refreshNodeContents(state.editingTreeNode.parent, true).then(y => { }); + refreshHierarchyEdit(state); + state.rootNode.children.forEach(async (child) => { + if (child.nodeId != null) { + await refreshNodeContents(child, false); + } + }); }); }).catch(e => { state.inError = true; @@ -492,8 +498,9 @@ const actions = >{ state.inError = false; contentStructureData.removeReferenceNode(payload.node.hierarchyEditDetailId).then(async response => { await refreshNodeContents(payload.node.parent, false); - await refreshNodeContents(payload.node.parent.parent, false); - await refreshNodeIfMatchingNodeId(payload.node.parent, state.editingTreeNode.nodeId, state.editingTreeNode.hierarchyEditDetailId); + if (payload.node.parent.parent != null) { + await refreshNodeContents(payload.node.parent.parent, false); + } }).catch(e => { state.inError = true; state.lastErrorMessage = "Error removing resource refrence."; diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveNode.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveNode.sql index c2f56c175..19361c38b 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveNode.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveNode.sql @@ -11,6 +11,7 @@ -- 20-05-2024 DB Added the creation of a new NodePath record for the moved node and update child nodes. -- 29-05-2024 DB Clear the NodePathId for moved nodes. NodePaths can not be updated incase susequent references are made to the original path. -- 07-08-2024 SA Remove all instance of the referenced path when moving a referenced folder +-- 23-08-2024 SA Moving a folder into a referenced folder should affect all instances of the referenced folder. ------------------------------------------------------------------------------- CREATE PROCEDURE [hierarchy].[HierarchyEditMoveNode] ( @@ -279,9 +280,48 @@ BEGIN AND rrdv.Deleted = 0 AND hed.Deleted = 0 - -- Remove all instance of the referenced path when moving a referenced folder + -- Remove all instance of the referenced path when moving a referenced folder EXEC hierarchy.HierarchyEditRemoveNodeReferencesOnMoveNode @HierarchyEditDetailId,@UserId,@UserTimezoneOffset + + -- Moving a folder into a referenced folder should affect all instances of the referenced folder. + + DECLARE @CurrentNodeId INT, + @ReferenceHierarchyEditDetailId INT + + SELECT @CurrentNodeId = hed.NodeId + FROM [hierarchy].[HierarchyEditDetail] hed + WHERE hed.Id = @MoveToHierarchyEditDetailId + + -- Declare the cursor + + DECLARE NodeCursor CURSOR FOR + SELECT Id AS ReferenceHierarchyEditDetailId + FROM hierarchy.HierarchyEditDetail + WHERE NodeId = @CurrentNodeId + AND Id != @MoveToHierarchyEditDetailId + -- Open the cursor + OPEN NodeCursor; + + -- Fetch the first row from the cursor + FETCH NEXT FROM NodeCursor + INTO @ReferenceHierarchyEditDetailId; + + -- Loop until no more rows are returned + WHILE @@FETCH_STATUS = 0 + BEGIN + -- Execute the script to add new folder references in all referenced instances + EXEC [hierarchy].[HierarchyEditReferenceNode] @HierarchyEditDetailId, @ReferenceHierarchyEditDetailId, @UserId,@UserTimezoneOffset + + -- Fetch the next row from the cursor + FETCH NEXT FROM NodeCursor + INTO @ReferenceHierarchyEditDetailId; + END + + -- Close and deallocate the cursor + CLOSE NodeCursor; + DEALLOCATE NodeCursor; + ------------------------------------------------------------ -- Refresh HierarchyEditNodeResourceLookup ------------------------------------------------------------ diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveResource.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveResource.sql index 33ac712fb..fcc90d16e 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveResource.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveResource.sql @@ -7,6 +7,7 @@ -- -- 11-01-2022 KD Initial Revision. -- 08-08-2024 SA Remove all instance of the referenced path when moving a referenced resource +-- 23-08-2024 SA Moving a resource into a referenced folder should affect all instances of the referenced folder ------------------------------------------------------------------------------- CREATE PROCEDURE [hierarchy].[HierarchyEditMoveResource] ( @@ -175,6 +176,45 @@ BEGIN -- Remove all instance of the referenced path when moving a referenced resource EXEC hierarchy.HierarchyEditRemoveResourceReferencesOnMoveResource @HierarchyEditDetailId,@ParentNodeId,@UserId,@UserTimezoneOffset + + -- Moving a resource into a referenced folder should affect all instances of the referenced folder + + DECLARE @CurrentNodeId INT, + @ReferenceHierarchyEditDetailId INT + + SELECT @CurrentNodeId = hed.NodeId + FROM [hierarchy].[HierarchyEditDetail] hed + WHERE hed.Id = @MoveToHierarchyEditDetailId + + -- Declare the cursor + + DECLARE NodeCursor CURSOR FOR + SELECT Id AS ReferenceHierarchyEditDetailId + FROM hierarchy.HierarchyEditDetail + WHERE NodeId = @CurrentNodeId + AND Id != @MoveToHierarchyEditDetailId + -- Open the cursor + OPEN NodeCursor; + + -- Fetch the first row from the cursor + FETCH NEXT FROM NodeCursor + INTO @ReferenceHierarchyEditDetailId; + + -- Loop until no more rows are returned + WHILE @@FETCH_STATUS = 0 + BEGIN + -- Execute the update statement for the current row + EXEC [hierarchy].[HierarchyEditReferenceResource] @HierarchyEditDetailId, @ReferenceHierarchyEditDetailId, @UserId,@UserTimezoneOffset + + -- Fetch the next row from the cursor + FETCH NEXT FROM NodeCursor + INTO @ReferenceHierarchyEditDetailId; + END + + -- Close and deallocate the cursor + CLOSE NodeCursor; + DEALLOCATE NodeCursor; + ------------------------------------------------------------ -- Refresh HierarchyEditNodeResourceLookup ------------------------------------------------------------ diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql index a30906480..01f3d20df 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql @@ -18,6 +18,8 @@ -- 03-06-2024 DB Publish NodePathDisplayVersion records. -- 13-06-2024 DB Publish ResourceReferenceDisplayVersion records. -- 26-07-2024 SA Remove references to be implemented +-- 27-08-2024 SA Moving a folder into a referenced folder should affect all instances of the referenced folder.[added + -- condition to avoid duplicate entries in to NodeLink table] ------------------------------------------------------------------------------- CREATE PROCEDURE [hierarchy].[HierarchyEditPublish] ( @@ -62,7 +64,7 @@ BEGIN ---------------------------------------------------------- -- Create new NodeLinks (arising from Create or Reference Node) INSERT INTO [hierarchy].[NodeLink] ([ParentNodeId],[ChildNodeId],[DisplayOrder],[Deleted],[CreateUserId],[CreateDate],[AmendUserId],[AmendDate]) - SELECT + SELECT DISTINCT ParentNodeId, NodeId AS ChildNodeId, DisplayOrder, @@ -284,21 +286,6 @@ BEGIN AND hed.Deleted = 0 AND nr.Deleted = 0 - -- Update NodeResource Deleted status , if the reference is removed. - UPDATE - nr - SET - Deleted = 1, - AmendUserId = @AmendUserId, - AmendDate = @AmendDate - FROM - hierarchy.HierarchyEditDetail hed - INNER JOIN - hierarchy.NodeResource nr ON hed.NodeResourceId = nr.Id - WHERE - HierarchyEditId = @HierarchyEditId - AND hed.Deleted =1 - ---------------------------------------------------------- -- NodeVersion ---------------------------------------------------------- From bd8ddec1db956f16e9d913b12c5a91d23ce7798c Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Mon, 2 Sep 2024 11:17:27 +0100 Subject: [PATCH 2/3] Operations are restricted to the current HierarchyEditId --- .../Hierarchy/HierarchyEditMoveNode.sql | 9 ++++++--- .../Hierarchy/HierarchyEditMoveResource.sql | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveNode.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveNode.sql index 19361c38b..526e04a30 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveNode.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveNode.sql @@ -291,7 +291,8 @@ BEGIN SELECT @CurrentNodeId = hed.NodeId FROM [hierarchy].[HierarchyEditDetail] hed - WHERE hed.Id = @MoveToHierarchyEditDetailId + WHERE hed.Id = @MoveToHierarchyEditDetailId + AND HierarchyEditId = @HierarchyEditId -- Declare the cursor @@ -299,7 +300,9 @@ BEGIN SELECT Id AS ReferenceHierarchyEditDetailId FROM hierarchy.HierarchyEditDetail WHERE NodeId = @CurrentNodeId - AND Id != @MoveToHierarchyEditDetailId + AND Id != @MoveToHierarchyEditDetailId + AND HierarchyEditId = @HierarchyEditId + AND deleted = 0 -- Open the cursor OPEN NodeCursor; @@ -310,7 +313,7 @@ BEGIN -- Loop until no more rows are returned WHILE @@FETCH_STATUS = 0 BEGIN - -- Execute the script to add new folder references in all referenced instances + -- Execute the script to add new folder references in all referenced instances EXEC [hierarchy].[HierarchyEditReferenceNode] @HierarchyEditDetailId, @ReferenceHierarchyEditDetailId, @UserId,@UserTimezoneOffset -- Fetch the next row from the cursor diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveResource.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveResource.sql index fcc90d16e..75d7b9603 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveResource.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveResource.sql @@ -184,7 +184,8 @@ BEGIN SELECT @CurrentNodeId = hed.NodeId FROM [hierarchy].[HierarchyEditDetail] hed - WHERE hed.Id = @MoveToHierarchyEditDetailId + WHERE hed.Id = @MoveToHierarchyEditDetailId + AND HierarchyEditId = @HierarchyEditId -- Declare the cursor @@ -192,7 +193,9 @@ BEGIN SELECT Id AS ReferenceHierarchyEditDetailId FROM hierarchy.HierarchyEditDetail WHERE NodeId = @CurrentNodeId - AND Id != @MoveToHierarchyEditDetailId + AND Id != @MoveToHierarchyEditDetailId + AND HierarchyEditId = @HierarchyEditId + AND deleted = 0 -- Open the cursor OPEN NodeCursor; From f47de2c28d68b1e1f02232e012ce9f4cd68d4414 Mon Sep 17 00:00:00 2001 From: Swapnamol Abraham Date: Mon, 2 Sep 2024 12:22:43 +0100 Subject: [PATCH 3/3] Added Distinct condition to avoid duplicate entries in to the [hierarchy].[NodeResource] table --- .../Stored Procedures/Hierarchy/HierarchyEditPublish.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql index 01f3d20df..8c8d27f37 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql @@ -232,7 +232,7 @@ BEGIN -- Create moved NodeResource/s in their new locations INSERT INTO [hierarchy].[NodeResource] ([NodeId],[ResourceId],[DisplayOrder],[VersionStatusId],[PublicationId],[Deleted],[CreateUserId],[CreateDate],[AmendUserId],[AmendDate]) - SELECT ParentNodeId, ResourceId, DisplayOrder, 2 /* Published */, @PublicationId, 0, CreateUserId, CreateDate, AmendUserId, AmendDate + SELECT DISTINCT ParentNodeId, ResourceId, DisplayOrder, 2 /* Published */, @PublicationId, 0, @AmendUserId, @AmendDate, @AmendUserId, @AmendDate FROM hierarchy.HierarchyEditDetail WHERE HierarchyEditId = @HierarchyEditId AND HierarchyEditDetailTypeId = 5 -- Node Resource