From 12790580435112fb34ea8a2488de6318de1d7ffe Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Mon, 6 May 2024 08:40:01 +0200 Subject: [PATCH] feature: #586 implement review feedback --- .../model/response/factory/AssetMapperFactory.java | 11 +++++++++-- .../model/response/mapping/submodel/MapperHelper.java | 9 --------- .../infrastructure/repository/BpnRepositoryImpl.java | 6 +++++- .../bpn/infrastructure/repository/BpnServiceImpl.java | 7 ++----- .../common/config/RestTemplateConfiguration.java | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/AssetMapperFactory.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/AssetMapperFactory.java index 34c8e5b638..88e9dbf3af 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/AssetMapperFactory.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/AssetMapperFactory.java @@ -47,7 +47,6 @@ import static org.apache.commons.collections4.ListUtils.emptyIfNull; import static org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.mapping.submodel.MapperHelper.enrichAssetBase; -import static org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.mapping.submodel.MapperHelper.enrichManufacturingInformation; import static org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.mapping.submodel.MapperHelper.getContractAgreementId; import static org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.mapping.submodel.MapperHelper.getOwner; import static org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.mapping.submodel.MapperHelper.getShortId; @@ -94,9 +93,10 @@ private List toAssetBase(IRSResponse irsResponse, assetBase.setOwner(getOwner(assetBase, irsResponse)); assetBase.setIdShort(getShortId(irsResponse.shells(), assetBase.getId())); assetBase.setContractAgreementId(getContractAgreementId(irsResponse.shells(), assetBase.getId())); + assetBase.setManufacturerId(getManufacturerId(irsResponse, assetBase)); + assetBase.setManufacturerName(bpnService.findByBpn(assetBase.getManufacturerId())); enrichUpwardAndDownwardDescriptions(descriptionMap, assetBase); - enrichManufacturingInformation(irsResponse, assetBase, bpnService); enrichAssetBase(tractionBatteryCode, assetBase); enrichAssetBase(partSiteInformationAsPlanned, assetBase); @@ -187,6 +187,13 @@ private Optional getAsBuiltDetailMapper(IrsSubmodel irsSubm return asBuiltDetailMappers.stream().filter(asBuiltDetailMapper -> asBuiltDetailMapper.validMapper(irsSubmodel)).findFirst(); } + private String getManufacturerId(IRSResponse irsResponse, AssetBase assetBase){ + if (assetBase.getManufacturerId() == null && assetBase.getId().equals(irsResponse.jobStatus().globalAssetId())) { + return irsResponse.jobStatus().parameter().bpn(); + } + return assetBase.getManufacturerId(); + } + } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/MapperHelper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/MapperHelper.java index 410d3d64a3..81a856d51f 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/MapperHelper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/mapping/submodel/MapperHelper.java @@ -72,13 +72,4 @@ public static void enrichAssetBase(List detailAspectModels, A .ifPresent(detailAspectModel -> assetBase.setDetailAspectModels(List.of(detailAspectModel))); } - public static void enrichManufacturingInformation(IRSResponse irsResponse, AssetBase assetBase, BpnService bpnService) { - if (assetBase.getManufacturerId() == null && assetBase.getId().equals(irsResponse.jobStatus().globalAssetId())) { - String bpn = irsResponse.jobStatus().parameter().bpn(); - assetBase.setManufacturerId(bpn); - assetBase.setManufacturerName(bpnService.findByBpn(bpn)); - } else { - assetBase.setManufacturerName(bpnService.findByBpn(assetBase.getManufacturerId())); - } - } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/repository/BpnRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/repository/BpnRepositoryImpl.java index f65bd1ba6b..a2744c7b1d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/repository/BpnRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/repository/BpnRepositoryImpl.java @@ -22,10 +22,12 @@ import bpn.request.BpnMappingRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.eclipse.tractusx.traceability.bpn.domain.model.BpnEdcMapping; import org.eclipse.tractusx.traceability.bpn.domain.model.BpnNotFoundException; import org.eclipse.tractusx.traceability.bpn.infrastructure.model.BpnEntity; import org.eclipse.tractusx.traceability.bpn.infrastructure.model.BusinessPartnerResponse; +import org.eclipse.tractusx.traceability.bpn.infrastructure.model.NameResponse; import org.springframework.stereotype.Component; import java.util.List; @@ -89,7 +91,9 @@ public void updateManufacturers(Map bpns) { @Override public BpnEntity save(BusinessPartnerResponse businessPartner) { - String value = businessPartner.getNames() == null ? null : businessPartner.getNames().get(0).getValue(); + String value = businessPartner.getNames() == null ? null : businessPartner.getNames().stream() + .filter(it -> StringUtils.isNotBlank(it.getValue())) + .findFirst().map(NameResponse::getValue).orElse(null); BpnEntity entity = BpnEntity.builder().manufacturerId(businessPartner.getBpn()).manufacturerName(value).build(); return repository.save(entity); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/repository/BpnServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/repository/BpnServiceImpl.java index ca3cc1d15d..bec8a4699b 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/repository/BpnServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/repository/BpnServiceImpl.java @@ -20,6 +20,7 @@ package org.eclipse.tractusx.traceability.bpn.infrastructure.repository; import bpn.request.BpnMappingRequest; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.bpn.domain.model.BpnEdcMapping; import org.eclipse.tractusx.traceability.bpn.domain.model.BpnNotFoundException; @@ -33,16 +34,12 @@ @Slf4j @Component +@RequiredArgsConstructor public class BpnServiceImpl implements BpnService { private final BpnRepository bpnRepository; private final BpdmClient bpdmClient; - public BpnServiceImpl(BpnRepository bpnRepository, BpdmClient bpdmClient) { - this.bpnRepository = bpnRepository; - this.bpdmClient = bpdmClient; - } - @Override public String findByBpn(String bpn) { String manufacturerName = bpnRepository.findManufacturerName(bpn); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java index 9e65c0f30e..151bf1f6ec 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java @@ -73,7 +73,7 @@ public class RestTemplateConfiguration { private final ClientRegistrationRepository clientRegistrationRepository; - /* RestTemplate used by trace x for the edc contracts used within the edc provider.*/ + /* RestTemplate used by trace x for the resolution of manufacturer names by BPN.*/ @Bean(BPDM_CLIENT_REST_TEMPLATE) public RestTemplate bpdmClientRestTemplate(@Autowired BpdmProperties bpdmProperties) { final var clientRegistration = clientRegistrationRepository.findByRegistrationId(bpdmProperties.getOAuthClientId());