opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/ServerDescriptor.java
@@ -32,6 +32,7 @@ import org.forgerock.opendj.ldap.schema.ObjectClass; import org.opends.guitools.controlpanel.util.ConfigFromDirContext; import org.opends.quicksetup.UserData; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.tools.tasks.TaskEntry; import org.opends.server.types.Schema; @@ -607,8 +608,8 @@ && attr1.isOperational() == attr2.isOperational() && attr1.isSingleValue() == attr2.isSingleValue() && areEqual(attr1.getApproximateMatchingRule(), attr2.getApproximateMatchingRule()) && areEqual(new SomeSchemaElement(attr1).getDefinitionWithFileName(), new SomeSchemaElement(attr2).getDefinitionWithFileName()) && areEqual(new ServerSchemaElement(attr1).getDefinitionWithFileName(), new ServerSchemaElement(attr2).getDefinitionWithFileName()) && areEqual(attr1.getDescription(), attr2.getDescription()) && areEqual(attr1.getEqualityMatchingRule(), attr2.getEqualityMatchingRule()) && areEqual(attr1.getOrderingMatchingRule(), attr2.getOrderingMatchingRule()) opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/SomeSchemaElement.java
File was deleted opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/DeleteSchemaElementsTask.java
@@ -16,6 +16,7 @@ */ package org.opends.guitools.controlpanel.task; import static org.opends.guitools.controlpanel.util.Utilities.*; import static org.opends.messages.AdminToolMessages.*; import static org.opends.server.types.ExistingFileBehavior.*; import static org.opends.server.util.SchemaUtils.*; @@ -46,12 +47,12 @@ import org.forgerock.opendj.ldap.schema.SchemaBuilder; import org.forgerock.opendj.ldap.schema.SchemaElement; import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.ui.ColorAndFontConstants; import org.opends.guitools.controlpanel.ui.ProgressDialog; import org.opends.guitools.controlpanel.util.Utilities; import org.opends.server.config.ConfigConstants; import org.opends.server.core.DirectoryServer; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.Attributes; import org.opends.server.types.Entry; import org.opends.server.types.LDIFExportConfig; @@ -221,14 +222,14 @@ int numberDeleted = 0; for (ObjectClass objectClass : ocsToDelete) { final SomeSchemaElement element = new SomeSchemaElement(objectClass); final ServerSchemaElement element = new ServerSchemaElement(objectClass); deleteSchemaElement(element, numberDeleted, totalNumber, INFO_CTRL_PANEL_DELETING_OBJECTCLASS); numberDeleted++; } for (AttributeType attribute : attrsToDelete) { final SomeSchemaElement element = new SomeSchemaElement(attribute); final ServerSchemaElement element = new ServerSchemaElement(attribute); deleteSchemaElement(element, numberDeleted, totalNumber, INFO_CTRL_PANEL_DELETING_ATTRIBUTE); numberDeleted++; } @@ -255,7 +256,7 @@ } } private void deleteSchemaElement(final SomeSchemaElement element, final int numberDeleted, final int totalNumber, private void deleteSchemaElement(final ServerSchemaElement element, final int numberDeleted, final int totalNumber, final Arg1<Object> deletingElementMsg) throws OnlineUpdateException, OpenDsException { SwingUtilities.invokeLater(new Runnable() @@ -271,7 +272,8 @@ printEquivalentCommandToDelete(element); getProgressDialog().appendProgressHtml( Utilities.getProgressWithPoints( deletingElementMsg.get(element.getNameOrOID()), ColorAndFontConstants.progressFont)); deletingElementMsg.get(getElementNameOrOID(element)), ColorAndFontConstants.progressFont)); } }); @@ -279,7 +281,7 @@ { try { BasicAttribute attr = new BasicAttribute(element.getAttributeName()); BasicAttribute attr = new BasicAttribute(getAttributeConfigName(element)); attr.add(getSchemaFileAttributeValue(element)); ModificationItem mod = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, attr); getInfo().getConnection().getLdapContext().modifyAttributes( @@ -315,7 +317,7 @@ * @param schemaElement the schema element to be deleted. * @throws OpenDsException if an error occurs. */ private void updateSchemaFile(SomeSchemaElement schemaElement) throws OpenDsException private void updateSchemaFile(ServerSchemaElement schemaElement) throws OpenDsException { String schemaFile = getSchemaFile(schemaElement); @@ -325,8 +327,7 @@ Entry schemaEntry = reader.readEntry(); Modification mod = new Modification(ModificationType.DELETE, Attributes.create( schemaElement.getAttributeName(), Attributes.create(getAttributeConfigName(schemaElement), getSchemaFileAttributeValue(schemaElement))); schemaEntry.applyModification(mod); try (LDIFWriter writer = new LDIFWriter(exportConfig)) @@ -347,7 +348,7 @@ * @param element the schema element. * @return the schema file for a given schema element. */ private String getSchemaFile(SomeSchemaElement element) private String getSchemaFile(ServerSchemaElement element) { String schemaFile = element.getSchemaFile(); if (schemaFile == null) @@ -369,7 +370,7 @@ * @param element the schema element. * @return the value in the schema file for the provided element. */ private String getSchemaFileAttributeValue(SomeSchemaElement element) private String getSchemaFileAttributeValue(ServerSchemaElement element) { return element.toString(); } @@ -379,10 +380,10 @@ * progress dialog. * @param element the schema element to be deleted. */ private void printEquivalentCommandToDelete(SomeSchemaElement element) private void printEquivalentCommandToDelete(ServerSchemaElement element) { String schemaFile = getSchemaFile(element); String attrName = element.getAttributeName(); String attrName = getAttributeConfigName(element); String attrValue = getSchemaFileAttributeValue(element); String msg; @@ -412,22 +413,24 @@ getProgressDialog().appendProgressHtml(Utilities.applyFont(msg, ColorAndFontConstants.progressFont)); } private LocalizableMessage getEquivalentCommandOfflineMsg(SomeSchemaElement element, String schemaFile) private LocalizableMessage getEquivalentCommandOfflineMsg(ServerSchemaElement element, String schemaFile) { if (element.isAttributeType()) String nameOrOID = getElementNameOrOID(element); if (isAttributeType(element)) { return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_ATTRIBUTE_OFFLINE.get(element.getNameOrOID(), schemaFile); return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_ATTRIBUTE_OFFLINE.get(nameOrOID, schemaFile); } return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_OBJECTCLASS_OFFLINE.get(element.getNameOrOID(), schemaFile); return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_OBJECTCLASS_OFFLINE.get(nameOrOID, schemaFile); } private LocalizableMessage getEquivalentCommandOnlineMsg(SomeSchemaElement element) private LocalizableMessage getEquivalentCommandOnlineMsg(ServerSchemaElement element) { if (element.isAttributeType()) String nameOrOID = getElementNameOrOID(element); if (isAttributeType(element)) { return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_ATTRIBUTE_ONLINE.get(element.getNameOrOID()); return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_ATTRIBUTE_ONLINE.get(nameOrOID); } return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_OBJECTCLASS_ONLINE.get(element.getNameOrOID()); return INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_DELETE_OBJECTCLASS_ONLINE.get(nameOrOID); } private AttributeType getAttributeToAdd(AttributeType attrToDelete) @@ -444,7 +447,7 @@ if (isSuperior) { // get a new attribute without the superior type return SomeSchemaElement.changeSuperiorType(attrToDelete, null); return updateAttributeTypeWithNewSuperiorType(attrToDelete, null); } else { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ModifyAttributeTask.java
@@ -36,7 +36,6 @@ import org.forgerock.opendj.ldap.schema.ObjectClass; import org.forgerock.opendj.ldap.schema.SchemaBuilder; import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.ui.ColorAndFontConstants; import org.opends.guitools.controlpanel.ui.ProgressDialog; import org.opends.guitools.controlpanel.util.Utilities; @@ -149,7 +148,7 @@ else if (oldAttribute.equals(attrToDelete.getSuperiorType())) { // get a new attribute with the new superior type return SomeSchemaElement.changeSuperiorType(attrToDelete, newAttribute); return Utilities.updateAttributeTypeWithNewSuperiorType(attrToDelete, newAttribute); } else { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/NewSchemaElementsTask.java
@@ -16,9 +16,11 @@ */ package org.opends.guitools.controlpanel.task; import static org.forgerock.opendj.ldap.ModificationType.*; import static org.forgerock.util.Utils.*; import static org.opends.messages.AdminToolMessages.*; import static org.opends.guitools.controlpanel.util.Utilities.*; import java.io.File; import java.util.ArrayList; @@ -40,15 +42,14 @@ import org.forgerock.i18n.LocalizableMessage; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.ObjectClass; import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.ui.ColorAndFontConstants; import org.opends.guitools.controlpanel.ui.ProgressDialog; import org.opends.guitools.controlpanel.util.Utilities; import org.opends.server.config.ConfigConstants; import org.opends.server.core.DirectoryServer; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.Attribute; import org.opends.server.types.Attributes; import org.opends.server.types.DirectoryException; @@ -61,7 +62,6 @@ import org.opends.server.util.LDIFReader; import org.opends.server.util.LDIFWriter; import org.opends.server.util.ServerConstants; import org.opends.server.util.StaticUtils; /** * An abstract class used to re-factor some code between the different tasks @@ -169,12 +169,12 @@ } } private List<String> getElementsNameOrOID(final Collection<SomeSchemaElement> schemaElements) private List<String> getElementsNameOrOID(final Collection<ServerSchemaElement> schemaElements) { final List<String> nameOrOIDs = new ArrayList<>(); for (SomeSchemaElement schemaElement : schemaElements) for (ServerSchemaElement schemaElement : schemaElements) { nameOrOIDs.add(schemaElement.getNameOrOID()); nameOrOIDs.add(getElementNameOrOID(schemaElement)); } return nameOrOIDs; } @@ -245,8 +245,8 @@ private void updateSchemaOffline() throws OpenDsException { // Group the changes in the same schema file. final Map<String, List<SomeSchemaElement>> mapAttrs = copy(attributeTypesToSchemaElements(attrsToAdd)); final Map<String, List<SomeSchemaElement>> mapClasses = copy(objectClassesToSchemaElements(ocsToAdd)); final Map<String, List<ServerSchemaElement>> mapAttrs = copy(attributeTypesToSchemaElements(attrsToAdd)); final Map<String, List<ServerSchemaElement>> mapClasses = copy(objectClassesToSchemaElements(ocsToAdd)); final Set<String> allFileNames = new LinkedHashSet<>(mapAttrs.keySet()); allFileNames.addAll(mapClasses.keySet()); @@ -264,23 +264,23 @@ } } private List<SomeSchemaElement> get(Map<String, List<SomeSchemaElement>> hmElems, String fileName) private List<ServerSchemaElement> get(Map<String, List<ServerSchemaElement>> hmElems, String fileName) { List<SomeSchemaElement> elems = hmElems.get(fileName); return elems != null ? elems : Collections.<SomeSchemaElement> emptyList(); List<ServerSchemaElement> elems = hmElems.get(fileName); return elems != null ? elems : Collections.<ServerSchemaElement> emptyList(); } private Map<String, List<SomeSchemaElement>> copy(Set<SomeSchemaElement> elemsToAdd) private Map<String, List<ServerSchemaElement>> copy(Set<ServerSchemaElement> elemsToAdd) { Map<String, List<SomeSchemaElement>> hmElems = new LinkedHashMap<>(); for (SomeSchemaElement elem : elemsToAdd) Map<String, List<ServerSchemaElement>> hmElems = new LinkedHashMap<>(); for (ServerSchemaElement elem : elemsToAdd) { String fileName = elem.getSchemaFile(); if (fileName == null) { fileName = ""; } List<SomeSchemaElement> elems = hmElems.get(fileName); List<ServerSchemaElement> elems = hmElems.get(fileName); if (elems == null) { elems = new ArrayList<>(); @@ -293,17 +293,17 @@ private void addAttributeOnline(final AttributeType attribute) throws OpenDsException { addSchemaElementOnline(new SomeSchemaElement(attribute), addSchemaElementOnline(new ServerSchemaElement(attribute), INFO_CTRL_PANEL_CREATING_ATTRIBUTE_PROGRESS.get(attribute.getNameOrOID())); } private void addObjectClassOnline(final ObjectClass objectClass) throws OpenDsException { addSchemaElementOnline(new SomeSchemaElement(objectClass), addSchemaElementOnline(new ServerSchemaElement(objectClass), INFO_CTRL_PANEL_CREATING_OBJECTCLASS_PROGRESS.get(objectClass.getNameOrOID())); } private void addSchemaElementOnline(final SomeSchemaElement schemaElement, final LocalizableMessage progressMsg) private void addSchemaElementOnline(final ServerSchemaElement schemaElement, final LocalizableMessage progressMsg) throws OpenDsException { SwingUtilities.invokeLater(new Runnable() @@ -318,8 +318,8 @@ }); try { final BasicAttribute attr = new BasicAttribute(schemaElement.getAttributeName()); attr.add(getElementDefinition(schemaElement)); final BasicAttribute attr = new BasicAttribute(getAttributeConfigName(schemaElement)); attr.add(schemaElement.toString()); final ModificationItem mod = new ModificationItem(DirContext.ADD_ATTRIBUTE, attr); getInfo().getConnection().getLdapContext().modifyAttributes( ConfigConstants.DN_DEFAULT_SCHEMA_ROOT, new ModificationItem[] { mod }); @@ -339,188 +339,58 @@ }); } private String getValueOffline(SomeSchemaElement element) /** Returns the definition for provided element without the file name. */ private String getValueOffline(ServerSchemaElement element) { final Map<String, List<String>> props = element.getExtraProperties(); List<String> previousValues = props.get(ServerConstants.SCHEMA_PROPERTY_FILENAME); element.setExtraPropertySingleValue(null, ServerConstants.SCHEMA_PROPERTY_FILENAME, null); String attributeWithoutFileDefinition = getElementDefinition(element); if (previousValues != null && !previousValues.isEmpty()) { element.setExtraPropertyMultipleValues(null, ServerConstants.SCHEMA_PROPERTY_FILENAME, new ArrayList<String>(previousValues)); } return attributeWithoutFileDefinition; return updateSchemaElementExtraPropertySingleValue(null, element, ServerConstants.SCHEMA_PROPERTY_FILENAME, null) .toString(); } private String getElementDefinition(SomeSchemaElement element) private Set<ServerSchemaElement> objectClassesToSchemaElements(final Collection<ObjectClass> classes) { final List<String> names = new ArrayList<>(); for (final String name : element.getNames()) { names.add(StaticUtils.toLowerCase(name)); } return element.isAttributeType() ? getAttributeTypeDefinition(element.getAttributeType(), names) : getObjectClassDefinition(element.getObjectClass(), names); } private String getAttributeTypeDefinition(final AttributeType attributeType, final List<String> names) { final StringBuilder buffer = new StringBuilder(); buffer.append("( ").append(attributeType.getOID()); appendCollection(buffer, "NAME", names); appendDescription(buffer, attributeType.getDescription()); appendIfTrue(buffer, " OBSOLETE", attributeType.isObsolete()); final AttributeType superiorType = attributeType.getSuperiorType(); final String superiorTypeOID = superiorType != null ? superiorType.getOID() : null; appendIfNotNull(buffer, " SUP ", superiorTypeOID); addMatchingRuleIfNotNull(buffer, " EQUALITY ", attributeType.getEqualityMatchingRule()); addMatchingRuleIfNotNull(buffer, " ORDERING ", attributeType.getOrderingMatchingRule()); addMatchingRuleIfNotNull(buffer, " SUBSTR ", attributeType.getSubstringMatchingRule()); appendIfNotNull(buffer, " SYNTAX ", attributeType.getSyntax().getOID()); appendIfTrue(buffer, " SINGLE-VALUE", attributeType.isSingleValue()); appendIfTrue(buffer, " COLLECTIVE", attributeType.isCollective()); appendIfTrue(buffer, " NO-USER-MODIFICATION", attributeType.isNoUserModification()); appendIfNotNull(buffer, " USAGE ", attributeType.getUsage()); final MatchingRule approximateMatchingRule = attributeType.getApproximateMatchingRule(); if (approximateMatchingRule != null) { buffer.append(" ").append(ServerConstants.SCHEMA_PROPERTY_APPROX_RULE).append(" '") .append(approximateMatchingRule.getOID()).append("'"); } appendExtraProperties(buffer, attributeType.getExtraProperties()); buffer.append(")"); return buffer.toString(); } private void addMatchingRuleIfNotNull(final StringBuilder buffer, final String label, final MatchingRule matchingRule) { if (matchingRule != null) { append(buffer, label, matchingRule.getOID()); } } private String getObjectClassDefinition(final ObjectClass objectClass, final List<String> names) { final StringBuilder buffer = new StringBuilder(); buffer.append("( "); buffer.append(objectClass.getOID()); appendCollection(buffer, "NAME", names); appendDescription(buffer, objectClass.getDescription()); appendIfTrue(buffer, " OBSOLETE", objectClass.isObsolete()); appendOIDs(buffer, "SUP", objectClassesToSchemaElements(objectClass.getSuperiorClasses())); appendIfNotNull(buffer, " ", objectClass.getObjectClassType()); appendOIDs(buffer, "MUST", attributeTypesToSchemaElements(objectClass.getDeclaredRequiredAttributes())); appendOIDs(buffer, "MAY", attributeTypesToSchemaElements(objectClass.getDeclaredOptionalAttributes())); appendExtraProperties(buffer, objectClass.getExtraProperties()); buffer.append(")"); return buffer.toString(); } private void appendOIDs(final StringBuilder buffer, final String label, final Collection<SomeSchemaElement> schemaElements) { if (!schemaElements.isEmpty()) { buffer.append(" ").append(label).append(" ( "); final Iterator<SomeSchemaElement> it = schemaElements.iterator(); buffer.append(it.next().getOID()); while (it.hasNext()) { buffer.append(" $ ").append(it.next().getOID()); } buffer.append(" )"); } } private Set<SomeSchemaElement> objectClassesToSchemaElements(final Collection<ObjectClass> classes) { Set<SomeSchemaElement> elements = new HashSet<>(); Set<ServerSchemaElement> elements = new HashSet<>(); for (ObjectClass objectClass : classes) { elements.add(new SomeSchemaElement(objectClass)); elements.add(new ServerSchemaElement(objectClass)); } return elements; } private Set<SomeSchemaElement> attributeTypesToSchemaElements(final Collection<AttributeType> types) private Set<ServerSchemaElement> attributeTypesToSchemaElements(final Collection<AttributeType> types) { Set<SomeSchemaElement> elements = new HashSet<>(); Set<ServerSchemaElement> elements = new HashSet<>(); for (AttributeType type : types) { elements.add(new SomeSchemaElement(type)); elements.add(new ServerSchemaElement(type)); } return elements; } private List<AttributeType> schemaElementsToAttributeTypes(final Collection<SomeSchemaElement> elements) private List<AttributeType> schemaElementsToAttributeTypes(final Collection<ServerSchemaElement> elements) { List<AttributeType> types = new ArrayList<>(); for (SomeSchemaElement element : elements) for (ServerSchemaElement element : elements) { types.add(element.getAttributeType()); types.add((AttributeType) element.asSchemaElement()); } return types; } private List<ObjectClass> schemaElementsToObjectClasses(final Collection<SomeSchemaElement> elements) private List<ObjectClass> schemaElementsToObjectClasses(final Collection<ServerSchemaElement> elements) { List<ObjectClass> classes = new ArrayList<>(); for (SomeSchemaElement element : elements) for (ServerSchemaElement element : elements) { classes.add(element.getObjectClass()); classes.add((ObjectClass) element.asSchemaElement()); } return classes; } private void appendIfTrue(final StringBuilder buffer, final String label, final boolean labelIsActive) { if (labelIsActive) { buffer.append(label); } } private void appendIfNotNull(final StringBuilder buffer, final String label, final Object value) { if (value != null) { append(buffer, label, value.toString()); } } private void append(final StringBuilder buffer, final String label, final String value) { buffer.append(label).append(value); } private void appendDescription(final StringBuilder buffer, final String description) { if (description != null && !description.isEmpty()) { buffer.append(" DESC '"); buffer.append(description); buffer.append("'"); } } private void appendExtraProperties( final StringBuilder buffer, final Map<String, List<String>> extraProperties) { for (final Map.Entry<String, List<String>> e : extraProperties.entrySet()) { appendCollection(buffer, e.getKey(), e.getValue()); } } private void appendCollection(final StringBuilder buffer, final String property, final Collection<String> values) { final boolean isMultiValued = values.size() > 1; @@ -541,7 +411,7 @@ } } private void printEquivalentCommandLineToAddOnline(SomeSchemaElement element) private void printEquivalentCommandLineToAddOnline(ServerSchemaElement element) { List<String> args = new ArrayList<>(); args.add("-a"); @@ -550,9 +420,9 @@ final String equivalentCmdLine = getEquivalentCommandLine(getCommandLinePath("ldapmodify"), args); final StringBuilder sb = new StringBuilder(); final String attName = element.getAttributeName(); final String elementId = element.getNameOrOID(); final LocalizableMessage message = element.isAttributeType() final String attName = getAttributeConfigName(element); final String elementId = getElementNameOrOID(element); final LocalizableMessage message = isAttributeType(element) ? INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_ATTRIBUTE_ONLINE.get(elementId) : INFO_CTRL_PANEL_EQUIVALENT_CMD_TO_ADD_OBJECTCLASS_ONLINE.get(elementId); sb.append(message).append("<br><b>") @@ -560,15 +430,15 @@ .append("dn: cn=schema<br>") .append("changetype: modify<br>") .append("add: ").append(attName).append("<br>") .append(attName).append(": ").append(getElementDefinition(element)).append("</b><br><br>"); .append(attName).append(": ").append(element.toString()).append("</b><br><br>"); getProgressDialog().appendProgressHtml(Utilities.applyFont(sb.toString(), ColorAndFontConstants.progressFont)); } private void updateSchemaOffline( String file, final List<AttributeType> attributes, final List<ObjectClass> objectClasses) throws OpenDsException { final List<SomeSchemaElement> schemaElements = new ArrayList<SomeSchemaElement>(attributeTypesToSchemaElements(attributes)); final List<ServerSchemaElement> schemaElements = new ArrayList<ServerSchemaElement>(attributeTypesToSchemaElements(attributes)); schemaElements.addAll(objectClassesToSchemaElements(objectClasses)); if (file == null) { @@ -619,7 +489,7 @@ updateSchemaUndefinedFile(fileName, schemaElements); } for (SomeSchemaElement schemaElement : schemaElements) for (ServerSchemaElement schemaElement : schemaElements) { notifyConfigurationElementCreated(schemaElement); } @@ -634,7 +504,7 @@ } private String equivalentCommandToAddOffline( String schemaFile, boolean isSchemaFileDefined, List<SomeSchemaElement> schemaElements) String schemaFile, boolean isSchemaFileDefined, List<ServerSchemaElement> schemaElements) { List<String> names = getElementsNameOrOID(schemaElements); @@ -656,9 +526,9 @@ } } for (SomeSchemaElement schemaElement : schemaElements) for (ServerSchemaElement element : schemaElements) { sb.append(schemaElement.getAttributeName()).append(": ").append(getValueOffline(schemaElement)).append("<br>"); sb.append(getAttributeConfigName(element)).append(": ").append(getValueOffline(element)).append("<br>"); } sb.append("</b><br><br>"); @@ -716,7 +586,7 @@ * @throws OpenDsException * if an error occurs updating the schema file. */ private void updateSchemaFile(String schemaFile, List<SomeSchemaElement> schemaElements) private void updateSchemaFile(String schemaFile, List<ServerSchemaElement> schemaElements) throws OpenDsException { try (final LDIFExportConfig exportConfig = new LDIFExportConfig(schemaFile, ExistingFileBehavior.OVERWRITE)) @@ -738,25 +608,25 @@ } } private void addElementsToEntry(List<SomeSchemaElement> schemaElements, Entry schemaEntry) private void addElementsToEntry(List<ServerSchemaElement> schemaElements, Entry schemaEntry) throws DirectoryException { for (SomeSchemaElement schemaElement : schemaElements) for (ServerSchemaElement element : schemaElements) { Attribute attr = Attributes.create(schemaElement.getAttributeName(), getValueOffline(schemaElement)); Attribute attr = Attributes.create(getAttributeConfigName(element), getValueOffline(element)); schemaEntry.applyModification(new Modification(ADD, attr)); } } private void updateSchemaUndefinedFile(String schemaFile, List<SomeSchemaElement> schemaElements) private void updateSchemaUndefinedFile(String schemaFile, List<ServerSchemaElement> schemaElements) throws OfflineUpdateException { try (LDIFExportConfig exportConfig = new LDIFExportConfig(schemaFile, ExistingFileBehavior.FAIL)) { List<String> lines = getSchemaEntryLines(); for (final SomeSchemaElement schemaElement : schemaElements) for (final ServerSchemaElement element : schemaElements) { lines.add(schemaElement.getAttributeName() + ": " + getValueOffline(schemaElement)); lines.add(getAttributeConfigName(element) + ": " + getValueOffline(element)); } for (String line : lines) { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/AbstractVLVIndexPanel.java
@@ -69,7 +69,6 @@ import org.opends.guitools.controlpanel.datamodel.CategorizedComboBoxElement; import org.opends.guitools.controlpanel.datamodel.IndexDescriptor; import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor; import org.opends.guitools.controlpanel.datamodel.VLVSortOrder; import org.opends.guitools.controlpanel.ui.components.TitlePanel; @@ -81,6 +80,7 @@ import org.opends.quicksetup.Installation; import org.opends.server.config.ConfigException; import org.opends.server.protocols.ldap.LDAPFilter; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.FilterType; import org.opends.server.types.LDAPException; import org.opends.server.types.OpenDsException; @@ -320,7 +320,7 @@ for (AttributeType attr : schema.getAttributeTypes()) { SomeSchemaElement element = new SomeSchemaElement(attr); ServerSchemaElement element = new ServerSchemaElement(attr); String name = attr.getNameOrOID(); if (!isDefined(name)) { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/BrowseSchemaPanel.java
@@ -16,6 +16,8 @@ */ package org.opends.guitools.controlpanel.ui; import static org.opends.guitools.controlpanel.util.Utilities.getElementNameOrOID; import static org.opends.messages.AdminToolMessages.*; import static org.opends.server.util.StaticUtils.*; @@ -73,7 +75,6 @@ import org.opends.guitools.controlpanel.browser.IconPool; import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; import org.opends.guitools.controlpanel.event.ConfigurationElementCreatedEvent; import org.opends.guitools.controlpanel.event.ConfigurationElementCreatedListener; @@ -99,6 +100,7 @@ import org.opends.guitools.controlpanel.util.LowerCaseComparator; import org.opends.guitools.controlpanel.util.Utilities; import org.opends.guitools.controlpanel.util.ViewPositions; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.Schema; /** The pane that is displayed when the user clicks on 'Browse Schema'. */ @@ -139,7 +141,7 @@ private JPopupMenu popup; private SomeSchemaElement lastCreatedElement; private ServerSchemaElement lastCreatedElement; private final CategoryTreeNode attributes = new CategoryTreeNode(INFO_CTRL_PANEL_ATTRIBUTES_CATEGORY_NODE.get()); private final CategoryTreeNode objectClasses = @@ -669,7 +671,7 @@ { if (mustAdd(oc)) { SomeSchemaElement element = new SomeSchemaElement(oc); ServerSchemaElement element = new ServerSchemaElement(oc); String name = oc.getNameOrOID(); if (Utilities.isStandard(element)) { @@ -697,7 +699,7 @@ Map<String, CustomAttributeTreeNode> hmCustomAttrs = new HashMap<>(); for (AttributeType attr : lastSchema.getAttributeTypes()) { SomeSchemaElement element = new SomeSchemaElement(attr); ServerSchemaElement element = new ServerSchemaElement(attr); if (mustAdd(attr)) { String name = attr.getNameOrOID(); @@ -870,7 +872,7 @@ if (lastCreatedElement != null) { if (node instanceof CustomObjectClassTreeNode && name.equals(lastCreatedElement.getNameOrOID())) && name.equals(getElementNameOrOID(lastCreatedElement))) { newSelectionPath = new TreePath(node.getPath()); lastCreatedElement = null; @@ -1462,9 +1464,9 @@ private void configurationElementCreated(ConfigurationElementCreatedEvent ev) { Object o = ev.getConfigurationObject(); if (o instanceof SomeSchemaElement) if (o instanceof ServerSchemaElement) { lastCreatedElement = (SomeSchemaElement) o; lastCreatedElement = (ServerSchemaElement) o; } } opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/CustomAttributePanel.java
@@ -71,7 +71,6 @@ import org.forgerock.opendj.ldap.schema.SchemaBuilder; import org.forgerock.opendj.ldap.schema.Syntax; import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; import org.opends.guitools.controlpanel.event.ConfigurationElementCreatedListener; import org.opends.guitools.controlpanel.event.ScrollPaneBorderListener; @@ -84,6 +83,7 @@ import org.opends.guitools.controlpanel.ui.renderer.SchemaElementComboBoxCellRenderer; import org.opends.guitools.controlpanel.util.LowerCaseComparator; import org.opends.guitools.controlpanel.util.Utilities; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.Schema; import org.opends.server.util.ServerConstants; import org.opends.server.util.StaticUtils; @@ -526,7 +526,7 @@ lastAliases.addAll(someAliases); this.aliases.setText(Utilities.getStringFromCollection(someAliases, ", ")); SomeSchemaElement element = new SomeSchemaElement(attr); ServerSchemaElement element = new ServerSchemaElement(attr); String sOrigin = element.getOrigin(); if (sOrigin == null) { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/CustomObjectClassPanel.java
@@ -65,7 +65,6 @@ import org.forgerock.opendj.ldap.schema.ObjectClassType; import org.forgerock.opendj.ldap.schema.SchemaBuilder; import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.datamodel.SortableListModel; import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; import org.opends.guitools.controlpanel.event.ConfigurationElementCreatedListener; @@ -81,6 +80,7 @@ import org.opends.guitools.controlpanel.ui.components.TitlePanel; import org.opends.guitools.controlpanel.ui.renderer.SchemaElementComboBoxCellRenderer; import org.opends.guitools.controlpanel.util.Utilities; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.Schema; import org.opends.server.util.ServerConstants; import org.opends.server.util.StaticUtils; @@ -500,7 +500,7 @@ lastAliases.addAll(aliases); this.aliases.setText(Utilities.getStringFromCollection(aliases, ", ")); String sOrigin = new SomeSchemaElement(oc).getOrigin(); String sOrigin = new ServerSchemaElement(oc).getOrigin(); if (sOrigin == null) { sOrigin = ""; opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
@@ -49,10 +49,10 @@ import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; import org.opends.guitools.controlpanel.datamodel.IndexDescriptor; import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; import org.opends.guitools.controlpanel.task.Task; import org.opends.guitools.controlpanel.util.Utilities; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.Schema; /** Panel that appears when the user defines a new index. */ @@ -125,7 +125,7 @@ TreeSet<String> customAttrNames = new TreeSet<>(); for (AttributeType attr : schema.getAttributeTypes()) { SomeSchemaElement element = new SomeSchemaElement(attr); ServerSchemaElement element = new ServerSchemaElement(attr); String name = attr.getNameOrOID(); if (!indexExists(backend, name)) { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StandardAttributePanel.java
@@ -40,11 +40,11 @@ import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.ObjectClass; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; import org.opends.guitools.controlpanel.ui.components.TitlePanel; import org.opends.guitools.controlpanel.util.LowerCaseComparator; import org.opends.guitools.controlpanel.util.Utilities; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.Schema; /** The panel that displays a standard attribute definition. */ @@ -237,7 +237,7 @@ n = superior != null ? superior.getNameOrOID() : null; parent.setText(n); oid.setText(attr.getOID()); origin.setText(StandardObjectClassPanel.getOrigin(new SomeSchemaElement(attr)).toString()); origin.setText(StandardObjectClassPanel.getOrigin(new ServerSchemaElement(attr)).toString()); n = attr.getDescription(); if (n == null) { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/StandardObjectClassPanel.java
@@ -44,11 +44,11 @@ import org.forgerock.i18n.LocalizableMessageBuilder; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.ObjectClass; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; import org.opends.guitools.controlpanel.ui.components.TitlePanel; import org.opends.guitools.controlpanel.util.LowerCaseComparator; import org.opends.guitools.controlpanel.util.Utilities; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.Schema; /** The panel that displays a standard object class definition. */ @@ -239,7 +239,7 @@ * @param element the schema element. * @return the message describing the schema element origin (file, RFC, etc.). */ static LocalizableMessage getOrigin(SomeSchemaElement element) static LocalizableMessage getOrigin(ServerSchemaElement element) { LocalizableMessageBuilder returnValue = new LocalizableMessageBuilder(); String fileName = element.getSchemaFile(); @@ -287,7 +287,7 @@ name.setText(n); parent.setText(getSuperiorText(oc)); oid.setText(oc.getOID()); origin.setText(getOrigin(new SomeSchemaElement(oc)).toString()); origin.setText(getOrigin(new ServerSchemaElement(oc)).toString()); n = oc.getDescription(); if (n == null) { opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/util/Utilities.java
@@ -18,7 +18,6 @@ import static com.forgerock.opendj.cli.Utils.*; import static com.forgerock.opendj.util.OperatingSystem.*; import static org.forgerock.opendj.ldap.DereferenceAliasesPolicy.*; import static org.forgerock.opendj.ldap.SearchScope.*; import static org.forgerock.opendj.ldap.requests.Requests.*; @@ -105,6 +104,9 @@ import org.forgerock.opendj.ldap.responses.SearchResultEntry; import org.forgerock.opendj.ldap.schema.AttributeType; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.schema.ObjectClass; import org.forgerock.opendj.ldap.schema.SchemaBuilder; import org.forgerock.opendj.ldap.schema.SchemaElement; import org.forgerock.opendj.ldap.schema.Syntax; import org.opends.admin.ads.util.ConnectionWrapper; import org.opends.guitools.controlpanel.ControlPanel; @@ -114,7 +116,6 @@ import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo; import org.opends.guitools.controlpanel.datamodel.CustomSearchResult; import org.opends.guitools.controlpanel.datamodel.MonitoringAttributes; import org.opends.guitools.controlpanel.datamodel.SomeSchemaElement; import org.opends.guitools.controlpanel.datamodel.SortableTableModel; import org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor; import org.opends.guitools.controlpanel.event.ClickTooltipDisplayer; @@ -127,9 +128,12 @@ import org.opends.quicksetup.Installation; import org.opends.quicksetup.ui.UIFactory; import org.opends.quicksetup.util.Utils; import org.opends.server.config.ConfigConstants; import org.opends.server.config.ConfigurationHandler; import org.opends.server.core.LockFileManager; import org.opends.server.core.ServerContext; import org.opends.server.schema.SchemaConstants; import org.opends.server.schema.ServerSchemaElement; import org.opends.server.types.OpenDsException; import org.opends.server.types.Schema; import org.opends.server.util.SchemaUtils; @@ -1991,7 +1995,7 @@ * @return {@code true} if the provided schema element is part of the standard, * {@code false} otherwise. */ public static boolean isStandard(SomeSchemaElement fileElement) public static boolean isStandard(ServerSchemaElement fileElement) { final String fileName = fileElement.getSchemaFile(); if (fileName != null) @@ -2013,7 +2017,7 @@ * @return {@code true} if the provided schema element is part of the configuration, * {@code false} otherwise. */ public static boolean isConfiguration(SomeSchemaElement fileElement) public static boolean isConfiguration(ServerSchemaElement fileElement) { String fileName = fileElement.getSchemaFile(); if (fileName != null) @@ -2805,4 +2809,149 @@ } } /** * Test whether provided schema element is an attribute type. * * @param element * Element to check. * @return {@code true} iff element is an attribute type. */ public static boolean isAttributeType(ServerSchemaElement element) { return element.asSchemaElement() instanceof AttributeType; } /** * Returns the name of configuration attribute corresponding to the provided element. * * @param element * Either an attribute type or an object class. * Using any other schema element will return invalid result. * @return Either "attributeTypes" or "objectClasses" */ public static String getAttributeConfigName(ServerSchemaElement element) { return isAttributeType(element) ? ConfigConstants.ATTR_ATTRIBUTE_TYPES : ConfigConstants.ATTR_OBJECTCLASSES; } /** * Returns the name or OID of provided element. * * @param element * Either an attribute type or an object class. * Using any other schema element will yield an exception. * @return Either "attributeTypes" or "objectClasses" */ public static String getElementNameOrOID(ServerSchemaElement element) { SchemaElement elem = element.asSchemaElement(); if (elem instanceof AttributeType) { return ((AttributeType) elem).getNameOrOID(); } return ((ObjectClass) elem).getNameOrOID(); } /** * Returns the OID of provided element. * * @param element * Either an attribute type or an object class. * Using any other schema element will yield an exception. * @return Either "attributeTypes" or "objectClasses" */ public static String getElementOID(ServerSchemaElement element) { SchemaElement elem = element.asSchemaElement(); if (elem instanceof AttributeType) { return ((AttributeType) elem).getOID(); } return ((ObjectClass) elem).getOID(); } /** * Return a new attribute type with the provided new superior type. * * @param attributeType * Initial attribute type. * @param newSuperiorType * new superior type to use. * @return the new attribute type */ public static AttributeType updateAttributeTypeWithNewSuperiorType(AttributeType attributeType, AttributeType newSuperiorType) { String superiorTypeOID = newSuperiorType != null ? newSuperiorType.getNameOrOID() : null; return new SchemaBuilder() .buildAttributeType(attributeType) .superiorType(superiorTypeOID) .addToSchemaOverwrite() .toSchema() .getAttributeType(attributeType.getNameOrOID()); } /** * Updates an extra property of provided schema element with a single value. * * @param serverContext * the server context * @param element * Either an attribute type or an object class. * Using any other schema element will yield an exception. * @param property * the property to set * @param value * the value to set * @return the updated schema element */ public static ServerSchemaElement updateSchemaElementExtraPropertySingleValue(ServerContext serverContext, ServerSchemaElement element, String property, String value) { List<String> values = value != null ? Arrays.asList(value) : null; return updateSchemaElementExtraPropertyMultiplesValues(serverContext, element, property, values); } /** * Updates an extra property of provided schema element with several values. * * @param serverContext * the server context * @param element * Either an attribute type or an object class. * Using any other schema element will yield an exception. * @param property * the property to set * @param values * the list of values to set * @return the updated schema element */ public static ServerSchemaElement updateSchemaElementExtraPropertyMultiplesValues(ServerContext serverContext, ServerSchemaElement element, String property, List<String> values) { org.forgerock.opendj.ldap.schema.Schema schemaNG = serverContext != null ? serverContext.getSchemaNG() : org.forgerock.opendj.ldap.schema.Schema.getDefaultSchema(); SchemaBuilder schemaBuilder = new SchemaBuilder(schemaNG); SchemaElement elem = element.asSchemaElement(); if (elem instanceof AttributeType) { AttributeType attr = (AttributeType) elem; AttributeType.Builder builder = schemaBuilder.buildAttributeType(attr).removeExtraProperty(property, (String) null); if (values != null && !values.isEmpty()) { builder.extraProperties(property, values); } return new ServerSchemaElement(builder.addToSchemaOverwrite().toSchema().getAttributeType(attr.getNameOrOID())); } // It is an object class ObjectClass oc = (ObjectClass) elem; ObjectClass.Builder builder = schemaBuilder.buildObjectClass(oc).removeExtraProperty(property, (String) null); if (values != null && !values.isEmpty()) { builder.extraProperties(property, values); } return new ServerSchemaElement(builder.addToSchemaOverwrite().toSchema().getObjectClass(oc.getNameOrOID())); } } opendj-server-legacy/src/main/java/org/opends/server/schema/ServerSchemaElement.java
@@ -48,6 +48,16 @@ } /** * Returns this schema element. * * @return this schema element */ public SchemaElement asSchemaElement() { return this.element; } /** * Retrieves the definition string used to create this schema element * and including the X-SCHEMA-FILE extension. *