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

Refactor: Simplify Gate/Pool API clients #483

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 @@ -46,7 +46,7 @@ class GateQueryService(
val content = mutableListOf<ChangelogGateDto>()

do {
val pageResponse = gateClient.changelog().getInputChangelog(
val pageResponse = gateClient.changelog.getInputChangelog(
searchRequest = ChangelogSearchRequest(timestampAfter = modifiedAfter),
paginationRequest = PaginationRequest(page, bridgeConfigProperties.queryPageSize)
)
Expand Down Expand Up @@ -123,7 +123,7 @@ class GateQueryService(
val content = mutableListOf<SharingStateDto>()

do {
val pageResponse = gateClient.sharingState().getSharingStates(
val pageResponse = gateClient.sharingState.getSharingStates(
businessPartnerType = businessPartnerType,
externalIds = externalIds,
paginationRequest = PaginationRequest(page, bridgeConfigProperties.queryPageSize)
Expand All @@ -148,7 +148,7 @@ class GateQueryService(
val validContent = mutableListOf<LegalEntityGateInputDto>()

do {
val pageResponse = gateClient.legalEntities().getLegalEntitiesByExternalIds(
val pageResponse = gateClient.legalEntities.getLegalEntitiesByExternalIds(
externalIds = externalIds,
paginationRequest = PaginationRequest(page, bridgeConfigProperties.queryPageSize)
)
Expand All @@ -169,7 +169,7 @@ class GateQueryService(
val validContent = mutableListOf<SiteGateInputDto>()

do {
val pageResponse = gateClient.sites().getSitesByExternalIds(
val pageResponse = gateClient.sites.getSitesByExternalIds(
externalIds = externalIds,
paginationRequest = PaginationRequest(page, bridgeConfigProperties.queryPageSize)
)
Expand All @@ -190,7 +190,7 @@ class GateQueryService(
val validContent = mutableListOf<AddressGateInputDto>()

do {
val pageResponse = gateClient.addresses().getAddressesByExternalIds(
val pageResponse = gateClient.addresses.getAddressesByExternalIds(
externalIds = externalIds,
paginationRequest = PaginationRequest(page, bridgeConfigProperties.queryPageSize)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,22 +260,22 @@ class GateUpdateService(

private fun putLegalEntityOutput(request: LegalEntityGateOutputRequest?) =
request?.let {
gateClient.legalEntities().upsertLegalEntitiesOutput(listOf(it))
gateClient.legalEntities.upsertLegalEntitiesOutput(listOf(it))
}

private fun putSiteOutput(request: SiteGateOutputRequest?) =
request?.let {
gateClient.sites().upsertSitesOutput(listOf(it))
gateClient.sites.upsertSitesOutput(listOf(it))
}

private fun putAddressOutput(request: AddressGateOutputRequest?) =
request?.let {
gateClient.addresses().upsertAddressesOutput(listOf(it))
gateClient.addresses.upsertAddressesOutput(listOf(it))
}

private fun upsertSharingState(request: SharingStateDto?) =
request?.let {
gateClient.sharingState().upsertSharingState(it)
gateClient.sharingState.upsertSharingState(it)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PoolUpdateService(
)
}

return poolClient.legalEntities().createBusinessPartners(createRequests)
return poolClient.legalEntities.createBusinessPartners(createRequests)
.also { logger.info { "Pool accepted ${it.entityCount} new legal entities, ${it.errorCount} were refused" } }
}

Expand All @@ -61,7 +61,7 @@ class PoolUpdateService(
)
}

return poolClient.legalEntities().updateBusinessPartners(updateRequests)
return poolClient.legalEntities.updateBusinessPartners(updateRequests)
.also { logger.info { "Pool accepted ${it.entityCount} updated legal entities, ${it.errorCount} were refused" } }
}

Expand Down Expand Up @@ -90,7 +90,7 @@ class PoolUpdateService(
"because some parent BPN-L entries are missing!"
}
}
return poolClient.sites().createSite(createRequests)
return poolClient.sites.createSite(createRequests)
.also { logger.info { "Pool accepted ${it.entityCount} new sites, ${it.errorCount} were refused" } }
}

Expand All @@ -106,7 +106,7 @@ class PoolUpdateService(
)
}

return poolClient.sites().updateSite(updateRequests)
return poolClient.sites.updateSite(updateRequests)
.also { logger.info { "Pool accepted ${it.entityCount} updated sites, ${it.errorCount} were refused" } }
}

Expand Down Expand Up @@ -156,20 +156,20 @@ class PoolUpdateService(
"because some parent BPN-L/S entries are missing!"
}
}
return poolClient.addresses().createAddresses(createRequests)
return poolClient.addresses.createAddresses(createRequests)
.also { logger.info { "Pool accepted ${it.entityCount} new addresses, ${it.errorCount} were refused" } }
}

private fun isSiteMainAddress(it: GateAddressInfo): Boolean {

val mainAdressExternalId = it.siteExternalId?.let { it1 -> gateQueryService.gateClient.sites().getSiteByExternalId(it1).mainAddress.externalId }
val mainAdressExternalId = it.siteExternalId?.let { it1 -> gateQueryService.gateClient.sites.getSiteByExternalId(it1).mainAddress.externalId }
return it.externalId == mainAdressExternalId
}

private fun isLegalAddress(it: GateAddressInfo): Boolean {

val legalAdressExternalId =
it.legalEntityExternalId?.let { it1 -> gateQueryService.gateClient.legalEntities().getLegalEntityByExternalId(it1).legalAddress.externalId }
it.legalEntityExternalId?.let { it1 -> gateQueryService.gateClient.legalEntities.getLegalEntityByExternalId(it1).legalAddress.externalId }
return it.externalId == legalAdressExternalId
}

Expand All @@ -187,7 +187,7 @@ class PoolUpdateService(
)
}

return poolClient.addresses().updateAddresses(updateRequests)
return poolClient.addresses.updateAddresses(updateRequests)
.also { logger.info { "Pool accepted ${it.entityCount} updated addresses, ${it.errorCount} were refused" } }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BridgeSyncIT @Autowired constructor(
@Test
fun `just use API clients`() {
assertGateChangelogHasCount(0)
val poolChangelogResponses = poolClient.changelogs().getChangelogEntries(
val poolChangelogResponses = poolClient.changelogs.getChangelogEntries(
paginationRequest = DEFAULT_PAGINATION_REQUEST, changelogSearchRequest = ChangelogSearchRequest(timestampAfter = null, bpns = null)
)
assertThat(poolChangelogResponses.contentSize).isZero()
Expand All @@ -83,7 +83,7 @@ class BridgeSyncIT @Autowired constructor(
GateRequestValues.legalEntityGateInputRequest2,
GateRequestValues.legalEntityGateInputRequest3
)
gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests)
gateClient.legalEntities.upsertLegalEntities(gateLegalEntityRequests)

assertGateChangelogHasCount(3 + 3) // 3 LEs + 3 addresses
assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0)
Expand All @@ -101,7 +101,7 @@ class BridgeSyncIT @Autowired constructor(

val gateLegalEntityRequestByBpn = gateLegalEntityRequests.associateBy { bpnByExternalId[it.externalId]!! }

val poolLegalEntityResponses = poolClient.legalEntities().getLegalEntities(
val poolLegalEntityResponses = poolClient.legalEntities.getLegalEntities(
bpSearchRequest = LegalEntityPropertiesSearchRequest.EmptySearchRequest,
paginationRequest = DEFAULT_PAGINATION_REQUEST
)
Expand All @@ -126,13 +126,13 @@ class BridgeSyncIT @Autowired constructor(
GateRequestValues.legalEntityGateInputRequest2,
GateRequestValues.legalEntityGateInputRequest3
)
gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests)
gateClient.legalEntities.upsertLegalEntities(gateLegalEntityRequests)

val gateSiteRequests = listOf(
GateRequestValues.siteGateInputRequest1,
GateRequestValues.siteGateInputRequest2
)
gateClient.sites().upsertSites(gateSiteRequests)
gateClient.sites.upsertSites(gateSiteRequests)

assertGateChangelogHasCount(3 + 2 + 3 + 2) // 3 LEs + 2 sites + 3 le addresses + 2 site main addresses
assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0)
Expand All @@ -150,7 +150,7 @@ class BridgeSyncIT @Autowired constructor(

val gateSiteRequestsByBpn = gateSiteRequests.associateBy { bpnByExternalId[it.externalId]!! }

val poolSiteResponses = poolClient.sites().searchSites(
val poolSiteResponses = poolClient.sites.searchSites(
siteSearchRequest = SiteBpnSearchRequest(sites = gateSiteRequestsByBpn.keys),
paginationRequest = DEFAULT_PAGINATION_REQUEST
)
Expand All @@ -173,17 +173,17 @@ class BridgeSyncIT @Autowired constructor(
val gateLegalEntityRequests = listOf(
GateRequestValues.legalEntityGateInputRequest1,
)
gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests)
gateClient.legalEntities.upsertLegalEntities(gateLegalEntityRequests)
val gateSiteRequests = listOf(
GateRequestValues.siteGateInputRequest1,
)
gateClient.sites().upsertSites(gateSiteRequests)
gateClient.sites.upsertSites(gateSiteRequests)

val gateAddressRequests = listOf(
addressGateInputRequest1,
GateRequestValues.addressGateInputRequest2
)
gateClient.addresses().upsertAddresses(gateAddressRequests)
gateClient.addresses.upsertAddresses(gateAddressRequests)

assertGateChangelogHasCount(1 + 1 + 2 + 2) // 1 LE + 1 site + 2 addresses
assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0)
Expand All @@ -201,7 +201,7 @@ class BridgeSyncIT @Autowired constructor(

val gateAddressRequestsByBpn = gateAddressRequests.associateBy { bpnByExternalId[it.externalId]!! }

val poolAddressResponses = poolClient.addresses().searchAddresses(
val poolAddressResponses = poolClient.addresses.searchAddresses(
addressSearchRequest = AddressPartnerBpnSearchRequest(addresses = gateAddressRequestsByBpn.keys),
paginationRequest = DEFAULT_PAGINATION_REQUEST
)
Expand All @@ -225,7 +225,7 @@ class BridgeSyncIT @Autowired constructor(
GateRequestValues.legalEntityGateInputRequest2,
GateRequestValues.legalEntityGateInputRequest3
)
gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests)
gateClient.legalEntities.upsertLegalEntities(gateLegalEntityRequests)
assertGateChangelogHasCount(3 + 3)
// Action: Sync from Gate to Pool and BPN back to Gate
bridgeClient.bridge().triggerSync()
Expand All @@ -249,7 +249,7 @@ class BridgeSyncIT @Autowired constructor(
),
),
)
gateClient.legalEntities().upsertLegalEntities(listOf(leRquestUpdate))
gateClient.legalEntities.upsertLegalEntities(listOf(leRquestUpdate))
assertGateChangelogHasCount(4 + 4) // 3 insert + 1 update
bridgeClient.bridge().triggerSync()
assertPoolChangelogHasCount(4 + 4)
Expand All @@ -275,13 +275,13 @@ class BridgeSyncIT @Autowired constructor(
GateRequestValues.legalEntityGateInputRequest2,
GateRequestValues.legalEntityGateInputRequest3
)
gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests)
gateClient.legalEntities.upsertLegalEntities(gateLegalEntityRequests)

val gateSiteRequests = listOf(
GateRequestValues.siteGateInputRequest1,
GateRequestValues.siteGateInputRequest2
)
gateClient.sites().upsertSites(gateSiteRequests)
gateClient.sites.upsertSites(gateSiteRequests)

assertGateChangelogHasCount(3 + 2 + 3 + 2) // 3 LEs + 2 sites + 3 le addresses + 2 site main addresses
assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0)
Expand All @@ -298,7 +298,7 @@ class BridgeSyncIT @Autowired constructor(
val bpnByExternalId = buildBpnByExternalIdMap(sharingStatesOkay)
val gateSiteRequestsByBpn = gateSiteRequests.associateBy { bpnByExternalId[it.externalId]!! }

val poolSiteResponses = poolClient.sites().searchSites(
val poolSiteResponses = poolClient.sites.searchSites(
siteSearchRequest = SiteBpnSearchRequest(sites = gateSiteRequestsByBpn.keys),
paginationRequest = DEFAULT_PAGINATION_REQUEST
)
Expand All @@ -316,9 +316,9 @@ class BridgeSyncIT @Autowired constructor(
),
)
)
gateClient.sites().upsertSites(listOf(siteRquestUpdate))
gateClient.sites.upsertSites(listOf(siteRquestUpdate))
bridgeClient.bridge().triggerSync()
val poolSiteUpdateResponses = poolClient.sites().searchSites(
val poolSiteUpdateResponses = poolClient.sites.searchSites(
siteSearchRequest = SiteBpnSearchRequest(sites = gateSiteRequestsByBpn.keys),
paginationRequest = DEFAULT_PAGINATION_REQUEST
)
Expand All @@ -340,17 +340,17 @@ class BridgeSyncIT @Autowired constructor(
val gateLegalEntityRequests = listOf(
GateRequestValues.legalEntityGateInputRequest1,
)
gateClient.legalEntities().upsertLegalEntities(gateLegalEntityRequests)
gateClient.legalEntities.upsertLegalEntities(gateLegalEntityRequests)
val gateSiteRequests = listOf(
GateRequestValues.siteGateInputRequest1,
)
gateClient.sites().upsertSites(gateSiteRequests)
gateClient.sites.upsertSites(gateSiteRequests)

val gateAddressRequests = listOf(
addressGateInputRequest1,
GateRequestValues.addressGateInputRequest2
)
gateClient.addresses().upsertAddresses(gateAddressRequests)
gateClient.addresses.upsertAddresses(gateAddressRequests)

assertGateChangelogHasCount(1 + 1 + 2 + 2) // 1 LE + le address + 1 site + main address + 2 addresses
assertThat(readSuccessfulSharingStatesWithBpn().size).isEqualTo(0)
Expand All @@ -364,7 +364,7 @@ class BridgeSyncIT @Autowired constructor(
val bpnByExternalId = buildBpnByExternalIdMap(readSuccessfulSharingStatesWithBpn())
val gateAddressRequestsByBpn = gateAddressRequests.associateBy { bpnByExternalId[it.externalId]!! }

val poolAddressResponses = poolClient.addresses().searchAddresses(
val poolAddressResponses = poolClient.addresses.searchAddresses(
addressSearchRequest = AddressPartnerBpnSearchRequest(addresses = gateAddressRequestsByBpn.keys),
paginationRequest = DEFAULT_PAGINATION_REQUEST
).content
Expand All @@ -383,9 +383,9 @@ class BridgeSyncIT @Autowired constructor(
),

)
gateClient.addresses().upsertAddresses(listOf(addressRequestUpdate))
gateClient.addresses.upsertAddresses(listOf(addressRequestUpdate))
bridgeClient.bridge().triggerSync()
val poolAddressUpdateResponses = poolClient.addresses().searchAddresses(
val poolAddressUpdateResponses = poolClient.addresses.searchAddresses(
addressSearchRequest = AddressPartnerBpnSearchRequest(addresses = gateAddressRequestsByBpn.keys),
paginationRequest = DEFAULT_PAGINATION_REQUEST
).content
Expand All @@ -402,7 +402,7 @@ class BridgeSyncIT @Autowired constructor(
}

private fun allLegalEntitiesFromPool(): Collection<LegalEntityMatchVerboseDto> {
val poolLegalEntityResponses = poolClient.legalEntities().getLegalEntities(
val poolLegalEntityResponses = poolClient.legalEntities.getLegalEntities(
bpSearchRequest = LegalEntityPropertiesSearchRequest.EmptySearchRequest,
paginationRequest = DEFAULT_PAGINATION_REQUEST
)
Expand All @@ -416,15 +416,15 @@ class BridgeSyncIT @Autowired constructor(
.mapValues { it.value.bpn }

private fun assertGateChangelogHasCount(changelogCount: Int) {
val gateChangelogResponses = gateClient.changelog().getInputChangelog(
val gateChangelogResponses = gateClient.changelog.getInputChangelog(
paginationRequest = DEFAULT_PAGINATION_REQUEST,
searchRequest = org.eclipse.tractusx.bpdm.gate.api.model.request.ChangelogSearchRequest(timestampAfter = null, businessPartnerTypes = emptySet())
)
assertThat(gateChangelogResponses.contentSize).isEqualTo(changelogCount)
}

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

Expand All @@ -434,7 +434,7 @@ class BridgeSyncIT @Autowired constructor(
}

private fun readSuccessfulSharingStatesWithBpn(): List<SharingStateDto> {
val sharingStates = gateClient.sharingState().getSharingStates(
val sharingStates = gateClient.sharingState.getSharingStates(
paginationRequest = DEFAULT_PAGINATION_REQUEST,
businessPartnerType = null,
externalIds = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class TestHelpers(
val identifierTypeDto4 =
IdentifierTypeDto(CommonValues.identifierTypeTechnicalKey4, IdentifierBusinessPartnerType.LEGAL_ENTITY, CommonValues.identifierTypeName4)

poolClient.metadata().createIdentifierType(identifierTypeDto1)
poolClient.metadata().createIdentifierType(identifierTypeDto2)
poolClient.metadata().createIdentifierType(identifierTypeDto3)
poolClient.metadata().createIdentifierType(identifierTypeDto4)
poolClient.metadata.createIdentifierType(identifierTypeDto1)
poolClient.metadata.createIdentifierType(identifierTypeDto2)
poolClient.metadata.createIdentifierType(identifierTypeDto3)
poolClient.metadata.createIdentifierType(identifierTypeDto4)

val legalForm1 = LegalFormRequest(
technicalKey = CommonValues.legalFormTechnicalKey1,
Expand All @@ -89,7 +89,7 @@ class TestHelpers(
abbreviation = CommonValues.legalFormAbbreviation2,
)

poolClient.metadata().createLegalForm(legalForm1)
poolClient.metadata().createLegalForm(legalForm2)
poolClient.metadata.createLegalForm(legalForm1)
poolClient.metadata.createLegalForm(legalForm2)
}
}
Loading