From 50e50bb0f27d1bb6f4c877605e745bf6a36cbab3 Mon Sep 17 00:00:00 2001 From: Chalapala RaghavendraReddy Date: Thu, 6 Feb 2025 15:20:51 +0530 Subject: [PATCH] Updated requested changes --- .../Interfaces/ISW360APICommunication.cs | 2 +- .../SW360Apicommunication.cs | 5 +-- .../ISW360ApicommunicationFacade.cs | 2 +- src/LCT.Facade/SW360ApicommunicationFacade.cs | 2 +- .../CreatorValidatorTest.cs | 24 +++++------ .../CreatorValidator.cs | 41 ++++++++++--------- 6 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/LCT.APICommunications/Interfaces/ISW360APICommunication.cs b/src/LCT.APICommunications/Interfaces/ISW360APICommunication.cs index 28f3ef69..372863b6 100644 --- a/src/LCT.APICommunications/Interfaces/ISW360APICommunication.cs +++ b/src/LCT.APICommunications/Interfaces/ISW360APICommunication.cs @@ -40,6 +40,6 @@ public interface ISw360ApiCommunication string AttachComponentSourceToSW360(AttachReport attachReport); void DownloadAttachmentUsingWebClient(string attachmentDownloadLink, string fileName); Task GetComponentDetailsByUrl(string componentLink); - Task GetAllReleasesWithAllData(string page, string pageEntries); + Task GetAllReleasesWithAllData(int page, int pageEntries); } } diff --git a/src/LCT.APICommunications/SW360Apicommunication.cs b/src/LCT.APICommunications/SW360Apicommunication.cs index 1673b3a7..8bdbf405 100644 --- a/src/LCT.APICommunications/SW360Apicommunication.cs +++ b/src/LCT.APICommunications/SW360Apicommunication.cs @@ -313,10 +313,9 @@ public async Task GetComponentUsingName(string componentNam string url = $"{sw360ComponentApi}{ApiConstant.ComponentNameUrl}{componentName}"; return await httpClient.GetAsync(url); } - public async Task GetAllReleasesWithAllData(string page, string pageEntries) + public async Task GetAllReleasesWithAllData(int page, int pageEntries) { - HttpClient httpClient = GetHttpClient(); - HttpResponseMessage httpResponseMessage=new HttpResponseMessage(); + HttpClient httpClient = GetHttpClient(); string url = $"{sw360ReleaseApi}?page={page}&allDetails=true&page_entries={pageEntries}"; return await httpClient.GetAsync(url); } diff --git a/src/LCT.Facade/Interfaces/ISW360ApicommunicationFacade.cs b/src/LCT.Facade/Interfaces/ISW360ApicommunicationFacade.cs index c4db7b9e..8b766303 100644 --- a/src/LCT.Facade/Interfaces/ISW360ApicommunicationFacade.cs +++ b/src/LCT.Facade/Interfaces/ISW360ApicommunicationFacade.cs @@ -43,6 +43,6 @@ public interface ISW360ApicommunicationFacade Task UpdateLinkedRelease(string projectId, string releaseId, UpdateLinkedRelease updateLinkedRelease); Task GetReleaseByExternalId(string purlId,string externalIdKey = ""); Task GetComponentByExternalId(string purlId, string externalIdKey = ""); - Task GetAllReleasesWithAllData(string page, string pageEntries); + Task GetAllReleasesWithAllData(int page, int pageEntries); } } diff --git a/src/LCT.Facade/SW360ApicommunicationFacade.cs b/src/LCT.Facade/SW360ApicommunicationFacade.cs index f1908221..3574f3af 100644 --- a/src/LCT.Facade/SW360ApicommunicationFacade.cs +++ b/src/LCT.Facade/SW360ApicommunicationFacade.cs @@ -195,7 +195,7 @@ public Task GetComponentByExternalId(string purlId, string { return m_sw360ApiCommunication.GetComponentByExternalId(purlId, externalIdKey); } - public Task GetAllReleasesWithAllData(string page,string pageEntries) + public Task GetAllReleasesWithAllData(int page, int pageEntries) { return m_sw360ApiCommunication.GetAllReleasesWithAllData(page, pageEntries); } diff --git a/src/LCT.SW360PackageCreator.UTest/CreatorValidatorTest.cs b/src/LCT.SW360PackageCreator.UTest/CreatorValidatorTest.cs index 00775dc3..57ea2025 100644 --- a/src/LCT.SW360PackageCreator.UTest/CreatorValidatorTest.cs +++ b/src/LCT.SW360PackageCreator.UTest/CreatorValidatorTest.cs @@ -52,7 +52,7 @@ public async Task ValidateAppSettings_TestPositive() { //Arrange string projectName = "Test"; - ProjectReleases projectReleases=new ProjectReleases(); + ProjectReleases projectReleases = new ProjectReleases(); var CommonAppSettings = new CommonAppSettings() { SW360 = new SW360() @@ -64,7 +64,7 @@ public async Task ValidateAppSettings_TestPositive() .ReturnsAsync(projectName); //Act - await CreatorValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object,projectReleases); + await CreatorValidator.ValidateAppSettings(CommonAppSettings, mockISw360ProjectService.Object, projectReleases); //Assert mockISw360ProjectService.Verify(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(), projectReleases), Times.AtLeastOnce); @@ -81,10 +81,10 @@ public async Task ValidateAppSettings_OnClosedProject_EndsTheApplication() { SW360 = new SW360() { - ProjectName= "Test" + ProjectName = "Test" } }; - + mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(), projectReleases)) .ReturnsAsync(projectName); @@ -104,9 +104,9 @@ public void ValidateAppSettings_TestNegative() ProjectReleases projectReleases = new ProjectReleases(); var CommonAppSettings = new CommonAppSettings() { - SW360=new SW360() + SW360 = new SW360() }; - mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(),projectReleases)) + mockISw360ProjectService.Setup(x => x.GetProjectNameByProjectIDFromSW360(It.IsAny(), It.IsAny(), projectReleases)) .ReturnsAsync(projectName); //Act @@ -147,7 +147,7 @@ public async Task TriggerFossologyValidation_TestPositive() var triggerStatusResponse = JsonConvert.SerializeObject(fossTriggerStatus); - mockISW360ApicommunicationFacade.Setup(x => x.GetAllReleasesWithAllData(It.IsAny(), It.IsAny())).ReturnsAsync(new HttpResponseMessage + mockISW360ApicommunicationFacade.Setup(x => x.GetAllReleasesWithAllData(It.IsAny(), It.IsAny())).ReturnsAsync(new HttpResponseMessage { Content = new StringContent(responseBody) }); @@ -160,14 +160,14 @@ public async Task TriggerFossologyValidation_TestPositive() await CreatorValidator.TriggerFossologyValidation(appSettings, mockISW360ApicommunicationFacade.Object); // Assert - mockISW360ApicommunicationFacade.Verify(x => x.GetAllReleasesWithAllData(It.IsAny(), It.IsAny()), Times.Once); - mockISW360ApicommunicationFacade.Verify(x => x.TriggerFossologyProcess(It.IsAny(), It.IsAny()), Times.Once); + mockISW360ApicommunicationFacade.Verify(x => x.GetAllReleasesWithAllData(It.IsAny(), It.IsAny()), Times.Once); + mockISW360ApicommunicationFacade.Verify(x => x.TriggerFossologyProcess(It.IsAny(), It.IsAny()), Times.Once); } [Test] public async Task FossologyUrlValidation_ValidUrl_ReturnsTrue() { // Arrange - + var appSettings = new CommonAppSettings() { @@ -228,7 +228,7 @@ public async Task FossologyUrlValidation_InvalidUrl_ReturnsFalse() // Assert Assert.IsFalse(result); } - + [Test] public async Task FossologyUrlValidation_InvalidUri_ThrowsException() @@ -282,7 +282,7 @@ public async Task FossologyUrlValidation_HttpRequestException_ReturnsFalse() Assert.IsFalse(result); } - + } } diff --git a/src/LCT.SW360PackageCreator/CreatorValidator.cs b/src/LCT.SW360PackageCreator/CreatorValidator.cs index 899b8aa4..c26ae18f 100644 --- a/src/LCT.SW360PackageCreator/CreatorValidator.cs +++ b/src/LCT.SW360PackageCreator/CreatorValidator.cs @@ -63,8 +63,8 @@ public static async Task TriggerFossologyValidation(CommonAppSettings appSetting try { - string page = "0"; - string pageEntries = "20"; + int page = 0; + int pageEntries = 40; bool validReleaseFound = false; ReleasesAllDetails.Sw360Release validRelease = null; int pageCount = 0; @@ -74,37 +74,40 @@ public static async Task TriggerFossologyValidation(CommonAppSettings appSetting string response = responseData?.Content?.ReadAsStringAsync()?.Result ?? string.Empty; ReleasesAllDetails releaseResponse = JsonConvert.DeserializeObject(response); - validRelease = releaseResponse.Embedded.Sw360releases + if (releaseResponse != null) + { + validRelease = releaseResponse?.Embedded?.Sw360releases? .FirstOrDefault(release => release.ClearingState == "APPROVED" && release.AllReleasesEmbedded?.Sw360attachments != null && release.AllReleasesEmbedded.Sw360attachments.Any(attachments => attachments.Count != 0)); - if (validRelease != null) - { - validReleaseFound = true; - } - else - { - // Check if there are more pages - int currentPage = int.Parse(page); - int totalPages = releaseResponse.Page.TotalPages; - if (currentPage < totalPages - 1) + if (validRelease != null) { - page = (currentPage + 1).ToString(); - pageCount++; + validReleaseFound = true; } else { - break; // No more pages to check + int currentPage = page; + int totalPages = (int)(releaseResponse?.Page?.TotalPages); + if (currentPage < totalPages - 1) + { + page = currentPage + 1; + pageCount++; + } + else + { + break; + } } } + } if (validReleaseFound) { - var releaseUrl = validRelease.Links.Self.Href; + var releaseUrl = validRelease?.Links?.Self?.Href; var releaseId = CommonHelper.GetSubstringOfLastOccurance(releaseUrl, "/"); - string sw360link = $"{validRelease.Name}:{validRelease.Version}:{appSettings.SW360.URL}{ApiConstant.Sw360ReleaseUrlApiSuffix}" + + string sw360link = $"{validRelease?.Name}:{validRelease?.Version}:{appSettings?.SW360?.URL}{ApiConstant.Sw360ReleaseUrlApiSuffix}" + $"{releaseId}#/tab-Summary"; FossTriggerStatus fossResult = await sw360CreatorService.TriggerFossologyProcessForValidation(releaseId, sw360link); if (!string.IsNullOrEmpty(fossResult?.Links?.Self?.Href)) @@ -116,7 +119,7 @@ public static async Task TriggerFossologyValidation(CommonAppSettings appSetting } catch (AggregateException ex) { - Logger.Debug($"\tError in TriggerFossologyProcess--{ex}"); + Logger.Debug($"\tError in TriggerFossologyValidation--{ex}"); Logger.Error($"Trigger Fossology Process failed.Please check fossology configuration in sw360"); environmentHelper.CallEnvironmentExit(-1); }