diff --git a/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java b/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java index 6244e57..342dfaf 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java @@ -1,64 +1,53 @@ package com.roshka.controller; + import com.roshka.modelo.Cargo; -import com.roshka.modelo.ConvocatoriaCargo; import com.roshka.repositorio.CargoRepository; -import com.roshka.repositorio.ConvocatoriaRepository; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @Controller public class CargoController { CargoRepository cargoRepo; - ConvocatoriaRepository convoRepo; @Autowired - public CargoController(CargoRepository cargoRepo, ConvocatoriaRepository convoRepo) { + public CargoController(CargoRepository cargoRepo) { this.cargoRepo = cargoRepo; - this.convoRepo = convoRepo; } @RequestMapping("/cargos") - public String menuCargos(Model model,@RequestParam(required = false) Long cargoId) { - - model.addAttribute("cargos", cargoRepo.findAll()); - model.addAttribute("convocatorias",cargoId==null? convoRepo.findAll() : convoRepo.findByCargoId(cargoId)); - return "cargo"; + public String menuCargos(Model model, + @RequestParam(required = false) String nombre + ) { + if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("cargos", cargoRepo.findAll()); + else model.addAttribute("cargos", cargoRepo.findByNombreContainingIgnoreCase(nombre)); + return "cargos"; } - @RequestMapping("/cargo") - public String formCargo(Model model) { - model.addAttribute("cargo", new Cargo()); + @RequestMapping(path = {"/cargo","/cargo/{id}"}, method = RequestMethod.GET) + public String formCargo(Model model,@PathVariable(required = false) Long id) { + + if(id == null) model.addAttribute("cargo", new Cargo()); + else model.addAttribute("cargo", cargoRepo.getById(id)); return "cargo-form"; } - @PostMapping("/cargo") - public String guardarCargo(@ModelAttribute Cargo cargo, BindingResult result) { + @PostMapping(path = {"/cargo","/cargo/{id}"}) + public String guardarCargo(@ModelAttribute Cargo cargo, BindingResult result, @PathVariable(required = false) Long id) { if(result.hasErrors()); + if(id != null ) cargo.setId(id); cargoRepo.save(cargo); System.out.println(cargo.getNombre()); return "redirect:/cargos"; } - @RequestMapping("/convocatoria") - public String formConvocatoria(Model model) { - model.addAttribute("cargos", cargoRepo.findAll()); - model.addAttribute("convocatoria", new ConvocatoriaCargo()); - return "convocatoria-form"; - } - @PostMapping("/convocatoria") - public String guardarConvocatoria(@ModelAttribute ConvocatoriaCargo convocatoria, BindingResult result) { - if(result.hasErrors()); - convoRepo.save(convocatoria); - System.out.println(convocatoria.getFechaInicio()); - return "redirect:/cargos"; - } } diff --git a/curriculumsearch/src/main/java/com/roshka/controller/ConvocatoriaController.java b/curriculumsearch/src/main/java/com/roshka/controller/ConvocatoriaController.java new file mode 100644 index 0000000..4556637 --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/controller/ConvocatoriaController.java @@ -0,0 +1,72 @@ +package com.roshka.controller; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import com.roshka.modelo.ConvocatoriaCargo; +import com.roshka.repositorio.CargoRepository; +import com.roshka.repositorio.ConvocatoriaRepository; + +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.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +public class ConvocatoriaController { + + CargoRepository cargoRepo; + ConvocatoriaRepository convoRepo; + + @Autowired + public ConvocatoriaController(CargoRepository cargoRepo, ConvocatoriaRepository convoRepo) { + this.cargoRepo = cargoRepo; + this.convoRepo = convoRepo; + } + + @RequestMapping("/convocatorias") + public String menuConvocatorias(Model model, + @RequestParam(required = false) Long cargoId, + @RequestParam(required = false) Integer isOpen//1: true, 0: false + ) { + + model.addAttribute("cargos", cargoRepo.findAll()); + + model.addAttribute("convocatorias", convoRepo.f1ndByCargoAndEstado(new TypedParameterValue(LongType.INSTANCE, cargoId), new Date(), new TypedParameterValue(IntegerType.INSTANCE, isOpen))); + //model.addAttribute("convocatorias",cargoId==null? convoRepo.findAll() : convoRepo.findByCargoId(cargoId)); + return "convocatorias"; + } + + + @RequestMapping(path = {"/convocatoria","/convocatoria/{id}"}) + public String formConvocatoria(Model model,@PathVariable(required = false) Long id) { + model.addAttribute("cargos", cargoRepo.findAll()); + if(id == null) model.addAttribute("convocatoria", new ConvocatoriaCargo()); + else { + ConvocatoriaCargo cc = convoRepo.getById(id); + cc.setFechaFinS(new SimpleDateFormat("yyyy-MM-dd").format((cc.getFechaFin()))); + cc.setFechaInicioS(new SimpleDateFormat("yyyy-MM-dd").format((cc.getFechaInicio()))); + + model.addAttribute("convocatoria", cc); + } + + return "convocatoria-form"; + } + + @PostMapping(path = {"/convocatoria","/convocatoria/{id}"}) + public String guardarConvocatoria(@ModelAttribute ConvocatoriaCargo convocatoria, BindingResult result, @PathVariable(required = false) Long id) { + if(result.hasErrors()); + if(id != null) convocatoria.setId(id); + convoRepo.save(convocatoria); + System.out.println(convocatoria.getFechaInicio()); + return "redirect:/convocatorias"; + } +} diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Cargo.java b/curriculumsearch/src/main/java/com/roshka/modelo/Cargo.java index f3dddf6..0179d06 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Cargo.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Cargo.java @@ -18,7 +18,7 @@ import com.fasterxml.jackson.annotation.JsonManagedReference; public class Cargo { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private long id; + private Long id; @NotBlank @Column(name = "nombre") @@ -28,13 +28,13 @@ public class Cargo { @JsonManagedReference private List convocatorias; - public long getId() { + public Long getId() { return id; } public String getNombre() { return nombre; } - public void setId(long id) { + public void setId(Long id) { this.id = id; } public void setNombre(String nombre) { diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java b/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java index 7a424e3..5e7ad21 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java @@ -22,7 +22,7 @@ import com.roshka.utils.Helper; public class ConvocatoriaCargo { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private long id; + private Long id; @ManyToOne() @JoinColumn(name = "cargo_id",insertable = false, updatable = false) @@ -41,18 +41,18 @@ public class ConvocatoriaCargo { @Column(name = "cupos") private int cupos; - //para serializar en el form como string + //para deserializar desde el form como string @Transient private String fechaFinS; - //para serializar en el form como string + //para deserializar desde el form como string @Transient private String fechaInicioS; @ManyToMany(mappedBy = "postulaciones") private List postulantes; - public long getId() { + public Long getId() { return id; } public Cargo getCargo() { @@ -67,7 +67,7 @@ public class ConvocatoriaCargo { public Date getFechaInicio() { return fechaInicio; } - public void setId(long id) { + public void setId(Long id) { this.id = id; } public void setCargo(Cargo cargo) { diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java index 3e8c119..556bc1c 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java @@ -1,9 +1,11 @@ package com.roshka.repositorio; +import java.util.List; + import com.roshka.modelo.Cargo; import org.springframework.data.jpa.repository.JpaRepository; public interface CargoRepository extends JpaRepository{ - + public List findByNombreContainingIgnoreCase(String nombre); } diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java index 3892883..e30b295 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java @@ -1,11 +1,17 @@ package com.roshka.repositorio; +import java.util.Date; import java.util.List; import com.roshka.modelo.ConvocatoriaCargo; +import org.hibernate.jpa.TypedParameterValue; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; public interface ConvocatoriaRepository extends JpaRepository { public List findByCargoId(Long cargoId); + + @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/webapp/jsp/cargo-form.jsp b/curriculumsearch/src/main/webapp/jsp/cargo-form.jsp index f5b81bd..f838bc9 100644 --- a/curriculumsearch/src/main/webapp/jsp/cargo-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/cargo-form.jsp @@ -13,7 +13,7 @@
- +
Nombre del cargo diff --git a/curriculumsearch/src/main/webapp/jsp/cargos.jsp b/curriculumsearch/src/main/webapp/jsp/cargos.jsp new file mode 100644 index 0000000..5c6f2e9 --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/cargos.jsp @@ -0,0 +1,49 @@ +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + + + + + + + Cargo + + + + +
+
+ + + +
+ Agregar Nuevo Cargo +
+
+ + + + + + + + + + + + + + + + + + + + + +
#Cargo
${sta.index+1}${cargo.getNombre()}Ver ConvocatoriasEditar cargo
+
+ + + \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/convocatoria-form.jsp b/curriculumsearch/src/main/webapp/jsp/convocatoria-form.jsp index 551208c..c5062a8 100644 --- a/curriculumsearch/src/main/webapp/jsp/convocatoria-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/convocatoria-form.jsp @@ -13,7 +13,7 @@
- +
Fecha inicial @@ -37,9 +37,6 @@
- - -
\ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/cargo.jsp b/curriculumsearch/src/main/webapp/jsp/convocatorias.jsp similarity index 79% rename from curriculumsearch/src/main/webapp/jsp/cargo.jsp rename to curriculumsearch/src/main/webapp/jsp/convocatorias.jsp index 50d293d..47703ed 100644 --- a/curriculumsearch/src/main/webapp/jsp/cargo.jsp +++ b/curriculumsearch/src/main/webapp/jsp/convocatorias.jsp @@ -13,14 +13,23 @@
- Cargos: - - Agregar Nuevo Cargo +
+ + + Estado: + +
+ +
+ +
+ +
Agregar Nueva Convocatoria @@ -28,6 +37,7 @@ # + Cargo Fecha Desde Fecha Hasta Vacantes @@ -38,10 +48,12 @@ ${sta.index+1} + ${convocatoria.getCargo().getNombre()} ${convocatoria.getFechaInicio().toString().split(" ")[0]} ${convocatoria.getFechaFin().toString().split(" ")[0]} ${convocatoria.getCupos()} Ver Postulantes + Editar @@ -49,13 +61,8 @@ +
- + \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/index.jsp b/curriculumsearch/src/main/webapp/jsp/index.jsp index 2f174d6..5a9a2a5 100644 --- a/curriculumsearch/src/main/webapp/jsp/index.jsp +++ b/curriculumsearch/src/main/webapp/jsp/index.jsp @@ -8,5 +8,9 @@ Form postulante + Lista de postulantes + Tecnologias + Lista de convocatorias + Lista de cargos \ No newline at end of file