001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2006-2008 Sun Microsystems, Inc. 015 * Portions Copyright 2013-2015 ForgeRock AS. 016 */ 017package org.opends.quicksetup.installer; 018 019import java.util.LinkedList; 020import java.util.List; 021 022/** 023 * This class is used to provide a data model for the Data Options panel of the 024 * installer. 025 */ 026public class NewSuffixOptions 027{ 028 /** 029 * This enumeration is used to know what the user wants to do for the data 030 * (import data or not, what use as source of the data...). 031 */ 032 public enum Type 033 { 034 /** 035 * Create base entry. 036 */ 037 CREATE_BASE_ENTRY, 038 /** 039 * Do not add any entry to the suffix. 040 */ 041 LEAVE_DATABASE_EMPTY, 042 /** 043 * Import data from an LDIF file. 044 */ 045 IMPORT_FROM_LDIF_FILE, 046 /** 047 * Generate data and import it to the suffix. 048 */ 049 IMPORT_AUTOMATICALLY_GENERATED_DATA 050 } 051 052 private Type type; 053 054 private List<String> baseDns = new LinkedList<>(); 055 056 private List<String> ldifPaths = new LinkedList<>(); 057 058 private String rejectedFile; 059 private String skippedFile; 060 061 private int numberEntries = 2000; 062 063 /** 064 * Private constructor. 065 * @param baseDns the base DNs of the suffix options. 066 */ 067 private NewSuffixOptions(List<String> baseDns) 068 { 069 this.baseDns.addAll(baseDns); 070 } 071 072 /** 073 * Creates a base entry suffix options. 074 * @param baseDNs the base DNs of the suffix options. 075 * @return a base entry suffix options. 076 */ 077 public static NewSuffixOptions createBaseEntry(List<String> baseDNs) 078 { 079 NewSuffixOptions ops = new NewSuffixOptions(baseDNs); 080 ops.type = Type.CREATE_BASE_ENTRY; 081 return ops; 082 } 083 084 /** 085 * Creates an empty suffix options. 086 * @param baseDNs the base DNs of the suffix options. 087 * @return an empty suffix options. 088 */ 089 public static NewSuffixOptions createEmpty(List<String> baseDNs) 090 { 091 NewSuffixOptions ops = new NewSuffixOptions(baseDNs); 092 ops.type = Type.LEAVE_DATABASE_EMPTY; 093 return ops; 094 } 095 096 /** 097 * Creates a base entry suffix options. 098 * @param baseDNs the base DNs of the suffix options. 099 * @param ldifPaths the LDIF files to be imported. 100 * @param rejectedFile the files where the rejected entries are stored. 101 * @param skippedFile the files where the skipped entries are stored. 102 * @return a base entry suffix options. 103 */ 104 public static NewSuffixOptions createImportFromLDIF(List<String> baseDNs, 105 List<String> ldifPaths, String rejectedFile, String skippedFile) 106 { 107 NewSuffixOptions ops = new NewSuffixOptions(baseDNs); 108 ops.type = Type.IMPORT_FROM_LDIF_FILE; 109 ops.ldifPaths.addAll(ldifPaths); 110 ops.rejectedFile = rejectedFile; 111 ops.skippedFile = skippedFile; 112 return ops; 113 } 114 115 /** 116 * Creates an automatically generated entries suffix options. 117 * @param baseDNs the base DNs of the suffix options. 118 * @param numberEntries the number of entries to generate. 119 * @return a base entry suffix options. 120 */ 121 public static NewSuffixOptions createAutomaticallyGenerated( 122 List<String> baseDNs, int numberEntries) 123 { 124 NewSuffixOptions ops = new NewSuffixOptions(baseDNs); 125 ops.type = Type.IMPORT_AUTOMATICALLY_GENERATED_DATA; 126 ops.numberEntries = numberEntries; 127 return ops; 128 } 129 130 /** 131 * Returns the type of NewSuffixOptions represented by this object (import 132 * data or not, what use as source of the data...). 133 * 134 * @return the type of NewSuffixOptions. 135 */ 136 public Type getType() 137 { 138 return type; 139 } 140 141 /** 142 * Returns the path of the LDIF file used to import data. 143 * @return the path of the LDIF file used to import data. 144 */ 145 public LinkedList<String> getLDIFPaths() 146 { 147 return new LinkedList<>(ldifPaths); 148 } 149 150 /** 151 * Returns the path to store the rejected entries of the import. 152 * <CODE>null</CODE> if no rejected file is specified. 153 * 154 * @return the path to store the rejected entries of the import. 155 * <CODE>null</CODE> if no rejected file is specified. 156 */ 157 public String getRejectedFile() 158 { 159 return rejectedFile; 160 } 161 162 /** 163 * Returns the path to store the skipped entries of the import. 164 * <CODE>null</CODE> if no skipped file is specified. 165 * 166 * @return the path to store the skipped entries of the import. 167 * <CODE>null</CODE> if no skipped file is specified. 168 */ 169 public String getSkippedFile() 170 { 171 return skippedFile; 172 } 173 174 /** 175 * Returns the number of entries that will be automatically generated. 176 * 177 * @return the number of entries that will be automatically generated. 178 */ 179 public int getNumberEntries() 180 { 181 return numberEntries; 182 } 183 184 /** 185 * Returns the base DN of the suffix that will be created in the server. 186 * 187 * @return the base DN of the suffix that will be created in the server. 188 */ 189 public LinkedList<String> getBaseDns() 190 { 191 return new LinkedList<>(baseDns); 192 } 193 194 /** 195 * Returns {@link InstallProgressStep} equivalent to the type of new suffix 196 * options. 197 * 198 * @return Returns {@link InstallProgressStep} equivalent to the type of new 199 * suffix options. 200 */ 201 public InstallProgressStep getInstallProgressStep() 202 { 203 switch (type) 204 { 205 case CREATE_BASE_ENTRY: 206 return InstallProgressStep.CREATING_BASE_ENTRY; 207 case IMPORT_FROM_LDIF_FILE: 208 return InstallProgressStep.IMPORTING_LDIF; 209 case IMPORT_AUTOMATICALLY_GENERATED_DATA: 210 return InstallProgressStep.IMPORTING_AUTOMATICALLY_GENERATED; 211 default: 212 return null; 213 } 214 } 215}