Skip to content

Commit

Permalink
feat(Orchestrator): add persistence layer
Browse files Browse the repository at this point in the history
- add jpa entity model
- adapted tests to use entity model where appropriate and setup a test database
- added a postgres dependency to the Orchestrator chart
  • Loading branch information
nicoprow committed Jul 9, 2024
1 parent 201db14 commit 3af8258
Show file tree
Hide file tree
Showing 36 changed files with 1,616 additions and 302 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ For changes to the BPDM Helm charts please consult the [changelog](charts/bpdm/C
- BPDM Gate: Post endpoint to upload business partner input data using csv file.(#700)
- BPDM Gate: GET endpoint to download the csv file template for business partner upload. (#700)
- Apps: Tax Jurisdiction Code to the physical address of a business partner (#955)
- BPDM Orchestrator: Tasks will now be persisted

### Changed:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.testcontainers.containers.PostgreSQLContainer
*/
class PostgreSQLContextInitializer : ApplicationContextInitializer<ConfigurableApplicationContext> {
companion object {
val postgreSQLContainer = PostgreSQLContainer("postgres:13.2")
val postgreSQLContainer = PostgreSQLContainer("postgres:15.4")
.withAccessToHost(true)
.withNetwork(Network.SHARED)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class DbTestHelpers(private val entityManagerFactory: EntityManagerFactory?) {
truncateDbTablesFromSchema("bpdm")
truncateDbTablesFromSchema("bpdmgate")
truncateDbTablesFromSchema("bpdm-bridge-dummy")
truncateDbTablesFromSchema("bpdm-orchestrator")
}

private fun truncateDbTablesFromSchema(dbSchemaName: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ fun <T> MutableCollection<T>.replace(elements: Collection<T>) {
addAll(elements)
}

fun <K, V> MutableMap<K, V>.replace(map: Map<K, V>) {
clear()
putAll(map)
}


/**
* Copy overlapping elements by index from [elements] to [this] collection by applying the [copyFunction].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.orchestrator.model
package org.eclipse.tractusx.bpdm.common.util

import org.eclipse.tractusx.orchestrator.api.model.BusinessPartner

data class GoldenRecordTask(
val taskId: String,
var businessPartner: BusinessPartner,
val processingState: TaskProcessingState
)
import java.sql.Timestamp
import java.time.Instant
import java.time.temporal.ChronoUnit

fun Instant.toTimestamp(): Timestamp = Timestamp.from(this.truncatedTo(ChronoUnit.MICROS))
14 changes: 14 additions & 0 deletions bpdm-orchestrator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Manage database migrations -->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>

<!-- Test -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
package org.eclipse.tractusx.bpdm.orchestrator

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.runApplication
import org.springframework.scheduling.annotation.EnableScheduling


@SpringBootApplication(exclude = [DataSourceAutoConfiguration::class])
@SpringBootApplication
@ConfigurationPropertiesScan
@EnableScheduling
class Application
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* Copyright (c) 2021,2024 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.orchestrator.entity

import jakarta.persistence.Column
import jakarta.persistence.Embeddable
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import org.eclipse.tractusx.orchestrator.api.model.BpnReferenceType

@Embeddable
data class BpnReferenceDb(
@Column(name = "value")
val referenceValue: String?,
@Column(name = "desired_bpn")
val desiredBpn: String?,
@Enumerated(EnumType.STRING)
@Column(name = "type")
val referenceType: BpnReferenceType?
) {
enum class Scope {
LegalEntity,
Site,
LegalAddress,
SiteMainAddress,
AdditionalAddress,
UncategorizedAddress
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2021,2024 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.orchestrator.entity

import jakarta.persistence.Column
import jakarta.persistence.Embeddable
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import org.eclipse.tractusx.bpdm.common.model.BusinessStateType
import java.sql.Timestamp

@Embeddable
data class BusinessStateDb(
@Column(name = "valid_from")
val validFrom: Timestamp?,
@Column(name = "valid_to")
val validTo: Timestamp?,
@Enumerated(EnumType.STRING)
@Column(name = "type")
val type: BusinessStateType?,
@Enumerated(EnumType.STRING)
@Column(name = "scope", nullable = false)
val scope: Scope
) {
enum class Scope {
LegalEntity,
Site,
Uncategorized,
LegalAddress,
SiteMainAddress,
AdditionalAddress,
UncategorizedAddress
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2021,2024 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.orchestrator.entity

import jakarta.persistence.Column
import jakarta.persistence.Embeddable
import java.sql.Timestamp

@Embeddable
data class ConfidenceCriteriaDb(
@Column(name = "shared_by_owner")
val sharedByOwner: Boolean?,
@Column(name = "checked_by_external_datasource")
val checkedByExternalDataSource: Boolean?,
@Column(name = "number_of_sharing_members")
val numberOfSharingMembers: Int?,
@Column(name = "last_confidence_check")
val lastConfidenceCheckAt: Timestamp?,
@Column(name = "next_confidence_check")
val nextConfidenceCheckAt: Timestamp?,
@Column(name = "confidence_level")
val confidenceLevel: Int?
) {
enum class Scope {
LegalEntity,
Site,
LegalAddress,
SiteMainAddress,
AdditionalAddress,
UncategorizedAddress
}
}
Loading

0 comments on commit 3af8258

Please sign in to comment.