Skip to content

Commit

Permalink
Merge pull request #393 from catenax-ng/refactor/API_cleanup
Browse files Browse the repository at this point in the history
Refctor: Cleanup DTOs
  • Loading branch information
nicoprow authored Aug 17, 2023
2 parents 2b754d6 + f32862f commit 83879e2
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.gate.api.model.request.ChangeLogSearchRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.ChangelogSearchRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.*
import org.springframework.stereotype.Service
import java.time.Instant
Expand All @@ -47,7 +47,7 @@ class GateQueryService(

do {
val pageResponse = gateClient.changelog().getInputChangelog(
searchRequest = ChangeLogSearchRequest(timestampAfter = modifiedAfter),
searchRequest = ChangelogSearchRequest(timestampAfter = modifiedAfter),
paginationRequest = PaginationRequest(page, bridgeConfigProperties.queryPageSize)
)
page++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressVerboseDto
import org.eclipse.tractusx.bpdm.gate.api.client.GateClient
import org.eclipse.tractusx.bpdm.gate.api.model.*
import org.eclipse.tractusx.bpdm.gate.api.model.request.AddressGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.ChangeLogSearchRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.LegalEntityGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.request.SiteGateInputRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.SharingStateDto
import org.eclipse.tractusx.bpdm.pool.api.client.PoolApiClient
import org.eclipse.tractusx.bpdm.pool.api.model.request.ChangelogSearchRequest
import org.eclipse.tractusx.bpdm.pool.api.model.request.LegalEntityPropertiesSearchRequest
import org.eclipse.tractusx.bpdm.pool.api.model.response.LegalEntityMatchVerboseDto
import org.eclipse.tractusx.bpdm.pool.api.model.response.SitePoolVerboseDto
Expand All @@ -44,6 +42,8 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.ContextConfiguration
import org.eclipse.tractusx.bpdm.gate.api.model.request.ChangelogSearchRequest as GateChangelogSearchRequest
import org.eclipse.tractusx.bpdm.pool.api.model.request.ChangelogSearchRequest as PoolChangelogSearchRequest

private val DEFAULT_PAGINATION_REQUEST = PaginationRequest(0, 100)

Expand All @@ -67,7 +67,7 @@ class BridgeSyncIT @Autowired constructor(
fun `just use API clients`() {
assertGateChangelogHasCount(0)
val poolChangelogResponses = poolClient.changelogs().getChangelogEntries(
paginationRequest = DEFAULT_PAGINATION_REQUEST, changelogSearchRequest = ChangelogSearchRequest(timestampAfter = null, bpns = null)
paginationRequest = DEFAULT_PAGINATION_REQUEST, changelogSearchRequest = PoolChangelogSearchRequest(timestampAfter = null, bpns = null)
)
assertThat(poolChangelogResponses.contentSize).isZero()
bridgeClient.bridge().triggerSync()
Expand Down Expand Up @@ -220,15 +220,15 @@ class BridgeSyncIT @Autowired constructor(
private fun assertGateChangelogHasCount(changelogCount: Int) {
val gateChangelogResponses = gateClient.changelog().getInputChangelog(
paginationRequest = DEFAULT_PAGINATION_REQUEST,
searchRequest = ChangeLogSearchRequest(timestampAfter = null, businessPartnerTypes = emptySet())
searchRequest = GateChangelogSearchRequest(timestampAfter = null, businessPartnerTypes = emptySet())
)
assertThat(gateChangelogResponses.contentSize).isEqualTo(changelogCount)
}

private fun assertPoolChangelogHasCount(changelogCount: Int) {
val poolChangelogResponses = poolClient.changelogs().getChangelogEntries(
paginationRequest = DEFAULT_PAGINATION_REQUEST,
changelogSearchRequest = ChangelogSearchRequest(timestampAfter = null, bpns = null)
changelogSearchRequest = PoolChangelogSearchRequest(timestampAfter = null, bpns = null)

)
assertThat(poolChangelogResponses.contentSize).isEqualTo(changelogCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import com.github.tomakehurst.wiremock.junit5.WireMockExtension
import com.github.tomakehurst.wiremock.verification.LoggedRequest
import org.assertj.core.api.Assertions
import org.eclipse.tractusx.bpdm.common.service.BaseSyncRecordService
import org.eclipse.tractusx.bpdm.gate.api.model.request.ChangeLogSearchRequest
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.PageChangeLogDto
import org.junit.jupiter.api.Assertions.assertThrows
Expand Down Expand Up @@ -125,15 +125,15 @@ class SyncStateIT @Autowired constructor(
Assertions.assertThat(loggedRequests.size).isEqualTo(3)

// 1st sync polls from initial timestamp (2000-01-01)
val pollFrom1stSync = parseBody<ChangeLogSearchRequest>(loggedRequests[0]).timestampAfter
val pollFrom1stSync = parseBody<ChangelogSearchRequest>(loggedRequests[0]).timestampAfter
Assertions.assertThat(pollFrom1stSync).isEqualTo(TS_INITIAL_POLL_FROM)

// 2nd sync polls from around timestamp of 1st successful sync
val pollFrom2ndSync = parseBody<ChangeLogSearchRequest>(loggedRequests[1]).timestampAfter
val pollFrom2ndSync = parseBody<ChangelogSearchRequest>(loggedRequests[1]).timestampAfter
Assertions.assertThat(pollFrom2ndSync).isBetween(tsBefore1stSuccessfulSync, tsAfter1stSuccessfulSync)

// 3rd sync polls from around timestamp of 2nd successful sync
val pollFrom3rdSync = parseBody<ChangeLogSearchRequest>(loggedRequests[2]).timestampAfter
val pollFrom3rdSync = parseBody<ChangelogSearchRequest>(loggedRequests[2]).timestampAfter
Assertions.assertThat(pollFrom3rdSync).isBetween(tsBefore2ndSuccessfulSync, tsAfter2ndSuccessfulSync)
}

Expand Down Expand Up @@ -211,23 +211,23 @@ class SyncStateIT @Autowired constructor(
Assertions.assertThat(loggedRequests.size).isEqualTo(5)

// 1st sync polls from initial timestamp (2000-01-01)
val pollFrom1stSync = parseBody<ChangeLogSearchRequest>(loggedRequests[0]).timestampAfter
val pollFrom1stSync = parseBody<ChangelogSearchRequest>(loggedRequests[0]).timestampAfter
Assertions.assertThat(pollFrom1stSync).isEqualTo(TS_INITIAL_POLL_FROM)

// 2nd sync polls from around timestamp of 1st successful sync
val pollFrom2ndSync = parseBody<ChangeLogSearchRequest>(loggedRequests[1]).timestampAfter
val pollFrom2ndSync = parseBody<ChangelogSearchRequest>(loggedRequests[1]).timestampAfter
Assertions.assertThat(pollFrom2ndSync).isBetween(tsBefore1stSuccessfulSync, tsAfter1stSuccessfulSync)

// 3rd sync still polls from same timestamp because last sync has failed!
val pollFrom3rdSync = parseBody<ChangeLogSearchRequest>(loggedRequests[2]).timestampAfter
val pollFrom3rdSync = parseBody<ChangelogSearchRequest>(loggedRequests[2]).timestampAfter
Assertions.assertThat(pollFrom3rdSync).isEqualTo(pollFrom2ndSync)

// 4th sync still polls from same timestamp because last sync has failed!
val pollFrom4thSync = parseBody<ChangeLogSearchRequest>(loggedRequests[3]).timestampAfter
val pollFrom4thSync = parseBody<ChangelogSearchRequest>(loggedRequests[3]).timestampAfter
Assertions.assertThat(pollFrom4thSync).isEqualTo(pollFrom2ndSync)

// 5th sync polls from around timestamp of 2nd successful sync
val pollFrom5thSync = parseBody<ChangeLogSearchRequest>(loggedRequests[4]).timestampAfter
val pollFrom5thSync = parseBody<ChangelogSearchRequest>(loggedRequests[4]).timestampAfter
Assertions.assertThat(pollFrom5thSync).isBetween(tsBefore2ndSuccessfulSync, tsAfter2ndSuccessfulSync)
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
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.request.ChangelogSearchRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.ChangelogGateDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageChangeLogDto
import org.springdoc.core.annotations.ParameterObject
Expand Down Expand Up @@ -53,7 +53,7 @@ interface GateChangelogApi {
@PostExchange("/input/changelog/search")
fun getInputChangelog(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody searchRequest: ChangeLogSearchRequest
@RequestBody searchRequest: ChangelogSearchRequest
): PageChangeLogDto<ChangelogGateDto>


Expand All @@ -71,6 +71,6 @@ interface GateChangelogApi {
@PostExchange("/output/changelog/search")
fun getOutputChangelog(
@ParameterObject @Valid paginationRequest: PaginationRequest,
@RequestBody searchRequest: ChangeLogSearchRequest
@RequestBody searchRequest: ChangelogSearchRequest
): PageChangeLogDto<ChangelogGateDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import io.swagger.v3.oas.annotations.Parameter
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import java.time.Instant

data class ChangeLogSearchRequest(
data class ChangelogSearchRequest(

@field:Parameter(description = "From when to search changelog entries", example = "2023-03-20T10:23:28.194Z", required = false)
val timestampAfter: Instant? = null,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package org.eclipse.tractusx.bpdm.gate.controller
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
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.request.ChangelogSearchRequest
import org.eclipse.tractusx.bpdm.gate.api.model.response.ChangelogGateDto
import org.eclipse.tractusx.bpdm.gate.api.model.response.PageChangeLogDto
import org.eclipse.tractusx.bpdm.gate.service.ChangelogService
Expand All @@ -38,7 +38,7 @@ class ChangelogController(

@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyInputDataAsRole())")
override fun getInputChangelog(
paginationRequest: PaginationRequest, searchRequest: ChangeLogSearchRequest
paginationRequest: PaginationRequest, searchRequest: ChangelogSearchRequest
): PageChangeLogDto<ChangelogGateDto> {
return changelogService.getChangeLogEntries(
searchRequest.externalIds,
Expand All @@ -53,7 +53,7 @@ class ChangelogController(
@PreAuthorize("hasAuthority(@gateSecurityConfigProperties.getReadCompanyOutputDataAsRole())")
override fun getOutputChangelog(
paginationRequest: PaginationRequest,
searchRequest: ChangeLogSearchRequest
searchRequest: ChangelogSearchRequest
): PageChangeLogDto<ChangelogGateDto> {
return changelogService.getChangeLogEntries(
searchRequest.externalIds,
Expand Down
Loading

0 comments on commit 83879e2

Please sign in to comment.