[JIRA] (HSEARCH-3325) Search 6 groundwork - Restore support for full-text filters
by Waldemar Kłaczyński (JIRA)
Waldemar Kłaczyński ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *commented* on HSEARCH-3325 ( https://hibernate.atlassian.net/browse/HSEARCH-3325?atlOrigin=eyJpIjoiMGU... )
Re: Search 6 groundwork - Restore support for full-text filters ( https://hibernate.atlassian.net/browse/HSEARCH-3325?atlOrigin=eyJpIjoiMGU... )
Another interesting solution for filters built in this way. It is possible to define a filter in a set with a binding field.
public class PermissionsBinder implements TypeBinder {
private String fieldName = "permissions" ;
private String operationName = "read" ;
public PermissionsBinder fieldName( String fieldName) {
this.fieldName = fieldName;
return this ;
}
public PermissionsBinder operationName( String operationName) {
this.operationName = operationName;
return this ;
}
@Override
public void bind(TypeBindingContext context) {
context.getDependencies().useRootOnly();
IndexFieldReference< String > permissionsField = context.getIndexSchemaElement()
.field( this.fieldName, f -> f.asString().analyzer( "permissions" ))
.toReference();
context.getIndexSchemaElement().filter( "is-permission" , new Filter())
.param( "operation" , operationName)
.param( "field" , this.fieldName)
.toReference();
context.setBridge( new Bridge(
permissionsField
));
}
private static class Bridge implements TypeBridge {
private final IndexFieldReference< String > permissionsField;
protected IdentityStoreResolver getIdentityService() {
IdentityStoreResolver isr = ServiceLocator.getService(IdentityStoreResolver.class, IdentityStoreResolver.JNDI_NAME);
return isr;
}
private Bridge(IndexFieldReference< String > permissionsField) {
this.permissionsField = permissionsField;
}
@Override
public void write(DocumentElement target, Object bridgedElement, TypeBridgeWriteContext context) {
StringBuilder brules = new StringBuilder();
IdentityStoreResolver isr = getIdentityService();
PermissionManager pm = isr.getPermissionManager();
List<Permission> permissions = pm.listPermissions(bridgedElement);
for (Permission permission : permissions) {
IdentityType assignee = permission.getAssignee();
if (assignee instanceof Group) {
String [] roles = permission.getRoles();
if (roles == null || roles.length < 1) {
roles = new String []{ "*" };
}
for ( String role : roles) {
brules.append(permission.getOperation()).append( ":" );
brules.append(permission.getContext()).append( ":" );
brules.append(permission.getPath()).append( ":" );
brules.append(role);
brules.append( "\n" );
}
} else {
brules.append(permission.getOperation()).append( ":" );
brules.append(permission.getContext()).append( ":" );
brules.append(permission.getPath());
brules.append( "\n" );
}
}
target.addValue( this.permissionsField, brules.toString());
}
}
private static class Filter implements FilterFactory {
@Override
public SearchPredicate create(FilterFactoryContext ctx) {
SearchPredicate filter;
SearchPredicateFactory predicate = ctx.predicate();
Account user = ctx.param( "user" );
String fieldPath = ctx.resolvePath(ctx.param( "field" ));
String operation = ctx.param( "operation" );
if (operation == null ) {
operation = "read" ;
}
PermissionQuery query = new PermissionQuery(fieldPath, operation, user);
filter = predicate.extension(LuceneExtension.get())
.fromLuceneQuery(query)
.toPredicate();
return filter;
}
}
}
( https://hibernate.atlassian.net/browse/HSEARCH-3325#add-comment?atlOrigin... ) Add Comment ( https://hibernate.atlassian.net/browse/HSEARCH-3325#add-comment?atlOrigin... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100122- sha1:38c716d )