Skip to content

Commit

Permalink
CDE-249 : FIX : correction entités suite à modification bdd Bacon
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-maraval committed Oct 26, 2023
1 parent acd0324 commit ce360a8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 66 deletions.
18 changes: 10 additions & 8 deletions src/main/java/fr/abes/logskbart/entity/bacon/LigneKbart.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
19 changes: 15 additions & 4 deletions src/main/java/fr/abes/logskbart/entity/bacon/ProviderPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
import lombok.Setter;

import java.io.Serializable;
import java.util.Date;

@Entity
@Table(name = "PROVIDER_PACKAGE")
@Getter @Setter
@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;
Expand All @@ -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;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -11,6 +10,6 @@

@Repository
@BaconDbConfiguration
public interface ProviderPackageRepository extends JpaRepository<ProviderPackage, ProviderPackageId> {
Optional<ProviderPackage> findByProviderPackageId(ProviderPackageId providerPackageId);
public interface ProviderPackageRepository extends JpaRepository<ProviderPackage, Integer> {
Optional<ProviderPackage> findByPackageNameAndDatePAndProviderIdtProvider(String packageName, Date dateP, Integer providerIdtProvider);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,15 +42,14 @@ private ProviderPackage handlePackageAndProvider(PackageKbartDto packageKbartDto
Optional<Provider> providerOpt = providerRepository.findByProvider(packageKbartDto.getProvider());
if (providerOpt.isPresent()) {
Provider provider = providerOpt.get();
ProviderPackageId providerPackageId = new ProviderPackageId(packageKbartDto.getPackageName(), packageKbartDto.getDatePackage(), provider.getIdtProvider());
Optional<ProviderPackage> providerPackage = providerPackageRepository.findByProviderPackageId(providerPackageId);
Optional<ProviderPackage> 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);
}
}
Expand Down

0 comments on commit ce360a8

Please sign in to comment.