From d7680870ce3532981bffaf64671e97bf506d86a2 Mon Sep 17 00:00:00 2001 From: Sofía Benítez Date: Wed, 22 Mar 2023 16:02:42 -0300 Subject: [PATCH] Primeros cambios para feriados --- .idea/.gitignore | 8 ++++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/th-app-java.iml | 9 +++++++++ .idea/vcs.xml | 6 ++++++ curriculumsearch/src/main/java/com/roshka/controller/FeriadoController.java | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ curriculumsearch/src/main/java/com/roshka/modelo/Feriado.java | 25 +++++++++++++++++++++++++ curriculumsearch/src/main/java/com/roshka/repositorio/FeriadoRepository.java | 24 ++++++++++++++++++++++++ curriculumsearch/src/main/java/com/roshka/service/Scheduler.java | 11 ++++++++++- curriculumsearch/src/main/webapp/jsp/birthday-form.jsp | 2 +- curriculumsearch/src/main/webapp/jsp/feriado-form.jsp | 42 ++++++++++++++++++++++++++++++++++++++++++ curriculumsearch/src/main/webapp/jsp/feriados.jsp | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ curriculumsearch/src/main/webapp/jsp/layouts/base.jsp | 11 ++++++++++- 13 files changed, 317 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/th-app-java.iml create mode 100644 .idea/vcs.xml create mode 100644 curriculumsearch/src/main/java/com/roshka/controller/FeriadoController.java create mode 100644 curriculumsearch/src/main/java/com/roshka/modelo/Feriado.java create mode 100644 curriculumsearch/src/main/java/com/roshka/repositorio/FeriadoRepository.java create mode 100644 curriculumsearch/src/main/webapp/jsp/feriado-form.jsp create mode 100644 curriculumsearch/src/main/webapp/jsp/feriados.jsp diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e7a3690 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..2f9bc10 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/th-app-java.iml b/.idea/th-app-java.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/th-app-java.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/curriculumsearch/src/main/java/com/roshka/controller/FeriadoController.java b/curriculumsearch/src/main/java/com/roshka/controller/FeriadoController.java new file mode 100644 index 0000000..dd2d965 --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/controller/FeriadoController.java @@ -0,0 +1,91 @@ +package com.roshka.controller; + +import com.roshka.modelo.Birthday; +import com.roshka.modelo.Feriado; +import com.roshka.repositorio.BirthdayRepository; +import com.roshka.repositorio.FeriadoRepository; +import org.apache.commons.codec.digest.DigestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +@Controller +@RequestMapping("/feriados") +public class FeriadoController { + + FeriadoRepository feriadoRepository; + + + @Autowired + public FeriadoController(FeriadoRepository feriadoRepository){ + this.feriadoRepository = feriadoRepository; + } + + @GetMapping(path = {"/agregar","/modificar/{id}"}) + public String addFeriadoView(Model model, @PathVariable(required = false) Long id) { + + if(id == null) model.addAttribute("feriado", new Feriado()); + else model.addAttribute("feriado", feriadoRepository.getById(id)); + return "feriado-form"; + } + + @RequestMapping() + public String menuFeriados(Model model, @RequestParam(required = false) String feriado, @RequestParam(defaultValue = "0")Integer nroPagina) { + final Integer CANTIDAD_POR_PAGINA = 10; + Pageable page = PageRequest.of(nroPagina,CANTIDAD_POR_PAGINA,Sort.by("id")); + + if(feriado == null || feriado.trim().isEmpty()) { + Page feriadoPag=feriadoRepository.findAllFeriado(page); + model.addAttribute("feriados", feriadoPag.getContent()); + model.addAttribute("pages", feriadoPag.getTotalPages()); + } + else { + Page feriadoPag=feriadoRepository.findByMotivoFeriadoContainingIgnoreCase(nombre.trim(),page); + model.addAttribute("pages", feriadoPag.getTotalPages()); + model.addAttribute("feriados", feriadoPag.getContent()); + } + return "feriados"; + } + + @PostMapping(path = {"/agregar","/modificar/{id}"}) + public String addFeriado(@RequestPart(name = "file") MultipartFile file, + @RequestPart(name = "motivoFeriado") String motivoFeriado, + @RequestPart(name = "fecha") String fecha, + @PathVariable(required = false) Long id, + Model model) { + if((id==null && feriadoRepository.existsByMotivoFeriadoIgnoreCase(motivoFeriado))){ + model.addAttribute("mismoMotivo", true); + return "feriado-form"; + } + Feriado feriado = new Feriado(); + if (id != null) { + feriado = feriadoRepository.getById(id); + } + feriado.setMotivoFeriado(motivoFeriado); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + try { + Date date = formatter.parse(fecha); + feriado.setFecha(date); + } catch (ParseException e) { + throw new RuntimeException(e); + } + + if(id != null ) feriado.setId(id); + feriadoRepository.save(feriado); + return "redirect:/feriados"; + } +} \ No newline at end of file diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Feriado.java b/curriculumsearch/src/main/java/com/roshka/modelo/Feriado.java new file mode 100644 index 0000000..1cc8c0c --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Feriado.java @@ -0,0 +1,25 @@ +package com.roshka.modelo; + +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import javax.validation.constraints.NotBlank; +import java.util.Date; + + +@Entity @Data +@Table(name="feriados") +public class Feriado { + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + @Column(name="id") + private Long id; + @Column(name="fecha") + @Temporal(TemporalType.DATE) + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date fecha; + @Column(name="motivoFeriado") + @NotBlank(message = "Este campo no puede estar vacio") + private String motivoFeriado; +} diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/FeriadoRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/FeriadoRepository.java new file mode 100644 index 0000000..e41c132 --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/FeriadoRepository.java @@ -0,0 +1,24 @@ +package com.roshka.repositorio; + +import com.roshka.modelo.Birthday; +import com.roshka.modelo.Feriado; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.Date; +import java.util.List; + +public interface FeriadoRepository extends JpaRepository { + + List findAllByFecha(Date publicationDate); + + public Page findByMotivoFeriadoContainingIgnoreCase(String nombre, Pageable pageable); + + public boolean existsByMotivoFeriadoIgnoreCase(String nombre); + + + @Query(value = "SELECT * FROM feriados", nativeQuery = true) + public Page findAllFeriado(Pageable pageable); +} diff --git a/curriculumsearch/src/main/java/com/roshka/service/Scheduler.java b/curriculumsearch/src/main/java/com/roshka/service/Scheduler.java index 02ae259..a87fb11 100644 --- a/curriculumsearch/src/main/java/com/roshka/service/Scheduler.java +++ b/curriculumsearch/src/main/java/com/roshka/service/Scheduler.java @@ -2,8 +2,10 @@ package com.roshka.service; import com.roshka.modelo.Beneficio; import com.roshka.modelo.Birthday; +import com.roshka.modelo.Feriado; import com.roshka.repositorio.BeneficioRepository; import com.roshka.repositorio.BirthdayRepository; +import com.roshka.repositorio.FeriadoRepository; import org.apache.hc.client5.http.classic.methods.HttpPost; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; @@ -84,7 +86,14 @@ public class Scheduler { } } - @Scheduled(cron = "0 0 15 * * FRI") + @Scheduled(cron = "0 0 8 * * MON-FRI") +// @Scheduled(cron = "0 * * * * *") + public void feriados(){ + + } + + + @Scheduled(cron = "0 0 1 * * FRI") // @Scheduled(cron = "0 * * * * *") public void beneficios() { String url = "https://hooks.slack.com/services/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"; diff --git a/curriculumsearch/src/main/webapp/jsp/birthday-form.jsp b/curriculumsearch/src/main/webapp/jsp/birthday-form.jsp index beb5f43..9bc3481 100644 --- a/curriculumsearch/src/main/webapp/jsp/birthday-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/birthday-form.jsp @@ -7,7 +7,7 @@
-
Cumpleaño
+
Cumpleaños
+<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<%@ taglib uri="http://kwonnam.pe.kr/jsp/template-inheritance" prefix="layout"%> + + + +
+
+
Feriados
+
+ +
+ + +
+ Este Feriado ya existe +
+ + +
+ +
+
+ + +
+
\ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/feriados.jsp b/curriculumsearch/src/main/webapp/jsp/feriados.jsp new file mode 100644 index 0000000..ffc5efd --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/feriados.jsp @@ -0,0 +1,79 @@ +<%@ 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" %> +<%@ taglib uri="http://kwonnam.pe.kr/jsp/template-inheritance" prefix="layout"%> + + + +

Lista de Feriados

+ +
+
+
+
+ + +
+
+ + +
+ +
+
+ +
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + +
#Motivo del FeriadoFecha
${sta.index+1}${feriado.getNombreCompleto()}${feriado.getFecha()}
+
+
+ +
+
+ + +
+ + + + diff --git a/curriculumsearch/src/main/webapp/jsp/layouts/base.jsp b/curriculumsearch/src/main/webapp/jsp/layouts/base.jsp index 8bc1339..eea8dba 100644 --- a/curriculumsearch/src/main/webapp/jsp/layouts/base.jsp +++ b/curriculumsearch/src/main/webapp/jsp/layouts/base.jsp @@ -52,6 +52,7 @@
  • Listar
  • + + -- libgit2 0.26.0