diff --git a/DEPENDENCIES b/DEPENDENCIES index dae28405c..e09353693 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -1,11 +1,8 @@ maven/mavencentral/ch.qos.logback/logback-classic/1.4.11, EPL-1.0 OR LGPL-2.1-only, approved, #3435 maven/mavencentral/ch.qos.logback/logback-core/1.4.11, EPL-1.0 OR LGPL-2.1-only, approved, #3373 -maven/mavencentral/com.carrotsearch/hppc/0.8.1, Apache-2.0, approved, CQ22339 maven/mavencentral/com.fasterxml.jackson.core/jackson-annotations/2.15.3, Apache-2.0, approved, #7947 maven/mavencentral/com.fasterxml.jackson.core/jackson-core/2.15.3, MIT AND Apache-2.0, approved, #7932 maven/mavencentral/com.fasterxml.jackson.core/jackson-databind/2.15.3, Apache-2.0, approved, #7934 -maven/mavencentral/com.fasterxml.jackson.dataformat/jackson-dataformat-cbor/2.15.3, Apache-2.0, approved, #10053 -maven/mavencentral/com.fasterxml.jackson.dataformat/jackson-dataformat-smile/2.15.3, Apache-2.0, approved, #10052 maven/mavencentral/com.fasterxml.jackson.dataformat/jackson-dataformat-toml/2.15.3, Apache-2.0, approved, #9160 maven/mavencentral/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml/2.15.3, Apache-2.0, approved, #8802 maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/2.15.3, Apache-2.0, approved, #8808 @@ -13,18 +10,13 @@ maven/mavencentral/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.15.3 maven/mavencentral/com.fasterxml.jackson.module/jackson-module-kotlin/2.15.3, Apache-2.0, approved, #10051 maven/mavencentral/com.fasterxml.jackson.module/jackson-module-parameter-names/2.15.3, Apache-2.0, approved, #8803 maven/mavencentral/com.fasterxml/classmate/1.5.1, Apache-2.0, approved, clearlydefined -maven/mavencentral/com.github.spullara.mustache.java/compiler/0.9.10, Apache-2.0, approved, CQ14417 maven/mavencentral/com.github.stephenc.jcip/jcip-annotations/1.0-1, Apache-2.0, approved, CQ21949 -maven/mavencentral/com.google.code.findbugs/jsr305/3.0.2, Apache-2.0, approved, #20 maven/mavencentral/com.neovisionaries/nv-i18n/1.29, Apache-2.0, approved, clearlydefined maven/mavencentral/com.nimbusds/content-type/2.2, Apache-2.0, approved, clearlydefined maven/mavencentral/com.nimbusds/lang-tag/1.7, Apache-2.0, approved, clearlydefined maven/mavencentral/com.nimbusds/nimbus-jose-jwt/9.24.4, Apache-2.0, approved, clearlydefined maven/mavencentral/com.nimbusds/oauth2-oidc-sdk/9.43.3, Apache-2.0, approved, clearlydefined -maven/mavencentral/com.tdunning/t-digest/3.2, Apache-2.0, approved, clearlydefined maven/mavencentral/com.zaxxer/HikariCP/5.0.1, Apache-2.0, approved, clearlydefined -maven/mavencentral/commons-codec/commons-codec/1.15, Apache-2.0 AND BSD-3-Clause AND LicenseRef-Public-Domain, approved, CQ22641 -maven/mavencentral/commons-logging/commons-logging/1.2, Apache-2.0, approved, CQ10162 maven/mavencentral/io.github.classgraph/classgraph/4.8.149, MIT, approved, CQ22530 maven/mavencentral/io.github.microutils/kotlin-logging-jvm/2.1.23, Apache-2.0, approved, clearlydefined maven/mavencentral/io.micrometer/micrometer-commons/1.11.5, Apache-2.0 AND (Apache-2.0 AND MIT), approved, #9243 @@ -55,53 +47,28 @@ maven/mavencentral/io.swagger.core.v3/swagger-core-jakarta/2.2.7, Apache-2.0, ap maven/mavencentral/io.swagger.core.v3/swagger-models-jakarta/2.2.7, Apache-2.0, approved, #5919 maven/mavencentral/jakarta.activation/jakarta.activation-api/2.1.2, EPL-2.0 OR BSD-3-Clause OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.jaf maven/mavencentral/jakarta.annotation/jakarta.annotation-api/2.1.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.ca -maven/mavencentral/jakarta.json/jakarta.json-api/2.1.2, EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #7907 maven/mavencentral/jakarta.persistence/jakarta.persistence-api/3.1.0, EPL-2.0 OR BSD-3-Clause AND (EPL-2.0 OR BSD-3-Clause AND BSD-3-Clause), approved, #7696 maven/mavencentral/jakarta.transaction/jakarta.transaction-api/2.0.1, EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0, approved, #7697 maven/mavencentral/jakarta.validation/jakarta.validation-api/3.0.2, Apache-2.0, approved, ee4j.validation maven/mavencentral/jakarta.xml.bind/jakarta.xml.bind-api/4.0.1, BSD-3-Clause, approved, ee4j.jaxb -maven/mavencentral/joda-time/joda-time/2.10.12, Apache-2.0, approved, clearlydefined -maven/mavencentral/net.java.dev.jna/jna/5.5.0, Apache-2.0 or LGPL-2.1, approved, #1508 maven/mavencentral/net.minidev/accessors-smart/2.4.11, Apache-2.0, approved, #7515 maven/mavencentral/net.minidev/json-smart/2.4.11, Apache-2.0, approved, #3288 -maven/mavencentral/net.sf.jopt-simple/jopt-simple/5.0.4, MIT, approved, CQ13174 maven/mavencentral/org.antlr/antlr4-runtime/4.10.1, BSD-3-Clause AND LicenseRef-Public-domain AND MIT AND LicenseRef-Unicode-TOU, approved, #7065 maven/mavencentral/org.apache.commons/commons-csv/1.10.0, Apache-2.0, approved, clearlydefined maven/mavencentral/org.apache.commons/commons-lang3/3.12.0, Apache-2.0, approved, clearlydefined maven/mavencentral/org.apache.commons/commons-text/1.10.0, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.apache.httpcomponents/httpasyncclient/4.1.5, Apache-2.0, approved, CQ13506 -maven/mavencentral/org.apache.httpcomponents/httpclient/4.5.13, Apache-2.0 AND LicenseRef-Public-Domain, approved, CQ23527 -maven/mavencentral/org.apache.httpcomponents/httpcore-nio/4.4.16, Apache-2.0, approved, CQ13509 -maven/mavencentral/org.apache.httpcomponents/httpcore/4.4.16, Apache-2.0, approved, CQ23528 maven/mavencentral/org.apache.logging.log4j/log4j-api/2.20.0, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.apache.logging.log4j/log4j-jul/2.20.0, Apache-2.0, approved, clearlydefined maven/mavencentral/org.apache.logging.log4j/log4j-to-slf4j/2.20.0, Apache-2.0, approved, #8799 -maven/mavencentral/org.apache.lucene/lucene-analysis-common/9.4.2, Apache-2.0 AND BSD-3-Clause, approved, #5636 -maven/mavencentral/org.apache.lucene/lucene-backward-codecs/9.4.2, Apache-2.0, approved, #4394 -maven/mavencentral/org.apache.lucene/lucene-core/9.4.2, Apache-2.0 AND BSD-3-Clause AND NCSA AND ISC AND LicenseRef-scancode-sunpro AND ICU AND LicenseRef-scancode-unicode-mappings AND MIT AND BSD-2-Clause, approved, #5635 -maven/mavencentral/org.apache.lucene/lucene-grouping/9.4.2, Apache-2.0, approved, #7005 -maven/mavencentral/org.apache.lucene/lucene-highlighter/9.4.2, Apache-2.0, approved, #6968 -maven/mavencentral/org.apache.lucene/lucene-join/9.4.2, Apache-2.0, approved, #6985 -maven/mavencentral/org.apache.lucene/lucene-memory/9.4.2, Apache-2.0, approved, #7007 -maven/mavencentral/org.apache.lucene/lucene-misc/9.4.2, Apache-2.0, approved, #6992 -maven/mavencentral/org.apache.lucene/lucene-queries/9.4.2, Apache-2.0, approved, #4386 -maven/mavencentral/org.apache.lucene/lucene-queryparser/9.4.2, Apache-2.0, approved, #4373 -maven/mavencentral/org.apache.lucene/lucene-sandbox/9.4.2, Apache-2.0, approved, #4369 -maven/mavencentral/org.apache.lucene/lucene-spatial-extras/9.4.2, Apache-2.0, approved, #6991 -maven/mavencentral/org.apache.lucene/lucene-spatial3d/9.4.2, Apache-2.0, approved, #6975 -maven/mavencentral/org.apache.lucene/lucene-suggest/9.4.2, Apache-2.0, approved, #6970 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-core/10.1.15, Apache-2.0 AND (EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0) AND (CDDL-1.0 OR GPL-2.0-only WITH Classpath-exception-2.0) AND W3C AND CC0-1.0, approved, #5949 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-el/10.1.15, Apache-2.0, approved, #6997 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-websocket/10.1.15, Apache-2.0, approved, #7920 maven/mavencentral/org.aspectj/aspectjweaver/1.9.20, EPL-1.0, approved, tools.aspectj -maven/mavencentral/org.eclipse.parsson/parsson/1.0.0, EPL-2.0, approved, ee4j.parsson maven/mavencentral/org.eclipse.tractusx/bpdm-common/4.1.0-SNAPSHOT, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx/bpdm-gate-api/4.1.0-SNAPSHOT, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx/bpdm-orchestrator-api/4.1.0-SNAPSHOT, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx/bpdm-orchestrator/4.1.0-SNAPSHOT, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.eclipse.tractusx/bpdm-pool-api/4.1.0-SNAPSHOT, Apache-2.0, approved, automotive.tractusx maven/mavencentral/org.flywaydb/flyway-core/9.16.3, Apache-2.0, approved, #7935 -maven/mavencentral/org.hdrhistogram/HdrHistogram/2.1.12, BSD-2-Clause OR LicenseRef-Public-Domain, approved, CQ13192 maven/mavencentral/org.hibernate.orm/hibernate-core/6.2.13.Final, LGPL-2.1-only AND Apache-2.0 AND MIT AND CC-PDDC AND (EPL-2.0 OR BSD-3-Clause), approved, #9121 maven/mavencentral/org.hibernate.validator/hibernate-validator/8.0.1.Final, Apache-2.0, approved, clearlydefined maven/mavencentral/org.jboss.logging/jboss-logging/3.5.3.Final, Apache-2.0, approved, #9471 @@ -111,20 +78,6 @@ maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.7.21, Apache-2.0, a maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.7.21, Apache-2.0, approved, clearlydefined maven/mavencentral/org.jetbrains.kotlin/kotlin-stdlib/1.7.21, Apache-2.0, approved, clearlydefined maven/mavencentral/org.jetbrains/annotations/13.0, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.opensearch.client/opensearch-java/2.0.0, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.opensearch.client/opensearch-rest-client/2.5.0, Apache-2.0, approved, #6995 -maven/mavencentral/org.opensearch.client/opensearch-rest-high-level-client/2.5.0, Apache-2.0, approved, #6984 -maven/mavencentral/org.opensearch.plugin/aggs-matrix-stats-client/2.5.0, Apache-2.0, approved, #6988 -maven/mavencentral/org.opensearch.plugin/lang-mustache-client/2.5.0, Apache-2.0, approved, #6978 -maven/mavencentral/org.opensearch.plugin/mapper-extras-client/2.5.0, Apache-2.0, approved, #7000 -maven/mavencentral/org.opensearch.plugin/parent-join-client/2.5.0, Apache-2.0, approved, #6969 -maven/mavencentral/org.opensearch.plugin/rank-eval-client/2.5.0, Apache-2.0, approved, #6993 -maven/mavencentral/org.opensearch/opensearch-cli/2.5.0, Apache-2.0, approved, #7002 -maven/mavencentral/org.opensearch/opensearch-core/2.5.0, Apache-2.0, approved, #6998 -maven/mavencentral/org.opensearch/opensearch-geo/2.5.0, Apache-2.0, approved, #6994 -maven/mavencentral/org.opensearch/opensearch-secure-sm/2.5.0, Apache-2.0, approved, #6990 -maven/mavencentral/org.opensearch/opensearch-x-content/2.5.0, Apache-2.0, approved, #6980 -maven/mavencentral/org.opensearch/opensearch/2.5.0, Apache-2.0, approved, #6996 maven/mavencentral/org.ow2.asm/asm/9.3, BSD-3-Clause, approved, clearlydefined maven/mavencentral/org.reactivestreams/reactive-streams/1.0.4, CC0-1.0, approved, CQ16332 maven/mavencentral/org.slf4j/jul-to-slf4j/2.0.9, MIT, approved, #7698 diff --git a/INSTALL.md b/INSTALL.md index aef4dcac9..53337704f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -20,7 +20,8 @@ Then depending on which module you want to start go to the module subfolder you * Docker and Docker Compose * Keycloak 17.0.0 (with enabled `auth` profile) -When running, the project requires a PostgreSQL database and an OpenSearch instance to be available to connect to. You can set up these dependencies manually, or you can use the provided `docker-compose` file which will start the necessary dependencies for you. +When running, the project requires a PostgreSQL database instance to be available to connect to. You can set up these dependencies manually, or you can use the +provided `docker-compose` file which will start the necessary dependencies for you. To use Docker Compose, navigate to the project directory and run the following command: @@ -29,7 +30,6 @@ docker-compose up ``` Per default configuration the application expects postgres to run on `localhost` on port `5432`. -Opensearch needs to run on `localhost` on port `9200` on default. You can find and edit the default configuration for the Pool in the `application.properties`, `application-auth.properties` files in the `resources` folder. @@ -40,7 +40,7 @@ The REST API documentation can be accessed at = GenericContainer(IMAGE) - .dependsOn(listOf(postgreSQLContainer, openSearchContainer, bpdmPoolContainer)) + .dependsOn(listOf(postgreSQLContainer, bpdmPoolContainer)) .withNetwork(postgreSQLContainer.getNetwork()) .withExposedPorts(BPDM_PORT, DEBUG_PORT) .withEnv( diff --git a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/BpdmPoolContextInitializer.kt b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/BpdmPoolContextInitializer.kt index e19df2cfd..58eff1144 100644 --- a/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/BpdmPoolContextInitializer.kt +++ b/bpdm-bridge-dummy/src/test/kotlin/com/catenax/bpdm/bridge/dummy/util/BpdmPoolContextInitializer.kt @@ -20,7 +20,6 @@ package com.catenax.bpdm.bridge.dummy.util -import com.catenax.bpdm.bridge.dummy.util.OpenSearchContextInitializer.Companion.openSearchContainer import com.catenax.bpdm.bridge.dummy.util.PostgreSQLContextInitializer.Companion.postgreSQLContainer import mu.KotlinLogging import org.springframework.boot.test.util.TestPropertyValues @@ -48,8 +47,8 @@ class BpdmPoolContextInitializer : ApplicationContextInitializer = GenericContainer(IMAGE) - .dependsOn(listOf(postgreSQLContainer, openSearchContainer)) - .withNetwork(postgreSQLContainer.getNetwork()) + .dependsOn(listOf(postgreSQLContainer)) + .withNetwork(postgreSQLContainer.network) .withExposedPorts(BPDM_PORT, DEBUG_PORT) .withEnv( "JAVA_OPTIONS", @@ -60,7 +59,6 @@ class BpdmPoolContextInitializer : ApplicationContextInitializer { - companion object { - const val OPENSEARCH_CONTAINER_STARTUP_TIMEOUT_SEC = 270L - const val OPENSEARCH_PORT = 9200 - - val openSearchContainer: GenericContainer<*> = GenericContainer("opensearchproject/opensearch:2.1.0") - .withExposedPorts(OPENSEARCH_PORT) - .waitingFor(HttpWaitStrategy() - .forPort(OPENSEARCH_PORT) - .forStatusCodeMatching { response -> response == 200 || response == 401 } - .withStartupTimeout(Duration.ofSeconds(OPENSEARCH_CONTAINER_STARTUP_TIMEOUT_SEC)) - ) - // based on sample docker-compose for development from https://opensearch.org/docs/latest/opensearch/install/docker - .withEnv("cluster.name", "cdqbridge") - .withEnv("node.name", "bpdm-opensearch") - .withEnv("bootstrap.memory_lock", "true") - .withEnv("OPENSEARCH_JAVA_OPTS", "-Xms512m -Xmx512m") - .withEnv("DISABLE_INSTALL_DEMO_CONFIG", "true") - .withEnv("DISABLE_SECURITY_PLUGIN", "true") - .withEnv("discovery.type", "single-node") - .withCreateContainerCmdModifier { cmd -> - cmd.hostConfig!!.withUlimits(arrayOf(Ulimit("nofile", 65536L, 65536L), Ulimit("memlock", -1L, -1L))) - } - .withNetwork(postgreSQLContainer.getNetwork()) - .dependsOn(listOf(postgreSQLContainer)) - } - - override fun initialize(applicationContext: ConfigurableApplicationContext) { - val openSearchAlias = applicationContext.environment.getProperty("bpdm.opensearch.alias") - openSearchContainer.withNetworkAliases(openSearchAlias) - openSearchContainer.start() - TestPropertyValues.of( - "bpdm.opensearch.host=${openSearchContainer.host}", - "bpdm.opensearch.port=${openSearchContainer.getMappedPort(OPENSEARCH_PORT)}", - "bpdm.opensearch.scheme=http", - ).applyTo(applicationContext.environment) - } -} \ No newline at end of file diff --git a/bpdm-bridge-dummy/src/test/resources/application-test.properties b/bpdm-bridge-dummy/src/test/resources/application-test.properties index 56d62217b..659711384 100644 --- a/bpdm-bridge-dummy/src/test/resources/application-test.properties +++ b/bpdm-bridge-dummy/src/test/resources/application-test.properties @@ -16,8 +16,6 @@ # # SPDX-License-Identifier: Apache-2.0 ################################################################################ -bpdm.opensearch.refresh-on-write=true -bpdm.opensearch.alias=bpdm-opensearch bpdm.datasource.alias=bpdm-postgres bpdm.pool.alias=bpdm-pool logging.level.root=INFO diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolAddressApi.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolAddressApi.kt index 36481f24e..18fd5291b 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolAddressApi.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolAddressApi.kt @@ -31,7 +31,9 @@ import org.eclipse.tractusx.bpdm.common.dto.response.PageDto import org.eclipse.tractusx.bpdm.pool.api.model.request.AddressPartnerCreateRequest import org.eclipse.tractusx.bpdm.pool.api.model.request.AddressPartnerSearchRequest import org.eclipse.tractusx.bpdm.pool.api.model.request.AddressPartnerUpdateRequest -import org.eclipse.tractusx.bpdm.pool.api.model.response.* +import org.eclipse.tractusx.bpdm.pool.api.model.response.AddressMatchVerboseDto +import org.eclipse.tractusx.bpdm.pool.api.model.response.AddressPartnerCreateResponseWrapper +import org.eclipse.tractusx.bpdm.pool.api.model.response.AddressPartnerUpdateResponseWrapper import org.springdoc.core.annotations.ParameterObject import org.springframework.http.MediaType import org.springframework.web.bind.annotation.* @@ -49,8 +51,7 @@ interface PoolAddressApi { summary = "Returns addresses by different search parameters", description = "This endpoint tries to find matches among all existing business partners of type address, " + "filtering out partners which entirely do not match and ranking the remaining partners according to the accuracy of the match. " + - "The match of a partner is better the higher its relevancy score. " + - "Note that when using search parameters the max page is \${bpdm.opensearch.max-page}." + "The match of a partner is better the higher its relevancy score. " ) @ApiResponses( value = [ diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolLegalEntityApi.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolLegalEntityApi.kt index ee5dad93e..c3f4e4299 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolLegalEntityApi.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolLegalEntityApi.kt @@ -27,9 +27,17 @@ import io.swagger.v3.oas.annotations.media.Schema import io.swagger.v3.oas.annotations.responses.ApiResponse import io.swagger.v3.oas.annotations.responses.ApiResponses import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest -import org.eclipse.tractusx.bpdm.common.dto.response.* -import org.eclipse.tractusx.bpdm.pool.api.model.request.* -import org.eclipse.tractusx.bpdm.pool.api.model.response.* +import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressVerboseDto +import org.eclipse.tractusx.bpdm.common.dto.response.PageDto +import org.eclipse.tractusx.bpdm.common.dto.response.PoolLegalEntityVerboseDto +import org.eclipse.tractusx.bpdm.common.dto.response.SiteVerboseDto +import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPartnerCreateRequest +import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPartnerUpdateRequest +import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPropertiesSearchRequest +import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalAddressVerboseDto +import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityMatchVerboseDto +import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityPartnerCreateResponseWrapper +import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityPartnerUpdateResponseWrapper import org.springdoc.core.annotations.ParameterObject import org.springframework.http.MediaType import org.springframework.http.ResponseEntity @@ -47,8 +55,7 @@ interface PoolLegalEntityApi { summary = "Returns legal entities by different search parameters", description = "This endpoint tries to find matches among all existing business partners of type legal entity, " + "filtering out partners which entirely do not match and ranking the remaining partners according to the accuracy of the match. " + - "The match of a partner is better the higher its relevancy score. " + - "Note that when using search parameters the max page is \${bpdm.opensearch.max-page}." + "The match of a partner is better the higher its relevancy score. " ) @ApiResponses( value = [ diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolOpenSearchApi.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolOpenSearchApi.kt deleted file mode 100644 index 124f40618..000000000 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolOpenSearchApi.kt +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.api - - -import io.swagger.v3.oas.annotations.Operation -import io.swagger.v3.oas.annotations.media.Content -import io.swagger.v3.oas.annotations.responses.ApiResponse -import io.swagger.v3.oas.annotations.responses.ApiResponses -import org.eclipse.tractusx.bpdm.pool.api.model.response.SyncDto -import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.DeleteMapping -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.service.annotation.DeleteExchange -import org.springframework.web.service.annotation.GetExchange -import org.springframework.web.service.annotation.HttpExchange -import org.springframework.web.service.annotation.PostExchange - - -@RequestMapping("/api/opensearch", produces = [MediaType.APPLICATION_JSON_VALUE]) -@HttpExchange("/api/opensearch") -interface PoolOpenSearchApi { - - @Operation( - summary = "Index new business partner records on OpenSearch", - description = "Triggers an asynchronous export of business partner records from BPDM to OpenSearch. " + - "Only exports records which have been updated since the last export. " - ) - @ApiResponses( - value = [ - ApiResponse(responseCode = "200", description = "Export of records successfully"), - ApiResponse(responseCode = "500", description = "Export failed (no connection to OpenSearch or database)", content = [Content()]) - ] - ) - @PostMapping("/business-partner") - @PostExchange("/business-partner") - fun export(): SyncDto - - @Operation( - summary = "Fetch information about the latest OpenSearch export", - description = "Fetch information about the latest export (either ongoing or already finished)" - ) - @ApiResponses( - value = [ - ApiResponse(responseCode = "200", description = "Export information found"), - ApiResponse(responseCode = "500", description = "Fetching failed (no connection to database)", content = [Content()]) - ] - ) - @GetMapping("/business-partner") - @GetExchange("/business-partner") - fun getBusinessPartners(): SyncDto - - - @Operation( - summary = "Clear business partner index on OpenSearch", - description = "Deletes all business partner records in the OpenSearch index. " + - "Also resets the timestamp from the last export." - ) - @ApiResponses( - value = [ - ApiResponse(responseCode = "200", description = "Index successfully cleared"), - ApiResponse(responseCode = "500", description = "Clearing failed (no connection to OpenSearch or database)", content = [Content()]) - ] - ) - @DeleteMapping("/business-partner") - @DeleteExchange("/business-partner") - fun clear() -} \ No newline at end of file diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolSiteApi.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolSiteApi.kt index 21380d0a6..2a169d2e8 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolSiteApi.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/PoolSiteApi.kt @@ -134,8 +134,7 @@ interface PoolSiteApi { @Operation( summary = "Get page of sites matching the pagination search criteria", - description = "This endpoint retrieves all existing business partners of type sites." + - "Note that when using search parameters the max page is \${bpdm.opensearch.max-page}." + description = "This endpoint retrieves all existing business partners of type sites." ) @ApiResponses( value = [ diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/client/PoolApiClient.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/client/PoolApiClient.kt index 133de5c1a..0886e8b55 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/client/PoolApiClient.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/client/PoolApiClient.kt @@ -35,7 +35,5 @@ interface PoolApiClient { val sites: PoolSiteApi - val opensearch: PoolOpenSearchApi - val saas: PoolSaasApi } diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/client/PoolClientImpl.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/client/PoolClientImpl.kt index 4c6101a8e..5b586c194 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/client/PoolClientImpl.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/client/PoolClientImpl.kt @@ -56,8 +56,6 @@ class PoolClientImpl( override val sites by lazy { createClient() } - override val opensearch by lazy { createClient() } - override val saas by lazy { createClient() } private inline fun createClient() = diff --git a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/SyncType.kt b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/SyncType.kt index d6710830d..0d8454020 100644 --- a/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/SyncType.kt +++ b/bpdm-pool-api/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/api/model/SyncType.kt @@ -20,6 +20,5 @@ package org.eclipse.tractusx.bpdm.pool.api.model enum class SyncType{ - OPENSEARCH, SAAS_IMPORT } \ No newline at end of file diff --git a/bpdm-pool/pom.xml b/bpdm-pool/pom.xml index 610fd2de4..c08a1a473 100644 --- a/bpdm-pool/pom.xml +++ b/bpdm-pool/pom.xml @@ -55,10 +55,6 @@ org.jetbrains.kotlin kotlin-reflect - - org.opensearch.client - opensearch-rest-high-level-client - org.springframework.boot spring-boot-starter-web @@ -109,14 +105,6 @@ io.github.microutils kotlin-logging-jvm - - org.opensearch.client - opensearch-rest-client - - - org.opensearch.client - opensearch-java - com.fasterxml.jackson.module jackson-module-kotlin diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/OpenSearchImplConfig.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/OpenSearchImplConfig.kt deleted file mode 100644 index 0c4556888..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/OpenSearchImplConfig.kt +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl - -import jakarta.annotation.PostConstruct -import mu.KotlinLogging -import org.springframework.context.annotation.ComponentScan -import org.springframework.context.annotation.Configuration -import org.springframework.scheduling.annotation.EnableAsync - -@Configuration -@ComponentScan -@EnableAsync -class OpenSearchImplConfig { - private val logger = KotlinLogging.logger { } - - @PostConstruct - fun logCreation() { - logger.info { "Enable and configure OpenSearch connection" } - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/config/OpenSearchClientConfig.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/config/OpenSearchClientConfig.kt deleted file mode 100644 index 7da3f8b5f..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/config/OpenSearchClientConfig.kt +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.config - -import org.apache.http.HttpHost -import org.eclipse.tractusx.bpdm.pool.config.OpenSearchConfigProperties -import org.opensearch.client.RestClient -import org.opensearch.client.RestClientBuilder -import org.opensearch.client.RestHighLevelClient -import org.opensearch.client.json.jackson.JacksonJsonpMapper -import org.opensearch.client.opensearch.OpenSearchClient -import org.opensearch.client.transport.OpenSearchTransport -import org.opensearch.client.transport.rest_client.RestClientTransport -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration - -/** - * Configures both the OpenSearch "High Level Rest Client" and "Java API Client", which are two alternative clients for accessing OpenSearch. - */ -@Configuration -class OpenSearchClientConfig( - private val openSearchConfigProperties: OpenSearchConfigProperties -) { - - /** - * Provides an OpenSearch Java API Client. - * The client shares the same Low Level Rest Client as the [RestHighLevelClient], which is recommended in the elastic search documentation when using both clients. - */ - @Bean - fun openSearchClient(restHighLevelClient: RestHighLevelClient): OpenSearchClient { - val transport: OpenSearchTransport = RestClientTransport(restHighLevelClient.lowLevelClient, JacksonJsonpMapper()) - return OpenSearchClient(transport) - } - - /** - * Provides the High Level Rest Client. - */ - @Bean - fun openSearchHighLevelRestClient(): RestHighLevelClient { - val restClientBuilder: RestClientBuilder = - RestClient.builder(HttpHost(openSearchConfigProperties.host, openSearchConfigProperties.port, openSearchConfigProperties.scheme)) - return RestHighLevelClient(restClientBuilder) - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/controller/OpenSearchController.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/controller/OpenSearchController.kt deleted file mode 100644 index f7475a587..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/controller/OpenSearchController.kt +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.controller - - -import org.eclipse.tractusx.bpdm.pool.api.PoolOpenSearchApi -import org.eclipse.tractusx.bpdm.pool.api.model.response.SyncDto -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service.OpenSearchSyncStarterService -import org.springframework.security.access.prepost.PreAuthorize -import org.springframework.web.bind.annotation.RestController - -@RestController -class OpenSearchController( - val openSearchSyncService: OpenSearchSyncStarterService -) : PoolOpenSearchApi { - - @PreAuthorize("hasAuthority(@poolSecurityConfigProperties.getManageOpensearchAsRole())") - override fun export(): SyncDto { - return openSearchSyncService.exportAsync() - } - - @PreAuthorize("hasAuthority(@poolSecurityConfigProperties.getManageOpensearchAsRole())") - override fun getBusinessPartners(): SyncDto { - return openSearchSyncService.getExportStatus() - } - - @PreAuthorize("hasAuthority(@poolSecurityConfigProperties.getManageOpensearchAsRole())") - override fun clear() { - openSearchSyncService.clearOpenSearch() - } -} diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/AddressDoc.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/AddressDoc.kt deleted file mode 100644 index 2257e3ca8..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/AddressDoc.kt +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc - -data class AddressDoc( - val administrativeAreas: Collection, - val postCodes: Collection, - val localities: Collection, - val thoroughfares: Collection, - val premises: Collection, - val postalDeliveryPoints: Collection -) diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/AddressPartnerDoc.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/AddressPartnerDoc.kt deleted file mode 100644 index 7926ca6d1..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/AddressPartnerDoc.kt +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc - -import com.fasterxml.jackson.annotation.JsonIgnore - -const val ADDRESS_PARTNER_INDEX_NAME = "address-partners" -const val MAPPINGS_FILE_PATH_ADDRESSES = "opensearch/index-mappings-addresses.json" - -data class AddressPartnerDoc( - @JsonIgnore // ignore since this is the id and does not need to be in the document source - val bpn: String, - val name: Collection -) - diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/LegalEntityDoc.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/LegalEntityDoc.kt deleted file mode 100644 index 073058e48..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/LegalEntityDoc.kt +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc - -import com.fasterxml.jackson.annotation.JsonIgnore - -const val LEGAL_ENTITIES_INDEX_NAME = "legal-entities" -const val MAPPINGS_FILE_PATH_LEGAL_ENTITIES = "opensearch/index-mappings-legal-entities.json" - -data class LegalEntityDoc( - @JsonIgnore // ignore since this is the id and does not need to be in the document source - val bpn: String, - val legalName: TextDoc, - val legalForm: TextDoc?, - val status: TextDoc?, - val addresses: Collection, - val classifications: Collection, - val sites: Collection -) diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/TextDoc.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/TextDoc.kt deleted file mode 100644 index 3e5902d97..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/doc/TextDoc.kt +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc - -data class TextDoc( - val text: String -) diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/AddressDocSearchRepository.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/AddressDocSearchRepository.kt deleted file mode 100644 index 5fe1afcab..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/AddressDocSearchRepository.kt +++ /dev/null @@ -1,112 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.repository - -import mu.KotlinLogging -import org.eclipse.tractusx.bpdm.pool.api.model.request.AddressPartnerSearchRequest -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.ADDRESS_PARTNER_INDEX_NAME -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.AddressPartnerDoc -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.util.BpdmOpenSearchQueryBuilder -import org.opensearch.action.search.SearchRequest -import org.opensearch.client.RequestOptions -import org.opensearch.client.RestHighLevelClient -import org.opensearch.index.query.QueryBuilders -import org.opensearch.search.SearchHits -import org.opensearch.search.builder.SearchSourceBuilder -import org.springframework.data.domain.Pageable -import org.springframework.stereotype.Repository - -/** - * Creates and executes OpenSearch queries for querying [AddressPartnerDoc] entries - */ -@Repository -class AddressDocSearchRepository( - val restHighLevelClient: RestHighLevelClient, - val bpdmQueryBuilder: BpdmOpenSearchQueryBuilder -) { - private val logger = KotlinLogging.logger { } - - /** - * Find [AddressPartnerDoc] entries by [partnerSearchRequest] field query texts. - * - * Query semantic: For every non-null [partnerSearchRequest] field query text (except country code): - * the corresponding [AddressPartnerDoc] field value needs to either contain the whole query text exactly, or contain some words of it or - * has matching prefixes. - * - * Quality of the result is determined by the type of match: full phrase match > word match > prefix match. - * If the request contains a country code, it needs to match exactly or the record will be filtered out. - * - * OpenSearch query structure: - * { - * "query":{ - * "bool": { - * "must":[ - * { - * "bool":{ - * "should": [ - * {"match_phrase": [searchRequest] field query text ...}, - * {"match": [searchRequest] field query text ...} - * {"prefix": ...} - * . - * . for every word in [searchRequest] field query text - * . - * {"prefix": ...} - * ] - * } - * } - * . - * . for every non-null [searchRequest] field - * . - * { ... } - * ], - * "filter": { "term": { "countryCode": [searchRequest] field query text ... } } - * } - * } - * } - */ - fun findBySearchRequest(partnerSearchRequest: AddressPartnerSearchRequest, pageable: Pageable): SearchHits { - val lowerCaseSearchRequest = bpdmQueryBuilder.toLowerCaseSearchRequest(partnerSearchRequest) - - val boolQuery = QueryBuilders.boolQuery() - val mustQuery = boolQuery.must() - - bpdmQueryBuilder.toFieldTextPairs(lowerCaseSearchRequest) - .map { (fieldName, queryText) -> bpdmQueryBuilder.buildInnerShouldQuery(fieldName, queryText) } - .forEach { mustQuery.add(it) } - - - - val searchRequest = SearchRequest() - val searchSourceBuilder = SearchSourceBuilder() - searchSourceBuilder - .query(boolQuery) - .from(pageable.pageNumber * pageable.pageSize) - .size(pageable.pageSize) - searchRequest.indices(ADDRESS_PARTNER_INDEX_NAME) - searchRequest.source(searchSourceBuilder) - - logger.info { searchRequest } - logger.info { restHighLevelClient.lowLevelClient.nodes.get(0).host.toHostString()} - val searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT) - - logger.info { searchResponse } - return searchResponse.hits - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/AddressPartnerDocRepository.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/AddressPartnerDocRepository.kt deleted file mode 100644 index 98d9bab5c..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/AddressPartnerDocRepository.kt +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.repository - -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.ADDRESS_PARTNER_INDEX_NAME -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.AddressPartnerDoc -import org.eclipse.tractusx.bpdm.pool.config.OpenSearchConfigProperties -import org.eclipse.tractusx.bpdm.pool.exception.BpdmOpenSearchException -import org.opensearch.client.opensearch.OpenSearchClient -import org.opensearch.client.opensearch._types.Refresh -import org.opensearch.client.opensearch.core.BulkRequest -import org.opensearch.client.opensearch.core.BulkResponse -import org.springframework.stereotype.Repository - -@Repository -class AddressPartnerDocRepository( - private val openSearchClient: OpenSearchClient, - private val openSearchConfigProperties: OpenSearchConfigProperties -) { - fun saveAll(addressPartnerDocs: Collection) { - if (addressPartnerDocs.isEmpty()) { - return - } - - val builder: BulkRequest.Builder = BulkRequest.Builder() - - for (addressPartnerDoc in addressPartnerDocs) { - builder.operations { op -> - op.index { idx -> - idx.index(ADDRESS_PARTNER_INDEX_NAME) - .id(addressPartnerDoc.bpn) - .document(addressPartnerDoc) - } - } - - if (openSearchConfigProperties.refreshOnWrite) { - builder.refresh(Refresh.True) - } - } - val result: BulkResponse = openSearchClient.bulk(builder.build()) - - if (result.errors()) { - val message = result.items().mapNotNull { it.error() }.mapNotNull { it.reason() } - .joinToString(separator = "\n", prefix = "Error when saving address partner docs \n") - throw BpdmOpenSearchException(message) - } - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/LegalEntityDocRepository.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/LegalEntityDocRepository.kt deleted file mode 100644 index 7ffb497b1..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/LegalEntityDocRepository.kt +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.repository - -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.LEGAL_ENTITIES_INDEX_NAME -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.LegalEntityDoc -import org.eclipse.tractusx.bpdm.pool.config.OpenSearchConfigProperties -import org.eclipse.tractusx.bpdm.pool.exception.BpdmOpenSearchException -import org.opensearch.client.opensearch.OpenSearchClient -import org.opensearch.client.opensearch._types.Refresh -import org.opensearch.client.opensearch.core.BulkRequest -import org.opensearch.client.opensearch.core.BulkResponse -import org.springframework.stereotype.Repository - -@Repository -class LegalEntityDocRepository( - private val openSearchClient: OpenSearchClient, - private val openSearchConfigProperties: OpenSearchConfigProperties -) { - fun saveAll(legalEntityDocs: Collection) { - if (legalEntityDocs.isEmpty()) { - return - } - - val builder: BulkRequest.Builder = BulkRequest.Builder() - - for (legalEntityDoc in legalEntityDocs) { - builder.operations { op -> - op.index { idx -> - idx.index(LEGAL_ENTITIES_INDEX_NAME) - .id(legalEntityDoc.bpn) - .document(legalEntityDoc) - } - } - - if (openSearchConfigProperties.refreshOnWrite) { - builder.refresh(Refresh.True) - } - } - val result: BulkResponse = openSearchClient.bulk(builder.build()) - - if (result.errors()) { - val message = result.items().mapNotNull { it.error() }.mapNotNull { it.reason() } - .joinToString(separator = "\n", prefix = "Error when saving business partner docs \n") - throw BpdmOpenSearchException(message) - } - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/LegalEntityDocSearchRepository.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/LegalEntityDocSearchRepository.kt deleted file mode 100644 index 18ea78eb9..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/repository/LegalEntityDocSearchRepository.kt +++ /dev/null @@ -1,105 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.repository - -import org.eclipse.tractusx.bpdm.pool.api.model.request.BusinessPartnerSearchRequest -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.LEGAL_ENTITIES_INDEX_NAME -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.LegalEntityDoc -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.util.BpdmOpenSearchQueryBuilder -import org.opensearch.action.search.SearchRequest -import org.opensearch.client.RequestOptions -import org.opensearch.client.RestHighLevelClient -import org.opensearch.index.query.QueryBuilders -import org.opensearch.search.SearchHits -import org.opensearch.search.builder.SearchSourceBuilder -import org.springframework.data.domain.Pageable -import org.springframework.stereotype.Repository - -/** - * Creates and executes OpenSearch queries for querying [LegalEntityDoc] entries - */ -@Repository -class LegalEntityDocSearchRepository( - val restHighLevelClient: RestHighLevelClient, - val bpdmQueryBuilder: BpdmOpenSearchQueryBuilder -) { - - /** - * Find [LegalEntityDoc] entries by [partnerSearchRequest] field query texts. - * - * Query semantic: For every non-null [partnerSearchRequest] field query text: the corresponding [LegalEntityDoc] field value needs to - * either contain the whole query text exactly, or contain some words of it or has matching prefixes. - * - * Quality of the result is determined by the type of match: full phrase match > word match > prefix match. - * - * OpenSearch query structure: - * { - * "query":{ - * "bool": { - * "must":[ - * "nested": { - * "path": path of [searchRequest] field - * "query": { - * "bool":{ - * "should": [ - * {"match_phrase": [searchRequest] field query text ...}, - * {"match": [searchRequest] field query text ...} - * {"prefix": ...} - * . - * . for every word in [searchRequest] field query text - * . - * {"prefix": ...} - * ] - * } - * } - * } - * . - * . for every non-null [searchRequest] field - * . - * {"nested": ...} - * ] - * } - * } - * } - */ - fun findBySearchRequest(partnerSearchRequest: BusinessPartnerSearchRequest, pageable: Pageable): SearchHits { - val lowerCaseSearchRequest = bpdmQueryBuilder.toLowerCaseSearchRequest(partnerSearchRequest) - - val boolQuery = QueryBuilders.boolQuery() - val mustQuery = boolQuery.must() - - bpdmQueryBuilder.toFieldTextPairs(lowerCaseSearchRequest) - .map { (fieldName, queryText) -> bpdmQueryBuilder.buildNestedQuery(fieldName, queryText, false) } - .forEach { mustQuery.add(it) } - - val searchRequest = SearchRequest() - val searchSourceBuilder = SearchSourceBuilder() - searchSourceBuilder - .query(boolQuery) - .from(pageable.pageNumber * pageable.pageSize) - .size(pageable.pageSize) - searchRequest.indices(LEGAL_ENTITIES_INDEX_NAME) - searchRequest.source(searchSourceBuilder) - - val searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT) - - return searchResponse.hits - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/DocumentMappingService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/DocumentMappingService.kt deleted file mode 100644 index 81dc15833..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/DocumentMappingService.kt +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service - -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.AddressDoc -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.AddressPartnerDoc -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.LegalEntityDoc -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.TextDoc -import org.eclipse.tractusx.bpdm.pool.entity.AlternativePostalAddress -import org.eclipse.tractusx.bpdm.pool.entity.LegalEntity -import org.eclipse.tractusx.bpdm.pool.entity.LogisticAddress -import org.eclipse.tractusx.bpdm.pool.entity.PhysicalPostalAddress -import org.springframework.stereotype.Service - -/** - * Responsible for mapping entities to their OpenSearch document representations - */ -@Service -class DocumentMappingService { - - /** - * Maps [LegalEntity] to [LegalEntityDoc] representation - */ - fun toDocument(partner: LegalEntity): LegalEntityDoc { - val partnerStatus = partner.states.maxWithOrNull(compareBy { it.validFrom }) - return LegalEntityDoc( - bpn = partner.bpn, - legalName = TextDoc(partner.legalName.value), - legalForm = partner.legalForm?.name?.let { TextDoc(it) }, - status = partnerStatus?.description?.let { TextDoc(it) }, - addresses = toAddresses(partner.legalAddress), - classifications = partner.classifications.mapNotNull { classif -> classif.value?.let { TextDoc(it) } }, - sites = partner.sites.map { TextDoc(it.name) } - ) - } - - /** - * Maps [LogisticAddress] to [AddressPartnerDoc] representation - */ - fun toDocument(logisticAddress: LogisticAddress): Collection { - - val addresses: MutableList = mutableListOf() - val list = listOfNotNull(logisticAddress.name) - addresses.add(toAddressPartnerDoc(list, (logisticAddress.physicalPostalAddress), logisticAddress.bpn)) - // TODO OpenSearch indexing doesn't work as expected when creating two AddressPartnerDocs with the same BPN (which is the ID), only last is indexed! - // For now don't index alternativePostalAddress, since this would override (more important) physicalPostalAddress! -// if (logisticAddress.alternativePostalAddress != null) { -// addresses.add(toAddressPartnerDoc((AlternativePostalAddressToSaasMapping(logisticAddress.alternativePostalAddress!!)), logisticAddress.bpn)) -// } - - return addresses - } - - /** - * Maps [logisticAddress] to [AddressPartnerDoc] representation - */ - fun toAddresses(logisticAddress: LogisticAddress): Collection { - - val addresses: MutableList = mutableListOf() - - addresses.add(toAddressDoc(logisticAddress.physicalPostalAddress)) - if (logisticAddress.alternativePostalAddress != null) { - addresses.add(toAddressDoc((logisticAddress.alternativePostalAddress!!))) - } - - return addresses - } - - fun toAddressPartnerDoc(name: List, address: PhysicalPostalAddress, bpn: String): AddressPartnerDoc { - return AddressPartnerDoc( - bpn = bpn, - name = name - ) - } - - - fun toAddressDoc(address: PhysicalPostalAddress): AddressDoc { - return AddressDoc( - administrativeAreas = setOf(TextDoc(address.administrativeAreaLevel1.toString())), - postCodes = setOf(TextDoc(address.postCode.toString())), - localities = setOf(TextDoc("")), - thoroughfares = setOf(TextDoc("")), - premises = setOf(TextDoc("")), - postalDeliveryPoints = setOf(TextDoc("")) - ) - } - - fun toAddressDoc(address: AlternativePostalAddress): AddressDoc { - return AddressDoc( - administrativeAreas = setOf(TextDoc(address.administrativeAreaLevel1.toString())), - postCodes = setOf(TextDoc(address.postCode.toString())), - localities = setOf(TextDoc("")), - thoroughfares = setOf(TextDoc("")), - premises = setOf(TextDoc("")), - postalDeliveryPoints = setOf(TextDoc("")) - ) - } - - -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/OpenSearchSyncPageService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/OpenSearchSyncPageService.kt deleted file mode 100644 index 3a69f1228..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/OpenSearchSyncPageService.kt +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service - -import mu.KotlinLogging -import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.AddressPartnerDoc -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.repository.AddressPartnerDocRepository -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.repository.LegalEntityDocRepository -import org.eclipse.tractusx.bpdm.pool.entity.PartnerChangelogEntry -import org.eclipse.tractusx.bpdm.pool.repository.LegalEntityRepository -import org.eclipse.tractusx.bpdm.pool.repository.LogisticAddressRepository -import org.eclipse.tractusx.bpdm.pool.service.PartnerChangelogService -import org.springframework.data.domain.Page -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional -import java.time.Instant - -@Service -class OpenSearchSyncPageService( - val legalEntityRepository: LegalEntityRepository, - val logisticAddressRepository: LogisticAddressRepository, - val legalEntityDocRepository: LegalEntityDocRepository, - val addressPartnerDocRepository: AddressPartnerDocRepository, - val documentMappingService: DocumentMappingService, - val changelogService: PartnerChangelogService -) { - private val logger = KotlinLogging.logger { } - - @Transactional - fun exportPartnersToOpenSearch(fromTime: Instant, pageIndex: Int, pageSize: Int): Page { - logger.debug { "Export page $pageIndex" } - val changelogEntriesPage = - changelogService.getChangelogEntriesCreatedAfter( - fromTime, - listOf(BusinessPartnerType.LEGAL_ENTITY, BusinessPartnerType.ADDRESS), - pageIndex, - pageSize - ) - val changelogEntriesBySubject = changelogEntriesPage.groupBy { it.businessPartnerType } - - val legalEntityBpns = changelogEntriesBySubject[BusinessPartnerType.LEGAL_ENTITY]?.map { it.bpn }?.toSet() - if (!legalEntityBpns.isNullOrEmpty()) { - val legalEntitiesToExport = legalEntityRepository.findDistinctByBpnIn(legalEntityBpns) - logger.debug { "Exporting ${legalEntitiesToExport.size} legal entity records" } - val partnerDocs = legalEntitiesToExport.map { documentMappingService.toDocument(it) }.toList() - legalEntityDocRepository.saveAll(partnerDocs) - } - - val addressBpns = changelogEntriesBySubject[BusinessPartnerType.ADDRESS]?.map { it.bpn }?.toSet() - if (!addressBpns.isNullOrEmpty()) { - val addressesToExport = logisticAddressRepository.findDistinctByBpnIn(addressBpns) - logger.debug { "Exporting ${addressesToExport.size} address records" } - val addressPartnerDocs : Collection = addressesToExport.flatMap { documentMappingService.toDocument(it) } - addressPartnerDocRepository.saveAll(addressPartnerDocs) - } - - return changelogEntriesPage - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/OpenSearchSyncService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/OpenSearchSyncService.kt deleted file mode 100644 index 91c49c356..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/OpenSearchSyncService.kt +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service - -import jakarta.persistence.EntityManager -import mu.KotlinLogging -import org.eclipse.tractusx.bpdm.pool.api.model.SyncType -import org.eclipse.tractusx.bpdm.pool.config.OpenSearchConfigProperties -import org.eclipse.tractusx.bpdm.pool.entity.PartnerChangelogEntry -import org.eclipse.tractusx.bpdm.pool.service.SyncRecordService -import org.springframework.data.domain.Page -import org.springframework.scheduling.annotation.Async -import org.springframework.stereotype.Service -import java.time.Instant - -/** - * Provides functionality for managing the OpenSearch index - */ -@Service -class OpenSearchSyncService( - val openSearchSyncPageService: OpenSearchSyncPageService, - val configProperties: OpenSearchConfigProperties, - val entityManager: EntityManager, - private val syncRecordService: SyncRecordService -) { - private val logger = KotlinLogging.logger { } - - /** - * Asynchronous version of [exportPaginated] - */ - @Async - fun exportPaginatedAsync(fromTime: Instant, saveState: String?) { - exportPaginated(fromTime, saveState) - } - - /** - * Export new changes of the business partner records to the OpenSearch index - * - * A new change is discovered by comparing the updated timestamp of the business partner record with the time of the last export - */ - fun exportPaginated(fromTime: Instant, saveState: String?) { - var page = saveState?.toIntOrNull() ?: 0 - var docsPage: Page - - logger.info { "Start OpenSearch export from time '$fromTime' and page '$page'" } - - do { - try { - docsPage = openSearchSyncPageService.exportPartnersToOpenSearch(fromTime, page, configProperties.exportPageSize) - page++ - val record = syncRecordService.getOrCreateRecord(SyncType.OPENSEARCH) - val newCount = record.count + docsPage.content.size - syncRecordService.setProgress(SyncType.OPENSEARCH, newCount, newCount.toFloat() / docsPage.totalElements) - - //Clear session after each page import to improve JPA performance - entityManager.clear() - - } catch (exception: RuntimeException) { - logger.error(exception) { "Exception encountered on OpenSearch export" } - syncRecordService.setSynchronizationError(SyncType.OPENSEARCH, exception.message!!, page.toString()) - return - } - } while (docsPage.totalPages > page) - - syncRecordService.setSynchronizationSuccess(SyncType.OPENSEARCH) - - logger.info { "Finished OpenSearch export successfully" } - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/OpenSearchSyncStarterService.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/OpenSearchSyncStarterService.kt deleted file mode 100644 index c1819d6b5..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/OpenSearchSyncStarterService.kt +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service - -import mu.KotlinLogging -import org.eclipse.tractusx.bpdm.pool.api.model.SyncType -import org.eclipse.tractusx.bpdm.pool.api.model.response.SyncDto -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.ADDRESS_PARTNER_INDEX_NAME -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.LEGAL_ENTITIES_INDEX_NAME -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.MAPPINGS_FILE_PATH_ADDRESSES -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.MAPPINGS_FILE_PATH_LEGAL_ENTITIES -import org.eclipse.tractusx.bpdm.pool.service.SyncRecordService -import org.eclipse.tractusx.bpdm.pool.service.toDto -import org.opensearch.client.RequestOptions -import org.opensearch.client.RestHighLevelClient -import org.opensearch.client.indices.CreateIndexRequest -import org.opensearch.client.indices.GetMappingsRequest -import org.opensearch.client.indices.GetMappingsResponse -import org.opensearch.client.opensearch.OpenSearchClient -import org.opensearch.client.opensearch.indices.DeleteIndexRequest -import org.opensearch.cluster.metadata.MappingMetadata -import org.opensearch.common.xcontent.XContentType -import org.springframework.context.ApplicationContextException -import org.springframework.context.event.ContextRefreshedEvent -import org.springframework.context.event.EventListener -import org.springframework.core.io.ResourceLoader -import org.springframework.scheduling.annotation.Scheduled -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional - -@Service -class OpenSearchSyncStarterService( - private val syncRecordService: SyncRecordService, - private val openSearchSyncService: OpenSearchSyncService, - private val openSearchClient: OpenSearchClient, - private val restHighLevelClient: RestHighLevelClient, - private val resourceLoader: ResourceLoader -) { - private val logger = KotlinLogging.logger { } - - /** - * Checks for changed records since the last export and exports those changes to OpenSearch - */ - @Scheduled(cron = "\${bpdm.opensearch.export-scheduler-cron-expr:-}", zone = "UTC") - fun export(): SyncDto { - return startExport(true) - } - - /** - * Non-blocking asynchronous variant of [export] - */ - fun exportAsync(): SyncDto { - return startExport(false) - } - - /** - * Fetch a [SyncDto] about the state of the latest export - */ - fun getExportStatus(): SyncDto { - return syncRecordService.getOrCreateRecord(SyncType.OPENSEARCH).toDto() - } - - /** - * Clears the whole index and resets the time of the last update - */ - @Transactional - fun clearOpenSearch() { - logger.info { "Recreating the OpenSearch indexes" } - - deleteIndexesIfExists(LEGAL_ENTITIES_INDEX_NAME, ADDRESS_PARTNER_INDEX_NAME) - createIndexes( - IndexDefinition(LEGAL_ENTITIES_INDEX_NAME, MAPPINGS_FILE_PATH_LEGAL_ENTITIES), - IndexDefinition(ADDRESS_PARTNER_INDEX_NAME, MAPPINGS_FILE_PATH_ADDRESSES) - ) - - syncRecordService.reset(SyncType.OPENSEARCH) - } - - /** - * Checks whether the existing indexes are up-to-date with the current index mappings and recreates the indexes if necessary - * - * @throws [ApplicationContextException] shutting down the application on exception - */ - @EventListener(ContextRefreshedEvent::class) - fun updateOnInit() { - logger.info { "Checking whether OpenSearch indexes need to be recreated..." } - try { - var recreateIndexes = false - - recreateIndexes = updateOnInit(IndexDefinition(LEGAL_ENTITIES_INDEX_NAME, MAPPINGS_FILE_PATH_LEGAL_ENTITIES)) || recreateIndexes - recreateIndexes = updateOnInit(IndexDefinition(ADDRESS_PARTNER_INDEX_NAME, MAPPINGS_FILE_PATH_ADDRESSES)) || recreateIndexes - - if (recreateIndexes) { - clearOpenSearch() - } else { - logger.info { "Index mappings still up-to-date" } - } - } catch (e: Throwable) { - // make sure Application exits when exception is thrown - throw ApplicationContextException("Exception when updating OpenSearch indexes during initialization", e) - } - } - - /** - * @return true if index mapping changed, false otherwise - */ - private fun updateOnInit(indexDefinition: IndexDefinition): Boolean { -/* val indexAlreadyExists = openSearchClient.indices().exists { it.index(indexDefinition.indexName) }.value() - - return if (!indexAlreadyExists) { - true - } else { - val tempIndexName = "temp-${indexDefinition.indexName}" - deleteIndexIfExists(tempIndexName) - createIndex(IndexDefinition(tempIndexName, indexDefinition.mappingsFilePath)) - - val existingMappingMetadata = getIndexMappings(indexDefinition.indexName).sourceAsMap() - val requiredMappingMetadata = getIndexMappings(tempIndexName).sourceAsMap() - - deleteIndexIfExists(tempIndexName) - - requiredMappingMetadata != existingMappingMetadata - }*/ - return true - } - - private fun getIndexMappings(indexName: String): MappingMetadata { - val request = GetMappingsRequest() - request.indices(indexName) - val getMappingResponse: GetMappingsResponse = restHighLevelClient.indices().getMapping(request, RequestOptions.DEFAULT) - return getMappingResponse.mappings()[indexName]!! - } - - /** - * Start export either asynchronously or synchronously depending on whether [inSync] - */ - private fun startExport(inSync: Boolean): SyncDto { - val record = syncRecordService.setSynchronizationStart(SyncType.OPENSEARCH) - val response = record.toDto() - - logger.debug { "Initializing OpenSearch export with records after '${record.fromTime}' from page '${record.errorSave}' and asynchronously: ${!inSync}" } - - if (inSync) - openSearchSyncService.exportPaginated(record.fromTime, record.errorSave) - else - openSearchSyncService.exportPaginatedAsync(record.fromTime, record.errorSave) - - return response - } - - private fun deleteIndexesIfExists(vararg indexNames: String) { - for (indexName in indexNames) { - deleteIndexIfExists(indexName) - } - } - - private fun deleteIndexIfExists(indexName: String) { - val indexExists = openSearchClient.indices().exists { it.index(indexName) }.value() - if (indexExists) { - val deleteIndexRequest: DeleteIndexRequest = DeleteIndexRequest.Builder().index(indexName).build() - openSearchClient.indices().delete(deleteIndexRequest) - } - } - - private fun createIndexes(vararg indexDefinitions: IndexDefinition) { - for (indexDefinition in indexDefinitions) { - createIndex(indexDefinition) - } - } - - private fun createIndex(indexDefinition: IndexDefinition) { - val indexMappings = String(resourceLoader.getResource("classpath:${indexDefinition.mappingsFilePath}").inputStream.readAllBytes()) - val request = CreateIndexRequest(indexDefinition.indexName) - request.mapping(indexMappings, XContentType.JSON) - - restHighLevelClient.indices().create(request, RequestOptions.DEFAULT) - } -} - -private data class IndexDefinition(val indexName: String, val mappingsFilePath: String) \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/SearchServiceImpl.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/SearchServiceImpl.kt deleted file mode 100644 index f592f7682..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/service/SearchServiceImpl.kt +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service - -import mu.KotlinLogging -import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest -import org.eclipse.tractusx.bpdm.common.dto.response.PageDto -import org.eclipse.tractusx.bpdm.pool.api.model.request.AddressPartnerSearchRequest -import org.eclipse.tractusx.bpdm.pool.api.model.request.BusinessPartnerSearchRequest -import org.eclipse.tractusx.bpdm.pool.api.model.response.AddressMatchVerboseDto -import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityMatchVerboseDto -import org.eclipse.tractusx.bpdm.pool.api.model.response.SiteMatchVerboseDto -import org.eclipse.tractusx.bpdm.pool.service.SearchService -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.repository.AddressDocSearchRepository -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.repository.LegalEntityDocSearchRepository -import org.eclipse.tractusx.bpdm.pool.config.OpenSearchConfigProperties -import org.eclipse.tractusx.bpdm.pool.entity.LegalEntity -import org.eclipse.tractusx.bpdm.pool.entity.LogisticAddress -import org.eclipse.tractusx.bpdm.pool.entity.Site -import org.eclipse.tractusx.bpdm.pool.exception.BpdmOpenSearchUserException -import org.eclipse.tractusx.bpdm.pool.repository.LegalEntityRepository -import org.eclipse.tractusx.bpdm.pool.repository.LogisticAddressRepository -import org.eclipse.tractusx.bpdm.pool.repository.SiteRepository -import org.eclipse.tractusx.bpdm.pool.service.* -import org.springframework.data.domain.PageRequest -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional -import kotlin.math.ceil - -/** - * Implements search functionality by using OpenSearch - */ -@Service -class SearchServiceImpl( - val legalEntityDocSearchRepository: LegalEntityDocSearchRepository, - val addressDocSearchRepository: AddressDocSearchRepository, - val legalEntityRepository: LegalEntityRepository, - val logisticAddressRepository: LogisticAddressRepository, - val siteRepository: SiteRepository, - val addressService: AddressService, - val siteService: SiteService, - val businessPartnerFetchService: BusinessPartnerFetchService, - val openSearchConfigProperties: OpenSearchConfigProperties -) : SearchService { - - private val logger = KotlinLogging.logger { } - - /** - * Uses the [searchRequest] to perform an OpenSearch query for business partners. - * The BPNs of found partners are used to query the whole business partner records from the database. - * The records are supplied with relevancy scores of the search hits and returned as a paginated result. - * In case BPNs found by OpenSearch can not be found in the database, the [PageDto] properties are - * adapted accordingly from the OpenSearch page information - * - */ - @Transactional - override fun searchLegalEntities( - searchRequest: BusinessPartnerSearchRequest, - paginationRequest: PaginationRequest - ): PageDto { - - val legalEntityPage = searchAndPreparePage(searchRequest, paginationRequest) - businessPartnerFetchService.fetchLegalEntityDependencies(legalEntityPage.content.map { (_, legalEntity) -> legalEntity }.toSet()) - - return with(legalEntityPage) { - PageDto(totalElements, totalPages, page, contentSize, - content.map { (score, legalEntity) -> legalEntity.toMatchDto(score) }) - } - } - - /** - * @see SearchServiceImpl.searchLegalEntities - */ - @Transactional - override fun searchAddresses(searchRequest: AddressPartnerSearchRequest, paginationRequest: PaginationRequest): PageDto { - val addressPage = searchAndPreparePage(searchRequest, paginationRequest) - - addressService.fetchLogisticAddressDependencies(addressPage.content.map { (_, address) -> address }.toSet()) - - return with(addressPage) { - PageDto(totalElements, totalPages, page, contentSize, - content.map { (score, address) -> address.toMatchDto(score) }) - } - } - - @Transactional - override fun searchSites(paginationRequest: PaginationRequest): PageDto { - val sitePage = searchAndPreparePageSite(paginationRequest) - - siteService.fetchSiteDependenciesPage(sitePage.content.map { site -> site }.toSet()) - - return with(sitePage) { - PageDto(totalElements, totalPages, page, contentSize, - content.map { site -> site.toMatchDto() }) - } - } - - private fun searchAndPreparePage( - searchRequest: BusinessPartnerSearchRequest, - paginationRequest: PaginationRequest - ): PageDto> { - return if (searchRequest == BusinessPartnerSearchRequest.EmptySearchRequest) { - paginateLegalEntities(paginationRequest) - } else { - searchIndex(searchRequest, paginationRequest) - } - } - - private fun searchAndPreparePage( - searchRequest: AddressPartnerSearchRequest, - paginationRequest: PaginationRequest - ): PageDto> { - - return if (searchRequest == AddressPartnerSearchRequest.EmptySearchRequest) { - paginateAddressPartner(paginationRequest) - } else { - searchIndex(searchRequest, paginationRequest) - } - } - - private fun searchAndPreparePageSite( - paginationRequest: PaginationRequest - ): PageDto { - - return paginateSite(paginationRequest) - - } - - private fun paginateLegalEntities(paginationRequest: PaginationRequest): PageDto> { - logger.debug { "Paginate database for legal entities" } - val legalEntityPage = legalEntityRepository.findAll(PageRequest.of(paginationRequest.page, paginationRequest.size)) - - return legalEntityPage.toDto(legalEntityPage.content.map { Pair(0f, it) }) // assign 0 score as no search has been conducted - } - - private fun paginateAddressPartner(paginationRequest: PaginationRequest): PageDto> { - logger.debug { "Paginate database for address partners" } - val addressPage = logisticAddressRepository.findAll(PageRequest.of(paginationRequest.page, paginationRequest.size)) - - return addressPage.toDto(addressPage.content.map { Pair(0f, it) }) // assign 0 score as no search has been conducted - } - - private fun paginateSite(paginationRequest: PaginationRequest): PageDto { - logger.debug { "Paginate database for sites" } - val sitePage = siteRepository.findAll(PageRequest.of(paginationRequest.page, paginationRequest.size)) - - return sitePage.toDto(sitePage.content.map { it }) - } - - private fun searchIndex( - searchRequest: BusinessPartnerSearchRequest, - paginationRequest: PaginationRequest - ): PageDto> { - logger.debug { "Search index for legal entities" } - - if (paginationRequest.page > openSearchConfigProperties.maxPage) - throw BpdmOpenSearchUserException("When using search parameters page can't exceed ${openSearchConfigProperties.maxPage} but was ${paginationRequest.page} instead") - - val searchResult = legalEntityDocSearchRepository.findBySearchRequest( - searchRequest, - PageRequest.of(paginationRequest.page, paginationRequest.size) - ) - - logger.debug { "Found ${searchResult.hits.size} business partners in OpenSearch. (${searchResult.totalHits} in total)" } - - val bpnHitMap = searchResult.associateBy { it.id } - - val legalEntities = legalEntityRepository.findDistinctByBpnIn(bpnHitMap.keys) - val missingPartners = bpnHitMap.keys.minus(legalEntities.map { it.bpn }.toSet()) - - if (missingPartners.isNotEmpty()) - logger.warn { "Some BPNs could not be found in the database: ${missingPartners.joinToString()}" } - - val scoreLegalEntityPairs = legalEntities.map { Pair(bpnHitMap[it.bpn]!!.score, it) }.sortedByDescending { it.first } - - val totalHits = searchResult.totalHits!!.value - missingPartners.size - val totalPages = ceil(totalHits.toDouble() / paginationRequest.size).toInt() - return PageDto(totalHits, totalPages, paginationRequest.page, legalEntities.size, scoreLegalEntityPairs) - } - - private fun searchIndex( - searchRequest: AddressPartnerSearchRequest, - paginationRequest: PaginationRequest - ): PageDto> { - logger.debug { "Search index for addresses" } - - if (paginationRequest.page > openSearchConfigProperties.maxPage) - throw BpdmOpenSearchUserException("When using search parameters page can't exceed ${openSearchConfigProperties.maxPage} but was ${paginationRequest.page} instead") - - val searchResult = addressDocSearchRepository.findBySearchRequest( - searchRequest, - PageRequest.of(paginationRequest.page, paginationRequest.size) - ) - - logger.info { "Found ${searchResult.hits.size} addresses in OpenSearch. (${searchResult.totalHits} in total)" } - - val bpnHitMap = searchResult.associateBy { it.id } - - val addresses = logisticAddressRepository.findDistinctByBpnIn(bpnHitMap.keys) - val missingPartners = bpnHitMap.keys.minus(addresses.map { it.bpn }.toSet()) - - if (missingPartners.isNotEmpty()) - logger.warn { "Some BPNs could not be found in the database: ${missingPartners.joinToString()}" } - - val scoreAddressPairs = addresses.map { Pair(bpnHitMap[it.bpn]!!.score, it) }.sortedByDescending { it.first } - - val totalHits = searchResult.totalHits!!.value - missingPartners.size - val totalPages = ceil(totalHits.toDouble() / paginationRequest.size).toInt() - return PageDto(totalHits, totalPages, paginationRequest.page, addresses.size, scoreAddressPairs) - } - -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/util/BpdmOpenSearchQueryBuilder.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/util/BpdmOpenSearchQueryBuilder.kt deleted file mode 100644 index e62f1914c..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/impl/util/BpdmOpenSearchQueryBuilder.kt +++ /dev/null @@ -1,200 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.util - -import org.apache.lucene.search.join.ScoreMode -import org.eclipse.tractusx.bpdm.pool.api.model.request.* -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.AddressDoc -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.AddressPartnerDoc -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.LegalEntityDoc -import org.opensearch.common.unit.Fuzziness -import org.opensearch.index.query.BoolQueryBuilder -import org.opensearch.index.query.InnerHitBuilder -import org.opensearch.index.query.NestedQueryBuilder -import org.opensearch.index.query.QueryBuilders -import org.springframework.stereotype.Component - -/** - * Offers utility methods for building OpenSearch queries - */ -@Component -class BpdmOpenSearchQueryBuilder { - - /** - * Returns an OpenSearch nested query object model for searching a [queryText] in the [LegalEntityDoc] [fieldName]. - * In case [queryText] is not null it is matched by phrase, word or prefix with the [fieldName] values. - * Otherwise, the query just returns possible values for [fieldName]. - * [withHitInfo] the query result not only contains the hit [LegalEntityDoc] but also the exact [fieldName] values hit. - */ - fun buildNestedQuery(fieldName: String, queryText: String?, withHitInfo: Boolean): NestedQueryBuilder { - val innerQuery = if (queryText == null) QueryBuilders.matchAllQuery() else buildInnerShouldQuery( - "$fieldName.text", - queryText - ) - - val nestedQuery = QueryBuilders.nestedQuery(fieldName, innerQuery, ScoreMode.Avg) - - if (withHitInfo) - nestedQuery.innerHit(InnerHitBuilder()) - - return nestedQuery - } - - /** - * Returns an OpenSearch boolean should query object model for searching a [queryText] in the [LegalEntityDoc] [fieldName]. - * [queryText] is not null it is matched by phrase, word or prefix with the [fieldName] values. - */ - fun buildInnerShouldQuery(fieldName: String, queryText: String): BoolQueryBuilder { - val boolQuery = QueryBuilders.boolQuery() - val shouldQuery = boolQuery.should() - shouldQuery.add(QueryBuilders.matchPhraseQuery(fieldName, queryText).boost(5f)) - shouldQuery.add( - QueryBuilders.matchQuery(fieldName, queryText).boost(3f).fuzziness(Fuzziness.ONE).prefixLength(3) - ) - shouldQuery.addAll(queryText.split(" ").filter { it.isNotBlank() }.map { QueryBuilders.prefixQuery(fieldName, it) }) - return boolQuery - } - - /** - * Converts a [searchRequest] into pairs of [LegalEntityDoc] field name to query text for that field. - * Fields with no query text are omitted. - */ - fun toFieldTextPairs(searchRequest: BusinessPartnerSearchRequest): Collection> { - return toFieldTextPairs(searchRequest.partnerProperties) - } - - /** - * Converts a [bpSearch] into pairs of [LegalEntityDoc] field name to query text for that field. - * @see toFieldTextPairs - */ - fun toFieldTextPairs(bpSearch: LegalEntityPropertiesSearchRequest): Collection> { - val bpParamPairs = mutableListOf( - Pair(LegalEntityDoc::legalName.name, bpSearch.legalName), - ) - - return bpParamPairs - .filter { (_, query) -> query != null } - .map { (fieldName, query) -> Pair(fieldName, query!!) } - } - - /** - * Converts a [addressSearch] into pairs of [LegalEntityDoc] field name to query text for that field. - * @see toFieldTextPairs - */ - fun toFieldTextPairs(addressSearch: AddressPropertiesSearchRequest): Collection> { - val addressParamPairs = listOf( - Pair("${LegalEntityDoc::addresses.name}.${AddressDoc::localities.name}", addressSearch.locality), - Pair( - "${LegalEntityDoc::addresses.name}.${AddressDoc::administrativeAreas.name}", - addressSearch.administrativeArea - ), - Pair("${LegalEntityDoc::addresses.name}.${AddressDoc::postCodes.name}", addressSearch.postCode), - Pair("${LegalEntityDoc::addresses.name}.${AddressDoc::premises.name}", addressSearch.premise), - Pair( - "${LegalEntityDoc::addresses.name}.${AddressDoc::postalDeliveryPoints.name}", - addressSearch.postalDeliveryPoint - ), - Pair("${LegalEntityDoc::addresses.name}.${AddressDoc::thoroughfares.name}", addressSearch.thoroughfare), - ) - - return addressParamPairs.filter { (_, query) -> query != null } - .map { (fieldName, query) -> Pair(fieldName, query!!) } - } - - /** - * Converts a [siteSearch] into pairs of [LegalEntityDoc] field name to query text for that field. - * @see toFieldTextPairs - */ - fun toFieldTextPairs(siteSearch: SitePropertiesSearchRequest): Collection> { - val siteParamPairs = listOf( - Pair(LegalEntityDoc::sites.name, siteSearch.siteName) - ) - - return siteParamPairs - .filter { (_, query) -> query != null } - .map { (fieldName, query) -> Pair(fieldName, query!!) } - } - - /** - * Converts a [addressSearch] into pairs of [AddressPartnerDoc] field name to query text for that field. - */ - fun toFieldTextPairs(addressSearch: AddressPartnerSearchRequest): Collection> { - val addressParamPairs = listOf( - Pair(AddressPartnerDoc::name.name, addressSearch.name) - - ) - - return addressParamPairs - .filter { (_, query) -> query != null } - .map { (fieldName, query) -> Pair(fieldName, query!!) } - } - - - - /** - * Returns a lowercase representation of [searchRequest] - */ - fun toLowerCaseSearchRequest(searchRequest: BusinessPartnerSearchRequest): BusinessPartnerSearchRequest { - return BusinessPartnerSearchRequest( - toLowerCaseSearchRequest(searchRequest.partnerProperties) - ) - } - - /** - * Returns a lowercase representation of [searchRequest] - */ - fun toLowerCaseSearchRequest(searchRequest: LegalEntityPropertiesSearchRequest): LegalEntityPropertiesSearchRequest { - return LegalEntityPropertiesSearchRequest( - searchRequest.legalName?.lowercase() - ) - } - - /** - * Returns a lowercase representation of [searchRequest] - */ - fun toLowerCaseSearchRequest(searchRequest: AddressPropertiesSearchRequest): AddressPropertiesSearchRequest { - return AddressPropertiesSearchRequest( - searchRequest.administrativeArea?.lowercase(), - searchRequest.postCode?.lowercase(), - searchRequest.locality?.lowercase(), - searchRequest.thoroughfare?.lowercase(), - searchRequest.premise?.lowercase(), - searchRequest.postalDeliveryPoint?.lowercase() - ) - } - - /** - * Returns a lowercase representation of [searchRequest] - */ - fun toLowerCaseSearchRequest(searchRequest: SitePropertiesSearchRequest): SitePropertiesSearchRequest { - return SitePropertiesSearchRequest( - searchRequest.siteName?.lowercase() - ) - } - - /** - * Returns a lowercase representation of [searchRequest] - */ - fun toLowerCaseSearchRequest(searchRequest: AddressPartnerSearchRequest): AddressPartnerSearchRequest { - return AddressPartnerSearchRequest( - searchRequest.name?.lowercase() - ) - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchConfigProperties.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchConfigProperties.kt deleted file mode 100644 index a5bec5668..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchConfigProperties.kt +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.config - -import org.springframework.boot.context.properties.ConfigurationProperties - - -@ConfigurationProperties(prefix = "bpdm.opensearch") -class OpenSearchConfigProperties( - val host: String = "localhost", - val port: Int = 9200, - val scheme: String = "http", - val exportPageSize: Int = 100, - val exportSchedulerCronExpr: String = "-", - val refreshOnWrite: Boolean = false, - val maxPage: Int = 20 -) \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchEnabledConfig.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchEnabledConfig.kt deleted file mode 100644 index df88d21bc..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/OpenSearchEnabledConfig.kt +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.config - -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.OpenSearchImplConfig -import org.springframework.context.annotation.Configuration -import org.springframework.context.annotation.Import - - -@Configuration -@Import(value = [OpenSearchImplConfig::class]) -class OpenSearchEnabledConfig \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/PoolSecurityConfigProperties.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/PoolSecurityConfigProperties.kt index 0ebf490d9..87cbfc173 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/PoolSecurityConfigProperties.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/config/PoolSecurityConfigProperties.kt @@ -28,8 +28,7 @@ data class PoolSecurityConfigProperties( var readPoolPartnerData: String = "read_pool_partner_data", var changePoolPartnerData: String = "change_pool_partner_data", var readMetaData: String = "read_meta_data", - var changeMetaData: String = "change_meta_data", - var manageOpensearch: String = "manage_opensearch" + var changeMetaData: String = "change_meta_data" ) { fun getReadPoolPartnerDataAsRole(): String { @@ -47,8 +46,4 @@ data class PoolSecurityConfigProperties( fun getChangeMetaDataAsRole(): String { return "ROLE_$changeMetaData" } - - fun getManageOpensearchAsRole(): String { - return "ROLE_$manageOpensearch" - } } diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/exception/BpdmOpenSearchException.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/exception/BpdmOpenSearchException.kt deleted file mode 100644 index 00b4da478..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/exception/BpdmOpenSearchException.kt +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.exception - -import org.springframework.http.HttpStatus -import org.springframework.web.bind.annotation.ResponseStatus - -@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) -class BpdmOpenSearchException(message: String) : RuntimeException(message) { -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/exception/BpdmOpenSearchUserException.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/exception/BpdmOpenSearchUserException.kt deleted file mode 100644 index 207a9b6cf..000000000 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/exception/BpdmOpenSearchUserException.kt +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.exception - -import org.springframework.http.HttpStatus -import org.springframework.web.bind.annotation.ResponseStatus - -@ResponseStatus(HttpStatus.BAD_REQUEST) -class BpdmOpenSearchUserException(message: String) : RuntimeException(message) { -} \ No newline at end of file diff --git a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt index 02632654c..245ca89a4 100644 --- a/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt +++ b/bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/ResponseMappings.kt @@ -269,10 +269,6 @@ fun Relation.toDto(): RelationVerboseDto { ) } -fun SyncRecord.toDto(): SyncDto { - return SyncDto(type, status, count, progress, errorDetails, startedAt, finishedAt) -} - fun PartnerChangelogEntry.toDto(): ChangelogEntryVerboseDto { return ChangelogEntryVerboseDto(bpn, businessPartnerType, createdAt, changelogType) } diff --git a/bpdm-pool/src/main/resources/application-auth.properties b/bpdm-pool/src/main/resources/application-auth.properties index 9dd289c93..63ca675d8 100644 --- a/bpdm-pool/src/main/resources/application-auth.properties +++ b/bpdm-pool/src/main/resources/application-auth.properties @@ -21,7 +21,6 @@ bpdm.pool-security.readPoolPartnerData=read_pool_partner_data bpdm.pool-security.changePoolPartnerData=change_pool_partner_data bpdm.pool-security.readMetaData=read_meta_data bpdm.pool-security.changeMetaData=change_meta_data -bpdm.pool-security.manageOpensearch=manage_opensearch bpdm.security.cors-origins=* #Generic OAuth configuration bpdm.security.client-id=BPDM_Client diff --git a/bpdm-pool/src/main/resources/application.properties b/bpdm-pool/src/main/resources/application.properties index e83b2f154..e3461fb55 100644 --- a/bpdm-pool/src/main/resources/application.properties +++ b/bpdm-pool/src/main/resources/application.properties @@ -47,16 +47,7 @@ management.health.livenessState.enabled=true management.health.readinessState.enabled=true #Disable Security on default bpdm.security.enabled=false -#Opensearch configuration -bpdm.opensearch.host=localhost -bpdm.opensearch.port=9200 -bpdm.opensearch.scheme=http -bpdm.opensearch.export-page-size=100 -bpdm.opensearch.max-page=20 -# Special value "-" disables scheduling. See javadoc of org.springframework.scheduling.support.CronExpression.parse for format. -bpdm.opensearch.export-scheduler-cron-expr=- -bpdm.opensearch.refresh-on-write=false # Orchestrator Client bpdm.pool-orchestrator.golden-record-scheduler-cron-expr=- bpdm.pool-orchestrator.base-url=http://localhost:8085/ diff --git a/bpdm-pool/src/main/resources/opensearch/index-mappings-addresses.json b/bpdm-pool/src/main/resources/opensearch/index-mappings-addresses.json deleted file mode 100644 index 5fc9f8221..000000000 --- a/bpdm-pool/src/main/resources/opensearch/index-mappings-addresses.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dynamic": "strict", - "properties": { - "name": { - "type": "search_as_you_type" - } - } -} \ No newline at end of file diff --git a/bpdm-pool/src/main/resources/opensearch/index-mappings-legal-entities.json b/bpdm-pool/src/main/resources/opensearch/index-mappings-legal-entities.json deleted file mode 100644 index 804a630c0..000000000 --- a/bpdm-pool/src/main/resources/opensearch/index-mappings-legal-entities.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "dynamic": "strict", - "properties": { - "legalName": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - }, - "legalForm": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - }, - "status": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - }, - "addresses": { - "type": "nested", - "properties": { - "administrativeAreas": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - }, - "postCodes": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - }, - "localities": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - }, - "thoroughfares": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - }, - "premises": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - }, - "postalDeliveryPoints": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - } - } - }, - "classifications": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - }, - "sites": { - "type": "nested", - "properties": { - "text": { - "type": "search_as_you_type" - } - } - } - } -} \ No newline at end of file diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/InvalidIndexStartupIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/InvalidIndexStartupIT.kt deleted file mode 100644 index 14aa33163..000000000 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/InvalidIndexStartupIT.kt +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch - -import org.assertj.core.api.Assertions.assertThat -import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest -import org.eclipse.tractusx.bpdm.pool.Application -import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl -import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPropertiesSearchRequest -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.doc.LEGAL_ENTITIES_INDEX_NAME -import org.eclipse.tractusx.bpdm.pool.util.* -import org.junit.jupiter.api.MethodOrderer.OrderAnnotation -import org.junit.jupiter.api.Order -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestMethodOrder -import org.opensearch.client.opensearch.OpenSearchClient -import org.opensearch.client.opensearch._types.Refresh -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.annotation.DirtiesContext -import org.springframework.test.context.ActiveProfiles -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.web.reactive.server.WebTestClient - -@SpringBootTest( - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class] -) -@ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) -@TestMethodOrder(OrderAnnotation::class) -class InvalidIndexStartupIT @Autowired constructor( - private val webTestClient: WebTestClient, - private val testHelpers: TestHelpers, - private val openSearchClient: OpenSearchClient, - private val poolClient: PoolClientImpl -) { - - - - val bpnBogusDocument = "BPN_FAKE" - - /** - * Not a real test but prepares the OpenSearch container for the next test that will be run in a fresh Spring-Boot context - * Create an invalid OpenSearch index and fill it with bogus content - */ - @Test - @Order(0) - @DirtiesContext - fun setupIndexForNextTest() { - testHelpers.truncateDbTables() - //Clear and set up an invalid OpenSearch context - openSearchClient.indices().delete { it.index(LEGAL_ENTITIES_INDEX_NAME) } - openSearchClient.indices().create { createRequestIndex -> - createRequestIndex.index(LEGAL_ENTITIES_INDEX_NAME).mappings { mapping -> - mapping.properties("outdatedField") { property -> - property.searchAsYouType { it } - } - } - } - - //Create a bogus document with a valid BPN - val invalidBp = InvalidBusinessPartnerDoc("outdated") - - openSearchClient.index { indexRequest -> - indexRequest.index(LEGAL_ENTITIES_INDEX_NAME).id(bpnBogusDocument).document(invalidBp).refresh(Refresh.True) - } - - //Check whether it really is inside the index - val getResponse = - openSearchClient.get({ getRequest -> getRequest.index(LEGAL_ENTITIES_INDEX_NAME).id(bpnBogusDocument) }, InvalidBusinessPartnerDoc::class.java) - assertThat(getResponse.found()).isTrue - } - - /** - * Given non-empty OpenSearch index with outdated/invalid document structure - * When application starts - * Then index deleted and recreated with up-to-date document structure - */ - @Test - @Order(1) - fun recreateOutdatedIndexOnStartup() { - // bogus document should not be in index anymore - val getResponse = - openSearchClient.get({ getRequest -> getRequest.index(LEGAL_ENTITIES_INDEX_NAME).id(bpnBogusDocument) }, InvalidBusinessPartnerDoc::class.java) - assertThat(getResponse.found()).isFalse - - //import a business partner to DB - testHelpers.createTestMetadata() - testHelpers.createBusinessPartnerStructure( - listOf( - LegalEntityStructureRequest( - legalEntity = BusinessPartnerNonVerboseValues.legalEntityCreate1, - ) - ) - ) - //export to index and check whether the imported business partner can be found as normal - testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) - - val searchResult = poolClient.legalEntities.getLegalEntities( - LegalEntityPropertiesSearchRequest.EmptySearchRequest, - PaginationRequest() - ) - - assertThat(searchResult.content).isNotEmpty - assertThat(searchResult.contentSize).isEqualTo(1) - } - - private data class InvalidBusinessPartnerDoc( - val outdatedField: String = "" - ) -} \ No newline at end of file diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/ValidIndexStartupIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/ValidIndexStartupIT.kt deleted file mode 100644 index f0a824fd1..000000000 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/ValidIndexStartupIT.kt +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch - -import org.assertj.core.api.Assertions -import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest -import org.eclipse.tractusx.bpdm.pool.Application -import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl -import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPropertiesSearchRequest -import org.eclipse.tractusx.bpdm.pool.util.* -import org.junit.jupiter.api.MethodOrderer -import org.junit.jupiter.api.Order -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestMethodOrder -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.annotation.DirtiesContext -import org.springframework.test.context.ActiveProfiles -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.web.reactive.server.WebTestClient - -@SpringBootTest( - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class] -) -@ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) -@TestMethodOrder(MethodOrderer.OrderAnnotation::class) -class ValidIndexStartupIT @Autowired constructor( - val webTestClient: WebTestClient, - val testHelpers: TestHelpers, - val poolClient: PoolClientImpl -) { - - - /** - * Not a real test but prepares the OpenSearch container for the next test that will be run in a fresh Spring-Boot context - * Create a valid OpenSearch index and fill it with content - */ - @Test - @Order(0) - @DirtiesContext - fun setupIndexForNextTest() { - testHelpers.truncateDbTables() - testHelpers.createTestMetadata() - //Clear and set up a fresh valid OpenSearch context - // webTestClient.invokeDeleteEndpointWithoutResponse(EndpointValues.OPENSEARCH_SYNC_PATH) - poolClient.opensearch.clear() - - //Import values to DB - testHelpers.createBusinessPartnerStructure( - listOf( - LegalEntityStructureRequest( - legalEntity = BusinessPartnerNonVerboseValues.legalEntityCreate1, - ), - LegalEntityStructureRequest( - legalEntity = BusinessPartnerNonVerboseValues.legalEntityCreate2, - ), - LegalEntityStructureRequest( - legalEntity = BusinessPartnerNonVerboseValues.legalEntityCreate3, - ) - ) - ) - - //Export to OpenSearch index - testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) - //Make sure entries are indeed there - val searchResult = poolClient.legalEntities.getLegalEntities( - LegalEntityPropertiesSearchRequest.EmptySearchRequest, - PaginationRequest() - ) - Assertions.assertThat(searchResult.content).isNotEmpty - Assertions.assertThat(searchResult.contentSize).isEqualTo(3) - } - - /** - * Given non-empty OpenSearch index with up-to-date document structure - * When application starts - * Then index not cleared - */ - @Test - @Order(1) - fun acceptValidIndexOnStartup() { - - val searchResult = poolClient.legalEntities.getLegalEntities( - LegalEntityPropertiesSearchRequest.EmptySearchRequest, - PaginationRequest() - ) - Assertions.assertThat(searchResult.content).isNotEmpty - Assertions.assertThat(searchResult.contentSize).isEqualTo(3) - } -} \ No newline at end of file diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/controller/OpenSearchControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/controller/OpenSearchControllerIT.kt deleted file mode 100644 index 3ea7b835c..000000000 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/component/opensearch/controller/OpenSearchControllerIT.kt +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.component.opensearch.controller - - -import com.fasterxml.jackson.databind.ObjectMapper -import org.assertj.core.api.Assertions.assertThat -import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest -import org.eclipse.tractusx.bpdm.common.dto.response.PageDto -import org.eclipse.tractusx.bpdm.pool.Application -import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl -import org.eclipse.tractusx.bpdm.pool.api.model.request.BusinessPartnerSearchRequest -import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPropertiesSearchRequest -import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityMatchVerboseDto -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service.OpenSearchSyncStarterService -import org.eclipse.tractusx.bpdm.pool.component.opensearch.impl.service.SearchServiceImpl -import org.eclipse.tractusx.bpdm.pool.util.* -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Test -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.context.ActiveProfiles -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.web.reactive.server.WebTestClient - - -/** - * Integration tests for the data sync endpoints in the OpenSearchController - */ -@SpringBootTest( - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class] -) -@ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) -class OpenSearchControllerIT @Autowired constructor( - private val webTestClient: WebTestClient, - private val openSearchSyncService: OpenSearchSyncStarterService, - private val objectMapper: ObjectMapper, - private val testHelpers: TestHelpers, - private val poolClient: PoolClientImpl, - private val searchService: SearchServiceImpl -) { - - - - // We import 3 legal entities which result in 6 OpenSearch records: 3 for the LEs itself and 3 for the corresponding legal addresses. - val partnerDocs = listOf( - BusinessPartnerNonVerboseValues.legalEntityCreate1, - BusinessPartnerNonVerboseValues.legalEntityCreate2, - BusinessPartnerNonVerboseValues.legalEntityCreate3 - ) - - @BeforeEach - fun beforeEach() { - testHelpers.truncateDbTables() - openSearchSyncService.clearOpenSearch() - - val importCollection = PageDto( - partnerDocs.size.toLong(), - 1, - 0, - partnerDocs.size, - partnerDocs - ) - - testHelpers.createTestMetadata() - testHelpers.createBusinessPartnerStructure( - listOf( - LegalEntityStructureRequest( - legalEntity = BusinessPartnerNonVerboseValues.legalEntityCreate1, - ), - LegalEntityStructureRequest( - legalEntity = BusinessPartnerNonVerboseValues.legalEntityCreate2, - ), - LegalEntityStructureRequest( - legalEntity = BusinessPartnerNonVerboseValues.legalEntityCreate3, - ) - ) - ) - - } - - - /** - * Given partners in database already exported - * When export - * Then partners are not exported to OpenSearch - */ - @Test - fun `export only new partners`() { - //export once to get partners into opensearch for given system state - var exportResponse = testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) - - assertThat(exportResponse.count).isEqualTo(6) - assertSearchableByNames(partnerDocs.map { it.legalName }) - - //export now to check behaviour - exportResponse = testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) - - assertThat(exportResponse.count).isEqualTo(0) - } - - /** - * Given new partners in database - * When export - * Then new partners can be searched - */ - @Test - fun `can search exported partners`() { - val exportResponse = testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) - - // We have - assertThat(exportResponse.count).isEqualTo(6) - assertSearchableByNames(partnerDocs.map { it.legalName }) - } - - /** - * Given partners in OpenSearch - * When delete index - * Then partners can't be searched anymore - */ - @Test - fun `empty index`() { - val names = partnerDocs.map { it.legalName } - - // fill the opensearch index - val exportResponse = testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) - - assertThat(exportResponse.count).isEqualTo(6) - assertSearchableByNames(names) - - //clear the index - poolClient.opensearch.clear() - - //check that the partners can really not be searched anymore - names.forEach { assertThat(searchBusinessPartnerByName(it)).matches { it.contentSize == 0 } } - } - - /** - * Given partners in OpenSearch - * When delete index and export - * Then partners again in OpenSearch - */ - @Test - fun `export all partners after empty index`() { - - // fill the opensearch index - testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) - - - //clear the index - poolClient.opensearch.clear() - - - //export partners again - val exportResponse = testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) - - assertThat(exportResponse.count).isEqualTo(6) - assertSearchableByNames(partnerDocs.map { it.legalName }) - - } - - private fun searchBusinessPartnerByName(name: String): PageDto { - - return searchService.searchLegalEntities( - BusinessPartnerSearchRequest(LegalEntityPropertiesSearchRequest(name)), - PaginationRequest() - ) - } - - private fun assertSearchableByNames(names: Collection) { - names.forEach { name -> - val pageResult = searchBusinessPartnerByName(name) - - assertThat(pageResult.content).isNotEmpty - assertThat(pageResult.content.first()).matches { it.legalName == name } - } - } - - -} \ No newline at end of file diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt index 395468d7e..394c0dc7d 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerIT.kt @@ -39,7 +39,7 @@ import org.springframework.test.context.ContextConfiguration @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class]) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) class AddressControllerIT @Autowired constructor( val testHelpers: TestHelpers, val poolClient: PoolApiClient diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerSearchIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerSearchIT.kt index 1b59385b8..d7aa76a4d 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerSearchIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/AddressControllerSearchIT.kt @@ -41,7 +41,7 @@ import org.springframework.test.web.reactive.server.WebTestClient @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class]) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) class AddressControllerSearchIT @Autowired constructor( val webTestClient: WebTestClient, val testHelpers: TestHelpers, @@ -83,19 +83,16 @@ class AddressControllerSearchIT @Autowired constructor( fun beforeEach() { testHelpers.truncateDbTables() - poolClient.opensearch.clear() testHelpers.createTestMetadata() val givenStructure = testHelpers.createBusinessPartnerStructure(listOf(partnerStructure3)) givenAddress1 = givenStructure[0].addresses[0].address // addressPartnerCreate1 - - testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) } /** - * Given addresses in OpenSearch + * Given addresses * When searching an address by name of BPN search criteria * Then the matching address is returned */ @@ -117,7 +114,7 @@ class AddressControllerSearchIT @Autowired constructor( } /** - * Given addresses in OpenSearch + * Given addresses * When searching an address by name of BPN that not exists in search criteria * Then the matching address is not found */ diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/BpnControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/BpnControllerIT.kt index c21fff09e..d2c9282e1 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/BpnControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/BpnControllerIT.kt @@ -25,7 +25,10 @@ import org.eclipse.tractusx.bpdm.common.dto.LegalEntityIdentifierDto import org.eclipse.tractusx.bpdm.pool.Application import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl import org.eclipse.tractusx.bpdm.pool.api.model.request.IdentifiersSearchRequest -import org.eclipse.tractusx.bpdm.pool.util.* +import org.eclipse.tractusx.bpdm.pool.util.BusinessPartnerNonVerboseValues +import org.eclipse.tractusx.bpdm.pool.util.LegalEntityStructureRequest +import org.eclipse.tractusx.bpdm.pool.util.PostgreSQLContextInitializer +import org.eclipse.tractusx.bpdm.pool.util.TestHelpers import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired @@ -38,7 +41,7 @@ import org.springframework.test.context.ContextConfiguration properties = ["bpdm.controller.search-request-limit=2"] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) class BpnControllerIT @Autowired constructor( val testHelpers: TestHelpers, val poolClient: PoolClientImpl diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/ChangelogControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/ChangelogControllerIT.kt index 1ced5aad4..935d53d63 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/ChangelogControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/ChangelogControllerIT.kt @@ -36,14 +36,13 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.ActiveProfiles import org.springframework.test.context.ContextConfiguration import java.time.Instant -import java.util.* @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class], properties = ["bpdm.controller.search-request-limit=2"] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class,OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) class ChangelogControllerIT @Autowired constructor( val testHelpers: TestHelpers, val poolClient: PoolClientImpl diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt index d32c07db2..c20ab407b 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerIT.kt @@ -27,7 +27,10 @@ import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressVerboseDto import org.eclipse.tractusx.bpdm.common.dto.response.PoolLegalEntityVerboseDto import org.eclipse.tractusx.bpdm.pool.Application import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl -import org.eclipse.tractusx.bpdm.pool.api.model.response.* +import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalAddressVerboseDto +import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityCreateError +import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityPartnerCreateVerboseDto +import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityUpdateError import org.eclipse.tractusx.bpdm.pool.util.* import org.eclipse.tractusx.bpdm.pool.util.BusinessPartnerNonVerboseValues.addressIdentifier import org.eclipse.tractusx.bpdm.pool.util.BusinessPartnerNonVerboseValues.logisticAddress3 @@ -46,7 +49,7 @@ import java.time.Instant webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) class LegalEntityControllerIT @Autowired constructor( val testHelpers: TestHelpers, val webTestClient: WebTestClient, diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerSearchIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerSearchIT.kt index 7f751a06e..ebdc0f845 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerSearchIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/LegalEntityControllerSearchIT.kt @@ -44,7 +44,7 @@ import org.springframework.test.web.reactive.server.WebTestClient webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class] ) @ActiveProfiles(value = ["test"]) -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) class LegalEntityControllerSearchIT @Autowired constructor( val webTestClient: WebTestClient, val testHelpers: TestHelpers, @@ -76,7 +76,6 @@ class LegalEntityControllerSearchIT @Autowired constructor( fun beforeEach() { testHelpers.truncateDbTables() - poolClient.opensearch.clear() testHelpers.createTestMetadata() val givenStructure = testHelpers.createBusinessPartnerStructure(listOf(partnerStructure1, partnerStructure2)) givenPartner1 = with(givenStructure[0].legalEntity) { legalEntity } @@ -85,11 +84,10 @@ class LegalEntityControllerSearchIT @Autowired constructor( legalName2 = givenStructure[1].legalEntity.legalName legalAddress1 = givenStructure[0].legalEntity.legalAddress legalAddress2 = givenStructure[1].legalEntity.legalAddress - testHelpers.startSyncAndAwaitSuccess(webTestClient, EndpointValues.OPENSEARCH_SYNC_PATH) } /** - * Given partners with same siteName in OpenSearch + * Given partners with same siteName * When searching by site name and requesting page with multiple items * Then response contains correct pagination values */ @@ -110,7 +108,7 @@ class LegalEntityControllerSearchIT @Autowired constructor( } /** - * Given partners with same siteName in OpenSearch + * Given partners with same siteName * When searching by site name and requesting multiple pages * Then responses contains correct pagination values */ @@ -135,36 +133,6 @@ class LegalEntityControllerSearchIT @Autowired constructor( assertPageEquals(secondPage, expectedSecondPage) } -// /** -// * Given partners in OpenSearch -// * When searching by site name -// * Then business partner is found -// */ -// @Test -// fun `search business partner by site name, result found`() { -// -// val expected = PageResponse( -// 1, 1, 0, 1, listOf( -// LegalEntityMatchResponse(score = 0f, legalEntity = givenPartner2, legalName = legalName2, legalAddress = legalAddress2) -// ) -// ) -// -// val pageResponse = searchBusinessPartnerBySiteName(RequestValues.siteCreate2.site.name, 0, 10) -// -// assertPageEquals(pageResponse, expected) -// } - - /** - * Given partners in OpenSearch - * When searching by nonexistent site name - * Then no business partner is found - */ -// @Test -// fun `search business partner by site name, no result found`() { -// val foundPartners = searchBusinessPartnerBySiteName("nonexistent name", 0, 10).content -// assertThat(foundPartners).isEmpty() -// } - private fun searchBusinessPartnerBySiteName(siteName: String, page: Int, size: Int): PageDto { val sitePropertiesSearchRequest = SitePropertiesSearchRequest(siteName) diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt index 15c65d56a..9ac1d6f6a 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/MetadataControllerIT.kt @@ -61,7 +61,7 @@ private typealias GetFunction = (client: WebTestClient, page: Int, size: Int) -> webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) class MetadataControllerIT @Autowired constructor( private val testHelpers: TestHelpers, private val webTestClient: WebTestClient, diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt index bcb3a6cf3..db667cce8 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/controller/SiteControllerIT.kt @@ -25,7 +25,9 @@ import org.eclipse.tractusx.bpdm.common.dto.IdentifierTypeDto import org.eclipse.tractusx.bpdm.common.dto.SiteDto import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest import org.eclipse.tractusx.bpdm.common.dto.request.SiteBpnSearchRequest -import org.eclipse.tractusx.bpdm.common.dto.response.* +import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressVerboseDto +import org.eclipse.tractusx.bpdm.common.dto.response.PageDto +import org.eclipse.tractusx.bpdm.common.dto.response.SiteVerboseDto import org.eclipse.tractusx.bpdm.pool.Application import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl import org.eclipse.tractusx.bpdm.pool.api.model.response.* @@ -40,7 +42,7 @@ import java.time.Instant @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class, TestHelpers::class]) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class,OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) class SiteControllerIT @Autowired constructor( val testHelpers: TestHelpers, val poolClient: PoolClientImpl diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveServiceTest.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveServiceTest.kt index df8ca392e..e2e0c6338 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveServiceTest.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskStepFetchAndReserveServiceTest.kt @@ -6,7 +6,6 @@ import org.eclipse.tractusx.bpdm.pool.Application import org.eclipse.tractusx.bpdm.pool.api.client.PoolClientImpl import org.eclipse.tractusx.bpdm.pool.repository.BpnRequestIdentifierRepository import org.eclipse.tractusx.bpdm.pool.service.TaskStepBuildService.CleaningError -import org.eclipse.tractusx.bpdm.pool.util.OpenSearchContextInitializer import org.eclipse.tractusx.bpdm.pool.util.PostgreSQLContextInitializer import org.eclipse.tractusx.bpdm.pool.util.TestHelpers import org.eclipse.tractusx.orchestrator.api.model.* @@ -22,7 +21,7 @@ import org.springframework.test.context.ContextConfiguration webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [Application::class] ) @ActiveProfiles("test") -@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class, OpenSearchContextInitializer::class]) +@ContextConfiguration(initializers = [PostgreSQLContextInitializer::class]) class TaskStepFetchAndReserveServiceTest @Autowired constructor( val cleaningStepService: TaskStepFetchAndReserveService, val bpnRequestIdentifierRepository: BpnRequestIdentifierRepository, diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/EndpointValues.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/EndpointValues.kt index 8701c62ee..bbbd922d4 100644 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/EndpointValues.kt +++ b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/EndpointValues.kt @@ -25,9 +25,6 @@ object EndpointValues { const val CATENA_LEGAL_ENTITY_PATH = "$CATENA_PATH/legal-entities" - - const val OPENSEARCH_SYNC_PATH = "api/opensearch/business-partner" - const val CATENA_METADATA_IDENTIFIER_TYPE_PATH = "$CATENA_PATH/identifier-types" const val CATENA_METADATA_LEGAL_FORM_PATH = "$CATENA_PATH/legal-forms" diff --git a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/OpenSearchContextInitializer.kt b/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/OpenSearchContextInitializer.kt deleted file mode 100644 index 45722a73a..000000000 --- a/bpdm-pool/src/test/kotlin/org/eclipse/tractusx/bpdm/pool/util/OpenSearchContextInitializer.kt +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2021,2023 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ******************************************************************************/ - -package org.eclipse.tractusx.bpdm.pool.util - -import com.github.dockerjava.api.model.Ulimit -import org.springframework.boot.test.util.TestPropertyValues -import org.springframework.context.ApplicationContextInitializer -import org.springframework.context.ConfigurableApplicationContext -import org.testcontainers.containers.GenericContainer -import org.testcontainers.containers.wait.strategy.HttpWaitStrategy - -/** - * When used on a spring boot test, starts a singleton opensearch container that is shared between all integration tests. - */ -class OpenSearchContextInitializer : ApplicationContextInitializer { - companion object { - private const val OPENSEARCH_PORT = 9200 - - private val openSearchContainer: GenericContainer<*> = GenericContainer("opensearchproject/opensearch:2.1.0") - .withExposedPorts(OPENSEARCH_PORT) - .waitingFor(HttpWaitStrategy() - .forPort(OPENSEARCH_PORT) - .forStatusCodeMatching { response -> response == 200 || response == 401 } - ) - // based on sample docker-compose for development from https://opensearch.org/docs/latest/opensearch/install/docker - .withEnv("cluster.name", "opensearch-cluster") - .withEnv("node.name", "bpdm-opensearch") - .withEnv("bootstrap.memory_lock", "true") - .withEnv("OPENSEARCH_JAVA_OPTS", "-Xms512m -Xmx512m") - .withEnv("DISABLE_INSTALL_DEMO_CONFIG", "true") - .withEnv("DISABLE_SECURITY_PLUGIN", "true") - .withEnv("discovery.type", "single-node") - .withCreateContainerCmdModifier { cmd -> - cmd.hostConfig!!.withUlimits(arrayOf(Ulimit("nofile", 65536L, 65536L), Ulimit("memlock", -1L, -1L))) - } - } - - override fun initialize(applicationContext: ConfigurableApplicationContext) { - openSearchContainer.start() - TestPropertyValues.of( - "bpdm.opensearch.host=${openSearchContainer.host}", - "bpdm.opensearch.port=${openSearchContainer.getMappedPort(OPENSEARCH_PORT)}", - "bpdm.opensearch.scheme=http" - ).applyTo(applicationContext.environment) - } -} \ No newline at end of file diff --git a/bpdm-pool/src/test/resources/application-test.properties b/bpdm-pool/src/test/resources/application-test.properties index 764c3af1a..d0a171dfa 100644 --- a/bpdm-pool/src/test/resources/application-test.properties +++ b/bpdm-pool/src/test/resources/application-test.properties @@ -16,8 +16,6 @@ # # SPDX-License-Identifier: Apache-2.0 ################################################################################ -# tests need to see changes in opensearch immediately, not just after waiting some time for automatic refresh -bpdm.opensearch.refresh-on-write=true logging.level.root=INFO # limit db connection pool size since connection pools are only closed when spring context is deleted spring.datasource.hikari.maximum-pool-size=2 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 641a66bc2..bd4a1678a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,33 +18,6 @@ services: volumes: - bpdm-postgres-data:/var/lib/postgresql/data - # based on sample docker-compose for development from https://opensearch.org/docs/latest/opensearch/install/docker - opensearch: - image: opensearchproject/opensearch:2.1.0 - container_name: bpdm-opensearch - environment: - - cluster.name=opensearch-cluster - - node.name=bpdm-opensearch - - bootstrap.memory_lock=true # along with the memlock settings below, disables swapping - - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM - - "DISABLE_INSTALL_DEMO_CONFIG=true" # disables execution of install_demo_configuration.sh bundled with security plugin, which installs demo certificates and security configurations to OpenSearch - - "DISABLE_SECURITY_PLUGIN=true" # disables security plugin entirely in OpenSearch by setting plugins.security.disabled: true in opensearch.yml - - "discovery.type=single-node" # disables bootstrap checks that are enabled when network.host is set to a non-loopback address - ulimits: - memlock: - soft: -1 - hard: -1 - nofile: - soft: 65536 # maximum number of open files for the OpenSearch user, set to at least 65536 on modern systems - hard: 65536 - volumes: - - bpdm-opensearch-data:/usr/share/opensearch/data - ports: - - 9200:9200 - - 9600:9600 # required for Performance Analyzer - volumes: bpdm-postgres-data: name: bpdm-postgres-data - bpdm-opensearch-data: - name: bpdm-opensearch-data diff --git a/pom.xml b/pom.xml index 295981943..a0496ec51 100644 --- a/pom.xml +++ b/pom.xml @@ -66,8 +66,6 @@ 3.9.1.2184 0.8.7 1.18.3 - 2.5.0 - 2.0.0 @@ -151,21 +149,6 @@ kotlin-logging-jvm ${kotlinlogging.version} - - org.opensearch.client - opensearch-rest-high-level-client - ${opensearch.version} - - - org.opensearch.client - opensearch-rest-client - ${opensearch.version} - - - org.opensearch.client - opensearch-java - ${opensearch-java.version} -