Skip to content

Commit

Permalink
feat(Gate) - Allow user to input nullable values
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsilva-CGI committed Oct 25, 2023
1 parent 4e9bf1c commit 91e50a0
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,38 @@ fun BusinessPartnerGenericDto.toLegalEntityDto(bpnReferenceDto: BpnReferenceDto,
hasChanged = true,
legalName = nameParts.joinToString(" "),
legalShortName = shortName,
identifiers = identifiers.map { it.toLegalEntityIdentifierDto() },
identifiers = identifiers.mapNotNull { it.toLegalEntityIdentifierDto() },
legalForm = legalForm,
states = states.map { it.toLegalEntityState() },
states = states.mapNotNull { it.toLegalEntityState() },
classifications = classifications.map { it.toBusinessPartnerClassificationDto() },
legalAddress = legalAddress

)
}

fun ClassificationDto.toBusinessPartnerClassificationDto(): BusinessPartnerClassificationDto {
fun ClassificationDto.toBusinessPartnerClassificationDto(): ClassificationDto {

return BusinessPartnerClassificationDto(code = code, type = type, value = value)
return ClassificationDto(code = code, type = type, value = value)
}

fun BusinessPartnerIdentifierDto.toLegalEntityIdentifierDto(): LegalEntityIdentifierDto {
fun BusinessPartnerIdentifierDto.toLegalEntityIdentifierDto(): LegalEntityIdentifierDto? {

return value?.let { value ->
type?.let { type ->
LegalEntityIdentifierDto(value = value, type = type, issuingBody = issuingBody)
}
}

return LegalEntityIdentifierDto(value = value, type = type, issuingBody = issuingBody)
}

fun BusinessPartnerStateDto.toLegalEntityState(): LegalEntityState {
fun BusinessPartnerStateDto.toLegalEntityState(): LegalEntityState? {

return LegalEntityState(description, validFrom, validTo, type)
return type?.let { LegalEntityState(description, validFrom, validTo, it) }
}

fun BusinessPartnerStateDto.toSiteState(): SiteStateDto {
fun BusinessPartnerStateDto.toSiteState(): SiteStateDto? {

return SiteStateDto(description, validFrom, validTo, type)
return type?.let { SiteStateDto(description, validFrom, validTo, it) }
}

fun BusinessPartnerGenericDto.toLogisticAddressDto(bpnReferenceDto: BpnReferenceDto):
Expand All @@ -82,7 +87,7 @@ fun BusinessPartnerGenericDto.toSiteDto(bpnReferenceDto: BpnReferenceDto, legalN
bpnSReference = bpnReferenceDto,
hasChanged = true,
name = legalName,
states = states.map { it.toSiteState() },
states = states.mapNotNull { it.toSiteState() },
mainAddress = siteAddressReference

)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ object CommonValues {
hasChanged = true,
legalName = nameParts.joinToString(" "),
legalShortName = shortName,
identifiers = identifiers.map { it.toLegalEntityIdentifierDto() },
identifiers = identifiers.mapNotNull { it.toLegalEntityIdentifierDto() },
legalForm = legalForm,
states = states.map { it.toLegalEntityState() },
states = states.mapNotNull { it.toLegalEntityState() },
classifications = classifications.map { it.toBusinessPartnerClassificationDto() }
)

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

val expectedLogisticAddressDto = LogisticAddressDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import io.swagger.v3.oas.annotations.media.Schema
data class BusinessPartnerIdentifierDto(

@get:Schema(description = "Technical key of the type to which this identifier belongs to")
val type: String,
val type: String? = null,

@get:Schema(description = "Value of the identifier")
val value: String,
val value: String? = null,

@get:Schema(description = "Body which issued the identifier")
val issuingBody: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ data class BusinessPartnerStateDto(
val validTo: LocalDateTime?,

@get:Schema(description = "The type of this specified status.")
val type: BusinessStateType,
val type: BusinessStateType?,

@get:Schema(description = "Denotation of the status.")
val description: String?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* 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 io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.ClassificationDescription
import org.eclipse.tractusx.bpdm.common.model.ClassificationType

@Schema(description = ClassificationDescription.header)
data class ClassificationBusinessPartnerDto(

@get:Schema(description = ClassificationDescription.type)
override val type: ClassificationType?,

@get:Schema(description = ClassificationDescription.code)
override val code: String?,

@get:Schema(description = ClassificationDescription.value)
override val value: String?
) : IBaseClassificationDto
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface IBaseBusinessPartnerDto {
val states: Collection<BusinessPartnerStateDto>

@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>
val classifications: Collection<IBaseClassificationDto>

@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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.eclipse.tractusx.bpdm.common.model.ClassificationType
@Schema(description = ClassificationDescription.header)
interface IBaseClassificationDto {
@get:Schema(description = ClassificationDescription.type)
val type: ClassificationType
val type: ClassificationType?

@get:Schema(description = ClassificationDescription.code)
val code: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerIdentifierDto
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerRole
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerStateDto
import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto
import org.eclipse.tractusx.bpdm.common.dto.ClassificationBusinessPartnerDto
import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressDto
import org.eclipse.tractusx.bpdm.gate.api.model.IBaseBusinessPartnerGateDto

Expand All @@ -38,12 +38,12 @@ data class BusinessPartnerInputRequest(
override val identifiers: Collection<BusinessPartnerIdentifierDto> = emptyList(),
override val legalForm: String? = null,
override val states: Collection<BusinessPartnerStateDto> = emptyList(),
override val classifications: Collection<ClassificationDto> = emptyList(),
override val classifications: Collection<ClassificationBusinessPartnerDto> = emptyList(),
override val roles: Collection<BusinessPartnerRole> = emptyList(),
override val postalAddress: BusinessPartnerPostalAddressDto = BusinessPartnerPostalAddressDto(),
override val isOwnCompanyData: Boolean = false,
override val bpnL: String? = null,
override val bpnS: String? = null,
override val bpnA: String? = null,

) : IBaseBusinessPartnerGateDto
) : IBaseBusinessPartnerGateDto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.swagger.v3.oas.annotations.media.Schema
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerIdentifierDto
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerRole
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerStateDto
import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto
import org.eclipse.tractusx.bpdm.common.dto.ClassificationBusinessPartnerDto
import org.eclipse.tractusx.bpdm.common.dto.openapidescription.CommonDescription
import org.eclipse.tractusx.bpdm.gate.api.model.BusinessPartnerPostalAddressDto
import org.eclipse.tractusx.bpdm.gate.api.model.IBaseBusinessPartnerGateDto
Expand All @@ -41,7 +41,7 @@ data class BusinessPartnerInputDto(
override val identifiers: Collection<BusinessPartnerIdentifierDto> = emptyList(),
override val legalForm: String? = null,
override val states: Collection<BusinessPartnerStateDto> = emptyList(),
override val classifications: Collection<ClassificationDto> = emptyList(),
override val classifications: Collection<ClassificationBusinessPartnerDto> = emptyList(),
override val roles: Collection<BusinessPartnerRole> = emptyList(),
override val postalAddress: BusinessPartnerPostalAddressDto,
override val isOwnCompanyData: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

package org.eclipse.tractusx.bpdm.gate.service

import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerIdentifierDto
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerStateDto
import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto
import org.eclipse.tractusx.bpdm.common.dto.GeoCoordinateDto
import org.eclipse.tractusx.bpdm.common.dto.*
import org.eclipse.tractusx.bpdm.common.exception.BpdmNullMappingException
import org.eclipse.tractusx.bpdm.common.model.StageType
import org.eclipse.tractusx.bpdm.gate.api.model.AlternativePostalAddressGateDto
Expand Down Expand Up @@ -51,7 +48,7 @@ class BusinessPartnerMappings {
identifiers = entity.identifiers.map(::toIdentifierDto),
legalForm = entity.legalForm,
states = entity.states.map(::toStateDto),
classifications = entity.classifications.map(::toClassificationDto),
classifications = entity.classifications.map(::toClassificationNullableDto),
roles = entity.roles,
postalAddress = toPostalAddressDto(entity.postalAddress),
isOwnCompanyData = entity.isOwnCompanyData,
Expand Down Expand Up @@ -91,9 +88,9 @@ class BusinessPartnerMappings {
externalId = dto.externalId,
nameParts = dto.nameParts.toMutableList(),
roles = dto.roles.toSortedSet(),
identifiers = dto.identifiers.map(::toIdentifier).toSortedSet(),
states = dto.states.map(::toState).toSortedSet(),
classifications = dto.classifications.map(::toClassification).toSortedSet(),
identifiers = dto.identifiers.mapNotNull(::toIdentifier).toSortedSet(),
states = dto.states.mapNotNull(::toState).toSortedSet(),
classifications = dto.classifications.mapNotNull(::toClassification).toSortedSet(),
shortName = dto.shortName,
legalForm = dto.legalForm,
isOwnCompanyData = dto.isOwnCompanyData,
Expand All @@ -113,9 +110,9 @@ class BusinessPartnerMappings {
externalId = dto.externalId,
nameParts = dto.nameParts.toMutableList(),
roles = dto.roles.toSortedSet(),
identifiers = dto.identifiers.map(::toIdentifier).toSortedSet(),
states = dto.states.map(::toState).toSortedSet(),
classifications = dto.classifications.map(::toClassification).toSortedSet(),
identifiers = dto.identifiers.mapNotNull(::toIdentifier).toSortedSet(),
states = dto.states.mapNotNull(::toState).toSortedSet(),
classifications = dto.classifications.map(::toClassificationOutput).toSortedSet(),
shortName = dto.shortName,
legalForm = dto.legalForm,
isOwnCompanyData = dto.isOwnCompanyData,
Expand Down Expand Up @@ -242,18 +239,29 @@ class BusinessPartnerMappings {
BusinessPartnerIdentifierDto(type = entity.type, value = entity.value, issuingBody = entity.issuingBody)

private fun toIdentifier(dto: BusinessPartnerIdentifierDto) =
Identifier(type = dto.type, value = dto.value, issuingBody = dto.issuingBody)
dto.type?.let { type ->
dto.value?.let { value ->
Identifier(type = type, value = value, issuingBody = dto.issuingBody)
}
}

private fun toStateDto(entity: State) =
BusinessPartnerStateDto(type = entity.type, validFrom = entity.validFrom, validTo = entity.validTo, description = entity.description)

private fun toState(dto: BusinessPartnerStateDto) =
State(type = dto.type, validFrom = dto.validFrom, validTo = dto.validTo, description = dto.description)
dto.type?.let { State(type = it, validFrom = dto.validFrom, validTo = dto.validTo, description = dto.description) }

private fun toClassificationNullableDto(entity: Classification) =
ClassificationBusinessPartnerDto(type = entity.type, code = entity.code, value = entity.value)

private fun toClassificationDto(entity: Classification) =
ClassificationDto(type = entity.type, code = entity.code, value = entity.value)

private fun toClassification(dto: ClassificationDto) =

private fun toClassification(dto: ClassificationBusinessPartnerDto) =
dto.type?.let { Classification(type = it, code = dto.code, value = dto.value) }

private fun toClassificationOutput(dto: ClassificationDto) =
Classification(type = dto.type, code = dto.code, value = dto.value)

private fun toGeoCoordinateDto(entity: GeographicCoordinate) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class OrchestratorMappings(
externalId = externalId,
nameParts = entity.nameParts.toMutableList(),
shortName = entity.shortName,
identifiers = entity.identifiers.map { toIdentifier(it) }.toSortedSet(),
identifiers = entity.identifiers.mapNotNull { toIdentifier(it) }.toSortedSet(),
legalForm = entity.legalForm,
states = entity.states.map { toState(it) }.toSortedSet(),
states = entity.states.mapNotNull { toState(it) }.toSortedSet(),
classifications = entity.classifications.map { toClassification(it) }.toSortedSet(),
roles = entity.roles.toSortedSet(),
postalAddress = toPostalAddress(entity.postalAddress),
Expand All @@ -147,10 +147,14 @@ class OrchestratorMappings(
)

private fun toIdentifier(dto: BusinessPartnerIdentifierDto) =
Identifier(type = dto.type, value = dto.value, issuingBody = dto.issuingBody)
dto.type?.let { type ->
dto.value?.let { value ->
Identifier(type = type, value = value, issuingBody = dto.issuingBody)
}
}

private fun toState(dto: BusinessPartnerStateDto) =
State(type = dto.type, validFrom = dto.validFrom, validTo = dto.validTo, description = dto.description)
dto.type?.let { State(type = it, validFrom = dto.validFrom, validTo = dto.validTo, description = dto.description) }

private fun toClassification(dto: ClassificationDto) =
Classification(type = dto.type, code = dto.code, value = dto.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.junit5.WireMockExtension
import org.assertj.core.api.Assertions
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerIdentifierDto
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerStateDto
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto
import org.eclipse.tractusx.bpdm.common.dto.*
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.exception.BpdmNullMappingException
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
Expand Down Expand Up @@ -329,7 +326,7 @@ class BusinessPartnerControllerIT @Autowired constructor(
identifiers = request.identifiers.toSortedSet(identifierDtoComparator),
legalForm = request.legalForm,
states = request.states.toSortedSet(stateDtoComparator),
classifications = request.classifications.toSortedSet(classificationDtoComparator),
classifications = request.classifications.toSortedSet(classificationDtoOutputComparator),
roles = request.roles.toSortedSet(),
postalAddress = request.postalAddress,
isOwnCompanyData = request.isOwnCompanyData,
Expand Down Expand Up @@ -360,7 +357,14 @@ class BusinessPartnerControllerIT @Autowired constructor(
.thenBy(nullsLast(), BusinessPartnerStateDto::validTo) // here null means MAX
.thenBy(BusinessPartnerStateDto::type)
.thenBy(BusinessPartnerStateDto::description)

val classificationDtoComparator = compareBy(
ClassificationBusinessPartnerDto::type,
ClassificationBusinessPartnerDto::code,
ClassificationBusinessPartnerDto::value
)

val classificationDtoOutputComparator = compareBy(
ClassificationDto::type,
ClassificationDto::code,
ClassificationDto::value
Expand Down
Loading

0 comments on commit 91e50a0

Please sign in to comment.