All Downloads are FREE. Search and download functionalities are using the official Maven repository.

co.elastic.clients.elasticsearch.cluster.PutComponentTemplateRequest 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.
 */

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package co.elastic.clients.elasticsearch.cluster;

import co.elastic.clients.elasticsearch._types.ErrorResponse;
import co.elastic.clients.elasticsearch._types.RequestBase;
import co.elastic.clients.elasticsearch._types.Time;
import co.elastic.clients.elasticsearch._types.mapping.TypeMapping;
import co.elastic.clients.elasticsearch.indices.AliasDefinition;
import co.elastic.clients.elasticsearch.indices.IndexSettings;
import co.elastic.clients.elasticsearch.indices.IndexState;
import co.elastic.clients.json.JsonData;
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.ObjectBuilderDeserializer;
import co.elastic.clients.json.ObjectDeserializer;
import co.elastic.clients.transport.Endpoint;
import co.elastic.clients.transport.endpoints.SimpleEndpoint;
import co.elastic.clients.util.ApiTypeHelper;
import co.elastic.clients.util.ObjectBuilder;
import co.elastic.clients.util.WithJsonObjectBuilderBase;
import jakarta.json.stream.JsonGenerator;
import java.lang.Boolean;
import java.lang.Long;
import java.lang.String;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.Nullable;

// typedef: cluster.put_component_template.Request

/**
 * Creates or updates a component template
 * 
 * @see API
 *      specification
 */
@JsonpDeserializable
public class PutComponentTemplateRequest extends RequestBase implements JsonpSerializable {
	private final Map meta;

	private final Map aliases;

	@Nullable
	private final Boolean create;

	@Nullable
	private final TypeMapping mappings;

	@Nullable
	private final Time masterTimeout;

	private final String name;

	@Nullable
	private final IndexSettings settings;

	private final IndexState template;

	@Nullable
	private final Long version;

	// ---------------------------------------------------------------------------------------------

	private PutComponentTemplateRequest(Builder builder) {

		this.meta = ApiTypeHelper.unmodifiable(builder.meta);
		this.aliases = ApiTypeHelper.unmodifiable(builder.aliases);
		this.create = builder.create;
		this.mappings = builder.mappings;
		this.masterTimeout = builder.masterTimeout;
		this.name = ApiTypeHelper.requireNonNull(builder.name, this, "name");
		this.settings = builder.settings;
		this.template = ApiTypeHelper.requireNonNull(builder.template, this, "template");
		this.version = builder.version;

	}

	public static PutComponentTemplateRequest of(Function> fn) {
		return fn.apply(new Builder()).build();
	}

	/**
	 * API name: {@code _meta}
	 */
	public final Map meta() {
		return this.meta;
	}

	/**
	 * API name: {@code aliases}
	 */
	public final Map aliases() {
		return this.aliases;
	}

