-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Orchestrator): add persistence layer
- 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
Showing
34 changed files
with
1,577 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...hestrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/entity/BpnReferenceDb.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...estrator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/entity/BusinessStateDb.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.time.Instant | ||
|
||
@Embeddable | ||
data class BusinessStateDb( | ||
@Column(name = "valid_from") | ||
val validFrom: Instant?, | ||
@Column(name = "valid_to") | ||
val validTo: Instant?, | ||
@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 | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...tor/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/entity/ConfidenceCriteriaDb.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.time.Instant | ||
|
||
@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: Instant?, | ||
@Column(name = "next_confidence_check") | ||
val nextConfidenceCheckAt: Instant?, | ||
@Column(name = "confidence_level") | ||
val confidenceLevel: Int? | ||
) { | ||
enum class Scope { | ||
LegalEntity, | ||
Site, | ||
LegalAddress, | ||
SiteMainAddress, | ||
AdditionalAddress, | ||
UncategorizedAddress | ||
} | ||
} |
176 changes: 176 additions & 0 deletions
176
...rator/src/main/kotlin/org/eclipse/tractusx/bpdm/orchestrator/entity/GoldenRecordTaskDb.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/******************************************************************************* | ||
* 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.util.replace | ||
import org.eclipse.tractusx.orchestrator.api.model.* | ||
import java.time.Instant | ||
import java.util.* | ||
|
||
@Entity | ||
@Table( | ||
name = "golden_record_tasks", | ||
indexes = [ | ||
Index(name = "index_tasks_uuid", columnList = "uuid"), | ||
Index(name = "index_tasks_step_step_state", columnList = "task_step,task_step_state"), | ||
Index(name = "index_tasks_pending_timeout", columnList = "task_pending_timeout"), | ||
Index(name = "index_tasks_retention_timeout", columnList = "task_retention_timeout") | ||
] | ||
) | ||
class GoldenRecordTaskDb( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "bpdm_sequence") | ||
@SequenceGenerator(name = "bpdm_sequence", sequenceName = "bpdm_sequence", allocationSize = 1) | ||
@Column(name = "id", nullable = false, updatable = false, insertable = false) | ||
val id: Long = 0, | ||
|
||
@Column(name = "uuid", nullable = false, updatable = false, unique = true, columnDefinition = "uuid") | ||
val uuid: UUID = UUID.randomUUID(), | ||
|
||
@Column(updatable = false, nullable = false, name = "CREATED_AT") | ||
var createdAt: Instant = Instant.now(), | ||
|
||
@Column(nullable = false, name = "UPDATED_AT") | ||
var updatedAt: Instant = createdAt, | ||
@Embedded | ||
val processingState: ProcessingState, | ||
@Embedded | ||
val businessPartner: BusinessPartner | ||
) { | ||
fun updateBusinessPartner(newBusinessPartnerData: BusinessPartner){ | ||
with(newBusinessPartnerData){ | ||
//Trick to make sure on a change to the business partner model | ||
// we get a compile error if we don't also adjust this update method | ||
// We discard the created business partner object afterward, it is just there for this check | ||
BusinessPartner( | ||
nameParts = nameParts.also { businessPartner.nameParts.replace(it) }, | ||
identifiers = identifiers.also { businessPartner.identifiers.replace(it) }, | ||
businessStates = businessStates.also { businessPartner.businessStates.replace(it) }, | ||
confidences = confidences.also { businessPartner.confidences.replace(it) }, | ||
addresses = addresses.also { businessPartner.addresses.replace(it) }, | ||
bpnReferences = bpnReferences.also { businessPartner.bpnReferences.replace(it) }, | ||
legalName = legalName.also { businessPartner.legalName = it }, | ||
legalShortName = legalShortName.also { businessPartner.legalShortName = it }, | ||
siteExists = siteExists.also { businessPartner.siteExists = it }, | ||
siteName = siteName.also { businessPartner.siteName = it }, | ||
legalForm = legalForm.also { businessPartner.legalForm = it }, | ||
isCatenaXMemberData = isCatenaXMemberData.also { businessPartner.isCatenaXMemberData = it }, | ||
owningCompany = owningCompany.also { businessPartner.owningCompany = it }, | ||
legalEntityHasChanged = legalEntityHasChanged.also { businessPartner.legalEntityHasChanged = it }, | ||
siteHasChanged = siteHasChanged.also { businessPartner.siteHasChanged = it } | ||
) | ||
} | ||
} | ||
|
||
@Embeddable | ||
class ProcessingState( | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "task_mode", nullable = false) | ||
var mode: TaskMode, | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "task_result_state", nullable = false) | ||
var resultState: ResultState, | ||
@ElementCollection | ||
@CollectionTable(name = "task_errors", joinColumns = [JoinColumn(name = "task_id", foreignKey = ForeignKey(name = "fk_errors_tasks"))]) | ||
val errors: MutableList<TaskErrorDb>, | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "task_step", nullable = false) | ||
var step: TaskStep, | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "task_step_state", nullable = false) | ||
var stepState: StepState, | ||
@Column(name = "task_pending_timeout") | ||
var pendingTimeout: Instant?, | ||
@Column(name = "task_retention_timeout") | ||
var retentionTimeout: Instant? | ||
) | ||
|
||
@Embeddable | ||
class BusinessPartner( | ||
@ElementCollection(fetch = FetchType.EAGER) | ||
@OrderColumn(name = "index", nullable = false) | ||
@CollectionTable( | ||
name = "business_partner_name_parts", | ||
joinColumns = [JoinColumn(name = "task_id", foreignKey = ForeignKey(name = "fk_name_parts_tasks"))] | ||
) | ||
val nameParts: MutableList<NamePartDb>, | ||
@ElementCollection(fetch = FetchType.EAGER) | ||
@OrderColumn(name = "index", nullable = false) | ||
@CollectionTable( | ||
name = "business_partner_identifiers", | ||
joinColumns = [JoinColumn(name = "task_id", foreignKey = ForeignKey(name = "fk_identifiers_tasks"))] | ||
) | ||
val identifiers: MutableList<IdentifierDb>, | ||
@ElementCollection(fetch = FetchType.EAGER) | ||
@OrderColumn(name = "index", nullable = false) | ||
@CollectionTable( | ||
name = "business_partner_states", | ||
joinColumns = [JoinColumn(name = "task_id", foreignKey = ForeignKey(name = "fk_states_tasks"))] | ||
) | ||
val businessStates: MutableList<BusinessStateDb>, | ||
@ElementCollection(fetch = FetchType.EAGER) | ||
@MapKeyColumn(name = "scope") | ||
@MapKeyEnumerated(EnumType.STRING) | ||
@CollectionTable( | ||
name = "business_partner_confidences", | ||
joinColumns = [JoinColumn(name = "task_id", foreignKey = ForeignKey(name = "fk_confidences_tasks"))], | ||
uniqueConstraints = [UniqueConstraint(name = "uc_business_partner_confidences_task_scope", columnNames = ["task_id", "scope"])] | ||
) | ||
val confidences: MutableMap<ConfidenceCriteriaDb.Scope, ConfidenceCriteriaDb>, | ||
@ElementCollection(fetch = FetchType.EAGER) | ||
@MapKeyColumn(name = "scope") | ||
@MapKeyEnumerated(EnumType.STRING) | ||
@CollectionTable( | ||
name = "business_partner_addresses", | ||
joinColumns = [JoinColumn(name = "task_id", foreignKey = ForeignKey(name = "fk_addresses_tasks"))], | ||
uniqueConstraints = [UniqueConstraint(name = "uc_business_partner_addresses_task_scope", columnNames = ["task_id", "scope"])] | ||
) | ||
val addresses: MutableMap<PostalAddressDb.Scope, PostalAddressDb>, | ||
@ElementCollection(fetch = FetchType.EAGER) | ||
@MapKeyColumn(name = "scope") | ||
@MapKeyEnumerated(EnumType.STRING) | ||
@CollectionTable( | ||
name = "business_partner_bpn_references", | ||
joinColumns = [JoinColumn(name = "task_id", foreignKey = ForeignKey(name = "fk_bpn_references_tasks"))], | ||
uniqueConstraints = [UniqueConstraint(name = "uc_business_partner_bpn_references_task_scope", columnNames = ["task_id", "scope"])] | ||
) | ||
val bpnReferences: MutableMap<BpnReferenceDb.Scope, BpnReferenceDb>, | ||
@Column(name = "legal_name") | ||
var legalName: String?, | ||
@Column(name = "legal_short_name") | ||
var legalShortName: String?, | ||
@Column(name = "site_exists", nullable = false) | ||
var siteExists: Boolean, | ||
@Column(name = "site_name") | ||
var siteName: String?, | ||
@Column(name = "legal_form") | ||
var legalForm: String?, | ||
@Column(name = "is_cx_member") | ||
var isCatenaXMemberData: Boolean?, | ||
@Column(name = "owning_company_bpnl") | ||
var owningCompany: String?, | ||
@Column(name = "legal_entity_has_changed") | ||
var legalEntityHasChanged: Boolean?, | ||
@Column(name = "site_has_changed") | ||
var siteHasChanged: Boolean? | ||
) | ||
|
||
} |
Oops, something went wrong.