
co.elastic.clients.elasticsearch.security.query_role.RoleQuery Maven / Gradle / Ivy
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.clients.elasticsearch.security.query_role;
import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.ExistsQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.IdsQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.MatchQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.PrefixQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.RangeQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.SimpleQueryStringQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.TermQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.TermsQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.WildcardQuery;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.JsonEnum;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.JsonpSerializable;
import co.elastic.clients.json.JsonpUtils;
import co.elastic.clients.json.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import co.elastic.clients.util.OpenTaggedUnion;
import co.elastic.clients.util.TaggedUnionUtils;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.Object;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;
//----------------------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------------------
//
// This code is generated from the Elasticsearch API specification
// at https://github.com/elastic/elasticsearch-specification
//
// Manual updates to this file will be lost when the code is
// re-generated.
//
// If you find a property that is missing or wrongly typed, please
// open an issue or a PR on the API specification repository.
//
//----------------------------------------------------------------
// typedef: security.query_role.RoleQueryContainer
/**
*
* @see API
* specification
*/
@JsonpDeserializable
public class RoleQuery implements OpenTaggedUnion, JsonpSerializable {
/**
* {@link RoleQuery} variant kinds.
*
* @see API
* specification
*/
public enum Kind implements JsonEnum {
Bool("bool"),
Exists("exists"),
Ids("ids"),
Match("match"),
MatchAll("match_all"),
Prefix("prefix"),
Range("range"),
SimpleQueryString("simple_query_string"),
Term("term"),
Terms("terms"),
Wildcard("wildcard"),
/** A custom {@code RoleQuery} defined by a plugin */
_Custom(null)
;
private final String jsonValue;
Kind(String jsonValue) {
this.jsonValue = jsonValue;
}
public String jsonValue() {
return this.jsonValue;
}
}
private final Kind _kind;
private final Object _value;
@Override
public final Kind _kind() {
return _kind;
}
@Override
public final Object _get() {
return _value;
}
public RoleQuery(RoleQueryVariant value) {
this._kind = ApiTypeHelper.requireNonNull(value._roleQueryKind(), this, "");
this._value = ApiTypeHelper.requireNonNull(value, this, "");
this._customKind = null;
}
private RoleQuery(Builder builder) {
this._kind = ApiTypeHelper.requireNonNull(builder._kind, builder, "");
this._value = ApiTypeHelper.requireNonNull(builder._value, builder, "");
this._customKind = builder._customKind;
}
public static RoleQuery of(Function> fn) {
return fn.apply(new Builder()).build();
}
/**
* Is this variant instance of kind {@code bool}?
*/
public boolean isBool() {
return _kind == Kind.Bool;
}
/**
* Get the {@code bool} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code bool} kind.
*/
public BoolQuery bool() {
return TaggedUnionUtils.get(this, Kind.Bool);
}
/**
* Is this variant instance of kind {@code exists}?
*/
public boolean isExists() {
return _kind == Kind.Exists;
}
/**
* Get the {@code exists} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code exists} kind.
*/
public ExistsQuery exists() {
return TaggedUnionUtils.get(this, Kind.Exists);
}
/**
* Is this variant instance of kind {@code ids}?
*/
public boolean isIds() {
return _kind == Kind.Ids;
}
/**
* Get the {@code ids} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code ids} kind.
*/
public IdsQuery ids() {
return TaggedUnionUtils.get(this, Kind.Ids);
}
/**
* Is this variant instance of kind {@code match}?
*/
public boolean isMatch() {
return _kind == Kind.Match;
}
/**
* Get the {@code match} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code match} kind.
*/
public MatchQuery match() {
return TaggedUnionUtils.get(this, Kind.Match);
}
/**
* Is this variant instance of kind {@code match_all}?
*/
public boolean isMatchAll() {
return _kind == Kind.MatchAll;
}
/**
* Get the {@code match_all} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code match_all} kind.
*/
public MatchAllQuery matchAll() {
return TaggedUnionUtils.get(this, Kind.MatchAll);
}
/**
* Is this variant instance of kind {@code prefix}?
*/
public boolean isPrefix() {
return _kind == Kind.Prefix;
}
/**
* Get the {@code prefix} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code prefix} kind.
*/
public PrefixQuery prefix() {
return TaggedUnionUtils.get(this, Kind.Prefix);
}
/**
* Is this variant instance of kind {@code range}?
*/
public boolean isRange() {
return _kind == Kind.Range;
}
/**
* Get the {@code range} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code range} kind.
*/
public RangeQuery range() {
return TaggedUnionUtils.get(this, Kind.Range);
}
/**
* Is this variant instance of kind {@code simple_query_string}?
*/
public boolean isSimpleQueryString() {
return _kind == Kind.SimpleQueryString;
}
/**
* Get the {@code simple_query_string} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code simple_query_string}
* kind.
*/
public SimpleQueryStringQuery simpleQueryString() {
return TaggedUnionUtils.get(this, Kind.SimpleQueryString);
}
/**
* Is this variant instance of kind {@code term}?
*/
public boolean isTerm() {
return _kind == Kind.Term;
}
/**
* Get the {@code term} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code term} kind.
*/
public TermQuery term() {
return TaggedUnionUtils.get(this, Kind.Term);
}
/**
* Is this variant instance of kind {@code terms}?
*/
public boolean isTerms() {
return _kind == Kind.Terms;
}
/**
* Get the {@code terms} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code terms} kind.
*/
public TermsQuery terms() {
return TaggedUnionUtils.get(this, Kind.Terms);
}
/**
* Is this variant instance of kind {@code wildcard}?
*/
public boolean isWildcard() {
return _kind == Kind.Wildcard;
}
/**
* Get the {@code wildcard} variant value.
*
* @throws IllegalStateException
* if the current variant is not of the {@code wildcard} kind.
*/
public WildcardQuery wildcard() {
return TaggedUnionUtils.get(this, Kind.Wildcard);
}
@Nullable
private final String _customKind;
/**
* Is this a custom {@code RoleQuery} defined by a plugin?
*/
public boolean _isCustom() {
return _kind == Kind._Custom;
}
/**
* Get the actual kind when {@code _kind()} equals {@link Kind#_Custom}
* (plugin-defined variant).
*/
@Nullable
public final String _customKind() {
return _customKind;
}
/**
* Get the custom plugin-defined variant value.
*
* @throws IllegalStateException
* if the current variant is not {@link Kind#_Custom}.
*/
public JsonData _custom() {
return TaggedUnionUtils.get(this, Kind._Custom);
}
@Override
@SuppressWarnings("unchecked")
public void serialize(JsonGenerator generator, JsonpMapper mapper) {
generator.writeStartObject();
generator.writeKey(_kind == Kind._Custom ? _customKind : _kind.jsonValue());
if (_value instanceof JsonpSerializable) {
((JsonpSerializable) _value).serialize(generator, mapper);
}
generator.writeEnd();
}
@Override
public String toString() {
return JsonpUtils.toString(this);
}
public static class Builder extends WithJsonObjectBuilderBase implements ObjectBuilder {
private Kind _kind;
private Object _value;
private String _customKind;
@Override
protected Builder self() {
return this;
}
public ObjectBuilder bool(BoolQuery v) {
this._kind = Kind.Bool;
this._value = v;
return this;
}
public ObjectBuilder bool(Function> fn) {
return this.bool(fn.apply(new BoolQuery.Builder()).build());
}
public ObjectBuilder exists(ExistsQuery v) {
this._kind = Kind.Exists;
this._value = v;
return this;
}
public ObjectBuilder exists(Function> fn) {
return this.exists(fn.apply(new ExistsQuery.Builder()).build());
}
public ObjectBuilder ids(IdsQuery v) {
this._kind = Kind.Ids;
this._value = v;
return this;
}
public ObjectBuilder ids(Function> fn) {
return this.ids(fn.apply(new IdsQuery.Builder()).build());
}
public ObjectBuilder match(MatchQuery v) {
this._kind = Kind.Match;
this._value = v;
return this;
}
public ObjectBuilder match(Function> fn) {
return this.match(fn.apply(new MatchQuery.Builder()).build());
}
public ObjectBuilder matchAll(MatchAllQuery v) {
this._kind = Kind.MatchAll;
this._value = v;
return this;
}
public ObjectBuilder matchAll(Function> fn) {
return this.matchAll(fn.apply(new MatchAllQuery.Builder()).build());
}
public ObjectBuilder prefix(PrefixQuery v) {
this._kind = Kind.Prefix;
this._value = v;
return this;
}
public ObjectBuilder prefix(Function> fn) {
return this.prefix(fn.apply(new PrefixQuery.Builder()).build());
}
public ObjectBuilder range(RangeQuery v) {
this._kind = Kind.Range;
this._value = v;
return this;
}
public ObjectBuilder range(Function> fn) {
return this.range(fn.apply(new RangeQuery.Builder()).build());
}
public ObjectBuilder simpleQueryString(SimpleQueryStringQuery v) {
this._kind = Kind.SimpleQueryString;
this._value = v;
return this;
}
public ObjectBuilder simpleQueryString(
Function> fn) {
return this.simpleQueryString(fn.apply(new SimpleQueryStringQuery.Builder()).build());
}
public ObjectBuilder term(TermQuery v) {
this._kind = Kind.Term;
this._value = v;
return this;
}
public ObjectBuilder term(Function> fn) {
return this.term(fn.apply(new TermQuery.Builder()).build());
}
public ObjectBuilder terms(TermsQuery v) {
this._kind = Kind.Terms;
this._value = v;
return this;
}
public ObjectBuilder terms(Function> fn) {
return this.terms(fn.apply(new TermsQuery.Builder()).build());
}
public ObjectBuilder wildcard(WildcardQuery v) {
this._kind = Kind.Wildcard;
this._value = v;
return this;
}
public ObjectBuilder wildcard(Function> fn) {
return this.wildcard(fn.apply(new WildcardQuery.Builder()).build());
}
/**
* Define this {@code RoleQuery} as a plugin-defined variant.
*
* @param name
* the plugin-defined identifier
* @param data
* the data for this custom {@code RoleQuery}. It is converted
* internally to {@link JsonData}.
*/
public ObjectBuilder _custom(String name, Object data) {
this._kind = Kind._Custom;
this._customKind = name;
this._value = JsonData.of(data);
return this;
}
public RoleQuery build() {
_checkSingleUse();
return new RoleQuery(this);
}
}
protected static void setupRoleQueryDeserializer(ObjectDeserializer op) {
op.add(Builder::bool, BoolQuery._DESERIALIZER, "bool");
op.add(Builder::exists, ExistsQuery._DESERIALIZER, "exists");
op.add(Builder::ids, IdsQuery._DESERIALIZER, "ids");
op.add(Builder::match, MatchQuery._DESERIALIZER, "match");
op.add(Builder::matchAll, MatchAllQuery._DESERIALIZER, "match_all");
op.add(Builder::prefix, PrefixQuery._DESERIALIZER, "prefix");
op.add(Builder::range, RangeQuery._DESERIALIZER, "range");
op.add(Builder::simpleQueryString, SimpleQueryStringQuery._DESERIALIZER, "simple_query_string");
op.add(Builder::term, TermQuery._DESERIALIZER, "term");
op.add(Builder::terms, TermsQuery._DESERIALIZER, "terms");
op.add(Builder::wildcard, WildcardQuery._DESERIALIZER, "wildcard");
op.setUnknownFieldHandler((builder, name, parser, mapper) -> {
JsonpUtils.ensureCustomVariantsAllowed(parser, mapper);
builder._custom(name, JsonData._DESERIALIZER.deserialize(parser, mapper));
});
}
public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy(Builder::new,
RoleQuery::setupRoleQueryDeserializer, Builder::build);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy