001/* 002 * Copyright 2021-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2021-2024 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2021-2024 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.unboundidds.tasks; 037 038 039 040import java.util.Collections; 041import java.util.LinkedHashMap; 042import java.util.List; 043import java.util.Map; 044 045import com.unboundid.ldap.sdk.Attribute; 046import com.unboundid.ldap.sdk.Entry; 047import com.unboundid.util.NotMutable; 048import com.unboundid.util.NotNull; 049import com.unboundid.util.StaticUtils; 050import com.unboundid.util.ThreadSafety; 051import com.unboundid.util.ThreadSafetyLevel; 052 053import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*; 054 055 056 057/** 058 * This class defines a Directory Server task that can be used to safely remove 059 * an object class from the server schema. It will make sure that the object 060 * class is not in use in the server before removing it. 061 * <BR> 062 * <BLOCKQUOTE> 063 * <B>NOTE:</B> This class, and other classes within the 064 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 065 * supported for use against Ping Identity, UnboundID, and 066 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 067 * for proprietary functionality or for external specifications that are not 068 * considered stable or mature enough to be guaranteed to work in an 069 * interoperable way with other types of LDAP servers. 070 * </BLOCKQUOTE> 071 * <BR> 072 * The properties that are available for use with this type of task include: 073 * <UL> 074 * <LI>The name or OID of the object class to remove from the server 075 * schema.</LI> 076 * </UL> 077 */ 078@NotMutable() 079@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 080public final class RemoveObjectClassTask 081 extends Task 082{ 083 /** 084 * The fully-qualified name of the Java class that is used for the remove 085 * object class task. 086 */ 087 @NotNull static final String REMOVE_OBJECT_CLASS_TASK_CLASS = 088 "com.unboundid.directory.server.tasks.RemoveObjectClassTask"; 089 090 091 092 /** 093 * The name of the attribute used to specify the name or OID of the object 094 * class to remove from the server schema. 095 */ 096 @NotNull public static final String ATTR_OBJECT_CLASS = 097 "ds-task-remove-object-class-name"; 098 099 100 101 /** 102 * The name of the object class used in remove object class task entries. 103 */ 104 @NotNull public static final String OC_REMOVE_OBJECT_CLASS_TASK = 105 "ds-task-remove-object-class"; 106 107 108 109 /** 110 * The task property that will be used for the object class name or OID. 111 */ 112 @NotNull static final TaskProperty PROPERTY_OBJECT_CLASS = 113 new TaskProperty(ATTR_OBJECT_CLASS, 114 INFO_REMOVE_OC_DISPLAY_NAME_ATTRIBUTE_TYPE.get(), 115 INFO_REMOVE_OC_DESCRIPTION_ATTRIBUTE_TYPE.get(), 116 String.class, true, false, false); 117 118 119 120 /** 121 * The serial version UID for this serializable class. 122 */ 123 private static final long serialVersionUID = 457552922409235779L; 124 125 126 127 // The name or OID for the object class to remove. 128 @NotNull private final String objectClass; 129 130 131 132 /** 133 * Creates a new uninitialized remove object class task instance that should 134 * only be used for obtaining general information about this task, including 135 * the task name, description, and supported properties. Attempts to use a 136 * task created with this constructor for any other reason will likely fail. 137 */ 138 RemoveObjectClassTask() 139 { 140 super(); 141 142 objectClass = null; 143 } 144 145 146 147 /** 148 * Creates a new remove object class task instance that will remove the 149 * specified object class from the server schema and will use the default 150 * values for all other properties. 151 * 152 * @param objectClass The name or OID of the object class to remove from the 153 * server schema. 154 */ 155 public RemoveObjectClassTask(@NotNull final String objectClass) 156 { 157 this(new RemoveObjectClassTaskProperties(objectClass)); 158 } 159 160 161 162 /** 163 * Creates a new remove object class task instance using the provided 164 * properties. 165 * 166 * @param properties The properties to use to create the remove object class 167 * task. It must not be {@code null}. 168 */ 169 public RemoveObjectClassTask( 170 @NotNull final RemoveObjectClassTaskProperties properties) 171 { 172 super(properties.getTaskID(), REMOVE_OBJECT_CLASS_TASK_CLASS, 173 properties.getScheduledStartTime(), properties.getDependencyIDs(), 174 properties.getFailedDependencyAction(), properties.getNotifyOnStart(), 175 properties.getNotifyOnCompletion(), properties.getNotifyOnSuccess(), 176 properties.getNotifyOnError(), properties.getAlertOnStart(), 177 properties.getAlertOnSuccess(), properties.getAlertOnError()); 178 179 objectClass = properties.getObjectClass(); 180 } 181 182 183 184 /** 185 * Creates a new remove object class task from the provided entry. 186 * 187 * @param entry The entry to use to create this remove object class task. 188 * 189 * @throws TaskException If the provided entry cannot be parsed as a remove 190 * object class task entry. 191 */ 192 public RemoveObjectClassTask(@NotNull final Entry entry) 193 throws TaskException 194 { 195 super(entry); 196 197 objectClass = entry.getAttributeValue(ATTR_OBJECT_CLASS); 198 if (objectClass == null) 199 { 200 throw new TaskException(ERR_REMOVE_OC_ENTRY_MISSING_OC.get(entry.getDN(), 201 ATTR_OBJECT_CLASS)); 202 } 203 } 204 205 206 207 /** 208 * Creates a new remove object class task from the provided set of task 209 * properties. 210 * 211 * @param properties The set of task properties and their corresponding 212 * values to use for the task. It must not be 213 * {@code null}. 214 * 215 * @throws TaskException If the provided set of properties cannot be used to 216 * create a valid remove object class task. 217 */ 218 public RemoveObjectClassTask( 219 @NotNull final Map<TaskProperty,List<Object>> properties) 220 throws TaskException 221 { 222 super(REMOVE_OBJECT_CLASS_TASK_CLASS, properties); 223 224 String oc = null; 225 for (final Map.Entry<TaskProperty,List<Object>> entry : 226 properties.entrySet()) 227 { 228 final TaskProperty p = entry.getKey(); 229 final String attrName = StaticUtils.toLowerCase(p.getAttributeName()); 230 final List<Object> values = entry.getValue(); 231 232 if (attrName.equals(ATTR_OBJECT_CLASS)) 233 { 234 oc = parseString(p, values, oc); 235 } 236 } 237 238 objectClass = oc; 239 if (objectClass == null) 240 { 241 throw new TaskException(ERR_REMOVE_OC_PROPS_MISSING_OC.get( 242 ATTR_OBJECT_CLASS)); 243 } 244 } 245 246 247 248 /** 249 * {@inheritDoc} 250 */ 251 @Override() 252 @NotNull() 253 public String getTaskName() 254 { 255 return INFO_REMOVE_OC_TASK_NAME.get(); 256 } 257 258 259 260 /** 261 * {@inheritDoc} 262 */ 263 @Override() 264 @NotNull() 265 public String getTaskDescription() 266 { 267 return INFO_REMOVE_OC_TASK_DESCRIPTION.get(); 268 } 269 270 271 272 /** 273 * Retrieves the name or OID of the object class to remove from the server 274 * schema. 275 * 276 * @return The name or OID of the object class to remove from the server 277 * schema. 278 */ 279 @NotNull() 280 public String getObjectClass() 281 { 282 return objectClass; 283 } 284 285 286 287 /** 288 * {@inheritDoc} 289 */ 290 @Override() 291 @NotNull() 292 protected List<String> getAdditionalObjectClasses() 293 { 294 return Collections.singletonList(OC_REMOVE_OBJECT_CLASS_TASK); 295 } 296 297 298 299 /** 300 * {@inheritDoc} 301 */ 302 @Override() 303 @NotNull() 304 protected List<Attribute> getAdditionalAttributes() 305 { 306 return Collections.singletonList( 307 new Attribute(ATTR_OBJECT_CLASS, objectClass)); 308 } 309 310 311 312 /** 313 * {@inheritDoc} 314 */ 315 @Override() 316 @NotNull() 317 public List<TaskProperty> getTaskSpecificProperties() 318 { 319 return Collections.singletonList(PROPERTY_OBJECT_CLASS); 320 } 321 322 323 324 /** 325 * {@inheritDoc} 326 */ 327 @Override() 328 @NotNull() 329 public Map<TaskProperty,List<Object>> getTaskPropertyValues() 330 { 331 final Map<TaskProperty,List<Object>> props = 332 new LinkedHashMap<>(StaticUtils.computeMapCapacity(20)); 333 props.put(PROPERTY_OBJECT_CLASS, 334 Collections.<Object>singletonList(objectClass)); 335 336 props.putAll(super.getTaskPropertyValues()); 337 return Collections.unmodifiableMap(props); 338 } 339}