| | |
| | | * |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.guitools.controlpanel.task; |
| | | |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | |
| | | import org.opends.server.types.SchemaFileElement; |
| | | import org.opends.server.util.LDIFReader; |
| | | import org.opends.server.util.LDIFWriter; |
| | | import org.opends.server.util.StaticUtils; |
| | | |
| | | /** |
| | | * The task that is launched when a schema element must be deleted. |
| | |
| | | } |
| | | } |
| | | |
| | | assert allOcsToDelete != null; |
| | | ArrayList<ObjectClass> lOcsToDelete = |
| | | new ArrayList<ObjectClass>(allOcsToDelete); |
| | | for (int i = lOcsToDelete.size() - 1; i >= 0; i--) |
| | |
| | | new LDIFExportConfig(schemaFile, |
| | | ExistingFileBehavior.OVERWRITE); |
| | | LDIFReader reader = null; |
| | | Entry schemaEntry = null; |
| | | LDIFWriter writer = null; |
| | | try |
| | | { |
| | | reader = new LDIFReader(new LDIFImportConfig(schemaFile)); |
| | | schemaEntry = reader.readEntry(); |
| | | Entry schemaEntry = reader.readEntry(); |
| | | |
| | | Modification mod = new Modification(ModificationType.DELETE, |
| | | Attributes.create( |
| | | getSchemaFileAttributeName(schemaElement).toLowerCase(), |
| | | getSchemaFileAttributeValue(schemaElement))); |
| | | schemaEntry.applyModification(mod); |
| | | LDIFWriter writer = new LDIFWriter(exportConfig); |
| | | writer = new LDIFWriter(exportConfig); |
| | | writer.writeEntry(schemaEntry); |
| | | exportConfig.getWriter().newLine(); |
| | | } |
| | | catch (Throwable t) |
| | | catch (IOException e) |
| | | { |
| | | throw new OfflineUpdateException( |
| | | ERR_CTRL_PANEL_ERROR_UPDATING_SCHEMA.get(e.toString()), e); |
| | | } |
| | | finally |
| | | { |
| | | if (reader != null) |
| | | { |
| | | try |
| | | { |
| | | reader.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | if (exportConfig != null) |
| | | { |
| | | try |
| | | { |
| | | exportConfig.close(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | } |
| | | StaticUtils.close(reader, exportConfig, writer); |
| | | } |
| | | } |
| | | |
| | |
| | | if (!f.isAbsolute()) |
| | | { |
| | | f = new File( |
| | | DirectoryServer.getEnvironmentConfig().getSchemaDirectory(false), |
| | | schemaFile); |
| | | if (f == null || ! f.exists() || f.isDirectory()) |
| | | { |
| | | f = new File( |
| | | DirectoryServer.getEnvironmentConfig().getSchemaDirectory(true), |
| | | schemaFile); |
| | | } |
| | | DirectoryServer.getEnvironmentConfig().getSchemaDirectory(), |
| | | schemaFile); |
| | | } |
| | | schemaFile = f.getAbsolutePath(); |
| | | return schemaFile; |
| | |
| | | |
| | | /** |
| | | * Returns the attribute name in the schema entry that corresponds to the |
| | | * profived schema element. |
| | | * provided schema element. |
| | | * @param element the schema element. |
| | | * @return the attribute name in the schema entry that corresponds to the |
| | | * profived schema element. |
| | | * provided schema element. |
| | | */ |
| | | private String getSchemaFileAttributeName(CommonSchemaElements element) |
| | | { |
| | |
| | | } |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.append( |
| | | msg+"<br><b>"); |
| | | sb.append(msg).append("<br><b>"); |
| | | sb.append(equiv); |
| | | sb.append("<br>"); |
| | | sb.append("dn: cn=schema<br>"); |
| | | sb.append("changetype: modify<br>"); |
| | | sb.append("delete: "+attrName+"<br>"); |
| | | sb.append(attrName+": "+attrValue); |
| | | sb.append("delete: ").append(attrName).append("<br>"); |
| | | sb.append(attrName).append(": ").append(attrValue); |
| | | sb.append("</b><br><br>"); |
| | | getProgressDialog().appendProgressHtml(Utilities.applyFont(sb.toString(), |
| | | ColorAndFontConstants.progressFont)); |
| | |
| | | { |
| | | AttributeType attrToAdd; |
| | | boolean isSuperior = false; |
| | | AttributeType newSuperior = attrToDelete.getSuperiorType(); |
| | | for (AttributeType attr : providedAttrsToDelete) |
| | | { |
| | | if (attr.equals(attrToDelete.getSuperiorType())) |
| | | { |
| | | isSuperior = true; |
| | | newSuperior = attr.getSuperiorType(); |
| | | AttributeType newSuperior = attr.getSuperiorType(); |
| | | while (newSuperior != null && |
| | | providedAttrsToDelete.contains(newSuperior)) |
| | | { |
| | |
| | | private Set<ObjectClass> getNewSuperiors(ObjectClass currentSup) |
| | | { |
| | | Set<ObjectClass> newSuperiors = new LinkedHashSet<ObjectClass>(); |
| | | if (currentSup.getSuperiorClasses() == null || |
| | | currentSup.getSuperiorClasses().isEmpty()) |
| | | { |
| | | // Nothing to do |
| | | } |
| | | else |
| | | if (currentSup.getSuperiorClasses() != null && |
| | | !currentSup.getSuperiorClasses().isEmpty()) |
| | | { |
| | | for (ObjectClass o : currentSup.getSuperiorClasses()) |
| | | { |