@ -3,14 +3,20 @@ package com.example.proyectofinal.controllers;
import com.example.proyectofinal.models.empresas.* ;
import com.example.proyectofinal.models.empresas.* ;
import com.example.proyectofinal.repositories.empresas.* ;
import com.example.proyectofinal.repositories.empresas.* ;
import jakarta.servlet.http.HttpSession ;
import com.example.proyectofinal.servicios.EmpresaService ;
import org.springframework.data.domain.Page ;
import org.springframework.data.domain.PageRequest ;
import org.springframework.data.domain.Pageable ;
import org.springframework.http.ResponseEntity ;
import org.springframework.ui.Model ;
import org.springframework.ui.Model ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Controller ;
import org.springframework.stereotype.Controller ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.PathVariable ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestParam ;
import org.springframework.web.bind.annotation.RequestParam ;
import javax.servlet.http.HttpServletRequest ;
import java.util.* ;
import java.util.* ;
@Controller
@Controller
@ -37,67 +43,73 @@ public class BuscadorController {
@Autowired
@Autowired
private CicloRepository cicloRepository ;
private CicloRepository cicloRepository ;
@Autowired
private EmpresaService empresaService ;
@GetMapping
@GetMapping
public String buscador ( ) {
public String buscador ( ) {
return "buscador_admin" ;
return "buscador_admin" ;
}
}
@GetMapping ( "/search" )
@GetMapping ( "/empresas/page/{pageNum}" )
public String search ( @RequestParam String query , @RequestParam String searchOption , Model model , HttpSession session ) {
public String seachEmpresasList ( @PathVariable int pageNum ,
@RequestParam ( defaultValue = "" ) String query ,
Model model ,
@RequestParam ( defaultValue = "10" ) int size ,
@RequestParam ( defaultValue = "id" ) String sortField ,
@RequestParam ( defaultValue = "asc" ) String sortDir ) {
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
if ( searchOption . equals ( "OptEmpresa" ) ) {
List < Empresa > empresas ;
List < Integer > itemsPage = Arrays . asList ( 5 , 10 , 15 , 20 , 25 , 50 ) ;
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
ArrayList < Empresa > empresas = new ArrayList < > ( empressaRepository . findAllAsc ( ) ) ;
Page < Empresa > page = this . empresaService . finadAllpaginated ( pageNum , size , "id" , "asc" ) ;
model . addAttribute ( "empresas" , empresas ) ;
empresas = page . getContent ( ) ;
} else {
Page < Empresa > page = this . empresaService . finadAllpaginated ( pageNum , size , sortField , sortDir ) ;
empresas = page . getContent ( ) ;
}
model . addAttribute ( "currentSize" , size ) ;
Map < String , Object > attributes = getPagAtrEmpresas ( pageNum , query , size , sortField , sortDir , empresas , itemsPage ) ;
for ( Map . Entry < String , Object > entry : attributes . entrySet ( ) ) {
model . addAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ;
}
return "/list/empresas" ;
return "/list/empresas" ;
}
}
// if(word.length == 1){
// ArrayList<Empresa> empresas = new ArrayList<>(empressaRepository.getEmpressaByKeywordsOrName(word[0]));
// model.addAttribute("empresas", empresas);
// return "/list/empresas";
public String searchAlumnosList ( @RequestParam String query , @RequestParam String searchOption , @RequestParam ( required = false ) String filter , Model model , @RequestParam ( defaultValue = "0" ) int page , @RequestParam ( defaultValue = "10" ) int size ) {
// }else if(word.length == 2){
Pageable pageable = PageRequest . of ( page , size ) ;
// ArrayList<Empresa> empresas = new ArrayList<>(empressaRepository.getEmpressaByKeywordsOrName(word[0]));
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
// empresas.addAll(empressaRepository.getEmpressaByKeywordsOrName(word[1]));
// model.addAttribute("empresas", empresas);
// return "/list/empresas";
// }
} else if ( searchOption . equals ( "OptAlumno" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todos" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todos" ) ) {
Array List< Alumno > alumnos = new ArrayList < > ( alumnoRepository . findAll ( ) ) ;
List < Alumno > alumnos = new ArrayList < > ( alumnoRepository . findAll ( ) ) ;
model . addAttribute ( "alumnos" , alumnos ) ;
model . addAttribute ( "alumnos" , alumnos ) ;
return "/list/alumnos" ;
return "/list/alumnos" ;
}
}
// if (word.length == 1) {
return "/list/alumnos" ;
// System.out.println("Buscando alumnos");
}
// ArrayList<Alumno> alumnos = new ArrayList<>(alumnoRepository.getAlumnoByKeywordsOrName(word[0]));
// model.addAttribute("alumnos", alumnos);
@GetMapping ( "/ofertas" )
// return "/list/alumnos";
public String searchOfertasList ( @RequestParam String query , @RequestParam String searchOption , @RequestParam ( required = false ) String filter , Model model , @RequestParam ( defaultValue = "0" ) int page , @RequestParam ( defaultValue = "10" ) int size ) {
// } else if (word.length == 2) {
Pageable pageable = PageRequest . of ( page , size ) ;
// System.out.println("Buscando alumnos");
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
// ArrayList<Alumno> alumnos = new ArrayList<>(alumnoRepository.getAlumnoByKeywordsOrName(word[0]));
// alumnos.addAll(alumnoRepository.getAlumnoByKeywordsOrName(word[1]));
// model.addAttribute("alumnos", alumnos);
// return "/list/alumnos";
// }
} else if ( searchOption . equals ( "OptOferta" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
Array List< Oferta > ofertas = new ArrayList < > ( ofertaRepository . findAll ( ) ) ;
List < Oferta > ofertas = new ArrayList < > ( ofertaRepository . findAll ( ) ) ;
model . addAttribute ( "ofertas" , ofertas ) ;
model . addAttribute ( "ofertas" , ofertas ) ;
return "/list/ofertas" ;
return "/list/ofertas" ;
}
}
// if (word.length == 1) {
return "/list/ofertas" ;
// ArrayList<Oferta> ofertas = new ArrayList<>(ofertaRepository.getOfertaFullTextSeach(word[0]));
}
// model.addAttribute("ofertas", ofertas);
// return "/list/ofertas";
@GetMapping ( "/sectores" )
// } else if (word.length == 2) {
public String searchSectoresList ( @RequestParam String query , @RequestParam String searchOption , @RequestParam ( required = false ) String filter , Model model , @RequestParam ( defaultValue = "0" ) int page , @RequestParam ( defaultValue = "10" ) int size ) {
// ArrayList<Oferta> ofertas = new ArrayList<>(ofertaRepository.getOfertaFullTextSeach(word[0]));
Pageable pageable = PageRequest . of ( page , size ) ;
// ofertas.addAll(ofertaRepository.getOfertaFullTextSeach(word[1]));
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
// model.addAttribute("ofertas", ofertas);
// return "/list/ofertas";
// }
} else if ( searchOption . equals ( "OptSector" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
Array List< Sector > sectores = new ArrayList < > ( sectorRepository . findAll ( ) ) ;
List < Sector > sectores = new ArrayList < > ( sectorRepository . findAll ( ) ) ;
model . addAttribute ( "sectores" , sectores ) ;
model . addAttribute ( "sectores" , sectores ) ;
return "/list/sectores" ;
return "/list/sectores" ;
} else {
} else {
@ -105,55 +117,92 @@ public class BuscadorController {
model . addAttribute ( "sectores" , sector ) ;
model . addAttribute ( "sectores" , sector ) ;
return "/list/sectores" ;
return "/list/sectores" ;
}
}
} else if ( searchOption . equals ( "OptSucursal" ) ) {
}
@GetMapping ( "/sucursales" )
public String searchSucursalesList ( @RequestParam String query , @RequestParam String searchOption , @RequestParam ( required = false ) String filter , Model model , @RequestParam ( defaultValue = "0" ) int page , @RequestParam ( defaultValue = "10" ) int size ) {
Pageable pageable = PageRequest . of ( page , size ) ;
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
ArrayList < Sucursal > sucursalSet = new ArrayList < > ( sucursalRepository . findAll ( ) ) ;
List< Sucursal > sucursalSet = new ArrayList < > ( sucursalRepository . findAll ( ) ) ;
model . addAttribute ( "sucursales" , sucursalSet ) ;
model . addAttribute ( "sucursales" , sucursalSet ) ;
return "/list/sucursales" ;
return "/list/sucursales" ;
}
}
// } else {
return "/list/sucursales" ;
// ArrayList<Sucursal> sucursalSet = new ArrayList<>(sucursalRepository.getSucursalFullTextSeach(word[0]));
// model.addAttribute("sucursales", sucursalSet);
// return "/list/sucursales";
// }
} else if ( searchOption . equals ( "OptSkill" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
ArrayList < Skill > skills = new ArrayList < > ( skillRepository . findAll ( ) ) ;
model . addAttribute ( "skills" , skills ) ;
return "/list/skills" ;
}
}
// else{
// ArrayList<Skill> skills = new ArrayList<>(skillRepository.getSkillFullTextSeach(word[0]));
// model.addAttribute("skills", skills);
@GetMapping ( "/contactos" )
// return "/list/skills";
public String searchContactosList ( @RequestParam String query , @RequestParam String searchOption , @RequestParam ( required = false ) String filter , Model model , @RequestParam ( defaultValue = "0" ) int page , @RequestParam ( defaultValue = "10" ) int size ) {
// }
Pageable pageable = PageRequest . of ( page , size ) ;
} else if ( searchOption . equals ( "OptContactos" ) ) {
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
Array List< Contacto > contactos = new ArrayList < > ( contactoRepository . findAll ( ) ) ;
List < Contacto > contactos = new ArrayList < > ( contactoRepository . findAll ( ) ) ;
model . addAttribute ( "contactos" , contactos ) ;
model . addAttribute ( "contactos" , contactos ) ;
return "/list/contactos" ;
return "/list/contactos" ;
}
}
// else {
return "/list/contactos" ;
// ArrayList<Contacto> contactos = new ArrayList<>(contactoRepository.getContactoFullTextSeach(word[0]));
}
// model.addAttribute("contactos", contactos);
// return "/list/contactos";
@GetMapping ( "/familias" )
// }
public String searchFamiliasList ( @RequestParam String query , @RequestParam String searchOption , @RequestParam ( required = false ) String filter , Model model , @RequestParam ( defaultValue = "0" ) int page , @RequestParam ( defaultValue = "10" ) int size ) {
} else if ( searchOption . equals ( "OptFamilias" ) ) {
Pageable pageable = PageRequest . of ( page , size ) ;
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
Array List< Familia > familias = new ArrayList < > ( familiaRepository . findAll ( ) ) ;
List< Familia > familias = new ArrayList < > ( familiaRepository . findAll ( ) ) ;
model . addAttribute ( "familias" , familias ) ;
model . addAttribute ( "familias" , familias ) ;
return "/list/familias" ;
return "/list/familias" ;
}
}
} else if ( searchOption . equals ( "OptCiclos" ) ) {
return "/list/familias" ;
}
@GetMapping ( "/ciclos" )
public String searchCiclosList ( @RequestParam String query , @RequestParam String searchOption , @RequestParam ( required = false ) String filter , Model model , @RequestParam ( defaultValue = "0" ) int page , @RequestParam ( defaultValue = "10" ) int size ) {
Pageable pageable = PageRequest . of ( page , size ) ;
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
ArrayList < Ciclo > ciclos = new ArrayList < > ( cicloRepository . findAll ( ) ) ;
List< Ciclo > ciclos = new ArrayList < > ( cicloRepository . findAll ( ) ) ;
model . addAttribute ( "ciclos" , ciclos ) ;
model . addAttribute ( "ciclos" , ciclos ) ;
return "/list/ciclos" ;
return "/list/ciclos" ;
}
}
} else {
return "/list/ciclos" ;
System . out . println ( "ERROR EN BUSQUEDA DE UNA PALABRA" ) ;
}
return "error" ;
@GetMapping ( "/skills" )
public String searchSkillsList ( @RequestParam String query , @RequestParam String searchOption , @RequestParam ( required = false ) String filter , Model model , @RequestParam ( defaultValue = "0" ) int page , @RequestParam ( defaultValue = "10" ) int size ) {
Pageable pageable = PageRequest . of ( page , size ) ;
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
if ( word . length = = 1 & & word [ 0 ] . equalsIgnoreCase ( "all" ) | | word [ 0 ] . equalsIgnoreCase ( "todas" ) ) {
List < Skill > skills = new ArrayList < > ( skillRepository . findAll ( ) ) ;
model . addAttribute ( "skills" , skills ) ;
return "/list/skills" ;
}
return "/list/skills" ;
}
}
return "error" ;
public Map < String , Object > getPagAtrEmpresas ( int pageNum , String query , int size , String sortField , String sortDir , List < Empresa > empresas , List < Integer > itemsPage ) {
Map < String , Object > attributes = new HashMap < > ( ) ;
Page < Empresa > page = this . empresaService . finadAllpaginated ( pageNum , size , "id" , "asc" ) ;
attributes . put ( "currentPage" , pageNum ) ;
attributes . put ( "totalPages" , page . getTotalPages ( ) ) ;
attributes . put ( "totalItems" , page . getTotalElements ( ) ) ;
attributes . put ( "sortField" , sortField ) ;
attributes . put ( "sortDir" , sortDir ) ;
attributes . put ( "reverseSortDir" , sortDir . equals ( "asc" ) ? "desc" : "asc" ) ;
attributes . put ( "empresas" , empresas ) ;
attributes . put ( "query" , query ) ;
attributes . put ( "itemsPage" , itemsPage ) ;
return attributes ;
}
@GetMapping ( "/empresas/search" )
public ResponseEntity < List < Empresa > > searchEmpresas ( @RequestParam String query ) {
List < Empresa > empresas = empresaService . search ( query ) ;
return ResponseEntity . ok ( empresas ) ;
}
}
}
}