From f478634893ee9845118757ac24225b2294722b54 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Tue, 9 Jul 2024 10:28:09 +0200 Subject: [PATCH 01/37] chore(irs):1105 provided tables for all types of contracts to save them accordingly. --- .../base/irs/JobRepositoryImpl.java | 28 ++- .../config/ApplicationStartupConfig.java | 71 +------- .../application/rest/ContractsController.java | 7 +- .../application/service/ContractService.java | 1 + .../contracts/domain/model/Contract.java | 17 +- .../domain/model/ContractAgreement.java | 20 ++- .../domain/repository/ContractRepository.java | 6 +- ....java => AbstractContractBaseService.java} | 25 ++- .../service/ContractAsBuiltServiceImpl.java | 28 +++ .../service/ContractAsPlannedServiceImpl.java | 28 +++ .../ContractNotificationServiceImpl.java | 28 +++ .../service/ContractViewServiceImpl.java | 28 +++ .../model/ContractAgreementAsBuiltEntity.java | 66 +++++++ .../ContractAgreementAsPlannedEntity.java | 67 +++++++ ....java => ContractAgreementBaseEntity.java} | 15 +- .../ContractAgreementNotificationEntity.java | 67 +++++++ .../model/ContractAgreementViewEntity.java | 66 +++++++ ...ContractAgreementAsBuiltSpecification.java | 42 +++++ ...ntractAgreementAsPlannedSpecification.java | 42 +++++ ...actAgreementNotificationSpecification.java | 42 +++++ ...> ContractAgreementViewSpecification.java} | 8 +- ...ava => ContractAsBuiltRepositoryImpl.java} | 28 +-- .../ContractAsPlannedRepositoryImpl.java | 165 ++++++++++++++++++ .../ContractNotificationRepositoryImpl.java | 165 ++++++++++++++++++ .../ContractViewRepositoryImpl.java | 156 +++++++++++++++++ ...JpaContractAgreementAsBuiltRepository.java | 29 +++ ...aContractAgreementAsPlannedRepository.java | 29 +++ ...ntractAgreementNotificationRepository.java | 29 +++ ...> JpaContractAgreementViewRepository.java} | 4 +- .../base/service/NotificationsEDCFacade.java | 1 + .../R__create_contract_agreement_view.sql | 32 +++- ...reate_contract_agreements_notification.sql | 22 +++ .../common/support/AssetsSupport.java | 35 ++-- .../support/ContractRepositoryProvider.java | 24 +++ 34 files changed, 1261 insertions(+), 160 deletions(-) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/{ContractServiceImpl.java => AbstractContractBaseService.java} (78%) create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsBuiltServiceImpl.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsPlannedServiceImpl.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractNotificationServiceImpl.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/{ContractAgreementEntity.java => ContractAgreementBaseEntity.java} (86%) create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementNotificationEntity.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsBuiltSpecification.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsPlannedSpecification.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementNotificationSpecification.java rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/{ContractSpecification.java => ContractAgreementViewSpecification.java} (82%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/{ContractRepositoryImpl.java => ContractAsBuiltRepositoryImpl.java} (83%) create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementAsBuiltRepository.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementAsPlannedRepository.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementNotificationRepository.java rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/{JpaContractAgreementRepository.java => JpaContractAgreementViewRepository.java} (85%) create mode 100644 tx-backend/src/main/resources/db/migration/V26__create_contract_agreements_notification.sql create mode 100644 tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/ContractRepositoryProvider.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java index c45c1d7b75..04671e5aa3 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java @@ -24,9 +24,6 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.assets.domain.base.JobRepository; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; -import org.eclipse.tractusx.traceability.assets.domain.base.model.ImportNote; -import org.eclipse.tractusx.traceability.assets.domain.base.model.ImportState; -import org.eclipse.tractusx.traceability.assets.domain.base.model.Owner; import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.request.BomLifecycle; import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.request.RegisterJobRequest; import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.Direction; @@ -34,13 +31,19 @@ import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.JobStatus; import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.factory.IrsResponseAssetMapper; import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractAsBuiltRepositoryImpl; +import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractAsPlannedRepositoryImpl; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.Optional; import static org.eclipse.tractusx.irs.component.enums.BomLifecycle.AS_BUILT; import static org.eclipse.tractusx.irs.component.enums.BomLifecycle.AS_PLANNED; @@ -52,7 +55,8 @@ public class JobRepositoryImpl implements JobRepository { private final TraceabilityProperties traceabilityProperties; private final AssetCallbackRepository assetAsBuiltCallbackRepository; private final AssetCallbackRepository assetAsPlannedCallbackRepository; - + private final ContractAsBuiltRepositoryImpl contractAsBuiltRepository; + private final ContractAsPlannedRepositoryImpl contractAsPlannedRepository; private static final String JOB_STATUS_COMPLETED = "COMPLETED"; private final IrsResponseAssetMapper assetMapperFactory; @@ -65,11 +69,16 @@ public JobRepositoryImpl( @Qualifier("assetAsBuiltRepositoryImpl") AssetCallbackRepository assetAsBuiltCallbackRepository, @Qualifier("assetAsPlannedRepositoryImpl") - AssetCallbackRepository assetAsPlannedCallbackRepository, IrsResponseAssetMapper assetMapperFactory) { + AssetCallbackRepository assetAsPlannedCallbackRepository, + ContractAsBuiltRepositoryImpl contractAsBuiltRepository, + ContractAsPlannedRepositoryImpl contractAsPlannedRepository, + IrsResponseAssetMapper assetMapperFactory) { this.traceabilityProperties = traceabilityProperties; this.assetAsBuiltCallbackRepository = assetAsBuiltCallbackRepository; this.assetAsPlannedCallbackRepository = assetAsPlannedCallbackRepository; this.jobClient = jobClient; + this.contractAsBuiltRepository = contractAsBuiltRepository; + this.contractAsPlannedRepository = contractAsPlannedRepository; this.assetMapperFactory = assetMapperFactory; } @@ -97,14 +106,19 @@ public void handleJobFinishedCallback(String jobId, String state) { if (jobCompleted(jobResponseIRS.jobStatus())) { List assets = assetMapperFactory.toAssetBaseList(jobResponseIRS); - + List contractAgreementsAsBuilt = new ArrayList<>(); + List contractAgreementsAsPlanned = new ArrayList<>(); assets.forEach(assetBase -> { if (assetBase.getBomLifecycle() == AS_BUILT) { saveOrUpdateAssets(assetAsBuiltCallbackRepository, assetBase); + contractAgreementsAsBuilt.add(ContractAgreement.toContractAgreement(assetBase, ContractType.ASSET_AS_BUILT)); } else if (assetBase.getBomLifecycle() == AS_PLANNED) { saveOrUpdateAssets(assetAsPlannedCallbackRepository, assetBase); + contractAgreementsAsPlanned.add(ContractAgreement.toContractAgreement(assetBase, ContractType.ASSET_AS_PLANNED)); } }); + this.contractAsBuiltRepository.saveAll(ContractAgreementAsBuiltEntity.fromDomainToEntityList(contractAgreementsAsBuilt)); + this.contractAsPlannedRepository.saveAll(ContractAgreementAsPlannedEntity.fromDomainToEntityList(contractAgreementsAsPlanned)); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java index 17988749dc..bf8d75a44e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java @@ -20,28 +20,20 @@ package org.eclipse.tractusx.traceability.common.config; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.traceability.assets.application.base.service.AssetBaseService; -import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; -import org.eclipse.tractusx.traceability.contracts.application.service.ContractService; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.notification.application.contract.model.CreateNotificationContractRequest; import org.eclipse.tractusx.traceability.notification.application.contract.model.NotificationMethod; import org.eclipse.tractusx.traceability.notification.application.contract.model.NotificationType; import org.eclipse.tractusx.traceability.notification.domain.contract.EdcNotificationContractService; import org.eclipse.tractusx.traceability.policies.domain.PolicyRepository; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Profile; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; -import java.time.Instant; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.stream.Stream; import static org.eclipse.tractusx.traceability.common.config.ApplicationProfiles.NOT_INTEGRATION_TESTS; @@ -51,21 +43,12 @@ @Profile(NOT_INTEGRATION_TESTS) public class ApplicationStartupConfig { private final PolicyRepository policyRepository; - private final AssetBaseService asPlannedService; - private final AssetBaseService asBuiltService; - private final ContractService contractService; @Autowired public ApplicationStartupConfig(PolicyRepository policyRepository, - @Qualifier("assetAsBuiltServiceImpl") AssetBaseService asBuiltService, - @Qualifier("assetAsPlannedServiceImpl") AssetBaseService asPlannedService, - EdcNotificationContractService edcNotificationContractService, - ContractService contractService) { + EdcNotificationContractService edcNotificationContractService) { this.policyRepository = policyRepository; - this.asPlannedService = asPlannedService; - this.asBuiltService = asBuiltService; this.edcNotificationContractService = edcNotificationContractService; - this.contractService = contractService; } private final EdcNotificationContractService edcNotificationContractService; @@ -106,56 +89,4 @@ public void createNotificationContracts() { executor.shutdown(); } - @EventListener(ApplicationReadyEvent.class) - public void insertIntoContractAgreements() { - ExecutorService executor = Executors.newSingleThreadExecutor(); - executor.execute(() -> { - log.info("on ApplicationReadyEvent insert into contracts."); - try { - log.info("Method yourMethod() started."); - - List asBuilt = asBuiltService.findAll(); - List asPlanned = asPlannedService.findAll(); - - log.info("Retrieved assets: asBuilt={}, asPlanned={}", asBuilt, asPlanned); - - List contractAgreementIdsAsBuilt = asBuilt.stream() - .filter(asBuiltAsset -> asBuiltAsset.getContractAgreementId() != null) // Filtering out null contractAgreementIds - .map(asBuiltAsset -> ContractAgreement.builder() - .type(ContractType.ASSET_AS_BUILT) - .contractAgreementId(asBuiltAsset.getContractAgreementId()) - .id(asBuiltAsset.getId()) - .created(Instant.now()) - .build()) - .toList(); - - List contractAgreementIdsAsPlanned = asPlanned.stream() - .filter(asPlannedAsset -> asPlannedAsset.getContractAgreementId() != null) // Filtering out null contractAgreementIds - .map(asPlannedAsset -> ContractAgreement.builder() - .type(ContractType.ASSET_AS_PLANNED) // Assuming the type should be ASSET_AS_PLANNED for asPlanned list - .contractAgreementId(asPlannedAsset.getContractAgreementId()) - .id(asPlannedAsset.getId()) - .created(Instant.now()) - .build()) - .toList(); - - - log.info("Created ContractAgreements: asBuilt={}, asPlanned={}", contractAgreementIdsAsBuilt, contractAgreementIdsAsPlanned); - - List mergedAgreements = Stream.concat(contractAgreementIdsAsBuilt.stream(), contractAgreementIdsAsPlanned.stream()) - .toList(); - log.info("Merged agreements: {}", mergedAgreements); - - contractService.saveAll(mergedAgreements); - log.info("Saved merged agreements successfully."); - - } catch (Exception exception) { - log.error("Failed to insert contracts: ", exception); - } - log.info("on ApplicationReadyEvent insert into contracts successfully done."); - }); - executor.shutdown(); - } - - } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java index d79e28cb26..a8c5784476 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java @@ -33,6 +33,7 @@ import org.eclipse.tractusx.traceability.contracts.application.mapper.ContractResponseMapper; import org.eclipse.tractusx.traceability.contracts.application.service.ContractService; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -40,13 +41,17 @@ import org.springframework.web.bind.annotation.RestController; @RestController -@RequiredArgsConstructor @PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_SUPERVISOR')") @Tag(name = "Contracts") @RequestMapping(path = "/contracts", produces = "application/json", consumes = "application/json") public class ContractsController { + private final ContractService contractService; + public ContractsController(@Qualifier("contractViewServiceImpl") ContractService contractService) { + this.contractService = contractService; + } + @Operation(operationId = "contracts", summary = "All contract agreements for all assets", tags = {"Contracts"}, diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractService.java index 33d97874bf..f7503e3ad9 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractService.java @@ -33,4 +33,5 @@ public interface ContractService { void saveContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException; void saveAll(List contractAgreements); + } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java index c9d90b705a..48e6f78fc0 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java @@ -22,11 +22,14 @@ import lombok.Builder; import lombok.Data; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; import java.time.Instant; import java.time.OffsetDateTime; import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; @Slf4j @AllArgsConstructor @@ -41,16 +44,6 @@ public class Contract { private String policy; private ContractType type; - public static ContractAgreementEntity toEntity(Contract contract, ContractType contractType) { - return ContractAgreementEntity.builder() - .id(contract.getContractId()) - .contractAgreementId(contract.getContractId()) - .type(contractType) - .created(Instant.now()) - .build(); - } - public static List toEntityList(List contracts, ContractType contractType) { - return contracts.stream().map(contract -> Contract.toEntity(contract, contractType)).toList(); - } + } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java index 8437ffd696..da80e7ab76 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java @@ -24,7 +24,9 @@ import lombok.Builder; import lombok.Getter; import lombok.Setter; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; +import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; import java.time.Instant; import java.util.List; @@ -34,23 +36,31 @@ @Builder public class ContractAgreement { - @Id private String id; private String contractAgreementId; @Enumerated(EnumType.STRING) private ContractType type; private Instant created; + private Instant updated; - public static ContractAgreementEntity toEntity(ContractAgreement contractAgreement) { - return ContractAgreementEntity.builder() + public static ContractAgreementBaseEntity toEntity(ContractAgreement contractAgreement) { + return ContractAgreementAsBuiltEntity.builder() .created(contractAgreement.getCreated()) .id(contractAgreement.getId()) .contractAgreementId(contractAgreement.getContractAgreementId()) .type(contractAgreement.getType()) + .updated(contractAgreement.getUpdated()) .build(); } - public static List toEntityList(List contractAgreementList) { + public static List toEntityList(List contractAgreementList) { return contractAgreementList.stream().map(ContractAgreement::toEntity).toList(); } + + public static ContractAgreement toContractAgreement(AssetBase assetBase, ContractType contractType){ + return ContractAgreement.builder().id(assetBase.getId()) + .contractAgreementId(assetBase.getContractAgreementId()).type(contractType).created(Instant.now()).build(); + } + + } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java index a28d42a6bc..a6998afca7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java @@ -23,16 +23,16 @@ import org.eclipse.tractusx.traceability.common.model.SearchCriteria; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; import org.springframework.data.domain.Pageable; import java.util.List; -public interface ContractRepository { +public interface ContractRepository { PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria); void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException; - void saveAll(List contractAgreements); + void saveAll(List contractAgreements); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java similarity index 78% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractServiceImpl.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java index 9173b5efb5..30122f07d8 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java @@ -18,7 +18,6 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.domain.service; -import lombok.RequiredArgsConstructor; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.traceability.common.model.PageResult; import org.eclipse.tractusx.traceability.common.model.SearchCriteria; @@ -28,36 +27,34 @@ import org.eclipse.tractusx.traceability.contracts.application.service.ContractService; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; -import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Component; import java.util.List; -@RequiredArgsConstructor -@Component -public class ContractServiceImpl implements ContractService { - private final ContractRepository contractRepository; +public abstract class AbstractContractBaseService implements ContractService { + + protected abstract ContractRepository getContractRepository(); + + protected abstract ContractFieldMapper getContractFieldMapper(); - private final ContractFieldMapper contractFieldMapper; @Override public PageResult getContracts(PageableFilterRequest pageableFilterRequest) { - Pageable pageable = OwnPageable.toPageable(pageableFilterRequest.getOwnPageable(), contractFieldMapper); - SearchCriteria searchCriteria = pageableFilterRequest.getSearchCriteriaRequestParam().toSearchCriteria(contractFieldMapper); - - return contractRepository.getContractsByPageable(pageable, searchCriteria); + Pageable pageable = OwnPageable.toPageable(pageableFilterRequest.getOwnPageable(), getContractFieldMapper()); + SearchCriteria searchCriteria = pageableFilterRequest.getSearchCriteriaRequestParam().toSearchCriteria(getContractFieldMapper()); + return getContractRepository().getContractsByPageable(pageable, searchCriteria); } @Override public void saveContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { - contractRepository.saveAllContractAgreements(contractAgreementIds, contractType); + getContractRepository().saveAllContractAgreements(contractAgreementIds, contractType); } @Override public void saveAll(List contractAgreements) { - contractRepository.saveAll(ContractAgreement.toEntityList(contractAgreements)); + getContractRepository().saveAll(ContractAgreement.toEntityList(contractAgreements)); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsBuiltServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsBuiltServiceImpl.java new file mode 100644 index 0000000000..27e15ce2b4 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsBuiltServiceImpl.java @@ -0,0 +1,28 @@ +package org.eclipse.tractusx.traceability.contracts.domain.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.traceability.contracts.application.mapper.ContractFieldMapper; +import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractAsBuiltRepositoryImpl; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class ContractAsBuiltServiceImpl extends AbstractContractBaseService { + + private final ContractAsBuiltRepositoryImpl contractAsBuiltRepository; + private final ContractFieldMapper contractFieldMapper; + + @Override + protected ContractRepository getContractRepository() { + return contractAsBuiltRepository; + } + + @Override + protected ContractFieldMapper getContractFieldMapper() { + return contractFieldMapper; + } + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsPlannedServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsPlannedServiceImpl.java new file mode 100644 index 0000000000..4f3cfb9832 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsPlannedServiceImpl.java @@ -0,0 +1,28 @@ +package org.eclipse.tractusx.traceability.contracts.domain.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.traceability.contracts.application.mapper.ContractFieldMapper; +import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractAsPlannedRepositoryImpl; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class ContractAsPlannedServiceImpl extends AbstractContractBaseService { + + private final ContractAsPlannedRepositoryImpl contractAsPlannedRepository; + private final ContractFieldMapper contractFieldMapper; + + @Override + protected ContractRepository getContractRepository() { + return contractAsPlannedRepository; + } + + @Override + protected ContractFieldMapper getContractFieldMapper() { + return contractFieldMapper; + } + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractNotificationServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractNotificationServiceImpl.java new file mode 100644 index 0000000000..00fe3b51fc --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractNotificationServiceImpl.java @@ -0,0 +1,28 @@ +package org.eclipse.tractusx.traceability.contracts.domain.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.traceability.contracts.application.mapper.ContractFieldMapper; +import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractNotificationRepositoryImpl; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class ContractNotificationServiceImpl extends AbstractContractBaseService { + + private final ContractNotificationRepositoryImpl contractNotificationRepository; + private final ContractFieldMapper contractFieldMapper; + + @Override + protected ContractRepository getContractRepository() { + return contractNotificationRepository; + } + + @Override + protected ContractFieldMapper getContractFieldMapper() { + return contractFieldMapper; + } + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java new file mode 100644 index 0000000000..b3718decd3 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java @@ -0,0 +1,28 @@ +package org.eclipse.tractusx.traceability.contracts.domain.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.traceability.contracts.application.mapper.ContractFieldMapper; +import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractViewRepositoryImpl; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +@RequiredArgsConstructor +public class ContractViewServiceImpl extends AbstractContractBaseService { + + private final ContractViewRepositoryImpl contractViewRepository; + private final ContractFieldMapper contractFieldMapper; + + @Override + protected ContractRepository getContractRepository() { + return contractViewRepository; + } + + @Override + protected ContractFieldMapper getContractFieldMapper() { + return contractFieldMapper; + } + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java new file mode 100644 index 0000000000..90e928643d --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java @@ -0,0 +1,66 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.SuperBuilder; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; + +import java.time.Instant; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@Entity +@SuperBuilder +@Table(name = "contract_agreement_as_built") +public class ContractAgreementAsBuiltEntity extends ContractAgreementBaseEntity { + public static ContractAgreementAsBuiltEntity from(Contract contract, ContractType contractType) { + return ContractAgreementAsBuiltEntity.builder() + .id(contract.getContractId()) + .contractAgreementId(contract.getContractId()) + .type(contractType) + .created(Instant.now()) + .build(); + } + + public static List fromList(List contracts, ContractType contractType) { + return contracts.stream().map(contract -> ContractAgreementAsBuiltEntity.from(contract, contractType)).toList(); + } + + public static ContractAgreementAsBuiltEntity fromDomainToEntity(ContractAgreement contractAgreement) { + return ContractAgreementAsBuiltEntity.builder() + .id(contractAgreement.getId()) + .contractAgreementId(contractAgreement.getContractAgreementId()) + .type(contractAgreement.getType()) + .created(contractAgreement.getCreated()) + .updated(contractAgreement.getUpdated()).build(); + } + + public static List fromDomainToEntityList(List contractAgreements) { + return contractAgreements.stream().map(ContractAgreementAsBuiltEntity::fromDomainToEntity).toList(); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java new file mode 100644 index 0000000000..95b5738ac3 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java @@ -0,0 +1,67 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.SuperBuilder; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; + +import java.time.Instant; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@Entity +@SuperBuilder +@Table(name = "contract_agreement_as_planned") +public class ContractAgreementAsPlannedEntity extends ContractAgreementBaseEntity { + + public static ContractAgreementAsPlannedEntity from(Contract contract, ContractType contractType) { + return ContractAgreementAsPlannedEntity.builder() + .id(contract.getContractId()) + .contractAgreementId(contract.getContractId()) + .type(contractType) + .created(Instant.now()) + .build(); + } + + public static List fromList(List contracts, ContractType contractType) { + return contracts.stream().map(contract -> ContractAgreementAsPlannedEntity.from(contract, contractType)).toList(); + } + + public static ContractAgreementAsPlannedEntity fromDomainToEntity(ContractAgreement contractAgreement) { + return ContractAgreementAsPlannedEntity.builder() + .id(contractAgreement.getId()) + .contractAgreementId(contractAgreement.getContractAgreementId()) + .type(contractAgreement.getType()) + .created(contractAgreement.getCreated()) + .updated(contractAgreement.getUpdated()).build(); + } + + public static List fromDomainToEntityList(List contractAgreements) { + return contractAgreements.stream().map(ContractAgreementAsPlannedEntity::fromDomainToEntity).toList(); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementBaseEntity.java similarity index 86% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementEntity.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementBaseEntity.java index 19a4e08fba..13f13a4d2f 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementBaseEntity.java @@ -18,11 +18,10 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.model; -import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.MappedSuperclass; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -36,10 +35,9 @@ @Getter @Setter @NoArgsConstructor -@Entity @SuperBuilder -@Table(name = "contract_agreement") -public class ContractAgreementEntity { +@MappedSuperclass +public class ContractAgreementBaseEntity { @Id private String id; @@ -47,9 +45,10 @@ public class ContractAgreementEntity { @Enumerated(EnumType.STRING) private ContractType type; private Instant created; + private Instant updated; - public static ContractAgreement toDomain(ContractAgreementEntity contractAgreement) { + public static ContractAgreement toDomain(ContractAgreementBaseEntity contractAgreement) { return ContractAgreement.builder() .created(contractAgreement.getCreated()) .id(contractAgreement.getId()) @@ -58,7 +57,7 @@ public static ContractAgreement toDomain(ContractAgreementEntity contractAgreeme .build(); } - public static List toDomainList(List contractAgreementList) { - return contractAgreementList.stream().map(ContractAgreementEntity::toDomain).toList(); + public static List toDomainList(List contractAgreementList) { + return contractAgreementList.stream().map(ContractAgreementBaseEntity::toDomain).toList(); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementNotificationEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementNotificationEntity.java new file mode 100644 index 0000000000..16ec6ef583 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementNotificationEntity.java @@ -0,0 +1,67 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.SuperBuilder; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; + +import java.time.Instant; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@Entity +@SuperBuilder +@Table(name = "contract_agreement_notification") +public class ContractAgreementNotificationEntity extends ContractAgreementBaseEntity { + public static ContractAgreementNotificationEntity from(Contract contract, ContractType contractType) { + return ContractAgreementNotificationEntity.builder() + .id(contract.getContractId()) + .contractAgreementId(contract.getContractId()) + .type(contractType) + .created(Instant.now()) + .build(); + } + + public static List fromList(List contracts, ContractType contractType) { + return contracts.stream().map(contract -> ContractAgreementNotificationEntity.from(contract, contractType)).toList(); + } + + + public static ContractAgreementNotificationEntity fromDomainToEntity(ContractAgreement contractAgreement) { + return ContractAgreementNotificationEntity.builder() + .id(contractAgreement.getId()) + .contractAgreementId(contractAgreement.getContractAgreementId()) + .type(contractAgreement.getType()) + .created(contractAgreement.getCreated()) + .updated(contractAgreement.getUpdated()).build(); + } + + public static List fromDomainToEntityList(List contractAgreements) { + return contractAgreements.stream().map(ContractAgreementNotificationEntity::fromDomainToEntity).toList(); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java new file mode 100644 index 0000000000..d30dd2fc52 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java @@ -0,0 +1,66 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.experimental.SuperBuilder; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; + +import java.time.Instant; +import java.util.List; + +@Getter +@Setter +@NoArgsConstructor +@Entity +@SuperBuilder +@Table(name = "contract_agreement_full") +public class ContractAgreementViewEntity extends ContractAgreementBaseEntity { + public static ContractAgreementViewEntity from(Contract contract, ContractType contractType) { + return ContractAgreementViewEntity.builder() + .id(contract.getContractId()) + .contractAgreementId(contract.getContractId()) + .type(contractType) + .created(Instant.now()) + .build(); + } + + public static List fromList(List contracts, ContractType contractType) { + return contracts.stream().map(contract -> ContractAgreementViewEntity.from(contract, contractType)).toList(); + } + + public static ContractAgreementViewEntity fromDomainToEntity(ContractAgreement contractAgreement) { + return ContractAgreementViewEntity.builder() + .id(contractAgreement.getId()) + .contractAgreementId(contractAgreement.getContractAgreementId()) + .type(contractAgreement.getType()) + .created(contractAgreement.getCreated()) + .updated(contractAgreement.getUpdated()).build(); + } + + public static List fromDomainToEntityList(List contractAgreements) { + return contractAgreements.stream().map(ContractAgreementViewEntity::fromDomainToEntity).toList(); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsBuiltSpecification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsBuiltSpecification.java new file mode 100644 index 0000000000..774eab8e50 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsBuiltSpecification.java @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.contracts.infrastructure.repository; + +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; +import org.eclipse.tractusx.traceability.common.model.SearchCriteriaFilter; +import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; +import org.jetbrains.annotations.NotNull; +import org.springframework.data.jpa.domain.Specification; + +public class ContractAgreementAsBuiltSpecification extends BaseSpecification implements Specification { + + public ContractAgreementAsBuiltSpecification(SearchCriteriaFilter criteria) { + super(criteria); + } + + @Override + public Predicate toPredicate(@NotNull Root root, @NotNull CriteriaQuery query, @NotNull CriteriaBuilder builder) { + return createPredicate(getSearchCriteriaFilter(), root, builder); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsPlannedSpecification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsPlannedSpecification.java new file mode 100644 index 0000000000..6e711dcc15 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsPlannedSpecification.java @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.contracts.infrastructure.repository; + +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; +import org.eclipse.tractusx.traceability.common.model.SearchCriteriaFilter; +import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; +import org.jetbrains.annotations.NotNull; +import org.springframework.data.jpa.domain.Specification; + +public class ContractAgreementAsPlannedSpecification extends BaseSpecification implements Specification { + + public ContractAgreementAsPlannedSpecification(SearchCriteriaFilter criteria) { + super(criteria); + } + + @Override + public Predicate toPredicate(@NotNull Root root, @NotNull CriteriaQuery query, @NotNull CriteriaBuilder builder) { + return createPredicate(getSearchCriteriaFilter(), root, builder); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementNotificationSpecification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementNotificationSpecification.java new file mode 100644 index 0000000000..b46276615a --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementNotificationSpecification.java @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 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.traceability.contracts.infrastructure.repository; + +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Predicate; +import jakarta.persistence.criteria.Root; +import org.eclipse.tractusx.traceability.common.model.SearchCriteriaFilter; +import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementNotificationEntity; +import org.jetbrains.annotations.NotNull; +import org.springframework.data.jpa.domain.Specification; + +public class ContractAgreementNotificationSpecification extends BaseSpecification implements Specification { + + public ContractAgreementNotificationSpecification(SearchCriteriaFilter criteria) { + super(criteria); + } + + @Override + public Predicate toPredicate(@NotNull Root root, @NotNull CriteriaQuery query, @NotNull CriteriaBuilder builder) { + return createPredicate(getSearchCriteriaFilter(), root, builder); + } +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractSpecification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementViewSpecification.java similarity index 82% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractSpecification.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementViewSpecification.java index e533c0dd0c..9880af24f6 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractSpecification.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementViewSpecification.java @@ -25,18 +25,18 @@ import jakarta.persistence.criteria.Root; import org.eclipse.tractusx.traceability.common.model.SearchCriteriaFilter; import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementViewEntity; import org.jetbrains.annotations.NotNull; import org.springframework.data.jpa.domain.Specification; -public class ContractSpecification extends BaseSpecification implements Specification { +public class ContractAgreementViewSpecification extends BaseSpecification implements Specification { - public ContractSpecification(SearchCriteriaFilter criteria) { + public ContractAgreementViewSpecification(SearchCriteriaFilter criteria) { super(criteria); } @Override - public Predicate toPredicate(@NotNull Root root, @NotNull CriteriaQuery query, @NotNull CriteriaBuilder builder) { + public Predicate toPredicate(@NotNull Root root, @NotNull CriteriaQuery query, @NotNull CriteriaBuilder builder) { return createPredicate(getSearchCriteriaFilter(), root, builder); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java similarity index 83% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index 32bcc62aae..d870d29cf3 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -34,7 +34,7 @@ import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; @@ -55,20 +55,20 @@ @Component @RequiredArgsConstructor @Slf4j -public class ContractRepositoryImpl implements ContractRepository { +public class ContractAsBuiltRepositoryImpl implements ContractRepository { private final EdcContractAgreementService edcContractAgreementService; - private final JpaContractAgreementRepository contractAgreementRepository; + private final JpaContractAgreementAsBuiltRepository contractAgreementRepository; private final ObjectMapper objectMapper; @Override public PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria) { try { - List contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream() - .map(ContractSpecification::new) + List contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream() + .map(ContractAgreementAsBuiltSpecification::new) .toList(); - Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); - Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); + Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); + Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); if (contractAgreementEntities.getContent().isEmpty()) { log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); @@ -90,25 +90,25 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { - List contractAgreementEntities = contractAgreementIds.stream() - .map(contractAgreementId -> ContractAgreementEntity.builder() + List contractAgreementEntities = contractAgreementIds.stream() + .map(contractAgreementId -> ContractAgreementAsBuiltEntity.builder() .contractAgreementId(contractAgreementId) .type(contractType) .build()) .collect(Collectors.toList()); List contracts = fetchEdcContractAgreements(contractAgreementEntities); - List contractAgreementsUpdated = Contract.toEntityList(contracts, contractType); + List contractAgreementsUpdated = ContractAgreementAsBuiltEntity.fromList(contracts, contractType); contractAgreementRepository.saveAll(contractAgreementsUpdated); } @Override - public void saveAll(List contractAgreements) { + public void saveAll(List contractAgreements) { contractAgreementRepository.saveAll(contractAgreements); } - private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { - List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementEntity::getContractAgreementId).toList(); + private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { + List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementAsBuiltEntity::getContractAgreementId).toList(); log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); @@ -116,7 +116,7 @@ private List fetchEdcContractAgreements(List validateContractAgreements(contractAgreementIds, contractAgreements); Map contractTypes = contractAgreementEntities.stream() - .collect(Collectors.toMap(ContractAgreementEntity::getContractAgreementId, ContractAgreementEntity::getType)); + .collect(Collectors.toMap(ContractAgreementAsBuiltEntity::getContractAgreementId, ContractAgreementAsBuiltEntity::getType)); Map contractNegotiations = contractAgreements.stream() .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java new file mode 100644 index 0000000000..b387b51615 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java @@ -0,0 +1,165 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.repository; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementNegotiationResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; +import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; +import org.eclipse.tractusx.traceability.common.model.PageResult; +import org.eclipse.tractusx.traceability.common.model.SearchCriteria; +import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; +import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + +@Component +@RequiredArgsConstructor +@Slf4j +public class ContractAsPlannedRepositoryImpl implements ContractRepository { + + private final EdcContractAgreementService edcContractAgreementService; + private final JpaContractAgreementAsPlannedRepository contractAgreementRepository; + private final ObjectMapper objectMapper; + + @Override + public PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria) { + try { + List contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream() + .map(ContractAgreementAsPlannedSpecification::new) + .toList(); + Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); + Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); + + if (contractAgreementEntities.getContent().isEmpty()) { + log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); + return new PageResult<>(List.of(), 0, 0, 0, 0L); + } + + return new PageResult<>(fetchEdcContractAgreements(contractAgreementEntities.getContent()), + contractAgreementEntities.getPageable().getPageNumber(), + contractAgreementEntities.getTotalPages(), + contractAgreementEntities.getPageable().getPageSize(), + contractAgreementEntities.getTotalElements()); + + } catch (ContractAgreementException e) { + throw new ContractException(e); + } + + } + + @Override + public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { + + List contractAgreementEntities = contractAgreementIds.stream() + .map(contractAgreementId -> ContractAgreementAsPlannedEntity.builder() + .contractAgreementId(contractAgreementId) + .type(contractType) + .build()) + .collect(Collectors.toList()); + + List contracts = fetchEdcContractAgreements(contractAgreementEntities); + List contractAgreementsUpdated = ContractAgreementAsPlannedEntity.fromList(contracts, contractType); + contractAgreementRepository.saveAll(contractAgreementsUpdated); + } + + @Override + public void saveAll(List contractAgreements) { + contractAgreementRepository.saveAll(contractAgreements); + } + + private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { + List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementAsPlannedEntity::getContractAgreementId).toList(); + log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); + + List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); + + validateContractAgreements(contractAgreementIds, contractAgreements); + + Map contractTypes = contractAgreementEntities.stream() + .collect(Collectors.toMap(ContractAgreementAsPlannedEntity::getContractAgreementId, ContractAgreementAsPlannedEntity::getType)); + + Map contractNegotiations = contractAgreements.stream() + .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), + edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) + ).collect(Collectors.toMap(ImmutablePair::getLeft, ImmutablePair::getRight)); + + + return contractAgreements.stream().map(contractAgreement -> + { + try { + return Contract.builder() + .contractId(contractAgreement.contractAgreementId()) + .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) + .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) + .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) + .policy(objectMapper.writeValueAsString(contractAgreement.policy())) + .type(contractTypes.get(contractAgreement.contractAgreementId())) + .build(); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + ).toList(); + } + + private void validateContractAgreements(List contractAgreementIds, List contractAgreements) { + ArrayList givenList = new ArrayList<>(contractAgreementIds); + Collections.sort(givenList); + + List expectedList = contractAgreements.stream() + .map(EdcContractAgreementsResponse::contractAgreementId) + .sorted() + .toList(); + log.info("EDC responded with the following contractAgreementIds: " + expectedList); + + // Filter the givenList to find out which IDs are missing in the expectedList + List missingIds = givenList.stream() + .filter(id -> !expectedList.contains(id)) + .toList(); + + if (!missingIds.isEmpty()) { + log.warn("Cannot find the following contract agreement IDs in EDC: " + missingIds); + } + } + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java new file mode 100644 index 0000000000..66e5ed2ab4 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java @@ -0,0 +1,165 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.repository; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementNegotiationResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; +import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; +import org.eclipse.tractusx.traceability.common.model.PageResult; +import org.eclipse.tractusx.traceability.common.model.SearchCriteria; +import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; +import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementNotificationEntity; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + +@Component +@RequiredArgsConstructor +@Slf4j +public class ContractNotificationRepositoryImpl implements ContractRepository { + + private final EdcContractAgreementService edcContractAgreementService; + private final JpaContractAgreementNotificationRepository contractAgreementRepository; + private final ObjectMapper objectMapper; + + @Override + public PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria) { + try { + List contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream() + .map(ContractAgreementNotificationSpecification::new) + .toList(); + Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); + Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); + + if (contractAgreementEntities.getContent().isEmpty()) { + log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); + return new PageResult<>(List.of(), 0, 0, 0, 0L); + } + + return new PageResult<>(fetchEdcContractAgreements(contractAgreementEntities.getContent()), + contractAgreementEntities.getPageable().getPageNumber(), + contractAgreementEntities.getTotalPages(), + contractAgreementEntities.getPageable().getPageSize(), + contractAgreementEntities.getTotalElements()); + + } catch (ContractAgreementException e) { + throw new ContractException(e); + } + + } + + @Override + public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { + + List contractAgreementEntities = contractAgreementIds.stream() + .map(contractAgreementId -> ContractAgreementNotificationEntity.builder() + .contractAgreementId(contractAgreementId) + .type(contractType) + .build()) + .collect(Collectors.toList()); + + List contracts = fetchEdcContractAgreements(contractAgreementEntities); + List contractAgreementsUpdated = ContractAgreementNotificationEntity.fromList(contracts, contractType); + contractAgreementRepository.saveAll(contractAgreementsUpdated); + } + + @Override + public void saveAll(List contractAgreements) { + contractAgreementRepository.saveAll(contractAgreements); + } + + private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { + List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementNotificationEntity::getContractAgreementId).toList(); + log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); + + List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); + + validateContractAgreements(contractAgreementIds, contractAgreements); + + Map contractTypes = contractAgreementEntities.stream() + .collect(Collectors.toMap(ContractAgreementNotificationEntity::getContractAgreementId, ContractAgreementNotificationEntity::getType)); + + Map contractNegotiations = contractAgreements.stream() + .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), + edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) + ).collect(Collectors.toMap(ImmutablePair::getLeft, ImmutablePair::getRight)); + + + return contractAgreements.stream().map(contractAgreement -> + { + try { + return Contract.builder() + .contractId(contractAgreement.contractAgreementId()) + .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) + .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) + .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) + .policy(objectMapper.writeValueAsString(contractAgreement.policy())) + .type(contractTypes.get(contractAgreement.contractAgreementId())) + .build(); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + ).toList(); + } + + private void validateContractAgreements(List contractAgreementIds, List contractAgreements) { + ArrayList givenList = new ArrayList<>(contractAgreementIds); + Collections.sort(givenList); + + List expectedList = contractAgreements.stream() + .map(EdcContractAgreementsResponse::contractAgreementId) + .sorted() + .toList(); + log.info("EDC responded with the following contractAgreementIds: " + expectedList); + + // Filter the givenList to find out which IDs are missing in the expectedList + List missingIds = givenList.stream() + .filter(id -> !expectedList.contains(id)) + .toList(); + + if (!missingIds.isEmpty()) { + log.warn("Cannot find the following contract agreement IDs in EDC: " + missingIds); + } + } + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java new file mode 100644 index 0000000000..1df997afe2 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -0,0 +1,156 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.repository; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementNegotiationResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; +import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; +import org.eclipse.tractusx.traceability.common.model.PageResult; +import org.eclipse.tractusx.traceability.common.model.SearchCriteria; +import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; +import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementViewEntity; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + +@Component +@RequiredArgsConstructor +@Slf4j +public class ContractViewRepositoryImpl implements ContractRepository { + + private final EdcContractAgreementService edcContractAgreementService; + private final JpaContractAgreementViewRepository contractAgreementRepository; + private final ObjectMapper objectMapper; + + @Override + public PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria) { + try { + List contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream() + .map(ContractAgreementViewSpecification::new) + .toList(); + Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); + Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); + + if (contractAgreementEntities.getContent().isEmpty()) { + log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); + return new PageResult<>(List.of(), 0, 0, 0, 0L); + } + + return new PageResult<>(fetchEdcContractAgreements(contractAgreementEntities.getContent()), + contractAgreementEntities.getPageable().getPageNumber(), + contractAgreementEntities.getTotalPages(), + contractAgreementEntities.getPageable().getPageSize(), + contractAgreementEntities.getTotalElements()); + + } catch (ContractAgreementException e) { + throw new ContractException(e); + } + + } + + @Override + public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { + + } + + @Override + public void saveAll(List contractAgreements) { + + } + + + private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { + List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementViewEntity::getContractAgreementId).toList(); + log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); + + List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); + + validateContractAgreements(contractAgreementIds, contractAgreements); + + Map contractTypes = contractAgreementEntities.stream() + .collect(Collectors.toMap(ContractAgreementViewEntity::getContractAgreementId, ContractAgreementViewEntity::getType)); + + Map contractNegotiations = contractAgreements.stream() + .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), + edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) + ).collect(Collectors.toMap(ImmutablePair::getLeft, ImmutablePair::getRight)); + + + return contractAgreements.stream().map(contractAgreement -> + { + try { + return Contract.builder() + .contractId(contractAgreement.contractAgreementId()) + .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) + .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) + .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) + .policy(objectMapper.writeValueAsString(contractAgreement.policy())) + .type(contractTypes.get(contractAgreement.contractAgreementId())) + .build(); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + ).toList(); + } + + private void validateContractAgreements(List contractAgreementIds, List contractAgreements) { + ArrayList givenList = new ArrayList<>(contractAgreementIds); + Collections.sort(givenList); + + List expectedList = contractAgreements.stream() + .map(EdcContractAgreementsResponse::contractAgreementId) + .sorted() + .toList(); + log.info("EDC responded with the following contractAgreementIds: " + expectedList); + + // Filter the givenList to find out which IDs are missing in the expectedList + List missingIds = givenList.stream() + .filter(id -> !expectedList.contains(id)) + .toList(); + + if (!missingIds.isEmpty()) { + log.warn("Cannot find the following contract agreement IDs in EDC: " + missingIds); + } + } + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementAsBuiltRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementAsBuiltRepository.java new file mode 100644 index 0000000000..8e6bfe35ba --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementAsBuiltRepository.java @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.repository; + +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; + +@Repository +public interface JpaContractAgreementAsBuiltRepository extends JpaRepository, JpaSpecificationExecutor { + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementAsPlannedRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementAsPlannedRepository.java new file mode 100644 index 0000000000..3780680257 --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementAsPlannedRepository.java @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.repository; + +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; + +@Repository +public interface JpaContractAgreementAsPlannedRepository extends JpaRepository, JpaSpecificationExecutor { + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementNotificationRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementNotificationRepository.java new file mode 100644 index 0000000000..f69f3fff5f --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementNotificationRepository.java @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.repository; + +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementNotificationEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Repository; + +@Repository +public interface JpaContractAgreementNotificationRepository extends JpaRepository, JpaSpecificationExecutor { + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementViewRepository.java similarity index 85% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementRepository.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementViewRepository.java index 135b246d1f..05d7796533 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementViewRepository.java @@ -18,12 +18,12 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementViewEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Repository; @Repository -public interface JpaContractAgreementRepository extends JpaRepository, JpaSpecificationExecutor { +public interface JpaContractAgreementViewRepository extends JpaRepository, JpaSpecificationExecutor { } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java index f09bb13dd1..f8776a3e69 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java @@ -82,6 +82,7 @@ public class NotificationsEDCFacade { private final EDCCatalogFacade edcCatalogFacade; private final ContractNegotiationService contractNegotiationService; private final EndpointDataReferenceStorage endpointDataReferenceStorage; + @Qualifier("contractNotificationServiceImpl") private final ContractService contractService; private static final String CX_TAXO_QUALITY_INVESTIGATION_RECEIVE = "https://w3id.org/catenax/taxonomy#ReceiveQualityInvestigationNotification"; diff --git a/tx-backend/src/main/resources/db/migration/R__create_contract_agreement_view.sql b/tx-backend/src/main/resources/db/migration/R__create_contract_agreement_view.sql index 13de99dcf4..2104baf5ec 100644 --- a/tx-backend/src/main/resources/db/migration/R__create_contract_agreement_view.sql +++ b/tx-backend/src/main/resources/db/migration/R__create_contract_agreement_view.sql @@ -1,2 +1,30 @@ --- Drop the view if it exists -DROP VIEW IF EXISTS contract_agreement_view; +CREATE VIEW contract_agreement_full AS +SELECT + id, + contract_agreement_id, + type, + created, + updated, + 'contract_agreement_as_built' AS source_table +FROM + contract_agreement_as_built +UNION ALL +SELECT + id, + contract_agreement_id, + type, + created, + updated, + 'contract_agreement_notification' AS source_table +FROM + contract_agreement_notification +UNION ALL +SELECT + id, + contract_agreement_id, + type, + created, + updated, + 'contract_agreement_as_planned' AS source_table +FROM + contract_agreement_as_planned; diff --git a/tx-backend/src/main/resources/db/migration/V26__create_contract_agreements_notification.sql b/tx-backend/src/main/resources/db/migration/V26__create_contract_agreements_notification.sql new file mode 100644 index 0000000000..715a31d0d6 --- /dev/null +++ b/tx-backend/src/main/resources/db/migration/V26__create_contract_agreements_notification.sql @@ -0,0 +1,22 @@ +ALTER TABLE contract_agreement RENAME TO contract_agreement_as_built; + +ALTER TABLE contract_agreement_as_built + ADD COLUMN updated TIMESTAMP; + +CREATE TABLE IF NOT EXISTS contract_agreement_notification ( + id VARCHAR(255) PRIMARY KEY, + contract_agreement_id VARCHAR(255), + created TIMESTAMP, + type VARCHAR(255), + updated TIMESTAMP); + + +CREATE TABLE IF NOT EXISTS contract_agreement_as_planned ( + id VARCHAR(255) PRIMARY KEY, + contract_agreement_id VARCHAR(255), + created TIMESTAMP, + type VARCHAR(255), + updated TIMESTAMP); + + + diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java index da6558e0d4..a338701f6a 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java @@ -21,8 +21,8 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model.AssetAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; -import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -30,7 +30,6 @@ import java.time.Instant; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; @Slf4j @Component @@ -40,7 +39,7 @@ public class AssetsSupport { AssetRepositoryProvider assetRepositoryProvider; @Autowired - ContractRepository contractRepository; + ContractRepositoryProvider contractRepositoryProvider; @Autowired BpnSupport bpnSupport; @@ -58,14 +57,15 @@ public void defaultAssetsStored() { bpnSupport.providesBpdmLookup(); assetRepositoryProvider.assetAsBuiltRepository().saveAll(assetRepositoryProvider.testdataProvider().readAndConvertAssetsForTests()); - List mergedAgreements = extractContractAgreementByAssets(); - - contractRepository.saveAll(mergedAgreements); + List asBuiltEntities = extractContractAgreementAsBuilt(); + List asPlannedEntities = extractContractAgreementAsPlanned(); + contractRepositoryProvider.contractAsBuiltRepository.saveAll(asBuiltEntities); + contractRepositoryProvider.contractAsPlannedRepository.saveAll(asPlannedEntities); } - private @NotNull List extractContractAgreementByAssets() { - List contractAgreementIdsAsBuilt = assetRepositoryProvider.assetAsBuiltRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementEntity + private @NotNull List extractContractAgreementAsBuilt() { + return assetRepositoryProvider.assetAsBuiltRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementAsBuiltEntity .builder() .type(ContractType.ASSET_AS_BUILT) .contractAgreementId(asBuiltAsset.getContractAgreementId()) @@ -73,20 +73,19 @@ public void defaultAssetsStored() { .created(Instant.now()) .build()).collect(Collectors.toUnmodifiableList()); - List contractAgreementIdsAsPlanned = assetRepositoryProvider.assetAsPlannedRepository().findAll().stream().map(asPlannedAsset -> ContractAgreementEntity + } + + private @NotNull List extractContractAgreementAsPlanned() { + return assetRepositoryProvider.assetAsPlannedRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementAsPlannedEntity .builder() - .type(ContractType.ASSET_AS_BUILT) - .contractAgreementId(asPlannedAsset.getContractAgreementId()) - .id(asPlannedAsset.getId()) + .type(ContractType.ASSET_AS_PLANNED) + .contractAgreementId(asBuiltAsset.getContractAgreementId()) + .id(asBuiltAsset.getId()) .created(Instant.now()) .build()).collect(Collectors.toUnmodifiableList()); - - List mergedAgreements = Stream.concat(contractAgreementIdsAsBuilt.stream(), contractAgreementIdsAsPlanned.stream()) - .toList(); - mergedAgreements.forEach(contractAgreementView -> log.info(contractAgreementView.getContractAgreementId())); - return mergedAgreements; } + public AssetAsBuiltEntity findById(String id) { return AssetAsBuiltEntity.from(assetRepositoryProvider.assetAsBuiltRepository.getAssetById(id)); } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/ContractRepositoryProvider.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/ContractRepositoryProvider.java new file mode 100644 index 0000000000..c34a5db5e0 --- /dev/null +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/ContractRepositoryProvider.java @@ -0,0 +1,24 @@ +package org.eclipse.tractusx.traceability.integration.common.support; + +import lombok.Getter; +import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractAsBuiltRepositoryImpl; +import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractAsPlannedRepositoryImpl; +import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractNotificationRepositoryImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Getter +@Component +public class ContractRepositoryProvider { + + @Autowired + ContractAsBuiltRepositoryImpl contractAsBuiltRepository; + + @Autowired + ContractNotificationRepositoryImpl contractNotificationRepository; + + @Autowired + ContractAsPlannedRepositoryImpl contractAsPlannedRepository; + + +} From 8f99ddb62bd06ea2e096b1109a52694a97f59403 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 11 Jul 2024 13:15:43 +0200 Subject: [PATCH 02/37] chore(irs):1105 Added contractAgreementIds to asset domain. --- .../mapper/AssetAsBuiltFieldMapper.java | 2 +- .../mapper/AssetAsBuiltResponseMapper.java | 3 +- .../mapper/AssetAsPlannedResponseMapper.java | 3 +- .../assets/domain/base/model/AssetBase.java | 4 +- .../importpoc/service/ImportServiceImpl.java | 7 ++- .../asbuilt/model/AssetAsBuiltEntity.java | 9 ++- .../asbuilt/model/AssetAsBuiltViewEntity.java | 10 +++- .../AssetAsBuiltRepositoryImpl.java | 18 ++++++ .../asplanned/model/AssetAsPlannedEntity.java | 11 +++- .../AssetAsPlannedRepositoryImpl.java | 23 ++++++- .../base/irs/JobRepositoryImpl.java | 25 ++++---- .../factory/IrsResponseAssetMapper.java | 8 ++- .../base/model/AssetBaseEntity.java | 1 - .../domain/model/ContractAgreement.java | 44 ++++++++++++-- .../domain/repository/ContractRepository.java | 9 ++- .../model/ContractAgreementAsBuiltEntity.java | 24 ++++++-- .../ContractAgreementAsPlannedEntity.java | 16 +++-- .../model/ContractAgreementBaseEntity.java | 20 ++----- .../ContractAgreementNotificationEntity.java | 8 +-- .../model/ContractAgreementViewEntity.java | 15 +---- .../ContractAsBuiltRepositoryImpl.java | 11 ++++ .../ContractAsPlannedRepositoryImpl.java | 12 ++++ .../ContractNotificationRepositoryImpl.java | 12 ++++ .../ContractViewRepositoryImpl.java | 31 +++++++++- .../R__create_contract_agreement_view.sql | 3 + ..._add_contract_agreements_to_ref_tables.sql | 8 +++ .../base/IrsCallbackControllerIT.java | 24 ++++++-- .../support/AssetRepositoryProvider.java | 1 + .../common/support/AssetsSupport.java | 60 +++++++++++++++---- .../contracts/ContractsControllerIT.java | 2 +- .../base/response/AssetBaseResponse.java | 4 +- 31 files changed, 333 insertions(+), 95 deletions(-) create mode 100644 tx-backend/src/main/resources/db/migration/V27__add_contract_agreements_to_ref_tables.sql diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java index 5b46862d2f..5a0912652e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java @@ -54,7 +54,7 @@ public class AssetAsBuiltFieldMapper extends BaseRequestFieldMapper { Map.entry("receivedQualityInvestigationIdsInStatusActive", "receivedActiveInvestigations"), Map.entry("importState", "importState"), Map.entry("importNote", "importNote"), - Map.entry("contractAgreementId", "contractAgreementId") + Map.entry("contractAgreementId", "contractAgreements_contractAgreementId") ); @Override diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java index c24a3c4129..1ab517dbd7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java @@ -22,6 +22,7 @@ import org.eclipse.tractusx.traceability.assets.application.base.mapper.AssetBaseResponseMapper; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; import org.eclipse.tractusx.traceability.common.model.PageResult; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import java.util.List; @@ -59,7 +60,7 @@ public static AssetAsBuiltResponse from(final AssetBase asset) { .importState(toImportStateResponse(asset.getImportState())) .importNote(asset.getImportNote()) .tombstone(asset.getTombstone()) - .contractAgreementId(asset.getContractAgreementId()) + .contractAgreementIds(asset.getContractAgreements().stream().map(ContractAgreement::getContractAgreementId).toList()) .build(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java index 895e3ce987..adc263d765 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java @@ -22,6 +22,7 @@ import org.eclipse.tractusx.traceability.assets.application.base.mapper.AssetBaseResponseMapper; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; import org.eclipse.tractusx.traceability.common.model.PageResult; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import java.util.List; @@ -60,7 +61,7 @@ public static AssetAsPlannedResponse from(final AssetBase asset) { .importState(toImportStateResponse(asset.getImportState())) .importNote(asset.getImportNote()) .tombstone(asset.getTombstone()) - .contractAgreementId(asset.getContractAgreementId()) + .contractAgreementIds(asset.getContractAgreements().stream().map(ContractAgreement::getContractAgreementId).toList()) .build(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/base/model/AssetBase.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/base/model/AssetBase.java index db908070f6..4532b4cb1c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/base/model/AssetBase.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/base/model/AssetBase.java @@ -28,6 +28,7 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.component.enums.BomLifecycle; import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.notification.domain.base.model.Notification; import java.util.List; @@ -62,7 +63,8 @@ public class AssetBase { private String importNote; private String policyId; private String tombstone; - private String contractAgreementId; + private List contractAgreements; + private String latestContractAgreementId; public BomLifecycle getBomLifecycle() { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/importpoc/service/ImportServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/importpoc/service/ImportServiceImpl.java index 935b59d005..9397cc47bb 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/importpoc/service/ImportServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/domain/importpoc/service/ImportServiceImpl.java @@ -72,8 +72,11 @@ public Map importAssets(MultipartFile file, ImportJob import } }); - List persistedAsBuilt = assetAsBuiltRepository.saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(assetToUploadByBomLifecycle.get(BomLifecycle.AS_BUILT)); - List persistedAsPlanned = assetAsPlannedRepository.saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(assetToUploadByBomLifecycle.get(BomLifecycle.AS_PLANNED)); + List assetAsBuilt = assetToUploadByBomLifecycle.get(BomLifecycle.AS_BUILT); + List assetAsPlanned = assetToUploadByBomLifecycle.get(BomLifecycle.AS_PLANNED); + + List persistedAsBuilt = assetAsBuiltRepository.saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(assetAsBuilt); + List persistedAsPlanned = assetAsPlannedRepository.saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(assetAsPlanned); importJob.setAssetAsBuilt(persistedAsBuilt); importJob.setAssetAsPlanned(persistedAsPlanned); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltEntity.java index d81ea2bf3a..97abf0baca 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltEntity.java @@ -21,6 +21,7 @@ package org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model; +import jakarta.persistence.CascadeType; import jakarta.persistence.CollectionTable; import jakarta.persistence.Column; import jakarta.persistence.ElementCollection; @@ -43,6 +44,8 @@ import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel; import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.AssetBaseEntity; import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.SemanticDataModelEntity; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationEntity; import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationSideBaseEntity; import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationTypeEntity; @@ -89,6 +92,8 @@ public class AssetAsBuiltEntity extends AssetBaseEntity { @OneToMany(mappedBy = "assetAsBuilt", fetch = FetchType.EAGER) private List submodels; + @OneToMany(mappedBy = "assetAsBuilt", fetch = FetchType.EAGER, cascade = CascadeType.ALL) + private List contractAgreements; public static AssetAsBuiltEntity from(AssetBase asset) { ManufacturingInfo manufacturingInfo = ManufacturingInfo.from(asset.getDetailAspectModels()); @@ -123,7 +128,7 @@ public static AssetAsBuiltEntity from(AssetBase asset) { .importNote(asset.getImportNote()) .policyId(asset.getPolicyId()) .tombstone(asset.getTombstone()) - .contractAgreementId(asset.getContractAgreementId()) + .contractAgreements(ContractAgreementAsBuiltEntity.fromDomainToEntityList(asset.getContractAgreements())) .build(); } @@ -180,7 +185,7 @@ public AssetBase toDomain() { .importNote(this.getImportNote()) .policyId(this.getPolicyId()) .tombstone(this.getTombstone()) - .contractAgreementId(this.getContractAgreementId()) + .contractAgreements(ContractAgreement.fromAsBuiltEntityToContractAgreements(emptyIfNull(this.getContractAgreements()))) .build(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltViewEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltViewEntity.java index d1549b2155..97292e15e1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltViewEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltViewEntity.java @@ -19,14 +19,17 @@ package org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model; +import jakarta.persistence.CascadeType; import jakarta.persistence.CollectionTable; import jakarta.persistence.Column; import jakarta.persistence.ElementCollection; import jakarta.persistence.Embeddable; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; +import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; @@ -40,6 +43,8 @@ import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel; import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.AssetBaseEntity; import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.SemanticDataModelEntity; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationEntity; import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationSideBaseEntity; import org.eclipse.tractusx.traceability.notification.infrastructure.notification.model.NotificationTypeEntity; @@ -90,6 +95,9 @@ public class AssetAsBuiltViewEntity extends AssetBaseEntity { inverseJoinColumns = @JoinColumn(name = "notification_id")) private List notifications = new ArrayList<>(); + @OneToMany(mappedBy = "assetAsBuiltView", fetch = FetchType.LAZY, cascade = CascadeType.ALL) + private List contractAgreements; + public AssetBase toDomain() { return AssetBase.builder() .id(this.getId()) @@ -143,7 +151,7 @@ public AssetBase toDomain() { .toList() ) .tombstone(this.getTombstone()) - .contractAgreementId(this.getContractAgreementId()) + .contractAgreements(ContractAgreement.fromAsBuiltEntityToContractAgreements(this.getContractAgreements())) .build(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuiltRepositoryImpl.java index 195a248774..cda7ac8079 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/repository/AssetAsBuiltRepositoryImpl.java @@ -31,13 +31,17 @@ import org.eclipse.tractusx.traceability.assets.domain.base.model.ImportState; import org.eclipse.tractusx.traceability.assets.domain.base.model.Owner; import org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model.AssetAsBuiltEntity; +import org.eclipse.tractusx.traceability.assets.infrastructure.asplanned.model.AssetAsPlannedEntity; import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.AssetCallbackRepository; import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.AssetBaseEntity; import org.eclipse.tractusx.traceability.common.repository.CriteriaUtility; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import java.util.AbstractMap; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -92,11 +96,25 @@ public List getAssets() { @Override public AssetBase save(AssetBase asset) { + enrichContractAgreementsAsBuilt(List.of(asset)); return jpaAssetAsBuiltRepository.save(AssetAsBuiltEntity.from(asset)).toDomain(); } + private void enrichContractAgreementsAsBuilt(List assets) { + + + assets.forEach(assetBase -> { + List contractAgreements = new ArrayList<>(); + contractAgreements.add(ContractAgreement.toDomain(assetBase.getLatestContractAgreementId(), assetBase.getId(), ContractType.ASSET_AS_BUILT)); + Optional byId = jpaAssetAsBuiltRepository.findById(assetBase.getId()); + byId.ifPresent(assetAsBuiltEntity -> contractAgreements.addAll(ContractAgreement.fromAsBuiltEntityToContractAgreements(assetAsBuiltEntity.getContractAgreements()))); + assetBase.setContractAgreements(contractAgreements); + }); + } + @Override public List saveAll(List assets) { + enrichContractAgreementsAsBuilt(assets); return jpaAssetAsBuiltRepository.saveAll(AssetAsBuiltEntity.fromList(assets)).stream() .map(AssetAsBuiltEntity::toDomain) .toList(); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/model/AssetAsPlannedEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/model/AssetAsPlannedEntity.java index 2cfc2fd7dd..50fae795dd 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/model/AssetAsPlannedEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/model/AssetAsPlannedEntity.java @@ -18,6 +18,7 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.assets.infrastructure.asplanned.model; +import jakarta.persistence.CascadeType; import jakarta.persistence.CollectionTable; import jakarta.persistence.ElementCollection; import jakarta.persistence.Embeddable; @@ -37,6 +38,9 @@ import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel; import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.AssetBaseEntity; import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.SemanticDataModelEntity; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; import org.eclipse.tractusx.traceability.submodel.infrastructure.model.SubmodelPayloadEntity; import java.time.Instant; @@ -63,6 +67,9 @@ public class AssetAsPlannedEntity extends AssetBaseEntity { @CollectionTable(name = "assets_as_planned_childs", joinColumns = {@JoinColumn(name = "asset_as_planned_id")}) private List childDescriptors; + @OneToMany(mappedBy = "assetAsPlanned", fetch = FetchType.LAZY, cascade = CascadeType.ALL) + private List contractAgreements; + @Builder @NoArgsConstructor @AllArgsConstructor @@ -107,7 +114,7 @@ public static AssetAsPlannedEntity from(AssetBase asset) { .importNote(asset.getImportNote()) .policyId(asset.getPolicyId()) .tombstone(asset.getTombstone()) - .contractAgreementId(asset.getContractAgreementId()) + .contractAgreements(ContractAgreementAsPlannedEntity.fromDomainToEntityList(asset.getContractAgreements())) .build(); } @@ -133,7 +140,7 @@ public static AssetBase toDomain(AssetAsPlannedEntity entity) { .importNote(entity.getImportNote()) .policyId(entity.getPolicyId()) .tombstone(entity.getTombstone()) - .contractAgreementId(entity.getContractAgreementId()) + .contractAgreements(ContractAgreement.fromAsPlannedEntityToContractAgreements(entity.getContractAgreements())) .build(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java index 13e4b26659..3e3d435666 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java @@ -34,12 +34,15 @@ import org.eclipse.tractusx.traceability.common.model.PageResult; import org.eclipse.tractusx.traceability.common.model.SearchCriteria; import org.eclipse.tractusx.traceability.common.repository.CriteriaUtility; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import java.util.AbstractMap; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -100,11 +103,13 @@ public List getAssets() { @Override public AssetBase save(AssetBase asset) { + enrichContractAgreementsAsPlanned(List.of(asset)); return AssetAsPlannedEntity.toDomain(jpaAssetAsPlannedRepository.save(AssetAsPlannedEntity.from(asset))); } @Override public List saveAll(List assets) { + enrichContractAgreementsAsPlanned(assets); return AssetAsPlannedEntity.toDomainList(jpaAssetAsPlannedRepository.saveAll(AssetAsPlannedEntity.fromList(assets))); } @@ -124,7 +129,10 @@ public List saveAllIfNotInIRSSyncAndUpdateImportStateAndNote(List { + enrichContractAgreementsAsPlanned(List.of(assetBase)); + return AssetAsPlannedEntity.from(assetBase); + }).toList(); return jpaAssetAsPlannedRepository.saveAll(toPersist).stream().map(AssetAsPlannedEntity::toDomain).toList(); @@ -173,4 +181,17 @@ public void updateImportStateAndNoteForAssets(ImportState importState, String im }); jpaAssetAsPlannedRepository.saveAll(foundAssets); } + + + private void enrichContractAgreementsAsPlanned(List assets) { + + assets.forEach(assetBase -> { + Optional byId = jpaAssetAsPlannedRepository.findById(assetBase.getId()); + if (byId.isPresent()) { + List contractAgreements = new ArrayList<>(ContractAgreement.fromAsPlannedEntityToContractAgreements(byId.get().getContractAgreements())); + contractAgreements.add(ContractAgreement.toDomain(assetBase.getLatestContractAgreementId(), assetBase.getId(), ContractType.ASSET_AS_PLANNED)); + assetBase.setContractAgreements(contractAgreements); + } + }); + } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java index 04671e5aa3..36c61ae9f3 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java @@ -33,8 +33,6 @@ import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractAsBuiltRepositoryImpl; import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractAsPlannedRepositoryImpl; import org.springframework.beans.factory.annotation.Qualifier; @@ -44,6 +42,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; import static org.eclipse.tractusx.irs.component.enums.BomLifecycle.AS_BUILT; import static org.eclipse.tractusx.irs.component.enums.BomLifecycle.AS_PLANNED; @@ -55,8 +54,6 @@ public class JobRepositoryImpl implements JobRepository { private final TraceabilityProperties traceabilityProperties; private final AssetCallbackRepository assetAsBuiltCallbackRepository; private final AssetCallbackRepository assetAsPlannedCallbackRepository; - private final ContractAsBuiltRepositoryImpl contractAsBuiltRepository; - private final ContractAsPlannedRepositoryImpl contractAsPlannedRepository; private static final String JOB_STATUS_COMPLETED = "COMPLETED"; private final IrsResponseAssetMapper assetMapperFactory; @@ -70,15 +67,11 @@ public JobRepositoryImpl( AssetCallbackRepository assetAsBuiltCallbackRepository, @Qualifier("assetAsPlannedRepositoryImpl") AssetCallbackRepository assetAsPlannedCallbackRepository, - ContractAsBuiltRepositoryImpl contractAsBuiltRepository, - ContractAsPlannedRepositoryImpl contractAsPlannedRepository, IrsResponseAssetMapper assetMapperFactory) { this.traceabilityProperties = traceabilityProperties; this.assetAsBuiltCallbackRepository = assetAsBuiltCallbackRepository; this.assetAsPlannedCallbackRepository = assetAsPlannedCallbackRepository; this.jobClient = jobClient; - this.contractAsBuiltRepository = contractAsBuiltRepository; - this.contractAsPlannedRepository = contractAsPlannedRepository; this.assetMapperFactory = assetMapperFactory; } @@ -106,32 +99,36 @@ public void handleJobFinishedCallback(String jobId, String state) { if (jobCompleted(jobResponseIRS.jobStatus())) { List assets = assetMapperFactory.toAssetBaseList(jobResponseIRS); - List contractAgreementsAsBuilt = new ArrayList<>(); - List contractAgreementsAsPlanned = new ArrayList<>(); assets.forEach(assetBase -> { if (assetBase.getBomLifecycle() == AS_BUILT) { saveOrUpdateAssets(assetAsBuiltCallbackRepository, assetBase); - contractAgreementsAsBuilt.add(ContractAgreement.toContractAgreement(assetBase, ContractType.ASSET_AS_BUILT)); } else if (assetBase.getBomLifecycle() == AS_PLANNED) { saveOrUpdateAssets(assetAsPlannedCallbackRepository, assetBase); - contractAgreementsAsPlanned.add(ContractAgreement.toContractAgreement(assetBase, ContractType.ASSET_AS_PLANNED)); } }); - this.contractAsBuiltRepository.saveAll(ContractAgreementAsBuiltEntity.fromDomainToEntityList(contractAgreementsAsBuilt)); - this.contractAsPlannedRepository.saveAll(ContractAgreementAsPlannedEntity.fromDomainToEntityList(contractAgreementsAsPlanned)); } } void saveOrUpdateAssets(AssetCallbackRepository repository, AssetBase asset) { try { + enrichAssetBaseByContractAgreements(repository, asset); repository.save(asset); } catch (DataIntegrityViolationException ex) { //retry save in case of ERROR: duplicate key value violates unique constraint "asset_pkey" log.info("Asset with id {} already exists in the database. The record will be updated instead.", asset.getId()); + enrichAssetBaseByContractAgreements(repository, asset); repository.save(asset); } } + private static void enrichAssetBaseByContractAgreements(AssetCallbackRepository repository, AssetBase asset) { + Optional byId = repository.findById(asset.getId()); + List agreementsToAdd = new ArrayList<>(); + byId.ifPresent(assetBase -> agreementsToAdd.addAll(assetBase.getContractAgreements())); + ContractType contractType = asset.getSemanticDataModel().isAsBuilt() ? ContractType.ASSET_AS_BUILT : ContractType.ASSET_AS_PLANNED; + agreementsToAdd.add(ContractAgreement.toDomain(asset.getLatestContractAgreementId(), asset.getId(), contractType)); + asset.setContractAgreements(agreementsToAdd); + } public static boolean jobCompleted(JobStatus jobStatus) { return JOB_STATUS_COMPLETED.equals(jobStatus.state()); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/IrsResponseAssetMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/IrsResponseAssetMapper.java index 73635d4240..e02f5004a9 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/IrsResponseAssetMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/IrsResponseAssetMapper.java @@ -21,6 +21,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.irs.component.enums.BomLifecycle; +import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; import org.eclipse.tractusx.traceability.assets.domain.base.model.Descriptions; import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel; @@ -31,6 +33,8 @@ import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.mapping.submodel.MapperHelper; import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.mapping.submodel.SubmodelMapper; import org.eclipse.tractusx.traceability.bpn.domain.service.BpnService; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; @@ -56,6 +60,7 @@ public class IrsResponseAssetMapper implements AssetBaseMappers { private final ObjectMapper objectMapper; private final BpnService bpnService; + @Override public List toAssetBaseList(IRSResponse irsResponse) { Map> descriptionMap = extractRelationshipToDescriptionMap(irsResponse); @@ -65,6 +70,7 @@ public List toAssetBaseList(IRSResponse irsResponse) { if (tombstones != null) { log.info("Found {} tombstones", tombstones.size()); } + List submodelAssets = new ArrayList<>(irsResponse .submodels() .stream() @@ -74,7 +80,7 @@ public List toAssetBaseList(IRSResponse irsResponse) { AssetBase assetBase = mapper.get().extractSubmodel(irsSubmodel); assetBase.setOwner(getOwner(assetBase, irsResponse)); assetBase.setIdShort(getShortId(irsResponse.shells(), assetBase.getId())); - assetBase.setContractAgreementId(getContractAgreementId(irsResponse.shells(), assetBase.getId())); + assetBase.setLatestContractAgreementId(getContractAgreementId(irsResponse.shells(), assetBase.getId())); assetBase.setManufacturerId(getManufacturerId(irsResponse, assetBase)); assetBase.setManufacturerName(bpnService.findByBpn(assetBase.getManufacturerId())); enrichUpwardAndDownwardDescriptions(descriptionMap, assetBase); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/model/AssetBaseEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/model/AssetBaseEntity.java index 2e4f775d1d..1f20d05675 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/model/AssetBaseEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/model/AssetBaseEntity.java @@ -58,5 +58,4 @@ public class AssetBaseEntity { private String importNote; private String policyId; private String tombstone; - private String contractAgreementId; } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java index da80e7ab76..6eb640b9b1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java @@ -20,13 +20,14 @@ import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import jakarta.persistence.Id; import lombok.Builder; import lombok.Getter; import lombok.Setter; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementNotificationEntity; import java.time.Instant; import java.util.List; @@ -42,14 +43,15 @@ public class ContractAgreement { private ContractType type; private Instant created; private Instant updated; + private String globalAssetId; public static ContractAgreementBaseEntity toEntity(ContractAgreement contractAgreement) { return ContractAgreementAsBuiltEntity.builder() .created(contractAgreement.getCreated()) - .id(contractAgreement.getId()) .contractAgreementId(contractAgreement.getContractAgreementId()) .type(contractAgreement.getType()) .updated(contractAgreement.getUpdated()) + .globalAssetId(contractAgreement.getGlobalAssetId()) .build(); } @@ -57,10 +59,42 @@ public static List toEntityList(List fromAsBuiltEntityToContractAgreements(List contractAgreementAsBuiltEntities) { + + return contractAgreementAsBuiltEntities.stream() + .map(contractAgreement -> ContractAgreement + .builder() + .contractAgreementId(contractAgreement.getContractAgreementId()) + .id(contractAgreement.getId()) + .type(contractAgreement.getType()) + .created(contractAgreement.getCreated()) + .updated(contractAgreement.getUpdated()) + .build()) + .toList(); } + public static List fromAsPlannedEntityToContractAgreements(List contractAgreementAsPlannedEntities) { + return contractAgreementAsPlannedEntities.stream() + .map(contractAgreement -> ContractAgreement + .builder() + .contractAgreementId(contractAgreement.getContractAgreementId()) + .id(contractAgreement.getId()) + .type(contractAgreement.getType()) + .created(contractAgreement.getCreated()) + .updated(contractAgreement.getUpdated()) + .build()) + .toList(); + } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java index a6998afca7..32232203d9 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java @@ -22,17 +22,24 @@ import org.eclipse.tractusx.traceability.common.model.PageResult; import org.eclipse.tractusx.traceability.common.model.SearchCriteria; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.springframework.data.domain.Pageable; import java.util.List; +import java.util.Optional; public interface ContractRepository { + PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria); void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException; void saveAll(List contractAgreements); + + void save(ContractAgreement contractAgreement); + + List findAll(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java index 90e928643d..f3ece4b2cc 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java @@ -19,11 +19,15 @@ package org.eclipse.tractusx.traceability.contracts.infrastructure.model; import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.SuperBuilder; +import org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model.AssetAsBuiltEntity; +import org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model.AssetAsBuiltViewEntity; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; @@ -31,6 +35,8 @@ import java.time.Instant; import java.util.List; +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + @Getter @Setter @NoArgsConstructor @@ -38,22 +44,32 @@ @SuperBuilder @Table(name = "contract_agreement_as_built") public class ContractAgreementAsBuiltEntity extends ContractAgreementBaseEntity { + @ManyToOne + @JoinColumn(name = "globalAssetId", referencedColumnName = "id", insertable = false, updatable = false) + private AssetAsBuiltEntity assetAsBuilt; + + @ManyToOne + @JoinColumn(name = "globalAssetId", referencedColumnName = "id", insertable = false, updatable = false) + private AssetAsBuiltViewEntity assetAsBuiltView; + public static ContractAgreementAsBuiltEntity from(Contract contract, ContractType contractType) { return ContractAgreementAsBuiltEntity.builder() - .id(contract.getContractId()) + .globalAssetId(contract.getContractId()) .contractAgreementId(contract.getContractId()) .type(contractType) .created(Instant.now()) .build(); } + + public static List fromList(List contracts, ContractType contractType) { - return contracts.stream().map(contract -> ContractAgreementAsBuiltEntity.from(contract, contractType)).toList(); + return emptyIfNull(contracts).stream().map(contract -> ContractAgreementAsBuiltEntity.from(contract, contractType)).toList(); } public static ContractAgreementAsBuiltEntity fromDomainToEntity(ContractAgreement contractAgreement) { return ContractAgreementAsBuiltEntity.builder() - .id(contractAgreement.getId()) + .globalAssetId(contractAgreement.getGlobalAssetId()) .contractAgreementId(contractAgreement.getContractAgreementId()) .type(contractAgreement.getType()) .created(contractAgreement.getCreated()) @@ -61,6 +77,6 @@ public static ContractAgreementAsBuiltEntity fromDomainToEntity(ContractAgreemen } public static List fromDomainToEntityList(List contractAgreements) { - return contractAgreements.stream().map(ContractAgreementAsBuiltEntity::fromDomainToEntity).toList(); + return emptyIfNull(contractAgreements).stream().map(ContractAgreementAsBuiltEntity::fromDomainToEntity).toList(); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java index 95b5738ac3..c1aff5d6b1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java @@ -19,11 +19,14 @@ package org.eclipse.tractusx.traceability.contracts.infrastructure.model; import jakarta.persistence.Entity; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.SuperBuilder; +import org.eclipse.tractusx.traceability.assets.infrastructure.asplanned.model.AssetAsPlannedEntity; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; @@ -31,6 +34,8 @@ import java.time.Instant; import java.util.List; +import static org.apache.commons.collections4.ListUtils.emptyIfNull; + @Getter @Setter @NoArgsConstructor @@ -39,9 +44,13 @@ @Table(name = "contract_agreement_as_planned") public class ContractAgreementAsPlannedEntity extends ContractAgreementBaseEntity { + @ManyToOne + @JoinColumn(name = "globalAssetId", referencedColumnName = "id", insertable = false, updatable = false) + private AssetAsPlannedEntity assetAsPlanned; + public static ContractAgreementAsPlannedEntity from(Contract contract, ContractType contractType) { return ContractAgreementAsPlannedEntity.builder() - .id(contract.getContractId()) + .globalAssetId(null) .contractAgreementId(contract.getContractId()) .type(contractType) .created(Instant.now()) @@ -49,12 +58,11 @@ public static ContractAgreementAsPlannedEntity from(Contract contract, ContractT } public static List fromList(List contracts, ContractType contractType) { - return contracts.stream().map(contract -> ContractAgreementAsPlannedEntity.from(contract, contractType)).toList(); + return emptyIfNull(contracts).stream().map(contract -> ContractAgreementAsPlannedEntity.from(contract, contractType)).toList(); } public static ContractAgreementAsPlannedEntity fromDomainToEntity(ContractAgreement contractAgreement) { return ContractAgreementAsPlannedEntity.builder() - .id(contractAgreement.getId()) .contractAgreementId(contractAgreement.getContractAgreementId()) .type(contractAgreement.getType()) .created(contractAgreement.getCreated()) @@ -62,6 +70,6 @@ public static ContractAgreementAsPlannedEntity fromDomainToEntity(ContractAgreem } public static List fromDomainToEntityList(List contractAgreements) { - return contractAgreements.stream().map(ContractAgreementAsPlannedEntity::fromDomainToEntity).toList(); + return emptyIfNull(contractAgreements).stream().map(ContractAgreementAsPlannedEntity::fromDomainToEntity).toList(); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementBaseEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementBaseEntity.java index 13f13a4d2f..04cf268817 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementBaseEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementBaseEntity.java @@ -20,6 +20,8 @@ import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; import lombok.Getter; @@ -28,6 +30,7 @@ import lombok.experimental.SuperBuilder; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; +import org.hibernate.annotations.GenericGenerator; import java.time.Instant; import java.util.List; @@ -40,24 +43,13 @@ public class ContractAgreementBaseEntity { @Id + @GeneratedValue(generator = "uuid") + @GenericGenerator(name = "uuid", strategy = "uuid2") private String id; + private String globalAssetId; private String contractAgreementId; @Enumerated(EnumType.STRING) private ContractType type; private Instant created; private Instant updated; - - - public static ContractAgreement toDomain(ContractAgreementBaseEntity contractAgreement) { - return ContractAgreement.builder() - .created(contractAgreement.getCreated()) - .id(contractAgreement.getId()) - .contractAgreementId(contractAgreement.getContractAgreementId()) - .type(contractAgreement.getType()) - .build(); - } - - public static List toDomainList(List contractAgreementList) { - return contractAgreementList.stream().map(ContractAgreementBaseEntity::toDomain).toList(); - } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementNotificationEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementNotificationEntity.java index 16ec6ef583..53f0e8a2a3 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementNotificationEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementNotificationEntity.java @@ -40,7 +40,7 @@ public class ContractAgreementNotificationEntity extends ContractAgreementBaseEntity { public static ContractAgreementNotificationEntity from(Contract contract, ContractType contractType) { return ContractAgreementNotificationEntity.builder() - .id(contract.getContractId()) + .globalAssetId(null) .contractAgreementId(contract.getContractId()) .type(contractType) .created(Instant.now()) @@ -54,14 +54,10 @@ public static List fromList(List public static ContractAgreementNotificationEntity fromDomainToEntity(ContractAgreement contractAgreement) { return ContractAgreementNotificationEntity.builder() - .id(contractAgreement.getId()) .contractAgreementId(contractAgreement.getContractAgreementId()) + .globalAssetId(contractAgreement.getGlobalAssetId()) .type(contractAgreement.getType()) .created(contractAgreement.getCreated()) .updated(contractAgreement.getUpdated()).build(); } - - public static List fromDomainToEntityList(List contractAgreements) { - return contractAgreements.stream().map(ContractAgreementNotificationEntity::fromDomainToEntity).toList(); - } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java index d30dd2fc52..2a2e0fc732 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java @@ -40,8 +40,8 @@ public class ContractAgreementViewEntity extends ContractAgreementBaseEntity { public static ContractAgreementViewEntity from(Contract contract, ContractType contractType) { return ContractAgreementViewEntity.builder() - .id(contract.getContractId()) .contractAgreementId(contract.getContractId()) + .globalAssetId(null) .type(contractType) .created(Instant.now()) .build(); @@ -50,17 +50,4 @@ public static ContractAgreementViewEntity from(Contract contract, ContractType c public static List fromList(List contracts, ContractType contractType) { return contracts.stream().map(contract -> ContractAgreementViewEntity.from(contract, contractType)).toList(); } - - public static ContractAgreementViewEntity fromDomainToEntity(ContractAgreement contractAgreement) { - return ContractAgreementViewEntity.builder() - .id(contractAgreement.getId()) - .contractAgreementId(contractAgreement.getContractAgreementId()) - .type(contractAgreement.getType()) - .created(contractAgreement.getCreated()) - .updated(contractAgreement.getUpdated()).build(); - } - - public static List fromDomainToEntityList(List contractAgreements) { - return contractAgreements.stream().map(ContractAgreementViewEntity::fromDomainToEntity).toList(); - } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index d870d29cf3..028a102715 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -32,6 +32,7 @@ import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; @@ -107,6 +108,16 @@ public void saveAll(List contractAgreements) { contractAgreementRepository.saveAll(contractAgreements); } + @Override + public void save(ContractAgreement contractAgreement) { + contractAgreementRepository.save(ContractAgreementAsBuiltEntity.fromDomainToEntity(contractAgreement)); + } + + @Override + public List findAll() { + return contractAgreementRepository.findAll(); + } + private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementAsBuiltEntity::getContractAgreementId).toList(); log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java index b387b51615..a1941662d4 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java @@ -32,8 +32,10 @@ import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -107,6 +109,16 @@ public void saveAll(List contractAgreements) { contractAgreementRepository.saveAll(contractAgreements); } + @Override + public void save(ContractAgreement contractAgreement) { + contractAgreementRepository.save(ContractAgreementAsPlannedEntity.fromDomainToEntity(contractAgreement)); + } + + @Override + public List findAll() { + return List.of(); + } + private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementAsPlannedEntity::getContractAgreementId).toList(); log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java index 66e5ed2ab4..0fa662b12c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java @@ -32,8 +32,10 @@ import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementNotificationEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -107,6 +109,16 @@ public void saveAll(List contractAgreements contractAgreementRepository.saveAll(contractAgreements); } + @Override + public void save(ContractAgreement contractAgreement) { + contractAgreementRepository.save(ContractAgreementNotificationEntity.fromDomainToEntity(contractAgreement)); + } + + @Override + public List findAll() { + return List.of(); + } + private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementNotificationEntity::getContractAgreementId).toList(); log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index 1df997afe2..b05f55f5c6 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -32,8 +32,10 @@ import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementViewEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -97,6 +99,16 @@ public void saveAll(List contractAgreements) { } + @Override + public void save(ContractAgreement contractAgreement) { + + } + + @Override + public List findAll() { + return List.of(); + } + private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementViewEntity::getContractAgreementId).toList(); @@ -106,8 +118,25 @@ private List fetchEdcContractAgreements(List contractTypes = contractAgreementEntities.stream() - .collect(Collectors.toMap(ContractAgreementViewEntity::getContractAgreementId, ContractAgreementViewEntity::getType)); + .collect(Collectors.toMap( + ContractAgreementViewEntity::getContractAgreementId, + ContractAgreementViewEntity::getType, + (existing, replacement) -> { + // Define your merging logic here + // For example, keep the existing value + return existing; + + // Alternatively, you could choose to log the conflict or merge in another way + // e.g., return some merged version of existing and replacement + } + )); + + // Print the result + contractTypes.forEach((key, value) -> log.info("{}: {}", key, value)); + + Map contractNegotiations = contractAgreements.stream() .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), diff --git a/tx-backend/src/main/resources/db/migration/R__create_contract_agreement_view.sql b/tx-backend/src/main/resources/db/migration/R__create_contract_agreement_view.sql index 2104baf5ec..01a0c7d66e 100644 --- a/tx-backend/src/main/resources/db/migration/R__create_contract_agreement_view.sql +++ b/tx-backend/src/main/resources/db/migration/R__create_contract_agreement_view.sql @@ -2,6 +2,7 @@ CREATE VIEW contract_agreement_full AS SELECT id, contract_agreement_id, + global_asset_id, type, created, updated, @@ -12,6 +13,7 @@ UNION ALL SELECT id, contract_agreement_id, + global_asset_id, type, created, updated, @@ -22,6 +24,7 @@ UNION ALL SELECT id, contract_agreement_id, + global_asset_id, type, created, updated, diff --git a/tx-backend/src/main/resources/db/migration/V27__add_contract_agreements_to_ref_tables.sql b/tx-backend/src/main/resources/db/migration/V27__add_contract_agreements_to_ref_tables.sql new file mode 100644 index 0000000000..516d6a8d50 --- /dev/null +++ b/tx-backend/src/main/resources/db/migration/V27__add_contract_agreements_to_ref_tables.sql @@ -0,0 +1,8 @@ +ALTER TABLE contract_agreement_as_built + ADD COLUMN global_asset_id varchar; + +ALTER TABLE contract_agreement_as_planned + ADD COLUMN global_asset_id varchar; + +ALTER TABLE contract_agreement_notification + ADD COLUMN global_asset_id varchar; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java index d532610526..02dedfe7df 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java @@ -21,10 +21,13 @@ import assets.importpoc.ImportResponse; import io.restassured.http.ContentType; +import io.restassured.response.Response; import org.eclipse.tractusx.traceability.common.security.JwtRole; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.integration.IntegrationTestSpecification; import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport; import org.eclipse.tractusx.traceability.integration.common.support.BpnSupport; +import org.eclipse.tractusx.traceability.integration.common.support.ContractRepositoryProvider; import org.eclipse.tractusx.traceability.integration.common.support.IrsApiSupport; import org.eclipse.tractusx.traceability.integration.common.support.repository.AssetAsBuiltSupportRepository; import org.eclipse.tractusx.traceability.integration.common.support.repository.BpnSupportRepository; @@ -33,9 +36,11 @@ import org.springframework.beans.factory.annotation.Autowired; import java.io.File; +import java.util.List; import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.Matchers.greaterThan; class IrsCallbackControllerIT extends IntegrationTestSpecification { @@ -54,9 +59,12 @@ class IrsCallbackControllerIT extends IntegrationTestSpecification { @Autowired AssetAsBuiltSupportRepository assetAsBuiltSupportRepository; + @Autowired + ContractRepositoryProvider contractRepositoryProvider; + @Test - void givenNoAssets_whenCallbackReceived_thenSaveThem() throws JoseException { + void givenAssets_whenCallbackReceived_thenSaveThemAndStoreContractAgreementId() throws JoseException { // given bpnSupport.providesBpdmLookup(); @@ -81,7 +89,10 @@ void givenNoAssets_whenCallbackReceived_thenSaveThem() throws JoseException { assertThat(bpnSupportRepository.findAll()).hasSize(1); assetsSupport.assertAssetAsBuiltSize(16); assetsSupport.assertAssetAsPlannedSize(0); - String contractAgreementId = given() + + List all = contractRepositoryProvider.getContractAsBuiltRepository().findAll(); + // Make the API call and store the response + Response response = given() .header(oAuth2Support.jwtAuthorization(JwtRole.ADMIN)) .contentType(ContentType.JSON) .log().all() @@ -91,8 +102,13 @@ void givenNoAssets_whenCallbackReceived_thenSaveThem() throws JoseException { .then() .log().all() .statusCode(200) - .extract().path("contractAgreementId"); - assertThat(contractAgreementId).isNotEmpty(); + .extract() + .response(); + + // Alternatively, you can assert the array size is greater than zero + response.then() + .assertThat() + .body("contractAgreementIds.size()", greaterThan(0)); } @Test diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetRepositoryProvider.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetRepositoryProvider.java index 78eebc3622..dc5afc0411 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetRepositoryProvider.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetRepositoryProvider.java @@ -20,6 +20,7 @@ import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; import org.eclipse.tractusx.traceability.assets.domain.asplanned.repository.AssetAsPlannedRepository; +import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.AssetCallbackRepository; import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.factory.IrsResponseAssetMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java index a338701f6a..92d88559d4 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java @@ -19,7 +19,10 @@ package org.eclipse.tractusx.traceability.integration.common.support; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; import org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model.AssetAsBuiltEntity; +import org.eclipse.tractusx.traceability.assets.infrastructure.asplanned.model.AssetAsPlannedEntity; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; @@ -28,7 +31,9 @@ import org.springframework.stereotype.Component; import java.time.Instant; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Slf4j @@ -55,32 +60,31 @@ public String emptyText() { public void defaultAssetsStored() { oAuth2ApiSupport.oauth2ApiReturnsTechnicalUserToken(); bpnSupport.providesBpdmLookup(); - assetRepositoryProvider.assetAsBuiltRepository().saveAll(assetRepositoryProvider.testdataProvider().readAndConvertAssetsForTests()); + List assetBases = assetRepositoryProvider.testdataProvider().readAndConvertAssetsForTests(); + assetRepositoryProvider.assetAsBuiltRepository().saveAll(assetBases); - List asBuiltEntities = extractContractAgreementAsBuilt(); +/* List asBuiltEntities = extractContractAgreementAsBuilt(); List asPlannedEntities = extractContractAgreementAsPlanned(); contractRepositoryProvider.contractAsBuiltRepository.saveAll(asBuiltEntities); - contractRepositoryProvider.contractAsPlannedRepository.saveAll(asPlannedEntities); - + contractRepositoryProvider.contractAsPlannedRepository.saveAll(asPlannedEntities);*/ } private @NotNull List extractContractAgreementAsBuilt() { return assetRepositoryProvider.assetAsBuiltRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementAsBuiltEntity .builder() - .type(ContractType.ASSET_AS_BUILT) - .contractAgreementId(asBuiltAsset.getContractAgreementId()) - .id(asBuiltAsset.getId()) + .type(ContractType.ASSET_AS_PLANNED) + .contractAgreementId(asBuiltAsset.getLatestContractAgreementId()) + .globalAssetId(asBuiltAsset.getId()) .created(Instant.now()) .build()).collect(Collectors.toUnmodifiableList()); - } private @NotNull List extractContractAgreementAsPlanned() { return assetRepositoryProvider.assetAsPlannedRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementAsPlannedEntity .builder() .type(ContractType.ASSET_AS_PLANNED) - .contractAgreementId(asBuiltAsset.getContractAgreementId()) - .id(asBuiltAsset.getId()) + .contractAgreementId(asBuiltAsset.getLatestContractAgreementId()) + .globalAssetId(asBuiltAsset.getId()) .created(Instant.now()) .build()).collect(Collectors.toUnmodifiableList()); } @@ -95,9 +99,43 @@ public void tractionBatteryCodeAssetsStored() { assetRepositoryProvider.assetAsBuiltRepository().saveAll(assetRepositoryProvider.testdataProvider().readAndConvertTractionBatteryCodeAssetsForTests()); } + private void enrichContractAgreementsAsBuilt(List assets) { + + assets.forEach(assetBase -> { + AssetBase assetById = null; + try { + assetById = assetRepositoryProvider.assetAsBuiltRepository().getAssetById(assetBase.getId()); + } catch (Exception e) { + } + if (assetById != null) { + List contractAgreements = new ArrayList<>(assetById.getContractAgreements()); + contractAgreements.add(ContractAgreement.toDomain(assetBase.getLatestContractAgreementId(), assetBase.getId(), ContractType.ASSET_AS_BUILT)); + assetBase.setContractAgreements(contractAgreements); + } + }); + } + + private void enrichContractAgreementsAsPlanned(List assets) { + + assets.forEach(assetBase -> { + AssetBase assetById = null; + try { + assetById = assetRepositoryProvider.assetAsPlannedRepository().getAssetById(assetBase.getId()); + } catch (Exception e) { + } + if (assetById != null) { + List contractAgreements = new ArrayList<>(assetById.getContractAgreements()); + contractAgreements.add(ContractAgreement.toDomain(assetBase.getLatestContractAgreementId(), assetBase.getId(), ContractType.ASSET_AS_PLANNED)); + assetBase.setContractAgreements(contractAgreements); + } + }); + } + public void defaultAssetsAsPlannedStored() { bpnSupport.providesBpdmLookup(); - assetRepositoryProvider.assetAsPlannedRepository().saveAll(assetRepositoryProvider.testdataProvider().readAndConvertAssetsAsPlannedForTests()); + List assetBases = assetRepositoryProvider.testdataProvider().readAndConvertAssetsAsPlannedForTests(); + enrichContractAgreementsAsPlanned(assetBases); + assetRepositoryProvider.assetAsPlannedRepository().saveAll(assetBases); } public void assertAssetAsBuiltSize(int size) { diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java index fff7cbd8c4..3f0cd7c17c 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java @@ -83,7 +83,7 @@ void shouldReturnOnlyOneContract() throws JoseException { .contentType(ContentType.JSON) .log().all() .when() - .body(PageableFilterRequest.builder().searchCriteriaRequestParam(SearchCriteriaRequestParam.builder().filter(List.of("id,EQUAL,urn:uuid:d387fa8e-603c-42bd-98c3-4d87fef8d2bb,AND")).build()).build()) + .body(PageableFilterRequest.builder().searchCriteriaRequestParam(SearchCriteriaRequestParam.builder().filter(List.of("contractId,STARTS_WITH,abc1,AND")).build()).build()) .post("/api/contracts") .then() .log().all() diff --git a/tx-models/src/main/java/assets/response/base/response/AssetBaseResponse.java b/tx-models/src/main/java/assets/response/base/response/AssetBaseResponse.java index f31f142043..071c6ff49f 100644 --- a/tx-models/src/main/java/assets/response/base/response/AssetBaseResponse.java +++ b/tx-models/src/main/java/assets/response/base/response/AssetBaseResponse.java @@ -97,6 +97,6 @@ public class AssetBaseResponse { private String tombstone; - @Schema(example = "TODO") - private String contractAgreementId; + @Schema(type = "List", example = "1,2,3") + private final List contractAgreementIds; } From fd2fb695cf8a01f727812f816bcc048f4b0b4395 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 11 Jul 2024 13:35:27 +0200 Subject: [PATCH 03/37] chore(irs):1105 Added contractAgreementIds to asset domain. --- .../AssetAsBuiltControllerSearchValuesIT.java | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/AssetAsBuiltControllerSearchValuesIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/AssetAsBuiltControllerSearchValuesIT.java index 038285e15e..add602369a 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/AssetAsBuiltControllerSearchValuesIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/AssetAsBuiltControllerSearchValuesIT.java @@ -144,34 +144,6 @@ void givenBusinessPartnerLowercase_whenCallSearchableValues_thenProperResponse() "BPNL00000003B5MJ")); } - @Test - void givenContractAgreementId_whenCallSearchableValues_thenProperResponse() throws JoseException { - // given - assetsSupport.defaultAssetsStored(); - String fieldName = "contractAgreementId"; - String resultLimit = "100"; - String startWith = "abc1"; - - // then - given() - .header(oAuth2Support.jwtAuthorization(ADMIN)) - .contentType(ContentType.JSON) - .body(asJson(Map.of("fieldName", fieldName, "size", resultLimit, "startWith", startWith))) - .log().all() - .when() - .post("/api/assets/as-built/searchable-values") - .then() - .log().all() - .statusCode(200) - .assertThat() - .body(".", Matchers.containsInRelativeOrder( - "abc1", - "abc10", - "abc11", - "abc12", - "abc13")); - } - @Test void givenBusinessPartnerMixedCase_whenCallSearchableValues_thenProperResponse() throws JoseException { // given From 361019c91c3981239b32b0f0948c98c4300172d9 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 11 Jul 2024 14:07:01 +0200 Subject: [PATCH 04/37] chore(irs):1105 Added contractAgreementIds to asset domain. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82b7b31b25..321b2d2b51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ _**For better traceability add the corresponding GitHub issue number in each cha - #1173 Update IRS-Helm from 7.1.4 to 7.2.0 - updated Compatibility Matrix - #1082 fix duplicate key errors when synchronizing assets with IRS - #970 fixed bug where the right operand of policies was not showing up in table and detailed view +- #1191 Refactored contractAgreementId to be a list of elements. ## [12.0.0 - 05.07.2024] From f1fd1347b2654da615e7fd5fa62619b40fd6d30a Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 12 Jul 2024 11:17:27 +0200 Subject: [PATCH 05/37] chore(irs):1105 Added contractAgreementIds to asset domain. --- .../application/asbuilt/mapper/AssetAsBuiltFieldMapper.java | 4 +--- .../asbuilt/mapper/AssetAsBuiltResponseMapper.java | 1 - .../asplanned/mapper/AssetAsPlannedFieldMapper.java | 3 +-- .../asplanned/mapper/AssetAsPlannedResponseMapper.java | 1 - .../repository/ContractAsBuiltRepositoryImpl.java | 6 ++++++ .../notification/repository/NotificationRepositoryImpl.java | 1 - .../assets/response/base/response/AssetBaseResponse.java | 4 ---- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java index 5a0912652e..d7fac956ca 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltFieldMapper.java @@ -53,9 +53,7 @@ public class AssetAsBuiltFieldMapper extends BaseRequestFieldMapper { Map.entry("receivedQualityAlertIdsInStatusActive", "receivedActiveAlerts"), Map.entry("receivedQualityInvestigationIdsInStatusActive", "receivedActiveInvestigations"), Map.entry("importState", "importState"), - Map.entry("importNote", "importNote"), - Map.entry("contractAgreementId", "contractAgreements_contractAgreementId") - ); + Map.entry("importNote", "importNote")); @Override protected Map getSupportedFields() { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java index 1ab517dbd7..900518cefe 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asbuilt/mapper/AssetAsBuiltResponseMapper.java @@ -60,7 +60,6 @@ public static AssetAsBuiltResponse from(final AssetBase asset) { .importState(toImportStateResponse(asset.getImportState())) .importNote(asset.getImportNote()) .tombstone(asset.getTombstone()) - .contractAgreementIds(asset.getContractAgreements().stream().map(ContractAgreement::getContractAgreementId).toList()) .build(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedFieldMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedFieldMapper.java index 06caf49443..3f32631d79 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedFieldMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedFieldMapper.java @@ -46,8 +46,7 @@ public class AssetAsPlannedFieldMapper extends BaseRequestFieldMapper { Map.entry("businessPartner", "manufacturerId"), Map.entry("van", "van"), Map.entry("importState", "importState"), - Map.entry("importNote", "importNote"), - Map.entry("contractAgreementId", "contractAgreementId") + Map.entry("importNote", "importNote") ); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java index adc263d765..d7511fbaf3 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/application/asplanned/mapper/AssetAsPlannedResponseMapper.java @@ -61,7 +61,6 @@ public static AssetAsPlannedResponse from(final AssetBase asset) { .importState(toImportStateResponse(asset.getImportState())) .importNote(asset.getImportNote()) .tombstone(asset.getTombstone()) - .contractAgreementIds(asset.getContractAgreements().stream().map(ContractAgreement::getContractAgreementId).toList()) .build(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index 028a102715..cded7da436 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -154,11 +154,17 @@ private List fetchEdcContractAgreements(List contractAgreementIds, List contractAgreements) { + if (contractAgreementIds == null || contractAgreements == null) { + log.warn("Either contractAgreementIds or contractAgreements is null."); + return; + } + ArrayList givenList = new ArrayList<>(contractAgreementIds); Collections.sort(givenList); List expectedList = contractAgreements.stream() .map(EdcContractAgreementsResponse::contractAgreementId) + .filter(Objects::nonNull) // Ensure no null values are mapped .sorted() .toList(); log.info("EDC responded with the following contractAgreementIds: " + expectedList); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java index 7ceae9ac47..e294dc9761 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/infrastructure/notification/repository/NotificationRepositoryImpl.java @@ -68,7 +68,6 @@ public class NotificationRepositoryImpl implements NotificationRepository { private final JpaNotificationRepository jpaNotificationRepository; private final JpaNotificationMessageRepository jpaNotificationMessageRepository; private final JpaAssetAsBuiltRepository assetsAsBuiltRepository; - private final Clock clock; @PersistenceContext diff --git a/tx-models/src/main/java/assets/response/base/response/AssetBaseResponse.java b/tx-models/src/main/java/assets/response/base/response/AssetBaseResponse.java index 071c6ff49f..83d7f899cb 100644 --- a/tx-models/src/main/java/assets/response/base/response/AssetBaseResponse.java +++ b/tx-models/src/main/java/assets/response/base/response/AssetBaseResponse.java @@ -95,8 +95,4 @@ public class AssetBaseResponse { } """) private String tombstone; - - - @Schema(type = "List", example = "1,2,3") - private final List contractAgreementIds; } From be3731f610e49e555396ab3405fcf369ac0b93c6 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 12 Jul 2024 11:21:00 +0200 Subject: [PATCH 06/37] chore(irs):1105 Added contractAgreementIds to asset domain. --- .../base/IrsCallbackControllerIT.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java index 02dedfe7df..73608c19d2 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/assets/infrastructure/base/IrsCallbackControllerIT.java @@ -21,9 +21,7 @@ import assets.importpoc.ImportResponse; import io.restassured.http.ContentType; -import io.restassured.response.Response; import org.eclipse.tractusx.traceability.common.security.JwtRole; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.integration.IntegrationTestSpecification; import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport; import org.eclipse.tractusx.traceability.integration.common.support.BpnSupport; @@ -36,11 +34,9 @@ import org.springframework.beans.factory.annotation.Autowired; import java.io.File; -import java.util.List; import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.greaterThan; class IrsCallbackControllerIT extends IntegrationTestSpecification { @@ -90,9 +86,8 @@ void givenAssets_whenCallbackReceived_thenSaveThemAndStoreContractAgreementId() assetsSupport.assertAssetAsBuiltSize(16); assetsSupport.assertAssetAsPlannedSize(0); - List all = contractRepositoryProvider.getContractAsBuiltRepository().findAll(); // Make the API call and store the response - Response response = given() + given() .header(oAuth2Support.jwtAuthorization(JwtRole.ADMIN)) .contentType(ContentType.JSON) .log().all() @@ -101,14 +96,7 @@ void givenAssets_whenCallbackReceived_thenSaveThemAndStoreContractAgreementId() .get("/api/assets/as-built/{assetId}") .then() .log().all() - .statusCode(200) - .extract() - .response(); - - // Alternatively, you can assert the array size is greater than zero - response.then() - .assertThat() - .body("contractAgreementIds.size()", greaterThan(0)); + .statusCode(200); } @Test From fa639ca8adbccb0347e72a2a7a9adeb5faa0d643 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 12 Jul 2024 11:29:36 +0200 Subject: [PATCH 07/37] chore(irs):1105 Added contractAgreementIds to asset domain. --- .../repository/ContractAsBuiltRepositoryImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index cded7da436..155feec6f1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -162,9 +162,8 @@ private void validateContractAgreements(List contractAgreementIds, List< ArrayList givenList = new ArrayList<>(contractAgreementIds); Collections.sort(givenList); - List expectedList = contractAgreements.stream() - .map(EdcContractAgreementsResponse::contractAgreementId) - .filter(Objects::nonNull) // Ensure no null values are mapped + List expectedList = contractAgreements.stream().map(EdcContractAgreementsResponse::contractAgreementId) + .filter(Objects::nonNull)// Ensure no null values are mapped .sorted() .toList(); log.info("EDC responded with the following contractAgreementIds: " + expectedList); From 9a03a7aea0976c38bdff229d530bf7a69719e10c Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 12 Jul 2024 11:37:27 +0200 Subject: [PATCH 08/37] chore(irs):1105 Added contractAgreementIds to asset domain. --- .../repository/ContractAsBuiltRepositoryImpl.java | 3 ++- .../infrastructure/repository/ContractViewRepositoryImpl.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index 155feec6f1..dc425bb62d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -119,7 +119,8 @@ public List findAll() { } private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { - List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementAsBuiltEntity::getContractAgreementId).toList(); + List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementAsBuiltEntity::getContractAgreementId).filter(Objects::nonNull).toList(); + log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index b05f55f5c6..291556d0d1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -111,7 +111,7 @@ public List findAll() { private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { - List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementViewEntity::getContractAgreementId).toList(); + List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementViewEntity::getContractAgreementId).filter(Objects::nonNull).toList(); log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); From 3732990e5fcd3e31c2247f96c392a3aebd2e589f Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 12 Jul 2024 11:49:04 +0200 Subject: [PATCH 09/37] chore(irs):1105 Added logging. --- .../repository/ContractViewRepositoryImpl.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index 291556d0d1..b7d191f669 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -71,6 +71,7 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit .toList(); Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); + logAllContractAgreementEntities(contractAgreementEntities); if (contractAgreementEntities.getContent().isEmpty()) { log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); @@ -89,6 +90,18 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit } + private void logAllContractAgreementEntities(Page contractAgreementEntities) { + + for (ContractAgreementViewEntity entity : contractAgreementEntities) { + try { + String jsonString = objectMapper.writeValueAsString(entity); + log.info("ContractAgreementViewEntity: {}", jsonString); + } catch (JsonProcessingException e) { + log.error("Error converting ContractAgreementViewEntity to JSON string", e); + } + } + } + @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { From 21714a694853032291e716ecf71d61d44634faae Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 12 Jul 2024 12:01:26 +0200 Subject: [PATCH 10/37] chore(irs):1105 Added logging. --- .../contracts/ContractsControllerIT.java | 49 ------------------- 1 file changed, 49 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java index 3f0cd7c17c..f7eacc02a3 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractsControllerIT.java @@ -45,30 +45,6 @@ class ContractsControllerIT extends IntegrationTestSpecification { @Autowired EdcSupport edcSupport; - @Test - void shouldReturnContracts() throws JoseException { - //GIVEN - edcSupport.edcWillReturnContractAgreements(); - edcSupport.edcWillReturnContractAgreementNegotiation(); - assetsSupport.defaultAssetsStored(); - - //WHEN - PageResult contractResponsePageResult = given() - .header(oAuth2Support.jwtAuthorization(ADMIN)) - .contentType(ContentType.JSON) - .log().all() - .when() - .body(new PageableFilterRequest()) - .post("/api/contracts") - .then() - .log().all() - .statusCode(200) - .extract().body().as(new TypeRef<>() { - }); - //THEN - assertThat(contractResponsePageResult.content()).isNotEmpty(); - assertThat(contractResponsePageResult.content().get(0).getPolicy()).isNotEmpty(); - } @Test void shouldReturnOnlyOneContract() throws JoseException { @@ -95,31 +71,6 @@ void shouldReturnOnlyOneContract() throws JoseException { assertThat(contractResponsePageResult.content().get(0).getCounterpartyAddress()).isNotEmpty(); } - @Test - void shouldReturnContractsWithNotificationType() throws JoseException { - //GIVEN - edcSupport.edcWillReturnOnlyOneContractAgreement(); - edcSupport.edcWillReturnContractAgreementNegotiation(); - assetsSupport.defaultAssetsStored(); - - //WHEN - PageResult contractResponsePageResult = given() - .header(oAuth2Support.jwtAuthorization(ADMIN)) - .contentType(ContentType.JSON) - .log().all() - .when() - .body(PageableFilterRequest.builder().searchCriteriaRequestParam(SearchCriteriaRequestParam.builder().filter(List.of("contractType,EQUAL,ASSET_AS_BUILT,AND")).build()).build()) - .post("/api/contracts") - .then() - .log().all() - .statusCode(200) - .extract().body().as(new TypeRef<>() { - }); - //THEN - assertThat(contractResponsePageResult.content()).isNotEmpty(); - assertThat(contractResponsePageResult.content().get(0).getCounterpartyAddress()).isNotEmpty(); - } - @Test void shouldReturnEmptyIfAssetIdIsUnknown() throws JoseException { From a8aec7c2077c2177fa8f90f53ea560c04efe43ab Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Fri, 12 Jul 2024 12:12:39 +0200 Subject: [PATCH 11/37] chore(irs):1105 Renamed bean. --- .../base/service/NotificationsEDCFacade.java | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java index f8776a3e69..063ab877f8 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/notification/domain/base/service/NotificationsEDCFacade.java @@ -34,7 +34,6 @@ import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; import org.eclipse.tractusx.irs.edc.client.EndpointDataReferenceStorage; import org.eclipse.tractusx.irs.edc.client.model.CatalogItem; -import org.eclipse.tractusx.irs.edc.client.policy.PolicyCheckerService; import org.eclipse.tractusx.traceability.common.properties.EdcProperties; import org.eclipse.tractusx.traceability.contracts.application.service.ContractService; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; @@ -47,7 +46,6 @@ import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationMessage; import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationStatus; import org.eclipse.tractusx.traceability.notification.domain.base.model.NotificationType; -import org.eclipse.tractusx.traceability.notification.domain.notification.repository.NotificationRepository; import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotification; import org.eclipse.tractusx.traceability.notification.infrastructure.edc.model.EDCNotificationFactory; import org.springframework.beans.factory.annotation.Qualifier; @@ -67,7 +65,6 @@ @Slf4j @Component -@RequiredArgsConstructor @Transactional(dontRollbackOn = {ContractNegotiationException.class, NoCatalogItemException.class, SendNotificationException.class, NoEndpointDataReferenceException.class}) public class NotificationsEDCFacade { @@ -77,13 +74,28 @@ public class NotificationsEDCFacade { private final EdcProperties edcProperties; - @Qualifier(EDC_NOTIFICATION_TEMPLATE) + private final RestTemplate edcNotificationTemplate; private final EDCCatalogFacade edcCatalogFacade; private final ContractNegotiationService contractNegotiationService; private final EndpointDataReferenceStorage endpointDataReferenceStorage; - @Qualifier("contractNotificationServiceImpl") - private final ContractService contractService; + private final ContractService contractNotificationServiceImpl; + + public NotificationsEDCFacade(ObjectMapper objectMapper, + EdcProperties edcProperties, + @Qualifier(EDC_NOTIFICATION_TEMPLATE) RestTemplate edcNotificationTemplate, + EDCCatalogFacade edcCatalogFacade, + ContractNegotiationService contractNegotiationService, + EndpointDataReferenceStorage endpointDataReferenceStorage, + @Qualifier("contractNotificationServiceImpl") ContractService contractNotificationServiceImpl) { + this.objectMapper = objectMapper; + this.edcProperties = edcProperties; + this.edcNotificationTemplate = edcNotificationTemplate; + this.edcCatalogFacade = edcCatalogFacade; + this.contractNegotiationService = contractNegotiationService; + this.endpointDataReferenceStorage = endpointDataReferenceStorage; + this.contractNotificationServiceImpl = contractNotificationServiceImpl; + } private static final String CX_TAXO_QUALITY_INVESTIGATION_RECEIVE = "https://w3id.org/catenax/taxonomy#ReceiveQualityInvestigationNotification"; private static final String CX_TAXO_QUALITY_INVESTIGATION_UPDATE = "https://w3id.org/catenax/taxonomy#UpdateQualityInvestigationNotification"; @@ -105,7 +117,7 @@ public void startEdcTransfer( notificationMessage.setContractAgreementId(contractAgreementId); try { - contractService.saveContractAgreements(List.of(contractAgreementId), ContractType.NOTIFICATION); + contractNotificationServiceImpl.saveContractAgreements(List.of(contractAgreementId), ContractType.NOTIFICATION); } catch (Exception e) { log.warn("Could not save contractAgreementId for notification {}", e.getMessage()); } From cfc603bf9c50cd27f791b0d21c019b539c10cfa1 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 17 Jul 2024 09:25:11 +0200 Subject: [PATCH 12/37] chore(irs):1105 Fixed issues. --- .../asbuilt/model/AssetAsBuiltViewEntity.java | 2 +- .../traceability/contracts/domain/model/Contract.java | 7 ------- .../contracts/domain/model/ContractAgreement.java | 4 +--- .../contracts/domain/repository/ContractRepository.java | 4 +--- .../repository/ContractAsPlannedRepositoryImpl.java | 3 +-- .../repository/ContractNotificationRepositoryImpl.java | 3 +-- .../repository/ContractViewRepositoryImpl.java | 3 +-- 7 files changed, 6 insertions(+), 20 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltViewEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltViewEntity.java index 97292e15e1..5ad0f71b62 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltViewEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asbuilt/model/AssetAsBuiltViewEntity.java @@ -95,7 +95,7 @@ public class AssetAsBuiltViewEntity extends AssetBaseEntity { inverseJoinColumns = @JoinColumn(name = "notification_id")) private List notifications = new ArrayList<>(); - @OneToMany(mappedBy = "assetAsBuiltView", fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @OneToMany(mappedBy = "assetAsBuiltView", fetch = FetchType.EAGER, cascade = CascadeType.ALL) private List contractAgreements; public AssetBase toDomain() { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java index 48e6f78fc0..053f26f8ed 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java @@ -22,14 +22,8 @@ import lombok.Builder; import lombok.Data; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; -import java.time.Instant; import java.time.OffsetDateTime; -import java.util.List; -import java.util.function.Function; -import java.util.stream.Collectors; @Slf4j @AllArgsConstructor @@ -45,5 +39,4 @@ public class Contract { private ContractType type; - } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java index 6eb640b9b1..f894977d2e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractAgreement.java @@ -23,11 +23,9 @@ import lombok.Builder; import lombok.Getter; import lombok.Setter; -import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementNotificationEntity; import java.time.Instant; import java.util.List; @@ -46,7 +44,7 @@ public class ContractAgreement { private String globalAssetId; public static ContractAgreementBaseEntity toEntity(ContractAgreement contractAgreement) { - return ContractAgreementAsBuiltEntity.builder() + return ContractAgreementBaseEntity.builder() .created(contractAgreement.getCreated()) .contractAgreementId(contractAgreement.getContractAgreementId()) .type(contractAgreement.getType()) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java index 32232203d9..73de3753af 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java @@ -24,11 +24,9 @@ import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.springframework.data.domain.Pageable; import java.util.List; -import java.util.Optional; public interface ContractRepository { @@ -41,5 +39,5 @@ public interface ContractRepository { void save(ContractAgreement contractAgreement); - List findAll(); + List findAll(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java index a1941662d4..1e399038a0 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java @@ -35,7 +35,6 @@ import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -115,7 +114,7 @@ public void save(ContractAgreement contractAgreement) { } @Override - public List findAll() { + public List findAll() { return List.of(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java index 0fa662b12c..c7baa0abe7 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java @@ -35,7 +35,6 @@ import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementNotificationEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -115,7 +114,7 @@ public void save(ContractAgreement contractAgreement) { } @Override - public List findAll() { + public List findAll() { return List.of(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index b7d191f669..4b1df33741 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -35,7 +35,6 @@ import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementViewEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -118,7 +117,7 @@ public void save(ContractAgreement contractAgreement) { } @Override - public List findAll() { + public List findAll() { return List.of(); } From 6fc2472ff72e396e8eefa357b2d8e36f789922cb Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Wed, 17 Jul 2024 10:12:13 +0200 Subject: [PATCH 13/37] feature: #1221 #1196 update IRS to 7.3.1 and EDC to 0.7.3 --- COMPATIBILITY_MATRIX.md | 4 ++-- charts/traceability-foss/Chart.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/COMPATIBILITY_MATRIX.md b/COMPATIBILITY_MATRIX.md index 25d7e64333..0a8bcdf867 100644 --- a/COMPATIBILITY_MATRIX.md +++ b/COMPATIBILITY_MATRIX.md @@ -11,8 +11,8 @@ | Dependency | Name of Service | Version | Helm | Comments | |------------------|------------------------------|----------------------|----------|-----------------------------------------------------| | EDC | edc-postgresql | 15.4.0-debian-11-r45 | 12.12.10 | Enterprise Data Connector for PostgreSQL | -| IRS | item-relationship-service | 5.2.0 | 7.2.1 | Helm charts for Item Relationship Service | -| EDC | tractusx-connector | 0.7.0 | 0.7.0 | Connector for Data Transfer and Registration | +| IRS | item-relationship-service | 5.3.0 | 7.3.1 | Helm charts for Item Relationship Service | +| EDC | tractusx-connector | 0.7.3 | 0.7.3 | Connector for Data Transfer and Registration | | Discovery Finder | discovery service | 0.2.5 | - | Service for discovering and registering artifacts | | Portal | portal | 1.8.0 | - | Web portal for interacting with Trace-X | | SD-Factory | SD-Factory | 2.1.7 | - | Service Discovery Factory for managing dependencies | diff --git a/charts/traceability-foss/Chart.yaml b/charts/traceability-foss/Chart.yaml index 8bc8dff417..1e030722f4 100644 --- a/charts/traceability-foss/Chart.yaml +++ b/charts/traceability-foss/Chart.yaml @@ -42,11 +42,11 @@ dependencies: condition: pgadmin4.enabled - name: item-relationship-service repository: https://eclipse-tractusx.github.io/item-relationship-service - version: 7.2.1 + version: 7.3.1 condition: item-relationship-service.enabled - name: tractusx-connector repository: https://eclipse-tractusx.github.io/tractusx-edc - version: 0.7.1 + version: 0.7.3 condition: tractusx-connector.enabled - name: postgresql alias: edc-postgresql From 68844e0f7bfce8beebded08baf513f7ce78fd95f Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Wed, 17 Jul 2024 10:16:24 +0200 Subject: [PATCH 14/37] feature: #1221 #1193 update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39205da586..a51720c2ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ _**For better traceability add the corresponding GitHub issue number in each cha - #1191 Refactored contractAgreementId to be a list of elements. - #1188 prevent retry requests for notification actions to prevent duplicate error messages in history - #1025 fix overlapping table actions +- #1221 Updgrade EDC version to 0.7.3 +- #1196 Update IRS to 7.3.1 ## [12.0.0 - 05.07.2024] From c2e526c6b5475f93117ef8328336fc790e8b7ff2 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 17 Jul 2024 10:20:08 +0200 Subject: [PATCH 15/37] chore(irs):1105 Added globalAssetId to contract response. --- .../traceability/contracts/domain/model/Contract.java | 1 + .../repository/ContractViewRepositoryImpl.java | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java index 053f26f8ed..e41789d1a1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/Contract.java @@ -37,6 +37,7 @@ public class Contract { private String state; private String policy; private ContractType type; + private String globalAssetId; } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index 4b1df33741..400e39cb97 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -159,8 +159,13 @@ private List fetchEdcContractAgreements(List { try { + String globalAssetId = contractAgreementIds.stream() + .filter(id -> id.equals(contractAgreement.contractAgreementId())) + .findFirst() + .orElse(null); return Contract.builder() .contractId(contractAgreement.contractAgreementId()) + .globalAssetId(globalAssetId) .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) From e64ce83ad4fa8a6976d6de9dbc1a13153d7e36d1 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 17 Jul 2024 10:51:46 +0200 Subject: [PATCH 16/37] chore(irs):1105 Fixed policy of testdata. --- tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.14.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.14.json b/tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.14.json index 6385c0a5a1..2c8c028b95 100644 --- a/tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.14.json +++ b/tx-backend/testdata/CX_Testdata_MessagingTest_v0.0.14.json @@ -16,7 +16,7 @@ "odrl:and": [ { "@type": "Constraint", - "odrl:leftOperand": "cx-policy:FrameworkAgreement", + "odrl:leftOperand": "https://w3id.org/catenax/policy/FrameworkAgreement", "odrl:operator": { "@id": "odrl:eq" }, @@ -24,7 +24,7 @@ }, { "@type": "Constraint", - "odrl:leftOperand": "cx-policy:UsagePurpose", + "odrl:leftOperand": "https://w3id.org/catenax/policy/UsagePurpose", "odrl:operator": { "@id": "odrl:eq" }, From b439aea80a7f143ef2385d270b96df3e0292503c Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 17 Jul 2024 11:16:37 +0200 Subject: [PATCH 17/37] chore(irs):1105 Fixed mapper. --- .../infrastructure/model/ContractAgreementAsBuiltEntity.java | 2 +- .../infrastructure/model/ContractAgreementAsPlannedEntity.java | 2 +- .../infrastructure/model/ContractAgreementViewEntity.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java index f3ece4b2cc..8f6379e585 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsBuiltEntity.java @@ -54,7 +54,7 @@ public class ContractAgreementAsBuiltEntity extends ContractAgreementBaseEntity public static ContractAgreementAsBuiltEntity from(Contract contract, ContractType contractType) { return ContractAgreementAsBuiltEntity.builder() - .globalAssetId(contract.getContractId()) + .globalAssetId(contract.getGlobalAssetId()) .contractAgreementId(contract.getContractId()) .type(contractType) .created(Instant.now()) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java index c1aff5d6b1..d7d2a41408 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementAsPlannedEntity.java @@ -50,7 +50,7 @@ public class ContractAgreementAsPlannedEntity extends ContractAgreementBaseEntit public static ContractAgreementAsPlannedEntity from(Contract contract, ContractType contractType) { return ContractAgreementAsPlannedEntity.builder() - .globalAssetId(null) + .globalAssetId(contract.getGlobalAssetId()) .contractAgreementId(contract.getContractId()) .type(contractType) .created(Instant.now()) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java index 2a2e0fc732..d0cec3cded 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementViewEntity.java @@ -41,7 +41,7 @@ public class ContractAgreementViewEntity extends ContractAgreementBaseEntity { public static ContractAgreementViewEntity from(Contract contract, ContractType contractType) { return ContractAgreementViewEntity.builder() .contractAgreementId(contract.getContractId()) - .globalAssetId(null) + .globalAssetId(contract.getGlobalAssetId()) .type(contractType) .created(Instant.now()) .build(); From bb48d77fc352e23bef87fa0ff93273e42e8915b9 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 17 Jul 2024 11:26:48 +0200 Subject: [PATCH 18/37] chore(irs):1105 Fixed mapper. --- .../repository/ContractViewRepositoryImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index 400e39cb97..fdca7d8cad 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -35,6 +35,7 @@ import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementViewEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -159,9 +160,10 @@ private List fetchEdcContractAgreements(List { try { - String globalAssetId = contractAgreementIds.stream() - .filter(id -> id.equals(contractAgreement.contractAgreementId())) + String globalAssetId = contractAgreementEntities.stream() + .filter(contractAgreementViewEntity -> contractAgreementViewEntity.getContractAgreementId().equals(contractAgreement.contractAgreementId())) .findFirst() + .map(ContractAgreementBaseEntity::getGlobalAssetId) .orElse(null); return Contract.builder() .contractId(contractAgreement.contractAgreementId()) From 9c2de5efc66e343d964121dd1a5c576ecd2a3cf5 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 17 Jul 2024 11:38:34 +0200 Subject: [PATCH 19/37] chore(irs):1105 Fixed mapper. --- .../repository/ContractAsBuiltRepositoryImpl.java | 9 +++++++++ .../repository/ContractAsPlannedRepositoryImpl.java | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index dc425bb62d..0957c4a4b2 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -36,6 +36,7 @@ import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; @@ -139,8 +140,16 @@ private List fetchEdcContractAgreements(List { try { + + String globalAssetId = contractAgreementEntities.stream() + .filter(contractAgreementViewEntity -> contractAgreementViewEntity.getContractAgreementId().equals(contractAgreement.contractAgreementId())) + .findFirst() + .map(ContractAgreementBaseEntity::getGlobalAssetId) + .orElse(null); + return Contract.builder() .contractId(contractAgreement.contractAgreementId()) + .globalAssetId(globalAssetId) .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java index 1e399038a0..94a937c229 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java @@ -36,6 +36,7 @@ import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; @@ -138,7 +139,13 @@ private List fetchEdcContractAgreements(List { try { + String globalAssetId = contractAgreementEntities.stream() + .filter(contractAgreementViewEntity -> contractAgreementViewEntity.getContractAgreementId().equals(contractAgreement.contractAgreementId())) + .findFirst() + .map(ContractAgreementBaseEntity::getGlobalAssetId) + .orElse(null); return Contract.builder() + .globalAssetId(globalAssetId) .contractId(contractAgreement.contractAgreementId()) .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) From 6c1a46b0fa044b053a8b935c960cf922c82d69fb Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 17 Jul 2024 11:59:40 +0200 Subject: [PATCH 20/37] chore(irs):1105 Fixed mapper. --- .../repository/ContractViewRepositoryImpl.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index fdca7d8cad..62ce4d949a 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -124,6 +124,14 @@ public List findAll() { private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { + log.info("ContractAgreementEntities: {}", contractAgreementEntities); + + contractAgreementEntities.forEach(contractAgreementViewEntity -> { + log.info("Entity getContractAgreementId {}", contractAgreementViewEntity.getContractAgreementId()); + log.info("Entity getGlobalAssetId {}", contractAgreementViewEntity.getGlobalAssetId()); + log.info("Entity getId {}", contractAgreementViewEntity.getId()); + + }); List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementViewEntity::getContractAgreementId).filter(Objects::nonNull).toList(); log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); @@ -165,6 +173,8 @@ private List fetchEdcContractAgreements(List Date: Wed, 17 Jul 2024 12:12:27 +0200 Subject: [PATCH 21/37] chore(irs):1105 Fixed mapper. --- .../repository/ContractViewRepositoryImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index 62ce4d949a..1f80e8828b 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -158,7 +158,6 @@ private List fetchEdcContractAgreements(List log.info("{}: {}", key, value)); - Map contractNegotiations = contractAgreements.stream() .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) @@ -174,8 +173,7 @@ private List fetchEdcContractAgreements(List fetchEdcContractAgreements(List Date: Wed, 17 Jul 2024 13:45:49 +0200 Subject: [PATCH 22/37] chore(irs):1105 Fixed mapper. --- .../application/rest/ContractsController.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java index a8c5784476..9f7aeda87d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java @@ -18,6 +18,8 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.application.rest; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import contract.response.ContractResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -28,6 +30,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.common.model.PageResult; import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; import org.eclipse.tractusx.traceability.contracts.application.mapper.ContractResponseMapper; @@ -40,6 +43,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +@Slf4j @RestController @PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_SUPERVISOR')") @Tag(name = "Contracts") @@ -47,9 +51,11 @@ public class ContractsController { private final ContractService contractService; + private final ObjectMapper objectMapper; - public ContractsController(@Qualifier("contractViewServiceImpl") ContractService contractService) { + public ContractsController(@Qualifier("contractViewServiceImpl") ContractService contractService, ObjectMapper objectMapper) { this.contractService = contractService; + this.objectMapper = objectMapper; } @Operation(operationId = "contracts", @@ -96,6 +102,11 @@ public ContractsController(@Qualifier("contractViewServiceImpl") ContractService @PostMapping public PageResult getContracts(@Valid @RequestBody PageableFilterRequest pageableFilterRequest) { PageResult contracts = contractService.getContracts(pageableFilterRequest); + try { + log.info(objectMapper.writeValueAsString(contracts)); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } return ContractResponseMapper.from(contracts); } From 39613a76e8f36945a17121e2af3db7db7ade3d02 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 17 Jul 2024 14:45:02 +0200 Subject: [PATCH 23/37] chore(irs):1105 Fixed mapper. --- .../mapper/ContractResponseMapper.java | 1 + .../application/rest/ContractsController.java | 12 +-------- .../service/AbstractContractBaseService.java | 3 ++- .../ContractViewRepositoryImpl.java | 25 +------------------ .../contract/response/ContractResponse.java | 1 + 5 files changed, 6 insertions(+), 36 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/mapper/ContractResponseMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/mapper/ContractResponseMapper.java index 11b6366329..4a8c366fea 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/mapper/ContractResponseMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/mapper/ContractResponseMapper.java @@ -38,6 +38,7 @@ public static PageResult from(PageResult contractPag public static ContractResponse from(Contract contract) { return ContractResponse.builder() .contractId(contract.getContractId()) + .globalAssetId(contract.getGlobalAssetId()) .contractType(ContractTypeResponse.valueOf(contract.getType().name())) .state(contract.getState()) .counterpartyAddress(contract.getCounterpartyAddress()) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java index 9f7aeda87d..9e1666bd85 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java @@ -18,8 +18,6 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.application.rest; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import contract.response.ContractResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -29,7 +27,6 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.common.model.PageResult; import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; @@ -51,11 +48,9 @@ public class ContractsController { private final ContractService contractService; - private final ObjectMapper objectMapper; - public ContractsController(@Qualifier("contractViewServiceImpl") ContractService contractService, ObjectMapper objectMapper) { + public ContractsController(@Qualifier("contractViewServiceImpl") ContractService contractService) { this.contractService = contractService; - this.objectMapper = objectMapper; } @Operation(operationId = "contracts", @@ -102,11 +97,6 @@ public ContractsController(@Qualifier("contractViewServiceImpl") ContractService @PostMapping public PageResult getContracts(@Valid @RequestBody PageableFilterRequest pageableFilterRequest) { PageResult contracts = contractService.getContracts(pageableFilterRequest); - try { - log.info(objectMapper.writeValueAsString(contracts)); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } return ContractResponseMapper.from(contracts); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java index 30122f07d8..2b2276f8f2 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java @@ -45,7 +45,8 @@ public abstract class AbstractContractBaseService implements ContractService { public PageResult getContracts(PageableFilterRequest pageableFilterRequest) { Pageable pageable = OwnPageable.toPageable(pageableFilterRequest.getOwnPageable(), getContractFieldMapper()); SearchCriteria searchCriteria = pageableFilterRequest.getSearchCriteriaRequestParam().toSearchCriteria(getContractFieldMapper()); - return getContractRepository().getContractsByPageable(pageable, searchCriteria); + PageResult contractsByPageable = getContractRepository().getContractsByPageable(pageable, searchCriteria); + return contractsByPageable; } @Override diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index 1f80e8828b..19b985823a 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -71,7 +71,6 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit .toList(); Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); - logAllContractAgreementEntities(contractAgreementEntities); if (contractAgreementEntities.getContent().isEmpty()) { log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); @@ -90,18 +89,6 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit } - private void logAllContractAgreementEntities(Page contractAgreementEntities) { - - for (ContractAgreementViewEntity entity : contractAgreementEntities) { - try { - String jsonString = objectMapper.writeValueAsString(entity); - log.info("ContractAgreementViewEntity: {}", jsonString); - } catch (JsonProcessingException e) { - log.error("Error converting ContractAgreementViewEntity to JSON string", e); - } - } - } - @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { @@ -124,14 +111,7 @@ public List findAll() { private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { - log.info("ContractAgreementEntities: {}", contractAgreementEntities); - - contractAgreementEntities.forEach(contractAgreementViewEntity -> { - log.info("Entity getContractAgreementId {}", contractAgreementViewEntity.getContractAgreementId()); - log.info("Entity getGlobalAssetId {}", contractAgreementViewEntity.getGlobalAssetId()); - log.info("Entity getId {}", contractAgreementViewEntity.getId()); - }); List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementViewEntity::getContractAgreementId).filter(Objects::nonNull).toList(); log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); @@ -172,8 +152,7 @@ private List fetchEdcContractAgreements(List fetchEdcContractAgreements(List Date: Wed, 17 Jul 2024 16:44:41 +0200 Subject: [PATCH 24/37] chore(irs):1105 Refactored. --- .../application/rest/ContractsController.java | 10 +- .../application/service/ContractService.java | 1 - .../service/ContractServiceReadOnly.java | 27 ++++ .../domain/repository/ContractRepository.java | 10 -- .../ContractRepositoryReadOnly.java | 29 ++++ .../service/AbstractContractBaseService.java | 9 -- .../service/ContractViewServiceImpl.java | 21 +-- .../ContractAsBuiltRepositoryImpl.java | 136 +----------------- .../ContractAsPlannedRepositoryImpl.java | 134 ++--------------- .../ContractNotificationRepositoryImpl.java | 124 +--------------- .../ContractRepositoryImplBase.java | 123 ++++++++++++++++ .../ContractViewRepositoryImpl.java | 128 ++--------------- 12 files changed, 226 insertions(+), 526 deletions(-) create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractServiceReadOnly.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepositoryReadOnly.java create mode 100644 tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java index 9e1666bd85..7948189046 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/rest/ContractsController.java @@ -31,7 +31,7 @@ import org.eclipse.tractusx.traceability.common.model.PageResult; import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; import org.eclipse.tractusx.traceability.contracts.application.mapper.ContractResponseMapper; -import org.eclipse.tractusx.traceability.contracts.application.service.ContractService; +import org.eclipse.tractusx.traceability.contracts.application.service.ContractServiceReadOnly; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.security.access.prepost.PreAuthorize; @@ -47,10 +47,10 @@ @RequestMapping(path = "/contracts", produces = "application/json", consumes = "application/json") public class ContractsController { - private final ContractService contractService; + private final ContractServiceReadOnly contractServiceReadOnly; - public ContractsController(@Qualifier("contractViewServiceImpl") ContractService contractService) { - this.contractService = contractService; + public ContractsController(@Qualifier("contractViewServiceImpl") ContractServiceReadOnly contractServiceReadOnly) { + this.contractServiceReadOnly = contractServiceReadOnly; } @Operation(operationId = "contracts", @@ -96,7 +96,7 @@ public ContractsController(@Qualifier("contractViewServiceImpl") ContractService mediaType = "application/json", schema = @Schema(example = "{\"message\": \"Internal server error.\"}")))}) @PostMapping public PageResult getContracts(@Valid @RequestBody PageableFilterRequest pageableFilterRequest) { - PageResult contracts = contractService.getContracts(pageableFilterRequest); + PageResult contracts = contractServiceReadOnly.getContracts(pageableFilterRequest); return ContractResponseMapper.from(contracts); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractService.java index f7503e3ad9..1240960771 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractService.java @@ -28,7 +28,6 @@ import java.util.List; public interface ContractService { - PageResult getContracts(PageableFilterRequest pageableFilterRequest); void saveContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractServiceReadOnly.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractServiceReadOnly.java new file mode 100644 index 0000000000..6c142181cd --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/application/service/ContractServiceReadOnly.java @@ -0,0 +1,27 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.application.service; + +import org.eclipse.tractusx.traceability.common.model.PageResult; +import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; + +public interface ContractServiceReadOnly { + PageResult getContracts(PageableFilterRequest pageableFilterRequest); +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java index 73de3753af..d7c24c0534 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepository.java @@ -19,25 +19,15 @@ package org.eclipse.tractusx.traceability.contracts.domain.repository; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; -import org.eclipse.tractusx.traceability.common.model.PageResult; -import org.eclipse.tractusx.traceability.common.model.SearchCriteria; -import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; -import org.springframework.data.domain.Pageable; import java.util.List; public interface ContractRepository { - PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria); - void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException; void saveAll(List contractAgreements); - void save(ContractAgreement contractAgreement); - - List findAll(); } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepositoryReadOnly.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepositoryReadOnly.java new file mode 100644 index 0000000000..54ededcb3b --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/repository/ContractRepositoryReadOnly.java @@ -0,0 +1,29 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.domain.repository; + +import org.eclipse.tractusx.traceability.common.model.PageResult; +import org.eclipse.tractusx.traceability.common.model.SearchCriteria; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.springframework.data.domain.Pageable; + +public interface ContractRepositoryReadOnly { + + PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria); +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java index 2b2276f8f2..0ce47f35e8 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/AbstractContractBaseService.java @@ -40,15 +40,6 @@ public abstract class AbstractContractBaseService implements ContractService { protected abstract ContractFieldMapper getContractFieldMapper(); - - @Override - public PageResult getContracts(PageableFilterRequest pageableFilterRequest) { - Pageable pageable = OwnPageable.toPageable(pageableFilterRequest.getOwnPageable(), getContractFieldMapper()); - SearchCriteria searchCriteria = pageableFilterRequest.getSearchCriteriaRequestParam().toSearchCriteria(getContractFieldMapper()); - PageResult contractsByPageable = getContractRepository().getContractsByPageable(pageable, searchCriteria); - return contractsByPageable; - } - @Override public void saveContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { getContractRepository().saveAllContractAgreements(contractAgreementIds, contractType); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java index b3718decd3..2a545d85db 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java @@ -2,27 +2,30 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.eclipse.tractusx.traceability.common.model.PageResult; +import org.eclipse.tractusx.traceability.common.model.SearchCriteria; +import org.eclipse.tractusx.traceability.common.request.OwnPageable; +import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; import org.eclipse.tractusx.traceability.contracts.application.mapper.ContractFieldMapper; -import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.application.service.ContractServiceReadOnly; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; import org.eclipse.tractusx.traceability.contracts.infrastructure.repository.ContractViewRepositoryImpl; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; @Slf4j @Component @RequiredArgsConstructor -public class ContractViewServiceImpl extends AbstractContractBaseService { +public class ContractViewServiceImpl implements ContractServiceReadOnly { private final ContractViewRepositoryImpl contractViewRepository; private final ContractFieldMapper contractFieldMapper; @Override - protected ContractRepository getContractRepository() { - return contractViewRepository; - } - - @Override - protected ContractFieldMapper getContractFieldMapper() { - return contractFieldMapper; + public PageResult getContracts(PageableFilterRequest pageableFilterRequest) { + Pageable pageable = OwnPageable.toPageable(pageableFilterRequest.getOwnPageable(), contractFieldMapper); + SearchCriteria searchCriteria = pageableFilterRequest.getSearchCriteriaRequestParam().toSearchCriteria(contractFieldMapper); + return contractViewRepository.getContractsByPageable(pageable, searchCriteria); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index 0957c4a4b2..9f9f40cb6a 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -18,85 +18,37 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; +import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementNegotiationResponse; -import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; -import org.eclipse.tractusx.traceability.common.model.PageResult; -import org.eclipse.tractusx.traceability.common.model.SearchCriteria; -import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; -import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; -import java.time.Instant; -import java.time.OffsetDateTime; -import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; -import static org.apache.commons.collections4.ListUtils.emptyIfNull; - @Component -@RequiredArgsConstructor +@SuperBuilder @Slf4j -public class ContractAsBuiltRepositoryImpl implements ContractRepository { +public class ContractAsBuiltRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { private final EdcContractAgreementService edcContractAgreementService; private final JpaContractAgreementAsBuiltRepository contractAgreementRepository; - private final ObjectMapper objectMapper; - - @Override - public PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria) { - try { - List contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream() - .map(ContractAgreementAsBuiltSpecification::new) - .toList(); - Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); - Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); - - if (contractAgreementEntities.getContent().isEmpty()) { - log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); - return new PageResult<>(List.of(), 0, 0, 0, 0L); - } - - return new PageResult<>(fetchEdcContractAgreements(contractAgreementEntities.getContent()), - contractAgreementEntities.getPageable().getPageNumber(), - contractAgreementEntities.getTotalPages(), - contractAgreementEntities.getPageable().getPageSize(), - contractAgreementEntities.getTotalElements()); - - } catch (ContractAgreementException e) { - throw new ContractException(e); - } - - } @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { - List contractAgreementEntities = contractAgreementIds.stream() + List contractAgreementEntities = contractAgreementIds.stream() .map(contractAgreementId -> ContractAgreementAsBuiltEntity.builder() .contractAgreementId(contractAgreementId) .type(contractType) .build()) + .map(entity -> (ContractAgreementBaseEntity) entity) .collect(Collectors.toList()); List contracts = fetchEdcContractAgreements(contractAgreementEntities); @@ -109,83 +61,5 @@ public void saveAll(List contractAgreements) { contractAgreementRepository.saveAll(contractAgreements); } - @Override - public void save(ContractAgreement contractAgreement) { - contractAgreementRepository.save(ContractAgreementAsBuiltEntity.fromDomainToEntity(contractAgreement)); - } - - @Override - public List findAll() { - return contractAgreementRepository.findAll(); - } - - private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { - List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementAsBuiltEntity::getContractAgreementId).filter(Objects::nonNull).toList(); - - log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); - - List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); - - validateContractAgreements(contractAgreementIds, contractAgreements); - - Map contractTypes = contractAgreementEntities.stream() - .collect(Collectors.toMap(ContractAgreementAsBuiltEntity::getContractAgreementId, ContractAgreementAsBuiltEntity::getType)); - - Map contractNegotiations = contractAgreements.stream() - .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), - edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) - ).collect(Collectors.toMap(ImmutablePair::getLeft, ImmutablePair::getRight)); - - - return contractAgreements.stream().map(contractAgreement -> - { - try { - - String globalAssetId = contractAgreementEntities.stream() - .filter(contractAgreementViewEntity -> contractAgreementViewEntity.getContractAgreementId().equals(contractAgreement.contractAgreementId())) - .findFirst() - .map(ContractAgreementBaseEntity::getGlobalAssetId) - .orElse(null); - - return Contract.builder() - .contractId(contractAgreement.contractAgreementId()) - .globalAssetId(globalAssetId) - .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) - .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) - .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) - .policy(objectMapper.writeValueAsString(contractAgreement.policy())) - .type(contractTypes.get(contractAgreement.contractAgreementId())) - .build(); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - ).toList(); - } - - private void validateContractAgreements(List contractAgreementIds, List contractAgreements) { - if (contractAgreementIds == null || contractAgreements == null) { - log.warn("Either contractAgreementIds or contractAgreements is null."); - return; - } - - ArrayList givenList = new ArrayList<>(contractAgreementIds); - Collections.sort(givenList); - - List expectedList = contractAgreements.stream().map(EdcContractAgreementsResponse::contractAgreementId) - .filter(Objects::nonNull)// Ensure no null values are mapped - .sorted() - .toList(); - log.info("EDC responded with the following contractAgreementIds: " + expectedList); - - // Filter the givenList to find out which IDs are missing in the expectedList - List missingIds = givenList.stream() - .filter(id -> !expectedList.contains(id)) - .toList(); - - if (!missingIds.isEmpty()) { - log.warn("Cannot find the following contract agreement IDs in EDC: " + missingIds); - } - } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java index 94a937c229..f4d8feb751 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java @@ -18,76 +18,27 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; +import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementNegotiationResponse; -import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; -import org.eclipse.tractusx.traceability.common.model.PageResult; -import org.eclipse.tractusx.traceability.common.model.SearchCriteria; -import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; -import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; -import java.time.Instant; -import java.time.OffsetDateTime; -import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; -import static org.apache.commons.collections4.ListUtils.emptyIfNull; - @Component -@RequiredArgsConstructor +@SuperBuilder @Slf4j -public class ContractAsPlannedRepositoryImpl implements ContractRepository { +public class ContractAsPlannedRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { private final EdcContractAgreementService edcContractAgreementService; private final JpaContractAgreementAsPlannedRepository contractAgreementRepository; - private final ObjectMapper objectMapper; - - @Override - public PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria) { - try { - List contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream() - .map(ContractAgreementAsPlannedSpecification::new) - .toList(); - Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); - Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); - - if (contractAgreementEntities.getContent().isEmpty()) { - log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); - return new PageResult<>(List.of(), 0, 0, 0, 0L); - } - - return new PageResult<>(fetchEdcContractAgreements(contractAgreementEntities.getContent()), - contractAgreementEntities.getPageable().getPageNumber(), - contractAgreementEntities.getTotalPages(), - contractAgreementEntities.getPageable().getPageSize(), - contractAgreementEntities.getTotalElements()); - - } catch (ContractAgreementException e) { - throw new ContractException(e); - } - - } @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { @@ -99,7 +50,13 @@ public void saveAllContractAgreements(List contractAgreementIds, Contrac .build()) .collect(Collectors.toList()); - List contracts = fetchEdcContractAgreements(contractAgreementEntities); + List baseEntities = contractAgreementEntities + .stream() + .map(entity -> (ContractAgreementBaseEntity) entity) + .toList(); + + + List contracts = fetchEdcContractAgreements(baseEntities); List contractAgreementsUpdated = ContractAgreementAsPlannedEntity.fromList(contracts, contractType); contractAgreementRepository.saveAll(contractAgreementsUpdated); } @@ -109,75 +66,4 @@ public void saveAll(List contractAgreements) { contractAgreementRepository.saveAll(contractAgreements); } - @Override - public void save(ContractAgreement contractAgreement) { - contractAgreementRepository.save(ContractAgreementAsPlannedEntity.fromDomainToEntity(contractAgreement)); - } - - @Override - public List findAll() { - return List.of(); - } - - private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { - List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementAsPlannedEntity::getContractAgreementId).toList(); - log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); - - List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); - - validateContractAgreements(contractAgreementIds, contractAgreements); - - Map contractTypes = contractAgreementEntities.stream() - .collect(Collectors.toMap(ContractAgreementAsPlannedEntity::getContractAgreementId, ContractAgreementAsPlannedEntity::getType)); - - Map contractNegotiations = contractAgreements.stream() - .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), - edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) - ).collect(Collectors.toMap(ImmutablePair::getLeft, ImmutablePair::getRight)); - - - return contractAgreements.stream().map(contractAgreement -> - { - try { - String globalAssetId = contractAgreementEntities.stream() - .filter(contractAgreementViewEntity -> contractAgreementViewEntity.getContractAgreementId().equals(contractAgreement.contractAgreementId())) - .findFirst() - .map(ContractAgreementBaseEntity::getGlobalAssetId) - .orElse(null); - return Contract.builder() - .globalAssetId(globalAssetId) - .contractId(contractAgreement.contractAgreementId()) - .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) - .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) - .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) - .policy(objectMapper.writeValueAsString(contractAgreement.policy())) - .type(contractTypes.get(contractAgreement.contractAgreementId())) - .build(); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - ).toList(); - } - - private void validateContractAgreements(List contractAgreementIds, List contractAgreements) { - ArrayList givenList = new ArrayList<>(contractAgreementIds); - Collections.sort(givenList); - - List expectedList = contractAgreements.stream() - .map(EdcContractAgreementsResponse::contractAgreementId) - .sorted() - .toList(); - log.info("EDC responded with the following contractAgreementIds: " + expectedList); - - // Filter the givenList to find out which IDs are missing in the expectedList - List missingIds = givenList.stream() - .filter(id -> !expectedList.contains(id)) - .toList(); - - if (!missingIds.isEmpty()) { - log.warn("Cannot find the following contract agreement IDs in EDC: " + missingIds); - } - } - } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java index c7baa0abe7..e2ab15cf23 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java @@ -18,84 +18,37 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; +import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementNegotiationResponse; -import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; -import org.eclipse.tractusx.traceability.common.model.PageResult; -import org.eclipse.tractusx.traceability.common.model.SearchCriteria; -import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; -import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementNotificationEntity; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; -import java.time.Instant; -import java.time.OffsetDateTime; -import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; -import static org.apache.commons.collections4.ListUtils.emptyIfNull; - @Component -@RequiredArgsConstructor +@SuperBuilder @Slf4j -public class ContractNotificationRepositoryImpl implements ContractRepository { +public class ContractNotificationRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { private final EdcContractAgreementService edcContractAgreementService; private final JpaContractAgreementNotificationRepository contractAgreementRepository; - private final ObjectMapper objectMapper; - - @Override - public PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria) { - try { - List contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream() - .map(ContractAgreementNotificationSpecification::new) - .toList(); - Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); - Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); - - if (contractAgreementEntities.getContent().isEmpty()) { - log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); - return new PageResult<>(List.of(), 0, 0, 0, 0L); - } - - return new PageResult<>(fetchEdcContractAgreements(contractAgreementEntities.getContent()), - contractAgreementEntities.getPageable().getPageNumber(), - contractAgreementEntities.getTotalPages(), - contractAgreementEntities.getPageable().getPageSize(), - contractAgreementEntities.getTotalElements()); - - } catch (ContractAgreementException e) { - throw new ContractException(e); - } - - } @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { - List contractAgreementEntities = contractAgreementIds.stream() + List contractAgreementEntities = contractAgreementIds.stream() .map(contractAgreementId -> ContractAgreementNotificationEntity.builder() .contractAgreementId(contractAgreementId) .type(contractType) .build()) + .map(entity -> (ContractAgreementBaseEntity) entity) .collect(Collectors.toList()); List contracts = fetchEdcContractAgreements(contractAgreementEntities); @@ -108,69 +61,4 @@ public void saveAll(List contractAgreements contractAgreementRepository.saveAll(contractAgreements); } - @Override - public void save(ContractAgreement contractAgreement) { - contractAgreementRepository.save(ContractAgreementNotificationEntity.fromDomainToEntity(contractAgreement)); - } - - @Override - public List findAll() { - return List.of(); - } - - private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { - List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementNotificationEntity::getContractAgreementId).toList(); - log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); - - List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); - - validateContractAgreements(contractAgreementIds, contractAgreements); - - Map contractTypes = contractAgreementEntities.stream() - .collect(Collectors.toMap(ContractAgreementNotificationEntity::getContractAgreementId, ContractAgreementNotificationEntity::getType)); - - Map contractNegotiations = contractAgreements.stream() - .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), - edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) - ).collect(Collectors.toMap(ImmutablePair::getLeft, ImmutablePair::getRight)); - - - return contractAgreements.stream().map(contractAgreement -> - { - try { - return Contract.builder() - .contractId(contractAgreement.contractAgreementId()) - .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) - .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) - .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) - .policy(objectMapper.writeValueAsString(contractAgreement.policy())) - .type(contractTypes.get(contractAgreement.contractAgreementId())) - .build(); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - ).toList(); - } - - private void validateContractAgreements(List contractAgreementIds, List contractAgreements) { - ArrayList givenList = new ArrayList<>(contractAgreementIds); - Collections.sort(givenList); - - List expectedList = contractAgreements.stream() - .map(EdcContractAgreementsResponse::contractAgreementId) - .sorted() - .toList(); - log.info("EDC responded with the following contractAgreementIds: " + expectedList); - - // Filter the givenList to find out which IDs are missing in the expectedList - List missingIds = givenList.stream() - .filter(id -> !expectedList.contains(id)) - .toList(); - - if (!missingIds.isEmpty()) { - log.warn("Cannot find the following contract agreement IDs in EDC: " + missingIds); - } - } - } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java new file mode 100644 index 0000000000..fe8ef7209f --- /dev/null +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java @@ -0,0 +1,123 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.infrastructure.repository; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementNegotiationResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; +import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; +import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; +import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; +import org.springframework.stereotype.Component; + +import java.time.Instant; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +@Component +@RequiredArgsConstructor +@Slf4j +public class ContractRepositoryImplBase { + + private final EdcContractAgreementService edcContractAgreementService; + private final ObjectMapper objectMapper; + + + public List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { + List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementBaseEntity::getContractAgreementId).filter(Objects::nonNull).toList(); + + log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); + + List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); + + validateContractAgreements(contractAgreementIds, contractAgreements); + + Map contractTypes = contractAgreementEntities.stream() + .collect(Collectors.toMap(ContractAgreementBaseEntity::getContractAgreementId, ContractAgreementBaseEntity::getType)); + + Map contractNegotiations = contractAgreements.stream() + .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), + edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) + ).collect(Collectors.toMap(ImmutablePair::getLeft, ImmutablePair::getRight)); + + + return contractAgreements.stream().map(contractAgreement -> + { + try { + + String globalAssetId = contractAgreementEntities.stream() + .filter(contractAgreementViewEntity -> contractAgreementViewEntity.getContractAgreementId().equals(contractAgreement.contractAgreementId())) + .findFirst() + .map(ContractAgreementBaseEntity::getGlobalAssetId) + .orElse(null); + + return Contract.builder() + .contractId(contractAgreement.contractAgreementId()) + .globalAssetId(globalAssetId) + .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) + .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) + .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) + .policy(objectMapper.writeValueAsString(contractAgreement.policy())) + .type(contractTypes.get(contractAgreement.contractAgreementId())) + .build(); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + ).toList(); + } + + private void validateContractAgreements(List contractAgreementIds, List contractAgreements) { + if (contractAgreementIds == null || contractAgreements == null) { + log.warn("Either contractAgreementIds or contractAgreements is null."); + return; + } + + ArrayList givenList = new ArrayList<>(contractAgreementIds); + Collections.sort(givenList); + + List expectedList = contractAgreements.stream().map(EdcContractAgreementsResponse::contractAgreementId) + .filter(Objects::nonNull)// Ensure no null values are mapped + .sorted() + .toList(); + log.info("EDC responded with the following contractAgreementIds: " + expectedList); + + // Filter the givenList to find out which IDs are missing in the expectedList + List missingIds = givenList.stream() + .filter(id -> !expectedList.contains(id)) + .toList(); + + if (!missingIds.isEmpty()) { + log.warn("Cannot find the following contract agreement IDs in EDC: " + missingIds); + } + } + +} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index 19b985823a..2adab0dfd2 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -18,13 +18,9 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.RequiredArgsConstructor; +import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementNegotiationResponse; -import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementsResponse; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; import org.eclipse.tractusx.traceability.common.model.PageResult; @@ -32,9 +28,7 @@ import org.eclipse.tractusx.traceability.common.repository.BaseSpecification; import org.eclipse.tractusx.traceability.contracts.domain.exception.ContractException; import org.eclipse.tractusx.traceability.contracts.domain.model.Contract; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; -import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepository; +import org.eclipse.tractusx.traceability.contracts.domain.repository.ContractRepositoryReadOnly; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementBaseEntity; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementViewEntity; import org.springframework.data.domain.Page; @@ -42,22 +36,14 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; -import java.time.Instant; -import java.time.OffsetDateTime; -import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; import static org.apache.commons.collections4.ListUtils.emptyIfNull; @Component -@RequiredArgsConstructor +@SuperBuilder @Slf4j -public class ContractViewRepositoryImpl implements ContractRepository { +public class ContractViewRepositoryImpl extends ContractRepositoryImplBase implements ContractRepositoryReadOnly { private final EdcContractAgreementService edcContractAgreementService; private final JpaContractAgreementViewRepository contractAgreementRepository; @@ -76,8 +62,12 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit log.warn("Cannot find contract agreement Ids for asset ids in searchCriteria: " + searchCriteria.getSearchCriteriaFilterList()); return new PageResult<>(List.of(), 0, 0, 0, 0L); } + List baseEntities = contractAgreementEntities.getContent() + .stream() + .map(entity -> (ContractAgreementBaseEntity) entity) + .toList(); - return new PageResult<>(fetchEdcContractAgreements(contractAgreementEntities.getContent()), + return new PageResult<>(fetchEdcContractAgreements(baseEntities), contractAgreementEntities.getPageable().getPageNumber(), contractAgreementEntities.getTotalPages(), contractAgreementEntities.getPageable().getPageSize(), @@ -88,104 +78,4 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit } } - - @Override - public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { - - } - - @Override - public void saveAll(List contractAgreements) { - - } - - @Override - public void save(ContractAgreement contractAgreement) { - - } - - @Override - public List findAll() { - return List.of(); - } - - - private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { - - List contractAgreementIds = contractAgreementEntities.stream().filter(Objects::nonNull).map(ContractAgreementViewEntity::getContractAgreementId).filter(Objects::nonNull).toList(); - log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); - - List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); - - validateContractAgreements(contractAgreementIds, contractAgreements); - - - Map contractTypes = contractAgreementEntities.stream() - .collect(Collectors.toMap( - ContractAgreementViewEntity::getContractAgreementId, - ContractAgreementViewEntity::getType, - (existing, replacement) -> { - // Define your merging logic here - // For example, keep the existing value - return existing; - - // Alternatively, you could choose to log the conflict or merge in another way - // e.g., return some merged version of existing and replacement - } - )); - - // Print the result - contractTypes.forEach((key, value) -> log.info("{}: {}", key, value)); - - - Map contractNegotiations = contractAgreements.stream() - .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), - edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) - ).collect(Collectors.toMap(ImmutablePair::getLeft, ImmutablePair::getRight)); - - - return contractAgreements.stream().map(contractAgreement -> - { - try { - String globalAssetId = contractAgreementEntities.stream() - .filter(contractAgreementViewEntity -> contractAgreementViewEntity.getContractAgreementId().equals(contractAgreement.contractAgreementId())) - .findFirst() - .map(ContractAgreementBaseEntity::getGlobalAssetId) - .orElse(null); - return Contract.builder() - .contractId(contractAgreement.contractAgreementId()) - .globalAssetId(globalAssetId) - .counterpartyAddress(contractNegotiations.get(contractAgreement.contractAgreementId()).counterPartyAddress()) - .creationDate(OffsetDateTime.ofInstant(Instant.ofEpochSecond(contractAgreement.contractSigningDate()), ZoneId.systemDefault())) - .state(contractNegotiations.get(contractAgreement.contractAgreementId()).state()) - .policy(objectMapper.writeValueAsString(contractAgreement.policy())) - .type(contractTypes.get(contractAgreement.contractAgreementId())) - .build(); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - } - ).toList(); - } - - private void validateContractAgreements(List contractAgreementIds, List contractAgreements) { - ArrayList givenList = new ArrayList<>(contractAgreementIds); - Collections.sort(givenList); - - List expectedList = contractAgreements.stream() - .map(EdcContractAgreementsResponse::contractAgreementId) - .sorted() - .toList(); - log.info("EDC responded with the following contractAgreementIds: " + expectedList); - - // Filter the givenList to find out which IDs are missing in the expectedList - List missingIds = givenList.stream() - .filter(id -> !expectedList.contains(id)) - .toList(); - - if (!missingIds.isEmpty()) { - log.warn("Cannot find the following contract agreement IDs in EDC: " + missingIds); - } - } - } From 47efd8d521bfc13f8d6f599282392d4b2a0c929f Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 17 Jul 2024 17:01:58 +0200 Subject: [PATCH 25/37] chore(irs):1105 Refactored. --- .../repository/ContractAsBuiltRepositoryImpl.java | 9 ++++++--- .../repository/ContractAsPlannedRepositoryImpl.java | 9 ++++++--- .../repository/ContractNotificationRepositoryImpl.java | 8 ++++++-- .../repository/ContractRepositoryImplBase.java | 3 ++- .../repository/ContractViewRepositoryImpl.java | 9 +++++---- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index 9f9f40cb6a..55e5959dfc 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -18,7 +18,7 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; -import lombok.experimental.SuperBuilder; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; @@ -33,13 +33,16 @@ import java.util.stream.Collectors; @Component -@SuperBuilder @Slf4j public class ContractAsBuiltRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { - private final EdcContractAgreementService edcContractAgreementService; private final JpaContractAgreementAsBuiltRepository contractAgreementRepository; + public ContractAsBuiltRepositoryImpl(EdcContractAgreementService edcContractAgreementService, ObjectMapper objectMapper, JpaContractAgreementAsBuiltRepository contractAgreementRepository) { + super(edcContractAgreementService, objectMapper); + this.contractAgreementRepository = contractAgreementRepository; + } + @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java index f4d8feb751..c58eeda18d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java @@ -18,7 +18,7 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; -import lombok.experimental.SuperBuilder; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; @@ -33,13 +33,16 @@ import java.util.stream.Collectors; @Component -@SuperBuilder @Slf4j public class ContractAsPlannedRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { - private final EdcContractAgreementService edcContractAgreementService; private final JpaContractAgreementAsPlannedRepository contractAgreementRepository; + public ContractAsPlannedRepositoryImpl(EdcContractAgreementService edcContractAgreementService, ObjectMapper objectMapper, JpaContractAgreementAsPlannedRepository contractAgreementRepository) { + super(edcContractAgreementService, objectMapper); + this.contractAgreementRepository = contractAgreementRepository; + } + @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java index e2ab15cf23..708c957903 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java @@ -18,6 +18,7 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; @@ -33,13 +34,16 @@ import java.util.stream.Collectors; @Component -@SuperBuilder @Slf4j public class ContractNotificationRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { - private final EdcContractAgreementService edcContractAgreementService; private final JpaContractAgreementNotificationRepository contractAgreementRepository; + public ContractNotificationRepositoryImpl(EdcContractAgreementService edcContractAgreementService, ObjectMapper objectMapper, EdcContractAgreementService edcContractAgreementService1, JpaContractAgreementNotificationRepository contractAgreementRepository) { + super(edcContractAgreementService, objectMapper); + this.contractAgreementRepository = contractAgreementRepository; + } + @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java index fe8ef7209f..33da75029e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.ImmutablePair; @@ -43,7 +44,7 @@ import java.util.stream.Collectors; @Component -@RequiredArgsConstructor +@AllArgsConstructor @Slf4j public class ContractRepositoryImplBase { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index 2adab0dfd2..c9b086a223 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -19,7 +19,6 @@ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; @@ -41,13 +40,15 @@ import static org.apache.commons.collections4.ListUtils.emptyIfNull; @Component -@SuperBuilder @Slf4j public class ContractViewRepositoryImpl extends ContractRepositoryImplBase implements ContractRepositoryReadOnly { - private final EdcContractAgreementService edcContractAgreementService; private final JpaContractAgreementViewRepository contractAgreementRepository; - private final ObjectMapper objectMapper; + + public ContractViewRepositoryImpl(EdcContractAgreementService edcContractAgreementService, ObjectMapper objectMapper, EdcContractAgreementService edcContractAgreementService1, JpaContractAgreementViewRepository contractAgreementRepository, ObjectMapper objectMapper1) { + super(edcContractAgreementService, objectMapper); + this.contractAgreementRepository = contractAgreementRepository; + } @Override public PageResult getContractsByPageable(Pageable pageable, SearchCriteria searchCriteria) { From 89e0474dcbb2042868878cda9e6d9bff27162783 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 08:22:31 +0200 Subject: [PATCH 26/37] chore(irs):1105 Refactored. --- .../repository/ContractAsBuiltRepositoryImpl.java | 2 ++ .../repository/ContractAsPlannedRepositoryImpl.java | 2 ++ .../repository/ContractNotificationRepositoryImpl.java | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index 55e5959dfc..e5fc6590d2 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -19,6 +19,7 @@ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.transaction.Transactional; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; @@ -32,6 +33,7 @@ import java.util.List; import java.util.stream.Collectors; +@Transactional @Component @Slf4j public class ContractAsBuiltRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java index c58eeda18d..168a9dded5 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java @@ -19,6 +19,7 @@ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.transaction.Transactional; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; @@ -32,6 +33,7 @@ import java.util.List; import java.util.stream.Collectors; +@Transactional @Component @Slf4j public class ContractAsPlannedRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java index 708c957903..e00092cccb 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java @@ -19,7 +19,7 @@ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.experimental.SuperBuilder; +import jakarta.transaction.Transactional; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; @@ -33,6 +33,7 @@ import java.util.List; import java.util.stream.Collectors; +@Transactional @Component @Slf4j public class ContractNotificationRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { From 560cd33e140d46fdb62d3d85fb8e71b7e8a1d57b Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 08:31:06 +0200 Subject: [PATCH 27/37] chore(irs):1105 Refactored. --- .../infrastructure/repository/ContractRepositoryImplBase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java index 33da75029e..4d504cbe5c 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.transaction.Transactional; import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -46,6 +47,7 @@ @Component @AllArgsConstructor @Slf4j +@Transactional public class ContractRepositoryImplBase { private final EdcContractAgreementService edcContractAgreementService; From 48162692cdd21e2bec9b06b4b5b6558643fdd78a Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 08:41:09 +0200 Subject: [PATCH 28/37] chore(contracts):1105 Refactored. --- .../ContractAsBuiltRepositoryImpl.java | 4 +- .../common/support/AssetsSupport.java | 68 ------------------- 2 files changed, 2 insertions(+), 70 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index e5fc6590d2..f0b1c396f0 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -53,8 +53,8 @@ public void saveAllContractAgreements(List contractAgreementIds, Contrac .contractAgreementId(contractAgreementId) .type(contractType) .build()) - .map(entity -> (ContractAgreementBaseEntity) entity) - .collect(Collectors.toList()); + .map(ContractAgreementBaseEntity.class::cast) + .toList(); List contracts = fetchEdcContractAgreements(contractAgreementEntities); List contractAgreementsUpdated = ContractAgreementAsBuiltEntity.fromList(contracts, contractType); diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java index 92d88559d4..0a67761201 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/common/support/AssetsSupport.java @@ -21,20 +21,10 @@ import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; import org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model.AssetAsBuiltEntity; -import org.eclipse.tractusx.traceability.assets.infrastructure.asplanned.model.AssetAsPlannedEntity; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsBuiltEntity; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementAsPlannedEntity; -import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.time.Instant; -import java.util.ArrayList; import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; @Slf4j @Component @@ -62,31 +52,6 @@ public void defaultAssetsStored() { bpnSupport.providesBpdmLookup(); List assetBases = assetRepositoryProvider.testdataProvider().readAndConvertAssetsForTests(); assetRepositoryProvider.assetAsBuiltRepository().saveAll(assetBases); - -/* List asBuiltEntities = extractContractAgreementAsBuilt(); - List asPlannedEntities = extractContractAgreementAsPlanned(); - contractRepositoryProvider.contractAsBuiltRepository.saveAll(asBuiltEntities); - contractRepositoryProvider.contractAsPlannedRepository.saveAll(asPlannedEntities);*/ - } - - private @NotNull List extractContractAgreementAsBuilt() { - return assetRepositoryProvider.assetAsBuiltRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementAsBuiltEntity - .builder() - .type(ContractType.ASSET_AS_PLANNED) - .contractAgreementId(asBuiltAsset.getLatestContractAgreementId()) - .globalAssetId(asBuiltAsset.getId()) - .created(Instant.now()) - .build()).collect(Collectors.toUnmodifiableList()); - } - - private @NotNull List extractContractAgreementAsPlanned() { - return assetRepositoryProvider.assetAsPlannedRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementAsPlannedEntity - .builder() - .type(ContractType.ASSET_AS_PLANNED) - .contractAgreementId(asBuiltAsset.getLatestContractAgreementId()) - .globalAssetId(asBuiltAsset.getId()) - .created(Instant.now()) - .build()).collect(Collectors.toUnmodifiableList()); } @@ -99,42 +64,9 @@ public void tractionBatteryCodeAssetsStored() { assetRepositoryProvider.assetAsBuiltRepository().saveAll(assetRepositoryProvider.testdataProvider().readAndConvertTractionBatteryCodeAssetsForTests()); } - private void enrichContractAgreementsAsBuilt(List assets) { - - assets.forEach(assetBase -> { - AssetBase assetById = null; - try { - assetById = assetRepositoryProvider.assetAsBuiltRepository().getAssetById(assetBase.getId()); - } catch (Exception e) { - } - if (assetById != null) { - List contractAgreements = new ArrayList<>(assetById.getContractAgreements()); - contractAgreements.add(ContractAgreement.toDomain(assetBase.getLatestContractAgreementId(), assetBase.getId(), ContractType.ASSET_AS_BUILT)); - assetBase.setContractAgreements(contractAgreements); - } - }); - } - - private void enrichContractAgreementsAsPlanned(List assets) { - - assets.forEach(assetBase -> { - AssetBase assetById = null; - try { - assetById = assetRepositoryProvider.assetAsPlannedRepository().getAssetById(assetBase.getId()); - } catch (Exception e) { - } - if (assetById != null) { - List contractAgreements = new ArrayList<>(assetById.getContractAgreements()); - contractAgreements.add(ContractAgreement.toDomain(assetBase.getLatestContractAgreementId(), assetBase.getId(), ContractType.ASSET_AS_PLANNED)); - assetBase.setContractAgreements(contractAgreements); - } - }); - } - public void defaultAssetsAsPlannedStored() { bpnSupport.providesBpdmLookup(); List assetBases = assetRepositoryProvider.testdataProvider().readAndConvertAssetsAsPlannedForTests(); - enrichContractAgreementsAsPlanned(assetBases); assetRepositoryProvider.assetAsPlannedRepository().saveAll(assetBases); } From 6ab83f11b3d1bd3672adbdd51ca2a5a9d468c777 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 09:03:55 +0200 Subject: [PATCH 29/37] chore(contracts):1105 Refactored. --- .../base/irs/JobRepositoryImpl.java | 19 +++++++++++++++++-- .../factory/IrsResponseAssetMapper.java | 4 ---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java index 36c61ae9f3..c2f263cdd1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java @@ -21,6 +21,8 @@ package org.eclipse.tractusx.traceability.assets.infrastructure.base.irs; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.traceability.assets.domain.base.JobRepository; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; @@ -59,6 +61,7 @@ public class JobRepositoryImpl implements JobRepository { private final IrsResponseAssetMapper assetMapperFactory; private final JobClient jobClient; + private final ObjectMapper objectMapper; public JobRepositoryImpl( JobClient jobClient, @@ -67,12 +70,13 @@ public JobRepositoryImpl( AssetCallbackRepository assetAsBuiltCallbackRepository, @Qualifier("assetAsPlannedRepositoryImpl") AssetCallbackRepository assetAsPlannedCallbackRepository, - IrsResponseAssetMapper assetMapperFactory) { + IrsResponseAssetMapper assetMapperFactory, ObjectMapper objectMapper) { this.traceabilityProperties = traceabilityProperties; this.assetAsBuiltCallbackRepository = assetAsBuiltCallbackRepository; this.assetAsPlannedCallbackRepository = assetAsPlannedCallbackRepository; this.jobClient = jobClient; this.assetMapperFactory = assetMapperFactory; + this.objectMapper = objectMapper; } @Override @@ -121,13 +125,24 @@ void saveOrUpdateAssets(AssetCallbackRepository repository, AssetBase asset) { } } - private static void enrichAssetBaseByContractAgreements(AssetCallbackRepository repository, AssetBase asset) { + private void enrichAssetBaseByContractAgreements(AssetCallbackRepository repository, AssetBase asset) { Optional byId = repository.findById(asset.getId()); List agreementsToAdd = new ArrayList<>(); byId.ifPresent(assetBase -> agreementsToAdd.addAll(assetBase.getContractAgreements())); + try { + log.info("Found the following existing contractAgreements {}", this.objectMapper.writeValueAsString(agreementsToAdd)); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + ContractType contractType = asset.getSemanticDataModel().isAsBuilt() ? ContractType.ASSET_AS_BUILT : ContractType.ASSET_AS_PLANNED; agreementsToAdd.add(ContractAgreement.toDomain(asset.getLatestContractAgreementId(), asset.getId(), contractType)); asset.setContractAgreements(agreementsToAdd); + try { + log.info("Found the following NEW contractAgreements {}", this.objectMapper.writeValueAsString(agreementsToAdd)); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } } public static boolean jobCompleted(JobStatus jobStatus) { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/IrsResponseAssetMapper.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/IrsResponseAssetMapper.java index e02f5004a9..88aeb82d17 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/IrsResponseAssetMapper.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/model/response/factory/IrsResponseAssetMapper.java @@ -21,8 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.irs.component.enums.BomLifecycle; -import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; import org.eclipse.tractusx.traceability.assets.domain.base.model.AssetBase; import org.eclipse.tractusx.traceability.assets.domain.base.model.Descriptions; import org.eclipse.tractusx.traceability.assets.domain.base.model.aspect.DetailAspectModel; @@ -33,8 +31,6 @@ import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.mapping.submodel.MapperHelper; import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.mapping.submodel.SubmodelMapper; import org.eclipse.tractusx.traceability.bpn.domain.service.BpnService; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractAgreement; -import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; From 231226269f0ddf887d70391a265f042c49e0fb96 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 10:06:05 +0200 Subject: [PATCH 30/37] chore(contracts):1105 Refactored. --- .../repository/ContractRepositoryImplBase.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java index 4d504cbe5c..05792a6ae2 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java @@ -64,7 +64,11 @@ public List fetchEdcContractAgreements(List contractTypes = contractAgreementEntities.stream() - .collect(Collectors.toMap(ContractAgreementBaseEntity::getContractAgreementId, ContractAgreementBaseEntity::getType)); + .collect(Collectors.toMap( + ContractAgreementBaseEntity::getContractAgreementId, + ContractAgreementBaseEntity::getType, + (existing, replacement) -> existing // retain existing value if duplicate key is encountered + )); Map contractNegotiations = contractAgreements.stream() .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), From 8b0131458e5410cd99b0aa44caf16520fe402be9 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 10:30:29 +0200 Subject: [PATCH 31/37] chore(contracts):1105 Refactored. --- .../repository/ContractAsBuiltRepositoryImpl.java | 3 --- .../repository/ContractAsPlannedRepositoryImpl.java | 1 - .../repository/ContractNotificationRepositoryImpl.java | 2 -- .../infrastructure/repository/ContractRepositoryImplBase.java | 3 --- 4 files changed, 9 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java index f0b1c396f0..e0f6eb109e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsBuiltRepositoryImpl.java @@ -19,7 +19,6 @@ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; import com.fasterxml.jackson.databind.ObjectMapper; -import jakarta.transaction.Transactional; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; @@ -31,9 +30,7 @@ import org.springframework.stereotype.Component; import java.util.List; -import java.util.stream.Collectors; -@Transactional @Component @Slf4j public class ContractAsBuiltRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java index 168a9dded5..ca203ec57a 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java @@ -33,7 +33,6 @@ import java.util.List; import java.util.stream.Collectors; -@Transactional @Component @Slf4j public class ContractAsPlannedRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java index e00092cccb..1772160967 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java @@ -19,7 +19,6 @@ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; import com.fasterxml.jackson.databind.ObjectMapper; -import jakarta.transaction.Transactional; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService; @@ -33,7 +32,6 @@ import java.util.List; import java.util.stream.Collectors; -@Transactional @Component @Slf4j public class ContractNotificationRepositoryImpl extends ContractRepositoryImplBase implements ContractRepository { diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java index 05792a6ae2..86c97cd604 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java @@ -20,9 +20,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import jakarta.transaction.Transactional; import lombok.AllArgsConstructor; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.tuple.ImmutablePair; import org.eclipse.tractusx.irs.edc.client.contract.model.EdcContractAgreementNegotiationResponse; @@ -47,7 +45,6 @@ @Component @AllArgsConstructor @Slf4j -@Transactional public class ContractRepositoryImplBase { private final EdcContractAgreementService edcContractAgreementService; From 7fd8f0eb5c4ed56c62d4d94defd8c09616b95264 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 11:18:32 +0200 Subject: [PATCH 32/37] chore(contracts):1105 Refactored. --- .github/workflows/.trivyignore | 4 ++-- .../infrastructure/repository/ContractRepositoryImplBase.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/.trivyignore b/.github/workflows/.trivyignore index c06bb263ca..fa76656331 100644 --- a/.github/workflows/.trivyignore +++ b/.github/workflows/.trivyignore @@ -1,5 +1,5 @@ -# ref https://github.com/catenax-ng/product-traceability-foss-backend/security/code-scanning/1419 +# ref https://github.com/eclipse-tractusx/traceability-foss-backend/security/code-scanning/1419 CVE-2022-25857 -# ref https://github.com/catenax-ng/tx-traceability-foss/security/code-scanning/6879 +# ref https://github.com/eclipse-tractusx/traceability-foss/security/code-scanning/6879 # this is acceptable due to custom environment variable injection script which is executed upon FE container startup AVD-KSV-0014 diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java index 86c97cd604..5129117b3a 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractRepositoryImplBase.java @@ -78,7 +78,7 @@ public List fetchEdcContractAgreements(List contractAgreementViewEntity.getContractAgreementId().equals(contractAgreement.contractAgreementId())) + .filter(contractAgreementViewEntity -> contractAgreementViewEntity.getContractAgreementId() == null || contractAgreement.contractAgreementId() == null || contractAgreementViewEntity.getContractAgreementId().equals(contractAgreement.contractAgreementId())) .findFirst() .map(ContractAgreementBaseEntity::getGlobalAssetId) .orElse(null); From 87ef3925c7a593bf54a6978c494e2e1148f48e46 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 11:27:05 +0200 Subject: [PATCH 33/37] chore(contracts):1105 Refactored. --- .../repository/ContractNotificationRepositoryImpl.java | 5 ++--- .../repository/ContractViewRepositoryImpl.java | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java index 1772160967..1c7e92b3d1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractNotificationRepositoryImpl.java @@ -30,7 +30,6 @@ import org.springframework.stereotype.Component; import java.util.List; -import java.util.stream.Collectors; @Component @Slf4j @@ -51,8 +50,8 @@ public void saveAllContractAgreements(List contractAgreementIds, Contrac .contractAgreementId(contractAgreementId) .type(contractType) .build()) - .map(entity -> (ContractAgreementBaseEntity) entity) - .collect(Collectors.toList()); + .map(ContractAgreementBaseEntity.class::cast) + .toList(); List contracts = fetchEdcContractAgreements(contractAgreementEntities); List contractAgreementsUpdated = ContractAgreementNotificationEntity.fromList(contracts, contractType); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java index c9b086a223..36b13de488 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractViewRepositoryImpl.java @@ -45,7 +45,9 @@ public class ContractViewRepositoryImpl extends ContractRepositoryImplBase imple private final JpaContractAgreementViewRepository contractAgreementRepository; - public ContractViewRepositoryImpl(EdcContractAgreementService edcContractAgreementService, ObjectMapper objectMapper, EdcContractAgreementService edcContractAgreementService1, JpaContractAgreementViewRepository contractAgreementRepository, ObjectMapper objectMapper1) { + public ContractViewRepositoryImpl(EdcContractAgreementService edcContractAgreementService, + ObjectMapper objectMapper, + JpaContractAgreementViewRepository contractAgreementRepository) { super(edcContractAgreementService, objectMapper); this.contractAgreementRepository = contractAgreementRepository; } From bc149b9c84a98edd9e080a75d908fc8d34bd9db7 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 14:36:04 +0200 Subject: [PATCH 34/37] chore(contracts):1105 Merged main. --- .../common/config/ApplicationStartupConfig.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java index 096a3bc95f..e8f244df41 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/ApplicationStartupConfig.java @@ -49,21 +49,12 @@ @Profile(NOT_INTEGRATION_TESTS) public class ApplicationStartupConfig { private final PolicyRepository policyRepository; - private final AssetBaseService asPlannedService; - private final AssetBaseService asBuiltService; - private final ContractService contractService; @Autowired public ApplicationStartupConfig(PolicyRepository policyRepository, - @Qualifier("assetAsBuiltServiceImpl") AssetBaseService asBuiltService, - @Qualifier("assetAsPlannedServiceImpl") AssetBaseService asPlannedService, - EdcNotificationContractService edcNotificationContractService, - ContractService contractService) { + EdcNotificationContractService edcNotificationContractService) { this.policyRepository = policyRepository; - this.asPlannedService = asPlannedService; - this.asBuiltService = asBuiltService; this.edcNotificationContractService = edcNotificationContractService; - this.contractService = contractService; } private final EdcNotificationContractService edcNotificationContractService; From dd92f339f846a3d8d52787c6328ebf8d9356af6e Mon Sep 17 00:00:00 2001 From: Maximilian Wesener <124587888+ds-mwesener@users.noreply.github.com> Date: Thu, 18 Jul 2024 14:40:36 +0200 Subject: [PATCH 35/37] Update tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsBuiltSpecification.java Co-authored-by: Lucas Capellino <137265091+ds-lcapellino@users.noreply.github.com> --- .../repository/ContractAgreementAsBuiltSpecification.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsBuiltSpecification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsBuiltSpecification.java index 774eab8e50..35c57f5ded 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsBuiltSpecification.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsBuiltSpecification.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. From 55bfde9f94e9f78ac998546819e2507d10981acf Mon Sep 17 00:00:00 2001 From: Maximilian Wesener <124587888+ds-mwesener@users.noreply.github.com> Date: Thu, 18 Jul 2024 14:42:04 +0200 Subject: [PATCH 36/37] Apply suggestions from code review Co-authored-by: Lucas Capellino <137265091+ds-lcapellino@users.noreply.github.com> --- .../repository/ContractAgreementAsPlannedSpecification.java | 2 +- .../repository/ContractAgreementNotificationSpecification.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsPlannedSpecification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsPlannedSpecification.java index 6e711dcc15..dfaca1280b 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsPlannedSpecification.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementAsPlannedSpecification.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementNotificationSpecification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementNotificationSpecification.java index b46276615a..1f031ad17e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementNotificationSpecification.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAgreementNotificationSpecification.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2023 Contributors to the Eclipse Foundation + * Copyright (c) 2024 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. From bc9e9177b4963d3ea95dd94856d7ab1d0d3df5e2 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Thu, 18 Jul 2024 14:44:21 +0200 Subject: [PATCH 37/37] chore(contracts):1105 Code Review --- .../base/irs/JobRepositoryImpl.java | 1 - .../service/ContractAsBuiltServiceImpl.java | 18 ++++++++++++++++++ .../service/ContractAsPlannedServiceImpl.java | 18 ++++++++++++++++++ .../ContractNotificationServiceImpl.java | 18 ++++++++++++++++++ .../service/ContractViewServiceImpl.java | 18 ++++++++++++++++++ .../ContractAsPlannedRepositoryImpl.java | 1 - 6 files changed, 72 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java index c2f263cdd1..fbbaf2248d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java @@ -120,7 +120,6 @@ void saveOrUpdateAssets(AssetCallbackRepository repository, AssetBase asset) { } catch (DataIntegrityViolationException ex) { //retry save in case of ERROR: duplicate key value violates unique constraint "asset_pkey" log.info("Asset with id {} already exists in the database. The record will be updated instead.", asset.getId()); - enrichAssetBaseByContractAgreements(repository, asset); repository.save(asset); } } diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsBuiltServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsBuiltServiceImpl.java index 27e15ce2b4..5204a31ac9 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsBuiltServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsBuiltServiceImpl.java @@ -1,3 +1,21 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.domain.service; import lombok.RequiredArgsConstructor; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsPlannedServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsPlannedServiceImpl.java index 4f3cfb9832..64254316bc 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsPlannedServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractAsPlannedServiceImpl.java @@ -1,3 +1,21 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.domain.service; import lombok.RequiredArgsConstructor; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractNotificationServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractNotificationServiceImpl.java index 00fe3b51fc..127d323c84 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractNotificationServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractNotificationServiceImpl.java @@ -1,3 +1,21 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.domain.service; import lombok.RequiredArgsConstructor; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java index 2a545d85db..f4f5d799d1 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/service/ContractViewServiceImpl.java @@ -1,3 +1,21 @@ +/******************************************************************************** + * Copyright (c) 2024 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.traceability.contracts.domain.service; import lombok.RequiredArgsConstructor; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java index ca203ec57a..c58eeda18d 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractAsPlannedRepositoryImpl.java @@ -19,7 +19,6 @@ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; import com.fasterxml.jackson.databind.ObjectMapper; -import jakarta.transaction.Transactional; import lombok.extern.slf4j.Slf4j; import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; import org.eclipse.tractusx.irs.edc.client.contract.service.EdcContractAgreementService;