Skip to content

Commit

Permalink
XWIKI-22726: Allow customizing the validation of HQL queries through …
Browse files Browse the repository at this point in the history
…configuration

* rename a component hint to be more consistent with the class name
* fail the whole validator if any of the patterns is wrong
* add some validator priority related documentation
  • Loading branch information
tmortagne committed Dec 13, 2024
1 parent 8d53032 commit 751f2c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.descriptor.ComponentDescriptor;
import org.xwiki.component.phase.Initializable;
Expand All @@ -48,17 +46,14 @@
*/
@Component
@Singleton
@Named("configuration")
@Named("configurable")
@Priority(ComponentDescriptor.DEFAULT_PRIORITY - 100)
public class ConfigurableHQLCompleteStatementValidator implements HQLCompleteStatementValidator, Initializable
{
@Inject
@Named("xwikiproperties")
private ConfigurationSource configuration;

@Inject
private Logger logger;

private List<Pattern> unsafe;

private List<Pattern> safe;
Expand All @@ -70,7 +65,7 @@ public void initialize() throws InitializationException
this.safe = getPatterns("query.hql.safe");
}

private List<Pattern> getPatterns(String key)
private List<Pattern> getPatterns(String key) throws InitializationException
{
List<String> patternStrings = this.configuration.getProperty(key, List.class);

Expand All @@ -81,8 +76,8 @@ private List<Pattern> getPatterns(String key)
try {
patterns.add(Pattern.compile(patternString));
} catch (Exception e) {
this.logger.warn("Failed to parse pattern [{}] for configuration [{}]: {}", patternString, key,
ExceptionUtils.getRootCauseMessage(e));
throw new InitializationException(
String.format("Failed to parse pattern [%s] for configuration [%s]", patternString, key), e);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

/**
* A component in charge of validating a passed HQL statement.
* <p>
* Note that since the {@code standard} validator always gives an answer, any extra validator must have a priority value
* lower than the default one ({@link org.xwiki.component.descriptor.ComponentDescriptor#DEFAULT_PRIORITY} to have a
* chance to be called.
*
* @version $Id$
* @since 17.0.0RC1
Expand Down

0 comments on commit 751f2c4

Please sign in to comment.