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

io.searchbox.indices.aliases.ModifyAliases Maven / Gradle / Ivy

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

import com.google.common.collect.ImmutableMap;
import io.searchbox.action.GenericResultAbstractAction;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author cihat keser
 */
public class ModifyAliases extends GenericResultAbstractAction {

    protected ModifyAliases(Builder builder) {
        super(builder);

        List actions = new LinkedList();
        for (AliasMapping aliasMapping : builder.actions) {
            actions.addAll(aliasMapping.getData());
        }
        this.payload = ImmutableMap.of("actions", actions);
        setURI(buildURI());
    }

    @Override
    protected String buildURI() {
        return super.buildURI() + "/_aliases";
    }

    @Override
    public String getRestMethodName() {
        return "POST";
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder()
                .appendSuper(super.hashCode())
                .toHashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (obj.getClass() != getClass()) {
            return false;
        }

        return new EqualsBuilder()
                .appendSuper(super.equals(obj))
                .isEquals();
    }

    public static class Builder extends GenericResultAbstractAction.Builder {
        private List actions = new LinkedList();

        public Builder(AliasMapping action) {
            actions.add(action);
        }

        public Builder(Collection actions) {
            this.actions.addAll(actions);
        }

        public Builder addAlias(AliasMapping action) {
            actions.add(action);
            return this;
        }

        public Builder addAlias(Collection actions) {
            this.actions.addAll(actions);
            return this;
        }

        public ModifyAliases build() {
            return new ModifyAliases(this);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy