Skip to content

Commit

Permalink
feature: #586 implement review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-lcapellino committed May 6, 2024
1 parent 4e056de commit 1279058
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,9 +93,10 @@ private List<AssetBase> 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);

Expand Down Expand Up @@ -187,6 +187,13 @@ private Optional<AsBuiltDetailMapper> 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();
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,4 @@ public static void enrichAssetBase(List<DetailAspectModel> 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()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,7 +91,9 @@ public void updateManufacturers(Map<String, String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 1279058

Please sign in to comment.