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

com.couchbase.client.core.api.manager.search.CoreSearchIndex Maven / Gradle / Ivy

There is a newer version: 3.7.2
Show newest version
/*
 * Copyright (c) 2023 Couchbase, Inc.
 *
 * Licensed 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 com.couchbase.client.core.api.manager.search;

import com.couchbase.client.core.annotation.Stability;
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonCreator;
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.couchbase.client.core.deps.com.fasterxml.jackson.annotation.JsonProperty;
import com.couchbase.client.core.error.InvalidArgumentException;
import com.couchbase.client.core.json.Mapper;

import java.util.HashMap;
import java.util.Map;

import static com.couchbase.client.core.util.CbCollections.isNullOrEmpty;


@Stability.Internal
@JsonIgnoreProperties(ignoreUnknown = true)
public class CoreSearchIndex {

  private final String name;
  private final String sourceName;

  private String uuid;
  private String type;
  private Map params;
  private String sourceUuid;
  private Map sourceParams;
  private String sourceType;
  private Map planParams;

  public CoreSearchIndex(final String name, final String sourceName) {
    this.name = name;
    this.sourceName = sourceName;
  }

  @JsonCreator
  public CoreSearchIndex(
    @JsonProperty("uuid") String uuid,
    @JsonProperty("name") String name,
    @JsonProperty("type") String type,
    @JsonProperty("params") Map params,
    @JsonProperty("sourceUUID") String sourceUuid,
    @JsonProperty("sourceName") String sourceName,
    @JsonProperty("sourceParams") Map sourceParams,
    @JsonProperty("sourceType") String sourceType,
    @JsonProperty("planParams") Map planParams) {
    this.uuid = uuid;
    this.name = name;
    this.sourceName = sourceName;
    this.type = type;
    this.params = params;
    this.sourceUuid = sourceUuid;
    this.sourceParams = sourceParams;
    this.sourceType = sourceType;
    this.planParams = planParams;
  }

  public static CoreSearchIndex fromJson(final String input) {
    try {
      return Mapper.decodeInto(input, CoreSearchIndex.class);
    } catch (Exception ex) {
      throw InvalidArgumentException.fromMessage("Could not decode search index JSON", ex);
    }
  }

  public String name() {
    return name;
  }

  public String uuid() {
    return uuid;
  }

  public CoreSearchIndex uuid(String uuid) {
    this.uuid = uuid;
    return this;
  }
  public CoreSearchIndex unsetUuid() {
    this.uuid = null;
    return this;
  }

  public String sourceName() {
    return sourceName;
  }

  public String type() {
    return type;
  }

  public Map params() {
    return params;
  }

  public CoreSearchIndex params(Map params) {
    this.params = params;
    return this;
  }

  public String sourceUuid() {
    return sourceUuid;
  }

  public CoreSearchIndex sourceUuid(String sourceUuid) {
    this.sourceUuid = sourceUuid;
    return this;
  }

  public Map sourceParams() {
    return sourceParams;
  }

  public CoreSearchIndex sourceParams(Map sourceParams) {
    this.sourceParams = sourceParams;
    return this;
  }

  public String sourceType() {
    return sourceType;
  }

  public CoreSearchIndex sourceType(String sourceType) {
    this.sourceType = sourceType;
    return this;
  }

  public Map planParams() {
    return planParams;
  }

  public CoreSearchIndex planParams(Map planParams) {
    this.planParams = planParams;
    return this;
  }

  public String toJson() {
    Map output = new HashMap<>();
    // A UUID is server-assigned.  It must be specified on an update, and must not be specified on a create.
    if (uuid != null) {
      output.put("uuid", uuid);
    }
    output.put("name", name);
    output.put("sourceName", sourceName);
    output.put("type", type == null ? "fulltext-index" : type);
    output.put("sourceType", sourceType == null ? "couchbase" : sourceType);

    if (!isNullOrEmpty(params))  {
      output.put("params", params);
    }
    if (!isNullOrEmpty(planParams)) {
      output.put("planParams", planParams);
    }
    if (!isNullOrEmpty(sourceParams)) {
      output.put("sourceParams", sourceParams);
    }
    if (sourceUuid != null) {
      output.put("sourceUUID", sourceUuid);
    }

    return Mapper.encodeAsString(output);
  }

  @Override
  public String toString() {
    return "CoreSearchIndex{" +
      "uuid='" + uuid + '\'' +
      ", name='" + name + '\'' +
      ", sourceName='" + sourceName + '\'' +
      ", type='" + type + '\'' +
      ", params=" + params +
      ", sourceUuid='" + sourceUuid + '\'' +
      ", sourceParams=" + sourceParams +
      ", sourceType='" + sourceType + '\'' +
      ", planParams=" + planParams +
      '}';
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy