La busqueda compleja, cuando eliges otra subcategoria com empressa por secoters, y usas la barra de busqueda de lista esta completa. Ajustes hecho a metodos encesarios en cotrolador,Interfaces, servicios y repositorios.

Funcionamiento minimo conseguido
master
vicsash 4 months ago
parent 8cef213edf
commit 665a45d106

@ -15,7 +15,6 @@ 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.text.ParseException;
import java.util.*;
@ -354,13 +353,23 @@ public class BuscadorController {
model.addAttribute("currentSize", size);
}
/**
* This mehod is used to search for entities in the database
* it uses the query that is passed as a parameter to search for the entities
* the query comes from the searchbar in the frontend, the list
* @param querySearchBar the text in searchbar from the lsit a String
* @return a list of entities that match the query
*/
@GetMapping("/empresas/search")
public ResponseEntity<List<Empresa>> searchEmpresas(@RequestParam String query, @RequestParam String secondaryQuery) {
List<Empresa> searchResult = empresaService.search(query);
public ResponseEntity<List<Empresa>> searchEmpresas(@RequestParam String querySearchBar, @RequestParam String query, @RequestParam String secondaryOption) {
if(secondaryOption.equalsIgnoreCase("Todo")){
List<Empresa> empresas = empresaService.search(querySearchBar);
return ResponseEntity.ok(empresas);
}else{
List<Empresa> searchResultCust = empresaService.searchCustom(querySearchBar,query,secondaryOption);
return ResponseEntity.ok(searchResultCust);
}
return ResponseEntity.ok(searchResult);
}
@GetMapping("/sectores/search")
@ -369,15 +378,27 @@ public class BuscadorController {
return ResponseEntity.ok(sectors);
}
@GetMapping("/contactos/search")
public ResponseEntity<List<Contacto>> searchContactos(@RequestParam String query) {
List<Contacto> contactos = contactosService.search(query);
public ResponseEntity<List<Contacto>> searchContactos(@RequestParam String querySearchBar, @RequestParam String query, @RequestParam String secondaryOption) {
if(secondaryOption.equalsIgnoreCase("Todo")){
List<Contacto> contactos = contactosService.search(querySearchBar);
return ResponseEntity.ok(contactos);
}else{
List<Contacto> searchResultCust = contactosService.searchCustom(querySearchBar,query,secondaryOption);
return ResponseEntity.ok(searchResultCust);
}
}
@GetMapping("/sucursales/search")
public ResponseEntity<List<Sucursal>> searchSucursales(@RequestParam String query) {
List<Sucursal> sucursals = sucursalService.search(query);
public ResponseEntity<List<Sucursal>> searchSucursales(@RequestParam String querySearchBar, @RequestParam String query, @RequestParam String secondaryOption) {
if(secondaryOption.equalsIgnoreCase("Todo")){
List<Sucursal> sucursals = sucursalService.search(querySearchBar);
return ResponseEntity.ok(sucursals);
}else{
List<Sucursal> searchResultCust = sucursalService.searchCustom(querySearchBar,query,secondaryOption);
return ResponseEntity.ok(searchResultCust);
}
}
@GetMapping("/familias/search")
@ -387,18 +408,31 @@ public class BuscadorController {
}
@GetMapping("/ciclos/search")
public ResponseEntity<List<Ciclo>> searchCiclos(@RequestParam String query) {
List<Ciclo> ciclos = cicloService.search(query);
public ResponseEntity<List<Ciclo>> searchCiclos(@RequestParam String querySearchBar, @RequestParam String query, @RequestParam String secondaryOption) {
if(secondaryOption.equalsIgnoreCase("Todo")){
List<Ciclo> ciclos = cicloService.search(querySearchBar);
return ResponseEntity.ok(ciclos);
}else{
List<Ciclo> searchResultCust = cicloService.searchCustom(querySearchBar,query,secondaryOption);
return ResponseEntity.ok(searchResultCust);
}
}
@GetMapping("/skills/search")
public ResponseEntity<List<Skill>> searchSkills(@RequestParam String query) {
List<Skill> ciclos = skillService.search(query);
return ResponseEntity.ok(ciclos);
}
@GetMapping("/alumnos/search")
public ResponseEntity<List<Alumno>> searchAlumnos(@RequestParam String query) {
List<Alumno> alumnos = alumnoService.search(query);
public ResponseEntity<List<Alumno>> searchAlumnos(@RequestParam String querySearchBar, @RequestParam String query, @RequestParam String secondaryOption) {
List<Alumno> alumnos;
if(secondaryOption.equalsIgnoreCase("Todo")){
alumnos = alumnoService.search(querySearchBar);
} else {
alumnos = alumnoService.searchCustom(querySearchBar,query, secondaryOption);
}
for (Alumno alumno : alumnos) {
List<Object[]> skillsData = alumnoRepository.findSkillsByAlumnoId(alumno.getId());
Set<Skill> skills = new HashSet<>();
@ -415,8 +449,13 @@ public class BuscadorController {
@GetMapping("/ofertas/search")
public ResponseEntity<List<Oferta>> searchOfertas(@RequestParam String query) {
List<Oferta> ofertas = ofertasService.search(query);
public ResponseEntity<List<Oferta>> searchOfertas(@RequestParam String querySearchBar, @RequestParam String query, @RequestParam String secondaryOption) {
List<Oferta> ofertas;
if(secondaryOption.equalsIgnoreCase("Todo")){
ofertas = ofertasService.search(querySearchBar);
} else {
ofertas = ofertasService.searchCustom(querySearchBar,query, secondaryOption);
}
for (Oferta oferta : ofertas) {
List<Object[]> skillsData = ofertaRepository.findSkillsByOfertaId(oferta.getId());
Set<Skill> skills = new HashSet<>();

@ -135,6 +135,7 @@ INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (1, 1); -- Jorge with Java
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (2, 10); -- Jane with ...
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (3, 2); -- Robert with Microsoft XL
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (4, 14); -- Emily with Marketing
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (5, 13); -- James with SQL

@ -11,6 +11,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public interface AlumnoRepository extends JpaRepository<Alumno, Long> {
@ -68,8 +69,23 @@ public interface AlumnoRepository extends JpaRepository<Alumno, Long> {
@Query("SELECT a FROM Alumno a WHERE lower(a.ciclo.nombre) IN :ciclos")
Page<Alumno> findAlumnoByCiclos(@Param("ciclos") String ciclos, Pageable pageable);
// @Query(value = "SELECT * FROM alumnos u WHERE MATCH(u.nombre, u.keywords, " +
// "u.apellido, u.apellido2, u.correo, u.correo2, u.nacionalidad, u.genero, u.dni, u.nia ) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
// public ArrayList<Alumno> getAlumnoByKeywordsOrName(String keyword1);
@Query("SELECT a FROM Alumno a WHERE lower(a.nombre) LIKE %:query%")
ArrayList<Alumno> alumnosByNombreCust(@Param("query") String query);
@Query("SELECT a FROM Alumno a WHERE lower(a.apellido) LIKE %:query%")
ArrayList<Alumno> alumnosByApellidoCust(@Param("query") String query);
@Query("SELECT a FROM Alumno a WHERE lower(a.ciclo.nombre) LIKE %:query%")
ArrayList<Alumno> alumnosByCicloCust(@Param("query") String query);
@Query("SELECT a FROM Alumno a WHERE lower(a.keywords) LIKE %:query%")
ArrayList<Alumno> alumnosByKeywordsCust(@Param("query") String query);
@Query("SELECT a FROM Alumno a WHERE lower(a.nia) LIKE %:query%")
ArrayList<Alumno> alumnosByNiaCust(@Param("query") String query);
@Query("SELECT a FROM Alumno a WHERE lower(a.dni) LIKE %:query%")
ArrayList<Alumno> alumnosByDniCust(@Param("query") String query);
}

@ -10,6 +10,7 @@ import org.springframework.data.repository.query.Param;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public interface CicloRepository extends JpaRepository<Ciclo, Long> {
@ -34,4 +35,10 @@ public interface CicloRepository extends JpaRepository<Ciclo, Long> {
@Query("SELECT c FROM Ciclo c WHERE LOWER(c.codigo) LIKE LOWER(CONCAT('%', :query, '%'))")
Page<Ciclo> findCicloByCodigos(@Param("query") String query, Pageable pageable);
@Query("SELECT c FROM Ciclo c WHERE c.familia.nombre LIKE %?1%")
ArrayList<Ciclo> cicloByFamCust(String query);
@Query("SELECT c FROM Ciclo c WHERE c.codigo LIKE %?1%")
ArrayList<Ciclo> cicloByCodCust(String query);
}

@ -10,6 +10,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public interface ContactoRepository extends JpaRepository<Contacto, Long> {
@ -43,4 +44,11 @@ public interface ContactoRepository extends JpaRepository<Contacto, Long> {
@Query("SELECT c FROM Contacto c WHERE lower(c.empresa.nombre) IN :companyNames")
Page<Contacto> findContactosByCompanyNames(@Param("companyNames") List<String> companyNames, Pageable pageable);
@Query("SELECT c FROM Contacto c WHERE c.nombre like %:query%")
ArrayList<Contacto> findContactosByNameCust(String query);
@Query("SELECT c FROM Contacto c WHERE c.empresa.nombre LIKE %:query%")
ArrayList<Contacto> findContactosByEmpresaNameCust(String query);
}

@ -12,6 +12,7 @@ import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public interface EmpressaRepository extends JpaRepository<Empresa, Long>, JpaSpecificationExecutor<Empresa> {
@ -37,7 +38,7 @@ public interface EmpressaRepository extends JpaRepository<Empresa, Long>, JpaSpe
@Query(value = "SELECT * FROM empresas u WHERE u.fk_sector = :sectorId", nativeQuery = true)
Page<Empresa> empresaBySector(@Param("sectorId") Long sectorId, Pageable pageable);
// In EmpressaRepository.java
//TODO: IMPLEMENT LOWERCASE FOR ALL QUERIES
@Query("SELECT e FROM Empresa e WHERE e.sector.nombre like :sectorName")
Page<Empresa> findEmpresasBySectorName(@Param("sectorName") String sectorName, Pageable pageable);
@ -47,15 +48,18 @@ public interface EmpressaRepository extends JpaRepository<Empresa, Long>, JpaSpe
@Query("SELECT e FROM Empresa e WHERE e.keywords LIKE %:query%")
Page<Empresa> findEmpresasByKeywords(String query, PageRequest of);
@Query("SELECT e FROM Empresa e WHERE lower(e.sector.nombre) IN :sectors")
Page<Empresa> findEmpresasBySectorNames(@Param("sectors") List<String> sectors, Pageable pageable);
@Query("SELECT e FROM Empresa e WHERE lower(e.nombre) IN :queryList")
Page<Empresa> findEmpresasByEmpresaNames(List<String> queryList, PageRequest of);
@Query("SELECT e FROM Empresa e WHERE lower(e.keywords) LIKE lower(concat('%', :query, '%'))")
Page<Empresa> findEmpresasByMultKeywords(@Param("query") String query, Pageable pageable);
@Query("SELECT e FROM Empresa e WHERE e.sector.nombre like :sectorName")
ArrayList<Empresa> findEmpresasBySectorNameCust(@Param("sectorName") String sectorName);
@Query("SELECT e FROM Empresa e WHERE e.nombre LIKE %:query%")
ArrayList<Empresa> findEmpresasByEmpresaNameCust(String quer);
@Query("SELECT e FROM Empresa e WHERE e.keywords LIKE %:query%")
ArrayList<Empresa> findEmpresasByKeywordsCust(String query);
// @Query()
// List<Empresa> findByQueryAndSecondaryOption(String query, String secondaryQuery);

@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@ -71,4 +72,22 @@ public interface OfertaRepository extends JpaRepository<Oferta, Long> {
@Query("SELECT o FROM Oferta o JOIN o.skills s WHERE lower(s.nombre) IN :queryList")
Page<Oferta> findOfertaBySkills(@Param("queryList") String queryList, Pageable pageable);
@Query("SELECT o FROM Oferta o WHERE o.nombre LIKE %:query%")
Collection<Oferta> ofertasByNombreCust(@Param("query") String query);
@Query("SELECT o FROM Oferta o WHERE o.sucursal.empresa.nombre LIKE %:query%")
Collection<Oferta> ofertasByEmpresaCust(@Param("query") String query);
@Query("SELECT o FROM Oferta o WHERE o.fecha < :query")
Collection<Oferta> ofertasByFechaAntesCust(@Param("query") Date query);
@Query("SELECT o FROM Oferta o WHERE o.fecha > :query")
Collection<Oferta> ofertasByFechaDespuesCust(@Param("query") Date query);
@Query(value = "SELECT o FROM Oferta o WHERE YEAR(o.fecha) = :query", nativeQuery = true)
Collection<Oferta> ofertasByAnoCust(@Param("query") int query);
@Query("SELECT o FROM Oferta o JOIN o.skills s WHERE s.nombre LIKE %:query%")
Collection<Oferta> ofertasBySkillCust(@Param("query") String query);
}

@ -20,7 +20,7 @@ public interface SucursalRepository extends JpaRepository<Sucursal, Long> {
@Query(value="Select * from sucursales where fk_empressa = ?1", nativeQuery = true)
public List<Sucursal> findByEmpresaId(Long id);
@Query("SELECT s FROM Sucursal s WHERE s.nombre LIKE %:query% OR s.localidad LIKE %:query% OR s.direccion LIKE %:query% OR CAST(s.id AS string) = :query")
@Query("SELECT s FROM Sucursal s WHERE s.nombre LIKE %:query% OR s.localidad LIKE %:query% OR s.direccion LIKE %:query% OR s.empresa.nombre LIKE %:query% OR CAST(s.sedeCentral AS string) = :query")
List<Sucursal> search(@Param("query") String query);
@Query("SELECT s FROM Sucursal s WHERE s.nombre = :nombre")
@ -43,4 +43,13 @@ public interface SucursalRepository extends JpaRepository<Sucursal, Long> {
@Query("SELECT s FROM Sucursal s WHERE s.localidad LIKE %:query%")
Page<Sucursal> findSucursalesByLocalidad(@Param("query") String query, Pageable pageable);
@Query("SELECT s FROM Sucursal s WHERE lower(s.nombre) LIKE %:query%")
ArrayList<Sucursal> sucursalByNameCust(@Param("query") String query);
@Query("SELECT s FROM Sucursal s WHERE lower(s.empresa.nombre) LIKE %:query%")
ArrayList<Sucursal> sucursalByEmpNameCust(String query);
@Query("SELECT s FROM Sucursal s WHERE lower(s.localidad) like %:query%")
ArrayList<Sucursal> sucursalByLoclCust(String query);
}

@ -1,6 +1,7 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Alumno;
import com.example.proyectofinal.models.empresas.Ciclo;
import com.example.proyectofinal.repositories.empresas.AlumnoRepository;
import com.example.proyectofinal.servicios.implemetations.IAlumno;
import org.springframework.beans.factory.annotation.Autowired;
@ -9,6 +10,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
@ -126,4 +128,39 @@ public class AlumnoService implements IAlumno{
return new PageImpl<>(allMatches.subList(start, end), PageRequest.of(pageNum - 1, size), allMatches.size());
}
@Override
public List<Alumno> searchCustom(String querySearchBar, String queryPrime, String secondaryOption) {
String[] queryMultiWord = queryPrime.split(",");
queryMultiWord = Arrays.stream(queryMultiWord).map(String::trim).toArray(String[]::new);
ArrayList<Alumno> listEmpPrime = new ArrayList<>();
ArrayList<Alumno> listEmpSec = new ArrayList<>();
if (!querySearchBar.isEmpty()) {
for (String query : queryMultiWord) {
query = query.trim().toLowerCase();
if (secondaryOption.equals("Nombre")) {
listEmpPrime.addAll(alumnoRepository.alumnosByNombreCust(query));
} else if (secondaryOption.equals("Apellido")) {
listEmpPrime.addAll(alumnoRepository.alumnosByApellidoCust(query));
} else if (secondaryOption.equals("Ciclo")) {
System.out.println("TEST QUERY: " + query);
listEmpPrime.addAll(alumnoRepository.alumnosByCicloCust(query));
} else if (secondaryOption.equals("Keywords")) {
listEmpPrime.addAll(alumnoRepository.alumnosByKeywordsCust(query));
} else if (secondaryOption.equals("Nia")) {
listEmpPrime.addAll(alumnoRepository.alumnosByNiaCust(query));
} else if (secondaryOption.equals("Dni")) {
listEmpPrime.addAll(alumnoRepository.alumnosByDniCust(query));
}
}
}
listEmpSec = (ArrayList<Alumno>) alumnoRepository.search(querySearchBar);
listEmpPrime.retainAll(listEmpSec);
return listEmpPrime;
}
}

@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
@ -124,4 +125,24 @@ public class CicloService implements ICiclos {
return new PageImpl<>(allMatches.subList(start, end), PageRequest.of(pageNum - 1, size), allMatches.size());
}
@Override
public List<Ciclo> searchCustom(String querySearchBar, String queryPrime, String secondaryOption) {
String[] queryMultiWord = queryPrime.split(",");
queryMultiWord = Arrays.stream(queryMultiWord).map(String::trim).toArray(String[]::new);
ArrayList<Ciclo> listEmpPrime = new ArrayList<>();
ArrayList<Ciclo> listEmpSec = new ArrayList<>();
if (!querySearchBar.isEmpty()) {
for (String query : queryMultiWord) {
query = query.trim().toLowerCase();
if (secondaryOption.equals("Familia")) {
listEmpPrime.addAll(cicloRepository.cicloByFamCust(query));
} else if (secondaryOption.equals("Codigo")) {
listEmpPrime.addAll(cicloRepository.cicloByCodCust(query));
}
}
}
listEmpSec = (ArrayList<Ciclo>) cicloRepository.search(querySearchBar);
listEmpPrime.retainAll(listEmpSec);
return listEmpPrime;
}
}

@ -12,6 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -126,4 +127,30 @@ public class ContactosService implements IContactos {
int end = Math.min((start + PageRequest.of(pageNum - 1, size).getPageSize()), allMatches.size());
return new PageImpl<>(allMatches.subList(start, end), PageRequest.of(pageNum - 1, size), allMatches.size());
}
@Override
public List<Contacto> searchCustom(String querySearchBar, String queryPrime, String secondaryOption) {
// See if the query is a single word or multiple words
String[] queryMultiWord = queryPrime.split(",");
queryMultiWord = Arrays.stream(queryMultiWord).map(String::trim).toArray(String[]::new);
// Create the ArrayLists to store the results
ArrayList<Contacto> listContactoPrime = new ArrayList<>();
ArrayList<Contacto> listContactoSec = new ArrayList<>();
// Confirm if the search bar is empty
if (!querySearchBar.isEmpty()) {
for (String query : queryMultiWord) {
query = query.trim().toLowerCase();
if (secondaryOption.equals("Nombre")) {
listContactoPrime.addAll(contactoRepository.findContactosByNameCust(query));
} else if (secondaryOption.equals("Empresa")) {
listContactoPrime.addAll(contactoRepository.findContactosByEmpresaNameCust(query));
}
}
}
System.out.println("listContactoPrime: TEST" + listContactoPrime);
listContactoSec = (ArrayList<Contacto>) contactoRepository.search(querySearchBar);
System.out.println("listContactoSec: TEST" + listContactoSec);
listContactoPrime.retainAll(listContactoSec);
return listContactoPrime;
}
}

@ -129,10 +129,32 @@ public class EmpresaService implements IEmpresa {
return new PageImpl<>(allMatches.subList(start, end), PageRequest.of(pageNum - 1, size), allMatches.size());
}
// @Override
// public List<Empresa> getEmpresasByQueryAndSecondaryOption(String query, String secondaryQuery) {
// return empresaRepository.findByQueryAndSecondaryOption(query, secondaryQuery);
// }
@Override
public List<Empresa> searchCustom(String querySearchBar, String queryPrime,String secondaryOption) {
//See if the query is a single word or multiple words
String[] queryMultiWord = queryPrime.split(",");
queryMultiWord = Arrays.stream(queryMultiWord).map(String::trim).toArray(String[]::new);
//Create the ArrayLists to store the results
ArrayList<Empresa> listEmpPrime = new ArrayList<>();
ArrayList<Empresa> listEmpSec = new ArrayList<>();
//Confirm if the search bar is empty
if (!querySearchBar.isEmpty()) {
for (String query : queryMultiWord) {
query = query.trim().toLowerCase();
if (secondaryOption.equals("Nombre")) {
listEmpPrime.addAll(empresaRepository.findEmpresasByEmpresaNameCust(query));
} else if (secondaryOption.equals("Sector")) {
listEmpPrime.addAll(empresaRepository.findEmpresasBySectorNameCust(query));
} else if (secondaryOption.equals("Keywords")) {
listEmpPrime.addAll(empresaRepository.findEmpresasByKeywordsCust(query));
}
}
}
listEmpSec = (ArrayList<Empresa>) empresaRepository.search(querySearchBar);
//Retain the common elements between the two lists
//In this case, the common elements are the companies that match the search bar and the query
listEmpPrime.retainAll(listEmpSec);
return listEmpPrime;
}
}

@ -1,5 +1,6 @@
package com.example.proyectofinal.servicios;
import com.example.proyectofinal.models.empresas.Ciclo;
import com.example.proyectofinal.models.empresas.Oferta;
import com.example.proyectofinal.models.empresas.Skill;
import com.example.proyectofinal.models.empresas.Sucursal;
@ -160,4 +161,27 @@ public class OfertaService implements IOferta {
}
}
@Override
public List<Oferta> searchCustom(String querySearchBar, String queryPrime, String secondaryOption) {
String[] queryMultiWord = queryPrime.split(",");
queryMultiWord = Arrays.stream(queryMultiWord).map(String::trim).toArray(String[]::new);
ArrayList<Oferta> listEmpPrime = new ArrayList<>();
ArrayList<Oferta> listEmpSec = new ArrayList<>();
if (!querySearchBar.isEmpty()) {
for (String query : queryMultiWord) {
query = query.trim().toLowerCase();
if (secondaryOption.equals("Nombre")) {
listEmpPrime.addAll(ofertaRepository.ofertasByNombreCust(query));
} else if (secondaryOption.equals("Empresa")) {
listEmpPrime.addAll(ofertaRepository.ofertasByEmpresaCust(query));
} else if (secondaryOption.equals("Skill")) {
listEmpPrime.addAll(ofertaRepository.ofertasBySkillCust(query));
}
}
}
listEmpSec = (ArrayList<Oferta>) ofertaRepository.search(querySearchBar);
listEmpPrime.retainAll(listEmpSec);
return listEmpPrime;
}
}

@ -12,6 +12,7 @@ import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Service
public class SucursalService implements ISucursal {
@ -111,11 +112,31 @@ public class SucursalService implements ISucursal {
allMatches.addAll(page.getContent());
}
}
// Convert the list of all matches to a page
System.out.println("TEST TEST TEST size"+allMatches.size());
System.out.println("TEST TEST TEST " + allMatches);
int start = (int) PageRequest.of(pageNum - 1, size).getOffset();
int end = Math.min((start + PageRequest.of(pageNum - 1, size).getPageSize()), allMatches.size());
return new PageImpl<>(allMatches.subList(start, end), PageRequest.of(pageNum - 1, size), allMatches.size());
}
@Override
public List<Sucursal> searchCustom(String querySearchBar, String queryPrime,String secondaryOption) {
String[] queryMultiWord = queryPrime.split(",");
queryMultiWord = Arrays.stream(queryMultiWord).map(String::trim).toArray(String[]::new);
ArrayList<Sucursal> listEmpPrime = new ArrayList<>();
ArrayList<Sucursal> listEmpSec = new ArrayList<>();
if (!querySearchBar.isEmpty()) {
for (String query : queryMultiWord) {
query = query.trim().toLowerCase();
if (secondaryOption.equals("Nombre")) {
listEmpPrime.addAll(sucursalRepository.sucursalByNameCust(query));
} else if (secondaryOption.equals("Empresa")) {
listEmpPrime.addAll(sucursalRepository.sucursalByEmpNameCust(query));
} else if (secondaryOption.equals("Localidad")) {
listEmpPrime.addAll(sucursalRepository.sucursalByLoclCust(query));
}
}
}
listEmpSec = (ArrayList<Sucursal>) sucursalRepository.search(querySearchBar);
listEmpPrime.retainAll(listEmpSec);
return listEmpPrime;
}
}

@ -25,4 +25,5 @@ public interface IAlumno extends IPagination<Alumno> {
Page<Alumno> getPage(int pageNum, int size, String sortField, String sortDir, String query, String secondaryOption);
List<Alumno> searchCustom(String querySearchBar, String query, String secondaryOption);
}

@ -27,5 +27,7 @@ public interface ICiclos extends IPagination<Ciclo> {
void deleteByFamiliaId(Long id);
Page<Ciclo> getPage(int pageNum, int size, String sortField, String sortDir, String query, String secondaryOption);
List<Ciclo> searchCustom(String querySearchBar, String query, String secondaryOption);
}

@ -25,4 +25,6 @@ public interface IContactos extends IPagination<Contacto> {
Contacto exists(Contacto contacto);
Page<Contacto> getPage(int pageNum, int size, String sortField, String sortDir, String query, String secondaryOption);
List<Contacto> searchCustom(String querySearchBar, String query, String secondaryOption);
}

@ -26,5 +26,7 @@ public interface IEmpresa extends IPagination<Empresa> {
Page<Empresa> getPageMultiWord(int pageNum, int size, String sortField, String sortDir, List<String> queryMultiWord, String secondaryOption);
List<Empresa> searchCustom(String querySearchBar, String query,String secondaryOption);
// List<Empresa> getEmpresasByQueryAndSecondaryOption(String query, String secondaryQuery);
}

@ -26,4 +26,6 @@ public interface IOferta extends IPagination<Oferta> {
void deleteByCicloId(Long id);
Page<Oferta> getPage(int pageNum, int size, String sortField, String sortDir, String query, String secondaryOption) throws ParseException;
List<Oferta> searchCustom(String querySearchBar, String query, String secondaryOption);
}

@ -25,4 +25,6 @@ public interface ISucursal extends IPagination<Sucursal> {
Sucursal exists(Sucursal sucursal);
Page<Sucursal> getPage(int pageNum, int size, String sortField, String sortDir, String query, String secondaryOption);
List<Sucursal> searchCustom(String querySearchBar, String query, String secondaryOption);
}

@ -1,51 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css">
<link rel="stylesheet" type="text/css" th:href="@{/style.css}">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">
<script type="text/javascript" src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
<meta charset="UTF-8">
<title>Title</title>
<style>
</style>
</head>
<body>
<h1>Listado de Sucursales<a href="/logout" class="logout-button"><i class="fas fa-door-open"></i></a></h1>
<div class="table">
<table class ="table table-hover table-responsive-xl">
<thead class="thread-light">
<tr>
<th>Id</th>
<th>Nombre</th>
<th>Localidad</th>
<th>Dirección</th>
<th>SedeCentral</th>
<th>Empressa</th>
</tr>
</thead>
<tbody>
<tr class="cell" th:each="sucursal :${sucursales}">
<td>[[${sucursal.id}]]</td>
<td>[[${sucursal.nombre}]]</td>
<td>[[${sucursal.localidad}]]</td>
<td>[[${sucursal.direccion}]]</td>
<td>[[${sucursal.sedeCentral}]]</td>
<td>[[${sucursal.empresa.nombre}]]</td>
</tr>
</tbody>
</table>
</div>
<button onclick="goBack()">Atras</button>
<script>
function goBack() {
window.history.back();
}
</script>
</body>
</html>
listEmpPrime: TEST[Empresa(id=4, nombre=Keytara, cif=123456789W4, correo=keytara@example.com, telefono=12345678904,
keywords=programador, sector=Sector(id=4, nombre=Musica)),
Empresa(id=9, nombre=FinTrack, cif=123456789W9, correo=fintrack@example.com, telefono=12345678909,
keywords=finance,investment, sector=Sector(id=4, nombre=Musica)),
Empresa(id=14, nombre=WealthTrack, cif=123456789W9, correo=wealthtrack@example.com, telefono=12345678909,
keywords=finance,investment, sector=Sector(id=4, nombre=Musica))]
listEmpSec: TEST[]

@ -101,7 +101,7 @@
}
// Log the value of the search bar to the console
console.log("Query: " + searchBar.value);
//console.log("Query: " + searchBar.value);
});
document.getElementById('searchForm').addEventListener('submit', function() {
var searchOption = document.getElementById('searchOption').value;
@ -178,8 +178,8 @@
options = [];
}
console.log("Primary dropdown value: " + primaryDropdown.value); // Add this line
console.log("Options to add to secondary dropdown: " + options); // Add this line
//console.log("Primary dropdown value: " + primaryDropdown.value); // Add this line
//console.log("Options to add to secondary dropdown: " + options); // Add this line
// Add the new options to the secondary dropdown
for (var i = 0; i < options.length; i++) {
@ -261,7 +261,7 @@
}
// Log the query to the console
console.log("Query SENT TEST: " + datePicker.value);
//console.log("Query SENT TEST: " + datePicker.value);
// Update the value of the hidden input field
document.getElementById('hiddenSecondaryOption').value = secondaryOption;

@ -154,7 +154,7 @@
</div>
<script src="/orderTable.js"></script>
<script>
<script th:inline="javascript">
function goBack() {
window.history.back();
}
@ -165,12 +165,12 @@
var isSearchBarUsed = false;
$table.on('click', '.edit-icon', function(event) {
console.log("Edit icon clicked");
//console.log("Edit icon clicked");
handleEdit(event);
});
$table.on('click', '.delete-icon', function(event) {
console.log("Delete icon clicked");
//console.log("Delete icon clicked");
handleDelete(event);
});
@ -178,13 +178,13 @@
console.log("handleEdit function called");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
console.log("Row ID: " + rowId);
// console.log("Row ID: " + rowId);
window.location = "/admin/alumno/update/" + rowId;
}
function handleDelete(event) {
console.log("handleDelete function called");
console.log("Delete icon clicked");
//console.log("handleDelete function called");
//console.log("Delete icon clicked");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
var modal = document.getElementById("modalDelete");
@ -216,11 +216,11 @@
}
$myInput.on('input', function() {
var query = document.querySelector('#myInput').value;
var querySearchBar = document.querySelector('#myInput').value;
var paginationControls = document.querySelector('#paginationControls');
var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') {
if (querySearchBar === '') {
isSearchBarUsed = false;
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
@ -232,7 +232,13 @@
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/alumnos/search?query=' + query)
/*<![CDATA[*/
var query = /*[[${query}]]*/ 'defaultQuery';
var secondaryOption = /*[[${secondaryOption}]]*/ 'defaultSecondaryOption';
/* rest of your JavaScript code */
/*]]>*/
fetch('/buscador/alumnos/search?querySearchBar=' + querySearchBar + '&query=' + query + '&secondaryOption=' + secondaryOption)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');
@ -267,12 +273,12 @@
document.querySelectorAll('.edit-icon').forEach(function(icon) {
icon.removeEventListener('click', handleEdit);
icon.addEventListener('click', handleEdit);
console.log("Edit icon event listener attached");
//console.log("Edit icon event listener attached");
});
document.querySelectorAll('.delete-icon').forEach(function(icon) {
icon.removeEventListener('click', handleDelete);
icon.addEventListener('click', handleDelete);
console.log("Delete icon event listener attached");
//console.log("Delete icon event listener attached");
});
table.style.pointerEvents = 'auto';
@ -303,7 +309,7 @@
observer.observe(document.querySelector('#table tbody'), { childList: true });
document.getElementById('create-icon').addEventListener('click', function() {
console.log("Create button clicked : TEST");
//console.log("Create button clicked : TEST");
window.location = "/admin/alumno/create";
});

@ -91,7 +91,7 @@
</div>
<script src="/orderTable.js"></script>
<script>
<script th:inline="javascript">
function goBack() {
window.history.back();
}
@ -153,11 +153,11 @@
}
$myInput.on('input', function() {
var query = document.querySelector('#myInput').value;
var querySearchBar = document.querySelector('#myInput').value;
var paginationControls = document.querySelector('#paginationControls');
var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') {
if (querySearchBar === '') {
isSearchBarUsed = false;
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
@ -169,7 +169,13 @@
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/ciclos/search?query=' + query)
/*<![CDATA[*/
var query = /*[[${query}]]*/ 'defaultQuery';
var secondaryOption = /*[[${secondaryOption}]]*/ 'defaultSecondaryOption';
/* rest of your JavaScript code */
/*]]>*/
fetch('/buscador/ciclos/search?querySearchBar=' + querySearchBar + '&query=' + query + '&secondaryOption=' + secondaryOption)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');

@ -111,7 +111,7 @@
</div>
<script src="/orderTable.js"></script>
<script>
<script th:inline="javascript">
function goBack() {
window.history.back();
}
@ -122,26 +122,26 @@
var isSearchBarUsed = false;
$table.on('click', '.edit-icon', function(event) {
console.log("Edit icon clicked");
//console.log("Edit icon clicked");
handleEdit(event);
});
$table.on('click', '.delete-icon', function(event) {
console.log("Delete icon clicked");
//console.log("Delete icon clicked");
handleDelete(event);
});
function handleEdit(event) {
console.log("handleEdit function called");
//console.log("handleEdit function called");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
console.log("Row ID: " + rowId);
//console.log("Row ID: " + rowId);
window.location = "/admin/contacto/update/" + rowId;
}
function handleDelete(event) {
console.log("handleDelete function called");
console.log("Delete icon clicked");
// console.log("handleDelete function called");
//console.log("Delete icon clicked");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
var modal = document.getElementById("modalDelete");
@ -173,11 +173,11 @@
}
$myInput.on('input', function() {
var query = document.querySelector('#myInput').value;
var querySearchBar = document.querySelector('#myInput').value;
var paginationControls = document.querySelector('#paginationControls');
var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') {
if (querySearchBar == '') {
isSearchBarUsed = false;
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
@ -189,7 +189,14 @@
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/contactos/search?query=' + query)
/*<![CDATA[*/
var query = /*[[${query}]]*/ 'defaultQuery';
var secondaryOption = /*[[${secondaryOption}]]*/ 'defaultSecondaryOption';
/* rest of your JavaScript code */
/*]]>*/
fetch('/buscador/contactos/search?querySearchBar=' + querySearchBar+ '&query=' + query + '&secondaryOption=' + secondaryOption)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');

@ -110,7 +110,7 @@
</div>
</div>
<script src="/orderTable.js"></script>
<script>
<script th:inline="javascript">
function goBack() {
window.history.back();
}
@ -122,12 +122,12 @@
var isSearchBarUsed = false;
$table.on('click', '.edit-icon', function (event) {
console.log("Edit icon clicked");
//console.log("Edit icon clicked");
handleEdit(event);
});
$table.on('click', '.delete-icon', function (event) {
console.log("Delete icon clicked");
//console.log("Delete icon clicked");
handleDelete(event);
});
@ -135,13 +135,13 @@
console.log("handleEdit function called");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
console.log("Row ID: " + rowId);
//console.log("Row ID: " + rowId);
window.location = "/admin/empresa/update/" + rowId;
}
function handleDelete(event) {
console.log("handleDelete function called");
console.log("Delete icon clicked");
//console.log("handleDelete function called");
//console.log("Delete icon clicked");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
var modal = document.getElementById("modalDelete");
@ -174,12 +174,11 @@
$myInput.on('input', function() {
var query = document.querySelector('#myInput').value;
var querySearchBar = document.querySelector('#myInput').value;
var paginationControls = document.querySelector('#paginationControls');
var entriesCountDropdown = document.querySelector('#entriesCount');
var empresasData = document.querySelector('#empresasData').value; // Retrieve the serialized empresas
if (query == '') {
if (querySearchBar === '') {
isSearchBarUsed = false;
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
@ -191,7 +190,16 @@
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/empresas/search?query=' + query)
/*<![CDATA[*/
var query = /*[[${query}]]*/ 'defaultQuery';
var secondaryOption = /*[[${secondaryOption}]]*/ 'defaultSecondaryOption';
/* rest of your JavaScript code */
/*]]>*/
//console.log("Query: " + query);
//console.log("Secondary Option: " + secondaryOption);
fetch('/buscador/empresas/search?querySearchBar=' + querySearchBar + '&query=' + query + '&secondaryOption=' + secondaryOption)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');
@ -217,12 +225,12 @@
document.querySelectorAll('.edit-icon').forEach(function(icon) {
icon.removeEventListener('click', handleEdit);
icon.addEventListener('click', handleEdit);
console.log("Edit icon event listener attached");
//console.log("Edit icon event listener attached");
});
document.querySelectorAll('.delete-icon').forEach(function(icon) {
icon.removeEventListener('click', handleDelete);
icon.addEventListener('click', handleDelete);
console.log("Delete icon event listener attached");
//console.log("Delete icon event listener attached");
});
table.style.pointerEvents = 'auto';
@ -249,7 +257,7 @@
observer.observe(document.querySelector('#table tbody'), {childList: true});
document.getElementById('create-icon').addEventListener('click', function () {
console.log("Create button clicked : TEST");
//console.log("Create button clicked : TEST");
window.location = "/admin/empresa/create";
});

@ -110,7 +110,7 @@
</div>
<script src="/orderTable.js"></script>
<script>
<script th:inline="javascript">
function goBack() {
window.history.back();
}
@ -121,26 +121,26 @@
var isSearchBarUsed = false;
$table.on('click', '.edit-icon', function(event) {
console.log("Edit icon clicked");
//console.log("Edit icon clicked");
handleEdit(event);
});
$table.on('click', '.delete-icon', function(event) {
console.log("Delete icon clicked");
//console.log("Delete icon clicked");
handleDelete(event);
});
function handleEdit(event) {
console.log("handleEdit function called");
//console.log("handleEdit function called");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
console.log("Row ID: " + rowId);
//console.log("Row ID: " + rowId);
window.location = "/admin/oferta/update/" + rowId;
}
function handleDelete(event) {
console.log("handleDelete function called");
console.log("Delete icon clicked");
//console.log("handleDelete function called");
//console.log("Delete icon clicked");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
var modal = document.getElementById("modalDelete");
@ -172,11 +172,18 @@
}
$myInput.on('input', function() {
var query = document.querySelector('#myInput').value;
var querySearchBar = document.querySelector('#myInput').value;
var paginationControls = document.querySelector('#paginationControls');
var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') {
/*<![CDATA[*/
var query = /*[[${query}]]*/ 'defaultQuery';
var secondaryOption = /*[[${secondaryOption}]]*/ 'defaultSecondaryOption';
/* rest of your JavaScript code */
/*]]>*/
if (querySearchBar === '') {
isSearchBarUsed = false;
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
@ -188,7 +195,7 @@
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/ofertas/search?query=' + query)
fetch('/buscador/ofertas/search?querySearchBar=' + querySearchBar + '&query=' + query + '&secondaryOption=' + secondaryOption)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');
@ -216,12 +223,12 @@
document.querySelectorAll('.edit-icon').forEach(function(icon) {
icon.removeEventListener('click', handleEdit);
icon.addEventListener('click', handleEdit);
console.log("Edit icon event listener attached");
//console.log("Edit icon event listener attached");
});
document.querySelectorAll('.delete-icon').forEach(function(icon) {
icon.removeEventListener('click', handleDelete);
icon.addEventListener('click', handleDelete);
console.log("Delete icon event listener attached");
//console.log("Delete icon event listener attached");
});
table.style.pointerEvents = 'auto';
@ -252,7 +259,7 @@
observer.observe(document.querySelector('#table tbody'), { childList: true });
document.getElementById('create-icon').addEventListener('click', function() {
console.log("Create button clicked : TEST");
//console.log("Create button clicked : TEST");
window.location = "/admin/oferta/create";
});

@ -104,7 +104,7 @@
</div>
<script src="/orderTable.js"></script>
<script>
<script th:inline="javascript">
function goBack() {
window.history.back();
}
@ -115,26 +115,26 @@
var isSearchBarUsed = false;
$table.on('click', '.edit-icon', function(event) {
console.log("Edit icon clicked");
//console.log("Edit icon clicked");
handleEdit(event);
});
$table.on('click', '.delete-icon', function(event) {
console.log("Delete icon clicked");
//console.log("Delete icon clicked");
handleDelete(event);
});
function handleEdit(event) {
console.log("handleEdit function called");
// console.log("handleEdit function called");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
console.log("Row ID: " + rowId);
// console.log("Row ID: " + rowId);
window.location = "/admin/sucursal/update/" + rowId;
}
function handleDelete(event) {
console.log("handleDelete function called");
console.log("Delete icon clicked");
//console.log("handleDelete function called");
//console.log("Delete icon clicked");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
var modal = document.getElementById("modalDelete");
@ -166,11 +166,11 @@
}
$myInput.on('input', function() {
var query = document.querySelector('#myInput').value;
var querySearchBar = document.querySelector('#myInput').value;
var paginationControls = document.querySelector('#paginationControls');
var entriesCountDropdown = document.querySelector('#entriesCount');
if (query == '') {
if (querySearchBar == '') {
isSearchBarUsed = false;
paginationControls.style.display = '';
entriesCountDropdown.style.display = '';
@ -182,7 +182,13 @@
entriesCountDropdown.style.display = 'none';
table.style.pointerEvents = 'none';
fetch('/buscador/sucursales/search?query=' + query)
/*<![CDATA[*/
var query = /*[[${query}]]*/ 'defaultQuery';
var secondaryOption = /*[[${secondaryOption}]]*/ 'defaultSecondaryOption';
/* rest of your JavaScript code */
/*]]>*/
fetch('/buscador/sucursales/search?querySearchBar=' + querySearchBar + '&query=' + query + '&secondaryOption=' + secondaryOption)
.then(response => response.json())
.then(data => {
var tableBody = document.querySelector('#table tbody');
@ -207,12 +213,12 @@
document.querySelectorAll('.edit-icon').forEach(function(icon) {
icon.removeEventListener('click', handleEdit);
icon.addEventListener('click', handleEdit);
console.log("Edit icon event listener attached");
//console.log("Edit icon event listener attached");
});
document.querySelectorAll('.delete-icon').forEach(function(icon) {
icon.removeEventListener('click', handleDelete);
icon.addEventListener('click', handleDelete);
console.log("Delete icon event listener attached");
//console.log("Delete icon event listener attached");
});
table.style.pointerEvents = 'auto';
@ -243,7 +249,7 @@
observer.observe(document.querySelector('#table tbody'), { childList: true });
document.getElementById('create-icon').addEventListener('click', function() {
console.log("Create button clicked : TEST");
//console.log("Create button clicked : TEST");
window.location = "/admin/sucursal/create";
});

Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.