Merge branch 'ch-evo-24-03-2025' into 'main'
Modification apportées par le DAI See merge request christianakpona/fiscad!8
This commit is contained in:
@@ -22,7 +22,7 @@ import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "api/secteur", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@SecurityRequirement(name = "bearer")
|
||||
//@SecurityRequirement(name = "bearer")
|
||||
@Tag(name = "Secteur")
|
||||
public class SecteurController {
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package io.gmss.fiscad.controllers.infocad.metier;
|
||||
|
||||
|
||||
import io.gmss.fiscad.entities.infocad.metier.Tpe;
|
||||
import io.gmss.fiscad.interfaces.infocad.metier.ParcelleGeomService;
|
||||
import io.gmss.fiscad.interfaces.infocad.metier.TpeService;
|
||||
import io.gmss.fiscad.paylaods.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import 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.multipart.MultipartFile;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "api/parcelleGeom", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@SecurityRequirement(name = "bearer")
|
||||
@Tag(name = "ParcelleGeometrie")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class ParcelleGeomController {
|
||||
|
||||
private final ParcelleGeomService parcelleGeomService;
|
||||
|
||||
public ParcelleGeomController(ParcelleGeomService parcelleGeomService) {
|
||||
this.parcelleGeomService = parcelleGeomService;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<?> createTpe(@RequestPart(required = true) MultipartFile file) {
|
||||
try{
|
||||
int n = parcelleGeomService.createParcelleFromGeoJsonFile(file);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, null, n+" Parcelles crées avec succès"),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(false, e.getMessage()),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/all")
|
||||
public ResponseEntity<?> getAllTpeList() {
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, parcelleGeomService.getParcelleGeomList(), "Liste des tpe chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/all-paged")
|
||||
public ResponseEntity<?> getAllTpePaged(@RequestParam int pageNo, @RequestParam int pageSize) {
|
||||
Pageable pageable = PageRequest.of(pageNo, pageSize);
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, parcelleGeomService.getParcelleGeomList(pageable), "Liste des tpe chargée avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/id/{id}")
|
||||
public ResponseEntity<?> getTpeById(@PathVariable Long id) {
|
||||
return new ResponseEntity<>(
|
||||
new ApiResponse<>(true, parcelleGeomService.getParcelleGeomById(id), "Tpe trouvé avec succès."),
|
||||
HttpStatus.OK
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "api/user", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@SecurityRequirement(name = "bearer")
|
||||
//@SecurityRequirement(name = "bearer")
|
||||
@Tag(name = "User")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class UserController {
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
package io.gmss.fiscad.entities.infocad.metier;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import io.gmss.fiscad.entities.BaseEntity;
|
||||
import io.gmss.fiscad.entities.decoupage.Quartier;
|
||||
import io.gmss.fiscad.entities.infocad.parametre.NatureDomaine;
|
||||
import io.gmss.fiscad.entities.rfu.metier.Batiment;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -11,11 +15,15 @@ import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.ColumnDefault;
|
||||
import org.hibernate.annotations.SQLDelete;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.MultiPolygon;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
import org.n52.jackson.datatype.jts.GeometryDeserializer;
|
||||
import org.n52.jackson.datatype.jts.GeometrySerializer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Entity
|
||||
@@ -43,21 +51,44 @@ public class ParcelleGeom extends BaseEntity implements Serializable {
|
||||
private String longitude;
|
||||
private String latitude;
|
||||
private String pointsPolygone;
|
||||
//////////
|
||||
private String departement;
|
||||
private String commune;
|
||||
private String arrondissement;
|
||||
private String villageQuartier;
|
||||
private String codeBloc;
|
||||
private String codeParcelle;
|
||||
private String codeEquipe;
|
||||
private Integer superficie;
|
||||
private String elNumeroEtatLieux;
|
||||
private String elLot;
|
||||
private String elLettreParcelle;
|
||||
private String rfuQuartierOuZone;
|
||||
private String rfuIlot;
|
||||
private String rfuLettreParcelle;
|
||||
private String dateCollecte;
|
||||
private String nomLotissement;
|
||||
private String nomEtPrenoms;
|
||||
private String sourceCollecte;
|
||||
private String observations;
|
||||
|
||||
////////////
|
||||
|
||||
@OneToOne
|
||||
private Parcelle parcelle;
|
||||
|
||||
|
||||
@ColumnDefault("0")
|
||||
private int geomSrid;
|
||||
|
||||
@JsonSerialize(using = GeometrySerializer.class)
|
||||
@JsonDeserialize(contentUsing = GeometryDeserializer.class)
|
||||
@Column(name = "geom", columnDefinition = "geometry(MultiPolygon,4326)")
|
||||
private MultiPolygon geometry;
|
||||
// @JsonSerialize(using = GeometrySerializer.class)
|
||||
// @JsonDeserialize(contentUsing = GeometryDeserializer.class)
|
||||
// @Column(name = "geom",columnDefinition = "geometry(Polygon,4326)")
|
||||
// private Polygon geometry ;
|
||||
|
||||
@JsonSerialize(using = GeometrySerializer.class)
|
||||
@JsonDeserialize(contentUsing = GeometryDeserializer.class)
|
||||
@Column(name = "geom_32631", columnDefinition = "geometry(MultiPolygon,32631)")
|
||||
private MultiPolygon geometry32631;
|
||||
// @Column(name = "geom_32631",columnDefinition = "geometry(Polygon,32631)")
|
||||
//private Polygon geometry32631 ;
|
||||
@Column(columnDefinition = "geometry")
|
||||
private Geometry geometry;
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package io.gmss.fiscad.implementations.infocad.metier;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.gmss.fiscad.entities.infocad.metier.Parcelle;
|
||||
import io.gmss.fiscad.entities.infocad.metier.ParcelleGeom;
|
||||
import io.gmss.fiscad.exceptions.BadRequestException;
|
||||
import io.gmss.fiscad.exceptions.NotFoundException;
|
||||
import io.gmss.fiscad.interfaces.infocad.metier.ParcelleGeomService;
|
||||
import io.gmss.fiscad.paylaods.request.ParcelleGeomPayload;
|
||||
import io.gmss.fiscad.repositories.infocad.metier.ParcelleGeomRepository;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
import org.locationtech.jts.io.ParseException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.io.WKTReader;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ParcelleGeomServiceImpl implements ParcelleGeomService {
|
||||
|
||||
private final ParcelleGeomRepository parcelleGeomRepository;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Override
|
||||
public int createParcelleFromGeoJsonFile(MultipartFile file) throws BadRequestException {
|
||||
InputStream inputStream = null;
|
||||
JsonNode rootNode=null;
|
||||
try {
|
||||
inputStream = file.getInputStream();
|
||||
rootNode = objectMapper.readTree(inputStream);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
int n=0;
|
||||
if (!rootNode.has("features")) {
|
||||
throw new RuntimeException("Le fichier ne contient pas de 'features'");
|
||||
}
|
||||
|
||||
WKTReader wktReader = new WKTReader();
|
||||
Iterator<JsonNode> features = rootNode.get("features").elements();
|
||||
|
||||
while (features.hasNext()) {
|
||||
n++;
|
||||
JsonNode feature = features.next();
|
||||
createOnParcelleFromGeoJson(feature);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelleGeom createOnParcelleFromGeoJson(JsonNode feature) throws BadRequestException {
|
||||
JsonNode geometryNode = feature.get("geometry");
|
||||
JsonNode propertiesNode = feature.get("properties");
|
||||
WKTReader wktReader = new WKTReader();
|
||||
if (geometryNode != null) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
ParcelleGeomPayload parcelleGeomPayload =new ParcelleGeomPayload();
|
||||
try {
|
||||
parcelleGeomPayload = objectMapper.readValue(propertiesNode.toString(), ParcelleGeomPayload.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Geometry geometry = null;
|
||||
try {
|
||||
String wkt = convertGeoJsonToWKT(geometryNode);
|
||||
geometry = wktReader.read(wkt);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
ParcelleGeom parcelleGeom = new ParcelleGeom();
|
||||
parcelleGeom.setGeometry(geometry);
|
||||
parcelleGeom.setCommune(parcelleGeomPayload.getDepartement());
|
||||
parcelleGeom.setArrondissement(parcelleGeomPayload.getArrondissement());
|
||||
parcelleGeom.setVillageQuartier(parcelleGeomPayload.getVillageQuartier());
|
||||
parcelleGeom.setCodeBloc(parcelleGeomPayload.getCodeBloc());
|
||||
parcelleGeom.setCodeParcelle(parcelleGeomPayload.getCodeParcelle());
|
||||
parcelleGeom.setCodeEquipe(parcelleGeomPayload.getCodeEquipe());
|
||||
parcelleGeom.setSuperficie(parcelleGeomPayload.getSuperficie());
|
||||
parcelleGeom.setElNumeroEtatLieux(parcelleGeomPayload.getElNumeroEtatLieux());
|
||||
parcelleGeom.setElLot(parcelleGeomPayload.getElLot());
|
||||
parcelleGeom.setRfuQuartierOuZone(parcelleGeomPayload.getRfuQuartierOuZone());
|
||||
parcelleGeom.setElLettreParcelle(parcelleGeomPayload.getElLettreParcelle());
|
||||
parcelleGeom.setRfuIlot(parcelleGeomPayload.getRfuIlot());
|
||||
parcelleGeom.setRfuLettreParcelle(parcelleGeomPayload.getRfuLettreParcelle());
|
||||
parcelleGeom.setDateCollecte(parcelleGeomPayload.getDateCollecte());
|
||||
parcelleGeom.setNomLotissement(parcelleGeomPayload.getNomLotissement());
|
||||
parcelleGeom.setNomEtPrenoms(parcelleGeomPayload.getNomEtPrenoms());
|
||||
parcelleGeom.setSourceCollecte(parcelleGeomPayload.getSourceCollecte());
|
||||
parcelleGeom.setObservations(parcelleGeomPayload.getObservations());
|
||||
return parcelleGeomRepository.save(parcelleGeom);
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelleGeom updateParcelleGeom(MultipartFile file) throws NotFoundException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteParcelle(Long id) throws NotFoundException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<ParcelleGeom> getParcelleGeomList(Pageable pageable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ParcelleGeom> getParcelleGeomList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ParcelleGeom> getParcelleGeomById(Long id) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
private String convertGeoJsonToWKT(JsonNode geometryNode) {
|
||||
String type = geometryNode.get("type").asText();
|
||||
String coordinates = geometryNode.get("coordinates").toString();
|
||||
switch (type) {
|
||||
case "Point":
|
||||
return "POINT " + formatCoordinates(coordinates);
|
||||
case "LineString":
|
||||
return "LINESTRING " + formatCoordinates(coordinates);
|
||||
case "Polygon":
|
||||
return "POLYGON " + formatCoordinates(coordinates);
|
||||
default:
|
||||
throw new RuntimeException("Type géométrique non pris en charge : " + type);
|
||||
}
|
||||
}
|
||||
|
||||
private String formatCoordinates(String jsonCoords) {
|
||||
return jsonCoords.replace("[", "(").replace("]", ")").replace(",", " ");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -195,7 +195,9 @@ public class UserServiceImpl implements UserService {
|
||||
user.isActive(),
|
||||
user.isResetPassword(),
|
||||
user.getRoles(),
|
||||
user.getStructure()))
|
||||
user.getStructure(),
|
||||
user.getIdCampagneCourant(),
|
||||
user.getIdSecteurCourant()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -296,6 +298,9 @@ public class UserServiceImpl implements UserService {
|
||||
user.isActive(),
|
||||
user.isResetPassword(),
|
||||
user.getRoles(),
|
||||
user.getStructure());
|
||||
user.getStructure(),
|
||||
user.getIdCampagneCourant(),
|
||||
user.getIdSecteurCourant());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.gmss.fiscad.interfaces.infocad.metier;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.gmss.fiscad.entities.infocad.metier.Parcelle;
|
||||
import io.gmss.fiscad.entities.infocad.metier.ParcelleGeom;
|
||||
import io.gmss.fiscad.exceptions.BadRequestException;
|
||||
import io.gmss.fiscad.exceptions.NotFoundException;
|
||||
import io.gmss.fiscad.paylaods.request.ParcellePayLoad;
|
||||
@@ -12,12 +14,11 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ParcelleGeomService {
|
||||
|
||||
|
||||
Parcelle createParcelle(MultipartFile file) throws BadRequestException;
|
||||
Parcelle updateParcelle(MultipartFile file) throws NotFoundException;
|
||||
int createParcelleFromGeoJsonFile(MultipartFile file) throws BadRequestException;
|
||||
ParcelleGeom createOnParcelleFromGeoJson(JsonNode jsonNode) throws BadRequestException;
|
||||
ParcelleGeom updateParcelleGeom(MultipartFile file) throws NotFoundException;
|
||||
void deleteParcelle(Long id) throws NotFoundException;
|
||||
Page<Parcelle> getParcelleList(Pageable pageable);
|
||||
List<Parcelle> getParcelleList();
|
||||
Optional<Parcelle> getParcelleById(Long id);
|
||||
Page<ParcelleGeom> getParcelleGeomList(Pageable pageable);
|
||||
List<ParcelleGeom> getParcelleGeomList();
|
||||
Optional<ParcelleGeom> getParcelleGeomById(Long id);
|
||||
}
|
||||
|
||||
@@ -22,5 +22,8 @@ public class UserResponse {
|
||||
private boolean resetPassword;
|
||||
private Set<Role> roles;
|
||||
private Structure structure;
|
||||
private Long idCampagneCourant;
|
||||
private Long idSecteurCourant;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package io.gmss.fiscad.paylaods.request;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL) // Ignore les valeurs null lors de la sérialisation
|
||||
public class ParcelleGeomPayload {
|
||||
private String departement;
|
||||
private String commune;
|
||||
private String arrondissement;
|
||||
private String villageQuartier;
|
||||
private String codeBloc;
|
||||
private String codeParcelle;
|
||||
private String codeEquipe;
|
||||
private Integer superficie;
|
||||
private String elNumeroEtatLieux;
|
||||
private String elLot;
|
||||
private String elLettreParcelle;
|
||||
private String rfuQuartierOuZone;
|
||||
private String rfuIlot;
|
||||
private String rfuLettreParcelle;
|
||||
private String dateCollecte;
|
||||
private String nomLotissement;
|
||||
private String nomEtPrenoms;
|
||||
private String sourceCollecte;
|
||||
private String observations;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.gmss.fiscad.repositories.infocad.metier;
|
||||
|
||||
import io.gmss.fiscad.entities.infocad.metier.Parcelle;
|
||||
import io.gmss.fiscad.entities.infocad.metier.ParcelleGeom;
|
||||
import io.gmss.fiscad.paylaods.response.restoration.ParcellePayLoad;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ParcelleGeomRepository extends JpaRepository<ParcelleGeom, Long> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -70,7 +70,10 @@ public class TokenAuthentificationProvider {
|
||||
user.isActive(),
|
||||
user.isResetPassword(),
|
||||
user.getRoles(),
|
||||
user.getStructure());
|
||||
user.getStructure(),
|
||||
user.getIdCampagneCourant(),
|
||||
user.getIdSecteurCourant());
|
||||
|
||||
}
|
||||
|
||||
public String getUsernameFromJWT(String token) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
spring.jpa.properties.hibernate.id.new_generator_mappings=false
|
||||
|
||||
# TEST ENV
|
||||
spring.datasource.url=jdbc:postgresql://vmi792116.contaboserver.net:5599/abomey_db
|
||||
spring.datasource.username=infocad_user
|
||||
|
||||
Reference in New Issue
Block a user