Merge pull request 'gestion de profil, secteur, section et arbre decoupage' (#72) from features/crud_entites into develop

Reviewed-on: #72
This commit was merged in pull request #72.
This commit is contained in:
2026-01-27 08:37:52 +00:00
56 changed files with 1975 additions and 205 deletions

View File

@@ -1,5 +1,6 @@
package io.gmss.fiscad.component; 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.Role;
import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.entities.user.User;
import io.gmss.fiscad.enums.UserRole; import io.gmss.fiscad.enums.UserRole;
@@ -42,17 +43,13 @@ public class DataLoadConfig {
public void loadRoles() { public void loadRoles() {
if (roleRepository.count() > 0) return; if (roleRepository.count() > 0) return;
Set<Role> roles = new HashSet<>(); Set<Role> roles = new HashSet<>();
roles.add(new Role(UserRole.ROLE_USER, "Role attribué aux utilisateurs simples.")); roles.add(new Role(UserRole.CREATE_USER, "Peut créer un utilisation."));
roles.add(new Role(UserRole.ROLE_ADMIN, "Role attribué aux administrateurs du système.")); roles.add(new Role(UserRole.READ_USER, "peut lire un utilisation"));
roles.add(new Role(UserRole.ROLE_DIRECTEUR, "Role attribué aux directeurs des structures.")); roles.add(new Role(UserRole.UPDATE_USER, "peut modifier un utilisation"));
roles.add(new Role(UserRole.ROLE_SUPERVISEUR, "Role attribué aux superviseurs des structures sur le terrain.")); roles.add(new Role(UserRole.DELETE_USER, "peut supprimer un utilisation"));
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."));
roleRepository.saveAll(roles); roleRepository.saveAll(roles);
} }
public void loadUsers() { public void loadUsers() {
@@ -65,9 +62,6 @@ public class DataLoadConfig {
admin.setPrenom("Principal"); admin.setPrenom("Principal");
admin.setPassword(passwordEncoder.encode(passwordFile)); admin.setPassword(passwordEncoder.encode(passwordFile));
admin.setActive(true); admin.setActive(true);
Set<Role> roles = new HashSet<>();
roles.add(roleRepository.findRoleByNom(UserRole.ROLE_ADMIN).get());
admin.setRoles(roles);
userRepository.save(admin); userRepository.save(admin);
} }
} }

View File

@@ -3,10 +3,12 @@ package io.gmss.fiscad.controllers.decoupage;
import io.gmss.fiscad.entities.decoupage.SecteurDecoupage; import io.gmss.fiscad.entities.decoupage.SecteurDecoupage;
import io.gmss.fiscad.exceptions.*; import io.gmss.fiscad.exceptions.*;
import io.gmss.fiscad.interfaces.decoupage.SecteurDecoupageService; import io.gmss.fiscad.interfaces.decoupage.SecteurDecoupageService;
import io.gmss.fiscad.interfaces.decoupage.SecteurService;
import io.gmss.fiscad.paylaods.ApiResponse; import io.gmss.fiscad.paylaods.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest; 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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.HttpClientErrorException;
@AllArgsConstructor
@RestController @RestController
@RequestMapping(value = "api/secteur-decoupage", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "api/secteur-decoupage", produces = MediaType.APPLICATION_JSON_VALUE)
@SecurityRequirement(name = "bearer") @SecurityRequirement(name = "bearer")
@Tag(name = "SecteurDecoupage") @Tag(name = "SecteurDecoupage")
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')") //@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPERVISEUR')")
public class SecteurDecoupageController { public class SecteurDecoupageController {
private final SecteurDecoupageService secteurDecoupageService; private final SecteurDecoupageService secteurDecoupageService;
private final SecteurService secteurService;
private static final Logger logger = LoggerFactory.getLogger(SecteurDecoupageController.class); private static final Logger logger = LoggerFactory.getLogger(SecteurDecoupageController.class);
public SecteurDecoupageController(SecteurDecoupageService secteurDecoupageService) {
this.secteurDecoupageService = secteurDecoupageService;
}
@PostMapping("/create") @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);
}
}
} }

View File

@@ -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);
}
}
}

View File

@@ -124,9 +124,8 @@ public class AuthController {
user.setUsername(userRequest.getEmail()); user.setUsername(userRequest.getEmail());
user.setPassword(userRequest.getPassword()); user.setPassword(userRequest.getPassword());
user.setActive(false); user.setActive(false);
Set<Role> roleSet = new HashSet<>(); //Set<Role> roleSet = new HashSet<>();
roleSet.add(roleService.getRoleByRoleName(UserRole.ROLE_ANONYMOUS).get()); //user.setAvoirFonctions(roleSet);
user.setRoles(roleSet);
user.setStructure(structureService.getStructureById(userRequest.getStructureId()).get()); user.setStructure(structureService.getStructureById(userRequest.getStructureId()).get());
return user; return user;
} }

View File

@@ -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);
}
}
}

View File

