From 75d3748cc8f3569547fa7bbe5f4873e0496b2011 Mon Sep 17 00:00:00 2001 From: Gaurav Mishra Date: Wed, 18 Dec 2024 11:21:44 +0530 Subject: [PATCH 01/21] fix(cloudant): fix structure of elemMatch query Fix structure of elemMatch query to use: {"field":{"$elemMatch":{"$eq":value}}} Instead of wrong: {"$elemMatch":{"field":{"$eq":value}}} Signed-off-by: Gaurav Mishra --- .../datahandler/cloudantclient/DatabaseConnectorCloudant.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseConnectorCloudant.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseConnectorCloudant.java index 1c9d0efc01..6ad3675e41 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseConnectorCloudant.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/cloudantclient/DatabaseConnectorCloudant.java @@ -785,7 +785,7 @@ public boolean contains(@NotNull String docId) { * @return New selector */ public static @NotNull Map elemMatch(String field, String value) { - return Collections.singletonMap("$elemMatch", - eq(field, value)); + return Collections.singletonMap(field, + eq("$elemMatch", value)); } } From 608975d62b3e95c1ec6a0015e9090be456096697 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 05:09:06 +0000 Subject: [PATCH 02/21] chore(deps): bump org.apache.commons:commons-text from 1.12.0 to 1.13.0 Bumps org.apache.commons:commons-text from 1.12.0 to 1.13.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-text dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4ac971d2ab..af9b45ded7 100644 --- a/pom.xml +++ b/pom.xml @@ -106,7 +106,7 @@ 1.12.0 2.18.0 3.17.0 - 1.12.0 + 1.13.0 2.1.4 3.17.3 1.0.2 From 08857345cb35b3d743c86dcf7d5ab4b3f7edb9d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 02:57:33 +0000 Subject: [PATCH 03/21] chore(deps): bump maven from `85d505f` to `b89ede2` Bumps maven from `85d505f` to `b89ede2`. --- updated-dependencies: - dependency-name: maven dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ff064473ea..c462b41c3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,7 +47,7 @@ COPY --from=sw360thriftbuild /usr/local/bin/thrift /usr/local/bin/thrift # SW360 Build Test image # 3-eclipse-temurin-21 -FROM maven@sha256:85d505fc45ba12ca042b3f4a27eb47a657d186111c4df0a9b15cc5d9359f9266 AS sw360test +FROM maven@sha256:b89ede2635fb8ebd9ba7a3f7d56140f2bd31337b8b0e9fa586b657ee003307a7 AS sw360test COPY --from=localthrift /usr/local/bin/thrift /usr/bin @@ -60,7 +60,7 @@ SHELL ["/bin/bash", "-c"] # is triggered by buildkit images # 3-eclipse-temurin-21 -FROM maven@sha256:85d505fc45ba12ca042b3f4a27eb47a657d186111c4df0a9b15cc5d9359f9266 AS sw360build +FROM maven@sha256:b89ede2635fb8ebd9ba7a3f7d56140f2bd31337b8b0e9fa586b657ee003307a7 AS sw360build ARG COUCHDB_HOST=localhost From 8e2234e8f27d0823da1b6540ca5889b63b1d795b Mon Sep 17 00:00:00 2001 From: Helio Chissini de Castro Date: Thu, 19 Dec 2024 18:59:03 -0300 Subject: [PATCH 04/21] chore: Move dependabot to weekly interval Signed-off-by: Helio Chissini de Castro --- .github/dependabot.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0743fa3ae1..157f88571b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,14 +3,14 @@ updates: - package-ecosystem: github-actions directory: / schedule: - interval: daily + interval: weekly - package-ecosystem: docker directory: / schedule: - interval: daily + interval: weekly - package-ecosystem: maven directory: / schedule: - interval: daily + interval: weekly From a5d4a5b3f8e8317262f3758ca8f8e75e85cabb80 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 02:39:26 +0000 Subject: [PATCH 05/21] chore(deps): bump actions/setup-java from 4.5.0 to 4.6.0 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4.5.0 to 4.6.0. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/8df1039502a15bceb9433410b1a100fbe190c53b...7a6d8a8234af8eb26422e24e3006232cccaa061b) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/docker_deploy.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 69a8bbfdf0..d23f8edbe9 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -62,7 +62,7 @@ jobs: sudo sed -i 's/^couchdb.password\s*=/& '${COUCHDB_PASSWORD}'/' /etc/sw360/couchdb-test.properties - name: Set up JDK 21 - uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0 + uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0 with: java-version: "21" distribution: "temurin" diff --git a/.github/workflows/docker_deploy.yml b/.github/workflows/docker_deploy.yml index 3d8a58f762..2dee558db0 100644 --- a/.github/workflows/docker_deploy.yml +++ b/.github/workflows/docker_deploy.yml @@ -52,7 +52,7 @@ jobs: uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Set up JDK 17 - uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0 + uses: actions/setup-java@7a6d8a8234af8eb26422e24e3006232cccaa061b # v4.6.0 with: java-version: "17" cache: "maven" From 3f5fd9ff7847bf62262fbc05ac0103ee58b5a1b7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 03:00:55 +0000 Subject: [PATCH 06/21] chore(deps-dev): bump nl.jqno.equalsverifier:equalsverifier Bumps [nl.jqno.equalsverifier:equalsverifier](https://github.com/jqno/equalsverifier) from 3.17.3 to 3.17.5. - [Release notes](https://github.com/jqno/equalsverifier/releases) - [Changelog](https://github.com/jqno/equalsverifier/blob/main/CHANGELOG.md) - [Commits](https://github.com/jqno/equalsverifier/compare/equalsverifier-3.17.3...equalsverifier-3.17.5) --- updated-dependencies: - dependency-name: nl.jqno.equalsverifier:equalsverifier dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index af9b45ded7..5f53f30ecb 100644 --- a/pom.xml +++ b/pom.xml @@ -108,7 +108,7 @@ 3.17.0 1.13.0 2.1.4 - 3.17.3 + 3.17.5 1.0.2 1.3.9-1 4.0.5 From ab17c1f93999c0fa74d441897ef6c8314b0ca3d4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 03:01:02 +0000 Subject: [PATCH 07/21] chore(deps): bump org.springframework.security:spring-security-oauth2-authorization-server Bumps [org.springframework.security:spring-security-oauth2-authorization-server](https://github.com/spring-projects/spring-authorization-server) from 1.4.0 to 1.4.1. - [Release notes](https://github.com/spring-projects/spring-authorization-server/releases) - [Commits](https://github.com/spring-projects/spring-authorization-server/compare/1.4.0...1.4.1) --- updated-dependencies: - dependency-name: org.springframework.security:spring-security-oauth2-authorization-server dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5f53f30ecb..08ada1a268 100644 --- a/pom.xml +++ b/pom.xml @@ -149,7 +149,7 @@ 3.3.3 3.0.1 1.1.1.RELEASE - 1.4.0 + 1.4.1 6.4.2 2.7.0 6.2.1 From ecea61e71f81fe09ab63e97b09a470dbd1f52d16 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 03:01:18 +0000 Subject: [PATCH 08/21] chore(deps): bump org.apache.maven.plugins:maven-failsafe-plugin Bumps [org.apache.maven.plugins:maven-failsafe-plugin](https://github.com/apache/maven-surefire) from 3.3.0 to 3.5.2. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.3.0...surefire-3.5.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-failsafe-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 08ada1a268..1e6d2a7253 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ 3.13.0 3.8.1 3.5.0 - 3.3.0 + 3.5.2 3.4.2 3.3.1 3.3.1 From c3d456d4944aab7ee792f886c4d9f0ff03a812bf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 03:01:13 +0000 Subject: [PATCH 09/21] chore(deps): bump com.tngtech.jgiven:jgiven-maven-plugin Bumps [com.tngtech.jgiven:jgiven-maven-plugin](https://github.com/TNG/jgiven) from 1.3.1 to 2.0.1. - [Release notes](https://github.com/TNG/jgiven/releases) - [Changelog](https://github.com/TNG/JGiven/blob/master/CHANGELOG.md) - [Commits](https://github.com/TNG/jgiven/compare/v1.3.1...v2.0.1) --- updated-dependencies: - dependency-name: com.tngtech.jgiven:jgiven-maven-plugin dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1e6d2a7253..742dac52a4 100644 --- a/pom.xml +++ b/pom.xml @@ -738,7 +738,7 @@ com.tngtech.jgiven jgiven-maven-plugin - 1.3.1 + 2.0.1 html From 05472fd45b64c6e8865cad524766f2d433f6e5a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:00:41 +0000 Subject: [PATCH 10/21] chore(deps): bump org.jboss.logging:jboss-logging Bumps [org.jboss.logging:jboss-logging](https://github.com/jboss-logging/jboss-logging) from 3.5.0.Final to 3.6.1.Final. - [Release notes](https://github.com/jboss-logging/jboss-logging/releases) - [Commits](https://github.com/jboss-logging/jboss-logging/compare/3.5.0.Final...3.6.1.Final) --- updated-dependencies: - dependency-name: org.jboss.logging:jboss-logging dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- keycloak/event-listeners/pom.xml | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/keycloak/event-listeners/pom.xml b/keycloak/event-listeners/pom.xml index e0616999b0..2df69d93ba 100644 --- a/keycloak/event-listeners/pom.xml +++ b/keycloak/event-listeners/pom.xml @@ -56,7 +56,7 @@ org.jboss.logging jboss-logging - 3.5.0.Final + 3.6.1.Final provided diff --git a/pom.xml b/pom.xml index 742dac52a4..ae6f80f49f 100644 --- a/pom.xml +++ b/pom.xml @@ -123,7 +123,7 @@ 2.0.1 2.0.1 2.0.0 - 3.5.0.Final + 3.6.1.Final 1.0 0.1.55 26.0.1 From 325cf0ef5ef38f542edd16485a4186fd22671507 Mon Sep 17 00:00:00 2001 From: Helio Chissini de Castro Date: Tue, 26 Nov 2024 08:55:45 +0100 Subject: [PATCH 11/21] fix(deps): Deprecate old commmons-lang library Signed-off-by: Helio Chissini de Castro --- .../db/ProjectDatabaseHandler.java | 4 +- .../sw360/fossology/FossologyHandler.java | 4 +- .../fossology/rest/FossologyRestClient.java | 2 +- backend/licenseinfo/pom.xml | 12 +- .../sw360/licenseinfo/LicenseInfoHandler.java | 2 +- .../outputGenerators/DocxUtils.java | 2 +- .../outputGenerators/XhtmlGenerator.java | 4 +- .../parsers/AbstractCLIParser.java | 4 +- .../sw360/search/db/SearchDocument.java | 2 +- .../vmcomponents/VMComponentHandler.java | 2 +- .../sw360/vmcomponents/common/SVMMapper.java | 2 +- .../vmcomponents/db/VMDatabaseHandler.java | 2 +- .../vmcomponents/handler/SVMSyncHandler.java | 2 +- .../process/VMProcessHandler.java | 2 +- .../handler/SVMSyncHandlerTest.java | 4 +- .../db/VulnerabilityDatabaseHandler.java | 2 +- .../vulnerabilities/VulnerabilityHandler.java | 2 +- .../permissions/DocumentPermissionsTest.java | 2 +- libraries/nouveau-handler/pom.xml | 10 - pom.xml | 6 + .../client/rest/OAuthClientController.java | 2 +- .../security/Sw360UserDetailsProvider.java | 2 +- ...Sw360CustomHeaderAuthenticationFilter.java | 4 +- ...360CustomHeaderAuthenticationProvider.java | 2 +- rest/resource-server/pom.xml | 5 +- .../report/SW360ReportService.java | 5 +- .../resourceserver/user/UserController.java | 264 ++++++++---------- 27 files changed, 161 insertions(+), 195 deletions(-) diff --git a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java index 28573e4e1f..cbd314956a 100644 --- a/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java +++ b/backend/common/src/main/java/org/eclipse/sw360/datahandler/db/ProjectDatabaseHandler.java @@ -22,7 +22,7 @@ import com.google.gson.JsonObject; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.thrift.TException; import org.eclipse.sw360.common.utils.BackendUtils; import org.eclipse.sw360.components.summary.SummaryType; @@ -1319,7 +1319,7 @@ public List fillClearingStateSummaryIncludingSubprojects(List return projects; } - + public Project fillClearingStateSummaryIncludingSubprojectsForSingleProject(Project project, User user) { final Map allProjectsIdMap = getRefreshedAllProjectsIdMap(); diff --git a/backend/fossology/src/main/java/org/eclipse/sw360/fossology/FossologyHandler.java b/backend/fossology/src/main/java/org/eclipse/sw360/fossology/FossologyHandler.java index c3a1feccd2..3662d1f726 100644 --- a/backend/fossology/src/main/java/org/eclipse/sw360/fossology/FossologyHandler.java +++ b/backend/fossology/src/main/java/org/eclipse/sw360/fossology/FossologyHandler.java @@ -25,7 +25,7 @@ import org.eclipse.sw360.fossology.config.FossologyRestConfig; import org.eclipse.sw360.fossology.rest.FossologyRestClient; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.thrift.TException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -159,7 +159,7 @@ public ExternalToolProcess process(String releaseId, User user, String uploadDes FossologyUtils.ensureOrderOfProcessSteps(fossologyProcess); - ExternalToolProcessStep furthestStep = fossologyProcess.getProcessSteps().get(fossologyProcess.getProcessSteps().size() - 1); + ExternalToolProcessStep furthestStep = fossologyProcess.getProcessSteps().get(fossologyProcess.getProcessSteps().size() - 1); if (FossologyUtils.FOSSOLOGY_STEP_NAME_UPLOAD.equals(furthestStep.getStepName())) { handleUploadStep(componentClient, release, user, fossologyProcess, sourceAttachment, uploadDescription); } else if (FossologyUtils.FOSSOLOGY_STEP_NAME_SCAN.equals(furthestStep.getStepName())) { diff --git a/backend/fossology/src/main/java/org/eclipse/sw360/fossology/rest/FossologyRestClient.java b/backend/fossology/src/main/java/org/eclipse/sw360/fossology/rest/FossologyRestClient.java index 40051a8373..4c77cf6776 100644 --- a/backend/fossology/src/main/java/org/eclipse/sw360/fossology/rest/FossologyRestClient.java +++ b/backend/fossology/src/main/java/org/eclipse/sw360/fossology/rest/FossologyRestClient.java @@ -16,7 +16,7 @@ import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.fossology.config.FossologyRestConfig; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/backend/licenseinfo/pom.xml b/backend/licenseinfo/pom.xml index 7f195b4be8..37761d9559 100644 --- a/backend/licenseinfo/pom.xml +++ b/backend/licenseinfo/pom.xml @@ -7,8 +7,8 @@ ~ ~ SPDX-License-Identifier: EPL-2.0 --> - + 4.0.0 @@ -20,7 +20,9 @@ backend-licenseinfo war backend-licenseinfo - licenseinfo + + licenseinfo + ${backend.deploy.dir} @@ -31,6 +33,10 @@ backend-common ${project.version} + + org.apache.commons + commons-text + org.apache.velocity velocity-engine-core diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java index 57b2574de9..d61d9623f6 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/LicenseInfoHandler.java @@ -40,7 +40,7 @@ import org.eclipse.sw360.licenseinfo.outputGenerators.*; import org.eclipse.sw360.licenseinfo.parsers.*; import org.eclipse.sw360.licenseinfo.util.LicenseNameWithTextUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TException; diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxUtils.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxUtils.java index 3ba3c7469b..77b175de40 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxUtils.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/DocxUtils.java @@ -12,7 +12,7 @@ package org.eclipse.sw360.licenseinfo.outputGenerators; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.poi.xwpf.usermodel.*; import org.apache.xmlbeans.XmlException; import org.eclipse.sw360.datahandler.common.CommonUtils; diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGenerator.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGenerator.java index e4d0054015..cd7908f6e3 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGenerator.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/outputGenerators/XhtmlGenerator.java @@ -12,7 +12,7 @@ package org.eclipse.sw360.licenseinfo.outputGenerators; -import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.text.StringEscapeUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.sw360.datahandler.thrift.SW360Exception; @@ -68,7 +68,7 @@ private String generateDisclosure(Collection projectLi } private String convertHeaderTextToHTML(String headerText) { - String html = StringEscapeUtils.escapeHtml(headerText); + String html = StringEscapeUtils.escapeHtml4(headerText); html = html.replace("\n", "
"); return html; } diff --git a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/AbstractCLIParser.java b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/AbstractCLIParser.java index 1a23238131..7d235e0f49 100644 --- a/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/AbstractCLIParser.java +++ b/backend/licenseinfo/src/main/java/org/eclipse/sw360/licenseinfo/parsers/AbstractCLIParser.java @@ -10,7 +10,7 @@ package org.eclipse.sw360.licenseinfo.parsers; import com.google.common.collect.Sets; -import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.text.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -88,7 +88,7 @@ public List getApplicableFileExtensions() { } protected static String normalizeEscapedXhtml(Node node) { - return StringEscapeUtils.unescapeHtml(StringEscapeUtils.unescapeXml(node.getTextContent().trim())); + return StringEscapeUtils.unescapeHtml4(StringEscapeUtils.unescapeXml(node.getTextContent().trim())); } protected static String normalizeSpace(Node node) { diff --git a/backend/search/src/main/java/org/eclipse/sw360/search/db/SearchDocument.java b/backend/search/src/main/java/org/eclipse/sw360/search/db/SearchDocument.java index 5411a30a0a..4ba9e3d2db 100644 --- a/backend/search/src/main/java/org/eclipse/sw360/search/db/SearchDocument.java +++ b/backend/search/src/main/java/org/eclipse/sw360/search/db/SearchDocument.java @@ -10,7 +10,7 @@ package org.eclipse.sw360.search.db; import org.eclipse.sw360.datahandler.common.SW360Constants; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import java.util.Collections; import java.util.HashMap; diff --git a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/VMComponentHandler.java b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/VMComponentHandler.java index f4f22931cc..fd29cbfd28 100644 --- a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/VMComponentHandler.java +++ b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/VMComponentHandler.java @@ -18,7 +18,7 @@ import org.eclipse.sw360.datahandler.thrift.vmcomponents.*; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.thrift.TException; diff --git a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/common/SVMMapper.java b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/common/SVMMapper.java index 3c59739b16..71e45c8538 100644 --- a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/common/SVMMapper.java +++ b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/common/SVMMapper.java @@ -6,7 +6,7 @@ import com.google.common.base.Joiner; import org.eclipse.sw360.datahandler.thrift.vmcomponents.*; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.common.SW360Utils; diff --git a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/db/VMDatabaseHandler.java b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/db/VMDatabaseHandler.java index 2b98dedd5c..e9915983e5 100644 --- a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/db/VMDatabaseHandler.java +++ b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/db/VMDatabaseHandler.java @@ -8,7 +8,7 @@ import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant; import org.eclipse.sw360.datahandler.thrift.vmcomponents.*; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.thrift.TBase; import org.eclipse.sw360.datahandler.common.DatabaseSettings; diff --git a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandler.java b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandler.java index 23307f9c56..452c63903c 100644 --- a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandler.java +++ b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandler.java @@ -7,7 +7,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.thrift.TBase; import org.eclipse.sw360.datahandler.common.DatabaseSettings; diff --git a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/process/VMProcessHandler.java b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/process/VMProcessHandler.java index 5b40af7c61..9baef3eb22 100644 --- a/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/process/VMProcessHandler.java +++ b/backend/vmcomponents/src/main/java/org/eclipse/sw360/vmcomponents/process/VMProcessHandler.java @@ -6,7 +6,7 @@ import org.eclipse.sw360.datahandler.thrift.vmcomponents.VMComponent; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import org.apache.thrift.TBase; import org.eclipse.sw360.datahandler.common.SW360Utils; diff --git a/backend/vmcomponents/src/test/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandlerTest.java b/backend/vmcomponents/src/test/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandlerTest.java index fb0e19e3db..b1875ca3a9 100644 --- a/backend/vmcomponents/src/test/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandlerTest.java +++ b/backend/vmcomponents/src/test/java/org/eclipse/sw360/vmcomponents/handler/SVMSyncHandlerTest.java @@ -7,7 +7,7 @@ import org.eclipse.sw360.datahandler.thrift.vmcomponents.*; import org.eclipse.sw360.vmcomponents.AbstractJSONMockTest; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.thrift.TException; import org.eclipse.sw360.datahandler.TestUtils; import org.eclipse.sw360.datahandler.cloudantclient.DatabaseConnectorCloudant; @@ -388,4 +388,4 @@ public void testFindMatchByReleaseText() throws Exception { assertTrue(match.getMatchTypes().contains(VMMatchType.VERSION_RC)); assertEquals(VMMatchState.MATCHING_LEVEL_3, match.getState()); } -} \ No newline at end of file +} diff --git a/backend/vulnerabilities-core/src/main/java/org/eclipse/sw360/vulnerabilities/db/VulnerabilityDatabaseHandler.java b/backend/vulnerabilities-core/src/main/java/org/eclipse/sw360/vulnerabilities/db/VulnerabilityDatabaseHandler.java index f8bcc662b8..930c0424d4 100644 --- a/backend/vulnerabilities-core/src/main/java/org/eclipse/sw360/vulnerabilities/db/VulnerabilityDatabaseHandler.java +++ b/backend/vulnerabilities-core/src/main/java/org/eclipse/sw360/vulnerabilities/db/VulnerabilityDatabaseHandler.java @@ -22,7 +22,7 @@ import org.eclipse.sw360.datahandler.thrift.vulnerabilities.*; import org.eclipse.sw360.vulnerabilities.common.VulnerabilityMapper; import org.apache.hc.core5.http.HttpStatus; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TBase; diff --git a/backend/vulnerabilities/src/main/java/org/eclipse/sw360/vulnerabilities/VulnerabilityHandler.java b/backend/vulnerabilities/src/main/java/org/eclipse/sw360/vulnerabilities/VulnerabilityHandler.java index 69945da0cc..b7d97062f4 100644 --- a/backend/vulnerabilities/src/main/java/org/eclipse/sw360/vulnerabilities/VulnerabilityHandler.java +++ b/backend/vulnerabilities/src/main/java/org/eclipse/sw360/vulnerabilities/VulnerabilityHandler.java @@ -34,7 +34,7 @@ import org.eclipse.sw360.vulnerabilities.common.VulnerabilityMapper; import org.eclipse.sw360.vulnerabilities.db.VulnerabilityDatabaseHandler; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TException; diff --git a/libraries/datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/DocumentPermissionsTest.java b/libraries/datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/DocumentPermissionsTest.java index 947b6e14fd..ad2d54b512 100644 --- a/libraries/datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/DocumentPermissionsTest.java +++ b/libraries/datahandler/src/test/java/org/eclipse/sw360/datahandler/permissions/DocumentPermissionsTest.java @@ -12,7 +12,7 @@ import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; -import org.apache.commons.lang.NotImplementedException; +import org.apache.commons.lang3.NotImplementedException; import org.eclipse.sw360.datahandler.thrift.users.RequestedAction; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/libraries/nouveau-handler/pom.xml b/libraries/nouveau-handler/pom.xml index 6125d39ced..a740482e7c 100644 --- a/libraries/nouveau-handler/pom.xml +++ b/libraries/nouveau-handler/pom.xml @@ -162,28 +162,18 @@ com.ibm.cloud cloudant - ${cloudantsdk.version} - - - commons-lang - commons-lang - 2.6 junit junit - ${junit.version} - test joda-time joda-time - 2.13.0 org.jetbrains annotations - 26.0.1 diff --git a/pom.xml b/pom.xml index ae6f80f49f..9e36b56d06 100644 --- a/pom.xml +++ b/pom.xml @@ -131,6 +131,7 @@ 2.0.1 0.9.6 20240303 + 2.13.0 1.13.1 4.13.2 2.24.3 @@ -626,6 +627,11 @@ pom test
+ + joda-time + joda-time + ${joda-time.version} + diff --git a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/client/rest/OAuthClientController.java b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/client/rest/OAuthClientController.java index 9521f35366..1bee15006f 100644 --- a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/client/rest/OAuthClientController.java +++ b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/client/rest/OAuthClientController.java @@ -16,7 +16,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.eclipse.sw360.datahandler.thrift.SW360Exception; import org.eclipse.sw360.rest.authserver.client.persistence.OAuthClientEntity; import org.eclipse.sw360.rest.authserver.client.persistence.OAuthClientRepository; diff --git a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/Sw360UserDetailsProvider.java b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/Sw360UserDetailsProvider.java index f3b9054da3..2b5bf4c8f1 100644 --- a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/Sw360UserDetailsProvider.java +++ b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/Sw360UserDetailsProvider.java @@ -9,7 +9,7 @@ */ package org.eclipse.sw360.rest.authserver.security; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.thrift.TException; diff --git a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationFilter.java b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationFilter.java index ff2ae5fbca..f8f7a4da6d 100644 --- a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationFilter.java +++ b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationFilter.java @@ -13,7 +13,7 @@ import jakarta.annotation.PostConstruct; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.sw360.datahandler.thrift.users.User; @@ -240,4 +240,4 @@ private static class CustomHeaderOAuthRequestDetails extends CustomHeaderAuthReq public String customParamClientSecret; public String grantType; } -} \ No newline at end of file +} diff --git a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationProvider.java b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationProvider.java index df77d27855..0956632216 100644 --- a/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationProvider.java +++ b/rest/authorization-server/src/main/java/org/eclipse/sw360/rest/authserver/security/customheaderauth/Sw360CustomHeaderAuthenticationProvider.java @@ -14,7 +14,7 @@ import jakarta.annotation.PostConstruct; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.sw360.datahandler.thrift.users.User; diff --git a/rest/resource-server/pom.xml b/rest/resource-server/pom.xml index aac6dc95cb..369acf278d 100644 --- a/rest/resource-server/pom.xml +++ b/rest/resource-server/pom.xml @@ -164,6 +164,10 @@ jakarta.xml.bind jakarta.xml.bind-api + + org.apache.commons + commons-text + org.glassfish.jaxb jaxb-runtime @@ -200,7 +204,6 @@ springdoc-openapi-starter-common ${springdoc-openapi-stater-common.version} - diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/report/SW360ReportService.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/report/SW360ReportService.java index 7cfe136317..e0526c8090 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/report/SW360ReportService.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/report/SW360ReportService.java @@ -46,8 +46,9 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Stream; - -import org.apache.commons.lang.StringUtils; +import jakarta.servlet.http.HttpServletRequest; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.thrift.Source; import org.eclipse.sw360.datahandler.thrift.attachments.Attachment; import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentUsage; diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/UserController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/UserController.java index 5ea5261767..d1294662ba 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/UserController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/user/UserController.java @@ -1,9 +1,8 @@ /* * Copyright Siemens AG, 2017-2018. Part of the SW360 Portal Project. * - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ + * This program and the accompanying materials are made available under the terms of the Eclipse + * Public License 2.0 which is available at https://www.eclipse.org/legal/epl-2.0/ * * SPDX-License-Identifier: EPL-2.0 */ @@ -22,8 +21,8 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.RandomStringUtils; -import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.text.StringEscapeUtils; import org.apache.thrift.TException; import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.common.SW360Constants; @@ -91,28 +90,25 @@ public class UserController implements RepresentationModelProcessor setOfUserProfileFields = ImmutableSet.builder() - .add(User._Fields.WANTS_MAIL_NOTIFICATION) - .add(User._Fields.NOTIFICATION_PREFERENCES).build(); + private static final ImmutableSet setOfUserProfileFields = + ImmutableSet.builder().add(User._Fields.WANTS_MAIL_NOTIFICATION) + .add(User._Fields.NOTIFICATION_PREFERENCES).build(); - @Operation( - summary = "List all of the service's users.", - description = "List all of the service's users.", - tags = {"Users"} - ) + @Operation(summary = "List all of the service's users.", + description = "List all of the service's users.", tags = {"Users"}) @RequestMapping(value = USERS_URL, method = RequestMethod.GET) - public ResponseEntity>> getUsers( - Pageable pageable, + public ResponseEntity>> getUsers(Pageable pageable, HttpServletRequest request, - @Parameter(description = "fullName of the users") - @RequestParam(value = "givenname", required = false) String givenname, + @Parameter(description = "fullName of the users") @RequestParam(value = "givenname", + required = false) String givenname, @RequestParam(value = "email", required = false) String email, - @Parameter(description = "luceneSearch parameter to filter the users.") - @RequestParam(value = "luceneSearch", required = false) boolean luceneSearch, + @Parameter(description = "luceneSearch parameter to filter the users.") @RequestParam( + value = "luceneSearch", required = false) boolean luceneSearch, @RequestParam(value = "lastname", required = false) String lastname, @RequestParam(value = "department", required = false) String department, - @RequestParam(value = "usergroup", required = false) UserGroup usergroup - ) throws TException, URISyntaxException, PaginationParameterException, ResourceClassNotFoundException { + @RequestParam(value = "usergroup", required = false) UserGroup usergroup) + throws TException, URISyntaxException, PaginationParameterException, + ResourceClassNotFoundException { PaginationResult paginationResult = null; List sw360Users = new ArrayList<>(); boolean isSearchByName = givenname != null && !givenname.isEmpty(); @@ -124,13 +120,15 @@ public ResponseEntity>> getUsers( Map> filterMap = new HashMap<>(); if (CommonUtils.isNotNullEmptyOrWhitespace(givenname)) { Set values = CommonUtils.splitToSet(givenname); - values = values.stream().map(NouveauLuceneAwareDatabaseConnector::prepareWildcardQuery) + values = values.stream() + .map(NouveauLuceneAwareDatabaseConnector::prepareWildcardQuery) .collect(Collectors.toSet()); filterMap.put(User._Fields.GIVENNAME.getFieldName(), values); } if (CommonUtils.isNotNullEmptyOrWhitespace(email)) { Set values = CommonUtils.splitToSet(email); - values = values.stream().map(NouveauLuceneAwareDatabaseConnector::prepareWildcardQuery) + values = values.stream() + .map(NouveauLuceneAwareDatabaseConnector::prepareWildcardQuery) .collect(Collectors.toSet()); filterMap.put(User._Fields.EMAIL.getFieldName(), values); } @@ -142,15 +140,16 @@ public ResponseEntity>> getUsers( Set values = CommonUtils.splitToSet(usergroup.toString()); filterMap.put(User._Fields.USER_GROUP.getFieldName(), values); } - if (CommonUtils.isNotNullEmptyOrWhitespace(lastname)) { - Set values = CommonUtils.splitToSet(lastname); - values = values.stream().map(NouveauLuceneAwareDatabaseConnector::prepareWildcardQuery) + if (CommonUtils.isNotNullEmptyOrWhitespace(lastname)) { + Set values = CommonUtils.splitToSet(lastname); + values = values.stream() + .map(NouveauLuceneAwareDatabaseConnector::prepareWildcardQuery) .collect(Collectors.toSet()); filterMap.put(User._Fields.LASTNAME.getFieldName(), values); } List userByGivenName = userService.refineSearch(filterMap); - paginationResult = restControllerHelper.createPaginationResult(request, pageable, userByGivenName, - SW360Constants.TYPE_USER); + paginationResult = restControllerHelper.createPaginationResult(request, pageable, + userByGivenName, SW360Constants.TYPE_USER); } else { if (isSearchByName) { sw360Users.addAll(userService.searchUserByName(givenname)); @@ -163,8 +162,8 @@ public ResponseEntity>> getUsers( } else { sw360Users = userService.getAllUsers(); } - paginationResult = restControllerHelper.createPaginationResult(request, pageable, sw360Users, - SW360Constants.TYPE_USER); + paginationResult = restControllerHelper.createPaginationResult(request, pageable, + sw360Users, SW360Constants.TYPE_USER); } List> userResources = new ArrayList<>(); for (User sw360User : paginationResult.getResources()) { @@ -186,16 +185,11 @@ public ResponseEntity>> getUsers( // '/users/{xyz}' searches by email, as opposed to by id, as is customary, // for compatibility with older version of the REST API - @Operation( - summary = "Get a single user.", - description = "Get a single user by email.", - tags = {"Users"} - ) + @Operation(summary = "Get a single user.", description = "Get a single user by email.", + tags = {"Users"}) @RequestMapping(value = USERS_URL + "/{email:.+}", method = RequestMethod.GET) - public ResponseEntity> getUserByEmail( - @Parameter(description = "The email of the user to be retrieved.") - @PathVariable("email") String email - ) { + public ResponseEntity> getUserByEmail(@Parameter( + description = "The email of the user to be retrieved.") @PathVariable("email") String email) { String decodedEmail; try { decodedEmail = URLDecoder.decode(email, "UTF-8"); @@ -208,51 +202,40 @@ public ResponseEntity> getUserByEmail( return new ResponseEntity<>(halResource, HttpStatus.OK); } - // unusual URL mapping for compatibility with older version of the REST API (see getUserByEmail()) - @Operation( - summary = "Get a single user.", - description = "Get a single user by id.", - tags = {"Users"} - ) + // unusual URL mapping for compatibility with older version of the REST API (see + // getUserByEmail()) + @Operation(summary = "Get a single user.", description = "Get a single user by id.", + tags = {"Users"}) @RequestMapping(value = USERS_URL + "/byid/{id:.+}", method = RequestMethod.GET) - public ResponseEntity> getUser( - @Parameter(description = "The id of the user to be retrieved.") - @PathVariable("id") String id - ) { + public ResponseEntity> getUser(@Parameter( + description = "The id of the user to be retrieved.") @PathVariable("id") String id) { User sw360User = userService.getUser(id); HalResource halResource = createHalUser(sw360User); return new ResponseEntity<>(halResource, HttpStatus.OK); } - @Operation( - summary = "Create a new user.", - description = "Create a user (not in Liferay).", - tags = {"Users"} - ) + @Operation(summary = "Create a new user.", description = "Create a user (not in Liferay).", + tags = {"Users"}) @PostMapping(value = USERS_URL) public ResponseEntity> createUser( - @Parameter(description = "The user to be created.") - @RequestBody User user - ) throws TException { - if(CommonUtils.isNullEmptyOrWhitespace(user.getPassword())) { - throw new HttpMessageNotReadableException("Password can not be null or empty or whitespace!"); + @Parameter(description = "The user to be created.") @RequestBody User user) + throws TException { + if (CommonUtils.isNullEmptyOrWhitespace(user.getPassword())) { + throw new HttpMessageNotReadableException( + "Password can not be null or empty or whitespace!"); } String encodedPassword = passwordEncoder.encode(user.getPassword()); user.setPassword(encodedPassword); User createdUser = userService.addUser(user); HalResource halResource = createHalUser(createdUser); - URI location = ServletUriComponentsBuilder - .fromCurrentRequest().path("/{id}") + URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}") .buildAndExpand(createdUser.getId()).toUri(); return ResponseEntity.created(location).body(halResource); } - @Operation( - summary = "Get current user's profile.", - description = "Get current user's profile.", - tags = {"Users"} - ) + @Operation(summary = "Get current user's profile.", description = "Get current user's profile.", + tags = {"Users"}) @GetMapping(value = USERS_URL + "/profile") public ResponseEntity> getUserProfile() { User sw360User = restControllerHelper.getSw360UserFromAuthentication(); @@ -260,58 +243,49 @@ public ResponseEntity> getUserProfile() { return ResponseEntity.ok(halUserResource); } - @Operation( - summary = "Update user's profile.", - description = "Update user's profile.", - tags = {"Users"} - ) + @Operation(summary = "Update user's profile.", description = "Update user's profile.", + tags = {"Users"}) @PatchMapping(value = USERS_URL + "/profile") public ResponseEntity> updateUserProfile( - @Parameter(description = "Updated user profile", - schema = @Schema(example = """ - { - "wantsMailNotification": true, - "notificationPreferences": { - "releaseCONTRIBUTORS": true, - "componentCREATED_BY": false, - "releaseCREATED_BY": false, - "moderationREQUESTING_USER": false, - "projectPROJECT_OWNER": true, - "moderationMODERATORS": false, - "releaseSUBSCRIBERS": true, - "componentMODERATORS": true, - "projectMODERATORS": false, - "projectROLES": false, - "releaseROLES": true, - "componentROLES": true, - "projectLEAD_ARCHITECT": false, - "componentCOMPONENT_OWNER": true, - "projectSECURITY_RESPONSIBLES": true, - "clearingREQUESTING_USER": true, - "projectCONTRIBUTORS": true, - "componentSUBSCRIBERS": true, - "projectPROJECT_RESPONSIBLE": false, - "releaseMODERATORS": false - } - } - """)) - @RequestBody Map userProfile - ) throws TException { + @Parameter(description = "Updated user profile", schema = @Schema(example = """ + { + "wantsMailNotification": true, + "notificationPreferences": { + "releaseCONTRIBUTORS": true, + "componentCREATED_BY": false, + "releaseCREATED_BY": false, + "moderationREQUESTING_USER": false, + "projectPROJECT_OWNER": true, + "moderationMODERATORS": false, + "releaseSUBSCRIBERS": true, + "componentMODERATORS": true, + "projectMODERATORS": false, + "projectROLES": false, + "releaseROLES": true, + "componentROLES": true, + "projectLEAD_ARCHITECT": false, + "componentCOMPONENT_OWNER": true, + "projectSECURITY_RESPONSIBLES": true, + "clearingREQUESTING_USER": true, + "projectCONTRIBUTORS": true, + "componentSUBSCRIBERS": true, + "projectPROJECT_RESPONSIBLE": false, + "releaseMODERATORS": false + } + } + """)) @RequestBody Map userProfile) throws TException { User sw360User = restControllerHelper.getSw360UserFromAuthentication(); - sw360User = restControllerHelper.updateUserProfile(sw360User, userProfile, setOfUserProfileFields); + sw360User = restControllerHelper.updateUserProfile(sw360User, userProfile, + setOfUserProfileFields); userService.updateUser(sw360User); HalResource halUserResource = new HalResource<>(sw360User); return ResponseEntity.ok(halUserResource); } - @Operation( - summary = "List all of rest api tokens.", + @Operation(summary = "List all of rest api tokens.", description = "List all of rest api tokens of current user.", - responses = { - @ApiResponse(responseCode = "200", description = "List of tokens.") - }, - tags = {"Users"} - ) + responses = {@ApiResponse(responseCode = "200", description = "List of tokens.")}, + tags = {"Users"}) @RequestMapping(value = USERS_URL + "/tokens", method = RequestMethod.GET) public ResponseEntity>> getUserRestApiTokens() { final User sw360User = restControllerHelper.getSw360UserFromAuthentication(); @@ -321,26 +295,22 @@ public ResponseEntity>> getUserRestApi return new ResponseEntity<>(CollectionModel.of(Collections.emptyList()), HttpStatus.OK); } - List> restApiResources = restApiTokens.stream() - .map(EntityModel::of) - .collect(Collectors.toList()); + List> restApiResources = + restApiTokens.stream().map(EntityModel::of).collect(Collectors.toList()); return new ResponseEntity<>(CollectionModel.of(restApiResources), HttpStatus.OK); } - @Operation( - summary = "Create rest api token.", + @Operation(summary = "Create rest api token.", description = "Create rest api token for current user.", responses = { @ApiResponse(responseCode = "201", description = "Create token successfully."), - @ApiResponse(responseCode = "500", description = "Create token failure.") - }, - tags = {"Users"} - ) + @ApiResponse(responseCode = "500", description = "Create token failure.")}, + tags = {"Users"}) @RequestMapping(value = USERS_URL + "/tokens", method = RequestMethod.POST) public ResponseEntity createUserRestApiToken( - @Parameter(description = "Token request", schema = @Schema(implementation = RestApiToken.class)) - @RequestBody Map requestBody - ) throws TException { + @Parameter(description = "Token request", schema = @Schema( + implementation = RestApiToken.class)) @RequestBody Map requestBody) + throws TException { User sw360User = restControllerHelper.getSw360UserFromAuthentication(); RestApiToken restApiToken = userService.convertToRestApiToken(requestBody, sw360User); String token = RandomStringUtils.random(20, true, true); @@ -351,24 +321,23 @@ public ResponseEntity createUserRestApiToken( return new ResponseEntity<>(token, HttpStatus.CREATED); } - @Operation( - summary = "Delete rest api token.", + @Operation(summary = "Delete rest api token.", description = "Delete rest api token by name for current user.", responses = { @ApiResponse(responseCode = "204", description = "Revoke token successfully."), - @ApiResponse(responseCode = "404", description = "Token name not found.") - }, - tags = {"Users"} - ) + @ApiResponse(responseCode = "404", description = "Token name not found.")}, + tags = {"Users"}) @RequestMapping(value = USERS_URL + "/tokens", method = RequestMethod.DELETE) public ResponseEntity revokeUserRestApiToken( - @Parameter(description = "Name of token to be revoked.", example = "MyToken") - @RequestParam("name") String tokenName - ) throws TException { + @Parameter(description = "Name of token to be revoked.", + example = "MyToken") @RequestParam("name") String tokenName) + throws TException { User sw360User = restControllerHelper.getSw360UserFromAuthentication(); if (!userService.isTokenNameExisted(sw360User, tokenName)) { - return new ResponseEntity<>("Token not found: " + StringEscapeUtils.escapeHtml(tokenName), HttpStatus.NOT_FOUND); + return new ResponseEntity<>( + "Token not found: " + StringEscapeUtils.escapeHtml4(tokenName), + HttpStatus.NOT_FOUND); } sw360User.getRestApiTokens().removeIf(t -> t.getName().equals(tokenName)); @@ -386,26 +355,16 @@ private HalResource createHalUser(User sw360User) { return new HalResource<>(sw360User); } - @Operation( - summary = "Fetch group list of a user.", - description = "Fetch the list of group for a particular user.", - tags = {"Users"} - ) - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "User and its groups.", - content = { - @Content(mediaType = "application/json", - examples = @ExampleObject( - value = """ - { - "primaryGrpList": ["DEPARTMENT"], - "secondaryGrpList": ["DEPARTMENT1","DEPARTMENT2"] - } - """ - )) - } - ) - }) + @Operation(summary = "Fetch group list of a user.", + description = "Fetch the list of group for a particular user.", tags = {"Users"}) + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "User and its groups.", + content = { + @Content(mediaType = "application/json", examples = @ExampleObject(value = """ + { + "primaryGrpList": ["DEPARTMENT"], + "secondaryGrpList": ["DEPARTMENT1","DEPARTMENT2"] + } + """))})}) @RequestMapping(value = USERS_URL + "/groupList", method = RequestMethod.GET) public ResponseEntity>> getGroupList() { User sw360User = restControllerHelper.getSw360UserFromAuthentication(); @@ -416,7 +375,8 @@ public ResponseEntity>> getGroupList() { if (mainDepartment != null && !mainDepartment.isEmpty()) { primaryGrpList.add(mainDepartment); } - Map> secondaryDepartmentsAndRoles = sw360User.getSecondaryDepartmentsAndRoles(); + Map> secondaryDepartmentsAndRoles = + sw360User.getSecondaryDepartmentsAndRoles(); if (secondaryDepartmentsAndRoles != null) { secondaryGrpList.addAll(secondaryDepartmentsAndRoles.keySet()); } From 6dbec3601e18a94c42e0221b887178f93c12da2a Mon Sep 17 00:00:00 2001 From: Rudra Chopra Date: Mon, 2 Dec 2024 13:13:57 +0530 Subject: [PATCH 12/21] fix(rest): adding additional fields to attachmentUsage endpoint. Signed-off-by: Rudra Chopra --- .../sw360/rest/resourceserver/core/RestControllerHelper.java | 2 ++ .../sw360/rest/resourceserver/project/ProjectController.java | 2 +- 2 files changed, 3 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 bee6b3ae95..4b3fd044ad 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 @@ -496,6 +496,8 @@ public Release convertToEmbeddedReleaseAttachments(Release release) { embeddedRelease.setName(release.getName()); embeddedRelease.setVersion(release.getVersion()); embeddedRelease.setAttachments(release.getAttachments()); + embeddedRelease.setComponentType(release.getComponentType()); + embeddedRelease.setClearingState(release.getClearingState()); embeddedRelease.setType(null); return embeddedRelease; } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java index d39ae9c5e8..a0648184e4 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/project/ProjectController.java @@ -1962,7 +1962,7 @@ private List> getReleaseObjectMapper(List fieldsToKeep = ImmutableSet.of("name", "version", ATTACHMENTS); + final ImmutableSet fieldsToKeep = ImmutableSet.of("name", "version", "componentType", "clearingState", ATTACHMENTS); Map valueToKeep = new LinkedHashMap<>(); Link releaseLink = null; if (relMap != null) { From 0683857036d9e1746ebe6e5dc7249f7be44a5666 Mon Sep 17 00:00:00 2001 From: Gaurav Mishra Date: Thu, 19 Dec 2024 15:09:04 +0530 Subject: [PATCH 13/21] feat(api): complete advance search for components Add all missing parameters to the components endpoint for filtering. Signed-off-by: Gaurav Mishra --- .../NouveauLuceneAwareDatabaseConnector.java | 21 ++- .../component/ComponentController.java | 129 ++++++++++++++---- 2 files changed, 124 insertions(+), 26 deletions(-) diff --git a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/couchdb/lucene/NouveauLuceneAwareDatabaseConnector.java b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/couchdb/lucene/NouveauLuceneAwareDatabaseConnector.java index 5366ede9dd..162b15c48b 100644 --- a/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/couchdb/lucene/NouveauLuceneAwareDatabaseConnector.java +++ b/libraries/datahandler/src/main/java/org/eclipse/sw360/datahandler/couchdb/lucene/NouveauLuceneAwareDatabaseConnector.java @@ -317,8 +317,14 @@ private static String sanitizeQueryInput(String input) { return "[" + dateToNouveauDouble(dates[0]) + RANGE_TO + dateToNouveauDouble(dates[1]) + "]"; } + /** + * Parse dates from String in (yyyy-MM-dd) format to Nouveau format (yyyyMMdd) which is used as a double in queries. + * @param date Date to convert + * @return Parsed date for Nouveau + * @throws ParseException If input date cannot be parsed + * @see #dateToNouveauFormat(Date) + */ public static @NotNull String dateToNouveauDouble(String date) throws ParseException { - SimpleDateFormat outputFormatter = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat inputFormatterDate = new SimpleDateFormat("yyyy-MM-dd"); Date parsedDate; try { @@ -328,6 +334,17 @@ private static String sanitizeQueryInput(String input) { } catch (Exception e) { throw new ParseException("Date format not recognized", 0); } - return outputFormatter.format(parsedDate.getTime()); + return dateToNouveauFormat(parsedDate); + } + + /** + * Convert a java.util.Date object to Nouveau format (yyyyMMdd) which is used as a double in queries. + * @param date Date to convert + * @return Parsed date for Nouveau + * @see #dateToNouveauDouble(String) + */ + public static @NotNull String dateToNouveauFormat(Date date) { + SimpleDateFormat outputFormatter = new SimpleDateFormat("yyyyMMdd"); + return outputFormatter.format(date.getTime()); } } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java index 99567ebecc..d36bface86 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java @@ -37,6 +37,7 @@ import org.eclipse.sw360.datahandler.thrift.attachments.AttachmentDTO; import org.eclipse.sw360.datahandler.thrift.components.Component; import org.eclipse.sw360.datahandler.thrift.components.ComponentDTO; +import org.eclipse.sw360.datahandler.thrift.components.ComponentType; import org.eclipse.sw360.datahandler.thrift.components.Release; import org.eclipse.sw360.datahandler.thrift.components.ReleaseLink; import org.eclipse.sw360.datahandler.thrift.projects.Project; @@ -71,7 +72,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; @@ -87,13 +87,11 @@ import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; -import java.net.URLDecoder; -import java.nio.charset.StandardCharsets; import java.util.*; import java.util.function.Consumer; +import java.util.function.Predicate; import java.util.stream.Collectors; import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo; @@ -141,13 +139,31 @@ public ResponseEntity>> getComponents( Pageable pageable, @Parameter(description = "Name of the component to filter") @RequestParam(value = "name", required = false) String name, - @Parameter(description = "Type of the component to filter") + @Parameter(description = "Categories of the component to filter, as a comma separated list.") + @RequestParam(value = "categories", required = false) String categories, + @Parameter(description = "Type of the component to filter", + schema = @Schema(implementation = ComponentType.class)) @RequestParam(value = "type", required = false) String componentType, + @Parameter(description = "Component languages to filter, as a comma separated list.") + @RequestParam(value = "languages", required = false) String languages, + @Parameter(description = "Software Platforms to filter, as a comma separated list.") + @RequestParam(value = "softwarePlatforms", required = false) String softwarePlatforms, + @Parameter(description = "Operating Systems to filter, as a comma separated list.") + @RequestParam(value = "operatingSystems", required = false) String operatingSystems, + @Parameter(description = "Vendors to filter, as a comma separated list.") + @RequestParam(value = "vendors", required = false) String vendors, + @Parameter(description = "Main Licenses to filter, as a comma separated list.") + @RequestParam(value = "mainLicenses", required = false) String mainLicenses, + @Parameter(description = "Created by user to filter (email).") + @RequestParam(value = "createdBy", required = false) String createdBy, + @Parameter(description = "Date component was created on (YYYY-MM-DD).", + schema = @Schema(type = "string", format = "date")) + @RequestParam(value = "createdOn", required = false) String createdOn, @Parameter(description = "Properties which should be present for each component in the result") @RequestParam(value = "fields", required = false) List fields, @Parameter(description = "Flag to get components with all details.") @RequestParam(value = "allDetails", required = false) boolean allDetails, - @Parameter(description = "lucenesearch parameter to filter the components.") + @Parameter(description = "Use lucenesearch to filter the components.") @RequestParam(value = "luceneSearch", required = false) boolean luceneSearch, HttpServletRequest request ) throws TException, URISyntaxException, PaginationParameterException, ResourceClassNotFoundException { @@ -158,12 +174,9 @@ public ResponseEntity>> getComponents( String queryString = request.getQueryString(); Map params = restControllerHelper.parseQueryString(queryString); - Map> filterMap = new HashMap<>(); if (luceneSearch) { - if (CommonUtils.isNotNullEmptyOrWhitespace(componentType)) { - Set values = CommonUtils.splitToSet(componentType); - filterMap.put(Component._Fields.COMPONENT_TYPE.getFieldName(), values); - } + Map> filterMap = getFilterMap(categories, componentType, languages, softwarePlatforms, + operatingSystems, vendors, mainLicenses, createdBy, createdOn); if (CommonUtils.isNotNullEmptyOrWhitespace(name)) { Set values = CommonUtils.splitToSet(name); values = values.stream().map(NouveauLuceneAwareDatabaseConnector::prepareWildcardQuery) @@ -177,19 +190,24 @@ public ResponseEntity>> getComponents( } else { allComponents.addAll(componentService.getComponentsForUser(sw360User)); } + Map> restrictions = getFilterMap(categories, componentType, languages, + softwarePlatforms, operatingSystems, vendors, mainLicenses, createdBy, createdOn); + if (!restrictions.isEmpty()) { + allComponents = new ArrayList<>(allComponents.stream() + .filter(filterComponentMap(restrictions)).toList()); + } } PaginationResult paginationResult = restControllerHelper.createPaginationResult(request, pageable, allComponents, SW360Constants.TYPE_COMPONENT); - CollectionModel resources = getFilteredComponentResources(componentType, fields, allDetails, luceneSearch, - sw360User, paginationResult); + CollectionModel resources = getFilteredComponentResources(fields, allDetails, sw360User, paginationResult); return new ResponseEntity<>(resources, HttpStatus.OK); } - private CollectionModel getFilteredComponentResources(String componentType, List fields, boolean allDetails, - boolean luceneSearch, User sw360User, PaginationResult paginationResult) - throws URISyntaxException { + private CollectionModel getFilteredComponentResources( + List fields, boolean allDetails, User sw360User, PaginationResult paginationResult + ) throws URISyntaxException { List> componentResources = new ArrayList<>(); Consumer consumer = c -> { EntityModel embeddedComponentResource = null; @@ -209,14 +227,7 @@ private CollectionModel getFilteredComponentResources(String componentType, List componentResources.add(embeddedComponentResource); }; - if (luceneSearch) { - paginationResult.getResources().stream().forEach(consumer); - } else { - paginationResult.getResources().stream() - .filter(component -> componentType == null - || (component.isSetComponentType() && componentType.equals(component.componentType.name()))) - .forEach(consumer); - } + paginationResult.getResources().forEach(consumer); CollectionModel resources; if (componentResources.isEmpty()) { @@ -1092,4 +1103,74 @@ public ResponseEntity splitComponents( return new ResponseEntity<>(requestStatus, HttpStatus.OK); } + + /** + * Create a map of filters with the field name in the key and expected value in the value (as set). + * @return Filter map from the user's request. + */ + private @NonNull Map> getFilterMap( + String categories, String componentType, String languages, String softwarePlatforms, + String operatingSystems, String vendors, String mainLicenses, String createdBy, String createdOn + ) { + Map> filterMap = new HashMap<>(); + if (CommonUtils.isNotNullEmptyOrWhitespace(categories)) { + filterMap.put(Component._Fields.CATEGORIES.getFieldName(), CommonUtils.splitToSet(categories)); + } + if (CommonUtils.isNotNullEmptyOrWhitespace(componentType)) { + filterMap.put(Component._Fields.COMPONENT_TYPE.getFieldName(), CommonUtils.splitToSet(componentType)); + } + if (CommonUtils.isNotNullEmptyOrWhitespace(languages)) { + filterMap.put(Component._Fields.LANGUAGES.getFieldName(), CommonUtils.splitToSet(languages)); + } + if (CommonUtils.isNotNullEmptyOrWhitespace(softwarePlatforms)) { + filterMap.put(Component._Fields.SOFTWARE_PLATFORMS.getFieldName(), CommonUtils.splitToSet(softwarePlatforms)); + } + if (CommonUtils.isNotNullEmptyOrWhitespace(operatingSystems)) { + filterMap.put(Component._Fields.OPERATING_SYSTEMS.getFieldName(), CommonUtils.splitToSet(operatingSystems)); + } + if (CommonUtils.isNotNullEmptyOrWhitespace(vendors)) { + filterMap.put(Component._Fields.VENDOR_NAMES.getFieldName(), CommonUtils.splitToSet(vendors)); + } + if (CommonUtils.isNotNullEmptyOrWhitespace(mainLicenses)) { + filterMap.put(Component._Fields.MAIN_LICENSE_IDS.getFieldName(), CommonUtils.splitToSet(mainLicenses)); + } + if (CommonUtils.isNotNullEmptyOrWhitespace(createdBy)) { + filterMap.put(Component._Fields.CREATED_BY.getFieldName(), CommonUtils.splitToSet(createdBy)); + } + if (CommonUtils.isNotNullEmptyOrWhitespace(createdOn)) { + filterMap.put(Component._Fields.CREATED_ON.getFieldName(), CommonUtils.splitToSet(createdOn)); + } + return filterMap; + } + + /** + * Create a filter predicate to remove all components which do not satisfy the restriction set. + * @param restrictions Restrictions set to filter components on + * @return Filter predicate for stream. + */ + private static @NonNull Predicate filterComponentMap(Map> restrictions) { + return component -> { + for (Map.Entry> restriction : restrictions.entrySet()) { + final Set filterSet = restriction.getValue(); + Component._Fields field = Component._Fields.findByName(restriction.getKey()); + Object fieldValue = component.getFieldValue(field); + if (fieldValue == null) { + return false; + } + if (field == Component._Fields.COMPONENT_TYPE && !filterSet.contains(component.componentType.name())) { + return false; + } else if ((field == Component._Fields.CREATED_BY || field == Component._Fields.CREATED_ON) + && !fieldValue.toString().equalsIgnoreCase(filterSet.iterator().next())) { + return false; + } else if (fieldValue instanceof Set) { + Set fieldValueSet = (Set) fieldValue; + fieldValueSet.retainAll(filterSet); + if (fieldValueSet.isEmpty()) { + return false; + } + } + } + return true; + }; + } } From d35afa4d2b97ef03db5ce60852aeccc321e06169 Mon Sep 17 00:00:00 2001 From: Gaurav Mishra Date: Thu, 19 Dec 2024 15:29:52 +0530 Subject: [PATCH 14/21] test(components): add test for component filter Add test cases for filtering components with more than 1 field. Signed-off-by: Gaurav Mishra --- .../src/docs/asciidoc/components.adoc | 20 +++++++++ .../component/ComponentController.java | 5 +-- .../restdocs/ComponentSpecTest.java | 41 +++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/rest/resource-server/src/docs/asciidoc/components.adoc b/rest/resource-server/src/docs/asciidoc/components.adoc index c7b8ec0473..a54ec75fd4 100644 --- a/rest/resource-server/src/docs/asciidoc/components.adoc +++ b/rest/resource-server/src/docs/asciidoc/components.adoc @@ -122,6 +122,26 @@ include::{snippets}/should_document_get_components_by_name/http-response.adoc[] include::{snippets}/should_document_get_components_by_name/links.adoc[] +[[resources-components-list-by-type-and-createdon]] +==== Filtering with more fields + +A `GET` request to fetch filtered list of service components. + +Note : send query parameter's value in encoded format. (Reference: `https://datatracker.ietf.org/doc/html/rfc3986`) + +===== Response structure +include::{snippets}/should_document_get_components_by_type_and_created_on/response-fields.adoc[] + +===== Example request +include::{snippets}/should_document_get_components_by_type_and_created_on/curl-request.adoc[] + +===== Example response +include::{snippets}/should_document_get_components_by_type_and_created_on/http-response.adoc[] + +===== Links +include::{snippets}/should_document_get_components_by_type_and_created_on/links.adoc[] + + [[resources-components-list-by-type]] ==== Listing by type diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java index d36bface86..b9e07f0892 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/component/ComponentController.java @@ -12,6 +12,7 @@ package org.eclipse.sw360.rest.resourceserver.component; +import com.google.common.collect.Sets; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.enums.ParameterIn; @@ -1163,9 +1164,7 @@ public ResponseEntity splitComponents( && !fieldValue.toString().equalsIgnoreCase(filterSet.iterator().next())) { return false; } else if (fieldValue instanceof Set) { - Set fieldValueSet = (Set) fieldValue; - fieldValueSet.retainAll(filterSet); - if (fieldValueSet.isEmpty()) { + if (Sets.intersection(filterSet, (Set) fieldValue).isEmpty()) { return false; } } diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ComponentSpecTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ComponentSpecTest.java index 4a7f7c5e96..1a6d439cb5 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ComponentSpecTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ComponentSpecTest.java @@ -911,6 +911,47 @@ public void should_document_get_components_by_name() throws Exception { ))); } + @Test + public void should_document_get_components_by_type_and_created_on() throws Exception { + mockMvc.perform(get("/api/components") + .header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword)) + .queryParam("componentType", angularComponent.getComponentType().toString()) + .queryParam("createdOn", angularComponent.getCreatedOn()) + .queryParam("categories", "javascript, sql") + .queryParam("luceneSearch", "false") + .queryParam("page", "0") + .queryParam("page_entries", "5") + .queryParam("sort", "name,desc") + .accept(MediaTypes.HAL_JSON)) + .andExpect(status().isOk()) + .andDo(this.documentationHandler.document( + queryParameters( + parameterWithName("componentType").description("Filter for type"), + parameterWithName("createdOn").description("Filter for component creation date"), + parameterWithName("categories").description("Filter for categories"), + parameterWithName("luceneSearch").description("Filter with exact match or lucene match."), + parameterWithName("page").description("Page of components"), + parameterWithName("page_entries").description("Amount of components per page"), + parameterWithName("sort").description("Defines order of the components") + ), + links( + linkWithRel("curies").description("Curies are used for online documentation"), + linkWithRel("first").description("Link to first page"), + linkWithRel("last").description("Link to last page") + ), + responseFields( + subsectionWithPath("_embedded.sw360:components.[]name").description("The name of the component"), + subsectionWithPath("_embedded.sw360:components.[]componentType").description("The component type, possible values are: " + Arrays.asList(ComponentType.values())), + subsectionWithPath("_embedded.sw360:components").description("An array of <>"), + subsectionWithPath("_links").description("<> to other resources"), + fieldWithPath("page").description("Additional paging information"), + fieldWithPath("page.size").description("Number of components per page"), + fieldWithPath("page.totalElements").description("Total number of all existing components"), + fieldWithPath("page.totalPages").description("Total number of pages"), + fieldWithPath("page.number").description("Number of the current page") + ))); + } + @Test public void should_document_update_component() throws Exception { ComponentDTO updateComponent = new ComponentDTO(); From 0043dec557d5feb1c4b2be33e050a328e9f1c953 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 02:45:50 +0000 Subject: [PATCH 15/21] chore(deps): bump com.squareup.okhttp3:okhttp from 4.10.0 to 4.12.0 Bumps [com.squareup.okhttp3:okhttp](https://github.com/square/okhttp) from 4.10.0 to 4.12.0. - [Changelog](https://github.com/square/okhttp/blob/master/CHANGELOG.md) - [Commits](https://github.com/square/okhttp/compare/parent-4.10.0...parent-4.12.0) --- updated-dependencies: - dependency-name: com.squareup.okhttp3:okhttp dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9e36b56d06..6c264ed307 100644 --- a/pom.xml +++ b/pom.xml @@ -137,7 +137,7 @@ 2.24.3 3.11.2 5.14.2 - 4.10.0 + 4.12.0 9.7.1 1.1.1 1.1.5 From c737350a99c6802437bd093baa9620d56ae9203e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 02:46:04 +0000 Subject: [PATCH 16/21] chore(deps): bump org.assertj:assertj-core from 3.26.3 to 3.27.0 Bumps [org.assertj:assertj-core](https://github.com/assertj/assertj) from 3.26.3 to 3.27.0. - [Release notes](https://github.com/assertj/assertj/releases) - [Commits](https://github.com/assertj/assertj/compare/assertj-build-3.26.3...assertj-build-3.27.0) --- updated-dependencies: - dependency-name: org.assertj:assertj-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c264ed307..b420a72681 100644 --- a/pom.xml +++ b/pom.xml @@ -95,7 +95,7 @@ 2.18.2 - 3.26.3 + 3.27.0 1.15.10 0.9.3 1.9.0 From b4e02713d92df6df683610658df7217735430789 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 02:46:09 +0000 Subject: [PATCH 17/21] chore(deps): bump com.google.guava:guava from 33.3.1-jre to 33.4.0-jre Bumps [com.google.guava:guava](https://github.com/google/guava) from 33.3.1-jre to 33.4.0-jre. - [Release notes](https://github.com/google/guava/releases) - [Commits](https://github.com/google/guava/commits) --- updated-dependencies: - dependency-name: com.google.guava:guava dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b420a72681..1582280e71 100644 --- a/pom.xml +++ b/pom.xml @@ -112,7 +112,7 @@ 1.0.2 1.3.9-1 4.0.5 - 33.3.1-jre + 33.4.0-jre 1.3 5.4.1 4.4.16 From fc812cc7c1fa309d61470622f3a9d2930ef8f8e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 03:14:55 +0000 Subject: [PATCH 18/21] chore(deps): bump github/codeql-action from 3.27.9 to 3.28.0 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.27.9 to 3.28.0. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/df409f7d9260372bd5f19e5b04e83cb3c43714ae...48ab28a6f5dbc2a99bf1e0131198dd8f1df78169) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/scorecard.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index b4d20d6f0a..1f94e2fc39 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -68,7 +68,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@df409f7d9260372bd5f19e5b04e83cb3c43714ae # v3.27.9 + uses: github/codeql-action/init@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0 with: languages: ${{ matrix.language }} build-mode: ${{ matrix.build-mode }} @@ -96,6 +96,6 @@ jobs: exit 1 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@df409f7d9260372bd5f19e5b04e83cb3c43714ae # v3.27.9 + uses: github/codeql-action/analyze@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index 586571256a..55e9057b73 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -55,6 +55,6 @@ jobs: retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@df409f7d9260372bd5f19e5b04e83cb3c43714ae # v3.27.9 + uses: github/codeql-action/upload-sarif@48ab28a6f5dbc2a99bf1e0131198dd8f1df78169 # v3.28.0 with: sarif_file: results.sarif From dfc187d9f609fa6644b8d5e38752c31236288d86 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 08:21:12 +0000 Subject: [PATCH 19/21] chore(deps-dev): bump net.bytebuddy:byte-buddy from 1.15.10 to 1.15.11 Bumps [net.bytebuddy:byte-buddy](https://github.com/raphw/byte-buddy) from 1.15.10 to 1.15.11. - [Release notes](https://github.com/raphw/byte-buddy/releases) - [Changelog](https://github.com/raphw/byte-buddy/blob/master/release-notes.md) - [Commits](https://github.com/raphw/byte-buddy/compare/byte-buddy-1.15.10...byte-buddy-1.15.11) --- updated-dependencies: - dependency-name: net.bytebuddy:byte-buddy dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1582280e71..94e4593598 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ 3.27.0 - 1.15.10 + 1.15.11 0.9.3 1.9.0 1.17.1 From 663ac83774c4c40c2817b898ff314e8f45043aeb Mon Sep 17 00:00:00 2001 From: nikesh kumar Date: Thu, 5 Dec 2024 13:18:21 +0530 Subject: [PATCH 20/21] fix(rest): Validate comment message while create a moderation request. Signed-off-by: Nikesh kumar --- .../src/docs/asciidoc/moderationRequests.adoc | 17 +++ .../core/RestControllerHelper.java | 6 + .../ModerationRequestController.java | 124 ++++++++++++++++++ .../restdocs/ModerationRequestSpecTest.java | 31 +++++ 4 files changed, 178 insertions(+) diff --git a/rest/resource-server/src/docs/asciidoc/moderationRequests.adoc b/rest/resource-server/src/docs/asciidoc/moderationRequests.adoc index 49ac1ede58..f8f8378a60 100644 --- a/rest/resource-server/src/docs/asciidoc/moderationRequests.adoc +++ b/rest/resource-server/src/docs/asciidoc/moderationRequests.adoc @@ -146,3 +146,20 @@ include::{snippets}/should_document_get_moderationrequests_submission/curl-reque ===== Example response include::{snippets}/should_document_get_moderationrequests_submission/http-response.adoc[] + +[[resources-moderationRequest-validate]] +==== Validate User And Message Moderation Requests + +A `POST` will validate the user and will check the comment message is present or not. + +===== Request parameter +include::{snippets}/should_document_check_user_message_moderationrequests/query-parameters.adoc[] + +===== Response structure +include::{snippets}/should_document_check_user_message_moderationrequests/response-fields.adoc[] + +===== Example request +include::{snippets}/should_document_check_user_message_moderationrequests/curl-request.adoc[] + +===== Example response +include::{snippets}/should_document_check_user_message_moderationrequests/http-response.adoc[] 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 4b3fd044ad..b50808fc02 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 @@ -54,6 +54,7 @@ import org.eclipse.sw360.datahandler.thrift.spdx.documentcreationinformation.*; import org.eclipse.sw360.datahandler.thrift.spdx.spdxdocument.SPDXDocument; import org.eclipse.sw360.datahandler.thrift.spdx.spdxpackageinfo.PackageInformation; +import org.eclipse.sw360.datahandler.thrift.users.RequestedAction; import org.eclipse.sw360.datahandler.thrift.users.User; import org.eclipse.sw360.datahandler.thrift.vendors.Vendor; import org.eclipse.sw360.datahandler.thrift.vulnerabilities.*; @@ -102,6 +103,7 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.servlet.support.ServletUriComponentsBuilder; import org.springframework.web.util.UriComponentsBuilder; +import static org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission; import jakarta.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; @@ -1687,4 +1689,8 @@ public ClearingRequest updateCRSize(ClearingRequest clearingRequest, Project pro } return clearingRequestService.getClearingRequestById(clearingRequest.getId(), sw360User); } + + public boolean isWriteActionAllowed(Object object, User user) { + return makePermission(object, user).isActionAllowed(RequestedAction.WRITE); + } } diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/moderationrequest/ModerationRequestController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/moderationrequest/ModerationRequestController.java index e3bba81d84..7eef857069 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/moderationrequest/ModerationRequestController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/moderationrequest/ModerationRequestController.java @@ -18,10 +18,13 @@ import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.SchemaProperty; import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.apache.thrift.TException; +import org.apache.thrift.transport.TTransportException; +import org.bouncycastle.util.test.TestFailedException; import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.common.SW360Constants; import org.eclipse.sw360.datahandler.resourcelists.PaginationParameterException; @@ -29,6 +32,7 @@ import org.eclipse.sw360.datahandler.resourcelists.ResourceClassNotFoundException; import org.eclipse.sw360.datahandler.thrift.ModerationState; import org.eclipse.sw360.datahandler.thrift.PaginationData; +import org.eclipse.sw360.datahandler.thrift.SW360Exception; import org.eclipse.sw360.datahandler.thrift.components.Component; import org.eclipse.sw360.datahandler.thrift.components.Release; import org.eclipse.sw360.datahandler.thrift.licenses.License; @@ -50,6 +54,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.rest.webmvc.BasePathAwareController; import org.springframework.data.rest.webmvc.RepositoryLinksResource; +import org.springframework.data.rest.webmvc.ResourceNotFoundException; import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.Link; @@ -57,8 +62,10 @@ import org.springframework.hateoas.server.RepresentationModelProcessor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.HttpClientErrorException; +import io.swagger.v3.oas.annotations.media.ExampleObject; import jakarta.servlet.http.HttpServletRequest; import com.fasterxml.jackson.annotation.JsonAutoDetect; @@ -495,4 +502,121 @@ private , F extends org.apache.thrift.TF setAddition.apply(addition); setDeletion.apply(deletion); } + + @PreAuthorize("hasAuthority('WRITE')") + @Operation( + summary = "Validate Moderation Request", + description = "This endpoint validates a user for a moderation request.", + tags = {"Moderation Requests"} + ) + @ApiResponses(value = { + @ApiResponse( + responseCode = "200", description = "Moderation request validated successfully.", + content = { + @Content(mediaType = "application/json", + examples = @ExampleObject( + value = "{\"message\": \"Moderation request validated successfully.\"}" + )) + } + ), + @ApiResponse( + responseCode = "202", + description = "Accepted - Moderation request is pending review.", + content = { + @Content(mediaType = "application/json", + examples = @ExampleObject( + value = "{\"message\": \"Moderation request is pending review.\"}" + )) + } + ), + @ApiResponse( + responseCode = "400", description = "Bad Request - Invalid input or missing parameters.", + content = { + @Content(mediaType = "application/json", + examples = @ExampleObject( + value = "{\"message\": \"Invalid input or missing required parameters.\"}" + )) + } + ), + @ApiResponse( + responseCode = "401", description = "Unauthorized - User does not have the required permissions.", + content = { + @Content(mediaType = "application/json", + examples = @ExampleObject( + value = "{\"message\": \"User is not authorized to perform this action.\"}" + )) + } + ), + @ApiResponse( + responseCode = "403", description = "Forbidden - Access denied.", + content = { + @Content(mediaType = "application/json", + examples = @ExampleObject( + value = "{\"message\": \"Access is denied due to insufficient permissions.\"}" + )) + } + ), + @ApiResponse( + responseCode = "500", description = "Internal Server Error.", + content = { + @Content(mediaType = "application/json", + examples = @ExampleObject( + value = "{\"message\": \"An unexpected error occurred while validating the moderation request.\"}" + )) + } + ) + }) + @RequestMapping(value = MODERATION_REQUEST_URL + "/validate", method = RequestMethod.POST) + public ResponseEntity validateModerationRequest( + @Parameter(description = "Project id.") + @RequestParam String entityType, + @Parameter(description = "Entity type", example = "Pass entity type like PROJECT/COMPONENT/RELEASE") + @RequestParam String entityId, + HttpServletRequest request) throws TException{ + + try { + User user = restControllerHelper.getSw360UserFromAuthentication(); + Object entity = getEntityByTypeAndId(entityType, entityId, user); + if (entity == null) { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body("Entity not found for the given ID: " + entityId); + } + boolean isWriteActionAllowed = restControllerHelper.isWriteActionAllowed(entity, user); + if (!isWriteActionAllowed) { + return ResponseEntity.status(HttpStatus.ACCEPTED).body( + "User allowed to perform write on entity.MR is required."); + } + return ResponseEntity.ok("User can write to the entity. MR is not required."); + } catch (SW360Exception ex) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Entity not found for the given ID: " + entityId); + } catch (IllegalArgumentException ex) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST) + .body("Invalid entity type provided: " + ex.getMessage()); + } catch (TException ex) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("An error occurred while processing the request: " + ex.getMessage()); + } + } + + /** + * Helper method to fetch entity by type and ID. + */ + private Object getEntityByTypeAndId(String entityType, String entityId, User user) throws TException { + try { + switch (entityType.toLowerCase()) { + case "project": + return projectService.getProjectForUserById(entityId, user); + case "component": + return componentService.getComponentForUserById(entityId, user); + case "release": + return releaseService.getReleaseForUserById(entityId, user); + default: + throw new IllegalArgumentException("Unsupported entity type: " + entityType); + } + } catch (TTransportException e) { + throw new RuntimeException("Unable to connect to the service. Please check the server status.", e); + } catch (TException e) { + throw e; + } + } } diff --git a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ModerationRequestSpecTest.java b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ModerationRequestSpecTest.java index 6e4fc441cf..d5dc8c14d0 100644 --- a/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ModerationRequestSpecTest.java +++ b/rest/resource-server/src/test/java/org/eclipse/sw360/rest/resourceserver/restdocs/ModerationRequestSpecTest.java @@ -29,6 +29,7 @@ import org.eclipse.sw360.rest.resourceserver.TestHelper; import org.eclipse.sw360.rest.resourceserver.moderationrequest.ModerationPatch; import org.eclipse.sw360.rest.resourceserver.moderationrequest.Sw360ModerationRequestService; +import org.eclipse.sw360.rest.resourceserver.project.Sw360ProjectService; import org.eclipse.sw360.rest.resourceserver.release.Sw360ReleaseService; import org.eclipse.sw360.rest.resourceserver.user.Sw360UserService; import org.junit.Before; @@ -40,6 +41,7 @@ import org.springframework.http.MediaType; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.web.servlet.MvcResult; import java.io.IOException; import java.util.ArrayList; @@ -50,12 +52,14 @@ import java.util.Map; import java.util.Set; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel; import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; @@ -81,6 +85,12 @@ public class ModerationRequestSpecTest extends TestRestDocsSpecBase { @MockBean private Sw360ModerationRequestService moderationRequestServiceMock; + @MockBean + private Sw360ProjectService projectServiceMock; + + @MockBean + private Project project; + @Before public void before() throws TException, IOException { Set moderatorList = new HashSet<>(); @@ -190,6 +200,7 @@ public void before() throws TException, IOException { user.setId("123456789"); user.setEmail(testUserId); user.setFullname("John Doe"); + user.setDepartment("xyz"); given(this.releaseServiceMock.getReleaseForUserById(eq(moderationRequest.getDocumentId()), any())).willReturn(releaseAdditions); given(this.userServiceMock.getUserByEmail(moderationRequest.getRequestingUser())).willReturn(new User("test.admin@sw360.org", "DEPT").setId("12345")); @@ -483,4 +494,24 @@ public void should_document_get_moderationrequests_submission() throws Exception subsectionWithPath("_links").description("<> to other resources") ))); } + + @Test + public void should_document_check_user_message_moderationrequests() throws Exception { + project = new Project(); + project.setId("98745"); + project.setName("Test Project"); + project.setProjectType(ProjectType.PRODUCT); + project.setVersion("1"); + project.setCreatedOn("2021-04-27"); + project.setCreatedBy("admin@sw360.org"); + given(this.projectServiceMock.getProjectForUserById(eq(project.getId()), any())).willReturn(project); + + this.mockMvc.perform(post("/api/moderationrequest/validate") + .param("entityType", "PROJECT") + .param("entityId", project.getId()) + .header("Authorization", TestHelper.generateAuthHeader(testUserId, testUserPassword)) + .accept(MediaTypes.HAL_JSON)) + .andExpect(status().isOk()) + .andReturn(); + } } From eeb3c86d4832aa797031e2cd7594d5dec3b488d4 Mon Sep 17 00:00:00 2001 From: Gaurav Mishra Date: Mon, 23 Dec 2024 14:22:17 +0530 Subject: [PATCH 21/21] fix(rest): fix doc for ModerationRequestController Signed-off-by: Gaurav Mishra --- .../ModerationRequestController.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/moderationrequest/ModerationRequestController.java b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/moderationrequest/ModerationRequestController.java index 7eef857069..b203c532b5 100644 --- a/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/moderationrequest/ModerationRequestController.java +++ b/rest/resource-server/src/main/java/org/eclipse/sw360/rest/resourceserver/moderationrequest/ModerationRequestController.java @@ -24,10 +24,8 @@ import lombok.RequiredArgsConstructor; import org.apache.thrift.TException; import org.apache.thrift.transport.TTransportException; -import org.bouncycastle.util.test.TestFailedException; import org.eclipse.sw360.datahandler.common.CommonUtils; import org.eclipse.sw360.datahandler.common.SW360Constants; -import org.eclipse.sw360.datahandler.resourcelists.PaginationParameterException; import org.eclipse.sw360.datahandler.resourcelists.PaginationResult; import org.eclipse.sw360.datahandler.resourcelists.ResourceClassNotFoundException; import org.eclipse.sw360.datahandler.thrift.ModerationState; @@ -54,7 +52,6 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.rest.webmvc.BasePathAwareController; import org.springframework.data.rest.webmvc.RepositoryLinksResource; -import org.springframework.data.rest.webmvc.ResourceNotFoundException; import org.springframework.hateoas.CollectionModel; import org.springframework.hateoas.EntityModel; import org.springframework.hateoas.Link; @@ -511,21 +508,21 @@ private , F extends org.apache.thrift.TF ) @ApiResponses(value = { @ApiResponse( - responseCode = "200", description = "Moderation request validated successfully.", + responseCode = "200", description = "Moderation request not required.", content = { @Content(mediaType = "application/json", examples = @ExampleObject( - value = "{\"message\": \"Moderation request validated successfully.\"}" + value = "{\"message\": \"User can write to the entity. MR is not required.\"}" )) } ), @ApiResponse( responseCode = "202", - description = "Accepted - Moderation request is pending review.", + description = "Moderation request will be required.", content = { @Content(mediaType = "application/json", examples = @ExampleObject( - value = "{\"message\": \"Moderation request is pending review.\"}" + value = "{\"message\": \"User allowed to perform write on entity. MR is required.\"}" )) } ), @@ -568,12 +565,12 @@ private , F extends org.apache.thrift.TF }) @RequestMapping(value = MODERATION_REQUEST_URL + "/validate", method = RequestMethod.POST) public ResponseEntity validateModerationRequest( - @Parameter(description = "Project id.") + @Parameter(description = "Entity type", example = "PROJECT", + schema = @Schema(allowableValues = {"PROJECT", "COMPONENT", "RELEASE"})) @RequestParam String entityType, - @Parameter(description = "Entity type", example = "Pass entity type like PROJECT/COMPONENT/RELEASE") - @RequestParam String entityId, - HttpServletRequest request) throws TException{ - + @Parameter(description = "Entity id.") + @RequestParam String entityId + ) { try { User user = restControllerHelper.getSw360UserFromAuthentication(); Object entity = getEntityByTypeAndId(entityType, entityId, user); @@ -584,7 +581,7 @@ public ResponseEntity validateModerationRequest( boolean isWriteActionAllowed = restControllerHelper.isWriteActionAllowed(entity, user); if (!isWriteActionAllowed) { return ResponseEntity.status(HttpStatus.ACCEPTED).body( - "User allowed to perform write on entity.MR is required."); + "User allowed to perform write on entity. MR is required."); } return ResponseEntity.ok("User can write to the entity. MR is not required."); } catch (SW360Exception ex) { @@ -615,8 +612,6 @@ private Object getEntityByTypeAndId(String entityType, String entityId, User use } } catch (TTransportException e) { throw new RuntimeException("Unable to connect to the service. Please check the server status.", e); - } catch (TException e) { - throw e; } } }