Skip to content

Commit

Permalink
Merge pull request #320 from catenax-ng/feat/api-model_rename_dtos_step4
Browse files Browse the repository at this point in the history
Feat/api model rename dtos step4
  • Loading branch information
nicoprow authored Jul 7, 2023
2 parents 7c45439 + ac58b44 commit 638b952
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
package com.catenax.bpdm.bridge.dummy.dto

import org.eclipse.tractusx.bpdm.common.dto.LegalEntityDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputDto

data class GateLegalEntityInfo(
val legalNameParts: List<String> = emptyList(),
val legalEntity: LegalEntityDto,
val legalAddress: AddressGateInputResponse,
val legalAddress: AddressGateInputDto,
val externalId: String,
val bpn: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ class GateQueryService(
return validContent
}

private fun getAddressesInput(externalIds: Set<String>): Collection<AddressGateInputResponse> {
private fun getAddressesInput(externalIds: Set<String>): Collection<AddressGateInputDto> {
if (externalIds.isEmpty()) {
return emptyList()
}

var page = 0
val validContent = mutableListOf<AddressGateInputResponse>()
val validContent = mutableListOf<AddressGateInputDto>()

do {
val pageResponse = gateClient.addresses().getAddressesByExternalIds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateOutputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateOutputDto
import org.springdoc.core.annotations.ParameterObject
import org.springframework.http.MediaType
Expand Down Expand Up @@ -76,7 +76,7 @@ interface GateAddressApi {

@GetMapping("/input/addresses/{externalId}")
@GetExchange("/input/addresses/{externalId}")
fun getAddressByExternalId(@Parameter(description = "External identifier") @PathVariable externalId: String): AddressGateInputResponse
fun getAddressByExternalId(@Parameter(description = "External identifier") @PathVariable externalId: String): AddressGateInputDto

@Operation(
summary = "Get page of addresses filtered by a collection of externalIds",
Expand All @@ -93,7 +93,7 @@ interface GateAddressApi {
fun getAddressesByExternalIds(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody externalIds: Collection<String>
): PageDto<AddressGateInputResponse>
): PageDto<AddressGateInputDto>


@Operation(
Expand All @@ -108,7 +108,7 @@ interface GateAddressApi {
)
@GetMapping("/input/addresses")
@GetExchange("/input/addresses")
fun getAddresses(@ParameterObject @Valid paginationRequest: PaginationRequest): PageDto<AddressGateInputResponse>
fun getAddresses(@ParameterObject @Valid paginationRequest: PaginationRequest): PageDto<AddressGateInputDto>

@Operation(
summary = "Get page of addresses (Output)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import jakarta.validation.Valid
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.ChangeLogSearchRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.ChangelogGateDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageChangeLogResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageChangeLogDto
import org.springdoc.core.annotations.ParameterObject
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.*
Expand All @@ -54,7 +54,7 @@ interface GateChangelogApi {
fun getInputChangelog(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody searchRequest: ChangeLogSearchRequest
): PageChangeLogResponse<ChangelogGateDto>
): PageChangeLogDto<ChangelogGateDto>


@Operation(
Expand All @@ -72,5 +72,5 @@ interface GateChangelogApi {
fun getOutputChangelog(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody searchRequest: ChangeLogSearchRequest
): PageChangeLogResponse<ChangelogGateDto>
): PageChangeLogDto<ChangelogGateDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.eclipse.tractusx.bpdm.gate.api.model.LogisticAddressGateDto
name = "AddressGateInputDto", description = "Address with legal entity or site references. " +
"Only one of either legal entity or site external id can be set for an address."
)
data class AddressGateInputResponse(
data class AddressGateInputDto(

@field:JsonUnwrapped
val address: LogisticAddressGateDto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data class LegalEntityGateInputDto(
val roles: Collection<BusinessPartnerRole> = emptyList(),

@get:Schema(description = "Address of the official seat of this legal entity")
val legalAddress: AddressGateInputResponse,
val legalAddress: AddressGateInputDto,

@Schema(description = "ID the record has in the external system where the record originates from", required = true)
val externalId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.eclipse.tractusx.bpdm.gate.api.exception.ChangeLogOutputError


@Schema(description = "Paginated collection of results")
data class PageChangeLogResponse<T>(
data class PageChangeLogDto<T>(
@Schema(description = "Total number of all results in all pages")
val totalElements: Long,
@Schema(description = "Total number pages")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data class SiteGateInputDto(
val site: SiteGateDto,

@get:Schema(description = "Main address where this site resides")
val mainAddress: AddressGateInputResponse,
val mainAddress: AddressGateInputDto,

@Schema(description = "ID the record has in the external system where the record originates from")
val externalId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.gate.api.GateAddressApi
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateOutputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateOutputDto
import org.eclipse.tractusx.bpdm.gate.config.ApiConfigProperties
import org.eclipse.tractusx.bpdm.gate.containsDuplicates
Expand Down Expand Up @@ -58,7 +58,7 @@ class AddressController(


@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyInputDataAsRole())")
override fun getAddressByExternalId(externalId: String): AddressGateInputResponse {
override fun getAddressByExternalId(externalId: String): AddressGateInputDto {

return addressService.getAddressByExternalId(externalId)
}
Expand All @@ -67,12 +67,12 @@ class AddressController(
override fun getAddressesByExternalIds(
paginationRequest: PaginationRequest,
externalIds: Collection<String>
): PageDto<AddressGateInputResponse> {
): PageDto<AddressGateInputDto> {
return addressService.getAddresses(page = paginationRequest.page, size = paginationRequest.size, externalIds = externalIds)
}

@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyInputDataAsRole())")
override fun getAddresses(paginationRequest: PaginationRequest): PageDto<AddressGateInputResponse> {
override fun getAddresses(paginationRequest: PaginationRequest): PageDto<AddressGateInputDto> {
return addressService.getAddresses(page = paginationRequest.page, size = paginationRequest.size)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.eclipse.tractusx.bpdm.common.model.OutputInputEnum
import org.eclipse.tractusx.bpdm.gate.api.GateChangelogApi
import org.eclipse.tractusx.bpdm.gate.api.model.request.ChangeLogSearchRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.ChangelogGateDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageChangeLogResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageChangeLogDto
import org.eclipse.tractusx.bpdm.gate.service.ChangelogService
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.validation.annotation.Validated
Expand All @@ -39,7 +39,7 @@ class ChangelogController(
@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyInputDataAsRole())")
override fun getInputChangelog(
paginationRequest: PaginationRequest, searchRequest: ChangeLogSearchRequest
): PageChangeLogResponse<ChangelogGateDto> {
): PageChangeLogDto<ChangelogGateDto> {
return changelogService.getChangeLogEntries(
searchRequest.externalIds,
searchRequest.lsaTypes,
Expand All @@ -54,7 +54,7 @@ class ChangelogController(
override fun getOutputChangelog(
paginationRequest: PaginationRequest,
searchRequest: ChangeLogSearchRequest
): PageChangeLogResponse<ChangelogGateDto> {
): PageChangeLogDto<ChangelogGateDto> {
return changelogService.getChangeLogEntries(
searchRequest.externalIds,
searchRequest.lsaTypes,
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.OutputInputEnum
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateOutputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateInputDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.AddressGateOutputDto
import org.eclipse.tractusx.bpdm.gate.config.BpnConfigProperties
import org.eclipse.tractusx.bpdm.gate.entity.ChangelogEntry
Expand All @@ -46,7 +46,7 @@ class AddressService(
) {
private val logger = KotlinLogging.logger { }

fun getAddresses(page: Int, size: Int, externalIds: Collection<String>? = null): PageDto<AddressGateInputResponse> {
fun getAddresses(page: Int, size: Int, externalIds: Collection<String>? = null): PageDto<AddressGateInputDto> {

val logisticAddressPage = if (externalIds != null) {
addressRepository.findByExternalIdInAndDataType(externalIds, OutputInputEnum.Input, PageRequest.of(page, size))
Expand All @@ -63,13 +63,13 @@ class AddressService(
)
}

private fun toValidLogisticAddresses(logisticAddressPage: Page<LogisticAddress>): List<AddressGateInputResponse> {
private fun toValidLogisticAddresses(logisticAddressPage: Page<LogisticAddress>): List<AddressGateInputDto> {
return logisticAddressPage.content.map { logisticAddress ->
logisticAddress.toAddressGateInputResponse(logisticAddress)
}
}

fun getAddressByExternalId(externalId: String): AddressGateInputResponse {
fun getAddressByExternalId(externalId: String): AddressGateInputDto {

val logisticAddress =
addressRepository.findByExternalIdAndDataType(externalId, OutputInputEnum.Input) ?: throw BpdmNotFoundException("Logistic Address", externalId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.eclipse.tractusx.bpdm.gate.api.exception.ChangeLogOutputError
import org.eclipse.tractusx.bpdm.gate.api.model.LsaType
import org.eclipse.tractusx.bpdm.gate.api.model.response.ChangelogGateDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.ErrorInfo
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageChangeLogResponse
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageChangeLogDto
import org.eclipse.tractusx.bpdm.gate.repository.ChangelogRepository
import org.eclipse.tractusx.bpdm.gate.repository.ChangelogRepository.Specs.byCreatedAtGreaterThan
import org.eclipse.tractusx.bpdm.gate.repository.ChangelogRepository.Specs.byExternalIdsIn
Expand All @@ -45,7 +45,7 @@ class ChangelogService(private val changelogRepository: ChangelogRepository) {
outputInputEnum: OutputInputEnum?,
page: Int,
pageSize: Int
): PageChangeLogResponse<ChangelogGateDto> {
): PageChangeLogDto<ChangelogGateDto> {

val nonNullExternalIds = externalIds ?: emptySet()

Expand Down Expand Up @@ -74,7 +74,7 @@ class ChangelogService(private val changelogRepository: ChangelogRepository) {
}


return PageChangeLogResponse(
return PageChangeLogDto(
page = page, totalElements = pageDto.totalElements,
totalPages = pageDto.totalPages,
contentSize = pageDto.content.size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ fun getMainAddressForLegalEntityExternalId(siteExternalId: String): String {
}

//Logistic Address mapping to AddressGateInputResponse
fun LogisticAddress.toAddressGateInputResponse(logisticAddressPage: LogisticAddress): AddressGateInputResponse {
fun LogisticAddress.toAddressGateInputResponse(logisticAddressPage: LogisticAddress): AddressGateInputDto {

val addressGateInputResponse = AddressGateInputResponse(
val addressGateInputResponse = AddressGateInputDto(
address = logisticAddressPage.toLogisticAddressDto(),
externalId = externalId,
legalEntityExternalId = legalEntity?.externalId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ object ResponseValues {
updatedAt = CommonValues.now,
)

val addressGateInputResponse1 = AddressGateInputResponse(
val addressGateInputResponse1 = AddressGateInputDto(
address = RequestValues.address1
.copy(
nameParts = listOf(CommonValues.name1),
Expand All @@ -280,7 +280,7 @@ object ResponseValues {
legalEntityExternalId = CommonValues.externalId1,
)

val addressGateInputResponse2 = AddressGateInputResponse(
val addressGateInputResponse2 = AddressGateInputDto(
address = RequestValues.address2
.copy(
nameParts = listOf(CommonValues.nameSite1),
Expand All @@ -289,15 +289,15 @@ object ResponseValues {
siteExternalId = CommonValues.externalIdSite1,
)

val logisticAddressGateInputResponse1 = AddressGateInputResponse(
val logisticAddressGateInputResponse1 = AddressGateInputDto(
address = RequestValues.logisticAddress1.copy(
nameParts = listOf(CommonValues.name1),
),
externalId = CommonValues.externalIdAddress1,
legalEntityExternalId = null,
)

val logisticAddressGateInputResponse2 = AddressGateInputResponse(
val logisticAddressGateInputResponse2 = AddressGateInputDto(
address = RequestValues.logisticAddress2.copy(
nameParts = listOf(CommonValues.name2),
),
Expand Down Expand Up @@ -327,7 +327,7 @@ object ResponseValues {
val legalEntityGateInputResponse1 = LegalEntityGateInputDto(
legalEntity = RequestValues.legalEntity1,
legalNameParts = listOf(CommonValues.name1),
legalAddress = AddressGateInputResponse(
legalAddress = AddressGateInputDto(
address = RequestValues.logisticAddress1,
externalId = "${CommonValues.externalId1}_legalAddress",
legalEntityExternalId = CommonValues.externalId1,
Expand All @@ -339,7 +339,7 @@ object ResponseValues {
val legalEntityGateInputResponse2 = LegalEntityGateInputDto(
legalEntity = RequestValues.legalEntity2,
legalNameParts = listOf(CommonValues.name2),
legalAddress = AddressGateInputResponse(
legalAddress = AddressGateInputDto(
address = RequestValues.logisticAddress2,
externalId = "${CommonValues.externalId2}_legalAddress",
legalEntityExternalId = CommonValues.externalId2,
Expand Down Expand Up @@ -382,7 +382,7 @@ object ResponseValues {
site = RequestValues.site1,
externalId = CommonValues.externalIdSite1,
legalEntityExternalId = CommonValues.externalId1,
mainAddress = AddressGateInputResponse(
mainAddress = AddressGateInputDto(
address = RequestValues.address1,
externalId = "${CommonValues.externalIdSite1}_site",
legalEntityExternalId = null,
Expand All @@ -394,7 +394,7 @@ object ResponseValues {
site = RequestValues.site2,
externalId = CommonValues.externalIdSite2,
legalEntityExternalId = CommonValues.externalId2,
mainAddress = AddressGateInputResponse(
mainAddress = AddressGateInputDto(
address = RequestValues.address2,
externalId = "${CommonValues.externalIdSite2}_site",
legalEntityExternalId = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.pool.api.model.request.ChangelogSearchRequest
import org.eclipse.tractusx.bpdm.pool.api.model.response.ChangelogEntryResponse
import org.eclipse.tractusx.bpdm.pool.api.model.response.ChangelogEntryVerboseDto
import org.springdoc.core.annotations.ParameterObject
import org.springframework.http.MediaType
import org.springframework.web.bind.annotation.PostMapping
Expand Down Expand Up @@ -56,5 +56,5 @@ interface PoolChangelogApi {
fun getChangelogEntries(
@RequestBody changelogSearchRequest: ChangelogSearchRequest,
@ParameterObject paginationRequest: PaginationRequest
): PageDto<ChangelogEntryResponse>
): PageDto<ChangelogEntryVerboseDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.eclipse.tractusx.bpdm.pool.api.model.ChangelogType
import java.time.Instant

@Schema(name = "ChangelogEntryVerboseDto", description = "Changelog entry for a business partner")
data class ChangelogEntryResponse(
data class ChangelogEntryVerboseDto(

@Schema(description = "Business Partner Number of the changelog entry")
val bpn: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.pool.api.PoolChangelogApi
import org.eclipse.tractusx.bpdm.pool.api.model.request.ChangelogSearchRequest
import org.eclipse.tractusx.bpdm.pool.api.model.response.ChangelogEntryResponse
import org.eclipse.tractusx.bpdm.pool.api.model.response.ChangelogEntryVerboseDto
import org.eclipse.tractusx.bpdm.pool.config.ControllerConfigProperties
import org.eclipse.tractusx.bpdm.pool.exception.BpdmRequestSizeException
import org.eclipse.tractusx.bpdm.pool.service.PartnerChangelogService
Expand All @@ -40,7 +40,7 @@ class ChangelogController(
override fun getChangelogEntries(
changelogSearchRequest: ChangelogSearchRequest,
paginationRequest: PaginationRequest
): PageDto<ChangelogEntryResponse> {
): PageDto<ChangelogEntryVerboseDto> {

changelogSearchRequest.bpns?.let { bpns ->
if (bpns.size > controllerConfigProperties.searchRequestLimit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class PartnerChangelogService(
fromTime: Instant?,
pageIndex: Int,
pageSize: Int
): PageDto<org.eclipse.tractusx.bpdm.pool.api.model.response.ChangelogEntryResponse> {
): PageDto<org.eclipse.tractusx.bpdm.pool.api.model.response.ChangelogEntryVerboseDto> {
val spec = Specification.allOf(byBpnsIn(bpns), byLsaTypesIn(lsaTypes), byUpdatedGreaterThan(fromTime))
val pageRequest = PageRequest.of(pageIndex, pageSize, Sort.by(PartnerChangelogEntry::updatedAt.name).ascending())
val page = partnerChangelogEntryRepository.findAll(spec, pageRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,6 @@ fun SyncRecord.toDto(): SyncDto {
return SyncDto(type, status, count, progress, errorDetails, startedAt, finishedAt)
}

fun PartnerChangelogEntry.toDto(): ChangelogEntryResponse {
return ChangelogEntryResponse(bpn, changelogType, createdAt, changelogSubject)
fun PartnerChangelogEntry.toDto(): ChangelogEntryVerboseDto {
return ChangelogEntryVerboseDto(bpn, changelogType, createdAt, changelogSubject)
}
Loading

0 comments on commit 638b952

Please sign in to comment.