@@ -113,31 +113,18 @@ public class DemandeReinitialisationMPController {
} }
} }
@GetMapping("/all") // @GetMapping("/all")
public ResponseEntity<?> getAllDemandeReinitialisationMPList(@CurrentUser UserPrincipal userPrincipal) { // public ResponseEntity<?> getAllDemandeReinitialisationMPList(@CurrentUser UserPrincipal userPrincipal) {
try { // try {
//
User user = userPrincipal.getUser(); // User user = userPrincipal.getUser();
//
if (user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))) { // if (user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))) {
return new ResponseEntity<>( // return new ResponseEntity<>(
new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPList(), "Liste des demande de Reinitialisation chargée avec succès."), // new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPList(), "Liste des demande de Reinitialisation chargée avec succès."),
HttpStatus.OK // HttpStatus.OK
); // );
} else { // } 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 {
// if (user.getStructure() == null) { // if (user.getStructure() == null) {
// return new ResponseEntity<>( // 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."), // 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) { //// }else {
logger.error(e.getLocalizedMessage()); //// if (user.getStructure() == null) {
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); //// return new ResponseEntity<>(
} catch (NotFoundException | BadRequestException | MyFileNotFoundException | ResourceNotFoundException | //// 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."),
FileStorageException e) { //// HttpStatus.OK
logger.error(e.getLocalizedMessage()); //// );
return new ResponseEntity<>(new ApiResponse(false, null, e.getMessage()), HttpStatus.OK); //// } else {
} catch (NullPointerException e) { //// return new ResponseEntity<>(
logger.error(e.getLocalizedMessage()); //// new ApiResponse<>(true, demandeReinitialisationMPService.getDemandeReinitialisationMPNonTraiteList(user.getStructure()), "Liste des demande de Reinitialisation chargée avec succès."),
return new ResponseEntity<>(new ApiResponse(false, null, "Null value has been detected {" + e.getMessage() + "}."), HttpStatus.OK); //// 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); //// }
} // } 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") @GetMapping("/all-paged")
public ResponseEntity<?> getAllDemandeReinitialisationMPPaged(@RequestParam int pageNo, @RequestParam int pageSize) { public ResponseEntity<?> getAllDemandeReinitialisationMPPaged(@RequestParam int pageNo, @RequestParam int pageSize) {

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -165,12 +165,13 @@ public class UserController {
try { try {
User user = userService.getUserById(id); User user = userService.getUserById(id);
if(containsRoleAnonyme(user.getRoles())){ // if(user.getAvoirFonctions().isEmpty()){
return new ResponseEntity<>( // return new ResponseEntity<>(
new ApiResponse<>(false, user , "Ce compte n'est pas encore validé."), // new ApiResponse<>(false, user , "Ce compte n'est pas encore validé."),
HttpStatus.OK // HttpStatus.OK
); // );
} // }
if(user.isResetPassword()){ if(user.isResetPassword()){
return new ResponseEntity<>( return new ResponseEntity<>(
new ApiResponse<>(false, user , "Ce compte n'est pas encore validé."), new ApiResponse<>(false, user , "Ce compte n'est pas encore validé."),
@@ -236,19 +237,10 @@ public class UserController {
HttpStatus.OK HttpStatus.OK
); );
} }
User user = userPrincipal.getUser();
if (user.getRoles().stream().anyMatch(r -> r.getNom().equals(UserRole.ROLE_ADMIN))) { return new ResponseEntity<>(
return new ResponseEntity<>(
new ApiResponse<>(true, userService.getAllUserListResponse(), "Liste des utilisateurs chargée avec succès."),
HttpStatus.OK
);
} else {
return new ResponseEntity<>(
new ApiResponse<>(true, userService.getListUserResponseByStructure(userPrincipal.getUser().getStructure().getId()), "Liste des utilisateurs chargée avec succès."), 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) { } catch (HttpClientErrorException.MethodNotAllowed e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage());
return new ResponseEntity<>(new ApiResponse(false, null, "Method POST/GET is required."), HttpStatus.OK); 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); return new ResponseEntity<>(new ApiResponse(false, null, "An error has been occur and the content is {" + e.getMessage() + "}."), HttpStatus.OK);
} }
} }
public boolean containsRoleAnonyme(Set<Role> roles){
for(Role r: roles ){
if(r.getNom().equals(UserRole.ROLE_ANONYMOUS)){
return true;
}
}
return false;
}
} }

View File

@@ -37,4 +37,6 @@ public class BaseEntity implements Serializable {
private boolean deleted; private boolean deleted;
private Long externalKey; private Long externalKey;
private Long enqueteExternalKey; private Long enqueteExternalKey;
@JsonIgnore
private String source ;
} }

View File

@@ -24,9 +24,11 @@ public class Quartier extends BaseEntity implements Serializable {
private Long id; private Long id;
private String code; private String code;
private String nom; private String nom;
private String codeExterne;
// @JsonIgnore // @JsonIgnore
@ManyToOne @ManyToOne
private Arrondissement arrondissement; private Arrondissement arrondissement;
// @JsonIgnore // @JsonIgnore
// @OneToOne(mappedBy = "quartier") // @OneToOne(mappedBy = "quartier")
// private Bloc bloc; // private Bloc bloc;

View File

@@ -1,5 +1,6 @@
package io.gmss.fiscad.entities.decoupage; package io.gmss.fiscad.entities.decoupage;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference; import com.fasterxml.jackson.annotation.JsonManagedReference;
import io.gmss.fiscad.entities.BaseEntity; import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.entities.infocad.parametre.Structure; import io.gmss.fiscad.entities.infocad.parametre.Structure;
@@ -26,16 +27,16 @@ public class Secteur extends BaseEntity implements Serializable {
private Long id; private Long id;
private String code; private String code;
private String nom; private String nom;
@ManyToOne
private User chefSecteur;
@ManyToOne @ManyToOne
private Structure structure; private Structure structure;
//@JsonBackReference
@ManyToOne
private Section section ;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "secteur_id") @JoinColumn(name = "secteur_id")
@JsonManagedReference @JsonManagedReference
private List<SecteurDecoupage> secteurDecoupages; private List<SecteurDecoupage> secteurDecoupages;
///Creer un payload pour la creation de secteur découpage
/// ressource pour envoyer les découpage d'un secteur
} }

View File

@@ -40,12 +40,16 @@ public class SecteurDecoupage extends BaseEntity implements Serializable {
@ManyToOne @ManyToOne
private Secteur secteur; private Secteur secteur;
private String codeSecteur ;
@ManyToOne @ManyToOne
private Arrondissement arrondissement; private Arrondissement arrondissement;
@ManyToOne @ManyToOne
private Quartier quartier; private Quartier quartier;
private String codeQuartier ;
// @JsonIgnore // @JsonIgnore
// @OneToMany(mappedBy = "secteurDecoupage") // @OneToMany(mappedBy = "secteurDecoupage")
// private List<Bloc> blocs; // private List<Bloc> blocs;

View File

@@ -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<Secteur> fonctionList;
}

View File

