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

io.searchbox.action.AbstractDocumentTargetedAction Maven / Gradle / Ivy

There is a newer version: 6.3.1
Show newest version
package io.searchbox.action;

import io.searchbox.client.JestResult;
import org.apache.commons.lang3.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @author cihat keser
 */
public abstract class AbstractDocumentTargetedAction extends AbstractAction implements DocumentTargetedAction {

    protected String id;

    public AbstractDocumentTargetedAction(Builder builder) {
        super(builder);
        indexName = builder.index;
        typeName = builder.type;
        id = builder.id;
    }

    @Override
    public String getIndex() {
        return indexName;
    }

    @Override
    public String getType() {
        return typeName;
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    protected String buildURI() {
        StringBuilder sb = new StringBuilder(super.buildURI());

        if (StringUtils.isNotBlank(id)) {
            try {
                sb.append("/").append(URLEncoder.encode(id, CHARSET));
            } catch (UnsupportedEncodingException e) {
                log.error("Error occurred while adding document id to uri.", e);
            }
        }
        return sb.toString();
    }

    @SuppressWarnings("unchecked")
    protected abstract static class Builder extends AbstractAction.Builder {
        private String index;
        private String type;
        private String id;

        public K index(String index) {
            this.index = index;
            return (K) this;
        }

        public K type(String type) {
            this.type = type;
            return (K) this;
        }

        public K id(String id) {
            this.id = id;
            return (K) this;
        }

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy