diff --git a/src/main/java/io/gmss/fiscad/component/DataLoadConfig.java b/src/main/java/io/gmss/fiscad/component/DataLoadConfig.java index d463de1..6b20ce0 100755 --- a/src/main/java/io/gmss/fiscad/component/DataLoadConfig.java +++ b/src/main/java/io/gmss/fiscad/component/DataLoadConfig.java @@ -1,5 +1,6 @@ package io.gmss.fiscad.component; +import io.gmss.fiscad.entities.user.Profile; import io.gmss.fiscad.entities.user.Role; import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.enums.UserRole; @@ -42,17 +43,13 @@ public class DataLoadConfig { public void loadRoles() { - if (roleRepository.count() > 0) return; Set roles = new HashSet<>(); - roles.add(new Role(UserRole.ROLE_USER, "Role attribué aux utilisateurs simples.")); - roles.add(new Role(UserRole.ROLE_ADMIN, "Role attribué aux administrateurs du système.")); - roles.add(new Role(UserRole.ROLE_DIRECTEUR, "Role attribué aux directeurs des structures.")); - roles.add(new Role(UserRole.ROLE_SUPERVISEUR, "Role attribué aux superviseurs des structures sur le terrain.")); - roles.add(new Role(UserRole.ROLE_ENQUETEUR, "Role attribué aux enquêteurs des structures sur le terrain.")); - roles.add(new Role(UserRole.ROLE_ANONYMOUS, "Role attribué à toutes les personnes qui s'inscrivent en ligne pour le compte d'une structure.")); + roles.add(new Role(UserRole.CREATE_USER, "Peut créer un utilisation.")); + roles.add(new Role(UserRole.READ_USER, "peut lire un utilisation")); + roles.add(new Role(UserRole.UPDATE_USER, "peut modifier un utilisation")); + roles.add(new Role(UserRole.DELETE_USER, "peut supprimer un utilisation")); roleRepository.saveAll(roles); - } public void loadUsers() { @@ -65,9 +62,6 @@ public class DataLoadConfig { admin.setPrenom("Principal"); admin.setPassword(passwordEncoder.encode(passwordFile)); admin.setActive(true); - Set roles = new HashSet<>(); - roles.add(roleRepository.findRoleByNom(UserRole.ROLE_ADMIN).get()); - admin.setRoles(roles); userRepository.save(admin); } } diff --git a/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java b/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java index 6ee92a5..43c83f7 100644 --- a/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java +++ b/src/main/java/io/gmss/fiscad/controllers/decoupage/SecteurDecoupageController.java @@ -3,10 +3,12 @@ package io.gmss.fiscad.controllers.decoupage; import io.gmss.fiscad.entities.decoupage.SecteurDecoupage; import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.interfaces.decoupage.SecteurDecoupageService; +import io.gmss.fiscad.interfaces.decoupage.SecteurService; import io.gmss.fiscad.paylaods.ApiResponse; import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import lombok.AllArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; @@ -18,21 +20,18 @@ import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.client.HttpClientErrorException; - - +@AllArgsConstructor @RestController @RequestMapping(value = "api/secteur-decoupage", produces = MediaType.APPLICATION_JSON_VALUE) @SecurityRequirement(name = "bearer") @Tag(name = "SecteurDecoupage") -@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") +//@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") public class SecteurDecoupageController { private final SecteurDecoupageService secteurDecoupageService; + private final SecteurService secteurService; private static final Logger logger = LoggerFactory.getLogger(SecteurDecoupageController.class); - public SecteurDecoupageController(SecteurDecoupageService secteurDecoupageService) { - this.secteurDecoupageService = secteurDecoupageService; - } @PostMapping("/create") @@ -177,4 +176,28 @@ public class SecteurDecoupageController { } + @GetMapping("/arbre/user-id/{userId}") + public ResponseEntity getArborescenceByUserId(@PathVariable Long userId) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, secteurService.getStatParcelleDecoupageByUserId(userId), "SecteurDecoupage trouvé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); + } + } + + } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/controllers/infocad/metier/ParcelleController.java b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/ParcelleController.java new file mode 100644 index 0000000..aa1220a --- /dev/null +++ b/src/main/java/io/gmss/fiscad/controllers/infocad/metier/ParcelleController.java @@ -0,0 +1,222 @@ +package io.gmss.fiscad.controllers.infocad.metier; + +import io.gmss.fiscad.entities.infocad.metier.Enquete; +import io.gmss.fiscad.entities.infocad.metier.Parcelle; +import io.gmss.fiscad.exceptions.*; +import io.gmss.fiscad.interfaces.infocad.metier.EnqueteService; +import io.gmss.fiscad.interfaces.infocad.metier.ParcelleService; +import io.gmss.fiscad.paylaods.ApiResponse; +import io.gmss.fiscad.paylaods.request.EnqueteTraitementPayLoad; +import io.gmss.fiscad.paylaods.request.FiltreEnquetePayLoad; +import io.gmss.fiscad.paylaods.request.crudweb.EnquetePayLoadWeb; +import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +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; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; + +import java.util.List; + +@RestController +@RequestMapping(value = "api/parcelle", produces = MediaType.APPLICATION_JSON_VALUE) +@SecurityRequirement(name = "bearer") +@Tag(name = "Parcelle") +@CrossOrigin(origins = "*") +//@PreAuthorize("hasRole('ADMIN') or hasRole('SUPERVISEUR') or hasRole('ENQUETEUR')") +public class ParcelleController { + + private final EnqueteService enqueteService; + private final ParcelleService parcelleService; + + private static final Logger logger = LoggerFactory.getLogger(ParcelleController.class); + + public ParcelleController(EnqueteService enqueteService, ParcelleService parcelleService) { + this.enqueteService = enqueteService; + this.parcelleService = parcelleService; + } + + + @PostMapping("/create") + public ResponseEntity createParcelle(@RequestBody @Valid @Validated ParcellePayLoadWeb parcellePayLoadWeb) { + try { + Parcelle parcelle = parcelleService.createParcelle(parcellePayLoadWeb); + return new ResponseEntity<>( + new ApiResponse<>(true, parcelle, "parcelle créé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); + } + + } + + @PutMapping("/update/{id}") + public ResponseEntity updateEnquete(@PathVariable Long id, @RequestBody ParcellePayLoadWeb parcellePayLoadWeb) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, parcelleService.updateParcelle(id,parcellePayLoadWeb), "parcelle mise à jour 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); + } + } + + + + @DeleteMapping("/delete/{id}") + public ResponseEntity deleteStructurer(@PathVariable Long id) { + try { + parcelleService.deleteParcelle(id); + return new ResponseEntity<>( + new ApiResponse<>(true, "parcelle supprimé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") + public ResponseEntity getAllParcelle() { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, parcelleService.getParcelleList(), "Liste des enquetes 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/by-decoupage") + public ResponseEntity getAllByDecoupage() { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, enqueteService.getEnqueteCommuneArrondBloc(), "Liste des enquetes 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 getAllEnquetePaged(@RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, parcelleService.getParcelleList(pageable), "Liste des enquetes 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("/id/{id}") + public ResponseEntity getStructureById(@PathVariable Long id) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, parcelleService.getParcelleById(id), "enquete trouvé 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); + } + } + + + +} + diff --git a/src/main/java/io/gmss/fiscad/controllers/user/AuthController.java b/src/main/java/io/gmss/fiscad/controllers/user/AuthController.java index 02a9a4a..26d3adf 100755 --- a/src/main/java/io/gmss/fiscad/controllers/user/AuthController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/AuthController.java @@ -124,9 +124,8 @@ public class AuthController { user.setUsername(userRequest.getEmail()); user.setPassword(userRequest.getPassword()); user.setActive(false); - Set roleSet = new HashSet<>(); - roleSet.add(roleService.getRoleByRoleName(UserRole.ROLE_ANONYMOUS).get()); - user.setRoles(roleSet); + //Set roleSet = new HashSet<>(); + //user.setAvoirFonctions(roleSet); user.setStructure(structureService.getStructureById(userRequest.getStructureId()).get()); return user; } diff --git a/src/main/java/io/gmss/fiscad/controllers/user/AvoirFonctionController.java b/src/main/java/io/gmss/fiscad/controllers/user/AvoirFonctionController.java new file mode 100755 index 0000000..348f5dd --- /dev/null +++ b/src/main/java/io/gmss/fiscad/controllers/user/AvoirFonctionController.java @@ -0,0 +1,206 @@ +package io.gmss.fiscad.controllers.user; + + +import io.gmss.fiscad.entities.user.AvoirFonction; +import io.gmss.fiscad.exceptions.*; +import io.gmss.fiscad.interfaces.user.AvoirFonctionService; +import io.gmss.fiscad.paylaods.ApiResponse; +import io.gmss.fiscad.paylaods.request.crudweb.AvoirFonctionPaylaodWeb; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +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; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; + + +@RestController +@RequestMapping(value = "api/fonction-utilisateur", produces = MediaType.APPLICATION_JSON_VALUE) +@SecurityRequirement(name = "bearer") +@Tag(name = "Fonction Utilisateur") +@CrossOrigin(origins = "*") +public class AvoirFonctionController { + + private final AvoirFonctionService avoirFonctionService; + private static final Logger logger = LoggerFactory.getLogger(AvoirFonctionController.class); + + public AvoirFonctionController(AvoirFonctionService avoirFonctionService) { + this.avoirFonctionService = avoirFonctionService; + } + + + @PostMapping("/create") + public ResponseEntity createAvoirFonction(@RequestBody @Valid @Validated AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb ) { + try { + AvoirFonction avoirFonction = avoirFonctionService.createAvoirFonction(avoirFonctionPaylaodWeb); + return new ResponseEntity<>( + new ApiResponse<>(true, avoirFonction, "Fonction utilisateur créé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); + } + } + + + @PutMapping("/update/{id}") + public ResponseEntity updateAvoirFonction(@PathVariable Long id, @RequestBody AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, avoirFonctionService.updateAvoirFonction(id, avoirFonctionPaylaodWeb), "Fonction utilisateur mise à jour 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); + } + } + + @DeleteMapping("/delete/{id}") + public ResponseEntity deleteAvoirFonction(@PathVariable Long id) { + try { + avoirFonctionService.deleteAvoirFonction(id); + return new ResponseEntity<>( + new ApiResponse<>(true, "Fonction Utilisateur supprimé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") + public ResponseEntity getAll() { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, avoirFonctionService.getAvoirFonctionList(), "Liste des fonctions utilisateur."), + 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("/id/{id}") + public ResponseEntity getById(@PathVariable Long id) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, avoirFonctionService.getAvoirFonctionById(id), "Fonction utilisateur trouvés 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("/utilisateur-id/{userId}") + public ResponseEntity getByUserId(@PathVariable Long userId) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, avoirFonctionService.getUserAvoirFonctionById(userId), "Fonctions de utilisateur trouvées 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 getAllPaged(@RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, avoirFonctionService.getAvoirFonctionList(pageable), "Liste des fonction utilisateurs."), + 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); + } + } + +} diff --git a/src/main/java/io/gmss/fiscad/controllers/user/DemandeReinitialisationMPController.java b/src/main/java/io/gmss/fiscad/controllers/user/DemandeReinitialisationMPController.java index c680ca9..2ce55a8 100644 --- a/src/main/java/io/gmss/fiscad/controllers/user/DemandeReinitialisationMPController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/DemandeReinitialisationMPController.java @@ -113,31 +113,18 @@ public class DemandeReinitialisationMPController { } } - @GetMapping("/all") - public ResponseEntity getAllDemandeReinitialisationMPList(@CurrentUser UserPrincipal userPrincipal) { - try { - - User user = userPrincipal.getUser(); - - if (user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))) { - return new ResponseEntity<>( - new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPList(), "Liste des demande de Reinitialisation chargée avec succès."), - HttpStatus.OK - ); - } else { - if (user.getStructure() == null) { - return new ResponseEntity<>( - new ApiResponse<>(false, "Cet utilisateur n'est pas dans une structure; on ne peut donc pas afficher les demandes de réinitialisation de mot de passe."), - HttpStatus.OK - ); - } else { - return new ResponseEntity<>( - new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPNonTraiteList(user.getStructure()), "Liste des demande de Reinitialisation chargée avec succès."), - HttpStatus.OK - ); - } - } -// }else { +// @GetMapping("/all") +// public ResponseEntity getAllDemandeReinitialisationMPList(@CurrentUser UserPrincipal userPrincipal) { +// try { +// +// User user = userPrincipal.getUser(); +// +// if (user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))) { +// return new ResponseEntity<>( +// new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPList(), "Liste des demande de Reinitialisation chargée avec succès."), +// HttpStatus.OK +// ); +// } else { // if (user.getStructure() == null) { // return new ResponseEntity<>( // new ApiResponse<>(false, "Cet utilisateur n'est pas dans une structure; on ne peut donc pas afficher les demandes de réinitialisation de mot de passe."), @@ -150,22 +137,35 @@ public class DemandeReinitialisationMPController { // ); // } // } - } 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); - } - - } +//// }else { +//// if (user.getStructure() == null) { +//// return new ResponseEntity<>( +//// new ApiResponse<>(false, "Cet utilisateur n'est pas dans une structure; on ne peut donc pas afficher les demandes de réinitialisation de mot de passe."), +//// HttpStatus.OK +//// ); +//// } else { +//// return new ResponseEntity<>( +//// new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPNonTraiteList(user.getStructure()), "Liste des demande de Reinitialisation 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 getAllDemandeReinitialisationMPPaged(@RequestParam int pageNo, @RequestParam int pageSize) { diff --git a/src/main/java/io/gmss/fiscad/controllers/user/FonctionController.java b/src/main/java/io/gmss/fiscad/controllers/user/FonctionController.java new file mode 100644 index 0000000..aacb919 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/controllers/user/FonctionController.java @@ -0,0 +1,179 @@ +package io.gmss.fiscad.controllers.user; + + +import io.gmss.fiscad.entities.user.Fonction; +import io.gmss.fiscad.exceptions.*; +import io.gmss.fiscad.interfaces.rfu.metier.FonctionService; +import io.gmss.fiscad.paylaods.ApiResponse; +import io.gmss.fiscad.paylaods.request.crudweb.FonctionPaylaodWeb; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +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; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; + + +@RestController +@RequestMapping(value = "api/fonction", produces = MediaType.APPLICATION_JSON_VALUE) +@SecurityRequirement(name = "bearer") +@Tag(name = "Fonction") +@CrossOrigin(origins = "*") +public class FonctionController { + + private final FonctionService fonctionService; + + private static final Logger logger = LoggerFactory.getLogger(FonctionController.class); + + public FonctionController(FonctionService fonctionService) { + this.fonctionService = fonctionService; + } + + @PostMapping("/create") + public ResponseEntity createFonction(@RequestBody @Valid @Validated FonctionPaylaodWeb fonctionPaylaodWeb) { + try { + Fonction fonction = fonctionService.createFonction(fonctionPaylaodWeb); + return new ResponseEntity<>( + new ApiResponse<>(true, fonction, "Secteur affecté 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); + } + } + + @PutMapping("/update/{id}") + public ResponseEntity updateFonction(@PathVariable Long id, @RequestBody FonctionPaylaodWeb fonctionPaylaodWeb) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, fonctionService.updateFonction(id, fonctionPaylaodWeb), "Affectation de Secteur mise à jour 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); + } + } + + @DeleteMapping("/delete/{id}") + public ResponseEntity deleteFonction(@PathVariable Long id) { + try { + fonctionService.deleteFonction(id); + return new ResponseEntity<>( + new ApiResponse<>(true, "Fonction supprimé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") + public ResponseEntity getAllFonctionList() { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, fonctionService.getFonctionList(), "Liste des caractéristiques 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 getAllFonctionPaged(@RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + return new ResponseEntity<>( + new ApiResponse<>(true, fonctionService.getFonctionList(pageable), "Liste des caractéristiques 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("/id/{id}") + public ResponseEntity getFonctionById(@PathVariable Long id) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, fonctionService.getFonctionById(id), "Fonction trouvé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); + } + } +} diff --git a/src/main/java/io/gmss/fiscad/controllers/user/ProfileController.java b/src/main/java/io/gmss/fiscad/controllers/user/ProfileController.java new file mode 100755 index 0000000..78be4ad --- /dev/null +++ b/src/main/java/io/gmss/fiscad/controllers/user/ProfileController.java @@ -0,0 +1,182 @@ +package io.gmss.fiscad.controllers.user; + + +import io.gmss.fiscad.entities.user.Profile; +import io.gmss.fiscad.exceptions.*; +import io.gmss.fiscad.interfaces.user.ProfileService; +import io.gmss.fiscad.paylaods.ApiResponse; +import io.gmss.fiscad.paylaods.request.crudweb.ProfilePaylaodWeb; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +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; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.client.HttpClientErrorException; + + +@RestController +@RequestMapping(value = "api/profile", produces = MediaType.APPLICATION_JSON_VALUE) +@SecurityRequirement(name = "bearer") +@Tag(name = "Profile") +@CrossOrigin(origins = "*") +public class ProfileController { + + private final ProfileService profileService; + private static final Logger logger = LoggerFactory.getLogger(ProfileController.class); + + public ProfileController(ProfileService profileService) { + this.profileService = profileService; + } + + + @PostMapping("/create") + public ResponseEntity createProfile(@RequestBody @Valid @Validated ProfilePaylaodWeb profilePaylaodWeb ) { + try { + Profile profile = profileService.createProfile(profilePaylaodWeb); + return new ResponseEntity<>( + new ApiResponse<>(true, profile, "Profile created successully."), + 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); + } + } + + + @PutMapping("/update/{id}") + public ResponseEntity updateProfile(@PathVariable Long id, @RequestBody ProfilePaylaodWeb profilePaylaodWeb) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, profileService.updateProfile(id, profilePaylaodWeb), "Profile updated successully."), + 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); + } + } + + @DeleteMapping("/delete/{id}") + public ResponseEntity deleteProfile(@PathVariable Long id) { + try { + profileService.deleteProfile(id); + return new ResponseEntity<>( + new ApiResponse<>(true, "Profile deleted successully"), + 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") + public ResponseEntity getAll() { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, profileService.getProfileList(), "Liste des profiles."), + 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("/id/{id}") + public ResponseEntity getById(@PathVariable Long id) { + try { + return new ResponseEntity<>( + new ApiResponse<>(true, profileService.getProfileById(id), "Profile trouvé 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 getAllPaged(@RequestParam int pageNo, @RequestParam int pageSize) { + try { + Pageable pageable = PageRequest.of(pageNo, pageSize); + + return new ResponseEntity<>( + new ApiResponse<>(true, profileService.getProfileList(pageable), "Liste des profiles."), + 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); + } + } + +} diff --git a/src/main/java/io/gmss/fiscad/controllers/user/UserController.java b/src/main/java/io/gmss/fiscad/controllers/user/UserController.java index 0de0959..a222c51 100755 --- a/src/main/java/io/gmss/fiscad/controllers/user/UserController.java +++ b/src/main/java/io/gmss/fiscad/controllers/user/UserController.java @@ -165,12 +165,13 @@ public class UserController { try { User user = userService.getUserById(id); - if(containsRoleAnonyme(user.getRoles())){ - return new ResponseEntity<>( - new ApiResponse<>(false, user , "Ce compte n'est pas encore validé."), - HttpStatus.OK - ); - } +// if(user.getAvoirFonctions().isEmpty()){ +// return new ResponseEntity<>( +// new ApiResponse<>(false, user , "Ce compte n'est pas encore validé."), +// HttpStatus.OK +// ); +// } + if(user.isResetPassword()){ return new ResponseEntity<>( new ApiResponse<>(false, user , "Ce compte n'est pas encore validé."), @@ -236,19 +237,10 @@ public class UserController { HttpStatus.OK ); } - User user = userPrincipal.getUser(); - if (user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))) { - return new ResponseEntity<>( - new ApiResponse<>(true, userService.getAllUserListResponse(), "Liste des utilisateurs chargée avec succès."), - HttpStatus.OK - ); - } else { - return new ResponseEntity<>( + return new ResponseEntity<>( new ApiResponse<>(true, userService.getListUserResponseByStructure(userPrincipal.getUser().getStructure().getId()), "Liste des utilisateurs chargée avec succès."), - HttpStatus.OK - ); - } + HttpStatus.OK); } catch (HttpClientErrorException.MethodNotAllowed e) { logger.error(e.getLocalizedMessage()); return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); @@ -373,13 +365,4 @@ public class UserController { return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK); } } - - public boolean containsRoleAnonyme(Set roles){ - for(Role r: roles ){ - if(r.getNom().equals(UserRole.ROLE_ANONYMOUS)){ - return true; - } - } - return false; - } } diff --git a/src/main/java/io/gmss/fiscad/entities/BaseEntity.java b/src/main/java/io/gmss/fiscad/entities/BaseEntity.java index c4c0e61..8114cec 100755 --- a/src/main/java/io/gmss/fiscad/entities/BaseEntity.java +++ b/src/main/java/io/gmss/fiscad/entities/BaseEntity.java @@ -37,4 +37,6 @@ public class BaseEntity implements Serializable { private boolean deleted; private Long externalKey; private Long enqueteExternalKey; + @JsonIgnore + private String source ; } diff --git a/src/main/java/io/gmss/fiscad/entities/decoupage/Quartier.java b/src/main/java/io/gmss/fiscad/entities/decoupage/Quartier.java index 1bab512..8e830f0 100644 --- a/src/main/java/io/gmss/fiscad/entities/decoupage/Quartier.java +++ b/src/main/java/io/gmss/fiscad/entities/decoupage/Quartier.java @@ -24,9 +24,11 @@ public class Quartier extends BaseEntity implements Serializable { private Long id; private String code; private String nom; + private String codeExterne; // @JsonIgnore @ManyToOne private Arrondissement arrondissement; + // @JsonIgnore // @OneToOne(mappedBy = "quartier") // private Bloc bloc; diff --git a/src/main/java/io/gmss/fiscad/entities/decoupage/Secteur.java b/src/main/java/io/gmss/fiscad/entities/decoupage/Secteur.java index 25d09eb..574035f 100644 --- a/src/main/java/io/gmss/fiscad/entities/decoupage/Secteur.java +++ b/src/main/java/io/gmss/fiscad/entities/decoupage/Secteur.java @@ -1,5 +1,6 @@ package io.gmss.fiscad.entities.decoupage; +import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonManagedReference; import io.gmss.fiscad.entities.BaseEntity; import io.gmss.fiscad.entities.infocad.parametre.Structure; @@ -26,16 +27,16 @@ public class Secteur extends BaseEntity implements Serializable { private Long id; private String code; private String nom; - @ManyToOne - private User chefSecteur; + @ManyToOne private Structure structure; + //@JsonBackReference + @ManyToOne + private Section section ; + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "secteur_id") @JsonManagedReference private List secteurDecoupages; - - ///Creer un payload pour la creation de secteur découpage - /// ressource pour envoyer les découpage d'un secteur } diff --git a/src/main/java/io/gmss/fiscad/entities/decoupage/SecteurDecoupage.java b/src/main/java/io/gmss/fiscad/entities/decoupage/SecteurDecoupage.java index 416d62e..380c1ae 100644 --- a/src/main/java/io/gmss/fiscad/entities/decoupage/SecteurDecoupage.java +++ b/src/main/java/io/gmss/fiscad/entities/decoupage/SecteurDecoupage.java @@ -40,12 +40,16 @@ public class SecteurDecoupage extends BaseEntity implements Serializable { @ManyToOne private Secteur secteur; + private String codeSecteur ; + @ManyToOne private Arrondissement arrondissement; @ManyToOne private Quartier quartier; + private String codeQuartier ; + // @JsonIgnore // @OneToMany(mappedBy = "secteurDecoupage") // private List blocs; diff --git a/src/main/java/io/gmss/fiscad/entities/decoupage/Section.java b/src/main/java/io/gmss/fiscad/entities/decoupage/Section.java new file mode 100644 index 0000000..d75bde3 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/entities/decoupage/Section.java @@ -0,0 +1,36 @@ +package io.gmss.fiscad.entities.decoupage; + +import com.fasterxml.jackson.annotation.JsonManagedReference; +import io.gmss.fiscad.entities.BaseEntity; +import io.gmss.fiscad.entities.infocad.parametre.Structure; +import io.gmss.fiscad.entities.user.Fonction; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Where; + +import java.io.Serializable; +import java.util.List; + +@EqualsAndHashCode(callSuper = true) +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +@Where(clause = " deleted = false") +public class Section extends BaseEntity implements Serializable { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String code; + private String nom; + @ManyToOne + private Structure structure; + + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @JoinColumn(name = "section_id") + //@JsonManagedReference + private List fonctionList; +} diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Enquete.java b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Enquete.java index edd8642..7b321db 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Enquete.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Enquete.java @@ -15,6 +15,7 @@ import io.gmss.fiscad.entities.rfu.metier.EnqueteBatiment; import io.gmss.fiscad.entities.rfu.metier.EnqueteUniteLogement; import io.gmss.fiscad.entities.rfu.parametre.Campagne; import io.gmss.fiscad.entities.rfu.parametre.Equipe; +import io.gmss.fiscad.entities.rfu.parametre.Exercice; import io.gmss.fiscad.entities.rfu.parametre.ZoneRfu; import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.enums.StatutEnquete; @@ -55,10 +56,14 @@ public class Enquete extends BaseEntity implements Serializable { private boolean litige; - @JsonIgnore + @ManyToOne private User user; + @JsonIgnore + @ManyToOne + private Exercice exercice; + private Long mobileDataId; @JsonIgnore diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Parcelle.java b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Parcelle.java index 5113477..09486da 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/metier/Parcelle.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/metier/Parcelle.java @@ -59,9 +59,11 @@ public class Parcelle extends BaseEntity implements Serializable { private boolean synchronise; private Long idDerniereEnquete; private Long mobileDataId; - private String numEnterParcelle; + private String numEntreeParcelle; + private String codeQuartier; @ManyToOne private Rue rue ; + private String numeroRue ; // @JsonIgnore // @OneToMany(mappedBy = "parcelle") // private List batiments; diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java index 6f63b09..7dd90fd 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Personne.java @@ -78,10 +78,12 @@ public class Personne extends BaseEntity implements Serializable { @ColumnDefault("0") private int mustHaveRepresentant; private String filePath; + private String observation; @ColumnDefault("false") private boolean synchronise; + @OneToMany(mappedBy = "personne") private List uploads; diff --git a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Structure.java b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Structure.java index 015c868..ed7fda6 100644 --- a/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Structure.java +++ b/src/main/java/io/gmss/fiscad/entities/infocad/parametre/Structure.java @@ -33,7 +33,7 @@ import java.util.Set; "SET deleted = true " + "WHERE id = ?") @Where(clause = " deleted = false") -@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +//@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class Structure extends BaseEntity implements Serializable { @Id @@ -50,7 +50,8 @@ public class Structure extends BaseEntity implements Serializable { @NotNull @ManyToOne private Commune commune; - //@JsonIgnore + + @JsonIgnore @ManyToMany @JoinTable(name = "arrondissements_structures", joinColumns = @JoinColumn(name = "structure_id"), diff --git a/src/main/java/io/gmss/fiscad/entities/rfu/metier/EnqueteBatiment.java b/src/main/java/io/gmss/fiscad/entities/rfu/metier/EnqueteBatiment.java index b9490c2..fec0788 100644 --- a/src/main/java/io/gmss/fiscad/entities/rfu/metier/EnqueteBatiment.java +++ b/src/main/java/io/gmss/fiscad/entities/rfu/metier/EnqueteBatiment.java @@ -11,6 +11,7 @@ import io.gmss.fiscad.entities.infocad.metier.Enquete; import io.gmss.fiscad.entities.infocad.metier.Tpe; import io.gmss.fiscad.entities.infocad.metier.Upload; import io.gmss.fiscad.entities.infocad.parametre.Personne; +import io.gmss.fiscad.entities.rfu.parametre.Caracteristique; import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.enums.StatutEnregistrement; import jakarta.persistence.*; @@ -70,6 +71,10 @@ public class EnqueteBatiment extends BaseEntity implements Serializable { @ManyToOne private Personne personne; + @ManyToOne + @JoinColumn(name = "categorie_caracteristique_id") + private Caracteristique caracteristique; + private Long personneExternalKey; @JsonIgnore diff --git a/src/main/java/io/gmss/fiscad/entities/user/AvoirFonction.java b/src/main/java/io/gmss/fiscad/entities/user/AvoirFonction.java new file mode 100644 index 0000000..a2ec052 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/entities/user/AvoirFonction.java @@ -0,0 +1,67 @@ +package io.gmss.fiscad.entities.user; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.gmss.fiscad.deserializer.LocalDateDeserializer; +import io.gmss.fiscad.entities.BaseEntity; +import io.gmss.fiscad.entities.decoupage.Secteur; +import io.gmss.fiscad.entities.decoupage.Section; +import io.gmss.fiscad.entities.infocad.parametre.Structure; +import io.gmss.fiscad.enums.Titre; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.time.LocalDate; + +@EqualsAndHashCode(callSuper = true) +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +//@SQLDelete(sql = +// "UPDATE parcelle " + +// "SET deleted = true " + +// "WHERE id = ?") +//@Where(clause = " deleted = false") +public class AvoirFonction extends BaseEntity implements Serializable { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @JsonFormat(pattern = "dd-MM-yyyy") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDate dateDebut; + @JsonFormat(pattern = "dd-MM-yyyy") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDate dateFin; + + @JsonIgnore + @ManyToOne //(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "user_id", nullable = false) + @NotNull + private User user; + + @ManyToOne //(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "fonction_id", nullable = false) + @NotNull + private Fonction fonction; + + @Enumerated(EnumType.STRING) + private Titre titre; + + @JsonIgnore + public Long getExternalKey() { + return super.getExternalKey(); + } + @JsonIgnore + public Long getEnqueteExternalKey() { + return super.getEnqueteExternalKey(); + } + + +} diff --git a/src/main/java/io/gmss/fiscad/entities/user/Fonction.java b/src/main/java/io/gmss/fiscad/entities/user/Fonction.java new file mode 100644 index 0000000..d33bf47 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/entities/user/Fonction.java @@ -0,0 +1,67 @@ +package io.gmss.fiscad.entities.user; + +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.gmss.fiscad.deserializer.LocalDateDeserializer; +import io.gmss.fiscad.entities.BaseEntity; +import io.gmss.fiscad.entities.decoupage.Secteur; +import io.gmss.fiscad.entities.decoupage.Section; +import io.gmss.fiscad.entities.infocad.parametre.Structure; +import io.gmss.fiscad.entities.user.User; +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.springframework.stereotype.Service; + +import java.io.Serializable; +import java.time.LocalDate; + +@EqualsAndHashCode(callSuper = true) +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +//@SQLDelete(sql = +// "UPDATE parcelle " + +// "SET deleted = true " + +// "WHERE id = ?") +//@Where(clause = " deleted = false") +public class Fonction extends BaseEntity implements Serializable { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String code ; + private String nom ; + + @JsonBackReference + @ManyToOne + private Secteur secteur; + + @JsonBackReference + @ManyToOne + private Section section; + + //@JsonBackReference + @ManyToOne + private Structure structure; + + //@JsonIgnore + @ManyToOne //(fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "profile_id", nullable = false) + @NotNull + private Profile profile; + + @JsonIgnore + public Long getExternalKey() { + return super.getExternalKey(); + } + @JsonIgnore + public Long getEnqueteExternalKey() { + return super.getEnqueteExternalKey(); + } +} diff --git a/src/main/java/io/gmss/fiscad/entities/user/Profile.java b/src/main/java/io/gmss/fiscad/entities/user/Profile.java new file mode 100755 index 0000000..6a69486 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/entities/user/Profile.java @@ -0,0 +1,78 @@ +package io.gmss.fiscad.entities.user; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import io.gmss.fiscad.entities.BaseEntity; +import io.gmss.fiscad.enums.UserProfile; +import io.gmss.fiscad.enums.UserRole; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +//@EqualsAndHashCode(callSuper = true) +@Data +@AllArgsConstructor +@NoArgsConstructor +@Entity +public class Profile extends BaseEntity implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + @Enumerated(EnumType.STRING) + private UserProfile nom; + private String description; + + public Profile(UserProfile name, String description) { + this.nom = name; + this.description = description; + } + + @ManyToMany(fetch = FetchType.LAZY) + @JoinTable(name = "profile_role", + joinColumns = @JoinColumn(name = "profile_id"), + inverseJoinColumns = @JoinColumn(name = "role_id") + ) + private Set roles = new HashSet<>(); + + + @Override + public boolean equals(Object o) { + + // If the object is compared with itself then return true + if (o == this) { + return true; + } + + /* Check if o is an instance of Complex or not + "null instanceof [type]" also returns false */ + if (!(o instanceof Profile)) { + return false; + } + + // typecast o to Complex so that we can compare data members + Profile r = (Profile) o; + + // Compare the data members and return accordingly + return r.getNom().equals(this.getNom()); + } + + @Override + public int hashCode() { + return Objects.hash(id, nom, description); + } + + @JsonIgnore + public Long getExternalKey() { + return super.getExternalKey(); + } + @JsonIgnore + public Long getEnqueteExternalKey() { + return super.getEnqueteExternalKey(); + } +} diff --git a/src/main/java/io/gmss/fiscad/entities/user/Role.java b/src/main/java/io/gmss/fiscad/entities/user/Role.java index 55edd5a..005c520 100755 --- a/src/main/java/io/gmss/fiscad/entities/user/Role.java +++ b/src/main/java/io/gmss/fiscad/entities/user/Role.java @@ -1,5 +1,6 @@ package io.gmss.fiscad.entities.user; +import com.fasterxml.jackson.annotation.JsonIgnore; import io.gmss.fiscad.entities.BaseEntity; import io.gmss.fiscad.enums.UserRole; import jakarta.persistence.*; @@ -54,4 +55,13 @@ public class Role extends BaseEntity implements Serializable { public int hashCode() { return Objects.hash(id, nom, description); } + + @JsonIgnore + public Long getExternalKey() { + return super.getExternalKey(); + } + @JsonIgnore + public Long getEnqueteExternalKey() { + return super.getEnqueteExternalKey(); + } } diff --git a/src/main/java/io/gmss/fiscad/entities/user/User.java b/src/main/java/io/gmss/fiscad/entities/user/User.java index 983c223..9a77b33 100755 --- a/src/main/java/io/gmss/fiscad/entities/user/User.java +++ b/src/main/java/io/gmss/fiscad/entities/user/User.java @@ -16,6 +16,7 @@ import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; import java.io.Serializable; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -39,6 +40,12 @@ public class User extends BaseEntity implements Serializable { private String prenom; private String tel; private String email; + @Column( + name = "username", + nullable = false, + unique = true, + length = 200 + ) private String username; @JsonIgnore private String password; @@ -46,42 +53,31 @@ public class User extends BaseEntity implements Serializable { private boolean active; @Column(columnDefinition = "boolean default false") private boolean resetPassword; - @ManyToMany - @JoinTable(name = "users_roles", - joinColumns = @JoinColumn(name = "user_id"), - inverseJoinColumns = @JoinColumn(name = "roles_id") - ) - private Set roles; + + @OneToMany(mappedBy = "user") + private Set avoirFonctions= new HashSet<>(); @ManyToOne private Structure structure; -// @JsonIgnore -// @OneToMany(mappedBy = "user") -// private List enquetes; + @JsonIgnore @OneToMany(mappedBy = "user") private List participers; -// @JsonIgnore -// @OneToMany(mappedBy = "chefSecteur") -// private List secteurs; + @Transient private Long idCampagneCourant; @Transient private Long idSecteurCourant; -// public void setUsername(String username) { -// this.username = username; -// } - public boolean isAdmin() { - for (Role r : this.roles) { - if (r.getNom().equals(UserRole.ROLE_ADMIN)) { - return true; - } - } +// for (Role r : this.roles) { +// if (r.getNom().equals(UserRole.ROLE_ADMIN)) { +// return true; +// } +// } return false; } diff --git a/src/main/java/io/gmss/fiscad/enums/Titre.java b/src/main/java/io/gmss/fiscad/enums/Titre.java new file mode 100644 index 0000000..1ec5615 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/enums/Titre.java @@ -0,0 +1,6 @@ +package io.gmss.fiscad.enums; + +public enum Titre { + TITULAIRE, + INTERIMAIRE +} diff --git a/src/main/java/io/gmss/fiscad/enums/UserProfile.java b/src/main/java/io/gmss/fiscad/enums/UserProfile.java new file mode 100644 index 0000000..d5db6d2 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/enums/UserProfile.java @@ -0,0 +1,9 @@ +package io.gmss.fiscad.enums; + +public enum UserProfile { + INSPECTEUR_GESTIONNAIRE, + ADMIN_FONCTIONNEL, + INSPECTEUR_GESTIONNAIRE_CHEF_SECTEUR, + INSPECTEUR_GESTIONNAIRE_CHEF_SECTION, + INSPECTEUR_GESTIONNAIRE_CHEF_CENTRE +} diff --git a/src/main/java/io/gmss/fiscad/enums/UserRole.java b/src/main/java/io/gmss/fiscad/enums/UserRole.java index 03dfe4e..94a46a4 100644 --- a/src/main/java/io/gmss/fiscad/enums/UserRole.java +++ b/src/main/java/io/gmss/fiscad/enums/UserRole.java @@ -2,11 +2,23 @@ package io.gmss.fiscad.enums; public enum UserRole { - ROLE_ADMIN, - ROLE_USER, - ROLE_DIRECTEUR, - ROLE_SUPERVISEUR, - ROLE_ENQUETEUR, - ROLE_ANONYMOUS, - ROLE_RESPONSABLE + ADMIN, + CREATE_USER, + UPDATE_USER, + READ_USER, + DELETE_USER, + CREATE_PARCELLE, + UPDATE_PARCELLE, + READ_PARCELLE, + DELETE_PARCELLE, + CREATE_ENQUETE, + UPDATE_ENQUETE, + READ_ENQUETE, + DELETE_ENQUETE, + CREATE_BATIMENT, + UPDATE_BATIMENT, + READ_BATIMENT, + DELETE_BATIMENT + + } diff --git a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java index c85dc36..660f165 100644 --- a/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/decoupage/SecteurServiceImpl.java @@ -3,40 +3,44 @@ package io.gmss.fiscad.implementations.decoupage; import io.gmss.fiscad.entities.decoupage.Secteur; import io.gmss.fiscad.entities.decoupage.SecteurDecoupage; import io.gmss.fiscad.entities.infocad.parametre.Structure; +import io.gmss.fiscad.entities.user.AvoirFonction; import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.interfaces.decoupage.SecteurService; import io.gmss.fiscad.paylaods.request.synchronisation.SecteurDecoupagePayload; import io.gmss.fiscad.paylaods.request.synchronisation.SecteurPayload; +import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur; import io.gmss.fiscad.repositories.decoupage.ArrondissementRepository; import io.gmss.fiscad.repositories.decoupage.QuartierRepository; import io.gmss.fiscad.repositories.decoupage.SecteurRepository; +import io.gmss.fiscad.repositories.infocad.metier.ParcelleRepository; import io.gmss.fiscad.repositories.infocad.parametre.StructureRepository; +import io.gmss.fiscad.repositories.user.AvoirFonctionRepository; import io.gmss.fiscad.repositories.user.UserRepository; +import lombok.AllArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; +@AllArgsConstructor @Service public class SecteurServiceImpl implements SecteurService { private final SecteurRepository secteurRepository; + private final ParcelleRepository parcelleRepository; private final UserRepository userRepository; private final ArrondissementRepository arrondissementRepository; private final QuartierRepository quartierRepository; private final StructureRepository structureRepository; + private final AvoirFonctionRepository avoirFonctionRepository; + - public SecteurServiceImpl(SecteurRepository secteurRepository, UserRepository userRepository, ArrondissementRepository arrondissementRepository, QuartierRepository quartierRepository, StructureRepository structureRepository) { - this.secteurRepository = secteurRepository; - this.userRepository = userRepository; - this.arrondissementRepository = arrondissementRepository; - this.quartierRepository = quartierRepository; - this.structureRepository = structureRepository; - } @Override @@ -56,7 +60,7 @@ public class SecteurServiceImpl implements SecteurService { private Secteur getSecteurFromPayload(SecteurPayload secteurPayload) { Secteur secteur = new Secteur(); Optional optionalUser = userRepository.findById(secteurPayload.getChefSecteurId()); - secteur.setChefSecteur(optionalUser.orElse(null)); + //secteur.setChefSecteur(optionalUser.orElse(null)); Optional optionalStructure = structureRepository.findById(secteurPayload.getStructureId()); secteur.setStructure(optionalStructure.orElse(null)); List secteurDecoupageList = new ArrayList<>(); @@ -134,4 +138,40 @@ public class SecteurServiceImpl implements SecteurService { public Optional getSecteurById(Long id) { return secteurRepository.findById(id); } + + @Override + public List getStatParcelleDecoupageUnSecteur(Long secteurId) { + return parcelleRepository.findStatsBySecteurs(List.of(secteurId)); + } + + @Override + public List getStatParcelleDecoupageByUserId(Long userId) { + List avoirFonctions= avoirFonctionRepository.findAvoirFonctionByUser_Id(userId); + AtomicReference> parcelleStatsProjectionUnSecteurs = new AtomicReference<>(new ArrayList<>()); + + avoirFonctions.stream() + .filter(af -> af.getDateFin() == null || af.getDateFin().isAfter(LocalDate.now())) + .forEach(avoirFonction -> { + if(avoirFonction.getFonction().getSecteur()!=null){ + parcelleStatsProjectionUnSecteurs.set(parcelleRepository.findStatsBySecteurs(List.of(avoirFonction.getFonction().getSecteur().getId()))); + }else + if (avoirFonction.getFonction().getSection()!=null){ + List secteurs= secteurRepository.findDistinctBySection_Id(avoirFonction.getFonction().getSection().getId()); + List secteurIds = secteurs.stream() + .map(Secteur::getId) + .toList(); + parcelleStatsProjectionUnSecteurs.set(parcelleRepository.findStatsBySecteurs(secteurIds)); + }else if(avoirFonction.getFonction().getStructure()!=null){ + List secteurs= secteurRepository.findDistinctBySection_Structure_Id(avoirFonction.getFonction().getStructure().getId()); + List secteurIds = secteurs.stream() + .map(Secteur::getId) + .toList(); + parcelleStatsProjectionUnSecteurs.set(parcelleRepository.findStatsBySecteurs(secteurIds)); + } + + }); + + + return parcelleStatsProjectionUnSecteurs.get(); + } } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java index 6f41fa1..ef94b51 100644 --- a/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/infocad/metier/ParcelleServiceImpl.java @@ -18,7 +18,9 @@ import io.gmss.fiscad.service.GeometryService; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import java.util.List; @@ -95,6 +97,15 @@ public class ParcelleServiceImpl implements ParcelleService { @Override public Page getParcelleList(Pageable pageable) { + Sort sort = pageable.getSort().isSorted() + ? pageable.getSort() + : Sort.by(Sort.Direction.DESC, "id"); + + Pageable pageableWithSort = PageRequest.of( + pageable.getPageNumber(), + pageable.getPageSize(), + sort + ); return parcelleRepository.findAll(pageable); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteActiviteServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteActiviteServiceImpl.java index 345542a..964292b 100644 --- a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteActiviteServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/EnqueteActiviteServiceImpl.java @@ -26,18 +26,10 @@ public class EnqueteActiviteServiceImpl implements EnqueteActiviteService { if (enqueteActivitePayLoadWeb.getId() != null) { throw new BadRequestException("Il ne s'agit pas ici d'une nouvelle activité : " + enqueteActivitePayLoadWeb.getId()); } - if (enqueteActivitePayLoadWeb.getPersonneId() != null) { - throw new BadRequestException("Il ne s'agit pas ici d'une nouvelle activité : " + enqueteActivitePayLoadWeb.getId()); - } - if (enqueteActivitePayLoadWeb.getId() != null) { - throw new BadRequestException("Il ne s'agit pas ici d'une nouvelle activité : " + enqueteActivitePayLoadWeb.getId()); - } - if (enqueteActivitePayLoadWeb.getId() != null) { - throw new BadRequestException("Il ne s'agit pas ici d'une nouvelle activité : " + enqueteActivitePayLoadWeb.getId()); - } - if (enqueteActivitePayLoadWeb.getId() != null) { - throw new BadRequestException("Il ne s'agit pas ici d'une nouvelle activité : " + enqueteActivitePayLoadWeb.getId()); + if (enqueteActivitePayLoadWeb.getPersonneId() == null) { + throw new BadRequestException("Veuillez préciser le contribuable : " + enqueteActivitePayLoadWeb.getId()); } + EnqueteActivite enqueteActivite = entityFromPayLoadService.getEnqueteActivitePayLoadWeb(enqueteActivitePayLoadWeb); return enqueteActiviteRepository.save(enqueteActivite); } diff --git a/src/main/java/io/gmss/fiscad/implementations/rfu/metier/FonctionServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/FonctionServiceImpl.java new file mode 100644 index 0000000..4abe135 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/implementations/rfu/metier/FonctionServiceImpl.java @@ -0,0 +1,79 @@ +package io.gmss.fiscad.implementations.rfu.metier; + +import io.gmss.fiscad.entities.user.Fonction; +import io.gmss.fiscad.exceptions.BadRequestException; +import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.interfaces.rfu.metier.FonctionService; +import io.gmss.fiscad.paylaods.request.crudweb.FonctionPaylaodWeb; +import io.gmss.fiscad.repositories.rfu.metier.FonctionRepository; +import io.gmss.fiscad.service.EntityFromPayLoadService; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@AllArgsConstructor +@Service +public class FonctionServiceImpl implements FonctionService { + + private final FonctionRepository gererSecteurRepository; + private final EntityFromPayLoadService entityFromPayLoadService; + + + @Override + public Fonction createFonction(FonctionPaylaodWeb fonctionPaylaodWeb) throws BadRequestException { + if (fonctionPaylaodWeb.getId() != null) { + throw new BadRequestException("Impossible de créer un nouveau fonction ayant un id non null."); + } + Fonction fonction = entityFromPayLoadService.getFonctionFromPayLoadWeb(fonctionPaylaodWeb); + + return gererSecteurRepository.save(fonction); + } + + @Override + public Fonction updateFonction(Long id, FonctionPaylaodWeb fonctionPaylaodWeb) throws NotFoundException { + if (fonctionPaylaodWeb.getId() == null) { + throw new BadRequestException("Impossible de mettre à jour un nouveau fonction ayant un id null."); + } + if (!gererSecteurRepository.existsById(fonctionPaylaodWeb.getId())) { + throw new NotFoundException("Impossible de trouver le fonction spécifié dans notre base de données."); + } + Fonction fonction = entityFromPayLoadService.getFonctionFromPayLoadWeb(fonctionPaylaodWeb); + + return gererSecteurRepository.save(fonction); + } + + @Override + public void deleteFonction(Long id) throws NotFoundException { + Optional gererSecteurOptional = gererSecteurRepository.findById(id); + if (gererSecteurOptional.isPresent()) { + gererSecteurRepository.deleteById(gererSecteurOptional.get().getId()); + } else { + throw new NotFoundException("Impossible de trouver le gererSecteur spécifié dans notre base de données."); + } + } + + @Override + public Page getFonctionList(Pageable pageable) { + return gererSecteurRepository.findAll(pageable); + } + + @Override + public List getFonctionList() { + return gererSecteurRepository.findAll(); + } + + + @Override + public Optional getFonctionById(Long id) { + if (gererSecteurRepository.existsById(id)) { + return gererSecteurRepository.findById(id); + } else { + throw new NotFoundException("Impossible de trouver la caractéristique spécifiée dans la base de données."); + } + + } +} diff --git a/src/main/java/io/gmss/fiscad/implementations/user/AvoirFonctionServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/user/AvoirFonctionServiceImpl.java new file mode 100644 index 0000000..d0adead --- /dev/null +++ b/src/main/java/io/gmss/fiscad/implementations/user/AvoirFonctionServiceImpl.java @@ -0,0 +1,82 @@ +package io.gmss.fiscad.implementations.user; + +import io.gmss.fiscad.entities.user.AvoirFonction; +import io.gmss.fiscad.entities.user.AvoirFonction; +import io.gmss.fiscad.exceptions.BadRequestException; +import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.interfaces.user.AvoirFonctionService; +import io.gmss.fiscad.paylaods.request.crudweb.AvoirFonctionPaylaodWeb; +import io.gmss.fiscad.repositories.user.AvoirFonctionRepository; +import io.gmss.fiscad.repositories.user.AvoirFonctionRepository; +import io.gmss.fiscad.service.EntityFromPayLoadService; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; +@AllArgsConstructor +@Service +public class AvoirFonctionServiceImpl implements AvoirFonctionService { + + private final AvoirFonctionRepository avoirFonctionRepository; + private final EntityFromPayLoadService entityFromPayLoadService ; + + @Override + public AvoirFonction createAvoirFonction(AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws BadRequestException { + if (avoirFonctionPaylaodWeb.getId() != null) { + throw new BadRequestException("A new avoirFonction id to save must be null or empty."); + } + AvoirFonction avoirFonction = entityFromPayLoadService.getAvoirFonctionFromPayLoadWeb(avoirFonctionPaylaodWeb); + return avoirFonctionRepository.save(avoirFonction); + } + + @Override + public AvoirFonction updateAvoirFonction(Long id, AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws NotFoundException { + if (avoirFonctionPaylaodWeb.getId() == null) { + throw new BadRequestException("A new avoirFonction id to save must be null or empty."); + } + Optional optionalAvoirFonction= avoirFonctionRepository.findAvoirFonctionById(avoirFonctionPaylaodWeb.getId()); + if(optionalAvoirFonction.isEmpty()){ + throw new BadRequestException("Impossible de trouver la Fonction utilisateur à modifier"); + } + AvoirFonction avoirFonction = entityFromPayLoadService.getAvoirFonctionFromPayLoadWeb(avoirFonctionPaylaodWeb); + return avoirFonctionRepository.save(avoirFonction); + } + + @Override + public void deleteAvoirFonction(Long id) throws NotFoundException { + if (id == null) { + throw new BadRequestException("Impossible de supprimer un avoirFonction null "); + } + Optional optionalAvoirFonction= avoirFonctionRepository.findAvoirFonctionById(id); + if(optionalAvoirFonction.isEmpty()){ + throw new BadRequestException("Impossible de trouver le avoirFonction à supprimer"); + } + avoirFonctionRepository.deleteById(id); + } + + @Override + public Page getAvoirFonctionList(Pageable pageable) { + return avoirFonctionRepository.findAll(pageable); + } + + @Override + public List getAvoirFonctionList() { + return avoirFonctionRepository.findAll(); + } + + + @Override + public Optional getAvoirFonctionById(Long id) { + return avoirFonctionRepository.findAvoirFonctionById(id); + } + + @Override + public List getUserAvoirFonctionById(Long userId) { + return avoirFonctionRepository.findAvoirFonctionByUser_Id(userId); + } + + +} diff --git a/src/main/java/io/gmss/fiscad/implementations/user/ProfileServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/user/ProfileServiceImpl.java new file mode 100644 index 0000000..d83375d --- /dev/null +++ b/src/main/java/io/gmss/fiscad/implementations/user/ProfileServiceImpl.java @@ -0,0 +1,89 @@ +package io.gmss.fiscad.implementations.user; + +import io.gmss.fiscad.entities.user.Profile; +import io.gmss.fiscad.enums.UserProfile; +import io.gmss.fiscad.exceptions.BadRequestException; +import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.interfaces.user.ProfileService; +import io.gmss.fiscad.paylaods.request.crudweb.ProfilePaylaodWeb; +import io.gmss.fiscad.repositories.user.ProfileRepository; +import io.gmss.fiscad.service.EntityFromPayLoadService; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; +@AllArgsConstructor +@Service +public class ProfileServiceImpl implements ProfileService { + + private final ProfileRepository profileRepository; + private final EntityFromPayLoadService entityFromPayLoadService ; + + @Override + public Profile createProfile(ProfilePaylaodWeb profilePaylaodWeb) throws BadRequestException { + if (profilePaylaodWeb.getId() != null) { + throw new BadRequestException("A new profile id to save must be null or empty."); + } + Profile profile = entityFromPayLoadService.getProfileFromPayLoadWeb(profilePaylaodWeb); + return profileRepository.save(profile); + } + + @Override + public Profile updateProfile(Long id, ProfilePaylaodWeb profilePaylaodWeb) throws NotFoundException { + if (profilePaylaodWeb.getId() == null) { + throw new BadRequestException("A new profile id to save must be null or empty."); + } + Optional optionalProfile= profileRepository.findProfileById(profilePaylaodWeb.getId()); + if(optionalProfile.isEmpty()){ + throw new BadRequestException("Impossible de trouver le profile à modifier"); + } + Profile profile = entityFromPayLoadService.getProfileFromPayLoadWeb(profilePaylaodWeb); + return profileRepository.save(profile); + } + + @Override + public void deleteProfile(Long id) throws NotFoundException { + if (id == null) { + throw new BadRequestException("Impossible de supprimer un profile null "); + } + Optional optionalProfile= profileRepository.findProfileById(id); + if(optionalProfile.isEmpty()){ + throw new BadRequestException("Impossible de trouver le profile à supprimer"); + } + profileRepository.deleteById(id); + } + + @Override + public Page getProfileList(Pageable pageable) { + return profileRepository.findAll(pageable); + } + + @Override + public List getProfileList() { + return profileRepository.findAll(); + } + + + @Override + public Optional getProfileById(Long id) { + return profileRepository.findProfileById(id); + } + + @Override + public Optional getProfileByProfileName(UserProfile userProfile) { + return profileRepository.findProfileByNom(userProfile); + } + + @Override + public boolean profileExistByProfileName(UserProfile userProfile) { + return profileRepository.existsByNom(userProfile); + } + + @Override + public Profile retrieveProfileByProfileName(UserProfile userProfile) { + return profileRepository.getProfilesByNom(userProfile); + } +} diff --git a/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java b/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java index f861d38..0151347 100644 --- a/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java +++ b/src/main/java/io/gmss/fiscad/implementations/user/UserServiceImpl.java @@ -59,16 +59,17 @@ public class UserServiceImpl implements UserService { throw new BadRequestException("Cet utilisateur existe déjà dans la base de donnéees."); } - Set roleSet = new HashSet<>(); + // Set roleSet = new HashSet<>(); + +// user.getRoles().stream().forEach(role -> { +// if (roleService.roleExistByRoleName(role.getNom())) { +// roleSet.add(roleService.retrieveRoleByRoleName(role.getNom())); +// } +// }); - user.getRoles().stream().forEach(role -> { - if (roleService.roleExistByRoleName(role.getNom())) { - roleSet.add(roleService.retrieveRoleByRoleName(role.getNom())); - } - }); user.setUsername(user.getEmail()); user.setResetPassword(resetPassword); - user.setRoles(roleSet); + // user.setRoles(roleSet); user.setPassword(passwordEncoder.encode(user.getPassword())); userRepository.save(user); return user; @@ -104,9 +105,9 @@ public class UserServiceImpl implements UserService { String.format("L'utilisateur ayant pour id %s n'existe pas.", id) ) ); - if (user.getRoles() == null || user.getRoles().isEmpty()) { - user.setRoles(user1.getRoles()); - } +// if (user.getRoles() == null || user.getRoles().isEmpty()) { +// user.setRoles(user1.getRoles()); +// } if (user.getPassword() == null || user.getPassword().isBlank()) { user.setPassword(user1.getPassword()); @@ -161,26 +162,28 @@ public class UserServiceImpl implements UserService { @Override public List getActivatedUserListByStructure(Long structureId) { - Set roleSet = new HashSet<>(); - roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS)); - Optional structureOptional = structureService.getStructureById(structureId); - if (structureOptional.isPresent()) { - return userRepository.findAllByStructureAndRolesNotIn(structureOptional.get(), roleSet); - } else { - throw new NotFoundException("Impossible de trouver la structure spécifiée."); - } +// Set roleSet = new HashSet<>(); +// roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS)); +// Optional structureOptional = structureService.getStructureById(structureId); +// if (structureOptional.isPresent()) { +// return userRepository.findAllByStructureAndRolesNotIn(structureOptional.get(), roleSet); +// } else { +// throw new NotFoundException("Impossible de trouver la structure spécifiée."); +// } + return null; } @Override public List getUserUnActivatedListByStructure(Long structureId) { - Set roleSet = new HashSet<>(); - roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS)); - Optional structureOptional = structureService.getStructureById(structureId); - if (structureOptional.isPresent()) { - return userRepository.findAllByStructureAndRolesIn(structureOptional.get(), roleSet); - } else { - throw new NotFoundException("Impossible de trouver la structure spécifiée."); - } +// Set roleSet = new HashSet<>(); +// roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS)); +// Optional structureOptional = structureService.getStructureById(structureId); +// if (structureOptional.isPresent()) { +// return userRepository.findAllByStructureAndRolesIn(structureOptional.get(), roleSet); +// } else { +// throw new NotFoundException("Impossible de trouver la structure spécifiée."); +// } + return null; } private static List getUserResponses(List users) { @@ -194,7 +197,7 @@ public class UserServiceImpl implements UserService { user.getUsername(), user.isActive(), user.isResetPassword(), - user.getRoles(), + user.getAvoirFonctions(), user.getStructure(), user.getIdCampagneCourant(), user.getIdSecteurCourant())) @@ -217,7 +220,8 @@ public class UserServiceImpl implements UserService { @Override public List getUserByProfil(UserRole userRole) { - return userRepository.findAllByRolesContains(userRole); + //return userRepository.findAllByRolesContains(userRole); + return null; } @@ -264,11 +268,11 @@ public class UserServiceImpl implements UserService { User user = userRepository.findByUsername(username).orElseThrow(() -> new NotFoundException( String.format("L'utilisateur %s n'existe pas.", username) )); - Set roleSet = new HashSet<>(); - if (roleService.roleExistByRoleName(userRole)) { - roleSet.add(roleService.retrieveRoleByRoleName(userRole)); - } - user.setRoles(roleSet); +// Set roleSet = new HashSet<>(); +// if (roleService.roleExistByRoleName(userRole)) { +// roleSet.add(roleService.retrieveRoleByRoleName(userRole)); +// } + //user.setRoles(roleSet); user.setResetPassword(false); return userRepository.save(user); } @@ -297,7 +301,7 @@ public class UserServiceImpl implements UserService { user.getUsername(), user.isActive(), user.isResetPassword(), - user.getRoles(), + user.getAvoirFonctions(), user.getStructure(), user.getIdCampagneCourant(), user.getIdSecteurCourant()); diff --git a/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurService.java b/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurService.java index 6f83658..f9d2059 100644 --- a/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/decoupage/SecteurService.java @@ -4,6 +4,7 @@ import io.gmss.fiscad.entities.decoupage.Secteur; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.paylaods.request.synchronisation.SecteurPayload; +import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -25,4 +26,7 @@ public interface SecteurService { List getSecteurListUneStruture(Long structureId); Optional getSecteurById(Long id); + + List getStatParcelleDecoupageUnSecteur(Long serveurId) ; + List getStatParcelleDecoupageByUserId(Long userId) ; } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ParcelleService.java b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ParcelleService.java index 9896b84..2bb7e49 100755 --- a/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ParcelleService.java +++ b/src/main/java/io/gmss/fiscad/interfaces/infocad/metier/ParcelleService.java @@ -4,6 +4,7 @@ import io.gmss.fiscad.entities.infocad.metier.Parcelle; import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb; +import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -24,4 +25,6 @@ public interface ParcelleService { List getParcelleList(); Optional getParcelleById(Long id); + + } diff --git a/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/FonctionService.java b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/FonctionService.java new file mode 100755 index 0000000..4750c1d --- /dev/null +++ b/src/main/java/io/gmss/fiscad/interfaces/rfu/metier/FonctionService.java @@ -0,0 +1,26 @@ +package io.gmss.fiscad.interfaces.rfu.metier; + +import io.gmss.fiscad.entities.user.Fonction; +import io.gmss.fiscad.exceptions.BadRequestException; +import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.FonctionPaylaodWeb; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; +import java.util.Optional; + +public interface FonctionService { + + Fonction createFonction(FonctionPaylaodWeb fonctionPaylaodWeb) throws BadRequestException; + + Fonction updateFonction(Long id, FonctionPaylaodWeb fonctionPaylaodWeb) throws NotFoundException; + + void deleteFonction(Long id) throws NotFoundException; + + Page getFonctionList(Pageable pageable); + + List getFonctionList(); + + Optional getFonctionById(Long id); +} diff --git a/src/main/java/io/gmss/fiscad/interfaces/user/AvoirFonctionService.java b/src/main/java/io/gmss/fiscad/interfaces/user/AvoirFonctionService.java new file mode 100755 index 0000000..be51012 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/interfaces/user/AvoirFonctionService.java @@ -0,0 +1,28 @@ +package io.gmss.fiscad.interfaces.user; + +import io.gmss.fiscad.entities.user.AvoirFonction; +import io.gmss.fiscad.exceptions.BadRequestException; +import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.AvoirFonctionPaylaodWeb; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; +import java.util.Optional; + +public interface AvoirFonctionService { + + AvoirFonction createAvoirFonction(AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws BadRequestException; + + AvoirFonction updateAvoirFonction(Long id, AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb) throws NotFoundException; + + void deleteAvoirFonction(Long id) throws NotFoundException; + + Page getAvoirFonctionList(Pageable pageable); + + List getAvoirFonctionList(); + + Optional getAvoirFonctionById(Long id); + List getUserAvoirFonctionById(Long userId); + +} \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/interfaces/user/ProfileService.java b/src/main/java/io/gmss/fiscad/interfaces/user/ProfileService.java new file mode 100755 index 0000000..1fbeae1 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/interfaces/user/ProfileService.java @@ -0,0 +1,34 @@ +package io.gmss.fiscad.interfaces.user; + +import io.gmss.fiscad.entities.user.Profile; +import io.gmss.fiscad.enums.UserProfile; +import io.gmss.fiscad.exceptions.BadRequestException; +import io.gmss.fiscad.exceptions.NotFoundException; +import io.gmss.fiscad.paylaods.request.crudweb.ProfilePaylaodWeb; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; + +import java.util.List; +import java.util.Optional; + +public interface ProfileService { + + Profile createProfile(ProfilePaylaodWeb profilePaylaodWeb) throws BadRequestException; + + Profile updateProfile(Long id, ProfilePaylaodWeb profilePaylaodWeb) throws NotFoundException; + + void deleteProfile(Long id) throws NotFoundException; + + Page getProfileList(Pageable pageable); + + List getProfileList(); + + Optional getProfileById(Long id); + + Optional getProfileByProfileName(UserProfile userProfile); + + boolean profileExistByProfileName(UserProfile userProfile); + + Profile retrieveProfileByProfileName(UserProfile userProfile); + +} diff --git a/src/main/java/io/gmss/fiscad/paylaods/UserResponse.java b/src/main/java/io/gmss/fiscad/paylaods/UserResponse.java index 411e917..2f49df0 100644 --- a/src/main/java/io/gmss/fiscad/paylaods/UserResponse.java +++ b/src/main/java/io/gmss/fiscad/paylaods/UserResponse.java @@ -1,6 +1,7 @@ package io.gmss.fiscad.paylaods; import io.gmss.fiscad.entities.infocad.parametre.Structure; +import io.gmss.fiscad.entities.user.AvoirFonction; import io.gmss.fiscad.entities.user.Role; import lombok.AllArgsConstructor; import lombok.Data; @@ -20,7 +21,7 @@ public class UserResponse { private String username; private boolean active; private boolean resetPassword; - private Set roles; + private Set avoirFonctions; private Structure structure; private Long idCampagneCourant; private Long idSecteurCourant; diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/AvoirFonctionPaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/AvoirFonctionPaylaodWeb.java new file mode 100644 index 0000000..6a9892e --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/AvoirFonctionPaylaodWeb.java @@ -0,0 +1,26 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.gmss.fiscad.deserializer.LocalDateDeserializer; +import io.gmss.fiscad.enums.Titre; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; +import lombok.Data; + +import java.time.LocalDate; + +@Data +public class AvoirFonctionPaylaodWeb { + private Long id; + @JsonFormat(pattern = "dd-MM-yyyy") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDate dateDebut; + @JsonFormat(pattern = "dd-MM-yyyy") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDate dateFin; + private Long FonctionId; + private Long userId ; + @Enumerated(EnumType.STRING) + private Titre titre; +} diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/FonctionPaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/FonctionPaylaodWeb.java new file mode 100644 index 0000000..cccfd03 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/FonctionPaylaodWeb.java @@ -0,0 +1,25 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.gmss.fiscad.deserializer.LocalDateDeserializer; +import lombok.Data; + +import java.time.LocalDate; + +@Data +public class FonctionPaylaodWeb { + private Long id; + @JsonFormat(pattern = "dd-MM-yyyy") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDate dateDebut; + @JsonFormat(pattern = "dd-MM-yyyy") + @JsonDeserialize(using = LocalDateDeserializer.class) + private LocalDate dateFin; + private String code ; + private String nom ; + private Long secteurId; + private Long sectionId; + private Long StructureId ; + private Long ProfileId ; +} diff --git a/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ProfilePaylaodWeb.java b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ProfilePaylaodWeb.java new file mode 100644 index 0000000..df77374 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/request/crudweb/ProfilePaylaodWeb.java @@ -0,0 +1,22 @@ +package io.gmss.fiscad.paylaods.request.crudweb; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import io.gmss.fiscad.deserializer.LocalDateDeserializer; +import io.gmss.fiscad.entities.user.Role; +import io.gmss.fiscad.enums.Titre; +import io.gmss.fiscad.enums.UserProfile; +import jakarta.persistence.*; +import lombok.Data; + +import java.time.LocalDate; +import java.util.Set; + +@Data +public class ProfilePaylaodWeb { + private Long id; + @Enumerated(EnumType.STRING) + private UserProfile nom ; + private String description; + private Set roles; +} diff --git a/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ParcelleStatsProjectionUnSecteur.java b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ParcelleStatsProjectionUnSecteur.java new file mode 100644 index 0000000..da03755 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/paylaods/response/restoration/ParcelleStatsProjectionUnSecteur.java @@ -0,0 +1,27 @@ +package io.gmss.fiscad.paylaods.response.restoration; + +public interface ParcelleStatsProjectionUnSecteur { + // ================== Département ================== + Long getDepartementId(); + String getDepartementCode(); + String getDepartementNom(); + Long getNbParcellesDepartement(); + + // ================== Commune ================== + Long getCommuneId(); + String getCommuneCode(); + String getCommuneNom(); + Long getNbParcellesCommune(); + + // ================== Arrondissement ================== + Long getArrondissementId(); + String getArrondissementCode(); + String getArrondissementNom(); + Long getNbParcellesArrondissement(); + + // ================== Quartier ================== + Long getQuartierId(); + String getQuartierCode(); + String getQuartierNom(); + Long getNbParcellesQuartier(); +} diff --git a/src/main/java/io/gmss/fiscad/repositories/decoupage/SecteurRepository.java b/src/main/java/io/gmss/fiscad/repositories/decoupage/SecteurRepository.java index 4a844be..4c98f8e 100644 --- a/src/main/java/io/gmss/fiscad/repositories/decoupage/SecteurRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/decoupage/SecteurRepository.java @@ -41,7 +41,11 @@ public interface SecteurRepository extends JpaRepository { inner join secteur st on st.id=b.secteur_id left join enquete e on e.bloc_id=b.id where s.id=?1 and st.id=?2 - group by st.id,st.code,st.nom,s.id;; + group by st.id,st.code,st.nom,s.id; """, nativeQuery = true) List getSecteurEnqResponse(Long structure_id , Long secteurId); + + List findDistinctBySection_Id(Long sectionId); + List findDistinctBySection_Structure_Id(Long structureId); + } \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/repositories/decoupage/SectionRepository.java b/src/main/java/io/gmss/fiscad/repositories/decoupage/SectionRepository.java new file mode 100644 index 0000000..bc37c87 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/repositories/decoupage/SectionRepository.java @@ -0,0 +1,13 @@ +package io.gmss.fiscad.repositories.decoupage; + +import io.gmss.fiscad.entities.decoupage.Secteur; +import io.gmss.fiscad.entities.decoupage.Section; +import io.gmss.fiscad.paylaods.response.SecteurEnqResponse; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; + +public interface SectionRepository extends JpaRepository { + List findAllByStructure_Id(Long structureId); +} \ No newline at end of file diff --git a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ParcelleRepository.java b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ParcelleRepository.java index 955bbfe..8c30e6a 100755 --- a/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ParcelleRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/infocad/metier/ParcelleRepository.java @@ -3,6 +3,7 @@ package io.gmss.fiscad.repositories.infocad.metier; import io.gmss.fiscad.entities.infocad.metier.Parcelle; import io.gmss.fiscad.paylaods.response.StatistiqueTypeNombreResponse; import io.gmss.fiscad.paylaods.response.restoration.ParcellePayLoadRestor; +import io.gmss.fiscad.paylaods.response.restoration.ParcelleStatsProjectionUnSecteur; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -57,4 +58,41 @@ public interface ParcelleRepository extends JpaRepository { GROUP BY type """,nativeQuery = true) List getParcelleBatieResponse(@Param("codeQuartier") String codeQuartier); + + @Query( + value = """ + SELECT DISTINCT + d.id AS departement_id, + d.code AS departement_code, + d.nom AS departement_nom, + COUNT(p.id) OVER (PARTITION BY d.id) AS nb_parcelles_departement, + c.id AS commune_id, + c.code AS commune_code, + c.nom AS commune_nom, + COUNT(p.id) OVER (PARTITION BY c.id) AS nb_parcelles_commune, + a.id AS arrondissement_id, + a.code AS arrondissement_code, + a.nom AS arrondissement_nom, + COUNT(p.id) OVER (PARTITION BY a.id) AS nb_parcelles_arrondissement, + q.id AS quartier_id, + q.code AS quartier_code, + q.nom AS quartier_nom, + COUNT(p.id) OVER (PARTITION BY q.id) AS nb_parcelles_quartier + FROM secteur_decoupage sd + JOIN quartier q ON q.id = sd.quartier_id + JOIN arrondissement a ON a.id = q.arrondissement_id + JOIN commune c ON c.id = a.commune_id + JOIN departement d ON d.id = c.departement_id + LEFT JOIN parcelle p ON p.quartier_id = q.id + WHERE sd.secteur_id IN (:secteurIds)\s + ORDER BY + d.nom, c.nom, a.nom, q.nom; + """, + nativeQuery = true + ) + List findStatsBySecteurs( + @Param("secteurIds") List secteurIds + ); + + } diff --git a/src/main/java/io/gmss/fiscad/repositories/rfu/metier/FonctionRepository.java b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/FonctionRepository.java new file mode 100755 index 0000000..b5f2458 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/repositories/rfu/metier/FonctionRepository.java @@ -0,0 +1,9 @@ +package io.gmss.fiscad.repositories.rfu.metier; + +import io.gmss.fiscad.entities.user.Fonction; +import org.springframework.data.jpa.repository.JpaRepository; + + +public interface FonctionRepository extends JpaRepository { + +} diff --git a/src/main/java/io/gmss/fiscad/repositories/user/AvoirFonctionRepository.java b/src/main/java/io/gmss/fiscad/repositories/user/AvoirFonctionRepository.java new file mode 100755 index 0000000..055a457 --- /dev/null +++ b/src/main/java/io/gmss/fiscad/repositories/user/AvoirFonctionRepository.java @@ -0,0 +1,14 @@ +package io.gmss.fiscad.repositories.user; + +import io.gmss.fiscad.entities.user.AvoirFonction; +import io.gmss.fiscad.entities.user.AvoirFonction; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; +import java.util.Optional; + +public interface AvoirFonctionRepository extends JpaRepository { + Optional findAvoirFonctionById(Long id); + List findAvoirFonctionByUser_Id(Long userId); + +} diff --git a/src/main/java/io/gmss/fiscad/repositories/user/ProfileRepository.java b/src/main/java/io/gmss/fiscad/repositories/user/ProfileRepository.java new file mode 100755 index 0000000..abdbf6c --- /dev/null +++ b/src/main/java/io/gmss/fiscad/repositories/user/ProfileRepository.java @@ -0,0 +1,17 @@ +package io.gmss.fiscad.repositories.user; + +import io.gmss.fiscad.entities.user.Profile; +import io.gmss.fiscad.enums.UserProfile; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface ProfileRepository extends JpaRepository { + Optional findProfileById(Long id); + + Optional findProfileByNom(UserProfile nom); + + boolean existsByNom(UserProfile userProfile); + + Profile getProfilesByNom(UserProfile userProfile); +} diff --git a/src/main/java/io/gmss/fiscad/repositories/user/UserRepository.java b/src/main/java/io/gmss/fiscad/repositories/user/UserRepository.java index f0f5444..80326cc 100755 --- a/src/main/java/io/gmss/fiscad/repositories/user/UserRepository.java +++ b/src/main/java/io/gmss/fiscad/repositories/user/UserRepository.java @@ -18,9 +18,9 @@ public interface UserRepository extends JpaRepository { long countAllByUsernameIsNotNull(); - List findAllByStructureAndRolesIn(Structure structure, Set roleSet); + // List findAllByStructureAndRolesIn(Structure structure, Set roleSet); - List findAllByStructureAndRolesNotIn(Structure structure, Set roleSet); + // List findAllByStructureAndRolesNotIn(Structure structure, Set roleSet); - List findAllByRolesContains(UserRole userRole); + // List findAllByRolesContains(UserRole userRole); } diff --git a/src/main/java/io/gmss/fiscad/security/TokenAuthentificationProvider.java b/src/main/java/io/gmss/fiscad/security/TokenAuthentificationProvider.java index af77a1b..dbdff78 100755 --- a/src/main/java/io/gmss/fiscad/security/TokenAuthentificationProvider.java +++ b/src/main/java/io/gmss/fiscad/security/TokenAuthentificationProvider.java @@ -42,8 +42,8 @@ public class TokenAuthentificationProvider { Date expiryDate = new Date(now.getTime() + jwtExpirationInMs); Map claims = new HashMap<>(); - List roles = new ArrayList<>(); - userDetails.getAuthorities().forEach(role -> roles.add(role.getAuthority())); + //List roles = new ArrayList<>(); + //userDetails.getAuthorities().forEach(role -> roles.add(role.getAuthority())); //claims.put("roles", roles); User user = userRepository.findByUsername(userDetails.getUsername()).get(); claims.put("user", getUserResponseFromUser(user)); @@ -69,11 +69,10 @@ public class TokenAuthentificationProvider { user.getUsername(), user.isActive(), user.isResetPassword(), - user.getRoles(), + user.getAvoirFonctions(), user.getStructure(), user.getIdCampagneCourant(), user.getIdSecteurCourant()); - } public String getUsernameFromJWT(String token) { diff --git a/src/main/java/io/gmss/fiscad/security/UserPrincipal.java b/src/main/java/io/gmss/fiscad/security/UserPrincipal.java index 3b02e9f..3df80ad 100755 --- a/src/main/java/io/gmss/fiscad/security/UserPrincipal.java +++ b/src/main/java/io/gmss/fiscad/security/UserPrincipal.java @@ -1,17 +1,23 @@ package io.gmss.fiscad.security; +import io.gmss.fiscad.entities.user.AvoirFonction; +import io.gmss.fiscad.entities.user.Role; import io.gmss.fiscad.entities.user.User; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; +import java.time.LocalDate; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; public class UserPrincipal implements UserDetails { + /** * */ @@ -27,13 +33,26 @@ public class UserPrincipal implements UserDetails { public static UserPrincipal create(User user) { List authorities = new ArrayList<>(); - user.getRoles().forEach((role) -> - authorities.add(new SimpleGrantedAuthority(role.getNom().name())) + Set avoirFonctions= user.getAvoirFonctions() ; + + Set rolesUtilisateur = + avoirFonctions.stream() + .filter(af -> af.getDateFin() == null || af.getDateFin().isAfter(LocalDate.now())) + .flatMap(af -> af.getFonction().getProfile().getRoles().stream()) + .collect(Collectors.toSet()); + + rolesUtilisateur.forEach((role) -> { + authorities.add(new SimpleGrantedAuthority("ROLE_" + role.getNom().name())); + } ); + return new UserPrincipal( user, authorities ); + + + } public void setAuthorities(Collection authorities) { diff --git a/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java b/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java index c74b281..a9d922b 100644 --- a/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java +++ b/src/main/java/io/gmss/fiscad/service/EntityFromPayLoadService.java @@ -2,6 +2,8 @@ package io.gmss.fiscad.service; import io.gmss.fiscad.entities.decoupage.Commune; import io.gmss.fiscad.entities.decoupage.Nationalite; +import io.gmss.fiscad.entities.decoupage.Secteur; +import io.gmss.fiscad.entities.decoupage.Section; import io.gmss.fiscad.entities.infocad.metier.Enquete; import io.gmss.fiscad.entities.infocad.metier.Parcelle; import io.gmss.fiscad.entities.infocad.metier.Piece; @@ -9,19 +11,24 @@ import io.gmss.fiscad.entities.infocad.metier.Upload; import io.gmss.fiscad.entities.infocad.parametre.*; import io.gmss.fiscad.entities.rfu.metier.*; import io.gmss.fiscad.entities.rfu.parametre.Caracteristique; -import io.gmss.fiscad.enums.TypeObjet; +import io.gmss.fiscad.entities.user.AvoirFonction; +import io.gmss.fiscad.entities.user.Fonction; +import io.gmss.fiscad.entities.user.Profile; +import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.paylaods.request.crudweb.*; import io.gmss.fiscad.repositories.decoupage.CommuneRepository; import io.gmss.fiscad.repositories.decoupage.NationaliteRepository; +import io.gmss.fiscad.repositories.decoupage.SecteurRepository; +import io.gmss.fiscad.repositories.decoupage.SectionRepository; import io.gmss.fiscad.repositories.infocad.metier.EnqueteRepository; import io.gmss.fiscad.repositories.infocad.metier.ParcelleRepository; import io.gmss.fiscad.repositories.infocad.metier.PieceRepository; import io.gmss.fiscad.repositories.infocad.parametre.*; import io.gmss.fiscad.repositories.rfu.metier.*; import io.gmss.fiscad.repositories.rfu.parametre.CaracteristiqueRepository; +import io.gmss.fiscad.repositories.user.ProfileRepository; +import io.gmss.fiscad.repositories.user.UserRepository; import lombok.AllArgsConstructor; -import org.codehaus.groovy.transform.SourceURIASTTransformation; -import org.hibernate.event.spi.SaveOrUpdateEvent; import org.springframework.stereotype.Service; import java.util.Optional; @@ -48,6 +55,11 @@ public class EntityFromPayLoadService { private final ProfessionRepository professionRepository; private final TypePersonneRepository typePersonneRepository; private final CommuneRepository communeRepository; + private final FonctionRepository fonctionRepository; + private final SecteurRepository secteurRepository; + private final UserRepository userRepository; + private final ProfileRepository profileRepository; + private final SectionRepository sectionRepository; public CaracteristiqueParcelle getCaracteristiqueParcelleFromPayLoadWeb(CaracteristiqueParcellePayloadWeb caracteristiqueParcellePayloadWeb){ CaracteristiqueParcelle caracteristiqueParcelle=new CaracteristiqueParcelle(); @@ -225,6 +237,65 @@ public class EntityFromPayLoadService { return uniteLogement ; } + public Fonction getFonctionFromPayLoadWeb(FonctionPaylaodWeb fonctionPaylaodWeb){ + Fonction fonction =new Fonction(); + Optional optionalSecteur=Optional.empty(); + Optional
optionalSection=Optional.empty(); + Optional optionalProfile=Optional.empty(); + Optional optionalUser=Optional.empty(); + Optional optionalStructure=Optional.empty(); + + if(fonctionPaylaodWeb.getSecteurId()!=null) + optionalSecteur=secteurRepository.findById(fonctionPaylaodWeb.getSecteurId()); + if(fonctionPaylaodWeb.getProfileId()!=null) + optionalProfile=profileRepository.findById(fonctionPaylaodWeb.getProfileId()); + if(fonctionPaylaodWeb.getSectionId()!=null) + optionalSection=sectionRepository.findById(fonctionPaylaodWeb.getSecteurId()); + if(fonctionPaylaodWeb.getStructureId()!=null) + optionalStructure=structureRepository.findById(fonctionPaylaodWeb.getStructureId()); + + fonction.setSecteur(optionalSecteur.orElse(null)); + fonction.setProfile(optionalProfile.orElse(null)); + fonction.setSection(optionalSection.orElse(null)); + fonction.setStructure(optionalStructure.orElse(null)); + fonction.setProfile(optionalProfile.orElse(null)); + fonction.setId(fonctionPaylaodWeb.getId()); + fonction.setCode(fonctionPaylaodWeb.getCode()); + fonction.setNom(fonctionPaylaodWeb.getNom()); + return fonction; + } + + + public AvoirFonction getAvoirFonctionFromPayLoadWeb(AvoirFonctionPaylaodWeb avoirFonctionPaylaodWeb){ + AvoirFonction avoirFonction =new AvoirFonction(); + Optional optionalFonction=Optional.empty(); + Optional optionalUser=Optional.empty(); + + if(avoirFonctionPaylaodWeb.getFonctionId()!=null) + optionalFonction=fonctionRepository.findById(avoirFonctionPaylaodWeb.getFonctionId()); + if(avoirFonctionPaylaodWeb.getUserId()!=null) + optionalUser=userRepository.findById(avoirFonctionPaylaodWeb.getUserId()); + + avoirFonction.setFonction(optionalFonction.orElse(null)); + avoirFonction.setUser(optionalUser.orElse(null)); + avoirFonction.setTitre(avoirFonction.getTitre()); + avoirFonction.setId(avoirFonction.getId()); + avoirFonction.setDateDebut(avoirFonction.getDateDebut()); + avoirFonction.setDateFin(avoirFonction.getDateFin()); + + return avoirFonction; + } + + + public Profile getProfileFromPayLoadWeb(ProfilePaylaodWeb profilePaylaodWeb){ + Profile profile =new Profile(); + profile.setDescription(profilePaylaodWeb.getDescription()); + profile.setRoles(profilePaylaodWeb.getRoles()); + profile.setNom(profilePaylaodWeb.getNom()); + + return profile; + } + public Personne getPersonneFromPayLoadWeb(PersonnePayLoadWeb personnePayLoadWeb){ Personne personne=new Personne(); Optional optionalSituationMatrimoniale=Optional.empty(); diff --git a/src/main/resources/application-dgi.properties b/src/main/resources/application-dgi.properties index dd19eff..3fc31fe 100755 --- a/src/main/resources/application-dgi.properties +++ b/src/main/resources/application-dgi.properties @@ -1,17 +1,17 @@ server.port=8282 -io.gmss.fiscad.profile=${IO_GMSS_FISCAD_PROFILE} -#io.gmss.fiscad.profile=dgi +#io.gmss.fiscad.profile=${IO_GMSS_FISCAD_PROFILE} +io.gmss.fiscad.profile=dgi # TEST ENV #spring.datasource.url=jdbc:postgresql://vmi792116.contaboserver.net:5599/dgi_db #spring.datasource.username=infocad_user #spring.datasource.password=W5fwD({9*q53 # LOCAL ENV -#spring.datasource.url=jdbc:postgresql://localhost:5432/fiscad_dgi -#spring.datasource.username=infocad_user -#spring.datasource.password=W5fwD({9*q53 +spring.datasource.url=jdbc:postgresql://localhost:5432/fiscad_dgi +spring.datasource.username=infocad_user +spring.datasource.password=W5fwD({9*q53 # PROD ENVIRONNEMENT -spring.datasource.url=${SPRING_DATASOURCE_URL} -spring.datasource.username=${SPRING_DATASOURCE_USERNAME} -spring.datasource.password=${SPRING_DATASOURCE_PASSWORD} \ No newline at end of file +#spring.datasource.url=${SPRING_DATASOURCE_URL} +#spring.datasource.username=${SPRING_DATASOURCE_USERNAME} +#spring.datasource.password=${SPRING_DATASOURCE_PASSWORD} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 579bcfd..e93a597 100755 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,6 +1,6 @@ -spring.profiles.active=${SPRING_PROFILES_ACTIVE} +#spring.profiles.active=${SPRING_PROFILES_ACTIVE} #spring.profiles.active=abomey -#spring.profiles.active=dgi +spring.profiles.active=dgi spring.jpa.properties.hibernate.id.new_generator_mappings=false spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true spring.jpa.open-in-view=false @@ -46,11 +46,11 @@ logging.file.name=/app/logs/fiscad.log #app.abs.env.defaultuser = fiscad_admin -#app.default-user.username=fiscad_admin -#app.default-user.password=1234567890 +app.default-user.username=fiscad_admin +app.default-user.password=1234567890 -app.default-user.username=${DEFAULT_USER_NAME} -app.default-user.password=${DEFAULT_USER_PASSWORD} +#app.default-user.username=${DEFAULT_USER_NAME} +#app.default-user.password=${DEFAULT_USER_PASSWORD} app.upload.root=${file.upload_dir} app.upload.zips.received=${app.upload.root}/zips/received