@@ -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.metier.EnqueteUniteLogement;
import io.gmss.fiscad.entities.rfu.parametre.Campagne; import io.gmss.fiscad.entities.rfu.parametre.Campagne;
import io.gmss.fiscad.entities.rfu.parametre.Equipe; 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.rfu.parametre.ZoneRfu;
import io.gmss.fiscad.entities.user.User; import io.gmss.fiscad.entities.user.User;
import io.gmss.fiscad.enums.StatutEnquete; import io.gmss.fiscad.enums.StatutEnquete;
@@ -55,10 +56,14 @@ public class Enquete extends BaseEntity implements Serializable {
private boolean litige; private boolean litige;
@JsonIgnore
@ManyToOne @ManyToOne
private User user; private User user;
@JsonIgnore
@ManyToOne
private Exercice exercice;
private Long mobileDataId; private Long mobileDataId;
@JsonIgnore @JsonIgnore

View File

@@ -59,9 +59,11 @@ public class Parcelle extends BaseEntity implements Serializable {
private boolean synchronise; private boolean synchronise;
private Long idDerniereEnquete; private Long idDerniereEnquete;
private Long mobileDataId; private Long mobileDataId;
private String numEnterParcelle; private String numEntreeParcelle;
private String codeQuartier;
@ManyToOne @ManyToOne
private Rue rue ; private Rue rue ;
private String numeroRue ;
// @JsonIgnore // @JsonIgnore
// @OneToMany(mappedBy = "parcelle") // @OneToMany(mappedBy = "parcelle")
// private List<Batiment> batiments; // private List<Batiment> batiments;

View File

@@ -78,10 +78,12 @@ public class Personne extends BaseEntity implements Serializable {
@ColumnDefault("0") @ColumnDefault("0")
private int mustHaveRepresentant; private int mustHaveRepresentant;
private String filePath; private String filePath;
private String observation; private String observation;
@ColumnDefault("false") @ColumnDefault("false")
private boolean synchronise; private boolean synchronise;
@OneToMany(mappedBy = "personne") @OneToMany(mappedBy = "personne")
private List<Upload> uploads; private List<Upload> uploads;

View File

@@ -33,7 +33,7 @@ import java.util.Set;
"SET deleted = true " + "SET deleted = true " +
"WHERE id = ?") "WHERE id = ?")
@Where(clause = " deleted = false") @Where(clause = " deleted = false")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) //@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Structure extends BaseEntity implements Serializable { public class Structure extends BaseEntity implements Serializable {
@Id @Id
@@ -50,7 +50,8 @@ public class Structure extends BaseEntity implements Serializable {
@NotNull @NotNull
@ManyToOne @ManyToOne
private Commune commune; private Commune commune;
//@JsonIgnore
@JsonIgnore
@ManyToMany @ManyToMany
@JoinTable(name = "arrondissements_structures", @JoinTable(name = "arrondissements_structures",
joinColumns = @JoinColumn(name = "structure_id"), joinColumns = @JoinColumn(name = "structure_id"),

View File

@@ -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.Tpe;
import io.gmss.fiscad.entities.infocad.metier.Upload; import io.gmss.fiscad.entities.infocad.metier.Upload;
import io.gmss.fiscad.entities.infocad.parametre.Personne; 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.entities.user.User;
import io.gmss.fiscad.enums.StatutEnregistrement; import io.gmss.fiscad.enums.StatutEnregistrement;
import jakarta.persistence.*; import jakarta.persistence.*;
@@ -70,6 +71,10 @@ public class EnqueteBatiment extends BaseEntity implements Serializable {
@ManyToOne @ManyToOne
private Personne personne; private Personne personne;
@ManyToOne
@JoinColumn(name = "categorie_caracteristique_id")
private Caracteristique caracteristique;
private Long personneExternalKey; private Long personneExternalKey;
@JsonIgnore @JsonIgnore

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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<Role> 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();
}
}

View File

@@ -1,5 +1,6 @@
package io.gmss.fiscad.entities.user; package io.gmss.fiscad.entities.user;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.gmss.fiscad.entities.BaseEntity; import io.gmss.fiscad.entities.BaseEntity;
import io.gmss.fiscad.enums.UserRole; import io.gmss.fiscad.enums.UserRole;
import jakarta.persistence.*; import jakarta.persistence.*;
@@ -54,4 +55,13 @@ public class Role extends BaseEntity implements Serializable {
public int hashCode() { public int hashCode() {
return Objects.hash(id, nom, description); return Objects.hash(id, nom, description);
} }
@JsonIgnore
public Long getExternalKey() {
return super.getExternalKey();
}
@JsonIgnore
public Long getEnqueteExternalKey() {
return super.getEnqueteExternalKey();
}
} }

View File

@@ -16,6 +16,7 @@ import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@@ -39,6 +40,12 @@ public class User extends BaseEntity implements Serializable {
private String prenom; private String prenom;
private String tel; private String tel;
private String email; private String email;
@Column(
name = "username",
nullable = false,
unique = true,
length = 200
)
private String username; private String username;
@JsonIgnore @JsonIgnore
private String password; private String password;
@@ -46,42 +53,31 @@ public class User extends BaseEntity implements Serializable {
private boolean active; private boolean active;
@Column(columnDefinition = "boolean default false") @Column(columnDefinition = "boolean default false")
private boolean resetPassword; private boolean resetPassword;
@ManyToMany
@JoinTable(name = "users_roles", @OneToMany(mappedBy = "user")
joinColumns = @JoinColumn(name = "user_id"), private Set<AvoirFonction> avoirFonctions= new HashSet<>();
inverseJoinColumns = @JoinColumn(name = "roles_id")
)
private Set<Role> roles;
@ManyToOne @ManyToOne
private Structure structure; private Structure structure;
// @JsonIgnore
// @OneToMany(mappedBy = "user")
// private List<Enquete> enquetes;
@JsonIgnore @JsonIgnore
@OneToMany(mappedBy = "user") @OneToMany(mappedBy = "user")
private List<Participer> participers; private List<Participer> participers;
// @JsonIgnore
// @OneToMany(mappedBy = "chefSecteur")
// private List<Secteur> secteurs;
@Transient @Transient
private Long idCampagneCourant; private Long idCampagneCourant;
@Transient @Transient
private Long idSecteurCourant; private Long idSecteurCourant;
// public void setUsername(String username) {
// this.username = username;
// }
public boolean isAdmin() { public boolean isAdmin() {
for (Role r : this.roles) { // for (Role r : this.roles) {
if (r.getNom().equals(UserRole.ROLE_ADMIN)) { // if (r.getNom().equals(UserRole.ROLE_ADMIN)) {
return true; // return true;
} // }
} // }
return false; return false;
} }

View File

@@ -0,0 +1,6 @@
package io.gmss.fiscad.enums;
public enum Titre {
TITULAIRE,
INTERIMAIRE
}

View File

@@ -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
}

View File

@@ -2,11 +2,23 @@ package io.gmss.fiscad.enums;
public enum UserRole { public enum UserRole {
ROLE_ADMIN, ADMIN,
ROLE_USER, CREATE_USER,
ROLE_DIRECTEUR, UPDATE_USER,
ROLE_SUPERVISEUR, READ_USER,
ROLE_ENQUETEUR, DELETE_USER,
ROLE_ANONYMOUS, CREATE_PARCELLE,
ROLE_RESPONSABLE UPDATE_PARCELLE,
READ_PARCELLE,
DELETE_PARCELLE,
CREATE_ENQUETE,
UPDATE_ENQUETE,
READ_ENQUETE,
DELETE_ENQUETE,
CREATE_BATIMENT,
UPDATE_BATIMENT,
READ_BATIMENT,
DELETE_BATIMENT
} }

View File

@@ -3,40 +3,44 @@ package io.gmss.fiscad.implementations.decoupage;
import io.gmss.fiscad.entities.decoupage.Secteur; import io.gmss.fiscad.entities.decoupage.Secteur;
import io.gmss.fiscad.entities.decoupage.SecteurDecoupage; import io.gmss.fiscad.entities.decoupage.SecteurDecoupage;
import io.gmss.fiscad.entities.infocad.parametre.Structure; 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.entities.user.User;
import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.interfaces.decoupage.SecteurService; import io.gmss.fiscad.interfaces.decoupage.SecteurService;
import io.gmss.fiscad.paylaods.request.synchronisation.SecteurDecoupagePayload; import io.gmss.fiscad.paylaods.request.synchronisation.SecteurDecoupagePayload;
import io.gmss.fiscad.paylaods.request.synchronisation.SecteurPayload; 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.ArrondissementRepository;
import io.gmss.fiscad.repositories.decoupage.QuartierRepository; import io.gmss.fiscad.repositories.decoupage.QuartierRepository;
import io.gmss.fiscad.repositories.decoupage.SecteurRepository; 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.infocad.parametre.StructureRepository;
import io.gmss.fiscad.repositories.user.AvoirFonctionRepository;
import io.gmss.fiscad.repositories.user.UserRepository; import io.gmss.fiscad.repositories.user.UserRepository;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
@AllArgsConstructor
@Service @Service
public class SecteurServiceImpl implements SecteurService { public class SecteurServiceImpl implements SecteurService {
private final SecteurRepository secteurRepository; private final SecteurRepository secteurRepository;
private final ParcelleRepository parcelleRepository;
private final UserRepository userRepository; private final UserRepository userRepository;
private final ArrondissementRepository arrondissementRepository; private final ArrondissementRepository arrondissementRepository;
private final QuartierRepository quartierRepository; private final QuartierRepository quartierRepository;
private final StructureRepository structureRepository; 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 @Override
@@ -56,7 +60,7 @@ public class SecteurServiceImpl implements SecteurService {
private Secteur getSecteurFromPayload(SecteurPayload secteurPayload) { private Secteur getSecteurFromPayload(SecteurPayload secteurPayload) {
Secteur secteur = new Secteur(); Secteur secteur = new Secteur();
Optional<User> optionalUser = userRepository.findById(secteurPayload.getChefSecteurId()); Optional<User> optionalUser = userRepository.findById(secteurPayload.getChefSecteurId());
secteur.setChefSecteur(optionalUser.orElse(null)); //secteur.setChefSecteur(optionalUser.orElse(null));
Optional<Structure> optionalStructure = structureRepository.findById(secteurPayload.getStructureId()); Optional<Structure> optionalStructure = structureRepository.findById(secteurPayload.getStructureId());
secteur.setStructure(optionalStructure.orElse(null)); secteur.setStructure(optionalStructure.orElse(null));
List<SecteurDecoupage> secteurDecoupageList = new ArrayList<>(); List<SecteurDecoupage> secteurDecoupageList = new ArrayList<>();
@@ -134,4 +138,40 @@ public class SecteurServiceImpl implements SecteurService {
public Optional<Secteur> getSecteurById(Long id) { public Optional<Secteur> getSecteurById(Long id) {
return secteurRepository.findById(id); return secteurRepository.findById(id);
} }
@Override
public List<ParcelleStatsProjectionUnSecteur> getStatParcelleDecoupageUnSecteur(Long secteurId) {
return parcelleRepository.findStatsBySecteurs(List.of(secteurId));
}
@Override
public List<ParcelleStatsProjectionUnSecteur> getStatParcelleDecoupageByUserId(Long userId) {
List<AvoirFonction> avoirFonctions= avoirFonctionRepository.findAvoirFonctionByUser_Id(userId);
AtomicReference<List<ParcelleStatsProjectionUnSecteur>> 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<Secteur> secteurs= secteurRepository.findDistinctBySection_Id(avoirFonction.getFonction().getSection().getId());
List<Long> secteurIds = secteurs.stream()
.map(Secteur::getId)
.toList();
parcelleStatsProjectionUnSecteurs.set(parcelleRepository.findStatsBySecteurs(secteurIds));
}else if(avoirFonction.getFonction().getStructure()!=null){
List<Secteur> secteurs= secteurRepository.findDistinctBySection_Structure_Id(avoirFonction.getFonction().getStructure().getId());
List<Long> secteurIds = secteurs.stream()
.map(Secteur::getId)
.toList();
parcelleStatsProjectionUnSecteurs.set(parcelleRepository.findStatsBySecteurs(secteurIds));
}
});
return parcelleStatsProjectionUnSecteurs.get();
}
} }

View File

@@ -18,7 +18,9 @@ import io.gmss.fiscad.service.GeometryService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@@ -95,6 +97,15 @@ public class ParcelleServiceImpl implements ParcelleService {
@Override @Override
public Page<Parcelle> getParcelleList(Pageable pageable) { public Page<Parcelle> 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); return parcelleRepository.findAll(pageable);
} }

View File

@@ -26,18 +26,10 @@ public class EnqueteActiviteServiceImpl implements EnqueteActiviteService {
if (enqueteActivitePayLoadWeb.getId() != null) { if (enqueteActivitePayLoadWeb.getId() != null) {
throw new BadRequestException("Il ne s'agit pas ici d'une nouvelle activité : " + enqueteActivitePayLoadWeb.getId()); throw new BadRequestException("Il ne s'agit pas ici d'une nouvelle activité : " + enqueteActivitePayLoadWeb.getId());
} }
if (enqueteActivitePayLoadWeb.getPersonneId() != null) { if (enqueteActivitePayLoadWeb.getPersonneId() == null) {
throw new BadRequestException("Il ne s'agit pas ici d'une nouvelle activité : " + enqueteActivitePayLoadWeb.getId()); throw new BadRequestException("Veuillez préciser le contribuable : " + 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());
} }
EnqueteActivite enqueteActivite = entityFromPayLoadService.getEnqueteActivitePayLoadWeb(enqueteActivitePayLoadWeb); EnqueteActivite enqueteActivite = entityFromPayLoadService.getEnqueteActivitePayLoadWeb(enqueteActivitePayLoadWeb);
return enqueteActiviteRepository.save(enqueteActivite); return enqueteActiviteRepository.save(enqueteActivite);
} }

View File

@@ -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<Fonction> 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<Fonction> getFonctionList(Pageable pageable) {
return gererSecteurRepository.findAll(pageable);
}
@Override
public List<Fonction> getFonctionList() {
return gererSecteurRepository.findAll();
}
@Override
public Optional<Fonction> 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.");
}
}
}

