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

feat: Adjustments to Generic Business Partner model #479

Merged
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 @@ -30,27 +30,36 @@ interface IBaseBusinessPartnerDto {
@get:Schema(description = CommonDescription.externalId)
val externalId: String

@get:Schema(description = "")
@get:ArraySchema(arraySchema = Schema(description = "The list of name parts to accommodate the different number of name fields in different systems."))
val nameParts: List<String>

@get:Schema(description = "Abbreviated name or shorthand")
@get:Schema(description = "Abbreviated name or shorthand.")
val shortName: String?

@get:ArraySchema(arraySchema = Schema(description = "The list of identifiers of the business partner."))
@get:ArraySchema(arraySchema = Schema(description = "The list of identifiers of the business partner. Sorted and duplicates removed by the service."))
val identifiers: Collection<BusinessPartnerIdentifierDto>

@get:Schema(description = "Technical key of the legal form.")
val legalForm: String?

@get:ArraySchema(arraySchema = Schema(description = "The list of (temporary) states of the business partner."))
@get:ArraySchema(arraySchema = Schema(description = "The list of (temporary) states of the business partner. Sorted and duplicates removed by the service."))
val states: Collection<BusinessPartnerStateDto>

@get:ArraySchema(arraySchema = Schema(description = "The list of classifications of the legal entity, such as a specific industry."))
@get:ArraySchema(arraySchema = Schema(description = "The list of classifications of the business partner, such as a specific industry. Sorted and duplicates removed by the service."))
val classifications: Collection<ClassificationDto>

@get:ArraySchema(arraySchema = Schema(description = CommonDescription.roles))
@get:ArraySchema(arraySchema = Schema(description = "Roles this business partner takes in relation to the sharing member. Sorted and duplicates removed by the service."))
val roles: Collection<BusinessPartnerRole>

@get:Schema(name = "isOwner", description = "True if the sharing member declares itself as the owner of the business partner.")
val isOwner: Boolean

@get:Schema(description = "BPNL")
val bpnL: String?

@get:Schema(description = "BPNS")
val bpnS: String?

@get:Schema(description = "BPNA")
val bpnA: String?
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ data class BusinessPartnerInputRequest(
@get:Schema(description = "Address of the official seat of this business partner.")
val postalAddress: BusinessPartnerPostalAddressInputDto,

override val isOwner: Boolean = false
override val isOwner: Boolean = false,

override val bpnL: String? = null,
override val bpnS: String? = null,
override val bpnA: String? = null

) : IBaseBusinessPartnerDto
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ data class BusinessPartnerInputDto(

override val isOwner: Boolean,

override val bpnL: String?,
override val bpnS: String?,
override val bpnA: String?,

@get:Schema(description = CommonDescription.createdAt)
val createdAt: Instant,

@get:Schema(description = CommonDescription.updatedAt)
val updatedAt: Instant,
val updatedAt: Instant

) : IBaseBusinessPartnerDto
) : IBaseBusinessPartnerDto
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.eclipse.tractusx.bpdm.gate.api.model.*
import java.time.Instant


