Skip to content

Commit

Permalink
Merge pull request #990 from eclipse-tractusx/feat/orch-persistence-jpa
Browse files Browse the repository at this point in the history
Feat(Orchestrator): Add persistence to Golden Record Tasks
  • Loading branch information
SujitMBRDI authored Jul 11, 2024
2 parents 6299ee8 + 0febf9f commit 879381a
Show file tree
Hide file tree
Showing 39 changed files with 1,662 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
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,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.*
import org.eclipse.tractusx.bpdm.common.model.BusinessStateType

@Embeddable
data class BusinessStateDb(
@Convert(converter = DbTimestampConverter::class)
@Column(name = "valid_from")
val validFrom: DbTimestamp?,
@Convert(converter = DbTimestampConverter::class)
@Column(name = "valid_to")
val validTo: DbTimestamp?,
@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,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.Convert
import jakarta.persistence.Embeddable

@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?,
@Convert(converter = DbTimestampConverter::class)
@Column(name = "last_confidence_check")
val lastConfidenceCheckAt: DbTimestamp?,
@Convert(converter = DbTimestampConverter::class)
@Column(name = "next_confidence_check")
val nextConfidenceCheckAt: DbTimestamp?,
@Column(name = "confidence_level")
val confidenceLevel: Int?
) {
enum class Scope {
LegalEntity,
Site,
LegalAddress,
SiteMainAddress,
AdditionalAddress,
UncategorizedAddress
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* 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 java.time.Instant
import java.time.temporal.ChronoUnit

/**
* This helper type makes sure that all timestamps on the entities are actually truncated to microseconds (same as in the database)
*
* This makes sure that timestamps in entities and database are always equal even before the entity is persisted in the database
*/
class DbTimestamp(instant: Instant){
private val truncatedInstant = instant.truncatedTo(ChronoUnit.MICROS)

val instant get(): Instant = truncatedInstant

companion object{
fun now(): DbTimestamp = Instant.now().toTimestamp()
}
}

fun Instant.toTimestamp(): DbTimestamp = DbTimestamp(this)
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,20 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.orchestrator.model
package org.eclipse.tractusx.bpdm.orchestrator.entity

import org.eclipse.tractusx.orchestrator.api.model.*
import java.time.Instant
import jakarta.persistence.AttributeConverter
import jakarta.persistence.Converter
import java.sql.Timestamp

data class TaskProcessingState(
val mode: TaskMode,
var resultState: ResultState,
var errors: List<TaskErrorDto> = emptyList(),
@Converter
class DbTimestampConverter: AttributeConverter<DbTimestamp, Timestamp> {
override fun convertToDatabaseColumn(p0: DbTimestamp?): Timestamp? {
return p0?.let { Timestamp.from(it.instant) }
}

var step: TaskStep,
var stepState: StepState,
override fun convertToEntityAttribute(p0: Timestamp?): DbTimestamp? {
return p0?.let { DbTimestamp(p0.toInstant()) }
}

val taskCreatedAt: Instant,
var taskModifiedAt: Instant,

// only used while in resultState==pending
var taskPendingTimeout: Instant?,
// only used while in final resultState (!=pending)
var taskRetentionTimeout: Instant?
)
}
Loading

0 comments on commit 879381a

Please sign in to comment.