gestion revu de code en utilisant uniquement les DTO
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 36s
All checks were successful
CI - Build & Test (develop) / build-and-test (pull_request) Successful in 36s
This commit is contained in:
10
pom.xml
10
pom.xml
@@ -73,6 +73,7 @@
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.jasperreports</groupId>
|
||||
<artifactId>jasperreports</artifactId>
|
||||
@@ -155,7 +156,14 @@
|
||||
<version>1.7.6</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents.client5</groupId>
|
||||
<artifactId>httpclient5</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package io.gmss.fiscad.configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import io.gmss.fiscad.security.CustomUserDetailsService;
|
||||
import io.gmss.fiscad.security.JwtAuthenticationFilter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
@@ -63,4 +67,7 @@ public class ApplicationConfig {
|
||||
|
||||
return authenticationManagerBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package io.gmss.fiscad.configuration;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@Configuration
|
||||
public class RestTemplateConfig {
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
|
||||
return builder -> {
|
||||
builder.modules(new JavaTimeModule());
|
||||
builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RestTemplate restTemplate(ObjectMapper mapper) {
|
||||
|
||||
mapper.registerModule(new JavaTimeModule());
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
|
||||
MappingJackson2HttpMessageConverter converter =
|
||||
new MappingJackson2HttpMessageConverter(mapper);
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.getMessageConverters().removeIf(
|
||||
c -> c instanceof MappingJackson2HttpMessageConverter
|
||||
);
|
||||
restTemplate.getMessageConverters().add(converter);
|
||||
|
||||
return restTemplate;
|
||||
}
|
||||
}
|
||||
120
src/main/java/io/gmss/fiscad/configuration/SecurityConfig.java
Executable file
120
src/main/java/io/gmss/fiscad/configuration/SecurityConfig.java
Executable file
@@ -0,0 +1,120 @@
|
||||
//package io.gmss.fiscad.configuration;
|
||||
//
|
||||
//import com.backend.api.security.CustomUserDetailsService;
|
||||
//import com.backend.api.security.JwtAuthenticationEntryPoint;
|
||||
//import com.backend.api.security.JwtAuthenticationFilter;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.http.HttpMethod;
|
||||
//import org.springframework.security.authentication.AuthenticationManager;
|
||||
//import org.springframework.security.config.BeanIds;
|
||||
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||
//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
//import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
//import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
//
|
||||
//@Configuration
|
||||
//@EnableWebSecurity // active la sécurité web sur le projet
|
||||
//@EnableGlobalMethodSecurity( // est utilisé pour définir la sécurité sur les méthodes
|
||||
// securedEnabled = true, // est activé pour protéger un controlleur ou un service
|
||||
// jsr250Enabled = true, // active le role qui doit être utilisé
|
||||
// prePostEnabled = true // active le controle avant et après l'execution de la requête
|
||||
//)
|
||||
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
//
|
||||
// /**
|
||||
// * Est utilisé pour authentifier un utlisateur ou pour définir un role
|
||||
// */
|
||||
// @Autowired
|
||||
// CustomUserDetailsService customUserDetailsService;
|
||||
//
|
||||
// @Autowired
|
||||
// private JwtAuthenticationEntryPoint unauthorizedHandler;
|
||||
//
|
||||
// @Bean
|
||||
// public JwtAuthenticationFilter jwtAuthenticationFilter() {
|
||||
// return new JwtAuthenticationFilter();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// private static final String[] AUTH_WHITELIST = {
|
||||
//
|
||||
// // -- swagger ui
|
||||
// "/swagger-resources/**",
|
||||
// "/swagger-ui.html",
|
||||
// "/v3/api-docs",
|
||||
// "/swagger-ui/**",
|
||||
// "/webjars/**",
|
||||
// "/api/**",
|
||||
//// "/api/synonym/**",
|
||||
// "/api/auth/**"
|
||||
// };
|
||||
// @Override
|
||||
// public void configure(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
|
||||
// authenticationManagerBuilder
|
||||
// .userDetailsService(customUserDetailsService)
|
||||
// .passwordEncoder(passwordEncoder());
|
||||
// }
|
||||
//
|
||||
// @Bean(BeanIds.AUTHENTICATION_MANAGER)
|
||||
// @Override
|
||||
// public AuthenticationManager authenticationManagerBean() throws Exception {
|
||||
// return super.authenticationManagerBean();
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public PasswordEncoder passwordEncoder() {
|
||||
// return new BCryptPasswordEncoder();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @param http
|
||||
// * @throws Exception
|
||||
// */
|
||||
// @Override
|
||||
// protected void configure(HttpSecurity http) throws Exception {
|
||||
// http
|
||||
// .cors()
|
||||
// .and()
|
||||
// .csrf()
|
||||
// .disable()
|
||||
// .exceptionHandling()
|
||||
// .authenticationEntryPoint(unauthorizedHandler)
|
||||
// .and()
|
||||
// .sessionManagement()
|
||||
// .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||
// .and()
|
||||
// .authorizeRequests()
|
||||
// .antMatchers("/",
|
||||
// "/favicon.ico",
|
||||
// "/**/*.png",
|
||||
// "/**/*.gif",
|
||||
// "/**/*.svg",
|
||||
// "/**/*.jpg",
|
||||
// "/**/*.html",
|
||||
// "/**/*.css",
|
||||
// "/**/*.js")
|
||||
// .permitAll()
|
||||
// .antMatchers(AUTH_WHITELIST).permitAll()
|
||||
// .antMatchers("/api/auth/**")
|
||||
// .permitAll()
|
||||
// .antMatchers("/api/user/checkUsernameAvailability", "/api/user/checkEmailAvailability")
|
||||
// .permitAll()
|
||||
// .antMatchers(HttpMethod.GET, "/api/polls/**", "/api/users/**")
|
||||
// .permitAll()
|
||||
// .anyRequest()
|
||||
// .authenticated();
|
||||
//
|
||||
// // Add our custom JWT security filter
|
||||
// http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class);
|
||||
//
|
||||
// }
|
||||
//}
|
||||
@@ -1,11 +1,113 @@
|
||||
package io.gmss.fiscad.configuration;
|
||||
|
||||
|
||||
import io.gmss.fiscad.security.JwtAuthenticationEntryPoint;
|
||||
import io.gmss.fiscad.security.JwtAuthenticationFilter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@EnableWebSecurity
|
||||
@Configuration
|
||||
@EnableMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true)
|
||||
@RequiredArgsConstructor
|
||||
public class SpringSecurityConfig {
|
||||
|
||||
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
|
||||
private final AuthenticationProvider authenticationProvider;
|
||||
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
||||
|
||||
private static final String[] PUBLIC_ENDPOINTS = {
|
||||
"/api/auth/login",
|
||||
"/api/open/**",
|
||||
"/api/synchronisation/references",
|
||||
"/v3/api-docs/**",
|
||||
"/swagger-ui/**",
|
||||
"/swagger-ui.html",
|
||||
"/error",
|
||||
"/api/**" // A ENLEVER AVANT LA MISE EN PRODUCTION
|
||||
};
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||
|
||||
http
|
||||
// Désactivation CSRF car JWT stateless
|
||||
.csrf(AbstractHttpConfigurer::disable)
|
||||
|
||||
// CORS configuration propre
|
||||
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
|
||||
|
||||
// Gestion des exceptions d’authentification
|
||||
.exceptionHandling(exception ->
|
||||
exception.authenticationEntryPoint(jwtAuthenticationEntryPoint)
|
||||
)
|
||||
|
||||
// Stateless session
|
||||
.sessionManagement(session ->
|
||||
session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||
)
|
||||
|
||||
// Configuration des autorisations
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
// Autoriser les requêtes OPTIONS (CORS preflight)
|
||||
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
||||
|
||||
// Endpoints publics
|
||||
.requestMatchers(PUBLIC_ENDPOINTS).permitAll()
|
||||
|
||||
// Tout le reste nécessite authentification
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
|
||||
// Provider d’authentification
|
||||
.authenticationProvider(authenticationProvider)
|
||||
|
||||
// Ajout du filtre JWT avant UsernamePasswordAuthenticationFilter
|
||||
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
|
||||
|
||||
return http.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration CORS centralisée.
|
||||
* ⚠️ En production, remplacer "*" par ton domaine frontend.
|
||||
*/
|
||||
@Bean
|
||||
public CorsConfigurationSource corsConfigurationSource() {
|
||||
return request -> {
|
||||
CorsConfiguration configuration = new CorsConfiguration();
|
||||
|
||||
configuration.setAllowedOrigins(List.of("*")); // ⚠️ restreindre en prod
|
||||
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"));
|
||||
configuration.setAllowedHeaders(List.of("*"));
|
||||
configuration.setAllowCredentials(false);
|
||||
|
||||
return configuration;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
import io.gmss.fiscad.security.JwtAuthenticationEntryPoint;
|
||||
import io.gmss.fiscad.security.JwtAuthenticationFilter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
@@ -27,16 +129,15 @@ public class SpringSecurityConfig {
|
||||
private final JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
|
||||
private final AuthenticationProvider authenticationProvider;
|
||||
private final JwtAuthenticationFilter jwtAuthenticationFilter;
|
||||
|
||||
|
||||
private static final String[] AUTH_WHITELIST = {
|
||||
"/api/**",
|
||||
// "/api/**",
|
||||
"/api/auth/login",
|
||||
"/api/open/**",
|
||||
"/api/synchronisation/references",
|
||||
"/v3/api-docs/**",
|
||||
"/swagger-ui/**",
|
||||
"/swagger-ui.html"
|
||||
"/swagger-ui.html",
|
||||
"/error"
|
||||
|
||||
};
|
||||
|
||||
@@ -58,7 +159,7 @@ public class SpringSecurityConfig {
|
||||
.exceptionHandling(ex -> ex.authenticationEntryPoint(jwtAuthenticationEntryPoint))
|
||||
.authorizeHttpRequests(req ->
|
||||
req
|
||||
//.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
||||
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll()
|
||||
.requestMatchers(AUTH_WHITELIST).permitAll()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
@@ -66,11 +167,8 @@ public class SpringSecurityConfig {
|
||||
.authenticationProvider(authenticationProvider)
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(STATELESS))
|
||||
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
|
||||
|
||||
;
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
@@ -10,10 +10,14 @@ import io.gmss.fiscad.paylaods.dto.PersonneCompletDTO;
|
||||
import io.gmss.fiscad.paylaods.request.RecherchePersonneResquestBody;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.EnquetePayLoadWeb;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb;
|
||||
import io.gmss.fiscad.security.CurrentUser;
|
||||
import io.gmss.fiscad.security.UserPrincipal;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -37,9 +41,9 @@ public class PersonneController {
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<?> createPersonne(@RequestBody @Valid @Validated PersonnePayLoadWeb personnePayLoadWeb) {
|
||||
try {
|
||||
Personne personne = personneService.createPersonne(personnePayLoadWeb);
|
||||
personnePayLoadWeb = personneService.createPersonne(personnePayLoadWeb);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, personne, "Contribuable créé avec succès."),
|
||||
new ApiResponse<>(true, personnePayLoadWeb, "Contribuable créé avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
@@ -100,7 +104,7 @@ public class PersonneController {
|
||||
@GetMapping("/id/{id}")
|
||||
public ResponseEntity<?> getPersonneById(@PathVariable Long id) {
|
||||
try{
|
||||
Optional<Personne> optionalPersonne= personneService.getPersonneById(id);
|
||||
Optional<PersonnePayLoadWeb> optionalPersonne= personneService.getPersonneById(id);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, optionalPersonne.orElse(null), "Personne retrouvée avec succès."),
|
||||
HttpStatus.OK
|
||||
@@ -128,4 +132,54 @@ public class PersonneController {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/all")
|
||||
public ResponseEntity<?> getAllPersonne() {
|
||||
try {
|
||||
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, personneService.getPersonneList(), "Liste des personnes chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
||||
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
||||
FileStorageException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
||||
} catch (NullPointerException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/all-paged")
|
||||
public ResponseEntity<?> getAllPersonnePaged(@CurrentUser UserPrincipal currentUser,@RequestParam int pageNo, @RequestParam int pageSize) {
|
||||
try {
|
||||
Pageable pageable = PageRequest.of(pageNo, pageSize);
|
||||
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, personneService.getPersonneList(pageable), "Liste des personnes chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
} catch (HttpClientErrorException.MethodNotAllowed e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK);
|
||||
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException |
|
||||
FileStorageException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK);
|
||||
} catch (NullPointerException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "api/profile", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@RequestMapping(value = "api/profil", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@SecurityRequirement(name = "bearer")
|
||||
@Tag(name = "Profile")
|
||||
@CrossOrigin(origins = "*")
|
||||
|
||||
@@ -4,5 +4,6 @@ public enum EtatIdentificationPersonne {
|
||||
IFU,
|
||||
NPI,
|
||||
IFU_NPI,
|
||||
NEANT;
|
||||
NEANT,
|
||||
RFU;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,5 @@ package io.gmss.fiscad.enums;
|
||||
|
||||
public enum Origine {
|
||||
WEB,
|
||||
MOBILE,
|
||||
SIGIBE,
|
||||
RFU_LOGIL,
|
||||
ANIP
|
||||
MOBILE
|
||||
}
|
||||
|
||||
@@ -11,5 +11,6 @@ public enum ParametersType {
|
||||
OBJET_RESET_PASSWORD,
|
||||
CORPS_RESET_PASSWORD,
|
||||
OBJET_CREATE_ACCOUNT,
|
||||
CORPS_CREATE_ACCOUNT;
|
||||
CORPS_CREATE_ACCOUNT,
|
||||
TOKEN_IFU_EN_LIGNE ;
|
||||
}
|
||||
|
||||
@@ -2,13 +2,17 @@ package io.gmss.fiscad.implementations.infocad.metier;
|
||||
|
||||
|
||||
import io.gmss.fiscad.entities.infocad.parametre.*;
|
||||
import io.gmss.fiscad.enums.EtatIdentificationPersonne;
|
||||
import io.gmss.fiscad.enums.Origine;
|
||||
import io.gmss.fiscad.exceptions.BadRequestException;
|
||||
import io.gmss.fiscad.exceptions.NotFoundException;
|
||||
|
||||
import io.gmss.fiscad.interfaces.infocad.metier.PersonneService;
|
||||
import io.gmss.fiscad.paylaods.dto.*;
|
||||
import io.gmss.fiscad.paylaods.request.IfuEnLigneRechercheBody;
|
||||
import io.gmss.fiscad.paylaods.request.RecherchePersonneResquestBody;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb;
|
||||
import io.gmss.fiscad.paylaods.response.ifuenligne.IfuEnLigneContribuableResponse;
|
||||
import io.gmss.fiscad.persistence.repositories.decoupage.CommuneRepository;
|
||||
import io.gmss.fiscad.persistence.repositories.decoupage.NationaliteRepository;
|
||||
import io.gmss.fiscad.persistence.repositories.infocad.metier.MembreGroupeRepository;
|
||||
@@ -27,10 +31,12 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import java.time.ZoneId;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PersonneServiceImpl implements PersonneService {
|
||||
@@ -47,25 +53,17 @@ public class PersonneServiceImpl implements PersonneService {
|
||||
private final EntityFromPayLoadService entityFromPayLoadService;
|
||||
private final CallAPIService callAPIService;
|
||||
|
||||
|
||||
@Override
|
||||
public Personne createPersonne(PersonnePayLoadWeb personnePayLoadWeb) throws BadRequestException {
|
||||
// Optional<TypePersonne> optionalTypePersonne = typePersonneRepository.findById(personnePayLoadWeb.getTypePersonneId());
|
||||
//
|
||||
// Optional<Commune> optionalCommune = communeRepository.findById(personnePayLoadWeb.getCommuneId());
|
||||
//
|
||||
//
|
||||
// Optional<Nationalite> optionalNationalite = nationaliteRepository.findById(personnePayLoadWeb.getNationaliteId());
|
||||
//
|
||||
// Optional<SituationMatrimoniale> optionalQuartier = situationMatrimonialeRepository.findById(personnePayLoadWeb.getSituationMatrimonialeId());
|
||||
//
|
||||
// Optional<Profession> optionalProfession = professionRepository.findById(personnePayLoadWeb.getProfessionId());
|
||||
//
|
||||
public PersonnePayLoadWeb createPersonne(PersonnePayLoadWeb personnePayLoadWeb) throws BadRequestException {
|
||||
|
||||
Personne personne = entityFromPayLoadService.getPersonneFromPayLoadWeb(personnePayLoadWeb);
|
||||
return personneRepository.save(personne);
|
||||
personne =personneRepository.save(personne);
|
||||
return personneRepository.findBypersonneId(personne.getId()).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Personne updatePersonne(Long id, PersonnePayLoadWeb personnePayLoadWeb) throws NotFoundException {
|
||||
public PersonnePayLoadWeb updatePersonne(Long id, PersonnePayLoadWeb personnePayLoadWeb) throws NotFoundException {
|
||||
if (personnePayLoadWeb.getId() == null) {
|
||||
throw new BadRequestException("Impossible de mettre à jour une enquête ayant un id null.");
|
||||
}
|
||||
@@ -74,7 +72,8 @@ public class PersonneServiceImpl implements PersonneService {
|
||||
}
|
||||
|
||||
Personne personne = entityFromPayLoadService.getPersonneFromPayLoadWeb(personnePayLoadWeb);
|
||||
return personneRepository.save(personne);
|
||||
personne =personneRepository.save(personne);
|
||||
return personneRepository.findBypersonneId(personne.getId()).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,18 +82,18 @@ public class PersonneServiceImpl implements PersonneService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Personne> getPersonneList(Pageable pageable) {
|
||||
public Page<PersonnePayLoadWeb> getPersonneList(Pageable pageable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Personne> getPersonneList() {
|
||||
public List<PersonnePayLoadWeb> getPersonneList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Personne> getPersonneById(Long id) {
|
||||
return personneRepository.findById(id);
|
||||
public Optional<PersonnePayLoadWeb> getPersonneById(Long id) {
|
||||
return personneRepository.findBypersonneId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -195,15 +194,118 @@ public class PersonneServiceImpl implements PersonneService {
|
||||
);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<PersonnePayLoadWeb> recherchePersonne(RecherchePersonneResquestBody recherchePersonneResquestBody) {
|
||||
//
|
||||
//
|
||||
//
|
||||
// List<PersonnePayLoadWeb> personnePayLoadWebsRfuLoggil = new ArrayList<>();
|
||||
// personnePayLoadWebsRfuLoggil = recherchePersonneLocal(recherchePersonneResquestBody);
|
||||
//
|
||||
// try{
|
||||
//
|
||||
// LocalDate date = recherchePersonneResquestBody.getDateNaissance();
|
||||
// String dateNaissance = date != null
|
||||
// ? date.format(DateTimeFormatter.ISO_LOCAL_DATE)
|
||||
// : null;
|
||||
//
|
||||
// IfuEnLigneRechercheBody ifuEnLigneRechercheBody =new IfuEnLigneRechercheBody();
|
||||
// // ifuEnLigneRechercheBody.setIfu(recherchePersonneResquestBody.getIfu());
|
||||
// ifuEnLigneRechercheBody.setNom(recherchePersonneResquestBody.getNom());
|
||||
// ifuEnLigneRechercheBody.setPrenom(recherchePersonneResquestBody.getPrenom());
|
||||
// ifuEnLigneRechercheBody.setDateNaissance(dateNaissance);
|
||||
//
|
||||
// List<IfuEnLigneContribuableResponse> ifuEnLigneContribuableResponses =callAPIService.callApiRechercheContribIfuEnLigne(ifuEnLigneRechercheBody);
|
||||
// System.out.println(ifuEnLigneContribuableResponses);
|
||||
// if(ifuEnLigneContribuableResponses!=null && !ifuEnLigneContribuableResponses.isEmpty()){
|
||||
// //List<PersonnePayLoadWeb> finalPersonnePayLoadWebsRfuLoggil = personnePayLoadWebsRfuLoggil;
|
||||
// ifuEnLigneContribuableResponses.forEach(ifuEnLigneContribuableResponse -> {
|
||||
// PersonnePayLoadWeb personnePayLoadWeb=new PersonnePayLoadWeb();
|
||||
// personnePayLoadWeb.setSource(Origine.SIGIBE);
|
||||
// personnePayLoadWeb.setNpi(ifuEnLigneContribuableResponse.getNpi());
|
||||
// personnePayLoadWeb.setIfu(ifuEnLigneContribuableResponse.getIfu());
|
||||
// personnePayLoadWeb.setNomMere(ifuEnLigneContribuableResponse.getMotherlastname());
|
||||
// personnePayLoadWeb.setNom(ifuEnLigneContribuableResponse.getLastname());
|
||||
// personnePayLoadWeb.setPrenom(ifuEnLigneContribuableResponse.getFirstname());
|
||||
// personnePayLoadWeb.setPrenomMere(ifuEnLigneContribuableResponse.getBjmotherfirstname());
|
||||
//
|
||||
// Date birthdate = ifuEnLigneContribuableResponse.getBirthdate();
|
||||
// LocalDate localDate = birthdate != null
|
||||
// ? birthdate.toInstant()
|
||||
// .atZone(ZoneId.systemDefault())
|
||||
// .toLocalDate()
|
||||
// : null;
|
||||
// personnePayLoadWeb.setDateNaissanceOuConsti(localDate);
|
||||
// personnePayLoadWeb.setTel1(ifuEnLigneContribuableResponse.getPhonenumber());
|
||||
// personnePayLoadWeb.setLieuNaissance(ifuEnLigneContribuableResponse.getBirthplace());
|
||||
// personnePayLoadWeb.setSexe(ifuEnLigneContribuableResponse.getSexe());
|
||||
//
|
||||
// personnePayLoadWebsRfuLoggil.add(personnePayLoadWeb);
|
||||
// });
|
||||
// }
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// return personnePayLoadWebsRfuLoggil;
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public List<PersonnePayLoadWeb> recherchePersonne(RecherchePersonneResquestBody recherchePersonneResquestBody) {
|
||||
// callAPIService.callGetIfuEnLigneToken();
|
||||
List<PersonnePayLoadWeb> personnePayLoadWebsRfuLoggil = new ArrayList<>();
|
||||
personnePayLoadWebsRfuLoggil = recherchePersonneLocal(recherchePersonneResquestBody);
|
||||
public List<PersonnePayLoadWeb> recherchePersonne(RecherchePersonneResquestBody request) {
|
||||
|
||||
List<PersonnePayLoadWeb> result = new ArrayList<>(
|
||||
recherchePersonneLocal(request)
|
||||
);
|
||||
|
||||
try {
|
||||
// Conversion date en String format yyyy-MM-dd
|
||||
String dateNaissance = Optional.ofNullable(request.getDateNaissance())
|
||||
.map(d -> d.format(DateTimeFormatter.ISO_LOCAL_DATE))
|
||||
.orElse(null);
|
||||
// Construction du body IFU
|
||||
IfuEnLigneRechercheBody ifuRequest = new IfuEnLigneRechercheBody();
|
||||
ifuRequest.setNom(request.getNom());
|
||||
ifuRequest.setPrenom(request.getPrenom());
|
||||
ifuRequest.setDateNaissance(dateNaissance);
|
||||
|
||||
return personnePayLoadWebsRfuLoggil;
|
||||
List<IfuEnLigneContribuableResponse> responses =
|
||||
callAPIService.callApiRechercheContribIfuEnLigne(ifuRequest);
|
||||
|
||||
if (responses == null || responses.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (IfuEnLigneContribuableResponse r : responses) {
|
||||
|
||||
PersonnePayLoadWeb personne = new PersonnePayLoadWeb();
|
||||
personne.setEtatIdentificationPersonne(EtatIdentificationPersonne.IFU);
|
||||
personne.setNpi(r.getNpi());
|
||||
personne.setIfu(r.getIfu());
|
||||
personne.setNomMere(r.getMotherlastname());
|
||||
personne.setNom(r.getLastname());
|
||||
personne.setPrenom(r.getFirstname());
|
||||
personne.setPrenomMere(r.getBjmotherfirstname());
|
||||
personne.setTel1(r.getPhonenumber());
|
||||
personne.setLieuNaissance(r.getBirthplace());
|
||||
personne.setSexe(r.getSexe());
|
||||
|
||||
// Conversion Date → LocalDate
|
||||
Date birthdate = r.getBirthdate();
|
||||
LocalDate localDate = birthdate != null
|
||||
? birthdate.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDate()
|
||||
: null;
|
||||
personne.setDateNaissanceOuConsti(localDate);
|
||||
personne.setEtatIdentificationPersonne(EtatIdentificationPersonne.IFU);
|
||||
result.add(personne);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// logger.error("Erreur appel IFU EN LIGNE", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,17 +14,17 @@ import java.util.Optional;
|
||||
|
||||
public interface PersonneService {
|
||||
|
||||
Personne createPersonne(PersonnePayLoadWeb personnePayLoadWeb) throws BadRequestException;
|
||||
PersonnePayLoadWeb createPersonne(PersonnePayLoadWeb personnePayLoadWeb) throws BadRequestException;
|
||||
|
||||
Personne updatePersonne(Long id, PersonnePayLoadWeb personnePayLoadWeb) throws NotFoundException;
|
||||
PersonnePayLoadWeb updatePersonne(Long id, PersonnePayLoadWeb personnePayLoadWeb) throws NotFoundException;
|
||||
|
||||
void deletePersonne(Long id) throws NotFoundException;
|
||||
|
||||
Page<Personne> getPersonneList(Pageable pageable);
|
||||
Page<PersonnePayLoadWeb> getPersonneList(Pageable pageable);
|
||||
|
||||
List<Personne> getPersonneList();
|
||||
List<PersonnePayLoadWeb> getPersonneList();
|
||||
|
||||
Optional<Personne> getPersonneById(Long id);
|
||||
Optional<PersonnePayLoadWeb> getPersonneById(Long id);
|
||||
PersonneCompletDTO getPersonneComplete(Long id);
|
||||
List<PersonnePayLoadWeb> recherchePersonne(RecherchePersonneResquestBody recherchePersonneResquestBody);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public class ApiResponse<T> {
|
||||
private boolean success;
|
||||
private T object;
|
||||
private String message;
|
||||
|
||||
private int statusCode;
|
||||
|
||||
public ApiResponse(boolean success, String message) {
|
||||
this.success = success;
|
||||
@@ -23,4 +23,9 @@ public class ApiResponse<T> {
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
public ApiResponse(boolean success, T object, String message) {
|
||||
this.success = success;
|
||||
this.object = object;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
package io.gmss.fiscad.paylaods.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
public class IfuEnLigneRechercheBody {
|
||||
private String ifu;
|
||||
// private String ifu;
|
||||
private String nom;
|
||||
private String prenom;
|
||||
private String dateNaissance;
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package io.gmss.fiscad.paylaods.request.crudweb;
|
||||
|
||||
import io.gmss.fiscad.enums.Categorie;
|
||||
import io.gmss.fiscad.enums.EtatIdentificationPersonne;
|
||||
import io.gmss.fiscad.enums.Origine;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class PersonnePayLoadWeb {
|
||||
private Long id;
|
||||
@@ -46,9 +48,9 @@ public class PersonnePayLoadWeb {
|
||||
private String indicatifTel2;
|
||||
private String sexe;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Origine source;
|
||||
private EtatIdentificationPersonne etatIdentificationPersonne;
|
||||
|
||||
public PersonnePayLoadWeb(Long id, String ifu, String nom, String prenom, String raisonSociale, String numRavip, String npi, LocalDate dateNaissanceOuConsti, String lieuNaissance, String tel1, String nomJeuneFille, String nomMere,Origine source) {
|
||||
public PersonnePayLoadWeb(Long id, String ifu, String nom, String prenom, String raisonSociale, String numRavip, String npi, LocalDate dateNaissanceOuConsti, String lieuNaissance, String tel1, String nomJeuneFille, String nomMere,EtatIdentificationPersonne source) {
|
||||
this.id = id;
|
||||
this.ifu = ifu;
|
||||
this.nom = nom;
|
||||
@@ -61,6 +63,6 @@ public class PersonnePayLoadWeb {
|
||||
this.tel1 = tel1;
|
||||
this.nomJeuneFille = nomJeuneFille;
|
||||
this.nomMere = nomMere;
|
||||
this.source = source;
|
||||
this.etatIdentificationPersonne = source;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package io.gmss.fiscad.paylaods.response.ifuenligne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class IfuEnLigneContribuableResponse {
|
||||
private String npi;
|
||||
private String ifu;
|
||||
|
||||
private String mothernpi;
|
||||
private String motherlastname;
|
||||
private String bjfatherlastname;
|
||||
private String bjfatherfirstname;
|
||||
private String bjmotherfirstname;
|
||||
private String fathernpi;
|
||||
|
||||
private String lastname;
|
||||
private String firstname;
|
||||
private String maritalname;
|
||||
|
||||
private Date birthdate;
|
||||
|
||||
private String birthcountrycode;
|
||||
private String birthdepartment;
|
||||
private String birthtown;
|
||||
private String birthdistrict;
|
||||
private String birthvillage;
|
||||
private String birthplace;
|
||||
|
||||
private String residencecountrycode;
|
||||
private String residencedepartment;
|
||||
private String residencetown;
|
||||
private String residencedistrict;
|
||||
private String residencevillage;
|
||||
private String residenceaddress;
|
||||
|
||||
private String phonenumber;
|
||||
private String email;
|
||||
private String nationality;
|
||||
|
||||
private String sexe;
|
||||
|
||||
private String phonenumberindicatif;
|
||||
private String idPhoto;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.gmss.fiscad.paylaods.response.ifuenligne;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class IfuEnLigneLoginResponse {
|
||||
private String accessToken;
|
||||
private String tokenType ;
|
||||
}
|
||||
@@ -5,10 +5,13 @@ import io.gmss.fiscad.paylaods.request.crudweb.DeclarationNcPayloadWeb;
|
||||
import io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb;
|
||||
import io.gmss.fiscad.paylaods.response.statistique.StatistiqueTypeNombreResponse;
|
||||
import io.gmss.fiscad.paylaods.response.restoration.PersonnePayLoad;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import javax.swing.text.html.Option;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -80,7 +83,7 @@ public interface PersonneRepository extends JpaRepository<Personne, Long> {
|
||||
p.tel1,
|
||||
p.nomJeuneFille,
|
||||
p.nomMere,
|
||||
io.gmss.fiscad.enums.Origine.RFU_LOGIL
|
||||
io.gmss.fiscad.enums.EtatIdentificationPersonne.RFU
|
||||
)
|
||||
FROM Personne p
|
||||
WHERE
|
||||
@@ -91,7 +94,7 @@ public interface PersonneRepository extends JpaRepository<Personne, Long> {
|
||||
AND (:prenom IS NULL OR LOWER(trim(p.prenom)) LIKE (CONCAT('%', :prenom, '%')))
|
||||
AND (:raisonSociale IS NULL OR LOWER(trim(p.raisonSociale)) LIKE (CONCAT('%', :raisonSociale, '%')))
|
||||
AND (:nomMere IS NULL OR LOWER(trim(p.nomMere)) LIKE (CONCAT('%', :nomMere, '%')))
|
||||
AND (:dateNaissance IS NULL OR p.dateNaissanceOuConsti = :dateNaissance)
|
||||
AND p.dateNaissanceOuConsti =COALESCE(:dateNaissance, p.dateNaissanceOuConsti)
|
||||
"""
|
||||
)
|
||||
List<PersonnePayLoadWeb> findByFiltersInBaseIfuNpiCorrecte(
|
||||
@@ -105,4 +108,82 @@ public interface PersonneRepository extends JpaRepository<Personne, Long> {
|
||||
);
|
||||
|
||||
|
||||
// AND (:dateNaissance IS NULL OR p.dateNaissanceOuConsti = :dateNaissance)
|
||||
|
||||
|
||||
@Query( """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb(
|
||||
p.id,
|
||||
p.ifu,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.numRavip,
|
||||
p.npi,
|
||||
p.dateNaissanceOuConsti,
|
||||
p.lieuNaissance,
|
||||
p.tel1,
|
||||
p.nomJeuneFille,
|
||||
p.nomMere,
|
||||
p.etatIdentificationPersonne
|
||||
)
|
||||
FROM Personne p
|
||||
WHERE p.id = :personneId
|
||||
|
||||
"""
|
||||
)
|
||||
Optional<PersonnePayLoadWeb> findBypersonneId(
|
||||
@Param("personneId") Long personneId
|
||||
);
|
||||
|
||||
|
||||
@Query( """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb(
|
||||
p.id,
|
||||
p.ifu,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.numRavip,
|
||||
p.npi,
|
||||
p.dateNaissanceOuConsti,
|
||||
p.lieuNaissance,
|
||||
p.tel1,
|
||||
p.nomJeuneFille,
|
||||
p.nomMere,
|
||||
p.etatIdentificationPersonne
|
||||
)
|
||||
FROM Personne p
|
||||
"""
|
||||
)
|
||||
List<PersonnePayLoadWeb> findAllPersonneToDto();
|
||||
|
||||
@Query(
|
||||
value = """
|
||||
SELECT new io.gmss.fiscad.paylaods.request.crudweb.PersonnePayLoadWeb(
|
||||
p.id,
|
||||
p.ifu,
|
||||
p.nom,
|
||||
p.prenom,
|
||||
p.raisonSociale,
|
||||
p.numRavip,
|
||||
p.npi,
|
||||
p.dateNaissanceOuConsti,
|
||||
p.lieuNaissance,
|
||||
p.tel1,
|
||||
p.nomJeuneFille,
|
||||
p.nomMere,
|
||||
p.etatIdentificationPersonne
|
||||
)
|
||||
FROM Personne p
|
||||
""",
|
||||
countQuery = """
|
||||
SELECT COUNT(p)
|
||||
FROM Personne p
|
||||
"""
|
||||
)
|
||||
Page<PersonnePayLoadWeb> findAllPersonneToDto(Pageable pageable);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,27 +1,35 @@
|
||||
package io.gmss.fiscad.service;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.gmss.fiscad.entities.Parameters;
|
||||
import io.gmss.fiscad.enums.ParametersType;
|
||||
import io.gmss.fiscad.interfaces.ParametersRepository;
|
||||
import io.gmss.fiscad.paylaods.ApiResponse;
|
||||
import io.gmss.fiscad.paylaods.request.IfuEnLigneLoginBoby;
|
||||
import io.gmss.fiscad.paylaods.request.IfuEnLigneRechercheBody;
|
||||
import io.gmss.fiscad.paylaods.response.ifuenligne.IfuEnLigneContribuableResponse;
|
||||
import io.gmss.fiscad.paylaods.response.ifuenligne.IfuEnLigneLoginResponse;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.server.MethodNotAllowedException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class CallAPIService {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate ;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(CallAPIService.class);
|
||||
|
||||
@@ -34,10 +42,11 @@ public class CallAPIService {
|
||||
private String ifuEnLigneUserName;
|
||||
@Value("${ifu-en-ligne.api.password}")
|
||||
private String ifuEnLignePassWord;
|
||||
private String ifuEnLigneToken ;
|
||||
private String ifuEnLigneToken=null ;
|
||||
|
||||
public RestTemplate executeRestemplate(String localTokenName,String accessToken){
|
||||
RestTemplate restTemplate = new RestTemplateBuilder(rt-> rt.getInterceptors().add((request, body, execution) -> {
|
||||
|
||||
if(localTokenName!=null) {
|
||||
request.getHeaders().add(localTokenName, accessToken);
|
||||
}
|
||||
@@ -48,37 +57,69 @@ public class CallAPIService {
|
||||
return restTemplate;
|
||||
}
|
||||
|
||||
public String callGetIfuEnLigneToken(){
|
||||
|
||||
try {
|
||||
String url = ifuEnLigneBaseUrl+"/api/auth/signin" ;
|
||||
IfuEnLigneLoginBoby ifuEnLigneLoginBoby=new IfuEnLigneLoginBoby();
|
||||
ifuEnLigneLoginBoby.setUsernameOrEmail(ifuEnLigneUserName);
|
||||
ifuEnLigneLoginBoby.setPassword(ifuEnLignePassWord);
|
||||
System.out.println("JE SUIS DANS LE CALL API : "+url);
|
||||
HttpEntity<IfuEnLigneLoginBoby> request = new HttpEntity<>(ifuEnLigneLoginBoby);
|
||||
// public RestTemplate executeRestemplate(String accessToken) {
|
||||
//
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
//
|
||||
// restTemplate.getInterceptors().add((request, body, execution) -> {
|
||||
// System.out.println("LE TOKEN dans execute");
|
||||
// System.out.println(accessToken);
|
||||
// if (accessToken != null && !accessToken.isBlank()) {
|
||||
// request.getHeaders().setBearerAuth(accessToken);
|
||||
// }
|
||||
//
|
||||
// request.getHeaders().setAccept(List.of(MediaType.APPLICATION_JSON));
|
||||
// request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
|
||||
//
|
||||
// return execution.execute(request, body);
|
||||
// });
|
||||
//
|
||||
// return restTemplate;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
public IfuEnLigneLoginResponse callGetIfuEnLigneToken() {
|
||||
|
||||
try {
|
||||
|
||||
String url = ifuEnLigneBaseUrl + "api/auth/signin";
|
||||
|
||||
IfuEnLigneLoginBoby body = new IfuEnLigneLoginBoby();
|
||||
body.setUsernameOrEmail(ifuEnLigneUserName);
|
||||
body.setPassword(ifuEnLignePassWord);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setBearerAuth(ifuEnLigneToken);
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
||||
|
||||
HttpEntity<IfuEnLigneLoginBoby> request =
|
||||
new HttpEntity<>(body, headers);
|
||||
|
||||
RestTemplate restTemplate = executeRestemplate(null, null);
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class);
|
||||
|
||||
if(response.getStatusCodeValue()==200){
|
||||
return response.getBody() ;
|
||||
}else{
|
||||
System.out.println(response.getStatusCodeValue());
|
||||
ResponseEntity<IfuEnLigneLoginResponse> response =
|
||||
restTemplate.exchange(
|
||||
url,
|
||||
HttpMethod.POST,
|
||||
request,
|
||||
IfuEnLigneLoginResponse.class
|
||||
);
|
||||
|
||||
// sygmApiResponse.setStatut(false);
|
||||
|
||||
// sygmApiResponse.setMessage("HttpStatus "+response.getStatusCodeValue()+" --- "
|
||||
// +response.getBody().toString());
|
||||
// return sygmApiResponse;
|
||||
return null;
|
||||
if (response.getStatusCode().is2xxSuccessful()) {
|
||||
return response.getBody();
|
||||
}
|
||||
}catch (Exception e ){
|
||||
System.out.println("IFU EN LIGNE : "+e.getMessage()) ;
|
||||
e.printStackTrace();
|
||||
//throw new Exception(e.getMessage()) ;
|
||||
return null;
|
||||
|
||||
throw new RuntimeException("Erreur IFU : " + response.getStatusCode());
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
throw new RuntimeException("IFU EN LIGNE ERREUR : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -107,32 +148,105 @@ public class CallAPIService {
|
||||
// }
|
||||
|
||||
|
||||
public void callApiRechercheContribIfuEnLigne(IfuEnLigneRechercheBody ifuEnLigneRechercheBody) {
|
||||
// public void callApiRechercheContribIfuEnLigne(IfuEnLigneRechercheBody ifuEnLigneRechercheBody) {
|
||||
// try {
|
||||
// String url = ifuEnLigneBaseUrl+"/api/contribuable/fiscad";
|
||||
// //ApiResponse
|
||||
// RestTemplate restTemplate = executeRestemplate("Authorization",ifuEnLigneToken);
|
||||
// ResponseEntity<List<IfuEnLigneContribuableResponse>> response = restTemplate.getForEntity(url,ifuEnLigneRechercheBody, IfuEnLigneContribuableResponse.class);
|
||||
// if(response.getStatusCode().value()==200){
|
||||
// System.out.println(response.getBody());
|
||||
// }
|
||||
// } catch (
|
||||
// MethodNotAllowedException ex) {
|
||||
// logger.error(ex.toString());
|
||||
// //return new ResponseEntity(null, HttpStatus.METHOD_NOT_ALLOWED);
|
||||
// } catch (Exception e) {
|
||||
// logger.error(e.toString());
|
||||
// // return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
public List<IfuEnLigneContribuableResponse> callApiRechercheContribIfuEnLigne(
|
||||
IfuEnLigneRechercheBody requestBody) {
|
||||
|
||||
ensureToken();
|
||||
|
||||
String url = ifuEnLigneBaseUrl + "/api/contribuable/fiscad";
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setBearerAuth(ifuEnLigneToken);
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
||||
|
||||
HttpEntity<IfuEnLigneRechercheBody> httpEntity= new HttpEntity<>(requestBody,headers);
|
||||
|
||||
System.out.println(httpEntity.getBody());
|
||||
|
||||
System.out.println("BODY SENT:"+ requestBody);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
try {
|
||||
String url = ifuEnLigneBaseUrl+"/api/contribuable/fiscad";
|
||||
String token = callGetIfuEnLigneToken();
|
||||
RestTemplate restTemplate = executeRestemplate(null,null);
|
||||
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class);
|
||||
if(response.getStatusCode().value()==200){
|
||||
System.out.println(response.getBody());
|
||||
}
|
||||
} catch (
|
||||
MethodNotAllowedException ex) {
|
||||
logger.error(ex.toString());
|
||||
//return new ResponseEntity(null, HttpStatus.METHOD_NOT_ALLOWED);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString());
|
||||
// return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
System.out.println("JSON REAL SENT = " + mapper.writeValueAsString(requestBody));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ResponseEntity<ApiResponse<List<IfuEnLigneContribuableResponse>>> response =
|
||||
restTemplate.exchange(
|
||||
url,
|
||||
HttpMethod.POST,
|
||||
httpEntity,
|
||||
new ParameterizedTypeReference<>() {}
|
||||
);
|
||||
|
||||
ApiResponse<List<IfuEnLigneContribuableResponse>> body = response.getBody();
|
||||
|
||||
if (body == null) {
|
||||
throw new RuntimeException("Réponse API IFU vide");
|
||||
}
|
||||
|
||||
if (!body.isSuccess()) {
|
||||
throw new RuntimeException("API IFU erreur : " + body.getMessage());
|
||||
}
|
||||
|
||||
return body.getObject();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
|
||||
// @PostConstruct
|
||||
private synchronized void ensureToken() {
|
||||
|
||||
if (ifuEnLigneToken != null && !ifuEnLigneToken.isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<Parameters> optional =
|
||||
parametersRepository.findFirstByName(ParametersType.TOKEN_IFU_EN_LIGNE);
|
||||
|
||||
if (optional.isPresent()) {
|
||||
ifuEnLigneToken = optional.get().getValue();
|
||||
return;
|
||||
}
|
||||
|
||||
IfuEnLigneLoginResponse loginResponse = callGetIfuEnLigneToken();
|
||||
|
||||
if (loginResponse == null || loginResponse.getAccessToken() == null) {
|
||||
throw new RuntimeException("Impossible d'obtenir le token IFU");
|
||||
}
|
||||
|
||||
ifuEnLigneToken = loginResponse.getAccessToken();
|
||||
|
||||
Parameters parameters = new Parameters();
|
||||
parameters.setName(ParametersType.TOKEN_IFU_EN_LIGNE);
|
||||
parameters.setValue(ifuEnLigneToken);
|
||||
parametersRepository.save(parameters);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -496,6 +496,7 @@ public class EntityFromPayLoadService {
|
||||
personne.setNumRavip(personnePayLoadWeb.getNumRavip());
|
||||
personne.setObservation(personnePayLoadWeb.getObservation());
|
||||
personne.setSexe(personnePayLoadWeb.getSexe());
|
||||
personne.setEtatIdentificationPersonne(personnePayLoadWeb.getEtatIdentificationPersonne());
|
||||
|
||||
return personne ;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user