Skip to content

Commit

Permalink
Merge pull request #457 from catenax-ng/feat/gbpm_service_logic
Browse files Browse the repository at this point in the history
Feat: Implement generic business partner service logic in Gate
  • Loading branch information
nicoprow authored Sep 15, 2023
2 parents d2cd9da + 739a271 commit 8997116
Show file tree
Hide file tree
Showing 12 changed files with 448 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import org.eclipse.tractusx.bpdm.common.model.DeliveryServiceType
import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer

@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(description = PostalAddressDescription.headerAlternative)
@Schema(
description = PostalAddressDescription.headerAlternative,
requiredProperties = ["country", "city", "deliveryServiceType", "deliveryServiceNumber"]
)
data class AlternativePostalAddressDto(

override val geographicCoordinates: GeoCoordinateDto?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ package org.eclipse.tractusx.bpdm.common.service

import com.neovisionaries.i18n.CountryCode
import com.neovisionaries.i18n.LanguageCode
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.common.dto.response.type.TypeKeyNameUrlDto
import org.eclipse.tractusx.bpdm.common.dto.response.type.TypeKeyNameVerboseDto
import org.eclipse.tractusx.bpdm.common.model.NamedType
import org.eclipse.tractusx.bpdm.common.model.NamedUrlType
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest

fun <T : NamedUrlType> T.toDto(): TypeKeyNameUrlDto<T> {
return TypeKeyNameUrlDto(this, getTypeName(), getUrl())
Expand All @@ -41,3 +45,15 @@ fun LanguageCode.toDto(): TypeKeyNameVerboseDto<LanguageCode> {
fun CountryCode.toDto(): TypeKeyNameVerboseDto<CountryCode> {
return TypeKeyNameVerboseDto(this, getName())
}

fun PaginationRequest.toPageRequest() =
PageRequest.of(page, size)

fun <T, R> Page<T>.toPageDto(contentMapper: (T) -> R): PageDto<R> =
PageDto(
page = number,
totalElements = totalElements,
totalPages = totalPages,
contentSize = content.size,
content = content.map(contentMapper)
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.eclipse.tractusx.bpdm.gate.api.model.response.BusinessPartnerInputDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.BusinessPartnerOutputDto
import org.springdoc.core.annotations.ParameterObject
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
Expand Down Expand Up @@ -58,7 +59,7 @@ interface GateBusinessPartnerApi {
)
@PutMapping("/input/business-partners")
@PutExchange("/input/business-partners")
fun upsertBusinessPartnersInput(@RequestBody businessPartners: Collection<BusinessPartnerInputRequest>): Collection<BusinessPartnerInputDto>
fun upsertBusinessPartnersInput(@RequestBody businessPartners: Collection<BusinessPartnerInputRequest>): ResponseEntity<Collection<BusinessPartnerInputDto>>

@Operation(
summary = "Search business partner by external ID. An empty external ID list returns a paginated list of all business partners.",
Expand All @@ -72,9 +73,9 @@ interface GateBusinessPartnerApi {
)
@PostMapping("/input/business-partners/search")
@PostExchange("/input/business-partners/search")
fun getBusinessPartnersInputByExternalIds(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody externalIds: Collection<String>
fun getBusinessPartnersInput(
@RequestBody externalIds: Collection<String>? = null,
@ParameterObject @Valid paginationRequest: PaginationRequest = PaginationRequest()
): PageDto<BusinessPartnerInputDto>


Expand All @@ -92,8 +93,8 @@ interface GateBusinessPartnerApi {
@PostMapping("/output/business-partners/search")
@PostExchange("/output/business-partners/search")
fun getBusinessPartnersOutput(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody(required = false) externalIds: Collection<String>?
@RequestBody externalIds: Collection<String>? = null,
@ParameterObject @Valid paginationRequest: PaginationRequest = PaginationRequest()
): PageDto<BusinessPartnerOutputDto>

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import org.eclipse.tractusx.bpdm.gate.api.*

interface GateClient {

fun businessParters(): GateBusinessPartnerApi

fun addresses(): GateAddressApi

fun legalEntities(): GateLegalEntityApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ class GateClientImpl(
.build()
}

private val gateClientBusinessPartner by lazy { httpServiceProxyFactory.createClient(GateBusinessPartnerApi::class.java) }
private val gateClientAddress by lazy { httpServiceProxyFactory.createClient(GateAddressApi::class.java) }
private val gateClientLegalEntity by lazy { httpServiceProxyFactory.createClient(GateLegalEntityApi::class.java) }
private val gateClientSite by lazy { httpServiceProxyFactory.createClient(GateSiteApi::class.java) }
private val gateClientChangelog by lazy { httpServiceProxyFactory.createClient(GateChangelogApi::class.java) }
private val gateClientSharingState by lazy { httpServiceProxyFactory.createClient(GateSharingStateApi::class.java) }

override fun businessParters() = gateClientBusinessPartner

override fun addresses() = gateClientAddress

override fun legalEntities() = gateClientLegalEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ package org.eclipse.tractusx.bpdm.gate.api.model

import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "Identifier record for a business partner", requiredProperties = ["type"])
@Schema(
description = "Identifier record for a business partner",
requiredProperties = ["type", "value"]
)
data class BusinessPartnerIdentifierDto(

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

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

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

@get:Schema(description = "Body which issued the identifier")
val issuingBody: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import org.eclipse.tractusx.bpdm.common.dto.openapidescription.PostalAddressDesc
import org.eclipse.tractusx.bpdm.common.service.DataClassUnwrappedJsonDeserializer

@JsonDeserialize(using = DataClassUnwrappedJsonDeserializer::class)
@Schema(description = PostalAddressDescription.headerPhysical)
@Schema(
description = PostalAddressDescription.headerPhysical,
requiredProperties = ["country", "city"]
)
data class PhysicalPostalAddressGateDto(

override val geographicCoordinates: GeoCoordinateDto?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import org.eclipse.tractusx.bpdm.common.dto.ClassificationDto
import org.eclipse.tractusx.bpdm.gate.api.model.*


@Schema(description = "Generic business partner with external id", requiredProperties = ["externalId", "postalAddress"])
@Schema(
description = "Generic business partner with external id",
requiredProperties = ["externalId", "postalAddress"]
)
data class BusinessPartnerInputRequest(
override val externalId: String,
override val nameParts: List<String> = emptyList(),
override val shortName: String?,
override val shortName: String? = null,
override val identifiers: Collection<BusinessPartnerIdentifierDto> = emptyList(),
override val legalForm: String? = null,
override val states: Collection<BusinessPartnerStateDto> = emptyList(),
Expand All @@ -38,6 +41,6 @@ data class BusinessPartnerInputRequest(
@get:Schema(description = "Address of the official seat of this business partner.")
val postalAddress: BusinessPartnerPostalAddressInputDto,

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

) : IBaseBusinessPartnerDto
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,47 @@ package org.eclipse.tractusx.bpdm.gate.controller

import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.common.service.toPageRequest
import org.eclipse.tractusx.bpdm.gate.api.GateBusinessPartnerApi
import org.eclipse.tractusx.bpdm.gate.api.model.request.BusinessPartnerInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.BusinessPartnerInputDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.BusinessPartnerOutputDto
import org.eclipse.tractusx.bpdm.gate.config.ApiConfigProperties
import org.eclipse.tractusx.bpdm.gate.containsDuplicates
import org.eclipse.tractusx.bpdm.gate.service.BusinessPartnerService
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.RestController

@RestController
class BusinessPartnerController() : GateBusinessPartnerApi {
class BusinessPartnerController(
val businessPartnerService: BusinessPartnerService,
val apiConfigProperties: ApiConfigProperties
) : GateBusinessPartnerApi {

override fun upsertBusinessPartnersInput(businessPartners: Collection<BusinessPartnerInputRequest>): Collection<BusinessPartnerInputDto> {
TODO("Not yet implemented")
@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getChangeCompanyInputDataAsRole())")
override fun upsertBusinessPartnersInput(businessPartners: Collection<BusinessPartnerInputRequest>): ResponseEntity<Collection<BusinessPartnerInputDto>> {
if (businessPartners.size > apiConfigProperties.upsertLimit || businessPartners.map { it.externalId }.containsDuplicates()) {
return ResponseEntity(HttpStatus.BAD_REQUEST)
}
val result = businessPartnerService.upsertBusinessPartnersInput(businessPartners)
return ResponseEntity.ok(result)
}

override fun getBusinessPartnersInputByExternalIds(
paginationRequest: PaginationRequest,
externalIds: Collection<String>
@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyInputDataAsRole())")
override fun getBusinessPartnersInput(
externalIds: Collection<String>?,
paginationRequest: PaginationRequest
): PageDto<BusinessPartnerInputDto> {
TODO("Not yet implemented")
return businessPartnerService.getBusinessPartnersInput(paginationRequest.toPageRequest(), externalIds)
}

override fun getBusinessPartnersOutput(paginationRequest: PaginationRequest, externalIds: Collection<String>?): PageDto<BusinessPartnerOutputDto> {
TODO("Not yet implemented")
@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyOutputDataAsRole())")
override fun getBusinessPartnersOutput(
externalIds: Collection<String>?,
paginationRequest: PaginationRequest
): PageDto<BusinessPartnerOutputDto> {
return businessPartnerService.getBusinessPartnersOutput(paginationRequest.toPageRequest(), externalIds)
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@

package org.eclipse.tractusx.bpdm.gate.repository.generic

import org.eclipse.tractusx.bpdm.common.model.StageType
import org.eclipse.tractusx.bpdm.gate.entity.generic.BusinessPartner
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Repository

@Repository
interface BusinessPartnerRepository : JpaRepository<BusinessPartner, Long>
interface BusinessPartnerRepository : JpaRepository<BusinessPartner, Long>, CrudRepository<BusinessPartner, Long> {

fun findByStageAndExternalIdIn(stage: StageType, externalId: Collection<String>): Set<BusinessPartner>

fun findByStageAndExternalIdIn(stage: StageType, externalId: Collection<String>, pageable: Pageable): Page<BusinessPartner>

fun findByStage(stage: StageType, pageable: Pageable): Page<BusinessPartner>
}
Loading

0 comments on commit 8997116

Please sign in to comment.