View File

@@ -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<AvoirFonction> 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<AvoirFonction> optionalAvoirFonction= avoirFonctionRepository.findAvoirFonctionById(id);
if(optionalAvoirFonction.isEmpty()){
throw new BadRequestException("Impossible de trouver le avoirFonction à supprimer");
}
avoirFonctionRepository.deleteById(id);
}
@Override
public Page<AvoirFonction> getAvoirFonctionList(Pageable pageable) {
return avoirFonctionRepository.findAll(pageable);
}
@Override
public List<AvoirFonction> getAvoirFonctionList() {
return avoirFonctionRepository.findAll();
}
@Override
public Optional<AvoirFonction> getAvoirFonctionById(Long id) {
return avoirFonctionRepository.findAvoirFonctionById(id);
}
@Override
public List<AvoirFonction> getUserAvoirFonctionById(Long userId) {
return avoirFonctionRepository.findAvoirFonctionByUser_Id(userId);
}
}

View File

@@ -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<Profile> 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<Profile> optionalProfile= profileRepository.findProfileById(id);
if(optionalProfile.isEmpty()){
throw new BadRequestException("Impossible de trouver le profile à supprimer");
}
profileRepository.deleteById(id);
}
@Override
public Page<Profile> getProfileList(Pageable pageable) {
return profileRepository.findAll(pageable);
}
@Override
public List<Profile> getProfileList() {
return profileRepository.findAll();
}
@Override
public Optional<Profile> getProfileById(Long id) {
return profileRepository.findProfileById(id);
}
@Override
public Optional<Profile> 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);
}
}

