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

org.opensearch.migrations.cli.Items Maven / Gradle / Ivy

package org.opensearch.migrations.cli;

import java.util.List;
import java.util.stream.Collectors;

import lombok.Builder;
import lombok.Data;
import lombok.NonNull;

/**
 * Either items that are candidates for migration or have been migrated;
 */
@Builder
@Data
public class Items {
    static final String NONE_FOUND_MARKER = "";
    private final boolean dryRun;
    @NonNull
    private final List indexTemplates;
    @NonNull
    private final List componentTemplates;
    @NonNull
    private final List indexes;
    @NonNull
    private final List aliases;

    public String asCliOutput() {
        var sb = new StringBuilder();
        if (isDryRun()) {
            sb.append("Migration Candidates:" + System.lineSeparator());
        } else {
            sb.append("Migrated Items:" + System.lineSeparator());
        }
        sb.append(Format.indentToLevel(1) + "Index Templates:" + System.lineSeparator());
        sb.append(Format.indentToLevel(2) + getPrintableList(getIndexTemplates()) + System.lineSeparator());
        sb.append(System.lineSeparator());
        sb.append(Format.indentToLevel(1) + "Component Templates:" + System.lineSeparator());
        sb.append(Format.indentToLevel(2) +getPrintableList(getComponentTemplates()) + System.lineSeparator());
        sb.append(System.lineSeparator());
        sb.append(Format.indentToLevel(1) + "Indexes:" + System.lineSeparator());
        sb.append(Format.indentToLevel(2) + getPrintableList(getIndexes()) + System.lineSeparator());
        sb.append(System.lineSeparator());
        sb.append(Format.indentToLevel(1) + "Aliases:" + System.lineSeparator());
        sb.append(Format.indentToLevel(2) +getPrintableList(getAliases()) + System.lineSeparator());
        sb.append(System.lineSeparator());
        return sb.toString();
    }

    private String getPrintableList(List list) {
        if (list == null || list.isEmpty()) {
            return NONE_FOUND_MARKER;
        }
        return list.stream().sorted().collect(Collectors.joining(", "));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy