From ce360a80db887de75063eda7c8a68efabf47bd54 Mon Sep 17 00:00:00 2001 From: pierre-maraval Date: Thu, 26 Oct 2023 11:17:54 +0200 Subject: [PATCH] =?UTF-8?q?CDE-249=20:=20FIX=20:=20correction=20entit?= =?UTF-8?q?=C3=A9s=20suite=20=C3=A0=20modification=20bdd=20Bacon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logskbart/entity/bacon/LigneKbart.java | 18 ++++---- .../entity/bacon/ProviderPackage.java | 19 ++++++-- .../entity/bacon/ProviderPackageId.java | 46 ------------------- .../bacon/ProviderPackageRepository.java | 5 +- .../logskbart/service/KbartToBddService.java | 8 ++-- 5 files changed, 30 insertions(+), 66 deletions(-) delete mode 100644 src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackageId.java diff --git a/src/main/java/fr/abes/logskbart/entity/bacon/LigneKbart.java b/src/main/java/fr/abes/logskbart/entity/bacon/LigneKbart.java index 9f2922c..a0567cc 100644 --- a/src/main/java/fr/abes/logskbart/entity/bacon/LigneKbart.java +++ b/src/main/java/fr/abes/logskbart/entity/bacon/LigneKbart.java @@ -8,7 +8,7 @@ import java.util.Date; @Entity -@Table(name = "LIGNE_KBART_CONVERGENCE") +@Table(name = "LIGNE_KBART") @Setter @Getter public class LigneKbart implements Serializable { @Id @@ -65,13 +65,15 @@ public class LigneKbart implements Serializable { private String precedeingPublicationTitleId; @Column(name = "ACCESS_TYPE") private String accessType; - @ManyToOne(targetEntity = ProviderPackage.class, cascade = CascadeType.REMOVE, optional = false) - @JoinColumns({ - @JoinColumn(name = "PROVIDER_PACKAGE_PACKAGE", referencedColumnName = "PACKAGE"), - @JoinColumn(name = "PROVIDER_PACKAGE_DATE_P", referencedColumnName = "DATE_P"), - @JoinColumn(name = "PROVIDER_PACKAGE_IDT_PROVIDER", referencedColumnName = "PROVIDER_IDT_PROVIDER" - )}) - private ProviderPackage providerPackage; + @Column(name = "PACKAGE") + private String packageName; + @Column(name = "DATE_P") + private Date dateP; + @Column(name = "PROVIDER_IDT_PROVIDER") + private Integer providerIdtProvider; @Column(name = "BEST_PPN") private String bestPpn; + @ManyToOne(targetEntity = ProviderPackage.class, cascade = CascadeType.REMOVE, optional = false) + @JoinColumn(name = "ID_PROVIDER_PACKAGE", referencedColumnName = "ID_PROVIDER_PACKAGE") + private ProviderPackage providerPackage; } diff --git a/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackage.java b/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackage.java index 0f4421b..e1c62b5 100644 --- a/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackage.java +++ b/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackage.java @@ -7,6 +7,7 @@ import lombok.Setter; import java.io.Serializable; +import java.util.Date; @Entity @Table(name = "PROVIDER_PACKAGE") @@ -14,8 +15,16 @@ @AllArgsConstructor @NoArgsConstructor public class ProviderPackage implements Serializable { - @EmbeddedId - private ProviderPackageId providerPackageId; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ID_PROVIDER_PACKAGE") + private Integer providerPackageId; + @Column(name = "PACKAGE") + private String packageName; + @Column(name = "DATE_P") + private Date dateP; + @Column(name = "PROVIDER_IDT_PROVIDER") + private Integer providerIdtProvider; @Column(name = "LABEL_ABES") private char labelAbes; @@ -24,8 +33,10 @@ public class ProviderPackage implements Serializable { @JoinColumn(referencedColumnName = "IDT_PROVIDER", insertable = false, updatable = false) private Provider provider; - public ProviderPackage(ProviderPackageId providerPackageId, char labelAbes) { - this.providerPackageId = providerPackageId; + public ProviderPackage(String packageName, Date dateP, Integer providerIdtProvider, char labelAbes) { + this.packageName = packageName; + this.dateP = dateP; + this.providerIdtProvider = providerIdtProvider; this.labelAbes = labelAbes; } } diff --git a/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackageId.java b/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackageId.java deleted file mode 100644 index 0c7d45f..0000000 --- a/src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackageId.java +++ /dev/null @@ -1,46 +0,0 @@ -package fr.abes.logskbart.entity.bacon; - -import jakarta.persistence.Column; -import jakarta.persistence.Embeddable; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import java.io.Serializable; -import java.util.Date; -import java.util.Objects; - - -@Embeddable -@Getter -@NoArgsConstructor -public class ProviderPackageId implements Serializable { - @Column(name = "PACKAGE") - private String packageName; - @Column(name = "DATE_P") - private Date dateP; - @Column(name = "PROVIDER_IDT_PROVIDER") - private Integer providerIdtProvider; - - public ProviderPackageId(String packageName, Date datePackage, Integer idtProvider) { - this.packageName = packageName; - this.dateP = datePackage; - this.providerIdtProvider = idtProvider; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ProviderPackageId)) return false; - ProviderPackageId that = (ProviderPackageId) o; - return Objects.equals(getProviderIdtProvider(), that.getProviderIdtProvider()) && - Objects.equals(getDateP(), that.getDateP()) && - Objects.equals(getPackageName(), that.getPackageName()); - } - - @Override - public int hashCode() { - return Objects.hash(getProviderIdtProvider(), getDateP(), getPackageName()); - } -} diff --git a/src/main/java/fr/abes/logskbart/repository/bacon/ProviderPackageRepository.java b/src/main/java/fr/abes/logskbart/repository/bacon/ProviderPackageRepository.java index 7a6cc33..f0cbc94 100644 --- a/src/main/java/fr/abes/logskbart/repository/bacon/ProviderPackageRepository.java +++ b/src/main/java/fr/abes/logskbart/repository/bacon/ProviderPackageRepository.java @@ -2,7 +2,6 @@ import fr.abes.logskbart.configuration.BaconDbConfiguration; import fr.abes.logskbart.entity.bacon.ProviderPackage; -import fr.abes.logskbart.entity.bacon.ProviderPackageId; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @@ -11,6 +10,6 @@ @Repository @BaconDbConfiguration -public interface ProviderPackageRepository extends JpaRepository { - Optional findByProviderPackageId(ProviderPackageId providerPackageId); +public interface ProviderPackageRepository extends JpaRepository { + Optional findByPackageNameAndDatePAndProviderIdtProvider(String packageName, Date dateP, Integer providerIdtProvider); } diff --git a/src/main/java/fr/abes/logskbart/service/KbartToBddService.java b/src/main/java/fr/abes/logskbart/service/KbartToBddService.java index 2e84428..7916152 100644 --- a/src/main/java/fr/abes/logskbart/service/KbartToBddService.java +++ b/src/main/java/fr/abes/logskbart/service/KbartToBddService.java @@ -4,7 +4,6 @@ import fr.abes.logskbart.entity.bacon.LigneKbart; import fr.abes.logskbart.entity.bacon.Provider; import fr.abes.logskbart.entity.bacon.ProviderPackage; -import fr.abes.logskbart.entity.bacon.ProviderPackageId; import fr.abes.logskbart.repository.bacon.LigneKbartRepository; import fr.abes.logskbart.repository.bacon.ProviderPackageRepository; import fr.abes.logskbart.repository.bacon.ProviderRepository; @@ -43,15 +42,14 @@ private ProviderPackage handlePackageAndProvider(PackageKbartDto packageKbartDto Optional providerOpt = providerRepository.findByProvider(packageKbartDto.getProvider()); if (providerOpt.isPresent()) { Provider provider = providerOpt.get(); - ProviderPackageId providerPackageId = new ProviderPackageId(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), provider.getIdtProvider()); - Optional providerPackage = providerPackageRepository.findByProviderPackageId(providerPackageId); + Optional providerPackage = providerPackageRepository.findByPackageNameAndDatePAndProviderIdtProvider(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), provider.getIdtProvider()); //pas d'info de package, on le crée - return providerPackage.orElseGet(() -> providerPackageRepository.save(new ProviderPackage(providerPackageId, 'N'))); + return providerPackage.orElseGet(() -> providerPackageRepository.save(new ProviderPackage(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), provider.getIdtProvider(), 'N'))); } else { //pas de provider, ni de package, on les crée tous les deux Provider newProvider = new Provider(packageKbartDto.getProvider()); Provider savedProvider = providerRepository.save(newProvider); - ProviderPackage providerPackage = new ProviderPackage(new ProviderPackageId(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), savedProvider.getIdtProvider()), 'N'); + ProviderPackage providerPackage = new ProviderPackage(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), savedProvider.getIdtProvider(), 'N'); return providerPackageRepository.save(providerPackage); } }