View File

@@ -59,16 +59,17 @@ public class UserServiceImpl implements UserService {
throw new BadRequestException("Cet utilisateur existe déjà dans la base de donnéees."); throw new BadRequestException("Cet utilisateur existe déjà dans la base de donnéees.");
} }
Set<Role> roleSet = new HashSet<>(); // Set<Role> 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.setUsername(user.getEmail());
user.setResetPassword(resetPassword); user.setResetPassword(resetPassword);
user.setRoles(roleSet); // user.setRoles(roleSet);
user.setPassword(passwordEncoder.encode(user.getPassword())); user.setPassword(passwordEncoder.encode(user.getPassword()));
userRepository.save(user); userRepository.save(user);
return user; return user;
@@ -104,9 +105,9 @@ public class UserServiceImpl implements UserService {
String.format("L'utilisateur ayant pour id %s n'existe pas.", id) String.format("L'utilisateur ayant pour id %s n'existe pas.", id)
) )
); );
if (user.getRoles() == null || user.getRoles().isEmpty()) { // if (user.getRoles() == null || user.getRoles().isEmpty()) {
user.setRoles(user1.getRoles()); // user.setRoles(user1.getRoles());
} // }
if (user.getPassword() == null || user.getPassword().isBlank()) { if (user.getPassword() == null || user.getPassword().isBlank()) {
user.setPassword(user1.getPassword()); user.setPassword(user1.getPassword());
@@ -161,26 +162,28 @@ public class UserServiceImpl implements UserService {
@Override @Override
public List<User> getActivatedUserListByStructure(Long structureId) { public List<User> getActivatedUserListByStructure(Long structureId) {
Set<Role> roleSet = new HashSet<>(); // Set<Role> roleSet = new HashSet<>();
roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS)); // roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS));
Optional<Structure> structureOptional = structureService.getStructureById(structureId); // Optional<Structure> structureOptional = structureService.getStructureById(structureId);
if (structureOptional.isPresent()) { // if (structureOptional.isPresent()) {
return userRepository.findAllByStructureAndRolesNotIn(structureOptional.get(), roleSet); // return userRepository.findAllByStructureAndRolesNotIn(structureOptional.get(), roleSet);
} else { // } else {
throw new NotFoundException("Impossible de trouver la structure spécifiée."); // throw new NotFoundException("Impossible de trouver la structure spécifiée.");
} // }
return null;
} }
@Override @Override
public List<User> getUserUnActivatedListByStructure(Long structureId) { public List<User> getUserUnActivatedListByStructure(Long structureId) {
Set<Role> roleSet = new HashSet<>(); // Set<Role> roleSet = new HashSet<>();
roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS)); // roleSet.add(roleService.retrieveRoleByRoleName(UserRole.ROLE_ANONYMOUS));
Optional<Structure> structureOptional = structureService.getStructureById(structureId); // Optional<Structure> structureOptional = structureService.getStructureById(structureId);
if (structureOptional.isPresent()) { // if (structureOptional.isPresent()) {
return userRepository.findAllByStructureAndRolesIn(structureOptional.get(), roleSet); // return userRepository.findAllByStructureAndRolesIn(structureOptional.get(), roleSet);
} else { // } else {
throw new NotFoundException("Impossible de trouver la structure spécifiée."); // throw new NotFoundException("Impossible de trouver la structure spécifiée.");
} // }
return null;
} }
private static List<UserResponse> getUserResponses(List<User> users) { private static List<UserResponse> getUserResponses(List<User> users) {
@@ -194,7 +197,7 @@ public class UserServiceImpl implements UserService {
user.getUsername(), user.getUsername(),
user.isActive(), user.isActive(),
user.isResetPassword(), user.isResetPassword(),
user.getRoles(), user.getAvoirFonctions(),
user.getStructure(), user.getStructure(),
user.getIdCampagneCourant(), user.getIdCampagneCourant(),
user.getIdSecteurCourant())) user.getIdSecteurCourant()))
@@ -217,7 +220,8 @@ public class UserServiceImpl implements UserService {
@Override @Override
public List<User> getUserByProfil(UserRole userRole) { public List<User> 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( User user = userRepository.findByUsername(username).orElseThrow(() -> new NotFoundException(
String.format("L'utilisateur %s n'existe pas.", username) String.format("L'utilisateur %s n'existe pas.", username)
)); ));
Set<Role> roleSet = new HashSet<>(); // Set<Role> roleSet = new HashSet<>();
if (roleService.roleExistByRoleName(userRole)) { // if (roleService.roleExistByRoleName(userRole)) {
roleSet.add(roleService.retrieveRoleByRoleName(userRole)); // roleSet.add(roleService.retrieveRoleByRoleName(userRole));
} // }
user.setRoles(roleSet); //user.setRoles(roleSet);
user.setResetPassword(false); user.setResetPassword(false);
return userRepository.save(user); return userRepository.save(user);
} }
@@ -297,7 +301,7 @@ public class UserServiceImpl implements UserService {
user.getUsername(), user.getUsername(),
user.isActive(), user.isActive(),
user.isResetPassword(), user.isResetPassword(),
user.getRoles(), user.getAvoirFonctions(),
user.getStructure(), user.getStructure(),
user.getIdCampagneCourant(), user.getIdCampagneCourant(),
user.getIdSecteurCourant()); user.getIdSecteurCourant());

