-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
290 additions
and
76 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...ticsearch/src/main/java/be/kwakeroni/parameters/backend/es/api/ElasticSearchCriteria.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package be.kwakeroni.parameters.backend.es.api; | ||
|
||
import org.json.JSONObject; | ||
|
||
/** | ||
* (C) 2017 Maarten Van Puymbroeck | ||
*/ | ||
public interface ElasticSearchCriteria { | ||
|
||
public void addParameterMatch(String parameter, String value); | ||
|
||
public JSONObject toJSONObject(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...rc/main/java/be/kwakeroni/parameters/backend/es/service/DefaultElasticSearchCriteria.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package be.kwakeroni.parameters.backend.es.service; | ||
|
||
import be.kwakeroni.parameters.backend.es.api.ElasticSearchCriteria; | ||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* (C) 2017 Maarten Van Puymbroeck | ||
*/ | ||
class DefaultElasticSearchCriteria implements ElasticSearchCriteria{ | ||
|
||
private String group; | ||
private List<Match> parameterMatches = Collections.emptyList(); | ||
|
||
public DefaultElasticSearchCriteria(String group) { | ||
this.group = group; | ||
} | ||
|
||
@Override | ||
public void addParameterMatch(String parameter, String value) { | ||
if (this.parameterMatches.isEmpty()){ | ||
this.parameterMatches = new ArrayList<>(1); | ||
} | ||
this.parameterMatches.add(new Match(parameter, value)); | ||
} | ||
|
||
@Override | ||
public JSONObject toJSONObject() { | ||
if (parameterMatches == null || parameterMatches.isEmpty()) { | ||
return Match.match("_type", group); | ||
} else { | ||
JSONArray criteria = new JSONArray(); | ||
|
||
criteria.put(Match.match("_type", group)); | ||
|
||
this.parameterMatches.forEach(match -> criteria.put(match.toJSONObject())); | ||
|
||
|
||
return new JSONObject().put("bool", | ||
new JSONObject().put("must", criteria) | ||
); | ||
} | ||
} | ||
|
||
private static final class Match { | ||
public final String parameter; | ||
public final String value; | ||
|
||
public Match(String parameter, String value) { | ||
this.parameter = parameter; | ||
this.value = value; | ||
} | ||
|
||
public JSONObject toJSONObject() { | ||
return match(this.parameter, this.value); | ||
} | ||
|
||
public static JSONObject match(String parameter, String value) { | ||
return new JSONObject().put("match", | ||
new JSONObject().put(parameter, value)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../be/kwakeroni/parameters/basic/backend/query/support/IntermediaryBackendGroupSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package be.kwakeroni.parameters.basic.backend.query.support; | ||
|
||
import be.kwakeroni.parameters.backend.api.BackendGroup; | ||
import be.kwakeroni.parameters.backend.api.query.BackendQuery; | ||
import be.kwakeroni.parameters.backend.api.query.BackendWireFormatterContext; | ||
|
||
/** | ||
* (C) 2017 Maarten Van Puymbroeck | ||
*/ | ||
public abstract class IntermediaryBackendGroupSupport<Q extends BackendQuery<? extends Q, ?>, S, E> implements BackendGroup<Q, S, E> { | ||
|
||
private final BackendGroup<Q, S, E> subGroup; | ||
|
||
public IntermediaryBackendGroupSupport(BackendGroup<Q, S, E> subGroup) { | ||
this.subGroup = subGroup; | ||
} | ||
|
||
@Override | ||
public BackendQuery<? extends Q, ?> internalize(Object query, BackendWireFormatterContext context) { | ||
return context.internalize(this, query); | ||
} | ||
|
||
public BackendGroup<Q, S, E> getSubGroup() { | ||
return this.subGroup; | ||
} | ||
|
||
|
||
@Override | ||
public String getName() { | ||
return this.subGroup.getName(); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
.../be/kwakeroni/parameters/basic/backend/query/support/IntermediateBackendQuerySupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package be.kwakeroni.parameters.basic.backend.query.support; | ||
|
||
import be.kwakeroni.parameters.backend.api.query.BackendQuery; | ||
import be.kwakeroni.parameters.backend.api.query.BackendWireFormatterContext; | ||
|
||
/** | ||
* (C) 2017 Maarten Van Puymbroeck | ||
*/ | ||
public abstract class IntermediateBackendQuerySupport<Q extends BackendQuery<Q, V>, V> implements BackendQuery<Q, V> { | ||
|
||
private final Q subQuery; | ||
|
||
public IntermediateBackendQuerySupport(Q subQuery) { | ||
this.subQuery = subQuery; | ||
} | ||
|
||
protected BackendQuery<Q, V> getSubQuery() { | ||
return subQuery; | ||
} | ||
|
||
@Override | ||
public Object externalizeValue(V value, BackendWireFormatterContext wireFormatterContext) { | ||
return subQuery.externalizeValue(value, wireFormatterContext); | ||
} | ||
|
||
@Override | ||
public V internalizeValue(Object value, BackendWireFormatterContext wireFormatterContext) { | ||
return subQuery.internalizeValue(value, wireFormatterContext); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...arch/src/main/java/be/kwakeroni/parameters/basic/backend/es/ElasticSearchMappedGroup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package be.kwakeroni.parameters.basic.backend.es; | ||
|
||
import be.kwakeroni.parameters.backend.api.BackendGroup; | ||
import be.kwakeroni.parameters.backend.api.query.BackendQuery; | ||
import be.kwakeroni.parameters.backend.api.query.BackendWireFormatterContext; | ||
import be.kwakeroni.parameters.backend.es.api.ElasticSearchCriteria; | ||
import be.kwakeroni.parameters.backend.es.api.ElasticSearchData; | ||
import be.kwakeroni.parameters.backend.es.api.ElasticSearchEntry; | ||
import be.kwakeroni.parameters.backend.es.api.ElasticSearchQuery; | ||
import be.kwakeroni.parameters.basic.backend.query.BasicBackendWireFormatter; | ||
import be.kwakeroni.parameters.basic.backend.query.MappedBackendGroup; | ||
import be.kwakeroni.parameters.basic.backend.query.support.IntermediaryBackendGroupSupport; | ||
import be.kwakeroni.parameters.basic.backend.query.support.IntermediateBackendQuerySupport; | ||
import org.json.JSONObject; | ||
|
||
import java.util.Optional; | ||
import java.util.function.BiPredicate; | ||
|
||
/** | ||
* (C) 2017 Maarten Van Puymbroeck | ||
*/ | ||
public class ElasticSearchMappedGroup | ||
extends IntermediaryBackendGroupSupport<ElasticSearchQuery<?>, Object, ElasticSearchEntry> | ||
implements MappedBackendGroup<ElasticSearchQuery<?>, Object, ElasticSearchEntry> { | ||
|
||
private final String keyParameterName; | ||
|
||
public ElasticSearchMappedGroup(String keyParameterName, BackendGroup<ElasticSearchQuery<?>, Object, ElasticSearchEntry> subGroup) { | ||
super(subGroup); | ||
this.keyParameterName = keyParameterName; | ||
} | ||
|
||
@Override | ||
public ElasticSearchQuery<?> getEntryQuery(String keyValue, ElasticSearchQuery<?> subQuery) { | ||
return new ElasticSearchMappedQuery<>(keyValue, subQuery); | ||
} | ||
|
||
@Override | ||
public void validateNewEntry(ElasticSearchEntry entry, Object storage) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
private final class ElasticSearchMappedQuery<T> | ||
extends IntermediateBackendQuerySupport<ElasticSearchQuery<T>, T> | ||
implements ElasticSearchQuery<T>{ | ||
|
||
private final String keyValue; | ||
|
||
public ElasticSearchMappedQuery(String keyValue, ElasticSearchQuery<T> subQuery) { | ||
super(subQuery); | ||
this.keyValue = keyValue; | ||
} | ||
|
||
@Override | ||
public Optional<T> apply(ElasticSearchData data, ElasticSearchCriteria criteria) { | ||
criteria.addParameterMatch(keyParameterName, this.keyValue); | ||
return getSubQuery().raw().apply(data, criteria); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.