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

io.searchbox.snapshot.AbstractSnapshotAction Maven / Gradle / Ivy

package io.searchbox.snapshot;

import io.searchbox.action.GenericResultAbstractAction;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

/**
 * @author ckeser
 */
public abstract class AbstractSnapshotAction extends GenericResultAbstractAction {

    private String repository;
    private String snapshots;

    protected AbstractSnapshotAction(SnapshotBuilder builder) {
        super(builder);

        this.repository = builder.repository;
        this.snapshots = builder.getSnapshots();
        setURI(buildURI());
    }

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

    public abstract static class SnapshotBuilder extends Builder {
        protected String repository;

        protected SnapshotBuilder(String repository) {
            this.repository = repository;
        }

        protected abstract String getSnapshots();
    }

    public abstract static class SingleSnapshotBuilder extends SnapshotBuilder {
        private String snapshot;

        public SingleSnapshotBuilder(String repository, String snapshot) {
            super(repository);
            this.snapshot = snapshot;
        }

        @Override
        protected String getSnapshots() {
            return snapshot;
        }
    }

    @SuppressWarnings("unchecked")
    public abstract static class MultipleSnapshotBuilder extends SnapshotBuilder {
        private Set snapshots = new LinkedHashSet();

        public MultipleSnapshotBuilder(String repository) {
            super(repository);
        }

        public K addSnapshot(Collection snapshots) {
            this.snapshots.addAll(snapshots);
            return (K) this;
        }

        public K addSnapshot(String snapshot) {
            this.snapshots.add(snapshot);
            return (K) this;
        }

        @Override
        protected String getSnapshots() {
            if (snapshots.isEmpty()) {
                return "_all";
            } else {
                return StringUtils.join(snapshots, ",");
            }
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy