io.weaviate.client.v1.data.util.ReferencesPath Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client Show documentation
Show all versions of client Show documentation
A java client for Weaviate Vector Search Engine
// Generated by delombok at Tue Mar 05 13:44:27 UTC 2024
package io.weaviate.client.v1.data.util;
import io.weaviate.client.base.util.DbVersionSupport;
import io.weaviate.client.base.util.TriConsumer;
import io.weaviate.client.base.util.UrlEncoder;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class ReferencesPath {
private final DbVersionSupport support;
public ReferencesPath(DbVersionSupport support) {
this.support = support;
}
public String buildCreate(Params params) {
return commonBuild(params);
}
public String buildDelete(Params params) {
return commonBuild(params);
}
public String buildReplace(Params params) {
return commonBuild(params);
}
private String commonBuild(Params params) {
return build(params, this::addPathClassNameWithDeprecatedNotSupportedCheck, this::addPathId, this::addPathReferences, this::addPathProperty, this::addQueryConsistencyLevel, this::addQueryTenant);
}
@SafeVarargs
private final String build(Params params, TriConsumer, List>... appenders) {
Objects.requireNonNull(params);
List pathParams = new ArrayList<>();
List queryParams = new ArrayList<>();
pathParams.add("/objects");
Arrays.stream(appenders).forEach(consumer -> consumer.accept(params, pathParams, queryParams));
String path = String.join("/", pathParams);
if (!queryParams.isEmpty()) {
return path + "?" + String.join("&", queryParams);
}
return path;
}
private void addPathClassNameWithDeprecatedNotSupportedCheck(Params params, List pathParams, List queryParams) {
if (support.supportsClassNameNamespacedEndpoints()) {
if (StringUtils.isNotBlank(params.className)) {
pathParams.add(UrlEncoder.encodePathParam(params.className));
} else {
support.warnDeprecatedNonClassNameNamespacedEndpointsForObjects();
}
} else if (StringUtils.isNotBlank(params.className)) {
support.warnNotSupportedClassNamespacedEndpointsForObjects();
}
}
private void addPathId(Params params, List pathParams, List queryParams) {
if (StringUtils.isNotBlank(params.id)) {
pathParams.add(UrlEncoder.encodePathParam(params.id));
}
}
private void addPathReferences(Params params, List pathParams, List queryParams) {
pathParams.add("references");
}
private void addPathProperty(Params params, List pathParams, List queryParams) {
if (StringUtils.isNotBlank(params.property)) {
pathParams.add(UrlEncoder.encodePathParam(params.property));
}
}
private void addQueryConsistencyLevel(Params params, List pathParams, List queryParams) {
if (StringUtils.isNotBlank(params.consistencyLevel)) {
queryParams.add(UrlEncoder.encodeQueryParam("consistency_level", params.consistencyLevel));
}
}
private void addQueryTenant(Params params, List pathParams, List queryParams) {
if (StringUtils.isNotBlank(params.tenant)) {
queryParams.add(UrlEncoder.encodeQueryParam("tenant", params.tenant));
}
}
public static class Params {
private final String id;
private final String className;
private final String consistencyLevel;
private final String tenant;
private final String property;
@java.lang.SuppressWarnings("all")
Params(final String id, final String className, final String consistencyLevel, final String tenant, final String property) {
this.id = id;
this.className = className;
this.consistencyLevel = consistencyLevel;
this.tenant = tenant;
this.property = property;
}
@java.lang.SuppressWarnings("all")
public static class ParamsBuilder {
@java.lang.SuppressWarnings("all")
private String id;
@java.lang.SuppressWarnings("all")
private String className;
@java.lang.SuppressWarnings("all")
private String consistencyLevel;
@java.lang.SuppressWarnings("all")
private String tenant;
@java.lang.SuppressWarnings("all")
private String property;
@java.lang.SuppressWarnings("all")
ParamsBuilder() {
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public ReferencesPath.Params.ParamsBuilder id(final String id) {
this.id = id;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public ReferencesPath.Params.ParamsBuilder className(final String className) {
this.className = className;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public ReferencesPath.Params.ParamsBuilder consistencyLevel(final String consistencyLevel) {
this.consistencyLevel = consistencyLevel;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public ReferencesPath.Params.ParamsBuilder tenant(final String tenant) {
this.tenant = tenant;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public ReferencesPath.Params.ParamsBuilder property(final String property) {
this.property = property;
return this;
}
@java.lang.SuppressWarnings("all")
public ReferencesPath.Params build() {
return new ReferencesPath.Params(this.id, this.className, this.consistencyLevel, this.tenant, this.property);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "ReferencesPath.Params.ParamsBuilder(id=" + this.id + ", className=" + this.className + ", consistencyLevel=" + this.consistencyLevel + ", tenant=" + this.tenant + ", property=" + this.property + ")";
}
}
@java.lang.SuppressWarnings("all")
public static ReferencesPath.Params.ParamsBuilder builder() {
return new ReferencesPath.Params.ParamsBuilder();
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "ReferencesPath.Params(id=" + this.id + ", className=" + this.className + ", consistencyLevel=" + this.consistencyLevel + ", tenant=" + this.tenant + ", property=" + this.property + ")";
}
}
}