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 2015 ForgeRock AS. 015 */ 016package org.opends.guitools.controlpanel.datamodel; 017 018import java.util.HashSet; 019import java.util.LinkedHashSet; 020import java.util.Set; 021 022import org.opends.server.admin.std.meta.BackendIndexCfgDefn; 023import org.opends.server.util.RemoveOnceNewConfigFrameworkIsUsed; 024 025/** 026 * Defines the set of values for the index type and provides adaptors to convert 027 * from/to corresponding configuration classes. 028 */ 029@RemoveOnceNewConfigFrameworkIsUsed 030public enum IndexTypeDescriptor 031{ 032 /** 033 * This index type is used to improve the efficiency of searches using 034 * approximate matching search filters. 035 */ 036 APPROXIMATE(BackendIndexCfgDefn.IndexType.APPROXIMATE, 037 org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType.APPROXIMATE), 038 039 /** 040 * This index type is used to improve the efficiency of searches using 041 * equality search filters. 042 */ 043 EQUALITY(BackendIndexCfgDefn.IndexType.EQUALITY, 044 org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType.EQUALITY), 045 046 /** 047 * This index type is used to improve the efficiency of searches using 048 * extensible matching search filters. 049 */ 050 EXTENSIBLE(BackendIndexCfgDefn.IndexType.EXTENSIBLE, 051 org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType.EXTENSIBLE), 052 053 /** 054 * This index type is used to improve the efficiency of searches using 055 * "greater than or equal to" or "less then or equal to" search filters. 056 */ 057 ORDERING(BackendIndexCfgDefn.IndexType.ORDERING, 058 org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType.ORDERING), 059 060 /** 061 * This index type is used to improve the efficiency of searches using the 062 * presence search filters. 063 */ 064 PRESENCE(BackendIndexCfgDefn.IndexType.PRESENCE, 065 org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType.PRESENCE), 066 067 /** 068 * This index type is used to improve the efficiency of searches using 069 * substring search filters. 070 */ 071 SUBSTRING(BackendIndexCfgDefn.IndexType.SUBSTRING, 072 org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType.SUBSTRING); 073 074 private final BackendIndexCfgDefn.IndexType oldConfigBackendIndexType; 075 private final org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType backendIndexType; 076 077 private IndexTypeDescriptor(final BackendIndexCfgDefn.IndexType oldConfigBackendIndexType, 078 final org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType backendIndexType) 079 { 080 this.oldConfigBackendIndexType = oldConfigBackendIndexType; 081 this.backendIndexType = backendIndexType; 082 } 083 084 /** 085 * Convert the index type to the equivalent 086 * {@code BackendIndexCfgDefn.IndexType}. 087 * 088 * @return The index type to the equivalent 089 * {@code BackendIndexCfgDefn.IndexType} 090 */ 091 public BackendIndexCfgDefn.IndexType toBackendIndexType() 092 { 093 return oldConfigBackendIndexType; 094 } 095 096 private static IndexTypeDescriptor fromBackendIndexType(final BackendIndexCfgDefn.IndexType indexType) 097 { 098 switch (indexType) 099 { 100 case APPROXIMATE: 101 return APPROXIMATE; 102 case EQUALITY: 103 return EQUALITY; 104 case EXTENSIBLE: 105 return EXTENSIBLE; 106 case ORDERING: 107 return ORDERING; 108 case PRESENCE: 109 return PRESENCE; 110 case SUBSTRING: 111 return SUBSTRING; 112 default: 113 throw new IllegalArgumentException("No IndexTypeDescriptor corresponding to: " + indexType); 114 } 115 } 116 117 /** 118 * Convert the provided {@code Set<BackendIndexCfgDefn.IndexType>} to a 119 * {@code Set<IndexTypeDescriptor>}. 120 * 121 * @param indexTypes 122 * A set of {@code Set<BackendIndexCfgDefn.IndexType>} 123 * @return A set of {@code Set<IndexTypeDescriptor>} corresponding to the 124 * provided {@code Set<BackendIndexCfgDefn.IndexType>} 125 */ 126 public static Set<IndexTypeDescriptor> fromBackendIndexTypes(final Set<BackendIndexCfgDefn.IndexType> indexTypes) 127 { 128 final Set<IndexTypeDescriptor> indexTypeDescriptors = new LinkedHashSet<>(); 129 for (final BackendIndexCfgDefn.IndexType indexType : indexTypes) 130 { 131 indexTypeDescriptors.add(fromBackendIndexType(indexType)); 132 } 133 return indexTypeDescriptors; 134 } 135 136 /** 137 * Convert the provided {@code Set<IndexTypeDescriptor>} to a 138 * {@code Set<BackendIndexCfgDefn.IndexType>}. 139 * 140 * @param indexTypeDescriptors 141 * A set of {@code Set<IndexTypeDescriptor>} 142 * @return A set of {@code Set<BackendIndexCfgDefn.IndexType>} corresponding 143 * to the provided {@code Set<IndexTypeDescriptor>} 144 */ 145 public static Set<BackendIndexCfgDefn.IndexType> toBackendIndexTypes( 146 final Set<IndexTypeDescriptor> indexTypeDescriptors) 147 { 148 final Set<BackendIndexCfgDefn.IndexType> indexTypes = new LinkedHashSet<>(); 149 for (final IndexTypeDescriptor indexTypeDescriptor : indexTypeDescriptors) 150 { 151 indexTypes.add(indexTypeDescriptor.toBackendIndexType()); 152 } 153 return indexTypes; 154 } 155 156 /** 157 * Convert the provided {@code Set<IndexTypeDescriptor>} to a 158 * {@code Set<org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType>}. 159 * 160 * @param indexTypeDescriptors 161 * A set of {@code Set<IndexTypeDescriptor>} 162 * @return A set of 163 * {@code Set<org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType>} 164 * corresponding to the provided {@code Set<IndexTypeDescriptor>} 165 */ 166 public static Set<org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType> toNewConfigBackendIndexTypes( 167 final Set<IndexTypeDescriptor> indexTypeDescriptors) 168 { 169 Set<org.forgerock.opendj.server.config.meta.BackendIndexCfgDefn.IndexType> newConfigIndexTypes = new HashSet<>(); 170 for (IndexTypeDescriptor indexType : indexTypeDescriptors) 171 { 172 newConfigIndexTypes.add(indexType.backendIndexType); 173 } 174 return newConfigIndexTypes; 175 } 176 177}