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 f36c55d91e..c9d90b705a 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,7 +22,7 @@ import lombok.Builder; import lombok.Data; import lombok.extern.slf4j.Slf4j; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementView; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; import java.time.Instant; import java.time.OffsetDateTime; @@ -41,8 +41,8 @@ public class Contract { private String policy; private ContractType type; - public static ContractAgreementView toEntity(Contract contract, ContractType contractType) { - return ContractAgreementView.builder() + public static ContractAgreementEntity toEntity(Contract contract, ContractType contractType) { + return ContractAgreementEntity.builder() .id(contract.getContractId()) .contractAgreementId(contract.getContractId()) .type(contractType) @@ -50,7 +50,7 @@ public static ContractAgreementView toEntity(Contract contract, ContractType con .build(); } - public static List toEntityList(List contracts, ContractType contractType) { + 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 04ee586f82..8437ffd696 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,7 @@ import lombok.Builder; import lombok.Getter; import lombok.Setter; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementView; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; import java.time.Instant; import java.util.List; @@ -41,8 +41,8 @@ public class ContractAgreement { private ContractType type; private Instant created; - public static ContractAgreementView toEntity(ContractAgreement contractAgreement) { - return ContractAgreementView.builder() + public static ContractAgreementEntity toEntity(ContractAgreement contractAgreement) { + return ContractAgreementEntity.builder() .created(contractAgreement.getCreated()) .id(contractAgreement.getId()) .contractAgreementId(contractAgreement.getContractAgreementId()) @@ -50,7 +50,7 @@ public static ContractAgreementView toEntity(ContractAgreement contractAgreement .build(); } - public static List toEntityList(List contractAgreementList) { + public static List toEntityList(List contractAgreementList) { return contractAgreementList.stream().map(ContractAgreement::toEntity).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 833cda721f..a28d42a6bc 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,7 +23,7 @@ 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.ContractAgreementView; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; import org.springframework.data.domain.Pageable; import java.util.List; @@ -34,5 +34,5 @@ public interface ContractRepository { 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/ContractServiceImpl.java index 218e8bd8ce..9173b5efb5 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/ContractServiceImpl.java @@ -30,7 +30,6 @@ 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.infrastructure.model.ContractAgreementView; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementView.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementEntity.java similarity index 91% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementView.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementEntity.java index 2472aa1f93..19a4e08fba 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementView.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractAgreementEntity.java @@ -39,7 +39,7 @@ @Entity @SuperBuilder @Table(name = "contract_agreement") -public class ContractAgreementView { +public class ContractAgreementEntity { @Id private String id; @@ -49,7 +49,7 @@ public class ContractAgreementView { private Instant created; - public static ContractAgreement toDomain(ContractAgreementView contractAgreement) { + public static ContractAgreement toDomain(ContractAgreementEntity contractAgreement) { return ContractAgreement.builder() .created(contractAgreement.getCreated()) .id(contractAgreement.getId()) @@ -58,7 +58,7 @@ public static ContractAgreement toDomain(ContractAgreementView contractAgreement .build(); } - public static List toDomainList(List contractAgreementList) { - return contractAgreementList.stream().map(ContractAgreementView::toDomain).toList(); + public static List toDomainList(List contractAgreementList) { + return contractAgreementList.stream().map(ContractAgreementEntity::toDomain).toList(); } } 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/ContractRepositoryImpl.java index 0877b78b27..c76a8859bf 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/ContractRepositoryImpl.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.ContractAgreementView; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; @@ -45,7 +45,6 @@ import java.time.ZoneId; import java.util.ArrayList; import java.util.Collections; -import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -58,7 +57,7 @@ public class ContractRepositoryImpl implements ContractRepository { private final EdcContractAgreementService edcContractAgreementService; - private final JpaContractAgreementInfoViewRepository contractAgreementInfoViewRepository; + private final JpaContractAgreementRepository contractAgreementRepository; private final ObjectMapper objectMapper; @Override @@ -67,19 +66,19 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit List contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream() .map(ContractSpecification::new) .toList(); - Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); - Page contractAgreementInfoViews = contractAgreementInfoViewRepository.findAll(specification, pageable); + Specification specification = BaseSpecification.toSpecification(contractAgreementSpecifications); + Page contractAgreementEntities = contractAgreementRepository.findAll(specification, pageable); - if (contractAgreementInfoViews.getContent().isEmpty()) { + 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(contractAgreementInfoViews.getContent()), - contractAgreementInfoViews.getPageable().getPageNumber(), - contractAgreementInfoViews.getTotalPages(), - contractAgreementInfoViews.getPageable().getPageSize(), - contractAgreementInfoViews.getTotalElements()); + return new PageResult<>(fetchEdcContractAgreements(contractAgreementEntities.getContent()), + contractAgreementEntities.getPageable().getPageNumber(), + contractAgreementEntities.getTotalPages(), + contractAgreementEntities.getPageable().getPageSize(), + contractAgreementEntities.getTotalElements()); } catch (ContractAgreementException e) { throw new ContractException(e); @@ -90,33 +89,33 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { - List contractAgreementViews = contractAgreementIds.stream() - .map(contractAgreementId -> ContractAgreementView.builder() + List contractAgreementEntities = contractAgreementIds.stream() + .map(contractAgreementId -> ContractAgreementEntity.builder() .contractAgreementId(contractAgreementId) .type(contractType) .build()) .collect(Collectors.toList()); - List contracts = fetchEdcContractAgreements(contractAgreementViews); - List contractAgreementViewsUpdated = Contract.toEntityList(contracts, contractType); - contractAgreementInfoViewRepository.saveAll(contractAgreementViewsUpdated); + List contracts = fetchEdcContractAgreements(contractAgreementEntities); + List contractAgreementsUpdated = Contract.toEntityList(contracts, contractType); + contractAgreementRepository.saveAll(contractAgreementsUpdated); } @Override - public void saveAll(List contractAgreements) { - contractAgreementInfoViewRepository.saveAll(contractAgreements); + public void saveAll(List contractAgreements) { + contractAgreementRepository.saveAll(contractAgreements); } - private List fetchEdcContractAgreements(List contractAgreementInfoViews) throws ContractAgreementException { - List contractAgreementIds = contractAgreementInfoViews.stream().map(ContractAgreementView::getContractAgreementId).toList(); + private List fetchEdcContractAgreements(List contractAgreementEntities) throws ContractAgreementException { + List contractAgreementIds = contractAgreementEntities.stream().map(ContractAgreementEntity::getContractAgreementId).toList(); log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds); List contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds); validateContractAgreements(contractAgreementIds, contractAgreements); - Map contractTypes = contractAgreementInfoViews.stream() - .collect(Collectors.toMap(ContractAgreementView::getContractAgreementId, ContractAgreementView::getType)); + Map contractTypes = contractAgreementEntities.stream() + .collect(Collectors.toMap(ContractAgreementEntity::getContractAgreementId, ContractAgreementEntity::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/ContractSpecification.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/ContractSpecification.java index 9d76eda5c2..e533c0dd0c 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/ContractSpecification.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.ContractAgreementView; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; import org.jetbrains.annotations.NotNull; import org.springframework.data.jpa.domain.Specification; -public class ContractSpecification extends BaseSpecification implements Specification { +public class ContractSpecification extends BaseSpecification implements Specification { public ContractSpecification(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/JpaContractAgreementInfoViewRepository.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementRepository.java similarity index 86% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementInfoViewRepository.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementRepository.java index 9a11cfbad2..135b246d1f 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementInfoViewRepository.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/JpaContractAgreementRepository.java @@ -18,12 +18,12 @@ ********************************************************************************/ package org.eclipse.tractusx.traceability.contracts.infrastructure.repository; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementView; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Repository; @Repository -public interface JpaContractAgreementInfoViewRepository extends JpaRepository, JpaSpecificationExecutor { +public interface JpaContractAgreementRepository extends JpaRepository, JpaSpecificationExecutor { } 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 5bf0b629ee..13de99dcf4 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,10 +1,2 @@ -- Drop the view if it exists DROP VIEW IF EXISTS contract_agreement_view; - --- Create the table -CREATE TABLE contract_agreement ( - id varchar(255) PRIMARY KEY, - contract_agreement_id varchar(255), - type VARCHAR(255), - created TIMESTAMP -); diff --git a/tx-backend/src/main/resources/db/migration/V25__create_contract_agreements.sql b/tx-backend/src/main/resources/db/migration/V25__create_contract_agreements.sql new file mode 100644 index 0000000000..e73f7c9884 --- /dev/null +++ b/tx-backend/src/main/resources/db/migration/V25__create_contract_agreements.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS contract_agreement ( + id VARCHAR(255) PRIMARY KEY, + contract_agreement_id VARCHAR(255), + type VARCHAR(255), + created 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 fb256b0ea3..da6558e0d4 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 @@ -22,7 +22,7 @@ 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.ContractAgreementView; +import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementEntity; import org.jetbrains.annotations.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -58,14 +58,14 @@ public void defaultAssetsStored() { bpnSupport.providesBpdmLookup(); assetRepositoryProvider.assetAsBuiltRepository().saveAll(assetRepositoryProvider.testdataProvider().readAndConvertAssetsForTests()); - List mergedAgreements = extractContractAgreementByAssets(); + List mergedAgreements = extractContractAgreementByAssets(); contractRepository.saveAll(mergedAgreements); } - private @NotNull List extractContractAgreementByAssets() { - List contractAgreementIdsAsBuilt = assetRepositoryProvider.assetAsBuiltRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementView + private @NotNull List extractContractAgreementByAssets() { + List contractAgreementIdsAsBuilt = assetRepositoryProvider.assetAsBuiltRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementEntity .builder() .type(ContractType.ASSET_AS_BUILT) .contractAgreementId(asBuiltAsset.getContractAgreementId()) @@ -73,7 +73,7 @@ public void defaultAssetsStored() { .created(Instant.now()) .build()).collect(Collectors.toUnmodifiableList()); - List contractAgreementIdsAsPlanned = assetRepositoryProvider.assetAsPlannedRepository().findAll().stream().map(asPlannedAsset -> ContractAgreementView + List contractAgreementIdsAsPlanned = assetRepositoryProvider.assetAsPlannedRepository().findAll().stream().map(asPlannedAsset -> ContractAgreementEntity .builder() .type(ContractType.ASSET_AS_BUILT) .contractAgreementId(asPlannedAsset.getContractAgreementId()) @@ -81,7 +81,7 @@ public void defaultAssetsStored() { .created(Instant.now()) .build()).collect(Collectors.toUnmodifiableList()); - List mergedAgreements = Stream.concat(contractAgreementIdsAsBuilt.stream(), contractAgreementIdsAsPlanned.stream()) + List mergedAgreements = Stream.concat(contractAgreementIdsAsBuilt.stream(), contractAgreementIdsAsPlanned.stream()) .toList(); mergedAgreements.forEach(contractAgreementView -> log.info(contractAgreementView.getContractAgreementId())); return mergedAgreements;