From 9525243e8b9cc9b8b244756f8d94c530f80997c6 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Mon, 3 Jun 2024 15:16:28 +0100 Subject: [PATCH 1/6] Fix for video and video files with a case and assessment resource question block --- .../Controllers/Api/ContributeController.cs | 20 +++++----- .../ResourceService.cs | 40 +++++++++++++------ 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 825914c97..b62608374 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -832,13 +832,13 @@ private Dictionary CheckQuestionBlock(BlockCollectionViewModel mode if (questionBlock.MediaBlock.Video != null) { - if (questionBlock.MediaBlock.Video.VideoFile != null) + if (questionBlock.MediaBlock.Video.File != null) { - if (questionBlock.MediaBlock.Video.File != null) - { - filePath.Add(questionBlock.MediaBlock.Video.File.FileId, questionBlock.MediaBlock.Video.File.FilePath); - } + filePath.Add(questionBlock.MediaBlock.Video.File.FileId, questionBlock.MediaBlock.Video.File.FilePath); + } + if (questionBlock.MediaBlock.Video.VideoFile != null) + { if (questionBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) { filePath.Add(questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FileId, questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); @@ -882,13 +882,13 @@ private Dictionary CheckQuestionBlock(BlockCollectionViewModel mode if (feedbackBlock.MediaBlock.Video != null) { - if (feedbackBlock.MediaBlock.Video.VideoFile != null) + if (feedbackBlock.MediaBlock.Video.File != null) { - if (feedbackBlock.MediaBlock.Video.File != null) - { - filePath.Add(feedbackBlock.MediaBlock.Video.File.FileId, feedbackBlock.MediaBlock.Video.File.FilePath); - } + filePath.Add(feedbackBlock.MediaBlock.Video.File.FileId, feedbackBlock.MediaBlock.Video.File.FilePath); + } + if (feedbackBlock.MediaBlock.Video.VideoFile != null) + { if (feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) { filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FileId, feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); diff --git a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs index f6b8958e5..d85056f70 100644 --- a/WebAPI/LearningHub.Nhs.Services/ResourceService.cs +++ b/WebAPI/LearningHub.Nhs.Services/ResourceService.cs @@ -1347,12 +1347,16 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b rvs = rvs.Where(x => x.Id != resourceVersionId && x.PublicationId > 0).OrderByDescending(x => x.PublicationId).ToList(); var rv = rvs.FirstOrDefault(); var currentAssessmentVersion = await this.GetAssessmentViewModel(rv.Id); + List deletableFiles = null; if (assessmentDetails is { EndGuidance: { } } && assessmentDetails.EndGuidance.Blocks != null) { var endGuidanceFiles = this.CheckBlockFile(assessmentDetails.EndGuidance, currentAssessmentVersion.EndGuidance); if (endGuidanceFiles.Any()) { - retVal.AddRange(endGuidanceFiles); + deletableFiles = await this.GetResourceBlockCollectionsFilePathAsync(rv.Id, ResourceTypeEnum.Assessment); + retVal.AddRange(from entry in endGuidanceFiles + where deletableFiles.Contains(entry) + select entry); } } @@ -1361,7 +1365,10 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b var assessmentContentFiles = this.CheckBlockFile(assessmentDetails.AssessmentContent, currentAssessmentVersion.AssessmentContent); if (assessmentContentFiles.Any()) { - retVal.AddRange(assessmentContentFiles); + deletableFiles ??= await this.GetResourceBlockCollectionsFilePathAsync(rv.Id, ResourceTypeEnum.Assessment); + retVal.AddRange(from entry in assessmentContentFiles + where deletableFiles.Contains(entry) + select entry); } } } @@ -1382,7 +1389,14 @@ public async Task> GetObsoleteResourceFile(int resourceVersionId, b if (rv != null) { var currentCaseVersion = await this.GetCaseDetailsByIdAsync(rv.Id); - caseFiles = this.CheckBlockFile(caseDetails.BlockCollection, currentCaseVersion.BlockCollection); + var nonpublishedFiles = this.CheckBlockFile(caseDetails.BlockCollection, currentCaseVersion.BlockCollection); + if (nonpublishedFiles.Any()) + { + var deletableCaseFiles = await this.GetResourceBlockCollectionsFilePathAsync(rv.Id, ResourceTypeEnum.Case); + caseFiles.AddRange(from entry in nonpublishedFiles + where deletableCaseFiles.Contains(entry) + select entry); + } } } @@ -5092,13 +5106,13 @@ private Dictionary CheckQuestionBlock(BlockCollectionViewModel mode if (questionBlock.MediaBlock.Video != null) { - if (questionBlock.MediaBlock.Video.VideoFile != null) + if (questionBlock.MediaBlock.Video.File != null) { - if (questionBlock.MediaBlock.Video.File != null) - { - filePath.Add(questionBlock.MediaBlock.Video.File.FileId, questionBlock.MediaBlock.Video.File.FilePath); - } + filePath.Add(questionBlock.MediaBlock.Video.File.FileId, questionBlock.MediaBlock.Video.File.FilePath); + } + if (questionBlock.MediaBlock.Video.VideoFile != null) + { if (questionBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) { filePath.Add(questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FileId, questionBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); @@ -5142,13 +5156,13 @@ private Dictionary CheckQuestionBlock(BlockCollectionViewModel mode if (feedbackBlock.MediaBlock.Video != null) { - if (feedbackBlock.MediaBlock.Video.VideoFile != null) + if (feedbackBlock.MediaBlock.Video.File != null) { - if (feedbackBlock.MediaBlock.Video.File != null) - { - filePath.Add(feedbackBlock.MediaBlock.Video.File.FileId, feedbackBlock.MediaBlock.Video.File.FilePath); - } + filePath.Add(feedbackBlock.MediaBlock.Video.File.FileId, feedbackBlock.MediaBlock.Video.File.FilePath); + } + if (feedbackBlock.MediaBlock.Video.VideoFile != null) + { if (feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile != null) { filePath.Add(feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FileId, feedbackBlock.MediaBlock.Video.VideoFile.TranscriptFile.File.FilePath); From d94919c0f96a1fd64313753f67191cfddf8c8b1b Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Mon, 3 Jun 2024 15:47:47 +0100 Subject: [PATCH 2/6] catch any error while processing resource files --- .../Controllers/Api/ContributeController.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index b62608374..3b0b81c02 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -349,10 +349,17 @@ public async Task PublishResourceVersionAsync([FromBody] PublishVi { if (associatedResource.ResourceTypeEnum != ResourceTypeEnum.Scorm && associatedResource.ResourceTypeEnum != ResourceTypeEnum.Html) { - var obsoleteFiles = await this.resourceService.GetObsoleteResourceFile(publishViewModel.ResourceVersionId); - if (obsoleteFiles != null && obsoleteFiles.Any()) + try { - await this.fileService.PurgeResourceFile(null, obsoleteFiles); + var obsoleteFiles = await this.resourceService.GetObsoleteResourceFile(publishViewModel.ResourceVersionId); + if (obsoleteFiles != null && obsoleteFiles.Any()) + { + await this.fileService.PurgeResourceFile(null, obsoleteFiles); + } + } + catch (Exception ex) + { + this.Logger.LogInformation($"Error occurred while checking for obsolete files {ex.Message}, UserId: {this.CurrentUserId}."); } } } @@ -789,6 +796,7 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec } catch (Exception ex) { + this.Logger.LogInformation($"Error occurred while checking blockCollection files {ex.Message}, UserId: {this.CurrentUserId}."); } } From a08cf416dd38f49ac25deeb743159a50a63c27db Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Mon, 3 Jun 2024 15:59:22 +0100 Subject: [PATCH 3/6] changed endpoint used in getting resourcet ype resource publish --- .../Controllers/Api/ContributeController.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 3b0b81c02..706efacbb 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -343,24 +343,17 @@ public ActionResult GetSettings() [Route("PublishResourceVersion")] public async Task PublishResourceVersionAsync([FromBody] PublishViewModel publishViewModel) { - var associatedResource = await this.resourceService.GetResourceVersionExtendedAsync(publishViewModel.ResourceVersionId); + var associatedResource = await this.resourceService.GetResourceVersionAsync(publishViewModel.ResourceVersionId); var validationResult = await this.contributeService.SubmitResourceVersionForPublishAsync(publishViewModel); if (validationResult.IsValid) { - if (associatedResource.ResourceTypeEnum != ResourceTypeEnum.Scorm && associatedResource.ResourceTypeEnum != ResourceTypeEnum.Html) + if (associatedResource.ResourceType != ResourceTypeEnum.Scorm && associatedResource.ResourceType != ResourceTypeEnum.Html) { - try - { var obsoleteFiles = await this.resourceService.GetObsoleteResourceFile(publishViewModel.ResourceVersionId); if (obsoleteFiles != null && obsoleteFiles.Any()) { await this.fileService.PurgeResourceFile(null, obsoleteFiles); } - } - catch (Exception ex) - { - this.Logger.LogInformation($"Error occurred while checking for obsolete files {ex.Message}, UserId: {this.CurrentUserId}."); - } } } @@ -794,9 +787,8 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec _ = Task.Run(async () => { await this.fileService.PurgeResourceFile(null, deleteList); }); } } - catch (Exception ex) + catch { - this.Logger.LogInformation($"Error occurred while checking blockCollection files {ex.Message}, UserId: {this.CurrentUserId}."); } } From c45879840e5b9b0bdb477f142d001adae15747c5 Mon Sep 17 00:00:00 2001 From: Oluwatobi Awe Date: Tue, 4 Jun 2024 14:53:57 +0100 Subject: [PATCH 4/6] TD-3023 update for answers and wsi blocks --- .../Controllers/Api/ContributeController.cs | 11 +-- .../Resources/BlockCollectionFileSearch.sql | 38 ++++++++++- .../Resources/BlockCollectionRepository.cs | 68 ------------------- .../ResourceService.cs | 11 +-- 4 files changed, 51 insertions(+), 77 deletions(-) diff --git a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs index 706efacbb..f4068d040 100644 --- a/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs +++ b/LearningHub.Nhs.WebUI/Controllers/Api/ContributeController.cs @@ -738,10 +738,13 @@ private async Task RemoveBlockCollectionFiles(int resourceVersionId, BlockCollec { foreach (var oldblock in wsi?.WholeSlideImageBlock?.WholeSlideImageBlockItems) { - var entry = newBlocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId || x.WholeSlideImage?.File?.FilePath == oldblock.WholeSlideImage?.File?.FilePath).Any()); - if (entry == null) + if (oldblock != null && (oldblock.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingComplete || oldblock.WholeSlideImage.File.WholeSlideImageFile.Status == WholeSlideImageFileStatus.ProcessingFailed)) { - filePaths.Add(oldblock.WholeSlideImage?.File?.FilePath); + var entry = newBlocks.FirstOrDefault(x => x.WholeSlideImageBlock != null && x.WholeSlideImageBlock.WholeSlideImageBlockItems.Where(x => x.WholeSlideImage?.File?.FileId == oldblock.WholeSlideImage?.File?.FileId || x.WholeSlideImage?.File?.FilePath == oldblock.WholeSlideImage?.File?.FilePath).Any()); + if (entry == null) + { + filePaths.Add(oldblock.WholeSlideImage?.File?.FilePath); + } } } } @@ -809,7 +812,7 @@ private Dictionary CheckQuestionBlock(BlockCollectionViewModel mode { foreach (var imageBlock in answerBlock.BlockCollection.Blocks) { - if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null) + if (imageBlock.BlockType == BlockType.Media && imageBlock.MediaBlock != null && imageBlock.MediaBlock.Image.File != null) { filePath.Add(imageBlock.MediaBlock.Image.File.FileId, imageBlock.MediaBlock.Image.File.FilePath); } diff --git a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql index 00b4aa351..fcf2e5a4a 100644 --- a/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql +++ b/WebAPI/LearningHub.Nhs.Database/Stored Procedures/Resources/BlockCollectionFileSearch.sql @@ -7,6 +7,7 @@ -- Modification History -- -- 31-05-2024 TD-3023 Initial Revision +-- 04-06-2024 TD-3023 Included answer blocks to the search ------------------------------------------------------------------------------- @@ -93,6 +94,14 @@ END BlockCollectionId INT ); + DECLARE @QABlock TABLE ( + Id INT, + [Order] INT, + Title NVARCHAR(200), + BlockType INT, + BlockCollectionId INT + ); + -- Table to hold results for blocks DECLARE @BlockResult TABLE ( Id INT, @@ -129,6 +138,20 @@ END INNER JOIN @TempBlockResult b ON qb.BlockId = b.Id WHERE qb.Deleted = 0; + -- Insert answer question block data + INSERT INTO @QABlock + SELECT qb.Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.QuestionBlock qb + INNER JOIN @TempBlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0; + + --Insert AnswerBlockcollectionId + INSERT INTO @BlockCollectionId (Id) + SELECT qa.BlockCollectionId + FROM resources.QuestionAnswer qa + INNER JOIN @QABlock b ON qa.QuestionBlockId = b.Id + WHERE qa.Deleted = 0; + -- Insert block data INSERT INTO @BlockResult @@ -344,6 +367,7 @@ END DECLARE @_QuestionBlockCollectionId TABLE (Id INT); DECLARE @_ImageCarouselBlockCollectionId TABLE (Id INT); DECLARE @_AllBlockAssociatedFiles TABLE (FileId INT, FilePath NVARCHAR(200)); + DECLARE @_QABlock TABLE (Id INT,[Order] INT,Title NVARCHAR(200),BlockType INT,BlockCollectionId INT); -- Insert BlockCollectionIds based on the provided query IF @resourceType = 10 @@ -443,7 +467,19 @@ END INNER JOIN @_TempBlockResult b ON qb.BlockId = b.Id WHERE qb.Deleted = 0; + -- Insert answer question block data + INSERT INTO @_QABlock + SELECT qb.Id, [Order], Title, BlockType, BlockCollectionId + FROM resources.QuestionBlock qb + INNER JOIN @_TempBlockResult b ON qb.BlockId = b.Id + WHERE qb.Deleted = 0; + --Insert AnswerBlockcollectionId + INSERT INTO @_BlockCollectionId (Id) + SELECT qa.BlockCollectionId + FROM resources.QuestionAnswer qa + INNER JOIN @_QABlock b ON qa.QuestionBlockId = b.Id + WHERE qa.Deleted = 0; @@ -676,4 +712,4 @@ END ).value('.', 'NVARCHAR(MAX)'), 1, 2, ''); SET @filePath = @result; - END + END \ No newline at end of file diff --git a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs index dc9ac9d94..c18b90187 100644 --- a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs @@ -438,73 +438,5 @@ private void SetAuditFieldsOnChildren(int userId, ImageCarouselBlock imageCarous this.SetAuditFieldsForCreateOrDelete(userId, imageCarouselBlock.ImageBlockCollection, isCreate); this.SetAuditFieldsOnChildren(userId, imageCarouselBlock.ImageBlockCollection, isCreate); } - - private async Task GetResourceBlockCollectionsFilePath(int excludeResourceVersionId) - { - var command = new SqlCommand - { - CommandType = CommandType.StoredProcedure, - CommandText = "[resources].[CaseBlockCollectionGetAll]", - Parameters = { new SqlParameter("@excludeResourceVersionId", SqlDbType.Int) { Value = excludeResourceVersionId } }, - }; - - var results = this.DbContext.MultipleResults(command) - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With() - .With