View File

@@ -4,6 +4,7 @@ import io.gmss.fiscad.entities.decoupage.Secteur;
import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.synchronisation.SecteurPayload; 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.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@@ -25,4 +26,7 @@ public interface SecteurService {
List<Secteur> getSecteurListUneStruture(Long structureId); List<Secteur> getSecteurListUneStruture(Long structureId);
Optional<Secteur> getSecteurById(Long id); Optional<Secteur> getSecteurById(Long id);
List<ParcelleStatsProjectionUnSecteur> getStatParcelleDecoupageUnSecteur(Long serveurId) ;
List<ParcelleStatsProjectionUnSecteur> getStatParcelleDecoupageByUserId(Long userId) ;
} }

View File

@@ -4,6 +4,7 @@ import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.exceptions.BadRequestException; import io.gmss.fiscad.exceptions.BadRequestException;
import io.gmss.fiscad.exceptions.NotFoundException; import io.gmss.fiscad.exceptions.NotFoundException;
import io.gmss.fiscad.paylaods.request.crudweb.ParcellePayLoadWeb; 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.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@@ -24,4 +25,6 @@ public interface ParcelleService {
List<Parcelle> getParcelleList(); List<Parcelle> getParcelleList();
Optional<Parcelle> getParcelleById(Long id); Optional<Parcelle> getParcelleById(Long id);
} }

View File

@@ -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<Fonction> getFonctionList(Pageable pageable);
List<Fonction> getFonctionList();
Optional<Fonction> getFonctionById(Long id);
}

View File

@@ -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<AvoirFonction> getAvoirFonctionList(Pageable pageable);
List<AvoirFonction> getAvoirFonctionList();
Optional<AvoirFonction> getAvoirFonctionById(Long id);
List<AvoirFonction> getUserAvoirFonctionById(Long userId);
}

View File

@@ -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<Profile> getProfileList(Pageable pageable);
List<Profile> getProfileList();
Optional<Profile> getProfileById(Long id);
Optional<Profile> getProfileByProfileName(UserProfile userProfile);
boolean profileExistByProfileName(UserProfile userProfile);
Profile retrieveProfileByProfileName(UserProfile userProfile);
}

View File

@@ -1,6 +1,7 @@
package io.gmss.fiscad.paylaods; package io.gmss.fiscad.paylaods;
import io.gmss.fiscad.entities.infocad.parametre.Structure; import io.gmss.fiscad.entities.infocad.parametre.Structure;
import io.gmss.fiscad.entities.user.AvoirFonction;
import io.gmss.fiscad.entities.user.Role; import io.gmss.fiscad.entities.user.Role;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@@ -20,7 +21,7 @@ public class UserResponse {
private String username; private String username;
private boolean active; private boolean active;
private boolean resetPassword; private boolean resetPassword;
private Set<Role> roles; private Set<AvoirFonction> avoirFonctions;
private Structure structure; private Structure structure;
private Long idCampagneCourant; private Long idCampagneCourant;
private Long idSecteurCourant; private Long idSecteurCourant;

View File

@@ -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;
}

