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 bd4bd2d64b..11b6366329 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,7 +38,7 @@ public static PageResult from(PageResult contractPag public static ContractResponse from(Contract contract) { return ContractResponse.builder() .contractId(contract.getContractId()) - .contractType(ContractTypeResponse.valueOf(contract.get)) + .contractType(ContractTypeResponse.valueOf(contract.getType().name())) .state(contract.getState()) .counterpartyAddress(contract.getCounterpartyAddress()) .endDate(contract.getEndDate()) 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 6ea38d6efc..74e572d6bd 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 @@ -22,7 +22,7 @@ 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; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import java.util.List; 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 ca24fce840..f36c55d91e 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 @@ -23,7 +23,6 @@ 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.ContractType; import java.time.Instant; import java.time.OffsetDateTime; @@ -40,6 +39,7 @@ public class Contract { private OffsetDateTime endDate; private String state; private String policy; + private ContractType type; public static ContractAgreementView toEntity(Contract contract, ContractType contractType) { return ContractAgreementView.builder() diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractType.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractType.java similarity index 52% rename from tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractType.java rename to tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractType.java index ba9344989e..dc9ca4cd4f 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/infrastructure/model/ContractType.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/contracts/domain/model/ContractType.java @@ -1,4 +1,4 @@ -package org.eclipse.tractusx.traceability.contracts.infrastructure.model; +package org.eclipse.tractusx.traceability.contracts.domain.model; public enum ContractType { ASSET_AS_PLANNED, ASSET_AS_BUILT, NOTIFICATION; 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 7c787f6a91..dfbd7d824b 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,7 +22,7 @@ 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.infrastructure.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.springframework.data.domain.Pageable; import java.util.List; 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 0addc9cff2..a2863306eb 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 @@ -28,7 +28,7 @@ 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.repository.ContractRepository; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; 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/ContractAgreementView.java index 62feb520a2..3716b96b83 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/ContractAgreementView.java @@ -27,6 +27,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; import lombok.experimental.SuperBuilder; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import java.time.Instant; 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 968d496814..c6f28cda7b 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.repository.ContractRepository; import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractAgreementView; -import org.eclipse.tractusx.traceability.contracts.infrastructure.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; @@ -74,9 +74,8 @@ 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); } -// TODO we need the contractAgreementInfoViews into the featchEdcContractAgreements because we need to pass the type of it into the contract for the notifications - List contractAgreementIds = contractAgreementInfoViews.getContent().stream().map(ContractAgreementView::getContractAgreementId).toList(); - return new PageResult<>(fetchEdcContractAgreements(contractAgreementIds), + + return new PageResult<>(fetchEdcContractAgreements(contractAgreementInfoViews.getContent()), contractAgreementInfoViews.getPageable().getPageNumber(), contractAgreementInfoViews.getTotalPages(), contractAgreementInfoViews.getPageable().getPageSize(), @@ -90,18 +89,30 @@ public PageResult getContractsByPageable(Pageable pageable, SearchCrit @Override public void saveAllContractAgreements(List contractAgreementIds, ContractType contractType) throws ContractAgreementException { - List contracts = fetchEdcContractAgreements(contractAgreementIds); - List contractAgreementViews = Contract.toEntityList(contracts, contractType); - contractAgreementInfoViewRepository.saveAll(contractAgreementViews); + + List contractAgreementViews = contractAgreementIds.stream() + .map(contractAgreementId -> ContractAgreementView.builder() + .contractAgreementId(contractAgreementId) + .type(contractType) + .build()) + .collect(Collectors.toList()); + + List contracts = fetchEdcContractAgreements(contractAgreementViews); + List contractAgreementViewsUpdated = Contract.toEntityList(contracts, contractType); + contractAgreementInfoViewRepository.saveAll(contractAgreementViewsUpdated); } - private List fetchEdcContractAgreements(List contractAgreementIds) throws ContractAgreementException { - log.info("Trying to fetch contractAgreementIds from EDC: {}", contractAgreementIds); + private List fetchEdcContractAgreements(List contractAgreementInfoViews) throws ContractAgreementException { + List contractAgreementIds = contractAgreementInfoViews.stream().map(ContractAgreementView::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 contractNegotiations = contractAgreements.stream() .map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(), edcContractAgreementService.getContractAgreementNegotiation(agreement.contractAgreementId())) @@ -117,6 +128,7 @@ private List fetchEdcContractAgreements(List contractAgreement .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); 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 474cb481f7..b2fb81a840 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 @@ -33,12 +33,11 @@ import org.eclipse.tractusx.irs.edc.client.ContractNegotiationService; import org.eclipse.tractusx.irs.edc.client.EDCCatalogFacade; import org.eclipse.tractusx.irs.edc.client.EndpointDataReferenceStorage; -import org.eclipse.tractusx.irs.edc.client.contract.model.exception.ContractAgreementException; 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.infrastructure.model.ContractType; +import org.eclipse.tractusx.traceability.contracts.domain.model.ContractType; import org.eclipse.tractusx.traceability.notification.domain.base.exception.BadRequestException; import org.eclipse.tractusx.traceability.notification.domain.base.exception.ContractNegotiationException; import org.eclipse.tractusx.traceability.notification.domain.base.exception.NoCatalogItemException;