diff --git a/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java b/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java new file mode 100644 index 0000000..342dfaf --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/controller/CargoController.java @@ -0,0 +1,53 @@ +package com.roshka.controller; + + +import com.roshka.modelo.Cargo; +import com.roshka.repositorio.CargoRepository; +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; + + @Autowired + public CargoController(CargoRepository cargoRepo) { + this.cargoRepo = cargoRepo; + } + + @RequestMapping("/cargos") + 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(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(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"; + } + +} 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 3f35e7e..5e7ad21 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/ConvocatoriaCargo.java @@ -12,6 +12,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.Table; +import javax.persistence.Transient; import com.fasterxml.jackson.annotation.JsonBackReference; import com.roshka.utils.Helper; @@ -21,13 +22,16 @@ import com.roshka.utils.Helper; public class ConvocatoriaCargo { @Id @GeneratedValue(strategy = GenerationType.AUTO) - private long id; + private Long id; @ManyToOne() - @JoinColumn + @JoinColumn(name = "cargo_id",insertable = false, updatable = false) @JsonBackReference private Cargo cargo; + @Column(name = "cargo_id") + private Long cargoId; + @Column(name = "fecha_inicio") private Date fechaInicio; @@ -37,10 +41,18 @@ public class ConvocatoriaCargo { @Column(name = "cupos") private int cupos; + //para deserializar desde el form como string + @Transient + private String fechaFinS; + + //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() { @@ -55,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) { @@ -82,5 +94,25 @@ public class ConvocatoriaCargo { public void setPostulantes(List postulantes) { this.postulantes = postulantes; } + public Long getCargoId() { + return cargoId; + } + public void setCargoId(Long cargoId) { + this.cargoId = cargoId; + } + public String getFechaFinS() { + return fechaFinS; + } + public String getFechaInicioS() { + return fechaInicioS; + } + public void setFechaFinS(String fechaFinS) { + this.fechaFinS = fechaFinS; + setFechaFin(fechaFinS); + } + public void setFechaInicioS(String fechaInicioS) { + this.fechaInicioS = fechaInicioS; + setFechaInicio(fechaInicioS); + } } diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java new file mode 100644 index 0000000..556bc1c --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/CargoRepository.java @@ -0,0 +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 new file mode 100644 index 0000000..e30b295 --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/ConvocatoriaRepository.java @@ -0,0 +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.jsp b/curriculumsearch/src/main/webapp/jsp/cargo-form.jsp similarity index 50% rename from curriculumsearch/src/main/webapp/jsp/cargo.jsp rename to curriculumsearch/src/main/webapp/jsp/cargo-form.jsp index f0fb286..f838bc9 100644 --- a/curriculumsearch/src/main/webapp/jsp/cargo.jsp +++ b/curriculumsearch/src/main/webapp/jsp/cargo-form.jsp @@ -8,14 +8,21 @@ Cargo + + -

Hola

- - - - ${i.getPostulante().getNombre()} - -
-
+
+ +
+ Nombre del cargo + +
+
+ +
+ +
+
\ No newline at end of file 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 new file mode 100644 index 0000000..c5062a8 --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/convocatoria-form.jsp @@ -0,0 +1,42 @@ +<%@ 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 + + + + +
+ +
+ Fecha inicial + + +
+
+ Fecha Fin + +
+
+ Cupos: + +
+
+ Cargo + + + ${cargo.nombre} + + +
+ +
+
+ + \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/convocatorias.jsp b/curriculumsearch/src/main/webapp/jsp/convocatorias.jsp new file mode 100644 index 0000000..47703ed --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/convocatorias.jsp @@ -0,0 +1,68 @@ +<%@ 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 + + + + +
+
+ + + Estado: + +
+ +
+ +
+ +
+
+
+ Agregar Nueva Convocatoria + + + + + + + + + + + + + + + + + + + + + + + + + + + +
#CargoFecha DesdeFecha HastaVacantes
${sta.index+1}${convocatoria.getCargo().getNombre()}${convocatoria.getFechaInicio().toString().split(" ")[0]}${convocatoria.getFechaFin().toString().split(" ")[0]}${convocatoria.getCupos()}Ver PostulantesEditar
+ +
+ + + \ 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