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-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2013-2015 ForgeRock AS.
026 */
027package org.opends.quicksetup.installer;
028
029import java.util.LinkedList;
030import java.util.List;
031
032/**
033 * This class is used to provide a data model for the Data Options panel of the
034 * installer.
035 */
036public class NewSuffixOptions
037{
038  /**
039   * This enumeration is used to know what the user wants to do for the data
040   * (import data or not, what use as source of the data...).
041   */
042  public enum Type
043  {
044    /**
045     * Create base entry.
046     */
047    CREATE_BASE_ENTRY,
048    /**
049     * Do not add any entry to the suffix.
050     */
051    LEAVE_DATABASE_EMPTY,
052    /**
053     * Import data from an LDIF file.
054     */
055    IMPORT_FROM_LDIF_FILE,
056    /**
057     * Generate data and import it to the suffix.
058     */
059    IMPORT_AUTOMATICALLY_GENERATED_DATA
060  }
061
062  private Type type;
063
064  private List<String> baseDns = new LinkedList<>();
065
066  private List<String> ldifPaths = new LinkedList<>();
067
068  private String rejectedFile;
069  private String skippedFile;
070
071  private int numberEntries = 2000;
072
073  /**
074   * Private constructor.
075   * @param baseDns the base DNs of the suffix options.
076   */
077  private NewSuffixOptions(List<String> baseDns)
078  {
079    this.baseDns.addAll(baseDns);
080  }
081
082  /**
083   * Creates a base entry suffix options.
084   * @param baseDNs the base DNs of the suffix options.
085   * @return a base entry suffix options.
086   */
087  public static NewSuffixOptions createBaseEntry(List<String> baseDNs)
088  {
089    NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
090    ops.type = Type.CREATE_BASE_ENTRY;
091    return ops;
092  }
093
094  /**
095   * Creates an empty suffix options.
096   * @param baseDNs the base DNs of the suffix options.
097   * @return an empty suffix options.
098   */
099  public static NewSuffixOptions createEmpty(List<String> baseDNs)
100  {
101    NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
102    ops.type = Type.LEAVE_DATABASE_EMPTY;
103    return ops;
104  }
105
106  /**
107   * Creates a base entry suffix options.
108   * @param baseDNs the base DNs of the suffix options.
109   * @param ldifPaths the LDIF files to be imported.
110   * @param rejectedFile the files where the rejected entries are stored.
111   * @param skippedFile the files where the skipped entries are stored.
112   * @return a base entry suffix options.
113   */
114  public static NewSuffixOptions createImportFromLDIF(List<String> baseDNs,
115      List<String> ldifPaths, String rejectedFile, String skippedFile)
116  {
117    NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
118    ops.type = Type.IMPORT_FROM_LDIF_FILE;
119    ops.ldifPaths.addAll(ldifPaths);
120    ops.rejectedFile = rejectedFile;
121    ops.skippedFile = skippedFile;
122    return ops;
123  }
124
125  /**
126   * Creates an automatically generated entries suffix options.
127   * @param baseDNs the base DNs of the suffix options.
128   * @param numberEntries the number of entries to generate.
129   * @return a base entry suffix options.
130   */
131  public static NewSuffixOptions createAutomaticallyGenerated(
132      List<String> baseDNs, int numberEntries)
133  {
134    NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
135    ops.type = Type.IMPORT_AUTOMATICALLY_GENERATED_DATA;
136    ops.numberEntries = numberEntries;
137    return ops;
138  }
139
140  /**
141   * Returns the type of NewSuffixOptions represented by this object (import
142   * data or not, what use as source of the data...).
143   *
144   * @return the type of NewSuffixOptions.
145   */
146  public Type getType()
147  {
148    return type;
149  }
150
151  /**
152   * Returns the path of the LDIF file used to import data.
153   * @return the path of the LDIF file used to import data.
154   */
155  public LinkedList<String> getLDIFPaths()
156  {
157    return new LinkedList<>(ldifPaths);
158  }
159
160  /**
161   * Returns the path to store the rejected entries of the import.
162   * <CODE>null</CODE> if no rejected file is specified.
163   *
164   * @return the path to store the rejected entries of the import.
165   * <CODE>null</CODE> if no rejected file is specified.
166   */
167  public String getRejectedFile()
168  {
169    return rejectedFile;
170  }
171
172  /**
173   * Returns the path to store the skipped entries of the import.
174   * <CODE>null</CODE> if no skipped file is specified.
175   *
176   * @return the path to store the skipped entries of the import.
177   * <CODE>null</CODE> if no skipped file is specified.
178   */
179  public String getSkippedFile()
180  {
181    return skippedFile;
182  }
183
184  /**
185   * Returns the number of entries that will be automatically generated.
186   *
187   * @return the number of entries that will be automatically generated.
188   */
189  public int getNumberEntries()
190  {
191    return numberEntries;
192  }
193
194  /**
195   * Returns the base DN of the suffix that will be created in the server.
196   *
197   * @return the base DN of the suffix that will be created in the server.
198   */
199  public LinkedList<String> getBaseDns()
200  {
201    return new LinkedList<>(baseDns);
202  }
203
204  /**
205   * Returns {@link InstallProgressStep} equivalent to the type of new suffix
206   * options.
207   *
208   * @return Returns {@link InstallProgressStep} equivalent to the type of new
209   *         suffix options.
210   */
211  public InstallProgressStep getInstallProgressStep()
212  {
213    switch (type)
214    {
215    case CREATE_BASE_ENTRY:
216      return InstallProgressStep.CREATING_BASE_ENTRY;
217    case IMPORT_FROM_LDIF_FILE:
218      return InstallProgressStep.IMPORTING_LDIF;
219    case IMPORT_AUTOMATICALLY_GENERATED_DATA:
220      return InstallProgressStep.IMPORTING_AUTOMATICALLY_GENERATED;
221    default:
222      return null;
223    }
224  }
225}