diff --git a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java index d63bba8..bbb6c96 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java @@ -23,7 +23,7 @@ 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.IntegerType; @@ -95,30 +95,7 @@ public class PostulanteController { return "postulante-form"; } - private DBFile createFile(MultipartFile file) { - // Normalize file name - String fileName = StringUtils.cleanPath(file.getOriginalFilename()); - - try { - // Check if the file's name contains invalid characters - if(fileName.contains("..")) { - throw new Exception("Sorry! Filename contains invalid path sequence " + fileName); - } - if(file.getSize()==0) throw new Exception("Sorry! File cant be void");; - - DBFile dbFile = new DBFile(fileName, file.getContentType(), file.getBytes()); - - return dbFile; - } catch (IOException ex) { - ex.printStackTrace(); - return null; - } - catch(Exception ex){ - ex.printStackTrace(); - return null; - } - } - + @PostMapping(value = "/work-with-us",consumes = "multipart/form-data") public RedirectView guardarPostulante(@RequestPart(name = "file",required = false) MultipartFile file,@RequestPart("postulante") Postulante postulante, RedirectAttributes redirectAttributes){ //Codigo encargado de modificar postulacion si se envia mismo CI @@ -138,7 +115,7 @@ public class PostulanteController { } if(file!=null){ - DBFile cv = createFile(file); + DBFile cv = Helper.createFile(file); if(cv!=null) cv.setPostulante(postulante); postulante.setCvFile(cv); } diff --git a/curriculumsearch/src/main/java/com/roshka/utils/Helper.java b/curriculumsearch/src/main/java/com/roshka/utils/Helper.java index 78f3197..0c3ae5e 100644 --- a/curriculumsearch/src/main/java/com/roshka/utils/Helper.java +++ b/curriculumsearch/src/main/java/com/roshka/utils/Helper.java @@ -1,5 +1,6 @@ package com.roshka.utils; +import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.YearMonth; @@ -7,6 +8,11 @@ import java.time.ZoneOffset; import java.time.temporal.ChronoUnit; import java.util.Date; +import com.roshka.modelo.DBFile; + +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + public class Helper { /** * Se espera fecha en el formato yyyy-MM-dd @@ -31,4 +37,29 @@ public class Helper { return m1.until(m2, ChronoUnit.MONTHS) + 1; } + + public static DBFile createFile(MultipartFile file) { + // Normalize file name + String fileName = StringUtils.cleanPath(file.getOriginalFilename()); + + try { + // Check if the file's name contains invalid characters + if(fileName.contains("..")) { + throw new Exception("Sorry! Filename contains invalid path sequence " + fileName); + } + if(file.getSize()==0) throw new Exception("Sorry! File cant be void");; + + DBFile dbFile = new DBFile(fileName, file.getContentType(), file.getBytes()); + + return dbFile; + } catch (IOException ex) { + ex.printStackTrace(); + return null; + } + catch(Exception ex){ + ex.printStackTrace(); + return null; + } + } + } diff --git a/curriculumsearch/src/main/resources/static/main.js b/curriculumsearch/src/main/resources/static/main.js index f2bb020..8f1e033 100644 --- a/curriculumsearch/src/main/resources/static/main.js +++ b/curriculumsearch/src/main/resources/static/main.js @@ -266,7 +266,7 @@ function agregarFieldExpierncia(event){ const exp = experiencias[index]; if(exp==null) continue; content += ` -