mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
01.51.2025 512d2351717cb9301643fa34c4631efc5e4616c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2008 Sun Microsystems, Inc.
 * Portions Copyright 2013-2016 ForgeRock AS.
 */
package org.opends.quicksetup.installer;
 
import java.util.LinkedList;
import java.util.List;
 
/** This class is used to provide a data model for the Data Options panel of the installer. */
public class NewSuffixOptions
{
  /**
   * This enumeration is used to know what the user wants to do for the data
   * (import data or not, what use as source of the data...).
   */
  public enum Type
  {
    /** Create base entry. */
    CREATE_BASE_ENTRY,
    /** Do not add any entry to the suffix. */
    LEAVE_DATABASE_EMPTY,
    /** Import data from an LDIF file. */
    IMPORT_FROM_LDIF_FILE,
    /** Generate data and import it to the suffix. */
    IMPORT_AUTOMATICALLY_GENERATED_DATA
  }
 
  private Type type;
 
  private List<String> baseDns = new LinkedList<>();
 
  private List<String> ldifPaths = new LinkedList<>();
 
  private String rejectedFile;
  private String skippedFile;
 
  private int numberEntries = 2000;
 
  /**
   * Private constructor.
   * @param baseDns the base DNs of the suffix options.
   */
  private NewSuffixOptions(List<String> baseDns)
  {
    this.baseDns.addAll(baseDns);
  }
 
  /**
   * Creates a base entry suffix options.
   * @param baseDNs the base DNs of the suffix options.
   * @return a base entry suffix options.
   */
  public static NewSuffixOptions createBaseEntry(List<String> baseDNs)
  {
    NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
    ops.type = Type.CREATE_BASE_ENTRY;
    return ops;
  }
 
  /**
   * Creates an empty suffix options.
   * @param baseDNs the base DNs of the suffix options.
   * @return an empty suffix options.
   */
  public static NewSuffixOptions createEmpty(List<String> baseDNs)
  {
    NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
    ops.type = Type.LEAVE_DATABASE_EMPTY;
    return ops;
  }
 
  /**
   * Creates a base entry suffix options.
   * @param baseDNs the base DNs of the suffix options.
   * @param ldifPaths the LDIF files to be imported.
   * @param rejectedFile the files where the rejected entries are stored.
   * @param skippedFile the files where the skipped entries are stored.
   * @return a base entry suffix options.
   */
  public static NewSuffixOptions createImportFromLDIF(List<String> baseDNs,
      List<String> ldifPaths, String rejectedFile, String skippedFile)
  {
    NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
    ops.type = Type.IMPORT_FROM_LDIF_FILE;
    ops.ldifPaths.addAll(ldifPaths);
    ops.rejectedFile = rejectedFile;
    ops.skippedFile = skippedFile;
    return ops;
  }
 
  /**
   * Creates an automatically generated entries suffix options.
   * @param baseDNs the base DNs of the suffix options.
   * @param numberEntries the number of entries to generate.
   * @return a base entry suffix options.
   */
  public static NewSuffixOptions createAutomaticallyGenerated(
      List<String> baseDNs, int numberEntries)
  {
    NewSuffixOptions ops = new NewSuffixOptions(baseDNs);
    ops.type = Type.IMPORT_AUTOMATICALLY_GENERATED_DATA;
    ops.numberEntries = numberEntries;
    return ops;
  }
 
  /**
   * Returns the type of NewSuffixOptions represented by this object (import
   * data or not, what use as source of the data...).
   *
   * @return the type of NewSuffixOptions.
   */
  public Type getType()
  {
    return type;
  }
 
  /**
   * Returns the path of the LDIF file used to import data.
   * @return the path of the LDIF file used to import data.
   */
  public LinkedList<String> getLDIFPaths()
  {
    return new LinkedList<>(ldifPaths);
  }
 
  /**
   * Returns the path to store the rejected entries of the import.
   * <CODE>null</CODE> if no rejected file is specified.
   *
   * @return the path to store the rejected entries of the import.
   * <CODE>null</CODE> if no rejected file is specified.
   */
  public String getRejectedFile()
  {
    return rejectedFile;
  }
 
  /**
   * Returns the path to store the skipped entries of the import.
   * <CODE>null</CODE> if no skipped file is specified.
   *
   * @return the path to store the skipped entries of the import.
   * <CODE>null</CODE> if no skipped file is specified.
   */
  public String getSkippedFile()
  {
    return skippedFile;
  }
 
  /**
   * Returns the number of entries that will be automatically generated.
   *
   * @return the number of entries that will be automatically generated.
   */
  public int getNumberEntries()
  {
    return numberEntries;
  }
 
  /**
   * Returns the base DN of the suffix that will be created in the server.
   *
   * @return the base DN of the suffix that will be created in the server.
   */
  public LinkedList<String> getBaseDns()
  {
    return new LinkedList<>(baseDns);
  }
 
  /**
   * Returns {@link InstallProgressStep} equivalent to the type of new suffix
   * options.
   *
   * @return Returns {@link InstallProgressStep} equivalent to the type of new
   *         suffix options.
   */
  public InstallProgressStep getInstallProgressStep()
  {
    switch (type)
    {
    case CREATE_BASE_ENTRY:
      return InstallProgressStep.CREATING_BASE_ENTRY;
    case IMPORT_FROM_LDIF_FILE:
      return InstallProgressStep.IMPORTING_LDIF;
    case IMPORT_AUTOMATICALLY_GENERATED_DATA:
      return InstallProgressStep.IMPORTING_AUTOMATICALLY_GENERATED;
    default:
      return null;
    }
  }
}