mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-28 19:08:40 +00:00
A simple `condition` that compares a path into the model in the execution context to a value. The comparison is based on the following possible operators: `eq`, `not_eq`, `lt`, `lte`, `gt`, `gte`. The following example shows a `compare` condition that checks if the total hits in the payload is greater or equal to 5. ``` { "compare" : { "ctx.payload.hits.total" : { "gte" : "5" } } } ``` Original commit: elastic/x-pack-elasticsearch@6d4f2bbf10
58 lines
2.4 KiB
Java
58 lines
2.4 KiB
Java
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
*/
|
|
package org.elasticsearch.watcher.condition;
|
|
|
|
import org.elasticsearch.common.inject.AbstractModule;
|
|
import org.elasticsearch.common.inject.multibindings.MapBinder;
|
|
import org.elasticsearch.watcher.condition.always.AlwaysCondition;
|
|
import org.elasticsearch.watcher.condition.always.AlwaysConditionFactory;
|
|
import org.elasticsearch.watcher.condition.compare.CompareCondition;
|
|
import org.elasticsearch.watcher.condition.compare.CompareConditionFactory;
|
|
import org.elasticsearch.watcher.condition.never.NeverCondition;
|
|
import org.elasticsearch.watcher.condition.never.NeverConditionFactory;
|
|
import org.elasticsearch.watcher.condition.script.ScriptCondition;
|
|
import org.elasticsearch.watcher.condition.script.ScriptConditionFactory;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public class ConditionModule extends AbstractModule {
|
|
|
|
private final Map<String, Class<? extends ConditionFactory>> factories = new HashMap<>();
|
|
|
|
public void registerCondition(String type, Class<? extends ConditionFactory> factoryType) {
|
|
factories.put(type, factoryType);
|
|
}
|
|
|
|
@Override
|
|
protected void configure() {
|
|
|
|
MapBinder<String, ConditionFactory> factoriesBinder = MapBinder.newMapBinder(binder(), String.class, ConditionFactory.class);
|
|
|
|
bind(ScriptConditionFactory.class).asEagerSingleton();
|
|
factoriesBinder.addBinding(ScriptCondition.TYPE).to(ScriptConditionFactory.class);
|
|
|
|
bind(NeverConditionFactory.class).asEagerSingleton();
|
|
factoriesBinder.addBinding(NeverCondition.TYPE).to(NeverConditionFactory.class);
|
|
|
|
bind(AlwaysConditionFactory.class).asEagerSingleton();
|
|
factoriesBinder.addBinding(AlwaysCondition.TYPE).to(AlwaysConditionFactory.class);
|
|
|
|
bind(CompareConditionFactory.class).asEagerSingleton();
|
|
factoriesBinder.addBinding(CompareCondition.TYPE).to(CompareConditionFactory.class);
|
|
|
|
for (Map.Entry<String, Class<? extends ConditionFactory>> entry : factories.entrySet()) {
|
|
bind(entry.getValue()).asEagerSingleton();
|
|
factoriesBinder.addBinding(entry.getKey()).to(entry.getValue());
|
|
}
|
|
|
|
bind(ConditionRegistry.class).asEagerSingleton();
|
|
}
|
|
}
|