Skip to content

Commit

Permalink
Upgrade to contentgrid-spring 0.7.1, which supports spring boot 3
Browse files Browse the repository at this point in the history
  • Loading branch information
vierbergenlars committed Aug 23, 2023
1 parent 5947d6b commit c9d4965
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 206 deletions.
7 changes: 0 additions & 7 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,3 @@ include 'thunx-integration-tests:api-integration-tests'
// substitute module('com.contentgrid.opa-java-client:rego-java') with project(':rego-java')
// }
//}


sourceControl {
gitRepository(uri('https://github.com/xenit-eu/contentgrid-spring')) {
producesModule('com.contentgrid.spring:contentgrid-spring-data-rest')
}
}
6 changes: 1 addition & 5 deletions thunx-integration-tests/api-integration-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-starter-web'

testImplementation testFixtures('com.contentgrid.spring:contentgrid-spring-data-rest') {
version {
branch = 'spring-boot-3'
}
}
testImplementation testFixtures('com.contentgrid.spring:contentgrid-spring-data-rest:0.7.1')

runtimeOnly 'org.postgresql:postgresql'
runtimeOnly 'org.testcontainers:postgresql:1.18.3'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.springframework.data.querydsl.binding;

import com.contentgrid.thunx.predicates.querydsl.FieldByReflectionAccessStrategy;
import com.contentgrid.thunx.predicates.querydsl.QueryDslConverter;
import com.contentgrid.thunx.spring.data.context.AbacContext;
import com.contentgrid.thunx.spring.data.querydsl.EntityPathResolverBasedPathBuilderFactory;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.Predicate;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.querydsl.EntityPathResolver;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;

@Slf4j
public class AbacQuerydslPredicateBuilder {

private final QuerydslPredicateBuilder querydslPredicateBuilder;
private final EntityPathResolver resolver;
private final QueryDslConverter queryDslConverter;

public AbacQuerydslPredicateBuilder(ConversionService conversionService, EntityPathResolver resolver) {

Assert.notNull(conversionService, "ConversionService must not be null!");

this.querydslPredicateBuilder = new QuerydslPredicateBuilder(conversionService, resolver);
this.resolver = resolver;

this.queryDslConverter = new QueryDslConverter(new FieldByReflectionAccessStrategy(), new EntityPathResolverBasedPathBuilderFactory(
resolver));
}

@Nullable
public Predicate getPredicate(TypeInformation<?> type, MultiValueMap<String, String> values, QuerydslBindings bindings) {

Assert.notNull(bindings, "Context must not be null!");

BooleanBuilder builder = new BooleanBuilder();

var abacContext = AbacContext.getCurrentAbacContext();
if (abacContext != null) {
Predicate queryDslPredicate = this.queryDslConverter.from(abacContext, type.getType());
Assert.notNull(queryDslPredicate, "abac expression cannot be null");
log.debug("ABAC Querydsl Predicate: {}", queryDslPredicate);

builder.and(queryDslPredicate);
}

builder.and(querydslPredicateBuilder.getPredicate(type, values, bindings));

return builder.getValue();
}

}

This file was deleted.

0 comments on commit c9d4965

Please sign in to comment.