-
Notifications
You must be signed in to change notification settings - Fork 214
/
QueryCriteriaValidator.java
84 lines (73 loc) · 3.28 KB
/
QueryCriteriaValidator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.services.thingsearch.persistence.query.validation;
import java.util.Arrays;
import org.eclipse.ditto.services.thingsearch.common.config.DittoSearchConfig;
import org.eclipse.ditto.services.thingsearch.common.config.SearchConfig;
import org.eclipse.ditto.services.utils.akka.AkkaClassLoader;
import org.eclipse.ditto.services.utils.config.DefaultScopedConfig;
import org.eclipse.ditto.signals.commands.thingsearch.query.ThingSearchQueryCommand;
import akka.actor.AbstractExtensionId;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.ExtendedActorSystem;
import akka.actor.Extension;
/**
* Search Query Validator to be loaded by reflection.
* Can be used as an extension point to use custom validation of search queries.
* Implementations MUST have a public constructor taking the following parameters as arguments:
* <ul>
* <li>ActorSystem actorSystem: actor system in which this provider is loaded,</li>
* <li>ActorRef pubSubMediator: the mediator via which system-wide communication can be done</li>
* </ul>
*/
public abstract class QueryCriteriaValidator implements Extension {
/**
* Gets the criteria of a {@link org.eclipse.ditto.signals.commands.thingsearch.query.ThingSearchQueryCommand} and
* validates it.
*
* May throw an exception depending on the implementation in the used QueryCriteriaValidator.
*
*/
public abstract void validateCommand(final ThingSearchQueryCommand<?> command);
/**
* Load a {@code QueryCriteriaValidator} dynamically according to the search configuration.
*
* @param actorSystem The actor system in which to load the validator.
* @param pubSubMediator the mediator via which system-wide communication can be done.
* @return The validator.
*/
public static QueryCriteriaValidator get(final ActorSystem actorSystem, ActorRef pubSubMediator) {
return new ExtensionId(pubSubMediator).get(actorSystem);
}
/**
* ID of the actor system extension to validate the {@code QueryCriteriaValidator}.
*/
private static final class ExtensionId extends AbstractExtensionId<QueryCriteriaValidator> {
private final ActorRef pubSubMediator;
ExtensionId(final ActorRef pubSubMediator) {
super();
this.pubSubMediator = pubSubMediator;
}
@Override
public QueryCriteriaValidator createExtension(final ExtendedActorSystem system) {
final SearchConfig searchConfig =
DittoSearchConfig.of(DefaultScopedConfig.dittoScoped(
system.settings().config()));
return AkkaClassLoader.instantiate(system, QueryCriteriaValidator.class,
searchConfig.getQueryValidator(),
Arrays.asList(ActorSystem.class, ActorRef.class),
Arrays.asList(system, pubSubMediator));
}
}
}