This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
204 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
backend/src/main/java/com/senac/gestaocurso/enterprise/BooleanBuilderUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package com.senac.gestaocurso.enterprise; | ||
|
||
import com.querydsl.core.BooleanBuilder; | ||
import com.querydsl.core.types.Expression; | ||
import com.querydsl.core.types.dsl.Expressions; | ||
import com.querydsl.core.types.dsl.PathBuilder; | ||
|
||
|
||
import java.lang.reflect.Field; | ||
import java.time.LocalDate; | ||
|
||
|
||
public class BooleanBuilderUtil { | ||
|
||
|
||
public static BooleanBuilder buildPredicateFromFilter(String filter, Class<?> classes) { | ||
if (filter == null || filter.isEmpty()) { | ||
return new BooleanBuilder(); | ||
} | ||
|
||
|
||
BooleanBuilder predicate = new BooleanBuilder(); | ||
String[] parts = filter.split("\\+"); | ||
|
||
|
||
if (parts.length == 3) { | ||
try { | ||
Field field = getFieldRecursively(classes, parts[0]); | ||
field.setAccessible(true); | ||
Class<?> fieldType = field.getType(); | ||
PathBuilder<?> fieldPath = new PathBuilder<>(fieldType, field.getName()); | ||
|
||
|
||
switch (parts[1].toLowerCase()) { | ||
case "equal": | ||
predicate.and(fieldPath.eq(Expressions.constant(parts[2]))); | ||
break; | ||
case "notEqual": | ||
predicate.and(fieldPath.ne(Expressions.constant(parts[2]))); | ||
break; | ||
case "greater": | ||
predicate.and(Expressions.booleanTemplate("{0} > {1}", fieldPath, getType(fieldType, parts[2]))); | ||
break; | ||
case "lesser": | ||
predicate.and(Expressions.booleanTemplate("{0} < {1}", fieldPath, getType(fieldType, parts[2]))); | ||
break; | ||
case "greaterequal": | ||
predicate.and(Expressions.booleanTemplate("{0} >= {1}", fieldPath, getType(fieldType, parts[2]))); | ||
break; | ||
case "lesserequal": | ||
predicate.and(Expressions.booleanTemplate("{0} <= {1}", fieldPath, getType(fieldType, parts[2]))); | ||
break; | ||
case "like": | ||
predicate.and(Expressions.booleanTemplate("{0} like '%'||{1}||'%'", fieldPath, Expressions.constant(parts[2]))); | ||
break; | ||
default: | ||
throw new RuntimeException("Operador não suportado"); | ||
} | ||
|
||
|
||
} catch (NoSuchFieldException e) { | ||
throw new RuntimeException("Campo não encontrado"); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Acesso ilegal ao campo"); | ||
} | ||
} | ||
|
||
|
||
if (parts.length == 4) { | ||
try { | ||
Field field = getFieldRecursively(classes, parts[0]); | ||
field.setAccessible(true); | ||
Class<?> fieldType = field.getType(); | ||
PathBuilder<?> fieldPath = new PathBuilder<>(fieldType, field.getName()); | ||
|
||
|
||
switch (parts[1].toLowerCase()) { | ||
case "between": | ||
predicate.and(Expressions.booleanTemplate("{0} >= {1} AND {0} <= {2}", fieldPath, getType(fieldType, parts[2]), getType(fieldType, parts[3]))); | ||
break; | ||
default: | ||
throw new RuntimeException("Operador não suportado"); | ||
} | ||
|
||
|
||
} catch (NoSuchFieldException e) { | ||
throw new RuntimeException("Campo não encontrado"); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Acesso ilegal ao campo"); | ||
} | ||
} | ||
|
||
|
||
return predicate; | ||
} | ||
|
||
|
||
|
||
|
||
public static Expression getType(Class<?> fieldType, String part) { | ||
if (fieldType == Integer.class || fieldType == int.class) { | ||
return Expressions.constant(Integer.parseInt(part)); | ||
} else if (fieldType == Double.class || fieldType == double.class) { | ||
return Expressions.constant(Double.parseDouble(part)); | ||
} else if (fieldType == LocalDate.class) { | ||
return Expressions.constant(LocalDate.parse(part)); | ||
} | ||
return Expressions.constant(part); | ||
} | ||
|
||
|
||
private static Field getFieldRecursively(Class<?> classes, String fieldName) throws NoSuchFieldException { | ||
try { | ||
return classes.getDeclaredField(fieldName); | ||
} catch (NoSuchFieldException e) { | ||
if (classes.getSuperclass() != null) { | ||
return getFieldRecursively(classes.getSuperclass(), fieldName); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/com/senac/gestaocurso/enterprise/CustomQuerydslPredicateExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.senac.gestaocurso.enterprise; | ||
|
||
import com.querydsl.core.BooleanBuilder; | ||
import com.querydsl.core.types.Predicate; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.querydsl.QuerydslPredicateExecutor; | ||
|
||
|
||
import java.util.List; | ||
|
||
|
||
public interface CustomQuerydslPredicateExecutor<T> extends QuerydslPredicateExecutor<T> { | ||
|
||
|
||
@Override | ||
List<T> findAll(Predicate predicate); | ||
|
||
|
||
default Page<T> findAll(String filter, Class<T> entityType, Pageable pageable) { | ||
BooleanBuilder booleanBuilder = BooleanBuilderUtil.buildPredicateFromFilter(filter, entityType); | ||
return this.findAll(booleanBuilder, pageable); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/AulaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Aula; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface AulaRepository extends JpaRepository<Aula, Long> { | ||
public interface AulaRepository extends JpaRepository<Aula, Long>, CustomQuerydslPredicateExecutor<Aula> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/AvaliacaoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Avaliacao; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface AvaliacaoRepository extends JpaRepository<Avaliacao, Long> { | ||
public interface AvaliacaoRepository extends JpaRepository<Avaliacao, Long>, CustomQuerydslPredicateExecutor<Avaliacao> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/CargoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Cargo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface CargoRepository extends JpaRepository<Cargo, Long> { | ||
public interface CargoRepository extends JpaRepository<Cargo, Long>, CustomQuerydslPredicateExecutor<Cargo> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/CertifcacoesRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Certificacoes; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface CertifcacoesRepository extends JpaRepository<Certificacoes, Long>{ | ||
public interface CertifcacoesRepository extends JpaRepository<Certificacoes, Long>, CustomQuerydslPredicateExecutor<Certificacoes> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/CursoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Curso; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface CursoRepository extends JpaRepository<Curso, Long> { | ||
public interface CursoRepository extends JpaRepository<Curso, Long>, CustomQuerydslPredicateExecutor<Curso> { | ||
|
||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/DadosBancariosRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.DadosBancarios; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface DadosBancariosRepository extends JpaRepository <DadosBancarios, Long> { | ||
public interface DadosBancariosRepository extends JpaRepository <DadosBancarios, Long>, CustomQuerydslPredicateExecutor<DadosBancarios> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/DependentesRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Dependentes; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface DependentesRepository extends JpaRepository<Dependentes, Long> { | ||
public interface DependentesRepository extends JpaRepository<Dependentes, Long>, CustomQuerydslPredicateExecutor<Dependentes> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/ExpAnteriorRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.ExpAnterior; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ExpAnteriorRepository extends JpaRepository<ExpAnterior, Long> { | ||
public interface ExpAnteriorRepository extends JpaRepository<ExpAnterior, Long>, CustomQuerydslPredicateExecutor<ExpAnterior> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/FiliacaoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Filiacao; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface FiliacaoRepository extends JpaRepository<Filiacao, Long> { | ||
public interface FiliacaoRepository extends JpaRepository<Filiacao, Long>, CustomQuerydslPredicateExecutor<Filiacao> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/FrequenciaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Frequencia; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface FrequenciaRepository extends JpaRepository<Frequencia, Long> { | ||
public interface FrequenciaRepository extends JpaRepository<Frequencia, Long>, CustomQuerydslPredicateExecutor<Frequencia> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/FuncionarioRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/InscricaoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Inscricao; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public interface InscricaoRepository extends JpaRepository<Inscricao, Long> { | ||
public interface InscricaoRepository extends JpaRepository<Inscricao, Long>, CustomQuerydslPredicateExecutor<Inscricao> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/MateriaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Materia; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface MateriaRepository extends JpaRepository<Materia, Long> { | ||
public interface MateriaRepository extends JpaRepository<Materia, Long>, CustomQuerydslPredicateExecutor<Materia> { | ||
} |
3 changes: 2 additions & 1 deletion
3
backend/src/main/java/com/senac/gestaocurso/repository/TurmaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package com.senac.gestaocurso.repository; | ||
|
||
import com.senac.gestaocurso.enterprise.CustomQuerydslPredicateExecutor; | ||
import com.senac.gestaocurso.models.Turma; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface TurmaRepository extends JpaRepository<Turma, Long> { | ||
public interface TurmaRepository extends JpaRepository<Turma, Long>, CustomQuerydslPredicateExecutor<Turma> { | ||
} |