Skip to content

Commit

Permalink
feat(Api): add confidence criteria fields to generic business partner…
Browse files Browse the repository at this point in the history
… model

- add confidence criteria fields to generic API DTOs
- added persistence for the confidence criteria in the Gate
- changed test and test values accordingly
- made adjustments to the common base DTO interfaces for better integration
  • Loading branch information
nicoprow committed Dec 29, 2023
1 parent 94e960f commit 4a09886
Show file tree
Hide file tree
Showing 24 changed files with 305 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.eclipse.tractusx.orchestrator.api.model.*
import java.time.LocalDateTime


val dummyConfidenceCriteria = ConfidenceCriteria(
val dummyConfidenceCriteria = ConfidenceCriteriaDto(
sharedByOwner = false,
numberOfBusinessPartners = 1,
checkedByExternalDataSource = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ object CommonValues {
legalEntity = LegalEntityRepresentation(
shortName = shortName,
legalForm = legalForm,
classifications = classifications
classifications = classifications,
confidenceCriteria = dummyConfidenceCriteria
),
site = SiteRepresentation(name = siteName),
address = AddressRepresentation(name = addressName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ interface IBaseBusinessPartnerDto {
val roles: Collection<BusinessPartnerRole>

@get:Schema(description = "The legal entity, on which the business partner provides a view.")
val legalEntity: IBaseLegalEntityRepresentation
val legalEntity: IBaseLegalEntityRepresentation?

@get:Schema(description = "The site, on which the business partner provides a view.")
val site: IBaseSiteRepresentation
val site: IBaseSiteRepresentation?

@get:Schema(description = "The address, on which the business partner provides a view. ")
val address: IBaseAddressRepresentation
val address: IBaseAddressRepresentation?
}

@Schema(description = "A legal entity representation adds context information to the legal entity, on which the business partner provides a view. Additionally, it contains some of the information from the assigned legal entity.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ interface IBaseSiteDto {
@get:ArraySchema(arraySchema = Schema(description = SiteDescription.states))
val states: Collection<ISiteStateDto>

val confidenceCriteria: IConfidenceCriteriaDto
val confidenceCriteria: IConfidenceCriteriaDto?
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import org.eclipse.tractusx.bpdm.common.dto.IConfidenceCriteriaDto
import java.time.LocalDateTime

data class ConfidenceCriteriaDto(
override val sharedByOwner: Boolean?,
override val checkedByExternalDataSource: Boolean?,
override val numberOfBusinessPartners: Int?,
override val lastConfidenceCheckAt: LocalDateTime?,
override val nextConfidenceCheckAt: LocalDateTime?,
override val confidenceLevel: Int?
override val sharedByOwner: Boolean,
override val checkedByExternalDataSource: Boolean,
override val numberOfBusinessPartners: Int,
override val lastConfidenceCheckAt: LocalDateTime,
override val nextConfidenceCheckAt: LocalDateTime,
override val confidenceLevel: Int

) : IConfidenceCriteriaDto
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data class BusinessPartnerOutputDto(
override val roles: Collection<BusinessPartnerRole> = emptyList(),
override val isOwnCompanyData: Boolean = false,
override val legalEntity: LegalEntityRepresentationOutputDto,
override val site: SiteRepresentationOutputDto = SiteRepresentationOutputDto(),
override val site: SiteRepresentationOutputDto?,
override val address: AddressComponentOutputDto,

@get:Schema(description = CommonDescription.createdAt)
Expand All @@ -58,15 +58,17 @@ data class LegalEntityRepresentationOutputDto(
override val legalName: String? = null,
override val shortName: String? = null,
override val legalForm: String? = null,
override val classifications: Collection<BusinessPartnerClassificationDto> = emptyList()
override val classifications: Collection<BusinessPartnerClassificationDto> = emptyList(),
val confidenceCriteria: ConfidenceCriteriaDto
) : IBaseLegalEntityRepresentation

@Schema(
description = "Site properties of business partner output data"
)
data class SiteRepresentationOutputDto(
override val siteBpn: String? = null,
override val name: String? = null
override val siteBpn: String,
override val name: String? = null,
val confidenceCriteria: ConfidenceCriteriaDto
) : IBaseSiteRepresentation

@Schema(
Expand All @@ -79,4 +81,5 @@ data class AddressComponentOutputDto(
override val addressType: AddressType?,
override val physicalPostalAddress: PhysicalPostalAddressDto = PhysicalPostalAddressDto(),
override val alternativePostalAddress: AlternativePostalAddressDto = AlternativePostalAddressDto(),
val confidenceCriteria: ConfidenceCriteriaDto
) : IBaseAddressRepresentation
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,19 @@ class BusinessPartner(

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

@OneToOne(cascade = [CascadeType.ALL], orphanRemoval = true)
@JoinColumn(name = "legal_entity_confidence_id", unique = true)
var legalEntityConfidence: ConfidenceCriteria?,

@OneToOne(cascade = [CascadeType.ALL], orphanRemoval = true)
@JoinColumn(name = "site_confidence_id", unique = true)
var siteConfidence: ConfidenceCriteria?,

@OneToOne(cascade = [CascadeType.ALL], orphanRemoval = true)
@JoinColumn(name = "address_confidence_id", unique = true)
var addressConfidence: ConfidenceCriteria?,

) : BaseEntity()

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

import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Table
import org.eclipse.tractusx.bpdm.common.model.BaseEntity
import java.time.LocalDateTime


@Entity
@Table(name = "confidence_criteria")
class ConfidenceCriteria(
@Column(name = "shared_by_owner", nullable = false)
val sharedByOwner: Boolean,
@Column(name = "checked_by_external_data_source", nullable = false)
val checkedByExternalDataSource: Boolean,
@Column(name = "number_of_business_partners", nullable = false)
val numberOfBusinessPartners: Int,
@Column(name = "last_confidence_check_at", nullable = false)
val lastConfidenceCheckAt: LocalDateTime,
@Column(name = "next_confidence_check_at", nullable = false)
val nextConfidenceCheckAt: LocalDateTime,
@Column(name = "confidence_level", nullable = false)
val confidenceLevel: Int,
) : BaseEntity()
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.eclipse.tractusx.bpdm.gate.entity.GeographicCoordinate
import org.eclipse.tractusx.bpdm.gate.entity.PhysicalPostalAddress
import org.eclipse.tractusx.bpdm.gate.entity.Street
import org.eclipse.tractusx.bpdm.gate.entity.generic.*
import org.eclipse.tractusx.bpdm.gate.exception.BpdmInvalidPartnerException
import org.springframework.stereotype.Service

@Service
Expand Down Expand Up @@ -86,7 +87,10 @@ class BusinessPartnerMappings {
bpnL = dto.legalEntity.legalEntityBpn,
bpnS = dto.site.siteBpn,
bpnA = dto.address.addressBpn,
postalAddress = toPostalAddress(dto.address)
postalAddress = toPostalAddress(dto.address),
legalEntityConfidence = null,
siteConfidence = null,
addressConfidence = null
)
}

Expand Down Expand Up @@ -128,15 +132,27 @@ class BusinessPartnerMappings {
legalName = entity.legalName,
shortName = entity.shortName,
legalForm = entity.legalForm,
classifications = entity.classifications.map(::toClassificationDto)
classifications = entity.classifications.map(::toClassificationDto),
confidenceCriteria = entity.legalEntityConfidence?.let { toConfidenceDto(it) } ?: throw BpdmInvalidPartnerException(
entity.externalId,
"Missing address confidence criteria"
)
)
}

private fun toSiteComponentOutputDto(entity: BusinessPartner): SiteRepresentationOutputDto {
return SiteRepresentationOutputDto(
siteBpn = entity.bpnS,
name = entity.siteName
)
private fun toSiteComponentOutputDto(entity: BusinessPartner): SiteRepresentationOutputDto? {
return entity
.takeIf { it.bpnS != null }
?.let {
SiteRepresentationOutputDto(
siteBpn = entity.bpnS!!,
name = entity.siteName,
confidenceCriteria = entity.siteConfidence?.let { toConfidenceDto(it) } ?: throw BpdmInvalidPartnerException(
entity.externalId,
"Missing site confidence criteria"
)
)
}
}

private fun toAddressComponentOutputDto(entity: BusinessPartner): AddressComponentOutputDto {
Expand All @@ -150,10 +166,24 @@ class BusinessPartnerMappings {
entity.addressName,
addressType = entity.postalAddress.addressType,
physicalPostalAddress = entity.postalAddress.physicalPostalAddress?.toPhysicalPostalAddress() ?: PhysicalPostalAddressDto(),
alternativePostalAddress = entity.postalAddress.alternativePostalAddress?.toAlternativePostalAddressDto() ?: AlternativePostalAddressDto()
alternativePostalAddress = entity.postalAddress.alternativePostalAddress?.toAlternativePostalAddressDto() ?: AlternativePostalAddressDto(),
confidenceCriteria = entity.addressConfidence?.let { toConfidenceDto(it) } ?: throw BpdmInvalidPartnerException(
entity.externalId,
"Missing legal entity confidence criteria"
)
)
}

private fun toConfidenceDto(entity: ConfidenceCriteria) =
ConfidenceCriteriaDto(
sharedByOwner = entity.sharedByOwner,
checkedByExternalDataSource = entity.checkedByExternalDataSource,
numberOfBusinessPartners = entity.numberOfBusinessPartners,
lastConfidenceCheckAt = entity.lastConfidenceCheckAt,
nextConfidenceCheckAt = entity.nextConfidenceCheckAt,
confidenceLevel = entity.confidenceLevel
)


private fun toPostalAddress(dto: AddressRepresentationInputDto) =
PostalAddress(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,23 @@ class OrchestratorMappings(
legalName = entity.legalName,
shortName = entity.shortName,
legalForm = entity.legalForm,
classifications = entity.classifications.map { toClassificationDto(it) }
classifications = entity.classifications.map { toClassificationDto(it) },
confidenceCriteria = entity.legalEntityConfidence?.let { toConfidenceCriteria(it) }
)

private fun toSiteComponentDto(entity: BusinessPartner) = SiteRepresentation(
siteBpn = entity.bpnS,
name = entity.siteName
name = entity.siteName,
confidenceCriteria = entity.siteConfidence?.let { toConfidenceCriteria(it) }
)

private fun toAddressComponentDto(entity: BusinessPartner) = AddressRepresentation(
addressBpn = entity.bpnA,
name = entity.addressName,
addressType = entity.postalAddress.addressType,
physicalPostalAddress = entity.postalAddress.physicalPostalAddress?.let(::toPhysicalPostalAddressDto),
alternativePostalAddress = entity.postalAddress.alternativePostalAddress?.let(this::toAlternativePostalAddressDto)
alternativePostalAddress = entity.postalAddress.alternativePostalAddress?.let(this::toAlternativePostalAddressDto),
confidenceCriteria = entity.addressConfidence?.let { toConfidenceCriteria(it) }
)

private fun toClassificationDto(entity: Classification) =
Expand Down Expand Up @@ -139,6 +142,16 @@ class OrchestratorMappings(
}
}

private fun toConfidenceCriteria(entity: ConfidenceCriteria) =
ConfidenceCriteriaDto(
sharedByOwner = entity.sharedByOwner,
checkedByExternalDataSource = entity.checkedByExternalDataSource,
numberOfBusinessPartners = entity.numberOfBusinessPartners,
lastConfidenceCheckAt = entity.lastConfidenceCheckAt,
nextConfidenceCheckAt = entity.nextConfidenceCheckAt,
confidenceLevel = entity.confidenceLevel
)

fun toSharingStateType(resultState: ResultState) = when (resultState) {
ResultState.Pending -> SharingStateType.Pending
ResultState.Success -> SharingStateType.Success
Expand All @@ -162,7 +175,10 @@ class OrchestratorMappings(
bpnL = dto.legalEntity.legalEntityBpn,
bpnS = dto.site.siteBpn,
bpnA = dto.address.addressBpn,
stage = StageType.Output
stage = StageType.Output,
legalEntityConfidence = dto.legalEntity.confidenceCriteria?.let { toConfidenceCriteria(it) },
siteConfidence = dto.site.confidenceCriteria?.let { toConfidenceCriteria(it) },
addressConfidence = dto.address.confidenceCriteria?.let { toConfidenceCriteria(it) },
)

private fun toIdentifier(dto: BusinessPartnerIdentifierDto) =
Expand Down Expand Up @@ -229,4 +245,14 @@ class OrchestratorMappings(

private fun toGeographicCoordinate(dto: GeoCoordinateDto) =
GeographicCoordinate(latitude = dto.latitude, longitude = dto.longitude, altitude = dto.altitude)

private fun toConfidenceCriteria(dto: ConfidenceCriteriaDto) =
ConfidenceCriteria(
sharedByOwner = dto.sharedByOwner,
checkedByExternalDataSource = dto.checkedByExternalDataSource,
numberOfBusinessPartners = dto.numberOfBusinessPartners,
lastConfidenceCheckAt = dto.lastConfidenceCheckAt,
nextConfidenceCheckAt = dto.nextConfidenceCheckAt,
confidenceLevel = dto.confidenceLevel
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE TABLE confidence_criteria(
id BIGINT NOT NULL,
created_at TIMESTAMP WITH time zone NOT NULL,
updated_at TIMESTAMP WITH time zone NOT NULL,
uuid UUID NOT NULL,
shared_by_owner boolean NOT NULL,
checked_by_external_data_source boolean NOT NULL,
number_of_business_partners INT NOT NULL,
last_confidence_check_at TIMESTAMP NOT NULL,
next_confidence_check_at TIMESTAMP NOT NULL,
confidence_level INT NOT NULL,
CONSTRAINT pk_confidence_criteria PRIMARY KEY (id)
);

ALTER TABLE business_partners
ADD COLUMN legal_entity_confidence_id BIGINT,
ADD COLUMN site_confidence_id BIGINT,
ADD COLUMN address_confidence_id BIGINT;

ALTER TABLE business_partners
ADD CONSTRAINT fk_business_partners_confidence_l FOREIGN KEY (legal_entity_confidence_id) REFERENCES confidence_criteria (id),
ADD CONSTRAINT fk_business_partners_confidence_s FOREIGN KEY (site_confidence_id) REFERENCES confidence_criteria (id),
ADD CONSTRAINT fk_business_partners_confidence_a FOREIGN KEY (address_confidence_id) REFERENCES confidence_criteria (id);





Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ class BusinessPartnerControllerIT @Autowired constructor(
changelogType = ChangelogType.UPDATE
),
ChangelogEntryVerboseDto(
bpn = BusinessPartnerVerboseValues.bpOutputDtoCleaned.site.siteBpn!!,
bpn = BusinessPartnerVerboseValues.bpOutputDtoCleaned.site!!.siteBpn!!,
businessPartnerType = BusinessPartnerType.SITE,
timestamp = Instant.now(),
changelogType = ChangelogType.UPDATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ internal class BusinessPartnerIT @Autowired constructor(
classifications = sortedSetOf(createClassification()),
stage = StageType.Input,
parentId = null,
parentType = null
parentType = null,
legalEntityConfidence = null,
addressConfidence = null,
siteConfidence = null
)
}

Expand Down
Loading

0 comments on commit 4a09886

Please sign in to comment.