View File

@@ -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 ;
}

View File

@@ -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<Role> roles;
}

View File

@@ -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();
}

View File

@@ -41,7 +41,11 @@ public interface SecteurRepository extends JpaRepository<Secteur, Long> {
inner join secteur st on st.id=b.secteur_id inner join secteur st on st.id=b.secteur_id
left join enquete e on e.bloc_id=b.id left join enquete e on e.bloc_id=b.id
where s.id=?1 and st.id=?2 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) """, nativeQuery = true)
List<SecteurEnqResponse> getSecteurEnqResponse(Long structure_id , Long secteurId); List<SecteurEnqResponse> getSecteurEnqResponse(Long structure_id , Long secteurId);
List<Secteur> findDistinctBySection_Id(Long sectionId);
List<Secteur> findDistinctBySection_Structure_Id(Long structureId);
} }

View File

@@ -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<Section, Long> {
List<Secteur> findAllByStructure_Id(Long structureId);
}

View File

@@ -3,6 +3,7 @@ package io.gmss.fiscad.repositories.infocad.metier;
import io.gmss.fiscad.entities.infocad.metier.Parcelle; import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.paylaods.response.StatistiqueTypeNombreResponse; import io.gmss.fiscad.paylaods.response.StatistiqueTypeNombreResponse;
import io.gmss.fiscad.paylaods.response.restoration.ParcellePayLoadRestor; 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.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
@@ -57,4 +58,41 @@ public interface ParcelleRepository extends JpaRepository<Parcelle, Long> {
GROUP BY type GROUP BY type
""",nativeQuery = true) """,nativeQuery = true)
List<StatistiqueTypeNombreResponse> getParcelleBatieResponse(@Param("codeQuartier") String codeQuartier); List<StatistiqueTypeNombreResponse> 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<ParcelleStatsProjectionUnSecteur> findStatsBySecteurs(
@Param("secteurIds") List<Long> secteurIds
);
} }

View File

@@ -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<Fonction, Long> {
}

View File

@@ -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<AvoirFonction, Long> {
Optional<AvoirFonction> findAvoirFonctionById(Long id);
List<AvoirFonction> findAvoirFonctionByUser_Id(Long userId);
}

View File

@@ -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<Profile, Long> {
Optional<Profile> findProfileById(Long id);
Optional<Profile> findProfileByNom(UserProfile nom);
boolean existsByNom(UserProfile userProfile);
Profile getProfilesByNom(UserProfile userProfile);
}

View File

@@ -18,9 +18,9 @@ public interface UserRepository extends JpaRepository<User, Long> {
long countAllByUsernameIsNotNull(); long countAllByUsernameIsNotNull();
List<User> findAllByStructureAndRolesIn(Structure structure, Set<Role> roleSet); // List<User> findAllByStructureAndRolesIn(Structure structure, Set<Role> roleSet);
List<User> findAllByStructureAndRolesNotIn(Structure structure, Set<Role> roleSet); // List<User> findAllByStructureAndRolesNotIn(Structure structure, Set<Role> roleSet);
List<User> findAllByRolesContains(UserRole userRole); // List<User> findAllByRolesContains(UserRole userRole);
} }

View File

@@ -42,8 +42,8 @@ public class TokenAuthentificationProvider {
Date expiryDate = new Date(now.getTime() + jwtExpirationInMs); Date expiryDate = new Date(now.getTime() + jwtExpirationInMs);
Map<String, Object> claims = new HashMap<>(); Map<String, Object> claims = new HashMap<>();
List<String> roles = new ArrayList<>(); //List<String> roles = new ArrayList<>();
userDetails.getAuthorities().forEach(role -> roles.add(role.getAuthority())); //userDetails.getAuthorities().forEach(role -> roles.add(role.getAuthority()));
//claims.put("roles", roles); //claims.put("roles", roles);
User user = userRepository.findByUsername(userDetails.getUsername()).get(); User user = userRepository.findByUsername(userDetails.getUsername()).get();
claims.put("user", getUserResponseFromUser(user)); claims.put("user", getUserResponseFromUser(user));
@@ -69,11 +69,10 @@ public class TokenAuthentificationProvider {
user.getUsername(), user.getUsername(),
user.isActive(), user.isActive(),
user.isResetPassword(), user.isResetPassword(),
user.getRoles(), user.getAvoirFonctions(),
user.getStructure(), user.getStructure(),
user.getIdCampagneCourant(), user.getIdCampagneCourant(),
user.getIdSecteurCourant()); user.getIdSecteurCourant());
} }
public String getUsernameFromJWT(String token) { public String getUsernameFromJWT(String token) {

View File

@@ -1,17 +1,23 @@
package io.gmss.fiscad.security; 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 io.gmss.fiscad.entities.user.User;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class UserPrincipal implements UserDetails { public class UserPrincipal implements UserDetails {
/** /**
* *
*/ */
@@ -27,13 +33,26 @@ public class UserPrincipal implements UserDetails {
public static UserPrincipal create(User user) { public static UserPrincipal create(User user) {
List<GrantedAuthority> authorities = new ArrayList<>(); List<GrantedAuthority> authorities = new ArrayList<>();
user.getRoles().forEach((role) -> Set<AvoirFonction> avoirFonctions= user.getAvoirFonctions() ;
authorities.add(new SimpleGrantedAuthority(role.getNom().name()))
Set<Role> 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( return new UserPrincipal(
user, user,
authorities authorities
); );
} }
public void setAuthorities(Collection<? extends GrantedAuthority> authorities) { public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {

View File

@@ -2,6 +2,8 @@ package io.gmss.fiscad.service;
import io.gmss.fiscad.entities.decoupage.Commune; import io.gmss.fiscad.entities.decoupage.Commune;
import io.gmss.fiscad.entities.decoupage.Nationalite; 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.Enquete;
import io.gmss.fiscad.entities.infocad.metier.Parcelle; import io.gmss.fiscad.entities.infocad.metier.Parcelle;
import io.gmss.fiscad.entities.infocad.metier.Piece; 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.infocad.parametre.*;
import io.gmss.fiscad.entities.rfu.metier.*; import io.gmss.fiscad.entities.rfu.metier.*;
import io.gmss.fiscad.entities.rfu.parametre.Caracteristique; 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.paylaods.request.crudweb.*;
import io.gmss.fiscad.repositories.decoupage.CommuneRepository; import io.gmss.fiscad.repositories.decoupage.CommuneRepository;
import io.gmss.fiscad.repositories.decoupage.NationaliteRepository; 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.EnqueteRepository;
import io.gmss.fiscad.repositories.infocad.metier.ParcelleRepository; import io.gmss.fiscad.repositories.infocad.metier.ParcelleRepository;
import io.gmss.fiscad.repositories.infocad.metier.PieceRepository; import io.gmss.fiscad.repositories.infocad.metier.PieceRepository;
import io.gmss.fiscad.repositories.infocad.parametre.*; import io.gmss.fiscad.repositories.infocad.parametre.*;
import io.gmss.fiscad.repositories.rfu.metier.*; import io.gmss.fiscad.repositories.rfu.metier.*;
import io.gmss.fiscad.repositories.rfu.parametre.CaracteristiqueRepository; 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 lombok.AllArgsConstructor;
import org.codehaus.groovy.transform.SourceURIASTTransformation;
import org.hibernate.event.spi.SaveOrUpdateEvent;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Optional; import java.util.Optional;
@@ -48,6 +55,11 @@ public class EntityFromPayLoadService {
private final ProfessionRepository professionRepository; private final ProfessionRepository professionRepository;
private final TypePersonneRepository typePersonneRepository; private final TypePersonneRepository typePersonneRepository;
private final CommuneRepository communeRepository; 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){ public CaracteristiqueParcelle getCaracteristiqueParcelleFromPayLoadWeb(CaracteristiqueParcellePayloadWeb caracteristiqueParcellePayloadWeb){
CaracteristiqueParcelle caracteristiqueParcelle=new CaracteristiqueParcelle(); CaracteristiqueParcelle caracteristiqueParcelle=new CaracteristiqueParcelle();
@@ -225,6 +237,65 @@ public class EntityFromPayLoadService {
return uniteLogement ; return uniteLogement ;
} }
public Fonction getFonctionFromPayLoadWeb(FonctionPaylaodWeb fonctionPaylaodWeb){
Fonction fonction =new Fonction();
Optional<Secteur> optionalSecteur=Optional.empty();
Optional<Section> optionalSection=Optional.empty();
Optional<Profile> optionalProfile=Optional.empty();
Optional<User> optionalUser=Optional.empty();
Optional<Structure> 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<Fonction> optionalFonction=Optional.empty();
Optional<User> 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){ public Personne getPersonneFromPayLoadWeb(PersonnePayLoadWeb personnePayLoadWeb){
Personne personne=new Personne(); Personne personne=new Personne();
Optional<SituationMatrimoniale> optionalSituationMatrimoniale=Optional.empty(); Optional<SituationMatrimoniale> optionalSituationMatrimoniale=Optional.empty();

View File

@@ -1,17 +1,17 @@
server.port=8282 server.port=8282
io.gmss.fiscad.profile=${IO_GMSS_FISCAD_PROFILE} #io.gmss.fiscad.profile=${IO_GMSS_FISCAD_PROFILE}
#io.gmss.fiscad.profile=dgi io.gmss.fiscad.profile=dgi
# TEST ENV # TEST ENV
#spring.datasource.url=jdbc:postgresql://vmi792116.contaboserver.net:5599/dgi_db #spring.datasource.url=jdbc:postgresql://vmi792116.contaboserver.net:5599/dgi_db
#spring.datasource.username=infocad_user #spring.datasource.username=infocad_user
#spring.datasource.password=W5fwD({9*q53 #spring.datasource.password=W5fwD({9*q53
# LOCAL ENV # LOCAL ENV
#spring.datasource.url=jdbc:postgresql://localhost:5432/fiscad_dgi spring.datasource.url=jdbc:postgresql://localhost:5432/fiscad_dgi
#spring.datasource.username=infocad_user spring.datasource.username=infocad_user
#spring.datasource.password=W5fwD({9*q53 spring.datasource.password=W5fwD({9*q53
# PROD ENVIRONNEMENT # PROD ENVIRONNEMENT
spring.datasource.url=${SPRING_DATASOURCE_URL} #spring.datasource.url=${SPRING_DATASOURCE_URL}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME} #spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD} #spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}

View File

@@ -1,6 +1,6 @@
spring.profiles.active=${SPRING_PROFILES_ACTIVE} #spring.profiles.active=${SPRING_PROFILES_ACTIVE}
#spring.profiles.active=abomey #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.id.new_generator_mappings=false
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.jpa.open-in-view=false spring.jpa.open-in-view=false
@@ -46,11 +46,11 @@ logging.file.name=/app/logs/fiscad.log
#app.abs.env.defaultuser = fiscad_admin #app.abs.env.defaultuser = fiscad_admin
#app.default-user.username=fiscad_admin app.default-user.username=fiscad_admin
#app.default-user.password=1234567890 app.default-user.password=1234567890
app.default-user.username=${DEFAULT_USER_NAME} #app.default-user.username=${DEFAULT_USER_NAME}
app.default-user.password=${DEFAULT_USER_PASSWORD} #app.default-user.password=${DEFAULT_USER_PASSWORD}
app.upload.root=${file.upload_dir} app.upload.root=${file.upload_dir}
app.upload.zips.received=${app.upload.root}/zips/received app.upload.zips.received=${app.upload.root}/zips/received