Skip to content

Commit

Permalink
feature(chore):985 renamed components.
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-mwesener committed Jun 26, 2024
1 parent 478a39a commit de6d8a8
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,16 +41,16 @@ 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)
.created(Instant.now())
.build();
}

public static List<ContractAgreementView> toEntityList(List<Contract> contracts, ContractType contractType) {
public static List<ContractAgreementEntity> toEntityList(List<Contract> contracts, ContractType contractType) {
return contracts.stream().map(contract -> Contract.toEntity(contract, contractType)).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,16 +41,16 @@ 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())
.type(contractAgreement.getType())
.build();
}

public static List<ContractAgreementView> toEntityList(List<ContractAgreement> contractAgreementList) {
public static List<ContractAgreementEntity> toEntityList(List<ContractAgreement> contractAgreementList) {
return contractAgreementList.stream().map(ContractAgreement::toEntity).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,5 +34,5 @@ public interface ContractRepository {

void saveAllContractAgreements(List<String> contractAgreementIds, ContractType contractType) throws ContractAgreementException;

void saveAll(List<ContractAgreementView> contractAgreements);
void saveAll(List<ContractAgreementEntity> contractAgreements);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@Entity
@SuperBuilder
@Table(name = "contract_agreement")
public class ContractAgreementView {
public class ContractAgreementEntity {

@Id
private String id;
Expand All @@ -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())
Expand All @@ -58,7 +58,7 @@ public static ContractAgreement toDomain(ContractAgreementView contractAgreement
.build();
}

public static List<ContractAgreement> toDomainList(List<ContractAgreementView> contractAgreementList) {
return contractAgreementList.stream().map(ContractAgreementView::toDomain).toList();
public static List<ContractAgreement> toDomainList(List<ContractAgreementEntity> contractAgreementList) {
return contractAgreementList.stream().map(ContractAgreementEntity::toDomain).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -67,19 +66,19 @@ public PageResult<Contract> getContractsByPageable(Pageable pageable, SearchCrit
List<ContractSpecification> contractAgreementSpecifications = emptyIfNull(searchCriteria.getSearchCriteriaFilterList()).stream()
.map(ContractSpecification::new)
.toList();
Specification<ContractAgreementView> specification = BaseSpecification.toSpecification(contractAgreementSpecifications);
Page<ContractAgreementView> contractAgreementInfoViews = contractAgreementInfoViewRepository.findAll(specification, pageable);
Specification<ContractAgreementEntity> specification = BaseSpecification.toSpecification(contractAgreementSpecifications);
Page<ContractAgreementEntity> 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);
Expand All @@ -90,33 +89,33 @@ public PageResult<Contract> getContractsByPageable(Pageable pageable, SearchCrit
@Override
public void saveAllContractAgreements(List<String> contractAgreementIds, ContractType contractType) throws ContractAgreementException {

List<ContractAgreementView> contractAgreementViews = contractAgreementIds.stream()
.map(contractAgreementId -> ContractAgreementView.builder()
List<ContractAgreementEntity> contractAgreementEntities = contractAgreementIds.stream()
.map(contractAgreementId -> ContractAgreementEntity.builder()
.contractAgreementId(contractAgreementId)
.type(contractType)
.build())
.collect(Collectors.toList());

List<Contract> contracts = fetchEdcContractAgreements(contractAgreementViews);
List<ContractAgreementView> contractAgreementViewsUpdated = Contract.toEntityList(contracts, contractType);
contractAgreementInfoViewRepository.saveAll(contractAgreementViewsUpdated);
List<Contract> contracts = fetchEdcContractAgreements(contractAgreementEntities);
List<ContractAgreementEntity> contractAgreementsUpdated = Contract.toEntityList(contracts, contractType);
contractAgreementRepository.saveAll(contractAgreementsUpdated);
}

@Override
public void saveAll(List<ContractAgreementView> contractAgreements) {
contractAgreementInfoViewRepository.saveAll(contractAgreements);
public void saveAll(List<ContractAgreementEntity> contractAgreements) {
contractAgreementRepository.saveAll(contractAgreements);
}

private List<Contract> fetchEdcContractAgreements(List<ContractAgreementView> contractAgreementInfoViews) throws ContractAgreementException {
List<String> contractAgreementIds = contractAgreementInfoViews.stream().map(ContractAgreementView::getContractAgreementId).toList();
private List<Contract> fetchEdcContractAgreements(List<ContractAgreementEntity> contractAgreementEntities) throws ContractAgreementException {
List<String> contractAgreementIds = contractAgreementEntities.stream().map(ContractAgreementEntity::getContractAgreementId).toList();
log.info("Trying to fetch contractAgreementIds from EDC: " + contractAgreementIds);

List<EdcContractAgreementsResponse> contractAgreements = edcContractAgreementService.getContractAgreements(contractAgreementIds);

validateContractAgreements(contractAgreementIds, contractAgreements);

Map<String, ContractType> contractTypes = contractAgreementInfoViews.stream()
.collect(Collectors.toMap(ContractAgreementView::getContractAgreementId, ContractAgreementView::getType));
Map<String, ContractType> contractTypes = contractAgreementEntities.stream()
.collect(Collectors.toMap(ContractAgreementEntity::getContractAgreementId, ContractAgreementEntity::getType));

Map<String, EdcContractAgreementNegotiationResponse> contractNegotiations = contractAgreements.stream()
.map(agreement -> new ImmutablePair<>(agreement.contractAgreementId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractAgreementView> implements Specification<ContractAgreementView> {
public class ContractSpecification extends BaseSpecification<ContractAgreementEntity> implements Specification<ContractAgreementEntity> {

public ContractSpecification(SearchCriteriaFilter criteria) {
super(criteria);
}

@Override
public Predicate toPredicate(@NotNull Root<ContractAgreementView> root, @NotNull CriteriaQuery<?> query, @NotNull CriteriaBuilder builder) {
public Predicate toPredicate(@NotNull Root<ContractAgreementEntity> root, @NotNull CriteriaQuery<?> query, @NotNull CriteriaBuilder builder) {
return createPredicate(getSearchCriteriaFilter(), root, builder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContractAgreementView, String>, JpaSpecificationExecutor<ContractAgreementView> {
public interface JpaContractAgreementRepository extends JpaRepository<ContractAgreementEntity, String>, JpaSpecificationExecutor<ContractAgreementEntity> {

}
Original file line number Diff line number Diff line change
@@ -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
);
Original file line number Diff line number Diff line change
@@ -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
);
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,30 +58,30 @@ public void defaultAssetsStored() {
bpnSupport.providesBpdmLookup();
assetRepositoryProvider.assetAsBuiltRepository().saveAll(assetRepositoryProvider.testdataProvider().readAndConvertAssetsForTests());

List<ContractAgreementView> mergedAgreements = extractContractAgreementByAssets();
List<ContractAgreementEntity> mergedAgreements = extractContractAgreementByAssets();

contractRepository.saveAll(mergedAgreements);

}

private @NotNull List<ContractAgreementView> extractContractAgreementByAssets() {
List<ContractAgreementView> contractAgreementIdsAsBuilt = assetRepositoryProvider.assetAsBuiltRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementView
private @NotNull List<ContractAgreementEntity> extractContractAgreementByAssets() {
List<ContractAgreementEntity> contractAgreementIdsAsBuilt = assetRepositoryProvider.assetAsBuiltRepository().findAll().stream().map(asBuiltAsset -> ContractAgreementEntity
.builder()
.type(ContractType.ASSET_AS_BUILT)
.contractAgreementId(asBuiltAsset.getContractAgreementId())
.id(asBuiltAsset.getId())
.created(Instant.now())
.build()).collect(Collectors.toUnmodifiableList());

List<ContractAgreementView> contractAgreementIdsAsPlanned = assetRepositoryProvider.assetAsPlannedRepository().findAll().stream().map(asPlannedAsset -> ContractAgreementView
List<ContractAgreementEntity> contractAgreementIdsAsPlanned = assetRepositoryProvider.assetAsPlannedRepository().findAll().stream().map(asPlannedAsset -> ContractAgreementEntity
.builder()
.type(ContractType.ASSET_AS_BUILT)
.contractAgreementId(asPlannedAsset.getContractAgreementId())
.id(asPlannedAsset.getId())
.created(Instant.now())
.build()).collect(Collectors.toUnmodifiableList());

List<ContractAgreementView> mergedAgreements = Stream.concat(contractAgreementIdsAsBuilt.stream(), contractAgreementIdsAsPlanned.stream())
List<ContractAgreementEntity> mergedAgreements = Stream.concat(contractAgreementIdsAsBuilt.stream(), contractAgreementIdsAsPlanned.stream())
.toList();
mergedAgreements.forEach(contractAgreementView -> log.info(contractAgreementView.getContractAgreementId()));
return mergedAgreements;
Expand Down

0 comments on commit de6d8a8

Please sign in to comment.