Make RSQL visitor pluggable via a managed bean (#1145)
* Add a managed bean for a RsqlVisitorFactory Signed-off-by: Stefan Behl <stefan.behl@bosch.io> * Fix failing unit tests * Fix Sonar findings * Fix PR review findings
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import org.eclipse.hawkbit.repository.FieldNameProvider;
|
||||
|
||||
import cz.jirutka.rsql.parser.ast.Node;
|
||||
import cz.jirutka.rsql.parser.ast.RSQLVisitor;
|
||||
|
||||
/**
|
||||
* Factory to obtain {@link RSQLVisitor} instances that can be used to process
|
||||
* the {@link Node}s representing an RSQL query.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RsqlVisitorFactory {
|
||||
|
||||
/**
|
||||
* Provides a {@link RSQLVisitor} instance for validating RSQL queries based
|
||||
* on the given {@link FieldNameProvider}.
|
||||
*
|
||||
* @param <A>
|
||||
* The type of the {@link FieldNameProvider}.
|
||||
* @param fieldNameProvider
|
||||
* providing accessing to the relevant field names.
|
||||
*
|
||||
* @return An {@link RSQLVisitor} to validate the {@link Node}s of an RSQL
|
||||
* query.
|
||||
*/
|
||||
<A extends Enum<A> & FieldNameProvider> RSQLVisitor<Void, String> validationRsqlVisitor(Class<A> fieldNameProvider);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Bosch.IO GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository.rsql;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Helper class providing static access to the managed
|
||||
* {@link RsqlVisitorFactory} bean.
|
||||
*/
|
||||
public final class RsqlVisitorFactoryHolder {
|
||||
|
||||
private static final RsqlVisitorFactoryHolder SINGLETON = new RsqlVisitorFactoryHolder();
|
||||
|
||||
@Autowired
|
||||
private RsqlVisitorFactory rsqlVisitorFactory;
|
||||
|
||||
private RsqlVisitorFactoryHolder() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The holder singleton instance.
|
||||
*/
|
||||
public static RsqlVisitorFactoryHolder getInstance() {
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The managed RsqlVisitorFactory bean
|
||||
*/
|
||||
public RsqlVisitorFactory getRsqlVisitorFactory() {
|
||||
return rsqlVisitorFactory;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user