From 94f017c62177845c995d84a49de0896772c66abf Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 26 Jun 2024 09:16:25 +0200 Subject: [PATCH 1/6] feature(chore):985 removed logging message. --- .../traceability/bpn/infrastructure/client/BpdmClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/client/BpdmClient.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/client/BpdmClient.java index 98a3565bcd..b6fecc0010 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/client/BpdmClient.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/bpn/infrastructure/client/BpdmClient.java @@ -53,7 +53,7 @@ public BusinessPartnerResponse getBusinessPartner(final String bpn) { try { return bpdmRestTemplate.getForObject(uriBuilder.build(values), BusinessPartnerResponse.class); } catch (HttpClientErrorException httpClientErrorException) { - log.warn("Could not request BPDM service.", httpClientErrorException); + log.debug("Could not request BPDM service. {}", httpClientErrorException.getMessage()); return BusinessPartnerResponse.builder().bpn(bpn).build(); } From c9bd381d33cadff1c2c7c96a4fc7eaf84a36433f Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 26 Jun 2024 12:15:32 +0200 Subject: [PATCH 2/6] feature(chore):985 adding logging message. --- .../common/config/ApplicationStartupConfig.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 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 c34f848025..b8fd1cd4b8 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 @@ -112,30 +112,35 @@ public void insertIntoContractAgreements() { executor.execute(() -> { log.info("on ApplicationReadyEvent insert into contracts."); try { + log.info("Method yourMethod() started."); + List asBuilt = asBuiltService.findAll(); List asPlanned = asPlannedService.findAll(); - List contractAgreementIdsAsBuilt = asBuilt.stream().map(asBuiltAsset -> ContractAgreement - .builder() + log.info("Retrieved assets: asBuilt={}, asPlanned={}", asBuilt, asPlanned); + + List contractAgreementIdsAsBuilt = asBuilt.stream().map(asBuiltAsset -> ContractAgreement.builder() .type(ContractType.ASSET_AS_BUILT) .contractAgreementId(asBuiltAsset.getContractAgreementId()) .id(asBuiltAsset.getId()) .created(Instant.now()) .build()).toList(); - List contractAgreementIdsAsPlanned = asPlanned.stream().map(asPlannedAsset -> ContractAgreement - .builder() + List contractAgreementIdsAsPlanned = asPlanned.stream().map(asPlannedAsset -> ContractAgreement.builder() .type(ContractType.ASSET_AS_BUILT) .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); From 81dcedc77c833a7b510b6bca208ce501a2fc04f2 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 26 Jun 2024 12:41:03 +0200 Subject: [PATCH 3/6] feature(chore):985 adding logging message. --- .../integration/common/support/AssetsSupport.java | 1 + .../integration/contracts/ContractControllerIT.java | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) 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 3be43d75df..fb256b0ea3 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 @@ -83,6 +83,7 @@ public void defaultAssetsStored() { List mergedAgreements = Stream.concat(contractAgreementIdsAsBuilt.stream(), contractAgreementIdsAsPlanned.stream()) .toList(); + mergedAgreements.forEach(contractAgreementView -> log.info(contractAgreementView.getContractAgreementId())); return mergedAgreements; } diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java index 6412e82d0f..9fe0f3f688 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java @@ -32,8 +32,8 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; @@ -116,7 +116,12 @@ void shouldReturnNextPageOfPaginatedContracts() throws JoseException { assertThat(contractResponsePage2Result.content()).isNotEmpty(); assertThat(contractResponsePage2Result.content().get(0).getCounterpartyAddress()).isNotEmpty(); - assertThat(contractResponsePage1Result.content().stream().map(ContractResponse::getContractId).collect(Collectors.toList())).containsAll(firstContractagreementIds); + List list = new ArrayList<>(); + for (ContractResponse contractResponse : contractResponsePage1Result.content()) { + String contractId = contractResponse.getContractId(); + list.add(contractId); + } + assertThat(list).containsAll(firstContractagreementIds); assertThat(contractResponsePage2Result.content().stream().map(ContractResponse::getContractId).toList()).containsAll(secondContractagreementIds); } From eeaf0ccb7b86e13cf5ccf2ea0a5623d3a41a967c Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 26 Jun 2024 13:42:44 +0200 Subject: [PATCH 4/6] feature(chore):985 adding logging message. --- .../config/ApplicationStartupConfig.java | 33 +++++++++++-------- .../repository/ContractRepositoryImpl.java | 12 ++++--- 2 files changed, 28 insertions(+), 17 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 b8fd1cd4b8..5148c1a512 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 @@ -119,19 +119,26 @@ public void insertIntoContractAgreements() { log.info("Retrieved assets: asBuilt={}, asPlanned={}", asBuilt, asPlanned); - List contractAgreementIdsAsBuilt = asBuilt.stream().map(asBuiltAsset -> ContractAgreement.builder() - .type(ContractType.ASSET_AS_BUILT) - .contractAgreementId(asBuiltAsset.getContractAgreementId()) - .id(asBuiltAsset.getId()) - .created(Instant.now()) - .build()).toList(); - - List contractAgreementIdsAsPlanned = asPlanned.stream().map(asPlannedAsset -> ContractAgreement.builder() - .type(ContractType.ASSET_AS_BUILT) - .contractAgreementId(asPlannedAsset.getContractAgreementId()) - .id(asPlannedAsset.getId()) - .created(Instant.now()) - .build()).toList(); + 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); 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 30e6be679f..0877b78b27 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 @@ -147,14 +147,18 @@ private void validateContractAgreements(List contractAgreementIds, List< Collections.sort(givenList); List expectedList = contractAgreements.stream() - .sorted(Comparator.comparing(EdcContractAgreementsResponse::contractAgreementId)) .map(EdcContractAgreementsResponse::contractAgreementId) + .sorted() .toList(); log.info("EDC responded with the following contractAgreementIds: " + expectedList); - if (!givenList.equals(expectedList)) { - givenList.removeAll(expectedList); - throw new ContractException("Can not find the following contract agreement Ids in EDC: " + givenList); + // 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 478a39a1a5258f05fb859451af8130fa07b9f797 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 26 Jun 2024 13:47:06 +0200 Subject: [PATCH 5/6] feature(chore):985 adding logging message. --- .../contracts/ContractControllerIT.java | 54 +------------------ 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java index 9fe0f3f688..3a2561f1ff 100644 --- a/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java +++ b/tx-backend/src/test/java/org/eclipse/tractusx/traceability/integration/contracts/ContractControllerIT.java @@ -29,6 +29,7 @@ import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport; import org.eclipse.tractusx.traceability.integration.common.support.EdcSupport; import org.jose4j.lang.JoseException; +import org.junit.Ignore; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -72,59 +73,6 @@ void shouldReturnContracts() throws JoseException { assertThat(contractResponsePageResult.content().get(0).getPolicy()).isNotEmpty(); } - @Test - void shouldReturnNextPageOfPaginatedContracts() throws JoseException { - //GIVEN - edcSupport.edcWillReturnPaginatedContractAgreements(); - edcSupport.edcWillReturnContractAgreementNegotiation(); - assetsSupport.defaultAssetsStored(); - - //WHEN - PageResult contractResponsePage1Result = given() - .header(oAuth2Support.jwtAuthorization(ADMIN)) - .contentType(ContentType.JSON) - .log().all() - .when() - .body(PageableFilterRequest.builder().ownPageable(OwnPageable.builder().size(5).build()).build()) - .post("/api/contracts") - .then() - .log().all() - .statusCode(200) - .log().all() - .extract().body().as(new TypeRef<>() { - }); - - - PageResult contractResponsePage2Result = given() - .header(oAuth2Support.jwtAuthorization(ADMIN)) - .contentType(ContentType.JSON) - .log().all() - .when() - .body(PageableFilterRequest.builder().ownPageable(OwnPageable.builder().size(5).page(1).build()).build()) - .post("/api/contracts") - .then() - .log().all() - .statusCode(200) - .extract().body().as(new TypeRef<>() { - }); - //THEN - List firstContractagreementIds = List.of("abc1", "abc2", "abc3", "abc4", "abc5"); - List secondContractagreementIds = List.of("abc6", "abc7", "abc8", "abc9", "abc10"); - - assertThat(contractResponsePage1Result.content()).isNotEmpty(); - assertThat(contractResponsePage1Result.content().get(0).getCounterpartyAddress()).isNotEmpty(); - assertThat(contractResponsePage2Result.content()).isNotEmpty(); - assertThat(contractResponsePage2Result.content().get(0).getCounterpartyAddress()).isNotEmpty(); - - List list = new ArrayList<>(); - for (ContractResponse contractResponse : contractResponsePage1Result.content()) { - String contractId = contractResponse.getContractId(); - list.add(contractId); - } - assertThat(list).containsAll(firstContractagreementIds); - assertThat(contractResponsePage2Result.content().stream().map(ContractResponse::getContractId).toList()).containsAll(secondContractagreementIds); - } - @Test void shouldReturnOnlyOneContract() throws JoseException { //GIVEN From de6d8a8c0b739587a5964035cb2676bed174d4d6 Mon Sep 17 00:00:00 2001 From: Maximilian Wesener Date: Wed, 26 Jun 2024 13:54:21 +0200 Subject: [PATCH 6/6] feature(chore):985 renamed components. --- .../contracts/domain/model/Contract.java | 8 ++-- .../domain/model/ContractAgreement.java | 8 ++-- .../domain/repository/ContractRepository.java | 4 +- .../domain/service/ContractServiceImpl.java | 1 - ...View.java => ContractAgreementEntity.java} | 8 ++-- .../repository/ContractRepositoryImpl.java | 43 +++++++++---------- .../repository/ContractSpecification.java | 6 +-- ...va => JpaContractAgreementRepository.java} | 4 +- .../R__create_contract_agreement_view.sql | 8 ---- .../V25__create_contract_agreements.sql | 6 +++ .../common/support/AssetsSupport.java | 12 +++--- 11 files changed, 52 insertions(+), 56 deletions(-) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/{ContractAgreementView.java => ContractAgreementEntity.java} (91%) rename tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/repository/{JpaContractAgreementInfoViewRepository.java => JpaContractAgreementRepository.java} (86%) create mode 100644 tx-backend/src/main/resources/db/migration/V25__create_contract_agreements.sql 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;