Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: gate service and entity structure #968

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
package org.eclipse.tractusx.bpdm.gate.config

import jakarta.annotation.PostConstruct
import org.eclipse.tractusx.bpdm.gate.service.GoldenRecordTaskService
import org.eclipse.tractusx.bpdm.gate.service.GoldenRecordUpdateService
import org.eclipse.tractusx.bpdm.gate.service.TaskCreationService
import org.eclipse.tractusx.bpdm.gate.service.TaskResolutionService
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.TaskScheduler
import org.springframework.scheduling.support.CronTrigger
Expand All @@ -30,14 +31,15 @@ import org.springframework.scheduling.support.CronTrigger
class GoldenRecordTaskConfiguration(
private val configProperties: GoldenRecordTaskConfigProperties,
private val taskScheduler: TaskScheduler,
private val taskService: GoldenRecordTaskService,
private val taskCreationService: TaskCreationService,
private val taskResolutionService: TaskResolutionService,
private val updateService: GoldenRecordUpdateService
) {

@PostConstruct
fun scheduleGoldenRecordTasks() {
taskScheduler.scheduleIfEnabled(
{ taskService.createTasksForReadyBusinessPartners() },
{ taskCreationService.createTasksForReadyBusinessPartners() },
configProperties.creation.fromSharingMember.cron
)

Expand All @@ -47,7 +49,7 @@ class GoldenRecordTaskConfiguration(
)

taskScheduler.scheduleIfEnabled(
{ taskService.resolvePendingTasks() },
{ taskResolutionService.resolveTasks() },
configProperties.check.cron
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class ChangelogEntryDb(
@Column(name = "external_id", nullable = false, updatable = false)
val externalId: String,

@Column(name = "associated_owner_bpnl", nullable = true)
var associatedOwnerBpnl: String? = null,
@Column(name = "tenant_bpnl", nullable = true)
var tenantBpnl: String? = null,

@Enumerated(EnumType.STRING)
@Column(name = "changelog_type", nullable = false, updatable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class SharingStateDb(
@Column(name = "external_id", nullable = false)
var externalId: String,

@Column(name = "associated_owner_bpnl", nullable = true)
var associatedOwnerBpnl: String? = null,
@Column(name = "tenant_bpnl", nullable = true)
var tenantBpnl: String? = null,

@Enumerated(EnumType.STRING)
@Column(name = "sharing_state_type", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@ package org.eclipse.tractusx.bpdm.gate.entity.generic

import jakarta.persistence.*
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerRole
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.model.BaseEntity
import org.eclipse.tractusx.bpdm.common.model.StageType
import org.eclipse.tractusx.bpdm.gate.entity.SharingStateDb
import java.util.*

@Entity
@Table(name = "business_partners")
class BusinessPartnerDb(

@Column(name = "external_id")
var externalId: String,
@ManyToOne
@JoinColumn(name = "sharing_state_id", nullable = false)
var sharingState: SharingStateDb,

@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "business_partners_name_parts", joinColumns = [JoinColumn(name = "business_partner_id")])
Expand Down Expand Up @@ -74,9 +75,6 @@ class BusinessPartnerDb(
@Column(name = "is_own_company_data", nullable = false)
var isOwnCompanyData: Boolean = false,

@Column(name = "associated_owner_bpnl", nullable = true)
var associatedOwnerBpnl: String? = null,

@Column(name = "bpnl")
var bpnL: String? = null,

Expand All @@ -94,13 +92,6 @@ class BusinessPartnerDb(
@Enumerated(EnumType.STRING)
var stage: StageType,

@Column(name = "parent_id")
var parentId: String? = null,

@Column(name = "parent_type")
@Enumerated(EnumType.STRING)
var parentType: BusinessPartnerType? = null,

@OneToOne(cascade = [CascadeType.ALL], orphanRemoval = true)
@JoinColumn(name = "legal_entity_confidence_id", unique = true)
var legalEntityConfidence: ConfidenceCriteriaDb?,
Expand All @@ -113,5 +104,18 @@ class BusinessPartnerDb(
@JoinColumn(name = "address_confidence_id", unique = true)
var addressConfidence: ConfidenceCriteriaDb?,

) : BaseEntity()
) : BaseEntity() {

companion object {
fun createEmpty(sharingState: SharingStateDb, stage: StageType) =
BusinessPartnerDb(
sharingState = sharingState,
stage = stage,
postalAddress = PostalAddressDb(),
legalEntityConfidence = null,
siteConfidence = null,
addressConfidence = null
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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.gate.exception

class BpdmMissingSharingStateException(
externalId: String,
tenantBpnl: String?
) : RuntimeException("Sharing state with external-id '$externalId' in tenant '$tenantBpnl' is missing.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* 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.gate.model.upsert.output

import com.neovisionaries.i18n.CountryCode
import org.eclipse.tractusx.bpdm.common.model.DeliveryServiceType

data class AlternativeAddress(
val geographicCoordinates: GeoCoordinate?,
val country: CountryCode,
val administrativeAreaLevel1: String?,
val postalCode: String?,
val city: String,
val deliveryServiceType: DeliveryServiceType,
val deliveryServiceQualifier: String?,
val deliveryServiceNumber: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.gate.model
package org.eclipse.tractusx.bpdm.gate.model.upsert.output

import org.eclipse.tractusx.bpdm.gate.api.exception.BusinessPartnerSharingError
import org.eclipse.tractusx.bpdm.gate.api.model.response.ErrorInfo
import java.time.LocalDateTime

data class SharingStatusEvaluationResult(
val validExternalIds: Collection<String>,
val pendingExternalIds: Collection<String>,
val errors: Collection<ErrorInfo<BusinessPartnerSharingError>>
)
data class ConfidenceCriteria(
val sharedByOwner: Boolean,
val checkedByExternalDataSource: Boolean,
val numberOfSharingMembers: Int,
val lastConfidenceCheckAt: LocalDateTime,
val nextConfidenceCheckAt: LocalDateTime,
val confidenceLevel: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* 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.gate.model.upsert.output

data class GeoCoordinate(
val longitude: Float,
val latitude: Float,
val altitude: Float?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* 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.gate.model.upsert.output

import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType

data class Identifier(
val type: String,
val value: String,
val issuingBody: String?,
val businessPartnerType: BusinessPartnerType
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* 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.gate.model.upsert.output

import org.eclipse.tractusx.bpdm.common.dto.AddressType
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerRole

data class OutputUpsertData(
val nameParts: List<String>,
val identifiers: Collection<Identifier>,
val states: Collection<State>,
val roles: Collection<BusinessPartnerRole>,
val isOwnCompanyData: Boolean,
val legalEntityBpn: String,
val legalName: String,
val shortName: String?,
val legalForm: String?,
val siteBpn: String?,
val siteName: String?,
val addressBpn: String,
val addressName: String?,
val addressType: AddressType,
val physicalPostalAddress: PhysicalPostalAddress,
val alternativePostalAddress: AlternativeAddress?,
val legalEntityConfidence: ConfidenceCriteria,
val siteConfidence: ConfidenceCriteria?,
val addressConfidence: ConfidenceCriteria,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* 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.gate.model.upsert.output

import com.neovisionaries.i18n.CountryCode

data class PhysicalPostalAddress(
val geographicCoordinates: GeoCoordinate?,
val country: CountryCode,
val administrativeAreaLevel1: String?,
val administrativeAreaLevel2: String?,
val administrativeAreaLevel3: String?,
val postalCode: String?,
val city: String,
val district: String?,
val street: Street?,
val companyPostalCode: String?,
val industrialZone: String?,
val building: String?,
val floor: String?,
val door: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* 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.gate.model.upsert.output

import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.model.BusinessStateType
import java.time.LocalDateTime

data class State(
val validFrom: LocalDateTime?,
val validTo: LocalDateTime?,
val type: BusinessStateType,
val businessPartnerType: BusinessPartnerType
)
Loading