From 47d5b40d3746202ac62320d76bcb5dee5a38e5cf Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 9 Nov 2021 13:06:49 -0300 Subject: [PATCH] lista postulante con filtro --- curriculumsearch/src/main/java/com/roshka/DTO/PostulanteListaDTO.java | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java | 33 ++++++++++++++++++++++++++++++--- curriculumsearch/src/main/java/com/roshka/modelo/DisponibilidadConverter.java | 7 ++++++- curriculumsearch/src/main/java/com/roshka/modelo/Postulante.java | 6 +++--- curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java | 14 ++++++++++++++ curriculumsearch/src/main/java/com/roshka/utils/Helper.java | 10 ++++++++++ curriculumsearch/src/main/webapp/jsp/postulantes.jsp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++----------------------- 7 files changed, 185 insertions(+), 30 deletions(-) create mode 100644 curriculumsearch/src/main/java/com/roshka/DTO/PostulanteListaDTO.java diff --git a/curriculumsearch/src/main/java/com/roshka/DTO/PostulanteListaDTO.java b/curriculumsearch/src/main/java/com/roshka/DTO/PostulanteListaDTO.java new file mode 100644 index 0000000..4bd33ca --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/DTO/PostulanteListaDTO.java @@ -0,0 +1,71 @@ +package com.roshka.DTO; + +import java.util.List; + +import com.roshka.modelo.Disponibilidad; +import com.roshka.modelo.PostulanteTecnologia; + +public class PostulanteListaDTO { + private Long id; + private String nombre; + private String apellido; + private Disponibilidad disponibilidad; + private Integer nivelIngles; + private Long experienciaMeses; + private List tecnologias; + public PostulanteListaDTO(Long id, String nombre, String apellido, Disponibilidad disponibilidad, + Integer nivelIngles, Long experienciaMeses, List tecnologias) { + this.id = id; + this.nombre = nombre; + this.apellido = apellido; + this.disponibilidad = disponibilidad; + this.nivelIngles = nivelIngles; + this.experienciaMeses = experienciaMeses; + this.tecnologias = tecnologias; + } + 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 getApellido() { + return apellido; + } + public void setApellido(String apellido) { + this.apellido = apellido; + } + public Disponibilidad getDisponibilidad() { + return disponibilidad; + } + public void setDisponibilidad(Disponibilidad disponibilidad) { + this.disponibilidad = disponibilidad; + } + public Integer getNivelIngles() { + return nivelIngles; + } + public void setNivelIngles(Integer nivelIngles) { + this.nivelIngles = nivelIngles; + } + public Long getExperienciaMeses() { + return experienciaMeses; + } + public void setExperienciaMeses(Long experienciaMeses) { + this.experienciaMeses = experienciaMeses; + } + public List getTecnologias() { + return tecnologias; + } + public void setTecnologias(List tecnologias) { + this.tecnologias = tecnologias; + } + + + +} diff --git a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java index 1d0e158..a90d935 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java @@ -1,10 +1,12 @@ package com.roshka.controller; +import java.util.ArrayList; import java.util.List; import javax.validation.ConstraintViolationException; +import com.roshka.DTO.PostulanteListaDTO; import com.roshka.modelo.*; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -19,7 +21,10 @@ import com.roshka.repositorio.ExperienciaRepository; import com.roshka.repositorio.InstitucionRepository; import com.roshka.repositorio.PostulanteRepository; import com.roshka.repositorio.TecnologiaRepository; +import com.roshka.utils.Helper; +import org.hibernate.jpa.TypedParameterValue; +import org.hibernate.type.StringType; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -59,10 +64,32 @@ public class PostulanteController { @RequestMapping("/postulantes") public String postulantes(Model model, - @RequestParam(required = false,name = "tec")Long tecnologidaId) { + @RequestParam(required = false)Long tecId, + @RequestParam(required = false)String nombre, + @RequestParam(required = false)Disponibilidad dispo, + @RequestParam(required = false)Integer lvlEng, + @RequestParam(required = false)Integer lvlTec, + @RequestParam(required = false)Long instId, + @RequestParam(required = false)Long expInMonths + ) { model.addAttribute("tecnologias", tecRepo.findAll()); - if(tecnologidaId==null) model.addAttribute("postulantes", post.findAll()); - else model.addAttribute("postulantes", post.buscarPostulantesPorTecnologia(tecnologidaId)); + model.addAttribute("disponibilidades", Disponibilidad.values()); + model.addAttribute("institucionesEducativas", institucionRepository.findAll()); + List postulantes = post.postulantesMultiFiltro(nombre == null || nombre.trim().isEmpty() ? new TypedParameterValue(StringType.INSTANCE,null) : new TypedParameterValue(StringType.INSTANCE,"%"+nombre+"%"), dispo, lvlEng, lvlTec, tecId, instId); + List postulantesDTO = new ArrayList<>(); + + for (Postulante postulante : postulantes) { + long expTotal = 0; + //Sumamos el tiempo de experiencia total en meses de cada postulante + //expTotal = postulante.getExperiencias().stream().mapToLong(e -> Helper.getMonthsDifference(e.getFechaDesde(), e.getFechaHasta())).sum(); + for (Experiencia experiencia : postulante.getExperiencias()) { + expTotal += Helper.getMonthsDifference(experiencia.getFechaDesde(), experiencia.getFechaHasta()); + } + if(expInMonths != null && expInMonths > expTotal) continue; + postulantesDTO.add(new PostulanteListaDTO(postulante.getId(), postulante.getNombre(), postulante.getApellido(), postulante.getDisponibilidad(), postulante.getNivelIngles(), expTotal, postulante.getTecnologias())); + } + + model.addAttribute("postulantes", postulantesDTO); return "postulantes"; } diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/DisponibilidadConverter.java b/curriculumsearch/src/main/java/com/roshka/modelo/DisponibilidadConverter.java index 400c133..93b5f5f 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/DisponibilidadConverter.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/DisponibilidadConverter.java @@ -6,7 +6,7 @@ import javax.persistence.AttributeConverter; import javax.persistence.Converter; @Converter(autoApply = true) -public class DisponibilidadConverter implements AttributeConverter { +public class DisponibilidadConverter implements AttributeConverter, org.springframework.core.convert.converter.Converter { @Override public String convertToDatabaseColumn(Disponibilidad modalidad) { @@ -27,4 +27,9 @@ public class DisponibilidadConverter implements AttributeConverter { "join Tecnologia tec on pt.tecnologia.id=tec.id "+ "where tec.nombre=?1 and pt.nivel=?2") public List findByPostulanteTecnologiaM(String tecno,long idt); + + @Query(value = "select DISTINCT p " + + "from Postulante p join p.experiencias x " + + "join p.estudios e " + + "join p.tecnologias pt " + + "where (?1 is null or lower(p.nombre) LIKE lower(?1) or lower(p.apellido) LIKE lower(?1) ) " + + "and (p.disponibilidad = ?2 or ?2 is null) " + + "and (p.nivelIngles > ?3 or ?3 is null) "+ + "and (pt.nivel > ?4 or ?4 is null) "+ + "and (pt.tecnologia.id = ?5 or ?5 is null) "+ + " and (e.institucion.id = ?6 or ?6 is null ) ") + public List postulantesMultiFiltro(TypedParameterValue nombre, Disponibilidad disponibilidad, Integer nivelInges, Integer nivel, Long tecnoId, Long instId); } diff --git a/curriculumsearch/src/main/java/com/roshka/utils/Helper.java b/curriculumsearch/src/main/java/com/roshka/utils/Helper.java index 40f586f..c4b70b9 100644 --- a/curriculumsearch/src/main/java/com/roshka/utils/Helper.java +++ b/curriculumsearch/src/main/java/com/roshka/utils/Helper.java @@ -2,6 +2,9 @@ package com.roshka.utils; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.YearMonth; +import java.time.ZoneOffset; +import java.time.temporal.ChronoUnit; import java.util.Date; public class Helper { @@ -21,4 +24,11 @@ public class Helper { return null; } } + + public static final long getMonthsDifference(Date date1, Date date2) { + YearMonth m1 = YearMonth.from(date1.toInstant().atZone(ZoneOffset.UTC)); + YearMonth m2 = YearMonth.from(date2.toInstant().atZone(ZoneOffset.UTC)); + + return m1.until(m2, ChronoUnit.MONTHS) + 1; + } } diff --git a/curriculumsearch/src/main/webapp/jsp/postulantes.jsp b/curriculumsearch/src/main/webapp/jsp/postulantes.jsp index d452dc2..00c21fc 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulantes.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulantes.jsp @@ -13,28 +13,56 @@
- - +
+ + + +
+ + + + + + +
+ + + + + + +
@@ -54,7 +82,7 @@ - +
${postulante.nombre} ${postulante.apellido} ${postulante.disponibilidad.getDescripcion()} ${postulante.nivelIngles}0${postulante.experienciaMeses} ${detalle_tecnologia.getTecnologia().getNombre()}${not staTec.last ? "," : ""} -- libgit2 0.26.0