-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pool): #432 Upsert Business Partners from Cleaning Result
- add BpnRequestIdentifierMapping entity - map RequestIdentifier to bpn feat(pool): #432 Upsert Business Partners from Cleaning Result - map RequestIdentifier to bpn
- Loading branch information
1 parent
01774fe
commit 1210c60
Showing
7 changed files
with
279 additions
and
42 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/entity/BpnRequestIdentifierMapping.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
package org.eclipse.tractusx.bpdm.pool.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.Index | ||
import jakarta.persistence.Table | ||
import org.eclipse.tractusx.bpdm.common.model.BaseEntity | ||
|
||
@Entity | ||
@Table( | ||
name = "bpn_requestidentifier_mapping", | ||
indexes = [ | ||
Index(columnList = "request_identifier"), | ||
] | ||
) | ||
class BpnRequestIdentifierMapping( | ||
|
||
@Column(name = "request_identifier", unique = true, nullable = false) | ||
var requestIdentifier: String, | ||
@Column(name = "bpn", nullable = false) | ||
var bpn: String | ||
) : BaseEntity() |
30 changes: 30 additions & 0 deletions
30
...c/main/kotlin/org/eclipse/tractusx/bpdm/pool/repository/BpnRequestIdentifierRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
package org.eclipse.tractusx.bpdm.pool.repository | ||
|
||
import org.eclipse.tractusx.bpdm.pool.entity.BpnRequestIdentifierMapping | ||
import org.springframework.data.repository.CrudRepository | ||
import org.springframework.data.repository.PagingAndSortingRepository | ||
|
||
interface BpnRequestIdentifierRepository : PagingAndSortingRepository<BpnRequestIdentifierMapping, Long>, CrudRepository<BpnRequestIdentifierMapping, Long> { | ||
|
||
fun findDistinctByRequestIdentifierIn(requestIdentifiers: Collection<String>): Set<BpnRequestIdentifierMapping> | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
bpdm-pool/src/main/kotlin/org/eclipse/tractusx/bpdm/pool/service/TaskEntryBpnMapping.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
******************************************************************************/ | ||
|
||
package org.eclipse.tractusx.bpdm.pool.service | ||
|
||
import org.eclipse.tractusx.bpdm.pool.entity.BpnRequestIdentifierMapping | ||
import org.eclipse.tractusx.bpdm.pool.repository.BpnRequestIdentifierRepository | ||
import org.eclipse.tractusx.orchestrator.api.model.BpnReferenceDto | ||
import org.eclipse.tractusx.orchestrator.api.model.BpnReferenceType | ||
import org.eclipse.tractusx.orchestrator.api.model.TaskStepReservationEntryDto | ||
|
||
class TaskEntryBpnMapping(taskEntries: List<TaskStepReservationEntryDto>, bpnRequestIdentifierRepository: BpnRequestIdentifierRepository) { | ||
|
||
private val bpnByRequestIdentifier: MutableMap<String, String> | ||
private val createdBpnByRequestIdentifier: MutableMap<String, String> = mutableMapOf() | ||
init{ | ||
this.bpnByRequestIdentifier = readRequestMappings(taskEntries, bpnRequestIdentifierRepository) | ||
|
||
} | ||
|
||
private fun readRequestMappings(taskEntries: List<TaskStepReservationEntryDto>, bpnRequestIdentifierRepository: BpnRequestIdentifierRepository ): MutableMap<String, String> { | ||
|
||
val references = taskEntries.mapNotNull { it.businessPartner.legalEntity?.bpnLReference } + | ||
taskEntries.mapNotNull { it.businessPartner.site?.bpnSReference } + | ||
taskEntries.mapNotNull { it.businessPartner.address?.bpnAReference } | ||
|
||
val usedRequestIdentifiers: Collection<String> = references.map { it.referenceValue } | ||
|
||
val mappings = bpnRequestIdentifierRepository.findDistinctByRequestIdentifierIn(usedRequestIdentifiers) | ||
val bpnByRequestIdentifier = mappings | ||
.map { it.requestIdentifier to it.bpn } | ||
.toMap() | ||
return bpnByRequestIdentifier.toMutableMap() | ||
} | ||
|
||
fun getBpn(bpnLReference: BpnReferenceDto): String? { | ||
|
||
return if (bpnLReference.referenceType == BpnReferenceType.BpnRequestIdentifier) { | ||
bpnByRequestIdentifier.get(bpnLReference.referenceValue) | ||
} else { | ||
bpnLReference.referenceValue | ||
} | ||
} | ||
|
||
fun addMapping(bpnLReference: BpnReferenceDto, bpn: String) { | ||
|
||
createdBpnByRequestIdentifier[bpnLReference.referenceValue] = bpn | ||
bpnByRequestIdentifier[bpnLReference.referenceValue] = bpn | ||
} | ||
|
||
fun writeCreatedMappingsToDb(bpnRequestIdentifierRepository: BpnRequestIdentifierRepository) { | ||
|
||
val mappingsToCreate = createdBpnByRequestIdentifier.map{ | ||
BpnRequestIdentifierMapping(requestIdentifier=it.key, bpn =it.value) | ||
} | ||
bpnRequestIdentifierRepository.saveAll(mappingsToCreate) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
bpdm-pool/src/main/resources/db/migration/V4_1_0_0__bpn_mapping.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
-- field Rules | ||
create table bpn_requestidentifier_mapping | ||
( | ||
id bigint not null, | ||
uuid UUID not null, | ||
created_at timestamp without time zone not null, | ||
updated_at timestamp without time zone not null, | ||
request_identifier varchar(255) not null, | ||
bpn varchar(255) not null, | ||
primary key (id) | ||
); | ||
|
||
alter table bpn_requestidentifier_mapping | ||
add constraint uc_field_request_identifier unique (uuid); | ||
|
||
create index idx_request_identifier_on_bpn_requestidentifier_mapping | ||
on bpn_requestidentifier_mapping (request_identifier); | ||
|
||
commit; | ||
|
Oops, something went wrong.