diff --git a/cursorpaging-examples/webapp-with-maven/src/main/java/io/vigier/cursorpaging/example/webapp/api/model/DataRecordAttribute.java b/cursorpaging-examples/webapp-with-maven/src/main/java/io/vigier/cursorpaging/example/webapp/api/model/DataRecordAttribute.java index 2e58b4f..f675038 100644 --- a/cursorpaging-examples/webapp-with-maven/src/main/java/io/vigier/cursorpaging/example/webapp/api/model/DataRecordAttribute.java +++ b/cursorpaging-examples/webapp-with-maven/src/main/java/io/vigier/cursorpaging/example/webapp/api/model/DataRecordAttribute.java @@ -17,8 +17,8 @@ public enum DataRecordAttribute { ID( Attribute.of( DataRecord_.ID, UUID.class ) ), NAME( Attribute.of( DataRecord_.NAME, String.class ) ), - CREATED_AT( Attribute.path( DataRecord_.AUDIT_INFO, AuditInfo.class, AuditInfo_.CREATED_AT, Instant.class ) ), - MODIFIED_AT( Attribute.path( DataRecord_.AUDIT_INFO, AuditInfo.class, AuditInfo_.MODIFIED_AT, Instant.class ) ); + CREATED_AT( Attribute.of( DataRecord_.AUDIT_INFO, AuditInfo.class, AuditInfo_.CREATED_AT, Instant.class ) ), + MODIFIED_AT( Attribute.of( DataRecord_.AUDIT_INFO, AuditInfo.class, AuditInfo_.MODIFIED_AT, Instant.class ) ); private final Attribute attribute; diff --git a/cursorpaging-jpa-api/src/test/java/io/vigier/cursorpaging/jpa/serializer/SerializerTest.java b/cursorpaging-jpa-api/src/test/java/io/vigier/cursorpaging/jpa/serializer/SerializerTest.java index 3602964..60e325e 100644 --- a/cursorpaging-jpa-api/src/test/java/io/vigier/cursorpaging/jpa/serializer/SerializerTest.java +++ b/cursorpaging-jpa-api/src/test/java/io/vigier/cursorpaging/jpa/serializer/SerializerTest.java @@ -93,7 +93,7 @@ void shouldSerializePageRequestsWithOrFilter() { @Test void shouldSerializePageRequestsWithMultipleAttributes() { - final var attribute1 = Attribute.path( // + final var attribute1 = Attribute.of( // SingleAttribute.of( "one", TestEntity.class ), // SingleAttribute.of( "two", Instant.class ) ); final var attribute2 = Attribute.of( "three", Integer.class ); @@ -132,7 +132,7 @@ void shouldSerializeTotalCountIfPresent() { @Test void shouldDeserializeAndFilter() { - PageRequest request = PageRequest.create( r -> r.filter( + final PageRequest request = PageRequest.create( r -> r.filter( Filters.and( attribute( TestEntity_.id ).equalTo( 123L ), attribute( TestEntity_.name ).like( "%bumlux%" ) ) ).asc( TestEntity_.id ) ); final RequestSerializer serializer = RequestSerializer.create(); @@ -144,7 +144,7 @@ void shouldDeserializeAndFilter() { @Test void shouldSerializeParametersOfFilterRules() { - Map> parameters = Map.of( "Test1", List.of( "Value1" ) ); + final Map> parameters = Map.of( "Test1", List.of( "Value1" ) ); final var request = createPageRequest().copy( b -> b.rule( newTestRule( "TestRule", parameters ) ) ); final RequestSerializer serializer = RequestSerializer.create( c -> c.filterRuleFactory( "TestRule", p -> newTestRule( "TestRule", p ) ) ); @@ -186,7 +186,7 @@ void shouldLearnAttributesBySerializing() { } private PageRequest createPageRequest() { - final var attribute1 = Attribute.path( // + final var attribute1 = Attribute.of( // SingleAttribute.of( "one", TestEntity.class ), // SingleAttribute.of( "two", Instant.class ) ); final var attribute2 = Attribute.of( "three", Integer.class ); diff --git a/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/Attribute.java b/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/Attribute.java index 8ed109b..06af1f6 100644 --- a/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/Attribute.java +++ b/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/Attribute.java @@ -29,7 +29,7 @@ public class Attribute { private final boolean ignoreCase; - public Attribute( List attributes ) { + public Attribute( final List attributes ) { this.attributes = attributes; this.ignoreCase = false; } @@ -56,32 +56,51 @@ public static Attribute of( final SingularAttribute> } /** - * Creates a new attribute with a path of single attributes. This is needed to address properties of embedded - * entities + * Creates a new attribute as path of single attributes. This is needed to address properties of embedded entities * * @param path Path pointing to an attribute (of an embedded entity) * @return The attribute describing the path and the type of the single attributes */ - public static Attribute path( final jakarta.persistence.metamodel.Attribute... path ) { + public static Attribute of( final jakarta.persistence.metamodel.Attribute... path ) { return new Attribute( Arrays.stream( path ).map( SingleAttribute::of ).toList() ); } /** - * Creates a new attribute with a path of single attributes. This is needed to address properties of embedded + * Creates a new attribute with as path of single attributes. This is needed to address properties of embedded * entities * * @param path Path pointing to an attribute (of an embedded entity) * @return The attribute describing the path and the type of the single attributes */ - public static Attribute path( final SingleAttribute... path ) { + public static Attribute of( final SingleAttribute... path ) { return new Attribute( Arrays.asList( path ) ); } - public static Attribute path( final String name1, final Class type1, final String name2, final Class type2 ) { + /** + * Creates an attribute as path of 2 attributes + * + * @param name1 Attribute name 1 + * @param type1 Type of attribute 1 + * @param name2 Attribute name 2 + * @param type2 Type of attribute 2 + * @return The attribute describing the path and type to the specified attribute + */ + public static Attribute of( final String name1, final Class type1, final String name2, final Class type2 ) { return new Attribute( List.of( SingleAttribute.of( name1, type1 ), SingleAttribute.of( name2, type2 ) ) ); } - public static Attribute path( final String name1, final Class type1, final String name2, final Class type2, + /** + * Creates an attribute as path of 3 attributes + * + * @param name1 Attribute name 1 + * @param type1 Type of attribute 1 + * @param name2 Attribute name 2 + * @param type2 Type of attribute 2 + * @param name3 Attribute name 3 + * @param type3 Type of attribute 3 + * @return The attribute describing the path and type to the specified attribute + */ + public static Attribute of( final String name1, final Class type1, final String name2, final Class type2, final String name3, final Class type3 ) { return new Attribute( List.of( SingleAttribute.of( name1, type1 ), SingleAttribute.of( name2, type2 ), SingleAttribute.of( name3, type3 ) ) ); @@ -122,7 +141,7 @@ public String name() { * @param root The root of the entity * @param Entity type * @param Value type - * @return The path to the attribute + * @return The path-expression to the attribute */ public > Expression path( final Root root ) { Path path = root; @@ -135,14 +154,14 @@ public > Expression path( final Root ro } /** - * Get the type of the last attribute in the path + * Get the type of the last attribute in the of * * @param Expected Value type * @return the value type */ @SuppressWarnings( "unchecked" ) public > Class type() { - return (Class) attributes.get( attributes.size() - 1 ).type(); + return (Class) attributes.getLast().type(); } /** @@ -152,7 +171,7 @@ public > Class type() { * @param ignoreCase instruction to ignore character case for comparison operations. * @return New attribute with flag set. */ - Attribute ignoreCase( boolean ignoreCase ) { + Attribute ignoreCase( final boolean ignoreCase ) { return toBuilder().ignoreCase( ignoreCase ) .build(); } @@ -226,11 +245,11 @@ private boolean typeIsLong() { return type() == Long.class || type() == long.class; } - public List> verify( List> values ) { + public List> verify( final List> values ) { return values.stream().map( this::verify ).toList(); } - public Comparable[] verify( Comparable... values ) { + public Comparable[] verify( final Comparable... values ) { return Arrays.stream( values ).map( this::verify ).toArray( Comparable[]::new ); } } diff --git a/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/Filters.java b/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/Filters.java index 6ac1670..ca71b04 100644 --- a/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/Filters.java +++ b/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/Filters.java @@ -19,7 +19,7 @@ public static class FilterCreator { * @param value the value to compare to * @return the filter for the operation */ - public Filter equalTo( Comparable value ) { + public Filter equalTo( final Comparable value ) { return Filter.create( f -> f.attribute( attribute ).equalTo( attribute.verify( value ) ) ); } @@ -29,7 +29,7 @@ public Filter equalTo( Comparable value ) { * @param values the value to compare to * @return the filter for the operation */ - public Filter equalTo( List> values ) { + public Filter equalTo( final List> values ) { return Filter.create( f -> f.attribute( attribute ).equalTo( attribute.verify( values ) ) ); } @@ -39,7 +39,7 @@ public Filter equalTo( List> values ) { * @param values the value to compare to * @return the filter for the operation */ - public Filter in( List> values ) { + public Filter in( final List> values ) { return Filter.create( f -> f.attribute( attribute ).in( attribute.verify( values ) ) ); } @@ -49,7 +49,7 @@ public Filter in( List> values ) { * @param values the value to compare to * @return the filter for the operation */ - public Filter in( Comparable... values ) { + public Filter in( final Comparable... values ) { return Filter.create( f -> f.attribute( attribute ).in( attribute.verify( values ) ) ); } @@ -59,7 +59,7 @@ public Filter in( Comparable... values ) { * @param values the value to compare to * @return the filter for the operation */ - public Filter like( String... values ) { + public Filter like( final String... values ) { return Filter.create( f -> f.attribute( attribute ).like( attribute.verify( values ) ) ); } @@ -69,7 +69,7 @@ public Filter like( String... values ) { * @param values the value to compare to * @return the filter for the operation */ - public Filter like( List> values ) { + public Filter like( final List> values ) { return Filter.create( f -> f.attribute( attribute ).like( attribute.verify( values ) ) ); } @@ -79,7 +79,7 @@ public Filter like( List> values ) { * @param value The value to compare to * @return A filter for the operation */ - public Filter greaterThan( Comparable value ) { + public Filter greaterThan( final Comparable value ) { return Filter.create( f -> f.attribute( attribute ).greaterThan( attribute.verify( value ) ) ); } @@ -99,7 +99,7 @@ public Filter greaterThan( final List> values ) { * @param value The value to compare to * @return A filter for the operation */ - public Filter lessThan( Comparable value ) { + public Filter lessThan( final Comparable value ) { return Filter.create( f -> f.attribute( attribute ).lessThan( attribute.verify( value ) ) ); } @@ -109,7 +109,7 @@ public Filter lessThan( Comparable value ) { * @param values values to compare * @return A filter for the operation */ - public Filter lessThan( List> values ) { + public Filter lessThan( final List> values ) { return Filter.create( f -> f.attribute( attribute ).lessThan( attribute.verify( values ) ) ); } } @@ -134,54 +134,54 @@ public static FilterCreator attribute( final Attribute attribute ) { * @param type of the attribute to be filtered on * @return the filter creator for the operation */ - public static FilterCreator attribute( final String name, Class> type ) { + public static FilterCreator attribute( final String name, final Class> type ) { return FilterCreator.create( Attribute.of( name, type ) ); } /** - * Starts filter-creation with a path of the provided attributes + * Starts filter-creation with a of of the provided attributes * - * @param name1 of the first attribute in the path - * @param type1 of the first attribute in the path - * @param name2 of the second attribute in the path - * @param type2 of the second attribute in the path + * @param name1 of the first attribute in the of + * @param type1 of the first attribute in the of + * @param name2 of the second attribute in the of + * @param type2 of the second attribute in the of * @return the filter creator for the operation */ - public static FilterCreator attribute( final String name1, Class> type1, String name2, - Class> type2 ) { - return FilterCreator.create( Attribute.path( name1, type1, name2, type2 ) ); + public static FilterCreator attribute( final String name1, final Class> type1, + final String name2, final Class> type2 ) { + return FilterCreator.create( Attribute.of( name1, type1, name2, type2 ) ); } /** - * Starts filter-creation with a path of the provided attributes + * Starts filter-creation with a of of the provided attributes */ public static FilterCreator attribute( final jakarta.persistence.metamodel.Attribute... path ) { - return attribute( Attribute.path( path ) ); + return attribute( Attribute.of( path ) ); } /** - * Starts filter-creation with a path of the provided attributes + * Starts filter-creation with a of of the provided attributes */ public static FilterCreator attribute( final SingularAttribute> attribute ) { return attribute( Attribute.of( attribute ) ); } /** - * Starts filter-creation with a path of the provided attributes, ignoring the case in the subsequent operations. + * Starts filter-creation with a of of the provided attributes, ignoring the case in the subsequent operations. */ public static FilterCreator ignoreCase( final Attribute attribute ) { return FilterCreator.create( attribute.withIgnoreCase() ); } /** - * Starts filter-creation with a path of the provided attributes, ignoring the case in the subsequent operations. + * Starts filter-creation with a of of the provided attributes, ignoring the case in the subsequent operations. */ public static FilterCreator ignoreCase( final jakarta.persistence.metamodel.Attribute... path ) { - return ignoreCase( Attribute.path( path ) ); + return ignoreCase( Attribute.of( path ) ); } /** - * Starts filter-creation with a path of the provided attributes, ignoring the case in the subsequent operations. + * Starts filter-creation with a of of the provided attributes, ignoring the case in the subsequent operations. */ public static FilterCreator ignoreCase( final SingularAttribute> attribute ) { return ignoreCase( Attribute.of( attribute ) ); diff --git a/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/SingleAttribute.java b/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/SingleAttribute.java index 8cf524f..bc8e465 100644 --- a/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/SingleAttribute.java +++ b/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/SingleAttribute.java @@ -1,6 +1,6 @@ package io.vigier.cursorpaging.jpa; -import lombok.EqualsAndHashCode; +import java.util.Objects; import org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper; /** @@ -28,6 +28,8 @@ public static SingleAttribute of( final String name, final Class type ) { * @return the new instance. */ public static SingleAttribute of( final jakarta.persistence.metamodel.Attribute attribute ) { + Objects.requireNonNull( attribute, "Attribute must not be null: JPA metamodel might not be initialized, " + + "make sure the entity manager is created." ); return new SingleAttribute( attribute.getName(), attribute.getJavaType() ); } diff --git a/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/filter/FilterBuilder.java b/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/filter/FilterBuilder.java index d97ac03..f7c1938 100644 --- a/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/filter/FilterBuilder.java +++ b/cursorpaging-jpa/src/main/java/io/vigier/cursorpaging/jpa/filter/FilterBuilder.java @@ -28,15 +28,15 @@ public FilterBuilder attribute( final Attribute attribute ) { } /** - * Creates an attribute as path to an embedded entity's property. + * Creates an attribute as path to an embedded/related entity's property. * - * @param attributes the path to the property + * @param attributes the of to the property * @return the builder */ @SafeVarargs public final FilterBuilder path( final jakarta.persistence.metamodel.Attribute>... attributes ) { - this.attribute = Attribute.path( attributes ); + this.attribute = Attribute.of( attributes ); return this; } diff --git a/cursorpaging-jpa/src/test/java/io/vigier/cursorpaging/jpa/FilterTest.java b/cursorpaging-jpa/src/test/java/io/vigier/cursorpaging/jpa/FilterTest.java index 8bef81a..631444c 100644 --- a/cursorpaging-jpa/src/test/java/io/vigier/cursorpaging/jpa/FilterTest.java +++ b/cursorpaging-jpa/src/test/java/io/vigier/cursorpaging/jpa/FilterTest.java @@ -50,10 +50,9 @@ void shouldCreateFilterFromManualSpecifiedAttributeWithMultipleValues() { @Test void shouldCreateFilterFromPath() { - Long value = 4711L; + final Long value = 4711L; final var sut = Filter.create( - f -> f.attribute( Attribute.path( DataRecord_.TAGS, Set.class, Tag_.ID, Long.class ) ) - .equalTo( value ) ); + f -> f.attribute( Attribute.of( DataRecord_.TAGS, Set.class, Tag_.ID, Long.class ) ).equalTo( value ) ); verifyNameAndValue( sut, DataRecord_.TAGS + "." + Tag_.ID, Long.class, value ); } @@ -77,9 +76,9 @@ void shouldBeEqual() { shouldBeEqual( f1 -> f1.lessThan( "1L" ), f2 -> f2.lessThan( "1L" ) ); } - private void shouldBeEqual( Function f1, Function f2 ) { - var name1 = Attribute.of( "name", String.class ); - var name2 = Attribute.of( "name", String.class ); + private void shouldBeEqual( final Function f1, final Function f2 ) { + final var name1 = Attribute.of( "name", String.class ); + final var name2 = Attribute.of( "name", String.class ); Assertions.assertThat( f1.apply( Filters.attribute( name1 ) ) ) .isEqualTo( f2.apply( Filters.attribute( name2 ) ) ); @@ -87,9 +86,11 @@ private void shouldBeEqual( Function f1, Function values = List.of( "Test1", "Test2" ); + final List values = List.of( "Test1", "Test2" ); final var filter = Filters.ignoreCase( DataRecord_.tags, Tag_.name ).in( values ); - assertThat( filter.attributes() ).contains( Attribute.path( DataRecord_.tags, Tag_.name ).withIgnoreCase() ); + assertThat( filter.attributes() ).contains( Attribute.of( DataRecord_.tags, Tag_.name ).withIgnoreCase() ); assertThat( filter.values() ).hasSize( values.size() ); assertThat( filter.values( String.class ) ).containsAll( values ); diff --git a/cursorpaging-jpa/src/test/java/io/vigier/cursorpaging/jpa/itest/PostgreSqlCursorPageTest.java b/cursorpaging-jpa/src/test/java/io/vigier/cursorpaging/jpa/itest/PostgreSqlCursorPageTest.java index 57a74e9..7057f23 100644 --- a/cursorpaging-jpa/src/test/java/io/vigier/cursorpaging/jpa/itest/PostgreSqlCursorPageTest.java +++ b/cursorpaging-jpa/src/test/java/io/vigier/cursorpaging/jpa/itest/PostgreSqlCursorPageTest.java @@ -122,8 +122,8 @@ void shouldFetchPagesOrderedByCreatedDesc() { testDataGenerator.generateData( 15 ); final PageRequest request = PageRequest.create( b -> b.pageSize( 5 ) - .desc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) - .asc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.modifiedAt ) ) + .desc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) + .asc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.modifiedAt ) ) .asc( DataRecord_.id ) ); final var firstPage = dataRecordRepository.loadPage( request ); @@ -186,8 +186,8 @@ void shouldFetchPagesOrderedByNameAsc() { final var secondPageContent = secondPage.getContent(); assertThat( secondPageContent ).hasSize( 10 ); - final var lastOnFirstPage = firstPageContent.get( firstPageContent.size() - 1 ); - final var firstOnSecondPage = secondPageContent.get( 0 ); + final var lastOnFirstPage = firstPageContent.getLast(); + final var firstOnSecondPage = secondPageContent.getFirst(); assertThat( lastOnFirstPage ).extracting( DataRecord::getName ).isEqualTo( "Charlie" ); assertThat( firstOnSecondPage ).extracting( DataRecord::getName ).isEqualTo( "Charlie" ); @@ -208,7 +208,7 @@ void shouldUseDefaultPageSize() { void shouldFilterResults() { testDataGenerator.generateData( 100 ); final PageRequest request = PageRequest.create( b -> b.pageSize( 100 ) - .desc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) + .desc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) .asc( DataRecord_.id ) .filter( attribute( DataRecord_.name ).equalTo( "Alpha" ) ) ); @@ -224,7 +224,7 @@ void shouldFilterResultsWithInPredicate() { testDataGenerator.generateData( 100 ); final Filter nameIsAlphaOrBravo = Filter.create( b -> b.attribute( DataRecord_.name ).in( "Alpha", "Bravo" ) ); final PageRequest request = PageRequest.create( b -> b.pageSize( 100 ) - .desc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) + .desc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) .asc( DataRecord_.id ) .filter( nameIsAlphaOrBravo ) ); @@ -283,13 +283,13 @@ void shouldFilterResultsWithMultipleLikeExpressions() { void shouldFilterByGreaterAndLowerThan() { final var count = TestDataGenerator.NAMES.length; testDataGenerator.generateData( count ); - var all = dataRecordRepository.loadPage( PageRequest.create( - r -> r.asc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) ).pageSize( count ) ) ) + final var all = dataRecordRepository.loadPage( PageRequest.create( + r -> r.asc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ) ).pageSize( count ) ) ) .content(); - final var createdAt = Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ); - final var firstCreatedAt = all.get( 0 ).getAuditInfo().getCreatedAt(); - final var lastCreatedAt = all.get( all.size() - 1 ).getAuditInfo().getCreatedAt(); + final var createdAt = Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ); + final var firstCreatedAt = all.getFirst().getAuditInfo().getCreatedAt(); + final var lastCreatedAt = all.getLast().getAuditInfo().getCreatedAt(); assertThat( dataRecordRepository.loadPage( PageRequest.create( r -> r.desc( DataRecord_.id ) .filter( Filter.create( f -> f.attribute( createdAt ).greaterThan( firstCreatedAt ) ) ) ) ) ) // .hasSize( all.size() - 1 ); @@ -307,11 +307,11 @@ void shouldFilterByGreaterAndLowerThan() { @Test void shouldFilterAndFetchNextWithAndFilter() { testDataGenerator.generateData( 100 ); - var names = List.of( NAME_ALPHA, NAME_BRAVO, "Charlie", "Delta", "Echo" ); - var status = List.of( Status.DRAFT, Status.ACTIVE ); + final var names = List.of( NAME_ALPHA, NAME_BRAVO, "Charlie", "Delta", "Echo" ); + final var status = List.of( Status.DRAFT, Status.ACTIVE ); final var page1 = dataRecordRepository.loadPage( PageRequest.create( - r -> r.asc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) + r -> r.asc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) .pageSize( 5 ) .filter( Filters.and( attribute( DataRecord_.name ).in( names ), attribute( DataRecord_.status ).in( status ) ) ) ) ); @@ -365,7 +365,7 @@ void shouldAddCountInPageRequestWhenRequested() { void shouldReturnTotalCountWhenNoFilterPresent() { testDataGenerator.generateData( 42 ); final PageRequest request = PageRequest.create( b -> b.pageSize( 5 ) - .desc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) + .desc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) .asc( DataRecord_.id ) ); final var count = dataRecordRepository.count( request ); @@ -377,7 +377,7 @@ void shouldReturnTotalCountWhenNoFilterPresent() { void shouldReturnZeroCountWhenNoRecordsMatches() { testDataGenerator.generateData( 42 ); final PageRequest request = PageRequest.create( b -> b.pageSize( 5 ) - .desc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) + .desc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) .asc( DataRecord_.id ) .filter( attribute( DataRecord_.name ).equalTo( "name-does-not-exist" ) ) ); @@ -406,7 +406,7 @@ public Predicate toCountPredicate( final QueryBuilder cqb ) { @Override public List attributes() { - return List.of( Attribute.path( DataRecord_.securityClass, SecurityClass_.level ) ); + return List.of( Attribute.of( DataRecord_.securityClass, SecurityClass_.level ) ); } } @@ -524,7 +524,7 @@ void shouldFilterByAttributeOfEntryInManyToOneRelationship() { final int countPublic = (int) all.stream().filter( r -> r.getSecurityClass().getLevel() == 0 ).count(); final int countStandard = (int) all.stream().filter( r -> r.getSecurityClass().getLevel() == 1 ).count(); - final var attributeSecurityClassLevel = Attribute.path( DataRecord_.securityClass, SecurityClass_.level ); + final var attributeSecurityClassLevel = Attribute.of( DataRecord_.securityClass, SecurityClass_.level ); final var page = dataRecordRepository.loadPage( PageRequest.create( b -> b.pageSize( 99 ) .asc( DataRecord_.id ) .filter( attribute( attributeSecurityClassLevel ).equalTo( 0 ) ) ) ); @@ -541,8 +541,8 @@ void shouldFilterByAttributeOfEntryInManyToOneRelationship() { @Test void shouldFilterByAttributeOfEntryInManyToManyRelationship() { final List all = testDataGenerator.generateData( 99 ); - var redTag = tagRepository.findByName( "red" ); - var greenTag = tagRepository.findByName( "green" ); + final var redTag = tagRepository.findByName( "red" ); + final var greenTag = tagRepository.findByName( "green" ); final int redOrGreenCount = (int) all.stream() .filter( r -> r.getTags().contains( greenTag ) || r.getTags().contains( redTag ) ) .count(); @@ -581,7 +581,7 @@ public Predicate toPredicate( final QueryBuilder cqb ) { void shouldUseMoreComplicateFilterRulesForAclChecks() { testDataGenerator.generateData( 100 ); final PageRequest request = PageRequest.create( b -> b.pageSize( 100 ) - .desc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) + .desc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) .asc( DataRecord_.id ) .rule( new AclCheckFilterRule( SUBJECT_READ_STANDARD, READ ) ) ); @@ -591,7 +591,7 @@ void shouldUseMoreComplicateFilterRulesForAclChecks() { assertThat( firstPage.getContent() ).allMatch( e -> e.getSecurityClass().getLevel() <= 1 ); final PageRequest request2 = PageRequest.create( b -> b.pageSize( 100 ) - .desc( Attribute.path( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) + .desc( Attribute.of( DataRecord_.auditInfo, AuditInfo_.createdAt ) ) .asc( DataRecord_.id ) .rule( new AclCheckFilterRule( "does not exist", READ ) ) ); @@ -607,12 +607,12 @@ void shouldCombineFilterByOrCondition() { final int expectedSize = (int) all.stream() .filter( r -> r.getName().equals( NAME_ALPHA ) || r.getName().equals( NAME_BRAVO ) ) .count(); - var nameIsAlpha = attribute( DataRecord_.name ).equalTo( NAME_ALPHA ); - var nameIsBravo = attribute( DataRecord_.name ).equalTo( NAME_BRAVO ); - var request = PageRequest.create( + final var nameIsAlpha = attribute( DataRecord_.name ).equalTo( NAME_ALPHA ); + final var nameIsBravo = attribute( DataRecord_.name ).equalTo( NAME_BRAVO ); + final var request = PageRequest.create( r -> r.desc( DataRecord_.id ).filter( Filters.or( nameIsAlpha, nameIsBravo ) ) ); - var result = dataRecordRepository.loadPage( request ); + final var result = dataRecordRepository.loadPage( request ); assertThat( result ).hasSize( expectedSize ) .allSatisfy( r -> assertThat( r ).extracting( DataRecord::getName ).isIn( NAME_ALPHA, NAME_BRAVO ) ); @@ -622,20 +622,20 @@ void shouldCombineFilterByOrCondition() { @Test void shouldCombineAndWithOrFilter() { final var all = testDataGenerator.generateData( 99 ); - Tag red = tagRepository.findByName( "red" ); - Tag green = tagRepository.findByName( "green" ); + final Tag red = tagRepository.findByName( "red" ); + final Tag green = tagRepository.findByName( "green" ); final int expectedSize = (int) all.stream() .filter( r -> (r.getName().equals( NAME_ALPHA ) && r.getTags().contains( red )) // || (r.getName().equals( NAME_BRAVO ) && r.getTags().contains( green )) ) .count(); - var redAlpha = Filters.and( attribute( DataRecord_.name ).equalTo( NAME_ALPHA ), + final var redAlpha = Filters.and( attribute( DataRecord_.name ).equalTo( NAME_ALPHA ), attribute( DataRecord_.tags, Tag_.name ).equalTo( red.getName() ) ); - var greenBravo = Filters.and( attribute( DataRecord_.name ).equalTo( NAME_BRAVO ), + final var greenBravo = Filters.and( attribute( DataRecord_.name ).equalTo( NAME_BRAVO ), attribute( DataRecord_.tags, Tag_.name ).equalTo( green.getName() ) ); - var request = PageRequest.create( + final var request = PageRequest.create( r -> r.desc( DataRecord_.id ).filter( Filters.or( redAlpha, greenBravo ) ) ); - var result = dataRecordRepository.loadPage( request ); + final var result = dataRecordRepository.loadPage( request ); assertThat( result ).hasSize( expectedSize ).allSatisfy( r -> { if ( r.getName().equals( NAME_ALPHA ) ) {