Skip to content

Commit

Permalink
Move utilities to 'util' package, cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-muller666 committed Apr 1, 2024
1 parent 0d0b4f1 commit 08b62db
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 41 deletions.
7 changes: 3 additions & 4 deletions src/main/kotlin/no/acntech/kollectiveq/Filter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package no.acntech.kollectiveq
import no.acntech.kollectiveq.antlr4.FilterGrammarBaseVisitor
import no.acntech.kollectiveq.antlr4.FilterGrammarLexer
import no.acntech.kollectiveq.antlr4.FilterGrammarParser
import no.acntech.kollectiveq.text.DetailedParseException
import no.acntech.kollectiveq.text.EQ
import no.acntech.kollectiveq.time.FlexibleInstantParser
import no.acntech.kollectiveq.util.text.EQ
import no.acntech.kollectiveq.util.time.DetailedParseException
import no.acntech.kollectiveq.util.time.FlexibleInstantParser
import org.antlr.v4.runtime.CharStreams
import org.antlr.v4.runtime.CommonTokenStream
import org.antlr.v4.runtime.RecognitionException
Expand Down Expand Up @@ -140,7 +140,6 @@ class Filter {
}



/**
* Represents a sealed class `Value` that can hold different types of values.
*
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/no/acntech/kollectiveq/FilterPrintVisitor.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.acntech.kollectiveq

import no.acntech.kollectiveq.text.*
import no.acntech.kollectiveq.FilterPrintVisitor.PrintFormat
import no.acntech.kollectiveq.util.text.*

/**
* The FilterPrintVisitor class is responsible for visiting filter conditions and generating a formatted string representation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.acntech.kollectiveq

import no.acntech.kollectiveq.lang.ValidationException
import no.acntech.kollectiveq.util.lang.ValidationException

/**
* This visitor validates that the filter does not contain any conditions that are not allowed.
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/no/acntech/kollectiveq/Pagination.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package no.acntech.kollectiveq

import no.acntech.kollectiveq.text.EQUALS
import no.acntech.kollectiveq.util.text.EQUALS
import org.springframework.web.util.UriUtils
import java.nio.charset.StandardCharsets

Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/no/acntech/kollectiveq/Sorting.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.acntech.kollectiveq

import no.acntech.kollectiveq.text.*
import no.acntech.kollectiveq.util.text.*
import no.acntech.kollectiveq.util.time.DetailedParseException
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.web.util.UriUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import jakarta.persistence.metamodel.EntityType
import jakarta.persistence.metamodel.Metamodel
import no.acntech.kollectiveq.Filter
import no.acntech.kollectiveq.FilterBaseVisitor
import no.acntech.kollectiveq.collections.mapFromPairs
import no.acntech.kollectiveq.collections.prettyPrint
import no.acntech.kollectiveq.lang.TransformFunction
import no.acntech.kollectiveq.lang.identityTransform
import no.acntech.kollectiveq.persistence.PersistenceUtils
import no.acntech.kollectiveq.persistence.PersistenceUtils.getInverseAttribute
import no.acntech.kollectiveq.persistence.PersistenceUtils.getTargetEntityTypeForPluralAttribute
import no.acntech.kollectiveq.text.*
import no.acntech.kollectiveq.util.collections.mapFromPairs
import no.acntech.kollectiveq.util.collections.prettyPrint
import no.acntech.kollectiveq.util.lang.TransformFunction
import no.acntech.kollectiveq.util.lang.identityTransform
import no.acntech.kollectiveq.util.text.*
import no.acntech.kollectiveq.util.time.*
import org.apache.commons.lang3.builder.ToStringBuilder
import org.apache.commons.lang3.builder.ToStringStyle
import org.slf4j.Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package no.acntech.kollectiveq.jpql

import no.acntech.kollectiveq.Sorting
import no.acntech.kollectiveq.SortingVisitor
import no.acntech.kollectiveq.lang.TransformFunction
import no.acntech.kollectiveq.lang.identityTransform
import no.acntech.kollectiveq.text.COMMA_SPACE
import no.acntech.kollectiveq.text.DetailedParseException
import no.acntech.kollectiveq.text.EMPTY_STRING
import no.acntech.kollectiveq.text.SPACE
import no.acntech.kollectiveq.util.lang.TransformFunction
import no.acntech.kollectiveq.util.lang.identityTransform
import no.acntech.kollectiveq.util.text.COMMA_SPACE
import no.acntech.kollectiveq.util.text.EMPTY_STRING
import no.acntech.kollectiveq.util.text.SPACE
import no.acntech.kollectiveq.util.time.DetailedParseException

/**
* Visitor that transforms a [Sorting] to a JPQL ORDER BY clause.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import no.acntech.kollectiveq.Pagination
import no.acntech.kollectiveq.Sorting
import no.acntech.kollectiveq.jpql.JPQLTransformationFilterVisitor
import no.acntech.kollectiveq.jpql.JPQLTransformationSortingVisitor
import no.acntech.kollectiveq.lang.TransformFunction
import no.acntech.kollectiveq.lang.snakeToCamelTransformer
import no.acntech.kollectiveq.text.EMPTY_STRING
import no.acntech.kollectiveq.util.lang.TransformFunction
import no.acntech.kollectiveq.util.lang.snakeToCamelTransformer
import no.acntech.kollectiveq.util.text.EMPTY_STRING
import org.slf4j.LoggerFactory
import org.springframework.data.domain.Page
import org.springframework.data.domain.PageImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.google.common.base.CaseFormat
import no.acntech.kollectiveq.Filter
import no.acntech.kollectiveq.Pagination
import no.acntech.kollectiveq.Sorting
import no.acntech.kollectiveq.lang.TransformFunction
import no.acntech.kollectiveq.lang.createCaseFormatTransformFunction
import no.acntech.kollectiveq.util.lang.TransformFunction
import no.acntech.kollectiveq.util.lang.createCaseFormatTransformFunction
import org.springframework.data.domain.Page
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.repository.NoRepositoryBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package no.acntech.kollectiveq.persistence

import jakarta.persistence.*
import jakarta.persistence.metamodel.*
import no.acntech.kollectiveq.text.DOT
import no.acntech.kollectiveq.text.PERIOD
import no.acntech.kollectiveq.util.text.DOT
import no.acntech.kollectiveq.util.text.PERIOD
import java.lang.reflect.Field
import java.lang.reflect.Member
import java.lang.reflect.Method
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package no.acntech.kollectiveq.collections
package no.acntech.kollectiveq.util.collections

import no.acntech.kollectiveq.text.EMPTY_STRING
import no.acntech.kollectiveq.text.NEW_LINE
import no.acntech.kollectiveq.text.SPACE
import no.acntech.kollectiveq.util.text.EMPTY_STRING
import no.acntech.kollectiveq.util.text.NEW_LINE
import no.acntech.kollectiveq.util.text.SPACE

fun List<*>.prettyPrint(indentation: Int = 0): String {
val indent = SPACE.repeat(indentation)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package no.acntech.kollectiveq.lang
package no.acntech.kollectiveq.util.lang

import com.google.common.base.CaseFormat
import no.acntech.kollectiveq.collections.prettyPrint
import no.acntech.kollectiveq.util.collections.prettyPrint
import kotlin.reflect.full.memberProperties
import kotlin.reflect.jvm.isAccessible

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.acntech.kollectiveq.lang
package no.acntech.kollectiveq.util.lang

/**
* Thrown to indicate a validation problem.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.acntech.kollectiveq.text
package no.acntech.kollectiveq.util.text

const val EMPTY_STRING = ""

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.acntech.kollectiveq.text
package no.acntech.kollectiveq.util.time

import org.apache.commons.lang3.builder.ToStringBuilder
import org.apache.commons.lang3.builder.ToStringStyle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.acntech.kollectiveq.time
package no.acntech.kollectiveq.util.time

/**
* Parses a string into an [Instant] using a highly flexible formatter (parser) supporting a wide range of formats.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package no.acntech.kollectiveq.test.app.util.json
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import no.acntech.kollectiveq.time.FlexibleInstantParser
import no.acntech.kollectiveq.util.time.FlexibleInstantParser
import java.time.Instant
import java.time.format.DateTimeParseException

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import jakarta.persistence.TypedQuery
import no.acntech.kollectiveq.Filter
import no.acntech.kollectiveq.Pagination
import no.acntech.kollectiveq.Sorting
import no.acntech.kollectiveq.collections.prettyPrint
import no.acntech.kollectiveq.jpql.JPQLTransformationFilterVisitor
import no.acntech.kollectiveq.lang.snakeToCamelTransformer
import no.acntech.kollectiveq.test.app.domain.model.Department
import no.acntech.kollectiveq.test.app.domain.model.Employee
import no.acntech.kollectiveq.test.apptest.domain.repostitory.BaseRepositoryTest
import no.acntech.kollectiveq.util.collections.prettyPrint
import no.acntech.kollectiveq.util.lang.snakeToCamelTransformer
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.params.ParameterizedTest
Expand Down Expand Up @@ -79,7 +79,7 @@ class MiscRepoTests : BaseRepositoryTest() {
"'','name\$like:P*\$and:\$having:AVG(employees.year_of_birth)\$gte:2000', '', 'SELECT de_0 FROM Department de_0 WHERE (LOWER(de_0.name) LIKE LOWER('P%') AND de_0.id IN (SELECT em_0.department.id FROM Employee em_0 GROUP BY em_0.department.id HAVING AVG(em_0.yearOfBirth) >= 2000))'",
"'','\$having:AVG(employees.year_of_birth)\$gte:2000', '', 'SELECT de_0 FROM Department de_0 WHERE de_0.id IN (SELECT em_0.department.id FROM Employee em_0 GROUP BY em_0.department.id HAVING AVG(em_0.yearOfBirth) >= 2000)'",

)
)
fun testHavingClause(paginationVal: String, filterVal: String, sortVal: String, expectedJpqlQuery: String) {
// Select all departments that have employees with first name starting with J
val filter = Filter.of(filterVal, true)
Expand All @@ -93,7 +93,7 @@ class MiscRepoTests : BaseRepositoryTest() {
)
filter.accept(visitor)

val query: String = visitor.toQuery()
val query: String = visitor.toQuery()
println("whereClause: ${visitor.toWhereClause()}")
println("Query: $query")

Expand Down

0 comments on commit 08b62db

Please sign in to comment.