001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2010 Sun Microsystems, Inc.
025 *      Portions Copyright 2015 ForgeRock AS
026 */
027package org.opends.quicksetup.installer;
028
029import java.util.HashMap;
030import java.util.LinkedHashSet;
031import java.util.Map;
032import java.util.Set;
033
034import org.opends.admin.ads.SuffixDescriptor;
035import org.opends.server.tools.BackendTypeHelper.BackendTypeUIAdapter;
036
037/**
038 * This class is used to provide a data model for the Suffix to Replicate
039 * Options panel of the installer.
040 */
041public class SuffixesToReplicateOptions
042{
043  /**
044   * This enumeration is used to know what the user wants to do for the data
045   * (import data or not, what use as source of the data...).
046   */
047  public enum Type
048  {
049    /** Do not replicate suffix. */
050    NO_SUFFIX_TO_REPLICATE,
051
052    /** This is a new suffix in topology.. */
053    NEW_SUFFIX_IN_TOPOLOGY,
054
055    /** Replicate Contents of the new Suffix with existings server. */
056    REPLICATE_WITH_EXISTING_SUFFIXES
057  }
058
059  private Type type;
060  private Set<SuffixDescriptor> availableSuffixes;
061  private Set<SuffixDescriptor> suffixesToReplicate;
062  private Map<String, BackendTypeUIAdapter> backendsToReplicate;
063
064  /**
065   * Constructor for the SuffixesToReplicateOptions object.
066   *
067   * @param type
068   *          the Type of DataReplicationOptions.
069   * @param availableSuffixes
070   *          The set of suffixes which are available for replication.
071   * @param suffixesToReplicate
072   *          The set of suffixes which user wants to replicate.
073   */
074  public SuffixesToReplicateOptions(Type type, Set<SuffixDescriptor> availableSuffixes,
075      Set<SuffixDescriptor> suffixesToReplicate)
076  {
077    this(type, availableSuffixes, suffixesToReplicate, new HashMap<String, BackendTypeUIAdapter>());
078  }
079
080  /**
081   * Constructor for the SuffixesToReplicateOptions object.
082   *
083   * @param type
084   *          the Type of DataReplicationOptions.
085   * @param availableSuffixes
086   *          The set of suffixes which are available for replication.
087   * @param suffixesToReplicate
088   *          The set of suffixes which user wants to replicate.
089   * @param backendsToReplicate
090   *          The map with backend name as keys and their associated backend type
091   *          as value.
092   */
093  public SuffixesToReplicateOptions(Type type, Set<SuffixDescriptor> availableSuffixes,
094      Set<SuffixDescriptor> suffixesToReplicate, Map<String, BackendTypeUIAdapter> backendsToReplicate)
095  {
096    this.type = type;
097    this.availableSuffixes = new LinkedHashSet<>(availableSuffixes);
098    this.suffixesToReplicate = new LinkedHashSet<>(suffixesToReplicate);
099    this.backendsToReplicate = new HashMap<>(backendsToReplicate);
100  }
101
102  /**
103   * Returns the type of SuffixesToReplicateOptions represented by this object
104   * (replicate or not).
105   *
106   * @return the type of SuffixesToReplicateOptions.
107   */
108  public Type getType()
109  {
110    return type;
111  }
112
113  /**
114   * Returns the set of suffixes available for replication.
115   *
116   * @return the set of suffixes available for replication.
117   */
118  public Set<SuffixDescriptor> getAvailableSuffixes()
119  {
120    return availableSuffixes;
121  }
122
123  /**
124   * The set of suffixes that we must replicate with.
125   *
126   * @return the set of suffixes that we must replicate with.
127   */
128  public Set<SuffixDescriptor> getSuffixes()
129  {
130    return suffixesToReplicate;
131  }
132
133  /**
134   * Returns a map which associate backend names and backend types.
135   *
136   * @return A map which associate backend names and backend types.
137   */
138  public Map<String, BackendTypeUIAdapter> getSuffixBackendTypes()
139  {
140    return backendsToReplicate;
141  }
142}