-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDE-364 : vérification version plus récente d'un package
- Ajout datasource base Bacon - Ajout repository sur ProviderPackage et Provider - Ajout entity - Ajout méthode récupération provider / package / date à partir du nom du fichier - Ajout méthode vérification d'existance d'une version plus récente d'un package - Ajout TU
- Loading branch information
1 parent
d50b4b9
commit 7cab7ef
Showing
19 changed files
with
496 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/fr/abes/kbart2kafka/configuration/AbstractConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package fr.abes.kbart2kafka.configuration; | ||
|
||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | ||
|
||
import java.util.HashMap; | ||
|
||
public abstract class AbstractConfig { | ||
protected void configHibernate(LocalContainerEntityManagerFactoryBean em, String platform, boolean showsql, String dialect, String ddlAuto, boolean generateDdl, String initMode) { | ||
HibernateJpaVendorAdapter vendorAdapter | ||
= new HibernateJpaVendorAdapter(); | ||
vendorAdapter.setGenerateDdl(generateDdl); | ||
vendorAdapter.setShowSql(showsql); | ||
vendorAdapter.setDatabasePlatform(platform); | ||
em.setJpaVendorAdapter(vendorAdapter); | ||
HashMap<String, Object> properties = new HashMap<>(); | ||
properties.put("hibernate.format_sql", true); | ||
properties.put("hibernate.hbm2ddl.auto", ddlAuto); | ||
properties.put("hibernate.dialect", dialect); | ||
properties.put("logging.level.org.hibernate", "DEBUG"); | ||
properties.put("hibernate.type", "trace"); | ||
properties.put("spring.sql.init.mode", initMode); | ||
em.setJpaPropertyMap(properties); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/fr/abes/kbart2kafka/configuration/BaconDbConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package fr.abes.kbart2kafka.configuration; | ||
|
||
import lombok.NoArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
|
||
import javax.sql.DataSource; | ||
|
||
@Configuration | ||
@EnableJpaRepositories(entityManagerFactoryRef = "baconEntityManager", transactionManagerRef = "baconTransactionManager", basePackages = "fr.abes.kbart2kafka.repository") | ||
@NoArgsConstructor | ||
public class BaconDbConfig extends AbstractConfig { | ||
@Value("${spring.jpa.bacon.show-sql}") | ||
protected boolean showsql; | ||
@Value("${spring.jpa.bacon.properties.hibernate.dialect}") | ||
protected String dialect; | ||
@Value("${spring.jpa.bacon.hibernate.ddl-auto}") | ||
protected String ddlAuto; | ||
@Value("${spring.jpa.bacon.database-platform}") | ||
protected String platform; | ||
@Value("${spring.jpa.bacon.generate-ddl}") | ||
protected boolean generateDdl; | ||
@Value("${spring.sql.bacon.init.mode}") | ||
protected String initMode; | ||
|
||
@Bean | ||
@ConfigurationProperties(prefix = "spring.datasource.bacon") | ||
public DataSource baconDataSource() { return DataSourceBuilder.create().build(); } | ||
|
||
@Bean | ||
public LocalContainerEntityManagerFactoryBean baconEntityManager() { | ||
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); | ||
em.setDataSource(baconDataSource()); | ||
em.setPackagesToScan("fr.abes.kbart2kafka.entity"); | ||
configHibernate(em, platform, showsql, dialect, ddlAuto, generateDdl, initMode); | ||
return em; | ||
} | ||
|
||
@Primary | ||
@Bean | ||
public PlatformTransactionManager baconTransactionManager(@Qualifier("baconEntityManager") LocalContainerEntityManagerFactoryBean entityManagerFactory) { | ||
final JpaTransactionManager transactionManager = new JpaTransactionManager(); | ||
transactionManager.setEntityManagerFactory(entityManagerFactory.getObject()); | ||
return transactionManager; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package fr.abes.kbart2kafka.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
|
||
@Entity | ||
@Table(name = "PROVIDER") | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Provider implements Serializable { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq-provider") | ||
@SequenceGenerator(name = "seq-provider", sequenceName = "PROVIDER_SEQ", allocationSize = 1) | ||
@Column(name = "IDT_PROVIDER") | ||
private Integer idtProvider; | ||
@Column(name = "PROVIDER") | ||
private String provider; | ||
@Column(name = "NOM_CONTACT") | ||
private String nomContact; | ||
@Column(name = "PRENOM_CONTACT") | ||
private String prenomContact; | ||
@Column(name = "MAIL_CONTACT") | ||
private String mailContact; | ||
@Column(name = "DISPLAY_NAME") | ||
private String displayName; | ||
|
||
|
||
public Provider(String provider) { | ||
this.provider = provider; | ||
//on ne connait pas le display name à l'avance, on l'initialise au provider pour éviter une erreur not null dans la table | ||
this.displayName = provider; | ||
} | ||
|
||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/fr/abes/kbart2kafka/entity/ProviderPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package fr.abes.kbart2kafka.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
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, Comparable<ProviderPackage> { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "ID_PROVIDER_PACKAGE") | ||
private Integer idProviderPackage; | ||
@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; | ||
|
||
@ManyToOne | ||
@JoinColumn(referencedColumnName = "IDT_PROVIDER", insertable = false, updatable = false) | ||
private Provider provider; | ||
|
||
public ProviderPackage(String packageName, Date dateP, Integer providerIdtProvider, char labelAbes) { | ||
this.packageName = packageName; | ||
this.dateP = dateP; | ||
this.providerIdtProvider = providerIdtProvider; | ||
this.labelAbes = labelAbes; | ||
} | ||
|
||
public ProviderPackage(Integer idProviderPackage, String packageName, Date dateP, Integer providerIdtProvider, char labelAbes) { | ||
this.idProviderPackage = idProviderPackage; | ||
this.packageName = packageName; | ||
this.dateP = dateP; | ||
this.providerIdtProvider = providerIdtProvider; | ||
this.labelAbes = labelAbes; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{ id:"+idProviderPackage + ", packageName:"+packageName+", providerIdt:"+providerIdtProvider+" dateP:"+dateP+" }"; | ||
} | ||
|
||
@Override | ||
public int compareTo(ProviderPackage o) { | ||
return o.getDateP().compareTo(this.getDateP()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/fr/abes/kbart2kafka/exception/IllegalDateException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fr.abes.kbart2kafka.exception; | ||
|
||
public class IllegalDateException extends Throwable { | ||
public IllegalDateException(Exception e) { | ||
super(e); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/fr/abes/kbart2kafka/exception/IllegalPackageException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package fr.abes.kbart2kafka.exception; | ||
|
||
public class IllegalPackageException extends Throwable { | ||
public IllegalPackageException(Exception e) { | ||
super(e); | ||
} | ||
|
||
public IllegalPackageException(String s) { | ||
super(s); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
src/main/java/fr/abes/kbart2kafka/exception/IllegalProviderException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package fr.abes.kbart2kafka.exception; | ||
|
||
public class IllegalProviderException extends Throwable { | ||
public class IllegalProviderException extends Exception { | ||
public IllegalProviderException(String message) { | ||
super(message); | ||
} | ||
|
||
public IllegalProviderException(Exception e) { super(e); } | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/fr/abes/kbart2kafka/repository/ProviderPackageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package fr.abes.kbart2kafka.repository; | ||
|
||
import fr.abes.kbart2kafka.entity.ProviderPackage; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface ProviderPackageRepository extends JpaRepository<ProviderPackage, Integer> { | ||
List<ProviderPackage> findByPackageNameAndProviderIdtProvider(String packageName, Integer providerIdtProvider); | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/fr/abes/kbart2kafka/repository/ProviderRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package fr.abes.kbart2kafka.repository; | ||
|
||
|
||
import fr.abes.kbart2kafka.entity.Provider; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface ProviderRepository extends JpaRepository<Provider, Integer> { | ||
Optional<Provider> findByProvider(String provider); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/fr/abes/kbart2kafka/service/ProviderPackageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fr.abes.kbart2kafka.service; | ||
|
||
import fr.abes.kbart2kafka.entity.Provider; | ||
import fr.abes.kbart2kafka.entity.ProviderPackage; | ||
import fr.abes.kbart2kafka.repository.ProviderPackageRepository; | ||
import fr.abes.kbart2kafka.repository.ProviderRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Collections; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class ProviderPackageService { | ||
private final ProviderPackageRepository repository; | ||
|
||
private final ProviderRepository providerRepository; | ||
|
||
public ProviderPackageService(ProviderPackageRepository repository, ProviderRepository providerRepository) { | ||
this.repository = repository; | ||
this.providerRepository = providerRepository; | ||
} | ||
|
||
public boolean hasMoreRecentPackageInBdd(String provider, String packageName, Date datePackage) { | ||
Optional<Provider> providerBdd = providerRepository.findByProvider(provider); | ||
if (providerBdd.isPresent()) { | ||
List<ProviderPackage> packageList = repository.findByPackageNameAndProviderIdtProvider(packageName, providerBdd.get().getIdtProvider()); | ||
Collections.sort(packageList); | ||
return packageList.get(0).getDateP().after(datePackage); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.