Skip to content

Commit

Permalink
feat(Api): add confidence criteria fields to L/S/A business partner m…
Browse files Browse the repository at this point in the history
…odel

- added confidence criteria on all LSA business partner API dtos
- added persistence for the confidence criteria in the Pool
- changed test and test values accordingly
  • Loading branch information
nicoprow committed Dec 25, 2023
1 parent 6db517f commit 76b2363
Show file tree
Hide file tree
Showing 34 changed files with 469 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.pool.api.client.PoolApiClient
import org.eclipse.tractusx.bpdm.pool.api.model.ConfidenceCriteriaDto
import org.eclipse.tractusx.bpdm.pool.api.model.LogisticAddressDto
import org.eclipse.tractusx.bpdm.pool.api.model.SiteDto
import org.eclipse.tractusx.bpdm.pool.api.model.request.*
import org.eclipse.tractusx.bpdm.pool.api.model.response.*
import org.springframework.stereotype.Service
import java.time.LocalDateTime

@Service
class PoolUpdateService(
Expand All @@ -39,6 +41,15 @@ class PoolUpdateService(

private val logger = KotlinLogging.logger { }

private val dummyConfidenceCriteria = ConfidenceCriteriaDto(
sharedByOwner = false,
numberOfBusinessPartners = 1,
checkedByExternalDataSource = false,
lastConfidenceCheckAt = LocalDateTime.now(),
nextConfidenceCheckAt = LocalDateTime.now().plusDays(5),
confidenceLevel = 0
)

fun createLegalEntitiesInPool(entriesToCreate: Collection<GateLegalEntityInfo>): LegalEntityPartnerCreateResponseWrapper {
val createRequests = entriesToCreate.map {
LegalEntityPartnerCreateRequest(
Expand Down Expand Up @@ -77,6 +88,7 @@ class PoolUpdateService(
name = entry.site.nameParts.firstOrNull() ?: "",
states = entry.site.states.map(::gateToPoolSiteState),
mainAddress = gateToPoolLogisticAddress(entry.mainAddress),
confidenceCriteria = dummyConfidenceCriteria
),
index = entry.externalId,
bpnlParent = leParentBpn
Expand All @@ -101,6 +113,7 @@ class PoolUpdateService(
name = it.site.nameParts.firstOrNull() ?: "",
states = it.site.states.map(::gateToPoolSiteState),
mainAddress = gateToPoolLogisticAddress(it.mainAddress),
confidenceCriteria = dummyConfidenceCriteria
),
bpns = it.bpn!!
)
Expand Down Expand Up @@ -141,7 +154,8 @@ class PoolUpdateService(
states = entry.address.states.map(::gateToPoolAddressState),
identifiers = entry.address.identifiers.map(::gateToPoolAddressIdentifier),
physicalPostalAddress = gateToPoolPhysicalAddress(entry.address.physicalPostalAddress),
alternativePostalAddress = entry.address.alternativePostalAddress?.let(::gateToPoolAlternativeAddress)
alternativePostalAddress = entry.address.alternativePostalAddress?.let(::gateToPoolAlternativeAddress),
confidenceCriteria = dummyConfidenceCriteria
),
index = entry.externalId,
bpnParent = siteParentBpn
Expand Down Expand Up @@ -181,7 +195,8 @@ class PoolUpdateService(
states = it.address.states.map(::gateToPoolAddressState),
identifiers = it.address.identifiers.map(::gateToPoolAddressIdentifier),
physicalPostalAddress = gateToPoolPhysicalAddress(it.address.physicalPostalAddress),
alternativePostalAddress = it.address.alternativePostalAddress?.let(::gateToPoolAlternativeAddress)
alternativePostalAddress = it.address.alternativePostalAddress?.let(::gateToPoolAlternativeAddress),
confidenceCriteria = dummyConfidenceCriteria
),
bpna = it.bpn!!
)
Expand All @@ -190,5 +205,4 @@ class PoolUpdateService(
return poolClient.addresses.updateAddresses(updateRequests)
.also { logger.info { "Pool accepted ${it.entityCount} updated addresses, ${it.errorCount} were refused" } }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ package org.eclipse.tractusx.bpdm.cleaning.service

import org.eclipse.tractusx.bpdm.common.dto.AddressType
import org.eclipse.tractusx.orchestrator.api.model.*
import java.time.LocalDateTime


val dummyConfidenceCriteria = ConfidenceCriteria(
sharedByOwner = false,
numberOfBusinessPartners = 1,
checkedByExternalDataSource = false,
lastConfidenceCheckAt = LocalDateTime.now(),
nextConfidenceCheckAt = LocalDateTime.now().plusDays(5),
confidenceLevel = 0
)

fun BusinessPartnerGenericDto.toLegalEntityDto(bpnReferenceDto: BpnReferenceDto, legalAddress: LogisticAddressDto): LegalEntityDto {

return LegalEntityDto(
Expand All @@ -35,8 +45,8 @@ fun BusinessPartnerGenericDto.toLegalEntityDto(bpnReferenceDto: BpnReferenceDto,
legalForm = legalEntity.legalForm,
states = states.mapNotNull { it.toLegalEntityState() },
classifications = legalEntity.classifications.map { it.toLegalEntityClassificationDto() },
legalAddress = legalAddress

legalAddress = legalAddress,
confidenceCriteria = dummyConfidenceCriteria
)
}

Expand Down Expand Up @@ -75,7 +85,8 @@ fun BusinessPartnerGenericDto.toLogisticAddressDto(bpnReferenceDto: BpnReference
states = emptyList(),
identifiers = emptyList(),
physicalPostalAddress = address.physicalPostalAddress,
alternativePostalAddress = address.alternativePostalAddress
alternativePostalAddress = address.alternativePostalAddress,
confidenceCriteria = dummyConfidenceCriteria
)
}

Expand All @@ -87,8 +98,8 @@ fun BusinessPartnerGenericDto.toSiteDto(bpnReferenceDto: BpnReferenceDto, legalN
hasChanged = address.addressType in setOf(AddressType.SiteMainAddress, AddressType.LegalAndSiteMainAddress),
name = legalName,
states = states.mapNotNull { it.toSiteState() },
mainAddress = siteAddressReference

mainAddress = siteAddressReference,
confidenceCriteria = dummyConfidenceCriteria
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
package org.eclipse.tractusx.bpdm.cleaning.testdata

import com.neovisionaries.i18n.CountryCode
import org.eclipse.tractusx.bpdm.cleaning.service.toLegalEntityClassificationDto
import org.eclipse.tractusx.bpdm.cleaning.service.toLegalEntityIdentifierDto
import org.eclipse.tractusx.bpdm.cleaning.service.toLegalEntityState
import org.eclipse.tractusx.bpdm.cleaning.service.toSiteState
import org.eclipse.tractusx.bpdm.cleaning.service.*
import org.eclipse.tractusx.bpdm.common.dto.AddressType
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerRole
import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto
Expand Down Expand Up @@ -180,13 +177,15 @@ object CommonValues {
identifiers = identifiers.mapNotNull { it.toLegalEntityIdentifierDto() },
legalForm = legalForm,
states = states.mapNotNull { it.toLegalEntityState() },
classifications = classifications.map { it.toLegalEntityClassificationDto() }
classifications = classifications.map { it.toLegalEntityClassificationDto() },
confidenceCriteria = dummyConfidenceCriteria
)

val expectedSiteDto = SiteDto(
hasChanged = true,
name = nameParts.joinToString(" "),
states = states.mapNotNull { it.toSiteState() },
confidenceCriteria = dummyConfidenceCriteria
)

val expectedLogisticAddressDto = LogisticAddressDto(
Expand All @@ -195,7 +194,8 @@ object CommonValues {
name = nameParts.joinToString(" "),
states = emptyList(),
identifiers = emptyList(),
physicalPostalAddress = physicalPostalAddress
physicalPostalAddress = physicalPostalAddress,
confidenceCriteria = dummyConfidenceCriteria
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ interface IBaseLegalEntityDto {

@get:ArraySchema(arraySchema = Schema(description = LegalEntityDescription.classifications, required = false))
val classifications: Collection<ILegalEntityClassificationDto>

val confidenceCriteria: IConfidenceCriteriaDto?
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ interface IBaseLogisticAddressDto {
// TODO OpenAPI description for complex field does not work!!
@get:Schema(description = LogisticAddressDescription.alternativePostalAddress)
val alternativePostalAddress: IBaseAlternativePostalAddressDto?

val confidenceCriteria: IConfidenceCriteriaDto?
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ interface IBaseSiteDto {

@get:ArraySchema(arraySchema = Schema(description = SiteDescription.states))
val states: Collection<ISiteStateDto>

val confidenceCriteria: IConfidenceCriteriaDto
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* 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.common.dto

import java.time.LocalDateTime

interface IConfidenceCriteriaDto {
val sharedByOwner: Boolean?
val checkedByExternalDataSource: Boolean?
val numberOfBusinessPartners: Int?
val lastConfidenceCheckAt: LocalDateTime?
val nextConfidenceCheckAt: LocalDateTime?
val confidenceLevel: Int?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* 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.api.model

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?

) : IConfidenceCriteriaDto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ data class LegalEntityDto(
override val classifications: Collection<LegalEntityClassificationDto> = emptyList(),

@get:ArraySchema(arraySchema = Schema(description = CommonDescription.roles))
val roles: Collection<BusinessPartnerRole> = emptyList()
val roles: Collection<BusinessPartnerRole> = emptyList(),

override val confidenceCriteria: ConfidenceCriteriaDto? = null

) : IBaseLegalEntityDto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ data class LogisticAddressDto(
override val alternativePostalAddress: AlternativePostalAddressDto? = null,

@get:ArraySchema(arraySchema = Schema(description = LogisticAddressDescription.roles))
val roles: Collection<BusinessPartnerRole> = emptyList()
val roles: Collection<BusinessPartnerRole> = emptyList(),

override val confidenceCriteria: ConfidenceCriteriaDto? = null

) : IBaseLogisticAddressDto
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*******************************************************************************
* 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.orchestrator.api.model

import org.eclipse.tractusx.bpdm.common.dto.IConfidenceCriteriaDto
import java.time.LocalDateTime

data class ConfidenceCriteria(
override val sharedByOwner: Boolean? = null,
override val checkedByExternalDataSource: Boolean? = null,
override val numberOfBusinessPartners: Int? = null,
override val lastConfidenceCheckAt: LocalDateTime? = null,
override val nextConfidenceCheckAt: LocalDateTime? = null,
override val confidenceLevel: Int? = null
) : IConfidenceCriteriaDto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ data class LegalEntityDto(

override val classifications: Collection<LegalEntityClassificationDto> = emptyList(),

val legalAddress: LogisticAddressDto? = null
val legalAddress: LogisticAddressDto? = null,

override val confidenceCriteria: ConfidenceCriteria = ConfidenceCriteria()

) : IBaseLegalEntityDto
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ data class LogisticAddressDto(

override val physicalPostalAddress: PhysicalPostalAddressDto? = null,

override val alternativePostalAddress: AlternativePostalAddressDto? = null
override val alternativePostalAddress: AlternativePostalAddressDto? = null,

override val confidenceCriteria: ConfidenceCriteria = ConfidenceCriteria()

) : IBaseLogisticAddressDto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ data class SiteDto(
override val name: String? = null,
override val states: Collection<SiteStateDto> = emptyList(),

val mainAddress: LogisticAddressDto? = null
val mainAddress: LogisticAddressDto? = null,

override val confidenceCriteria: ConfidenceCriteria = ConfidenceCriteria()

) : IBaseSiteDto

0 comments on commit 76b2363

Please sign in to comment.