Skip to content

Commit

Permalink
fix(Cleaning-Service-Dummy): add confidence criteria to cleaned gener…
Browse files Browse the repository at this point in the history
…ic business partner
  • Loading branch information
nicoprow committed Jan 5, 2024
1 parent 772bb6d commit a53692d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class CleaningServiceDummy(

val addressDto = shouldCreateAddress(addressType, addressPartner)

return TaskStepResultEntryDto(reservedTask.taskId, BusinessPartnerFullDto(genericBusinessPartner, legalEntityDto, siteDto, addressDto))
val updatedGenericBusinessPartner = genericBusinessPartner.update(addressType, legalEntityDto, siteDto, addressDto)

return TaskStepResultEntryDto(reservedTask.taskId, BusinessPartnerFullDto(updatedGenericBusinessPartner, legalEntityDto, siteDto, addressDto))
}

private fun shouldCreateAddress(
Expand Down Expand Up @@ -154,5 +156,25 @@ class CleaningServiceDummy(
genericPartner.site.siteBpn != null
}

private fun BusinessPartnerGenericDto.update(
addressType: AddressType,
legalEntityDto: LegalEntityDto,
siteDto: SiteDto?,
logisticAddress: LogisticAddressDto?
): BusinessPartnerGenericDto {
val relevantAddress = when (addressType) {
AddressType.LegalAndSiteMainAddress -> legalEntityDto.legalAddress!!
AddressType.LegalAddress -> legalEntityDto.legalAddress!!
AddressType.SiteMainAddress -> siteDto!!.mainAddress!!
AddressType.AdditionalAddress -> logisticAddress!!
}

return copy(
legalEntity = legalEntity.copy(confidenceCriteria = legalEntityDto.confidenceCriteria),
site = site.copy(confidenceCriteria = siteDto?.confidenceCriteria),
address = address.copy(addressType = addressType, confidenceCriteria = relevantAddress.confidenceCriteria)
)
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
WITH mapping AS (
SELECT bp.id as business_partner_id, nextVal('bpdm_sequence') as confidence_id
FROM business_partners bp
WHERE bp.stage = 'Output' AND bp.site_confidence_id IS NULL AND (bp.address_type = 'SITE_MAIN_ADDRESS' OR bpd.address_type = 'LEGAL_AND_SITE_MAIN_ADDRESS')
),
confidence AS (
INSERT INTO confidence_criteria (id, created_at, updated_at, uuid, shared_by_owner, checked_by_external_data_source, number_of_business_partners, last_confidence_check_at, next_confidence_check_at, confidence_level)
SELECT mapping.confidence_id, NOW(), NOW(), gen_random_uuid(), FALSE, FALSE, 1, NOW()::timestamp, NOW()::timestamp, 0
FROM mapping
)
UPDATE business_partners bp
SET site_confidence_id = mapping.confidence_id
FROM mapping
WHERE bp.id = mapping.business_partner_id;

0 comments on commit a53692d

Please sign in to comment.