	/**
	 * Whether the index template should only be added if new or can also replace an
	 * existing one
	 * 

* API name: {@code create} */ @Nullable public final Boolean create() { return this.create; } /** * API name: {@code mappings} */ @Nullable public final TypeMapping mappings() { return this.mappings; } /** * Specify timeout for connection to master *

* API name: {@code master_timeout} */ @Nullable public final Time masterTimeout() { return this.masterTimeout; } /** * Required - The name of the template *

* API name: {@code name} */ public final String name() { return this.name; } /** * API name: {@code settings} */ @Nullable public final IndexSettings settings() { return this.settings; } /** * Required - API name: {@code template} */ public final IndexState template() { return this.template; } /** * API name: {@code version} */ @Nullable public final Long version() { return this.version; } /** * Serialize this object to JSON. */ public void serialize(JsonGenerator generator, JsonpMapper mapper) { generator.writeStartObject(); serializeInternal(generator, mapper); generator.writeEnd(); } protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { if (ApiTypeHelper.isDefined(this.meta)) { generator.writeKey("_meta"); generator.writeStartObject(); for (Map.Entry item0 : this.meta.entrySet()) { generator.writeKey(item0.getKey()); item0.getValue().serialize(generator, mapper); } generator.writeEnd(); } if (ApiTypeHelper.isDefined(this.aliases)) { generator.writeKey("aliases"); generator.writeStartObject(); for (Map.Entry item0 : this.aliases.entrySet()) { generator.writeKey(item0.getKey()); item0.getValue().serialize(generator, mapper); } generator.writeEnd(); } if (this.mappings != null) { generator.writeKey("mappings"); this.mappings.serialize(generator, mapper); } if (this.settings != null) { generator.writeKey("settings"); this.settings.serialize(generator, mapper); } generator.writeKey("template"); this.template.serialize(generator, mapper); if (this.version != null) { generator.writeKey("version"); generator.write(this.version); } } // --------------------------------------------------------------------------------------------- /** * Builder for {@link PutComponentTemplateRequest}. */ public static class Builder extends WithJsonObjectBuilderBase implements ObjectBuilder { @Nullable private Map meta; @Nullable private Map aliases; @Nullable private Boolean create; @Nullable private TypeMapping mappings; @Nullable private Time masterTimeout; private String name; @Nullable private IndexSettings settings; private IndexState template; @Nullable private Long version; /** * API name: {@code _meta} *

* Adds all entries of map to meta. */ public final Builder meta(Map map) { this.meta = _mapPutAll(this.meta, map); return this; } /** * API name: {@code _meta} *

* Adds an entry to meta. */ public final Builder meta(String key, JsonData value) { this.meta = _mapPut(this.meta, key, value); return this; } /** * API name: {@code aliases} *

* Adds all entries of map to aliases. */ public final Builder aliases(Map map) { this.aliases = _mapPutAll(this.aliases, map); return this; } /** * API name: {@code aliases} *

* Adds an entry to aliases. */ public final Builder aliases(String key, AliasDefinition value) { this.aliases = _mapPut(this.aliases, key, value); return this; } /** * API name: {@code aliases} *

* Adds an entry to aliases using a builder lambda. */ public final Builder aliases(String key, Function> fn) { return aliases(key, fn.apply(new AliasDefinition.Builder()).build()); } /** * Whether the index template should only be added if new or can also replace an * existing one *

* API name: {@code create} */ public final Builder create(@Nullable Boolean value) { this.create = value; return this; } /** * API name: {@code mappings} */ public final Builder mappings(@Nullable TypeMapping value) { this.mappings = value; return this; } /** * API name: {@code mappings} */ public final Builder mappings(Function> fn) { return this.mappings(fn.apply(new TypeMapping.Builder()).build()); } /** * Specify timeout for connection to master *

* API name: {@code master_timeout} */ public final Builder masterTimeout(@Nullable Time value) { this.masterTimeout = value; return this; } /** * Specify timeout for connection to master *

* API name: {@code master_timeout} */ public final Builder masterTimeout(Function> fn) { return this.masterTimeout(fn.apply(new Time.Builder()).build()); } /** * Required - The name of the template *

* API name: {@code name} */ public final Builder name(String value) { this.name = value; return this; } /** * API name: {@code settings} */ public final Builder settings(@Nullable IndexSettings value) { this.settings = value; return this; } /** * API name: {@code settings} */ public final Builder settings(Function> fn) { return this.settings(fn.apply(new IndexSettings.Builder()).build()); } /** * Required - API name: {@code template} */ public final Builder template(IndexState value) { this.template = value; return this; } /** * Required - API name: {@code template} */ public final Builder template(Function> fn) { return this.template(fn.apply(new IndexState.Builder()).build()); } /** * API name: {@code version} */ public final Builder version(@Nullable Long value) { this.version = value; return this; } @Override protected Builder self() { return this; } /** * Builds a {@link PutComponentTemplateRequest}. * * @throws NullPointerException * if some of the required fields are null. */ public PutComponentTemplateRequest build() { _checkSingleUse(); return new PutComponentTemplateRequest(this); } } // --------------------------------------------------------------------------------------------- /** * Json deserializer for {@link PutComponentTemplateRequest} */ public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer .lazy(Builder::new, PutComponentTemplateRequest::setupPutComponentTemplateRequestDeserializer); protected static void setupPutComponentTemplateRequestDeserializer( ObjectDeserializer op) { op.add(Builder::meta, JsonpDeserializer.stringMapDeserializer(JsonData._DESERIALIZER), "_meta"); op.add(Builder::aliases, JsonpDeserializer.stringMapDeserializer(AliasDefinition._DESERIALIZER), "aliases"); op.add(Builder::mappings, TypeMapping._DESERIALIZER, "mappings"); op.add(Builder::settings, IndexSettings._DESERIALIZER, "settings"); op.add(Builder::template, IndexState._DESERIALIZER, "template"); op.add(Builder::version, JsonpDeserializer.longDeserializer(), "version"); } // --------------------------------------------------------------------------------------------- /** * Endpoint "{@code cluster.put_component_template}". */ public static final Endpoint _ENDPOINT = new SimpleEndpoint<>( "es/cluster.put_component_template", // Request method request -> { return "PUT"; }, // Request path request -> { final int _name = 1 << 0; int propsSet = 0; propsSet |= _name; if (propsSet == (_name)) { StringBuilder buf = new StringBuilder(); buf.append("/_component_template"); buf.append("/"); SimpleEndpoint.pathEncode(request.name, buf); return buf.toString(); } throw SimpleEndpoint.noPathTemplateFound("path"); }, // Request parameters request -> { Map params = new HashMap<>(); if (request.masterTimeout != null) { params.put("master_timeout", request.masterTimeout._toJsonString()); } if (request.create != null) { params.put("create", String.valueOf(request.create)); } return params; }, SimpleEndpoint.emptyMap(), true, PutComponentTemplateResponse._DESERIALIZER); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy