From d109fe30e189ad4d445fae13d5bfdab1295f5db8 Mon Sep 17 00:00:00 2001 From: Giuli1297 Date: Wed, 10 Nov 2021 14:16:25 -0300 Subject: [PATCH] Postulacion con mismo numero de cedula actualiza postulacion anterior --- curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java | 17 +++++++++++++++-- curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java | 2 +- curriculumsearch/src/main/java/com/roshka/modelo/ReferenciaPersonal.java | 11 ++--------- curriculumsearch/src/main/java/com/roshka/repositorio/EstudioRepository.java | 4 ++++ curriculumsearch/src/main/java/com/roshka/repositorio/ExperienciaRepository.java | 3 +++ curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java | 2 ++ curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteTecnologiaRepository.java | 5 ++++- curriculumsearch/src/main/webapp/jsp/postulante-form.jsp | 2 +- 8 files changed, 32 insertions(+), 14 deletions(-) diff --git a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java index 9a09b88..59e7483 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java @@ -47,18 +47,23 @@ public class PostulanteController { InstitucionRepository institucionRepository; DepartamentoRepository depRepo; CiudadRepository ciuRepo; + EstudioRepository estudioRepository; + PostulanteTecnologiaRepository postulanteTecnologiaRepository; @Autowired public PostulanteController( PostulanteRepository post, TecnologiaRepository tecRepo, ExperienciaRepository expRepo, InstitucionRepository institucionRepository, DepartamentoRepository depRepo, - CiudadRepository ciuRepo) { + CiudadRepository ciuRepo, EstudioRepository estudioRepository, + PostulanteTecnologiaRepository postulanteTecnologiaRepository) { this.post = post; this.tecRepo = tecRepo; this.expRepo = expRepo; this.institucionRepository = institucionRepository; this.depRepo = depRepo; this.ciuRepo = ciuRepo; + this.estudioRepository = estudioRepository; + this.postulanteTecnologiaRepository = postulanteTecnologiaRepository; } @RequestMapping("home") @@ -121,11 +126,19 @@ public class PostulanteController { @PostMapping(value = "/postulante",consumes = "application/json") public String guardarPostulante(@RequestBody Postulante postulante){ + //Codigo encargado de modificar postulacion si se envia mismo CI + Postulante postulantex = post.findByNroDocument(postulante.getnroDocument()); + if(postulantex != null){ + estudioRepository.findByPostulante(postulantex).forEach(x -> estudioRepository.delete(x)); + expRepo.findByPostulante(postulantex).forEach(x -> expRepo.delete(x)); + postulanteTecnologiaRepository.findByPostulante(postulantex).forEach(x -> postulanteTecnologiaRepository.delete(x)); + postulante.setId(postulantex.getId()); + } postulante.getTecnologias().stream().filter( tec -> tec.getTecnologia().getId() != 0 ).forEach( tec -> tec.setTecnologia(tecRepo.getById(tec.getTecnologia().getId())) - ); + ); for(Estudio estudio: postulante.getEstudios()){ String nombreIns = ""; nombreIns = estudio.getInstitucion().getNombre().toLowerCase(); diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java b/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java index dca587e..797adcc 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java @@ -33,7 +33,7 @@ public class PostulanteTecnologia { @JoinColumn private Tecnologia tecnologia; - @ManyToOne() + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn @JsonBackReference(value = "postulantetecnologia-postulante") private Postulante postulante; diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/ReferenciaPersonal.java b/curriculumsearch/src/main/java/com/roshka/modelo/ReferenciaPersonal.java index 75aca3b..2c907e7 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/ReferenciaPersonal.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/ReferenciaPersonal.java @@ -1,13 +1,6 @@ package com.roshka.modelo; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; +import javax.persistence.*; import javax.validation.constraints.NotBlank; import com.fasterxml.jackson.annotation.JsonBackReference; @@ -31,7 +24,7 @@ public class ReferenciaPersonal { @Column(name = "relacion") private String relacion; - @ManyToOne(optional = false) + @ManyToOne(cascade = CascadeType.ALL, optional = false) @JoinColumn @JsonBackReference private Postulante postulante; diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/EstudioRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/EstudioRepository.java index 50d9336..ad25f79 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/EstudioRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/EstudioRepository.java @@ -1,10 +1,14 @@ package com.roshka.repositorio; +import com.roshka.modelo.Postulante; import org.springframework.data.jpa.repository.JpaRepository; import com.roshka.modelo.Estudio; +import java.util.List; + public interface EstudioRepository extends JpaRepository{ + public List findByPostulante(Postulante postulante); } diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/ExperienciaRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/ExperienciaRepository.java index cebad2a..5eadaaf 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/ExperienciaRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/ExperienciaRepository.java @@ -1,5 +1,6 @@ package com.roshka.repositorio; +import com.roshka.modelo.Postulante; import org.springframework.data.jpa.repository.JpaRepository; @@ -9,4 +10,6 @@ import com.roshka.modelo.Experiencia; public interface ExperienciaRepository extends JpaRepository { public List findByCargoLike(String cargo); + + public List findByPostulante(Postulante postulante); } diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java index cb9ef21..3cc8530 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java @@ -12,6 +12,8 @@ import com.roshka.modelo.Postulante; public interface PostulanteRepository extends JpaRepository { + public Postulante findByNroDocument(String ci); + @Query("select p from Postulante p join p.estudios e on e.institucion.nombre LIKE %?1%") public List findByInstitucionEstudio(String institucion); diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteTecnologiaRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteTecnologiaRepository.java index 8a295b0..012f485 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteTecnologiaRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteTecnologiaRepository.java @@ -1,12 +1,15 @@ package com.roshka.repositorio; +import com.roshka.modelo.Postulante; import org.springframework.data.jpa.repository.JpaRepository; import com.roshka.modelo.PostulanteTecnologia; -public interface PostulanteTecnologiaRepository extends JpaRepository{ +import java.util.List; +public interface PostulanteTecnologiaRepository extends JpaRepository{ + public List findByPostulante(Postulante postulante); } diff --git a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp index e6f19ca..55527cf 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp @@ -395,7 +395,7 @@ - +