diff --git a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java index 0ffb990..1e21adb 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java @@ -5,10 +5,9 @@ import java.util.List; import javax.validation.ConstraintViolationException; -import com.roshka.modelo.Disponibilidad; -import com.roshka.modelo.Modalidad; -import com.roshka.modelo.Postulante; +import com.roshka.modelo.*; import com.roshka.repositorio.ExperienciaRepository; +import com.roshka.repositorio.InstitucionRepository; import com.roshka.repositorio.PostulanteRepository; import com.roshka.repositorio.TecnologiaRepository; @@ -24,15 +23,18 @@ import org.springframework.web.bind.annotation.*; @Controller public class PostulanteController { - @Autowired - PostulanteRepository post; - - @Autowired + PostulanteRepository post; TecnologiaRepository tecRepo; - - @Autowired ExperienciaRepository expRepo; + InstitucionRepository institucionRepository; + @Autowired + public PostulanteController(PostulanteRepository post, TecnologiaRepository tecRepo, ExperienciaRepository expRepo, InstitucionRepository institucionRepository) { + this.post = post; + this.tecRepo = tecRepo; + this.expRepo = expRepo; + this.institucionRepository = institucionRepository; + } @RequestMapping("/") public String index() { @@ -53,11 +55,20 @@ public class PostulanteController { model.addAttribute("tecnologias", tecRepo.findAll()); model.addAttribute("modalidades", Modalidad.values()); model.addAttribute("disponibilidades", Disponibilidad.values()); + model.addAttribute("tiposDeEstudio", TipoDeEstudio.values()); + model.addAttribute("estadosEstudio", EstadoEstudio.values()); return "postulante-form"; } @PostMapping(value = "/postulante",consumes = "application/json") public String guardarPostulante(@RequestBody Postulante postulante){ + System.out.println("hola"); + for(Estudio estudio: postulante.getEstudios()){ + if(institucionRepository.findByNombre(estudio.getInstitucion().getNombre())==null){ + institucionRepository.save(estudio.getInstitucion()); + } + } + System.out.println("hola"); post.save(postulante); return "redirect:/"; } diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/EstadoEstudio.java b/curriculumsearch/src/main/java/com/roshka/modelo/EstadoEstudio.java new file mode 100644 index 0000000..be72d86 --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/modelo/EstadoEstudio.java @@ -0,0 +1,18 @@ +package com.roshka.modelo; + +public enum EstadoEstudio { + CURSANDO("Cursando"), + FINALIZADO("Finalizado"), + SUSPENDIDO("Suspendido"), + TESIS("En Proceso de Tesis"); + + private final String name; + + EstadoEstudio(String name){ + this.name = name; + } + + public String getName(){ + return this.name; + } +} diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Estudio.java b/curriculumsearch/src/main/java/com/roshka/modelo/Estudio.java index 4f45b1b..ae50b28 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Estudio.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Estudio.java @@ -19,9 +19,8 @@ public class Estudio { @Column(name="id") private long id; - @ManyToOne(fetch = FetchType.EAGER) + @Column(name = "tipo_de_estudio") @NotNull(message = "Este campo no puede ser null") - @JsonBackReference private TipoDeEstudio tipoDeEstudio; @NotNull(message = "Este campo no puede estar vacio") @@ -29,15 +28,15 @@ public class Estudio { @JsonBackReference private Institucion institucion; - @Column(name = "estado") - @NotBlank(message = "Este campo no puede estar vacio") - private String estado; - //Carrera, Bachiller @Column(name="tema_de_estudio") @NotBlank(message = "Este campo no puede estar vacio") private String temaDeEstudio; + @Column(name = "estado") + @NotNull(message = "Este campo no puede estar vacio") + private EstadoEstudio estado; + @Column(name="fecha_desde") @NotNull(message = "Este campo no puede estar vacio") @Past(message = "Este campo no puede estar en el futuro") @@ -49,7 +48,7 @@ public class Estudio { @ManyToOne @JoinColumn - @JsonBackReference + @JsonBackReference(value = "estudio-postulante") private Postulante postulante; public Postulante getPostulante() { @@ -79,7 +78,7 @@ public class Estudio { this.institucion = institucion; } - public void setEstado(String estado) { + public void setEstado(EstadoEstudio estado) { this.estado = estado; } @@ -99,7 +98,7 @@ public class Estudio { return institucion; } - public String getEstado() { + public EstadoEstudio getEstado() { return estado; } diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java b/curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java index f8d93ce..579e321 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Experiencia.java @@ -48,12 +48,12 @@ public class Experiencia { @Column(name = "descripcion") private String descripcion; - @JsonBackReference + @JsonBackReference(value = "experiencia-postulante") @ManyToOne(optional = false) @JoinColumn private Postulante postulante; - @JsonManagedReference + @JsonManagedReference(value = "experienciareconocimiento-experiencia") @OneToMany(mappedBy = "experiencia",cascade = CascadeType.ALL) private List reconocimientos; diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/ExperienciaReconocimiento.java b/curriculumsearch/src/main/java/com/roshka/modelo/ExperienciaReconocimiento.java index 1cb47a8..41adebf 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/ExperienciaReconocimiento.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/ExperienciaReconocimiento.java @@ -14,7 +14,7 @@ public class ExperienciaReconocimiento { @ManyToOne(optional = false) @JoinColumn - @JsonBackReference + @JsonBackReference(value = "experienciareconocimiento-experiencia") private Experiencia experiencia; @Column(name="nombre") diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Institucion.java b/curriculumsearch/src/main/java/com/roshka/modelo/Institucion.java index 1acddf4..d1538c5 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Institucion.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Institucion.java @@ -10,6 +10,7 @@ import java.util.List; @Table(name = "institucion") public class Institucion { @Id + @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private long id; @@ -24,4 +25,36 @@ public class Institucion { @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "institucion", fetch = FetchType.LAZY) @JsonManagedReference private List estudioList; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + public String getSubNombre() { + return subNombre; + } + + public void setSubNombre(String subNombre) { + this.subNombre = subNombre; + } + + public List getEstudioList() { + return estudioList; + } + + public void setEstudioList(List estudioList) { + this.estudioList = estudioList; + } } diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java b/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java index 865ec2f..8968850 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java @@ -71,15 +71,15 @@ public class Postulante { @Column(name = "disponibilidad", length = 2) private Disponibilidad disponibilidad; - @JsonManagedReference + @JsonManagedReference(value = "postulantetecnologia-postulante") @OneToMany(mappedBy = "postulante",cascade = CascadeType.ALL) private List tecnologias; - @JsonManagedReference + @JsonManagedReference(value = "experiencia-postulante") @OneToMany(mappedBy = "postulante",cascade = CascadeType.ALL) private List experiencias = new ArrayList<>(); - @JsonManagedReference + @JsonManagedReference(value = "estudio-postulante") @OneToMany(mappedBy = "postulante",cascade = CascadeType.ALL) private List estudios; diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java b/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java index d1a730b..bf9948f 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java @@ -35,7 +35,7 @@ public class PostulanteTecnologia { @ManyToOne() @JoinColumn - @JsonBackReference + @JsonBackReference(value = "postulantetecnologia-postulante") private Postulante postulante; public long getId() { return id; diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/TipoDeEstudio.java b/curriculumsearch/src/main/java/com/roshka/modelo/TipoDeEstudio.java index 11cc78b..4e845eb 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/TipoDeEstudio.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/TipoDeEstudio.java @@ -1,25 +1,21 @@ package com.roshka.modelo; -import com.fasterxml.jackson.annotation.JsonManagedReference; -import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import java.util.List; -@Entity -@Table(name = "tipo_de_estudio") -public class TipoDeEstudio { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private long id; +public enum TipoDeEstudio { + TERCIARIO("Terciario"), + SECUNDARIO("Secundario"), + CURSO("Curso"), + OTRO("Otro"); - @Column(name = "nombre") - @NotBlank(message = "Este campo no puede estar vacio") - private String nombre; + private final String name; - @OneToMany(cascade = CascadeType.PERSIST, mappedBy = "tipoDeEstudio", fetch = FetchType.LAZY) - @JsonManagedReference - private List estudioList; + TipoDeEstudio(String name){ + this.name = name; + } + + public String getName(){ + return this.name; + } } diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/InstitucionRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/InstitucionRepository.java new file mode 100644 index 0000000..a44fdaf --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/InstitucionRepository.java @@ -0,0 +1,8 @@ +package com.roshka.repositorio; + +import com.roshka.modelo.Institucion; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface InstitucionRepository extends JpaRepository { + public Institucion findByNombre(String nombre); +} diff --git a/curriculumsearch/src/main/resources/static/main.js b/curriculumsearch/src/main/resources/static/main.js index 357ce62..25cf5c5 100644 --- a/curriculumsearch/src/main/resources/static/main.js +++ b/curriculumsearch/src/main/resources/static/main.js @@ -202,8 +202,8 @@ document.querySelector("#btn-new-tech").addEventListener('click',()=>{document.q function agregarFieldEstudio(){ //recoger del form - const pairs = {}; - const formest = document.querySelector("[name=estudio-form"); + let pairs = {}; + const formest = document.querySelector("[name=estudio-form]"); const formData = new FormData(formest); const estudioReconocimiento = [{},{},{}]; let pos_rec; @@ -217,6 +217,12 @@ function agregarFieldEstudio(){ } } + let nombre = pairs["institucion"] + delete pairs["institucion"] + console.log(pairs) + pairs["institucion"] = { } + pairs["institucion"].nombre = nombre + pairs["institucion"].subNombre = "" pairs["estudioReconocimiento"] = estudioReconocimiento.filter(rec => rec.nombre); estudios[cont_estudios] = pairs; formest.reset(); @@ -230,7 +236,7 @@ function agregarFieldEstudio(){ if(est==null) continue; content += `
  • - ${est.institucion} + ${est.institucion.nombre}
  • diff --git a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp index 1e95353..5f2874c 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp @@ -406,41 +406,43 @@