@Schema(description = "Generic business partner output with external id", requiredProperties = ["externalId", "postalAddress", "bpna", "bpnl"])
@Schema(description = "Generic business partner output with external id", requiredProperties = ["externalId", "postalAddress", "bpnL", "bpnA"])
data class BusinessPartnerOutputDto(
override val externalId: String,
override val nameParts: List<String> = emptyList(),
Expand All @@ -42,19 +42,14 @@ data class BusinessPartnerOutputDto(

override val isOwner: Boolean,

@get:Schema(description = "BPNA")
val bpna: String,

@get:Schema(description = "BPNS")
val bpns: String?,

@get:Schema(description = "BPNL")
val bpnl: String,
override val bpnL: String,
override val bpnS: String?,
override val bpnA: String,

@get:Schema(description = CommonDescription.createdAt)
val createdAt: Instant,

@get:Schema(description = CommonDescription.updatedAt)
val updatedAt: Instant,
val updatedAt: Instant

) : IBaseBusinessPartnerDto
) : IBaseBusinessPartnerDto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package org.eclipse.tractusx.bpdm.gate.service
import org.eclipse.tractusx.bpdm.common.dto.AlternativePostalAddressDto
import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto
import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto
import org.eclipse.tractusx.bpdm.common.exception.BpdmNullMappingException
import org.eclipse.tractusx.bpdm.common.model.StageType
import org.eclipse.tractusx.bpdm.common.util.replace
import org.eclipse.tractusx.bpdm.gate.api.model.*
Expand All @@ -43,13 +44,16 @@ class BusinessPartnerMappings {
externalId = entity.externalId,
nameParts = entity.nameParts,
shortName = entity.shortName,
legalForm = entity.legalForm,
identifiers = entity.identifiers.map(::toIdentifierDto),
legalForm = entity.legalForm,
states = entity.states.map(::toStateDto),
classifications = entity.classifications.map(::toClassificationDto),
roles = entity.roles,
postalAddress = toPostalAddressInputDto(entity.postalAddress),
isOwner = entity.isOwner ?: false, // TODO should be mandatory in entity
isOwner = entity.isOwner,
bpnL = entity.bpnL,
bpnS = entity.bpnS,
bpnA = entity.bpnA,
createdAt = entity.createdAt,
updatedAt = entity.updatedAt
)
Expand All @@ -60,16 +64,18 @@ class BusinessPartnerMappings {
externalId = entity.externalId,
nameParts = entity.nameParts,
shortName = entity.shortName,
legalForm = entity.legalForm,
identifiers = entity.identifiers.map(::toIdentifierDto),
legalForm = entity.legalForm,
states = entity.states.map(::toStateDto),
classifications = entity.classifications.map(::toClassificationDto),
roles = entity.roles,
postalAddress = toPostalAddressOutputDto(entity.postalAddress),
isOwner = entity.isOwner ?: false, // TODO should be mandatory in entity
bpnl = entity.bpnL ?: throw NullPointerException("bpnL is null"),
bpns = entity.bpnS,
bpna = entity.bpnA ?: throw NullPointerException("bpnA is null"),
isOwner = entity.isOwner,
bpnL = entity.bpnL
?: throw BpdmNullMappingException(BusinessPartner::class, BusinessPartnerOutputDto::class, BusinessPartner::bpnL, entity.externalId),
bpnS = entity.bpnS,
bpnA = entity.bpnA
?: throw BpdmNullMappingException(BusinessPartner::class, BusinessPartnerOutputDto::class, BusinessPartner::bpnA, entity.externalId),
createdAt = entity.createdAt,
updatedAt = entity.updatedAt
)
Expand All @@ -87,9 +93,9 @@ class BusinessPartnerMappings {
shortName = dto.shortName,
legalForm = dto.legalForm,
isOwner = dto.isOwner,
bpnL = null,
bpnS = null,
bpnA = null,
bpnL = dto.bpnL,
bpnS = dto.bpnS,
bpnA = dto.bpnA,
postalAddress = toPostalAddress(dto.postalAddress)
)
}
Expand All @@ -103,6 +109,9 @@ class BusinessPartnerMappings {
entity.shortName = dto.shortName
entity.legalForm = dto.legalForm
entity.isOwner = dto.isOwner
entity.bpnL = dto.bpnL
entity.bpnS = dto.bpnS
entity.bpnA = dto.bpnA
updatePostalAddress(entity.postalAddress, dto.postalAddress)
}

Expand All @@ -122,7 +131,7 @@ class BusinessPartnerMappings {

private fun toPostalAddress(dto: BusinessPartnerPostalAddressInputDto) =
PostalAddress(
addressType = dto.addressType ?: AddressType.AdditionalAddress, // TODO should be optional in entity
addressType = dto.addressType,
physicalPostalAddress = dto.physicalPostalAddress.let(::toPhysicalPostalAddress),
alternativePostalAddress = dto.alternativePostalAddress?.let(::toAlternativePostalAddress)
)
Expand Down