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