mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

matthew_swift
19.13.2007 0326322b342aa2dea86f71760521022411739879
Fix issue 2451 part #1: https://opends.dev.java.net/issues/show_bug.cgi?id=2451

It is now possible to override the default naming argument for dsconfig sub-commands using the CLI profile in the XML definitions. To do this add the "naming-argument-override" attribute to a relation's CLI profile relation element. For example:

<adm:relation name="virtual-attribute">
<adm:one-to-many />
<adm:profile name="ldap">
<ldap:rdn-sequence>
cn=Virtual Attributes,cn=config
</ldap:rdn-sequence>
</adm:profile>
<adm:profile name="cli">
<cli:relation naming-argument-override="name">
<cli:default-property name="enabled" />
<cli:default-property name="attribute-type" />
</cli:relation>
</adm:profile>
</adm:relation>
4 files modified
72 ■■■■ changed files
opends/resource/admin/admin-cli.xsd 14 ●●●●● patch | view | raw | blame | history
opends/resource/admin/cliMOProfile.xsl 8 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsconfig/CLIProfile.java 36 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java 14 ●●●●● patch | view | raw | blame | history
opends/resource/admin/admin-cli.xsd
@@ -69,6 +69,20 @@
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
      <xsd:attribute name="naming-argument-override"
        type="adm:name-type" use="optional">
        <xsd:annotation>
          <xsd:documentation>
            A command-line argument name which should be used to
            override the default argument name used to identify managed
            objects referenced by this relation. By default the
            command-line argument name is derived by taking the last
            word in the relation name and appending "-name". For
            example, the relation "certificate-mapper" becomes
            "mapper-name".
          </xsd:documentation>
        </xsd:annotation>
      </xsd:attribute>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>
opends/resource/admin/cliMOProfile.xsl
@@ -52,6 +52,14 @@
    <xsl:for-each select="$this-all-relations">
      <xsl:sort select="@name" />
      <!--
        Generate the naming argument override if present
      -->
      <xsl:value-of
        select="concat('relation.', @name,
                       '.naming-argument-override=',
                       adm:profile[@name='cli']/cli:relation/@naming-argument-override,
                       '&#xa;')" />
      <!--
        Generate list of properties which should be displayed by default in list-xxx operations.
      -->
      <xsl:value-of
opends/src/server/org/opends/server/tools/dsconfig/CLIProfile.java
@@ -34,6 +34,7 @@
import java.util.Set;
import org.opends.server.admin.AbstractManagedObjectDefinition;
import org.opends.server.admin.InstantiableRelationDefinition;
import org.opends.server.admin.ManagedObjectDefinitionResource;
import org.opends.server.admin.RelationDefinition;
@@ -42,7 +43,7 @@
/**
 * This class is used to access CLI profile annotations.
 */
class CLIProfile {
final class CLIProfile {
  // The singleton instance.
  private static final CLIProfile INSTANCE = new CLIProfile();
@@ -88,6 +89,39 @@
  /**
   * Gets the naming argument which should be used for a relation
   * definition.
   *
   * @param r
   *          The relation definition.
   * @return Returns the naming argument which should be used for a
   *         relation definition.
   */
  public String getNamingArgument(InstantiableRelationDefinition<?, ?> r) {
    String s = resource.getString(r.getParentDefinition(),
        "relation." + r.getName() + ".naming-argument-override").trim();
    if (s.length() == 0) {
      // Use the last word in the managed object name as the argument
      // prefix.
      StringBuilder builder = new StringBuilder();
      s = r.getChildDefinition().getName();
      int i = s.lastIndexOf('-');
      if (i < 0 || i == (s.length() - 1)) {
        builder.append(s);
      } else {
        builder.append(s.substring(i + 1));
      }
      builder.append("-name");
      s = builder.toString();
    }
    return s;
  }
  /**
   * Determines if instances of the specified managed object
   * definition are to be used for customization.
   *
opends/src/server/org/opends/server/tools/dsconfig/SubCommandHandler.java
@@ -455,19 +455,7 @@
        AbstractManagedObjectDefinition<C, S> d, String name) {
      sz--;
      // Use the last word in the managed object name as the argument
      // prefix.
      StringBuilder builder = new StringBuilder();
      String s = d.getName();
      int i = s.lastIndexOf('-');
      if (i < 0 || i == (s.length() - 1)) {
        builder.append(s);
      } else {
        builder.append(s.substring(i + 1));
      }
      builder.append("-name");
      String argName = builder.toString();
      String argName = CLIProfile.getInstance().getNamingArgument(r);
      StringArgument arg;
      try {