diff --git a/curriculumsearch/pom.xml b/curriculumsearch/pom.xml index 40c2bd1..0068dd8 100644 --- a/curriculumsearch/pom.xml +++ b/curriculumsearch/pom.xml @@ -63,6 +63,17 @@ jstl 1.2 + + + org.springframework.boot + spring-boot-starter-security + + + + + + + diff --git a/curriculumsearch/src/main/java/com/roshka/CurriculumsearchApplication.java b/curriculumsearch/src/main/java/com/roshka/CurriculumsearchApplication.java index 8f876e3..177045b 100644 --- a/curriculumsearch/src/main/java/com/roshka/CurriculumsearchApplication.java +++ b/curriculumsearch/src/main/java/com/roshka/CurriculumsearchApplication.java @@ -6,15 +6,8 @@ import java.util.List; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.roshka.modelo.Ciudad; -import com.roshka.modelo.Departamento; -import com.roshka.modelo.Postulante; -import com.roshka.modelo.PostulanteTecnologia; -import com.roshka.modelo.Tecnologia; -import com.roshka.repositorio.CiudadRepository; -import com.roshka.repositorio.DepartamentoRepository; -import com.roshka.repositorio.PostulanteRepository; -import com.roshka.repositorio.TecnologiaRepository; +import com.roshka.modelo.*; +import com.roshka.repositorio.*; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; @@ -22,6 +15,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.Bean; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @SpringBootApplication @EnableJpaRepositories("com.roshka.repositorio") @@ -33,7 +27,8 @@ public class CurriculumsearchApplication { } @Bean - CommandLineRunner runner(PostulanteRepository postRepo,TecnologiaRepository tecRepo,DepartamentoRepository depR, CiudadRepository ciudR) { + CommandLineRunner runner(PostulanteRepository postRepo, TecnologiaRepository tecRepo, DepartamentoRepository depR, + CiudadRepository ciudR, RRHHUserRepository rrhhUserRepository) { return args -> { try { // read json and write to db @@ -53,6 +48,14 @@ public class CurriculumsearchApplication { List postulantes = mapper.readValue(inputStream,typeReference); postRepo.saveAll(postulantes); System.out.println("postulantes Saved!"); + String password = new BCryptPasswordEncoder().encode("test"); + RRHHUser testuser = new RRHHUser(); + testuser.setEmail("test@test.com"); + testuser.setFirstName("test"); + testuser.setLastName("test"); + testuser.setPassword(password); + rrhhUserRepository.save(testuser); + System.out.println("Usuario Test: \nEmail: test@test.com\nPassword: test"); } catch (IOException e){ System.out.println("Unable to save tecnologias: " + e.getMessage()); 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/configuration/CustomUserDetails.java b/curriculumsearch/src/main/java/com/roshka/configuration/CustomUserDetails.java new file mode 100644 index 0000000..d8ad7b4 --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/configuration/CustomUserDetails.java @@ -0,0 +1,56 @@ +package com.roshka.configuration; + +import java.util.Collection; + +import com.roshka.modelo.RRHHUser; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +public class CustomUserDetails implements UserDetails { + + private RRHHUser user; + + public CustomUserDetails(RRHHUser user) { + this.user = user; + } + + @Override + public Collection getAuthorities() { + return null; + } + + @Override + public String getPassword() { + return user.getPassword(); + } + + @Override + public String getUsername() { + return user.getEmail(); + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return true; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return true; + } + + public String getFullName() { + return user.getFirstName() + " " + user.getLastName(); + } + +} \ No newline at end of file diff --git a/curriculumsearch/src/main/java/com/roshka/configuration/CustomUserDetailsService.java b/curriculumsearch/src/main/java/com/roshka/configuration/CustomUserDetailsService.java new file mode 100644 index 0000000..cd1f7cb --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/configuration/CustomUserDetailsService.java @@ -0,0 +1,24 @@ +package com.roshka.configuration; + +import com.roshka.modelo.RRHHUser; +import com.roshka.repositorio.RRHHUserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +public class CustomUserDetailsService implements UserDetailsService { + + @Autowired + private RRHHUserRepository userRepo; + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + RRHHUser user = userRepo.findByEmail(username); + if (user == null) { + throw new UsernameNotFoundException("User not found"); + } + return new CustomUserDetails(user); + } + +} diff --git a/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java b/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java new file mode 100644 index 0000000..d1279b2 --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/configuration/WebSecurityConfig.java @@ -0,0 +1,75 @@ +package com.roshka.configuration; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; + +import javax.sql.DataSource; + +@Configuration +@EnableWebSecurity +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + @Autowired + private DataSource dataSource; + + @Bean + public UserDetailsService userDetailsService() { + return new CustomUserDetailsService(); + } + + @Bean + public BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Bean + public DaoAuthenticationProvider authenticationProvider() { + DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); + authProvider.setUserDetailsService(userDetailsService()); + authProvider.setPasswordEncoder(passwordEncoder()); + + return authProvider; + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.authenticationProvider(authenticationProvider()); + } + + @Override + protected void configure(HttpSecurity http) throws Exception { + http +// .csrf().disable() + .authorizeRequests() + .antMatchers("/").authenticated() + .antMatchers("/home").authenticated() + .antMatchers("/cargo*").authenticated() + .antMatchers("/convocatoria*").authenticated() + .antMatchers("/tecnologia*").authenticated() + .antMatchers("/postulantes").authenticated() + .anyRequest().permitAll() + .and() + .formLogin() + .loginPage("/login") + .usernameParameter("email") + .defaultSuccessUrl("/home") + .permitAll() + .and() + .logout() + .logoutUrl("/logout") + .logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET")) + .clearAuthentication(true) + .invalidateHttpSession(true) + .deleteCookies("JSESSIONID", "remember-me") + .logoutSuccessUrl("/login"); + } + +} \ No newline at end of file diff --git a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java index 34d2c4d..9a09b88 100644 --- a/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java +++ b/curriculumsearch/src/main/java/com/roshka/controller/PostulanteController.java @@ -1,10 +1,14 @@ package com.roshka.controller; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; 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; @@ -13,13 +17,18 @@ import com.roshka.modelo.EstadoCivil; import com.roshka.modelo.Nacionalidad; import com.roshka.modelo.Postulante; import com.roshka.modelo.TipoExperiencia; +import com.roshka.repositorio.*; import com.roshka.repositorio.CiudadRepository; import com.roshka.repositorio.DepartamentoRepository; 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; @@ -40,7 +49,10 @@ public class PostulanteController { CiudadRepository ciuRepo; @Autowired - public PostulanteController(PostulanteRepository post, TecnologiaRepository tecRepo, ExperienciaRepository expRepo, InstitucionRepository institucionRepository, DepartamentoRepository depRepo, CiudadRepository ciuRepo) { + public PostulanteController( + PostulanteRepository post, TecnologiaRepository tecRepo, ExperienciaRepository expRepo, + InstitucionRepository institucionRepository, DepartamentoRepository depRepo, + CiudadRepository ciuRepo) { this.post = post; this.tecRepo = tecRepo; this.expRepo = expRepo; @@ -49,8 +61,7 @@ public class PostulanteController { this.ciuRepo = ciuRepo; } - - @RequestMapping("/") + @RequestMapping("home") public String index() { @@ -59,10 +70,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)Long lvlEng, + @RequestParam(required = false)Long 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"; } @@ -88,23 +121,30 @@ public class PostulanteController { @PostMapping(value = "/postulante",consumes = "application/json") public String guardarPostulante(@RequestBody Postulante postulante){ - System.out.println("hola"); postulante.getTecnologias().stream().filter( tec -> tec.getTecnologia().getId() != 0 ).forEach( tec -> tec.setTecnologia(tecRepo.getById(tec.getTecnologia().getId())) ); for(Estudio estudio: postulante.getEstudios()){ - Institucion institucion = institucionRepository.findByNombre(estudio.getInstitucion().getNombre()); + String nombreIns = ""; + nombreIns = estudio.getInstitucion().getNombre().toLowerCase(); + Institucion institucion = institucionRepository.findByNombre(nombreIns); if(institucion==null){ institucionRepository.save(estudio.getInstitucion()); }else{ estudio.setInstitucion(institucion); } } - System.out.println("hola"); post.save(postulante); - return "redirect:/"; + return "redirect:/postulacion-correcta"; + } + + @GetMapping("/postulacion-correcta") + public String successPostulation(Model model){ + model.addAttribute("mensaje1", "Tu informacion se ha recibido correctamente!"); + model.addAttribute("mensaje2", " espera por que nos pongamos en contacto!"); + return "exitoRegistro"; } @ResponseStatus(HttpStatus.BAD_REQUEST) @@ -125,11 +165,11 @@ public class PostulanteController { - @GetMapping({"/postid"}) - public String getPostulanteDetalle(Model model) { - Postulante p = post.findById(1L) .get(); + @GetMapping({"/postulante/{postulanteId}"}) + public String getPostulanteDetalle(Model model, @PathVariable("postulanteId") Long postulanteId) { + Postulante p = post.findById(postulanteId).orElse(null); model.addAttribute("postulante",p); return "detallepostulante"; -} + } } diff --git a/curriculumsearch/src/main/java/com/roshka/controller/RRHHUserController.java b/curriculumsearch/src/main/java/com/roshka/controller/RRHHUserController.java new file mode 100644 index 0000000..262fbfd --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/controller/RRHHUserController.java @@ -0,0 +1,57 @@ +package com.roshka.controller; + +import com.roshka.modelo.RRHHUser; +import com.roshka.repositorio.RRHHUserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; + +import javax.servlet.http.HttpServletRequest; + +@Controller +public class RRHHUserController { + private static final long REGISTER_CODE = 1234; + RRHHUserRepository rrhhUserRepository; + + @Autowired + public RRHHUserController(RRHHUserRepository rrhhUserRepository){ + this.rrhhUserRepository = rrhhUserRepository; + } + + @GetMapping("/") + public String redirectOnHome(){ + return "redirect:/home"; + } + + @GetMapping("/register") + public String showRegistrationForm(Model model) { + model.addAttribute("user", new RRHHUser()); + + return "registration"; + } + + @GetMapping("/login") + public String getLogin(Model model, HttpServletRequest request) { + if(request.getParameter("error")!=null){ + model.addAttribute("error", "Credenciales Incorrectas"); + } + return "login"; + } + + @PostMapping("/process_register") + public String processRegister(HttpServletRequest request, RRHHUser user) { + if(Long.parseLong(request.getParameter("registrationCode")) != REGISTER_CODE){ + return "redirect:/register"; + } + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + String encodedPassword = passwordEncoder.encode(user.getPassword()); + user.setPassword(encodedPassword); + + rrhhUserRepository.save(user); + + return "register_success"; + } +} diff --git a/curriculumsearch/src/main/java/com/roshka/controller/TecnologiaController.java b/curriculumsearch/src/main/java/com/roshka/controller/TecnologiaController.java new file mode 100644 index 0000000..e7a5333 --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/controller/TecnologiaController.java @@ -0,0 +1,59 @@ +package com.roshka.controller; + +import com.roshka.modelo.Tecnologia; +import com.roshka.repositorio.TecnologiaRepository; + +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.GetMapping; +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 TecnologiaController { + + TecnologiaRepository tecRepo; + + +@Autowired +public TecnologiaController(TecnologiaRepository tecRepo){ + this.tecRepo = tecRepo; + +} + +@GetMapping(path = {"/tecnologia","/tecnologia/{id}"}) +public String addtecnologiaView(Model model,@PathVariable(required = false) Long id) { + + + if(id == null) model.addAttribute("tecnologia", new Tecnologia()); + else model.addAttribute("tecnologia", tecRepo.getById(id)); + return "tecnologia-form"; +} + +@RequestMapping("/tecnologias") + public String menuTecnologias(Model model, + @RequestParam(required = false) String nombre + ) { + if(nombre == null || nombre.trim().isEmpty()) model.addAttribute("tecnologias", tecRepo.findAll()); + else model.addAttribute("tecnologias", tecRepo.findByNombreContainingIgnoreCase(nombre)); + return "tecnologias"; + } + +@PostMapping(path = {"/tecnologia","/tecnologia/{id}"}) + public String addtecnologia(@ModelAttribute Tecnologia tecnologia, BindingResult result, @PathVariable(required = false) Long id) { + if(result.hasErrors()); + if(id != null ) tecnologia.setId(id); + tecRepo.save(tecnologia); + System.out.println(tecnologia.getNombre()); + return "redirect:/tecnologias"; + } + + + + +} diff --git a/curriculumsearch/src/main/java/com/roshka/modelo/Ciudad.java b/curriculumsearch/src/main/java/com/roshka/modelo/Ciudad.java index 9ddced7..6bca1c5 100644 --- a/curriculumsearch/src/main/java/com/roshka/modelo/Ciudad.java +++ b/curriculumsearch/src/main/java/com/roshka/modelo/Ciudad.java @@ -14,6 +14,7 @@ import javax.persistence.Table; import com.fasterxml.jackson.annotation.JsonBackReference; + @Entity @Table(name="ciudad") public class Ciudad{ @@ -66,6 +67,6 @@ public class Ciudad{ - + } 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 { + + @Override + public String convertToDatabaseColumn(TipoDocumento modalidad) { + if (modalidad == null) { + return null; + } + return modalidad.getCode(); + } + + @Override + public TipoDocumento convertToEntityAttribute(String code) { + if (code == null) { + return null; + } + + return Arrays.stream(TipoDocumento.values()) + .filter(c -> c.getCode().equals(code)) + .findFirst() + .orElseThrow(IllegalArgumentException::new); + } +} + diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java index 22de503..cb9ef21 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/PostulanteRepository.java @@ -2,15 +2,17 @@ package com.roshka.repositorio; import java.util.List; +import org.hibernate.jpa.TypedParameterValue; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import com.roshka.modelo.Disponibilidad; import com.roshka.modelo.Postulante; public interface PostulanteRepository extends JpaRepository { - @Query("select p from Postulante p join p.estudios e on e.institucion LIKE %?1%") + @Query("select p from Postulante p join p.estudios e on e.institucion.nombre LIKE %?1%") public List findByInstitucionEstudio(String institucion); @Query("select p from Postulante p " + @@ -36,8 +38,18 @@ public interface PostulanteRepository extends JpaRepository { "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, Long nivelInges, Long nivel, Long tecnoId, Long instId); + } diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/RRHHUserRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/RRHHUserRepository.java new file mode 100644 index 0000000..d13c336 --- /dev/null +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/RRHHUserRepository.java @@ -0,0 +1,8 @@ +package com.roshka.repositorio; + +import com.roshka.modelo.RRHHUser; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RRHHUserRepository extends JpaRepository { + RRHHUser findByEmail(String username); +} diff --git a/curriculumsearch/src/main/java/com/roshka/repositorio/TecnologiaRepository.java b/curriculumsearch/src/main/java/com/roshka/repositorio/TecnologiaRepository.java index 3bfc4ca..fed1587 100644 --- a/curriculumsearch/src/main/java/com/roshka/repositorio/TecnologiaRepository.java +++ b/curriculumsearch/src/main/java/com/roshka/repositorio/TecnologiaRepository.java @@ -2,9 +2,11 @@ package com.roshka.repositorio; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + import com.roshka.modelo.Tecnologia; public interface TecnologiaRepository extends JpaRepository { - + public List findByNombreContainingIgnoreCase(String nombre); } diff --git a/curriculumsearch/src/main/java/com/roshka/utils/Helper.java b/curriculumsearch/src/main/java/com/roshka/utils/Helper.java index 40f586f..78f3197 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 { @@ -12,7 +15,7 @@ public class Helper { */ public static Date convertirFecha(String fecha) { try { - + if(fecha == null || fecha.trim().equals("")) return null; return new SimpleDateFormat("yyyy-MM-dd").parse(fecha); } catch (ParseException e) { // TODO Auto-generated catch block @@ -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/resources/application.properties b/curriculumsearch/src/main/resources/application.properties index 192b323..031335f 100644 --- a/curriculumsearch/src/main/resources/application.properties +++ b/curriculumsearch/src/main/resources/application.properties @@ -1,10 +1,10 @@ spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect -spring.jpa.show-sql=true +#spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true -logging.level.org.hibernate.SQL=DEBUG -logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE +#logging.level.org.hibernate.SQL=DEBUG +#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE spring.sql.init.mode=always spring.sql.init.platform=postgres diff --git a/curriculumsearch/src/main/resources/json/postulante.json b/curriculumsearch/src/main/resources/json/postulante.json index 3ffaf21..e14b92c 100644 --- a/curriculumsearch/src/main/resources/json/postulante.json +++ b/curriculumsearch/src/main/resources/json/postulante.json @@ -3,11 +3,11 @@ "resumen": "In irure aliquip qui cillum veniam sint amet amet sint ex proident anim mollit.", "nacionalidad":"Paraguayo", "estadoCivil":"Soltero", - "tipoDocumento":"ci", + "tipoDocumento":"CI", "nombre": "Taylor", "apellido": "Obrien", "correo": "gladysalexander@dadabase.com", - "ci": 5821432, + "nroDocument": 5821432, "ciudadId": 238, "telefono": "(950) 417-3681", "fechaNacimiento": "2021-08-16", @@ -61,11 +61,11 @@ "resumen": "Do nostrud aliqua adipisicing in sunt aute id do elit ut dolor ad aliquip.", "nacionalidad":"Paraguayo", "estadoCivil":"Soltero", - "tipoDocumento":"ci", + "tipoDocumento":"CI", "nombre": "Hopkins", "apellido": "Parks", "correo": "grahamgriffith@zilidium.com", - "ci": 4213361, + "nroDocument": 4213361, "ciudadId": 96, "telefono": "(866) 560-2541", "fechaNacimiento": "2021-09-04", @@ -107,11 +107,11 @@ "resumen": "Occaecat non cupidatat amet reprehenderit consectetur ullamco et.", "nacionalidad":"Paraguayo", "estadoCivil":"Soltero", - "tipoDocumento":"ci", + "tipoDocumento":"CI", "nombre": "Alejandra", "apellido": "Riggs", "correo": "ruthrobertson@homelux.com", - "ci": 4605787, + "nroDocument": 4605787, "ciudadId": 30, "telefono": "(876) 580-2411", "fechaNacimiento": "2021-01-28", @@ -153,11 +153,11 @@ "resumen": "Qui ullamco excepteur velit ad ullamco id id nisi irure dolore cupidatat mollit ullamco veniam.", "nacionalidad":"Paraguayo", "estadoCivil":"Soltero", - "tipoDocumento":"ci", + "tipoDocumento":"CI", "nombre": "Angelina", "apellido": "Wallace", "correo": "christiwalls@capscreen.com", - "ci": 4591352, + "nroDocument": 4591352, "ciudadId": 65, "telefono": "(931) 499-3122", "fechaNacimiento": "2021-06-05", @@ -199,11 +199,11 @@ "resumen": "Deserunt tempor ut et eiusmod et labore Lorem.", "nacionalidad":"Paraguayo", "estadoCivil":"Soltero", - "tipoDocumento":"ci", + "tipoDocumento":"CI", "nombre": "Rivas", "apellido": "Owens", "correo": "shirleyguzman@equitox.com", - "ci": 3969318, + "nroDocument": 3969318, "ciudadId": 143, "telefono": "(972) 524-2610", "fechaNacimiento": "2021-09-09", @@ -245,11 +245,11 @@ "resumen": "Aliqua est adipisicing do exercitation sit laborum aliquip aliqua adipisicing enim aute.", "nacionalidad":"Paraguayo", "estadoCivil":"Soltero", - "tipoDocumento":"ci", + "tipoDocumento": "CI", "nombre": "Estelle", "apellido": "Gamble", "correo": "mclaughlinpate@enomen.com", - "ci": 2329745, + "nroDocument": 2329745, "ciudadId": 248, "telefono": "(933) 501-3525", "fechaNacimiento": "2021-03-24", @@ -291,11 +291,11 @@ "resumen": "Officia eiusmod ut reprehenderit tempor consequat elit amet ex voluptate aute anim do.", "nacionalidad":"Paraguayo", "estadoCivil":"Soltero", - "tipoDocumento":"ci", + "tipoDocumento":"CI", "nombre": "Mariana", "apellido": "Ratliff", "correo": "loramiddleton@musanpoly.com", - "ci": 4519594, + "nroDocument": 4519594, "ciudadId": 104, "telefono": "(817) 492-2493", "fechaNacimiento": "2021-07-30", diff --git a/curriculumsearch/src/main/resources/static/main.js b/curriculumsearch/src/main/resources/static/main.js index eb1e56a..749e74c 100644 --- a/curriculumsearch/src/main/resources/static/main.js +++ b/curriculumsearch/src/main/resources/static/main.js @@ -26,7 +26,14 @@ const formValidator = function () { }, false) }) } - +function carg(elemento) { + var element = document.getElementById('descripcion'); + if(elemento == "otro"){ + element.style.display='block'; + }else{ + element.style.display='none'; + } +} function agregarFieldExpierncia(event){ //recoger del form const pairs = {}; @@ -79,7 +86,7 @@ function agregarFieldExpierncia(event){ content += `
  • ${exp.institucion} - +
  • ` @@ -173,6 +180,7 @@ function serializeJSON (form) { // Create a new FormData object const formData = new FormData(form); + // Create an object to hold the name/value pairs const pairs = {}; @@ -189,20 +197,24 @@ function serializeJSON (form) { } async function postData(url = '', data = {}) { + var token = document.querySelector("meta[name='_csrf']").content; + var headerxs = document.querySelector("meta[name='_csrf_header']").content; // Default options are marked with * - const response = await fetch(url, { + let senddata = { method: 'POST', // *GET, POST, PUT, DELETE, etc. mode: 'cors', // no-cors, *cors, same-origin cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached credentials: 'same-origin', // include, *same-origin, omit headers: { - 'Content-Type': 'application/json' - // 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Type': 'application/json', + // 'Content-Type': 'application/x-www-form-urlencoded', }, redirect: 'follow', // manual, *follow, error referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url body: data // body data type must match "Content-Type" header - }); + } + senddata["headers"][headerxs] = token; + const response = await fetch(url, senddata); return response; // parses JSON response into native JavaScript objects } formValidator() diff --git a/curriculumsearch/src/main/webapp/jsp/alerts.jsp b/curriculumsearch/src/main/webapp/jsp/alerts.jsp new file mode 100644 index 0000000..173ec86 --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/alerts.jsp @@ -0,0 +1,18 @@ +<%@ 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" %> + +
    + + + + + + +
    \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/exitoRegistro.jsp b/curriculumsearch/src/main/webapp/jsp/exitoRegistro.jsp new file mode 100644 index 0000000..f462dbf --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/exitoRegistro.jsp @@ -0,0 +1,51 @@ +<%@ 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" %> + + + + + + +
    +
    + +
    +

    Genial!

    +

    ${mensaje1}
    ${mensaje2}

    +
    + + \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/header.jsp b/curriculumsearch/src/main/webapp/jsp/header.jsp new file mode 100644 index 0000000..b31d9d3 --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/header.jsp @@ -0,0 +1,9 @@ +<%@ 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" %> +
    +
    + +
    +
    \ 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 5a9a2a5..49f9816 100644 --- a/curriculumsearch/src/main/webapp/jsp/index.jsp +++ b/curriculumsearch/src/main/webapp/jsp/index.jsp @@ -1,16 +1,27 @@ +<%@ 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" %> + + Document - Form postulante - Lista de postulantes - Tecnologias - Lista de convocatorias - Lista de cargos + + \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/login.jsp b/curriculumsearch/src/main/webapp/jsp/login.jsp new file mode 100644 index 0000000..11e5c13 --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/login.jsp @@ -0,0 +1,51 @@ +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + + + + Login + + + + + + +
    +
    +
    +
    +
    +
    + + + + +

    Ingresar

    +
    + + +
    + +
    + + +
    + + + +
    + +
    + +
    +
    +
    +
    +
    +
    + + + + diff --git a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp index c11b9e2..63b3b5f 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulante-form.jsp @@ -15,7 +15,7 @@ @@ -180,18 +180,19 @@ - -
    - - -
    - Luce Bien! -
    + +
    + +
    - - + +
    Luce Bien!
    @@ -468,6 +469,8 @@
    + + diff --git a/curriculumsearch/src/main/webapp/jsp/postulantes.jsp b/curriculumsearch/src/main/webapp/jsp/postulantes.jsp index d452dc2..c2c85e2 100644 --- a/curriculumsearch/src/main/webapp/jsp/postulantes.jsp +++ b/curriculumsearch/src/main/webapp/jsp/postulantes.jsp @@ -13,28 +13,56 @@
    - - +
    + + + +
    + + + + + + +
    + + + + + + +
    @@ -54,21 +82,30 @@ - + - + + - - - -
    ${postulante.nombre} ${postulante.apellido} ${postulante.disponibilidad.getDescripcion()} ${postulante.nivelIngles}0${postulante.experienciaMeses} - ${detalle_tecnologia.getTecnologia().getNombre()}${not staTec.last ? "," : ""} + ${detalle_tecnologia.getTecnologia().getNombre()}${not staTec.last ? "," : ""}
    Ver
    -
    - + \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/register_success.jsp b/curriculumsearch/src/main/webapp/jsp/register_success.jsp new file mode 100644 index 0000000..7c28633 --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/register_success.jsp @@ -0,0 +1,15 @@ + + + + + Registration Success + + + +
    +

    You have signed up successfully!

    +

    Click here to Login

    +
    + + + \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/registration.jsp b/curriculumsearch/src/main/webapp/jsp/registration.jsp new file mode 100644 index 0000000..fc9a74f --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/registration.jsp @@ -0,0 +1,75 @@ +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> + + + + Registration Success + + + + + + + + + +
    +
    +
    +
    +
    + Sample photo +
    +

    Informacion de Registro

    + + +
    + Email + +
    +
    +
    +
    + Nombre + +
    +
    +
    +
    + Apellido + +
    +
    +
    + +
    + Contrasena + +
    +
    +
    + +
    + + +
    + +
    +
    + + +
    + +
    +
    +
    +
    +
    +
    + + diff --git a/curriculumsearch/src/main/webapp/jsp/tecnologia-form.jsp b/curriculumsearch/src/main/webapp/jsp/tecnologia-form.jsp new file mode 100644 index 0000000..caceeea --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/tecnologia-form.jsp @@ -0,0 +1,39 @@ +<%@ 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" %> + + + + + + + + + + + Hello, world! + + + + + + + + + + name: + + + + + + + + + + + + \ No newline at end of file diff --git a/curriculumsearch/src/main/webapp/jsp/tecnologias.jsp b/curriculumsearch/src/main/webapp/jsp/tecnologias.jsp new file mode 100644 index 0000000..975ce1b --- /dev/null +++ b/curriculumsearch/src/main/webapp/jsp/tecnologias.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" %> + + + + + + + Tecnologia + + + + +
    +
    + + + +
    + Agregar Nueva Tecnologia +
    +
    + + + + + + + + + + + + + + + + + + + + + +
    #Tecnologia
    ${sta.index+1}${tecnologia.getNombre()}Editar tecnologia
    +
    + + + \ No newline at end of file