From 790c7ae9dc68040f0894f7427b48a7c7c16e2e9c Mon Sep 17 00:00:00 2001 From: hoangnt2 Date: Mon, 7 Aug 2023 17:28:29 +0700 Subject: [PATCH] Fix(REST): Add COTS details information when fetch a single release that has component type COTS --- .../core/RestControllerHelper.java | 16 ++++++++++++++++ .../resourceserver/restdocs/ReleaseSpecTest.java | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java index 0d2733731f..6577ab2a0e 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/core/RestControllerHelper.java @@ -38,6 +38,8 @@ import org.eclipse.sw360.datahandler.thrift.components.Component; import org.eclipse.sw360.datahandler.thrift.components.ComponentDTO; import org.eclipse.sw360.datahandler.thrift.components.ComponentService; +import org.eclipse.sw360.datahandler.thrift.components.ComponentType; +import org.eclipse.sw360.datahandler.thrift.components.COTSDetails; import org.eclipse.sw360.datahandler.thrift.packages.Package; import org.eclipse.sw360.datahandler.thrift.components.Release; import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink; @@ -318,6 +320,7 @@ public void addEmbeddedDataToHalResourceRelease(HalResource halResource, Release addEmbeddedCreatedByToHalResourceRelease(halResource, sw360Release.getCreatedBy()); addEmbeddedModifiedByToHalResourceRelease(halResource, sw360Release.getModifiedBy()); addEmbeddedSubcribeToHalResourceRelease(halResource, sw360Release); + addEmbeddedCotsDetails(halResource, sw360Release); } public void addEmbeddedContributorsToHalResourceRelease(HalResource halResource, Release sw360Release) { @@ -1295,4 +1298,17 @@ public ProjectDTO convertToEmbeddedProjectDTO(Project project) { embeddedProject.setType(null); return embeddedProject; } + + public void addEmbeddedCotsDetails(HalResource halResource, Release release) { + if (null != release.getCotsDetails() && release.getComponentType().equals(ComponentType.COTS)) { + HalResource cotsDetailsHalResource = new HalResource<>(release.getCotsDetails()); + if (CommonUtils.isNotNullEmptyOrWhitespace(release.getCotsDetails().getCotsResponsible())) { + User sw360User = userService.getUserByEmail(release.getCotsDetails().getCotsResponsible()); + if (null != sw360User) { + addEmbeddedUser(cotsDetailsHalResource, sw360User, "sw360:cotsResponsible"); + } + } + addEmbeddedFields("sw360:cotsDetails", cotsDetailsHalResource, halResource); + } + } } diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ReleaseSpecTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ReleaseSpecTest.java index e56a087ee9..1aebf55624 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ReleaseSpecTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ReleaseSpecTest.java @@ -185,7 +185,7 @@ public void before() throws TException, IOException { component.setDescription("Angular is a development platform for building mobile and desktop web applications."); component.setCreatedOn("2016-12-15"); component.setCreatedBy("admin@sw360.org"); - component.setComponentType(ComponentType.OSS); + component.setComponentType(ComponentType.COTS); component.setVendorNames(new HashSet<>(Collections.singletonList("Google"))); component.setModerators(new HashSet<>(Arrays.asList("admin@sw360.org", "john@sw360.org"))); usedByComponent.add(component); @@ -221,6 +221,10 @@ public void before() throws TException, IOException { clearingInformation.setComponentClearingReportIsSet(false); clearingInformation.setExternalUrl("https://external.url"); + COTSDetails cotsDetails1 = new COTSDetails().setClearingDeadline("2016-12-18").setContainsOSS(true) + .setCotsResponsible("admin@sw360.org").setLicenseClearingReportURL("http://licenseclearingreporturl.com") + .setOssInformationURL("http://ossinformationurl.com").setUsedLicense("MIT"); + release.setId(releaseId); owner.setReleaseId(release.getId()); release.setName("Spring Core 4.3.4"); @@ -250,6 +254,8 @@ public void before() throws TException, IOException { release.setSoftwarePlatforms(new HashSet<>(Arrays.asList("Java SE", ".NET"))); release.setEccInformation(eccInformation); release.setClearingInformation(clearingInformation); + release.setCotsDetails(cotsDetails1); + release.setComponentType(ComponentType.COTS); Set licenseIds = new HashSet<>(); licenseIds.add("MIT"); @@ -695,6 +701,7 @@ public void should_document_get_release() throws Exception { subsectionWithPath("_embedded.sw360:modifiedBy").description("A release modifiedBy with email and link to their <>"), subsectionWithPath("_embedded.sw360:createdBy").description("A release createdBy with email and link to their <>"), subsectionWithPath("_embedded.sw360:attachments").description("An array of all release attachments and link to their <>"), + subsectionWithPath("_embedded.sw360:cotsDetails").description("Cots details information of release has component type = COTS "), subsectionWithPath("_links").description("<> to other resources") ))); }