@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping ;
import org.springframework.web.bind.annotation.RequestParam ;
import javax.servlet.http.HttpSession ;
import java.util.* ;
@Controller
@ -58,35 +59,18 @@ public class BuscadorController {
@RequestParam ( defaultValue = "nombre" ) String sortField ,
@RequestParam ( defaultValue = "asc" ) String sortDir ,
@RequestParam String secondaryOption ,
Model model ) {
System . out . println ( "Selected option TEST: " + secondaryOption ) ;
Model model ) {
Page < Empresa > page = empresaService . getPage ( pageNum , size , sortField , sortDir , query , secondaryOption ) ;
List < Integer > itemsPage = Arrays . asList ( 5 , 10 , 15 , 20 , 25 , 50 ) ;
if ( page ! = null ) {
List < Empresa > empresas = page . getContent ( ) ;
model . addAttribute ( "currentPage" , pageNum ) ;
model . addAttribute ( "totalPages" , page . getTotalPages ( ) ) ;
model . addAttribute ( "totalItems" , page . getTotalElements ( ) ) ;
addPaginationAttributes ( model , pageNum , page , sortField , sortDir , query , itemsPage , size ) ;
model . addAttribute ( "empresas" , empresas ) ;
model . addAttribute ( "sortField" , sortField ) ;
model . addAttribute ( "sortDir" , sortDir ) ;
model . addAttribute ( "reverseSortDir" , sortDir . equals ( "asc" ) ? "desc" : "asc" ) ;
model . addAttribute ( "query" , query ) ;
model . addAttribute ( "secondaryOption" , secondaryOption ) ;
model . addAttribute ( "itemsPage" , itemsPage ) ;
model . addAttribute ( "currentSize" , size ) ;
} else {
System . out . println ( "No se encontraron empresas" ) ;
// System.out.println("No se encontraron empresas");
}
// List<Object> models = model.asMap().values().stream().toList();
// for(Object m : models){
// System.out.println(m);
// }
return "/list/empresas" ;
}
@ -101,15 +85,11 @@ public class BuscadorController {
String [ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
List < Integer > itemsPage = Arrays . asList ( 5 , 10 , 15 , 20 , 25 , 50 ) ;
Map < String , Object > attributes = new HashMap < > ( ) ;
if ( secondaryOption . equalsIgnoreCase ( "Todo" ) ) {
sortField = "nombre" ;
sortDir = "asc" ;
attributes = getPaginatedAttributes ( pageNum , query , size , sortField , sortDir , alumnoService , itemsPage ) ;
}
attributes = getPaginatedAttributes ( pageNum , query , size , sortField , sortDir , sectorService , itemsPage ) ;
for ( Map . Entry < String , Object > entry : attributes . entrySet ( ) ) {
model . addAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ;
}
model . addAttribute ( "secondaryOption" , secondaryOption ) ;
return "/list/sectores" ;
}
@ -122,17 +102,16 @@ public class BuscadorController {
@RequestParam ( defaultValue = "asc" ) String sortDir ,
@RequestParam ( defaultValue = "" ) String secondaryOption ,
Model model ) {
String[ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
Page< Contacto > page = contactosService . getPage ( pageNum , size , sortField , sortDir , query , secondaryOption ) ;
List < Integer > itemsPage = Arrays . asList ( 5 , 10 , 15 , 20 , 25 , 50 ) ;
Map < String , Object > attributes = new HashMap < > ( ) ;
if ( secondaryOption . equalsIgnoreCase ( "Todo" ) ) {
sortField = "nombre" ;
sortDir = "asc" ;
attributes = getPaginatedAttributes ( pageNum , query , size , sortField , sortDir , alumnoService , itemsPage ) ;
}
for ( Map . Entry < String , Object > entry : attributes . entrySet ( ) ) {
model . addAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ;
if ( page ! = null ) {
List < Contacto > contactos = page . getContent ( ) ;
addPaginationAttributes ( model , pageNum , page , sortField , sortDir , query , itemsPage , size ) ;
model . addAttribute ( "contactos" , contactos ) ;
model . addAttribute ( "query" , query ) ;
model . addAttribute ( "secondaryOption" , secondaryOption ) ;
} else {
//System.out.println("No se encontraron Contactos");
}
return "/list/contactos" ;
}
@ -145,16 +124,16 @@ public class BuscadorController {
@RequestParam ( defaultValue = "asc" ) String sortDir ,
@RequestParam ( defaultValue = "" ) String secondaryOption ,
Model model ) {
String[ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
Page< Sucursal > page = sucursalService . getPage ( pageNum , size , sortField , sortDir , query , secondaryOption ) ;
List < Integer > itemsPage = Arrays . asList ( 5 , 10 , 15 , 20 , 25 , 50 ) ;
Map < String , Object > attributes = new HashMap < > ( ) ;
if ( secondaryOption . equalsIgnoreCase ( "Todo" ) ) {
sortField = "nombre" ;
sortDir = "asc" ;
attributes = getPaginatedAttributes ( pageNum , query , size , sortField , sortDir , alumnoService , itemsPage ) ;
}
for ( Map . Entry < String , Object > entry : attributes . entrySet ( ) ) {
model . addAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ;
if ( page ! = null ) {
List < Sucursal > sucursals = page . getContent ( ) ;
addPaginationAttributes( model , pageNum , page , sortField , sortDir , query , itemsPage , size ) ;
model. addAttribute ( "sucursals" , sucursals ) ;
model. addAttribute ( "query" , query ) ;
model . addAttribute ( "secondaryOption" , secondaryOption ) ;
} else {
// System.out.println("No se encontraron sucursales");
}
return "/list/sucursales" ;
}
@ -167,16 +146,16 @@ public class BuscadorController {
@RequestParam ( defaultValue = "asc" ) String sortDir ,
@RequestParam ( defaultValue = "" ) String secondaryOption ,
Model model ) {
String[ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
Page< Oferta > page = ofertasService . getPage ( pageNum , size , sortField , sortDir , query , secondaryOption ) ;
List < Integer > itemsPage = Arrays . asList ( 5 , 10 , 15 , 20 , 25 , 50 ) ;
Map < String , Object > attributes = new HashMap < > ( ) ;
if ( secondaryOption . equalsIgnoreCase ( "Todo" ) ) {
sortField = "nombre" ;
sortDir = "asc" ;
attributes = getPaginatedAttributes ( pageNum , query , size , sortField , sortDir , alumnoService , itemsPage ) ;
}
for ( Map . Entry < String , Object > entry : attributes . entrySet ( ) ) {
model . addAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ;
if ( page ! = null ) {
List < Oferta > ofertas = page . getContent ( ) ;
addPaginationAttributes( model , pageNum , page , sortField , sortDir , query , itemsPage , size ) ;
model. addAttribute ( "ofertas" , ofertas ) ;
model . addAttribute ( "query" , query ) ;
model . addAttribute ( "secondaryOption" , secondaryOption ) ;
} else {
// System.out.println("No se encontraron ofertas");
}
return "/list/ofertas" ;
}
@ -195,11 +174,12 @@ public class BuscadorController {
if ( secondaryOption . equalsIgnoreCase ( "Todo" ) ) {
sortField = "nombre" ;
sortDir = "asc" ;
attributes = getPaginatedAttributes ( pageNum , query , size , sortField , sortDir , alumno Service, itemsPage ) ;
attributes = getPaginatedAttributes ( pageNum , query , size , sortField , sortDir , familia Service, itemsPage ) ;
}
for ( Map . Entry < String , Object > entry : attributes . entrySet ( ) ) {
model . addAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ;
}
model . addAttribute ( "secondaryOption" , secondaryOption ) ;
return "/list/familias" ;
}
@ -211,16 +191,16 @@ public class BuscadorController {
@RequestParam ( defaultValue = "asc" ) String sortDir ,
@RequestParam ( defaultValue = "" ) String secondaryOption ,
Model model ) {
String[ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
Page< Ciclo > page = cicloService . getPage ( pageNum , size , sortField , sortDir , query , secondaryOption ) ;
List < Integer > itemsPage = Arrays . asList ( 5 , 10 , 15 , 20 , 25 , 50 ) ;
Map < String , Object > attributes = new HashMap < > ( ) ;
if ( secondaryOption . equalsIgnoreCase ( "Todo" ) ) {
sortField = "nombre" ;
sortDir = "asc" ;
attributes = getPaginatedAttributes ( pageNum , query , size , sortField , sortDir , alumnoService , itemsPage ) ;
}
for ( Map . Entry < String , Object > entry : attributes . entrySet ( ) ) {
model . addAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ;
if ( page ! = null ) {
List < Ciclo > ciclos = page . getContent ( ) ;
addPaginationAttributes( model , pageNum , page , sortField , sortDir , query , itemsPage , size ) ;
model. addAttribute ( "ciclos" , ciclos ) ;
model. addAttribute ( "query" , query ) ;
model . addAttribute ( "secondaryOption" , secondaryOption ) ;
} else {
// System.out.println("No se encontraron ofertas");
}
return "/list/ciclos" ;
}
@ -234,16 +214,16 @@ public class BuscadorController {
@RequestParam ( defaultValue = "" ) String secondaryOption ,
Model model ) {
String[ ] word = query . split ( "\\b(y|o)\\b|[,/]" ) ;
Page< Alumno > page = alumnoService . getPage ( pageNum , size , sortField , sortDir , query , secondaryOption ) ;
List < Integer > itemsPage = Arrays . asList ( 5 , 10 , 15 , 20 , 25 , 50 ) ;
Map < String , Object > attributes = new HashMap < > ( ) ;
if ( secondaryOption . equalsIgnoreCase ( "Todo" ) ) {
sortField = "nombre" ;
sortDir = "asc" ;
attributes = getPaginatedAttributes ( pageNum , query , size , sortField , sortDir , alumnoService , itemsPage ) ;
}
for ( Map . Entry < String , Object > entry : attributes . entrySet ( ) ) {
model . addAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ;
if ( page ! = null ) {
List < Alumno > alumnos = page . getContent ( ) ;
addPaginationAttributes( model , pageNum , page , sortField , sortDir , query , itemsPage , size ) ;
model. addAttribute ( "alumnos" , alumnos ) ;
model. addAttribute ( "query" , query ) ;
model . addAttribute ( "secondaryOption" , secondaryOption ) ;
} else {
// System.out.println("No se encontraron alumnos");
}
return "/list/alumnos" ;
}
@ -268,6 +248,7 @@ public class BuscadorController {
for ( Map . Entry < String , Object > entry : attributes . entrySet ( ) ) {
model . addAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ;
}
model . addAttribute ( "secondaryOption" , secondaryOption ) ;
return "/list/skills" ;
}
public < T > Map < String , Object > getPaginatedAttributes ( int pageNum , String query , int size , String sortField , String sortDir , IPagination < T > service , List < Integer > itemsPage ) {
@ -287,11 +268,24 @@ public class BuscadorController {
return attributes ;
}
public void addPaginationAttributes ( Model model , int pageNum , Page < ? > page , String sortField , String sortDir , String query , List < Integer > itemsPage , int size ) {
model . addAttribute ( "currentPage" , pageNum ) ;
model . addAttribute ( "totalPages" , page . getTotalPages ( ) ) ;
model . addAttribute ( "totalItems" , page . getTotalElements ( ) ) ;
model . addAttribute ( "sortField" , sortField ) ;
model . addAttribute ( "sortDir" , sortDir ) ;
model . addAttribute ( "reverseSortDir" , sortDir . equals ( "asc" ) ? "desc" : "asc" ) ;
model . addAttribute ( "itemsPage" , itemsPage ) ;
model . addAttribute ( "currentSize" , size ) ;
}
@GetMapping ( "/empresas/search" )
public ResponseEntity < List < Empresa > > searchEmpresas ( @RequestParam String query ) {
List < Empresa > empresas = empresaService . search ( query ) ;
return ResponseEntity . ok ( empresas ) ;
public ResponseEntity < List < Empresa > > searchEmpresas ( @RequestParam String query , @RequestParam String secondaryQuery ) {
List < Empresa > searchResult = empresaService . search ( query ) ;
return ResponseEntity . ok ( searchResult ) ;
}
@GetMapping ( "/sectores/search" )