{"id":25458782,"url":"https://github.com/overworkedcriminal/entity-filters","last_synced_at":"2025-11-03T00:30:32.500Z","repository":{"id":278059767,"uuid":"933810432","full_name":"OverworkedCriminal/entity-filters","owner":"OverworkedCriminal","description":"Spring Boot Specification API filters generator","archived":false,"fork":false,"pushed_at":"2025-02-17T19:01:43.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-17T19:41:57.169Z","etag":null,"topics":["code-generation","java","library","spring-boot-specification"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OverworkedCriminal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-16T18:32:38.000Z","updated_at":"2025-02-17T19:01:46.000Z","dependencies_parsed_at":"2025-02-17T19:52:03.858Z","dependency_job_id":null,"html_url":"https://github.com/OverworkedCriminal/entity-filters","commit_stats":null,"previous_names":["overworkedcriminal/entity-filters"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OverworkedCriminal%2Fentity-filters","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OverworkedCriminal%2Fentity-filters/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OverworkedCriminal%2Fentity-filters/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OverworkedCriminal%2Fentity-filters/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OverworkedCriminal","download_url":"https://codeload.github.com/OverworkedCriminal/entity-filters/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239404150,"owners_count":19632703,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","java","library","spring-boot-specification"],"created_at":"2025-02-18T03:28:38.389Z","updated_at":"2025-11-03T00:30:32.470Z","avatar_url":"https://github.com/OverworkedCriminal.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Entity-filters\n\nSpring Boot library that allows to automatically generate filter classes for given entities. \n\nFor any class T annotated with @Entity and @GenerateFilters class TFilters will be generated.\nTFilters will have intoSpecification() method that allows easy integration with Spring Boot\nSpecification API.\n\n\n## Project organization\n| module | description |\n| --- | --- |\n| filters | classes that allow filtering by some type |\n| generator-filters | classes that allow automatic TFilters generation |\n| tests | library tests |\n\n## Example\nFor given entity:\n```Java\n@Entity\n@GenerateFilters\npublic class CodeGenerationTestEntity {\n    @Id\n    private Long id;\n    private String name;\n    private BigDecimal price;\n    private LocalDate createdAt;\n    private LocalDateTime updatedAt;\n    private Integer version;\n}\n```\nThis filters class will be generated\n```Java\n@Getter\n@Setter\n@Builder\n@NoArgsConstructor\n@AllArgsConstructor\npublic class CodeGenerationTestEntityFilters {\n    @Valid private NumericValueFilter\u003cjava.lang.Long\u003e id;\n    @Valid private StringValueFilter name;\n    @Valid private NumericValueFilter\u003cjava.math.BigDecimal\u003e price;\n    @Valid private NumericValueFilter\u003cjava.time.LocalDate\u003e createdAt;\n    @Valid private NumericValueFilter\u003cjava.time.LocalDateTime\u003e updatedAt;\n    @Valid private NumericValueFilter\u003cjava.lang.Integer\u003e version;\n\n    public Specification\u003cCodeGenerationTestEntity\u003e intoSpecification() {\n        return Specification.allOf(\n            mapFilterToSpecification(CodeGenerationTestEntity_.id, id),\n            mapFilterToSpecification(CodeGenerationTestEntity_.name, name),\n            mapFilterToSpecification(CodeGenerationTestEntity_.price, price),\n            mapFilterToSpecification(CodeGenerationTestEntity_.createdAt, createdAt),\n            mapFilterToSpecification(CodeGenerationTestEntity_.updatedAt, updatedAt),\n            mapFilterToSpecification(CodeGenerationTestEntity_.version, version)\n        );\n    }\n\n    private static \u003cT extends Comparable\u003cT\u003e\u003e Specification\u003cCodeGenerationTestEntity\u003e mapFilterToSpecification(\n        SingularAttribute\u003cCodeGenerationTestEntity, ? extends T\u003e attribute,\n        NumericValueFilter\u003c? extends T\u003e filter\n    ) {\n        if (filter == null) {\n            return (root, query, cb) -\u003e cb.conjunction();\n        }\n\n        return switch (filter.getType()) {\n            case LESS          -\u003e (root, query, cb) -\u003e cb.lessThan(root.get(attribute), filter.getV1());\n            case LESS_EQUAL    -\u003e (root, query, cb) -\u003e cb.lessThanOrEqualTo(root.get(attribute), filter.getV1());\n            case EQUAL         -\u003e (root, query, cb) -\u003e cb.equal(root.get(attribute), filter.getV1());\n            case GREATER       -\u003e (root, query, cb) -\u003e cb.greaterThan(root.get(attribute), filter.getV1());\n            case GREATER_EQUAL -\u003e (root, query, cb) -\u003e cb.greaterThanOrEqualTo(root.get(attribute), filter.getV1());\n            case BETWEEN       -\u003e (root, query, cb) -\u003e cb.between(root.get(attribute), filter.getV1(), filter.getV2());\n            case IS_NULL       -\u003e (root, query, cb) -\u003e cb.isNull(root.get(attribute));\n            case IS_NOT_NULL   -\u003e (root, query, cb) -\u003e cb.isNotNull(root.get(attribute));\n        };\n    }\n\n    private static \u003cT extends Comparable\u003cT\u003e\u003e Specification\u003cCodeGenerationTestEntity\u003e mapFilterToSpecification(\n        SingularAttribute\u003cCodeGenerationTestEntity, ? extends T\u003e attribute,\n        StringValueFilter filter\n    ) {\n        if (filter == null) {\n            return (root, query, cb) -\u003e cb.conjunction();\n        }\n\n        return switch (filter.getType()) {\n            case EQUAL             -\u003e (root, query, cb) -\u003e cb.equal(root.get(attribute), filter.getV());\n            case EQUAL_IGNORE_CASE -\u003e (root, query, cb) -\u003e cb.equal(\n                cb.upper(\n                    root\n                        .get(attribute)\n                        .as(String.class)\n                ),\n                filter.getV().toUpperCase()\n            );\n            case IS_NULL     -\u003e (root, query, cb) -\u003e cb.isNull(root.get(attribute));\n            case IS_NOT_NULL -\u003e (root, query, cb) -\u003e cb.isNotNull(root.get(attribute));\n        };\n    }\n\n}\n```\n\n## How to run tests\n```bash\nmvn test\n```\n\nIf for some reason there's problem with running test using onlny ```mvn test``` try this:\n\n```bash\nmvn clean\nmvn test-compile\nmvn test\n```\n\n## How to use it (Maven)\nFirst compile tests (without it there may be errors related to code not being generated at correct time )\n```bash\nmvn test-compile\n```\nThen install library\n```bash\nmvn install\n```\n\nAdd dependencies to pom.xml\n```xml\n\u003c!-- Filters --\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.example.filter\u003c/groupId\u003e\n  \u003cartifactId\u003efilters\u003c/artifactId\u003e\n  \u003cversion\u003e0.0.2\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003c!-- Filters automatic generation --\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.example.filter\u003c/groupId\u003e\n  \u003cartifactId\u003egenerator-filters\u003c/artifactId\u003e\n  \u003cversion\u003e0.0.2\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003c!-- It's necessary to also add lombok dependency --\u003e\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.projectlombok\u003c/groupId\u003e\n  \u003cartifactId\u003elombok\u003c/artifactId\u003e\n  \u003cversion\u003e1.18.36\u003c/version\u003e\n  \u003cscope\u003eprovided\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nAdd plugins to pom.xml\n```xml\n\u003cbuild\u003e\n  \u003cplugins\u003e\n    \u003cplugin\u003e\n      \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n      \u003cartifactId\u003espring-boot-maven-plugin\u003c/artifactId\u003e\n    \u003c/plugin\u003e\n    \u003cplugin\u003e\n      \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n      \u003cartifactId\u003emaven-compiler-plugin\u003c/artifactId\u003e\n      \u003cversion\u003e3.13.0\u003c/version\u003e\n      \u003cconfiguration\u003e\n        \u003cannotationProcessorPaths\u003e\n          \u003c!--\n            Generates T_ class that allows to access entity field names\n            required by Specification API\n          --\u003e\n          \u003cpath\u003e\n            \u003cgroupId\u003eorg.hibernate\u003c/groupId\u003e\n            \u003cartifactId\u003ehibernate-jpamodelgen\u003c/artifactId\u003e\n            \u003cversion\u003e6.6.6.Final\u003c/version\u003e\n          \u003c/path\u003e\n          \u003c!-- Lombok generator --\u003e\n          \u003cpath\u003e\n            \u003cgroupId\u003eorg.projectlombok\u003c/groupId\u003e\n            \u003cartifactId\u003elombok\u003c/artifactId\u003e\n            \u003cversion\u003e1.18.36\u003c/version\u003e\n          \u003c/path\u003e\n          \u003c!-- Filters automatic generation --\u003e\n          \u003cpath\u003e\n            \u003cgroupId\u003ecom.example.filter\u003c/groupId\u003e\n            \u003cartifactId\u003egenerator-filters\u003c/artifactId\u003e\n            \u003cversion\u003e0.0.2\u003c/version\u003e\n          \u003c/path\u003e\n        \u003c/annotationProcessorPaths\u003e\n      \u003c/configuration\u003e\n    \u003c/plugin\u003e\n  \u003c/plugins\u003e\n\u003c/build\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foverworkedcriminal%2Fentity-filters","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foverworkedcriminal%2Fentity-filters","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foverworkedcriminal%2Fentity-filters/lists"}