From d4e647f7c9d8bd1eee7e4b4a2c735b27f6b3fa10 Mon Sep 17 00:00:00 2001 From: willgonzz Date: Wed, 10 Nov 2021 09:25:15 -0300 Subject: [PATCH] Postulantes convocatoria --- curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java | 23 ++++++++++++++++++++--- curriculumsearch/src/main/java/com/roshka/modelo/Cargo.java | 3 +++ curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java | 3 +++ curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java | 4 +++- curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java | 2 +- curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java | 3 ++- curriculumsearch/src/main/resources/static/main.js | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ curriculumsearch/src/main/webapp/jsp/postulante-form.jsp | 40 ++++++++++++++++++++++++++++++++++++++-- 8 files changed, 143 insertions(+), 8 deletions(-) diff --git a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java index 1d0e158..8ae81e0 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java @@ -1,6 +1,7 @@ package com.roshka.controller; +import java.util.Date; import java.util.List; import javax.validation.ConstraintViolationException; @@ -13,13 +14,18 @@ import com.roshka.modelo.EstadoCivil; import com.roshka.modelo.Nacionalidad; import com.roshka.modelo.Postulante; import com.roshka.modelo.TipoExperiencia; +import com.roshka.repositorio.CargoRepository; import com.roshka.repositorio.CiudadRepository; +import com.roshka.repositorio.ConvocatoriaRepository; import com.roshka.repositorio.DepartamentoRepository; import com.roshka.repositorio.ExperienciaRepository; import com.roshka.repositorio.InstitucionRepository; import com.roshka.repositorio.PostulanteRepository; import com.roshka.repositorio.TecnologiaRepository; +import org.hibernate.jpa.TypedParameterValue; +import org.hibernate.type.IntegerType; +import org.hibernate.type.LongType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -38,15 +44,19 @@ public class PostulanteController { InstitucionRepository institucionRepository; DepartamentoRepository depRepo; CiudadRepository ciuRepo; + ConvocatoriaRepository cargoRepo; + CargoRepository carRepo; @Autowired - public PostulanteController(PostulanteRepository post, TecnologiaRepository tecRepo, ExperienciaRepository expRepo, InstitucionRepository institucionRepository, DepartamentoRepository depRepo, CiudadRepository ciuRepo) { + public PostulanteController(PostulanteRepository post, TecnologiaRepository tecRepo, ExperienciaRepository expRepo, InstitucionRepository institucionRepository, DepartamentoRepository depRepo, CiudadRepository ciuRepo,ConvocatoriaRepository cargoRepo, CargoRepository carRepo) { this.post = post; this.tecRepo = tecRepo; this.expRepo = expRepo; this.institucionRepository = institucionRepository; this.depRepo = depRepo; this.ciuRepo = ciuRepo; + this.cargoRepo =cargoRepo; + this.carRepo=carRepo; } @@ -75,11 +85,12 @@ public class PostulanteController { model.addAttribute("estadosCiviles", EstadoCivil.values()); model.addAttribute("nacionalidades", Nacionalidad.values()); model.addAttribute("tiposExperencia", TipoExperiencia.values()); + model.addAttribute("CargosDisponibles", cargoRepo.f1ndByCargoAndEstado(new TypedParameterValue(LongType.INSTANCE, null), new Date(), new TypedParameterValue(IntegerType.INSTANCE, 1))); try { model.addAttribute("ciudades", new ObjectMapper().writeValueAsString(ciuRepo.findAll())); - } catch (JsonProcessingException e) { + } catch (JsonProcessingException er) { // TODO Auto-generated catch block - e.printStackTrace(); + er.printStackTrace(); } model.addAttribute("departamentos", depRepo.findAll()); @@ -94,6 +105,12 @@ public class PostulanteController { ).forEach( tec -> tec.setTecnologia(tecRepo.getById(tec.getTecnologia().getId())) ); + + + for (int i = 0; i < postulante.getPostulaciones().size(); i++) { + postulante.getPostulaciones().set(i, cargoRepo.getById(postulante.getPostulaciones().get(i).getId())); + } + for(Estudio estudio: postulante.getEstudios()){ Institucion institucion = institucionRepository.findByNombre(estudio.getInstitucion().getNombre()); if(institucion==null){ diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Cargo.java b/curriculumsearch/src/main/java/com/roshka/modelo/Cargo.java index 0179d06..0d6586e 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Cargo.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Cargo.java @@ -47,4 +47,7 @@ public class Cargo { public void setConvocatorias(List convocatorias) { this.convocatorias = convocatorias; } + public static Object values() { + return null; + } } diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java b/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java index 5e7ad21..9e0919b 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java @@ -15,10 +15,13 @@ import javax.persistence.Table; import javax.persistence.Transient; import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.roshka.utils.Helper; @Entity @Table(name = "convocatoria_cargo") +@JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property="@UUID") public class ConvocatoriaCargo { @Id @GeneratedValue(strategy = GenerationType.AUTO) diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java b/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java index 4852fd2..fb1c30c 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java @@ -3,8 +3,10 @@ package com.roshka.modelo; import javax.persistence.*; import javax.validation.constraints.*; +import com.fasterxml.jackson.annotation.JsonIdentityInfo; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonManagedReference; +import com.fasterxml.jackson.annotation.ObjectIdGenerators; import com.roshka.utils.Helper; import java.util.ArrayList; @@ -14,6 +16,7 @@ import java.util.List; @Entity @Table(name="postulante") +@JsonIdentityInfo(generator = ObjectIdGenerators.UUIDGenerator.class, property="@UUID") public class Postulante { @Id @GeneratedValue(strategy = GenerationType.AUTO) @@ -103,7 +106,6 @@ public class Postulante { joinColumns = @JoinColumn(name="postulante_id", referencedColumnName="id"), inverseJoinColumns= @JoinColumn(name="convocatoria_cargo_id", referencedColumnName="id") ) - @JsonIgnore private List postulaciones; diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java b/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java index dca587e..97ca513 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/PostulanteTecnologia.java @@ -34,7 +34,7 @@ public class PostulanteTecnologia { private Tecnologia tecnologia; @ManyToOne() - @JoinColumn + @JoinColumn @JsonBackReference(value = "postulantetecnologia-postulante") private Postulante postulante; diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java index e30b295..25926c9 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java @@ -11,7 +11,8 @@ import org.springframework.data.jpa.repository.Query; public interface ConvocatoriaRepository extends JpaRepository { public List findByCargoId(Long cargoId); - + //@Query(value="selec x from ConvocatoriaCargo x where (x.fechaFinal > ?1)",nativeQuery = true) + //public List findConvocatoriaCargoByCargo(Date fechaFinal); @Query("select c from ConvocatoriaCargo c where ( ?1 is null and ?3 is null) or ( ( ( (c.fechaFin > ?2 and ?3 = 1) or (c.fechaFin < ?2 and ?3 = 0)) or ?3 is null ) and (c.cargoId = ?1 or ?1 is null) )") public List f1ndByCargoAndEstado(TypedParameterValue cargoId, Date fecha, TypedParameterValue isOpen); } diff --git a/curriculumsearch/src/main/resources/static/main.js b/curriculumsearch/src/main/resources/static/main.js index 9080b8d..3e86f06 100644 --- a/curriculumsearch/src/main/resources/static/main.js +++ b/curriculumsearch/src/main/resources/static/main.js @@ -1,9 +1,11 @@ var cont_experiencia = 0; let cont_estudios = 0; let cont_tecnologia = 0; +let cont_cargo = 0; const experiencias = []; const estudios = []; const tecnologias = []; +const postulaciones = []; const formValidator = function () { 'use strict' @@ -190,6 +192,7 @@ function serializeJSON (form) { pairs["experiencias"] = experiencias.filter(exp => exp)//eliminacion de nulos pairs["estudios"] = estudios.filter(est => est)//eliminacion de nulos pairs["tecnologias"] = tecnologias.filter(tec => tec)//eliminacion de nulos + pairs["postulaciones"] = postulaciones.filter(car => car)//eliminacion de nulos // Return the JSON string return JSON.stringify(pairs, null, 2); @@ -319,7 +322,77 @@ function eliminarEstudio(event) { //eliminar en html event.target.parentElement.remove() } +/*--------------------------------------------------------------------*/ +function agregarFieldCargo(){ + //recoger del form + const pairs = {}; + const formcar = document.querySelector("[name=cargo-form]"); + const formData = new FormData(formcar); + + //Validacion + let returnFlag = false; + + let requiredValues = ["nombre"] + + formData.forEach((value, key)=>{ + if(requiredValues.includes(key) + && value==="" && returnFlag == false){ + console.log(key, value) + returnFlag = true; + } + }); + + if(returnFlag===true){ + let message = "Rellene " + for(let i=0;i option[value="'+pairs["cargo-id"]+'"]').innerHTML} + console.log(postulaciones) + formcar.reset(); + //imprimir lista actualizada + const div = document.querySelector("#cargos") + const div1 = document.createElement('div'); + console.log(postulaciones[0]) + + let content1='
    ' + for (let index = 0; index < postulaciones.length; index++) { + const car = postulaciones[index]; + if(car==null) continue; + content1 += ` +
  • + ${document.querySelector('[name=cargo-id] > option[value="'+pairs["cargo-id"]+'"]').innerHTML} + +
  • + + ` + } + content1 += "
" + div1.innerHTML = content1 + div.innerHTML = ''; + div.appendChild(div1); + cont_cargo++; +} + +/*---------------------------------------------------------------------------------------------------*/ +function eliminarCargoPostulante(event) { + //eliminar del array + postulaciones[event.target.parentElement.id.split("-")[1]]=null + //eliminar en html + event.target.parentElement.remove() +} +/*--------------------------------------------------------------------*/ //evento para cambio de ciudad segun departamento diff --git a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp index ec59523..db1caea 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp @@ -260,7 +260,13 @@ - +
+
 Cargo al que postulas

+
+ +
+
+
 Agregar Experiencia

@@ -296,7 +302,37 @@ - + + +