Search in sources :

Example 86 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class TriggerSpecificationParserTest method testWithSearchContextOption.

@Test
public void testWithSearchContextOption() throws Exception {
    TriggerSpecification triggerSpecification = null;
    String spec = "AFTER ModifyDN.Rename CALL \"Logger.logModifyDNRenameOperation\" \n" + "{ searchContext { scope one } \"cn=Logger,ou=Stored Procedures,ou=system\" } \n" + "($entry, $newrdn);  # Stored Procedure Parameter(s)";
    triggerSpecification = parser.parse(spec);
    assertNotNull(triggerSpecification);
    assertEquals(triggerSpecification.getActionTime(), ActionTime.AFTER);
    assertEquals(triggerSpecification.getLdapOperation(), LdapOperation.MODIFYDN_RENAME);
    List<SPSpec> spSpecs = triggerSpecification.getSPSpecs();
    assertTrue(spSpecs != null);
    assertTrue(spSpecs.size() == 1);
    SPSpec theSpec = spSpecs.get(0);
    assertEquals(theSpec.getName(), "Logger.logModifyDNRenameOperation");
    assertEquals(theSpec.getOptions().size(), 1);
    assertTrue(theSpec.getOptions().contains(new StoredProcedureSearchContextOption(new Dn("cn=Logger,ou=Stored Procedures,ou=system"), SearchScope.ONELEVEL)));
    assertEquals(theSpec.getParameters().size(), 2);
    assertTrue(theSpec.getParameters().contains(StoredProcedureParameter.ModifyDN_ENTRY.instance()));
    assertTrue(theSpec.getParameters().contains(StoredProcedureParameter.ModifyDN_NEW_RDN.instance()));
}
Also used : StoredProcedureSearchContextOption(org.apache.directory.api.ldap.trigger.StoredProcedureSearchContextOption) SPSpec(org.apache.directory.api.ldap.trigger.TriggerSpecification.SPSpec) Dn(org.apache.directory.api.ldap.model.name.Dn) TriggerSpecification(org.apache.directory.api.ldap.trigger.TriggerSpecification) Test(org.junit.Test)

Example 87 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class DnNode method rename.

/**
 * rename the DnNode's Dn
 *
 * @param newRdn the new Rdn of this node
 * @throws LdapException If the rename failed
 */
public synchronized void rename(Rdn newRdn) throws LdapException {
    Dn temp = nodeDn.getParent();
    temp = temp.add(newRdn);
    Rdn oldRdn = nodeRdn;
    nodeRdn = temp.getRdn();
    nodeDn = temp;
    if (parent != null) {
        parent.children.remove(oldRdn.getNormName());
        parent.children.put(nodeRdn.getNormName(), this);
    }
    updateAfterModDn(nodeDn);
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn)

Example 88 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class DnNode method move.

/**
 * move the DnNode's Dn
 *
 * @param newParent the new parent Dn
 * @throws LdapException If the move failed
 */
public synchronized void move(Dn newParent) throws LdapException {
    DnNode<N> tmp = null;
    Dn tmpDn = null;
    // check if the new parent Dn is child of the parent
    if (newParent.isDescendantOf(parent.nodeDn)) {
        tmp = parent;
        tmpDn = parent.nodeDn;
    }
    // if yes, then drill for the new parent node
    if (tmpDn != null) {
        int parentNodeSize = tmpDn.size();
        int count = newParent.size() - parentNodeSize;
        while (count-- > 0) {
            tmp = tmp.getChild(newParent.getRdn(parentNodeSize++));
        }
    }
    // root node and then find the new parent node
    if (tmp == null) {
        tmp = this;
        while (tmp.parent != null) {
            tmp = tmp.parent;
        }
        tmp = tmp.getNode(newParent);
    }
    nodeDn = newParent.add(nodeRdn);
    updateAfterModDn(nodeDn);
    if (parent != null) {
        parent.children.remove(nodeRdn.getNormName());
    }
    parent = tmp;
    parent.children.put(nodeRdn.getNormName(), this);
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn)

Example 89 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class TestDnNode method testAdd3LevelDN.

/**
 * Test the addition of a Dn with three Rdn
 */
@Test
public void testAdd3LevelDN() throws LdapException {
    DnNode<Dn> tree = new DnNode<Dn>();
    Dn dn = new Dn("dc=c,dc=b,dc=a");
    tree.add(dn, dn);
    assertNotNull(tree);
    Map<String, DnNode<Dn>> children = tree.getChildren();
    assertNotNull(children);
    assertEquals(1, children.size());
    assertNull(tree.getElement());
    DnNode<Dn> level1 = children.get(new Rdn("dc=a").getNormName());
    DnNode<Dn> level2 = level1.getChildren().get(new Rdn("dc=b").getNormName());
    DnNode<Dn> level3 = level2.getChildren().get(new Rdn("dc=c").getNormName());
    assertNotNull(level3);
    assertEquals(dn, level3.getElement());
}
Also used : DnNode(org.apache.directory.api.ldap.util.tree.DnNode) Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn) Test(org.junit.Test)

Example 90 with Dn

use of org.apache.directory.api.ldap.model.name.Dn in project directory-ldap-api by apache.

the class TestDnNode method testIsLeafDN.

// ---------------------------------------------------------------------------
// Test the isLeaf(Dn) method
// ---------------------------------------------------------------------------
@Test
public void testIsLeafDN() throws Exception {
    DnNode<Dn> tree = new DnNode<Dn>();
    Dn dn1 = new Dn("dc=c,dc=b,dc=a");
    tree.add(dn1, dn1);
    Dn dn2 = new Dn("dc=e,dc=a");
    tree.add(dn2);
    assertFalse(tree.isLeaf(Dn.EMPTY_DN));
    assertFalse(tree.isLeaf(new Dn("dc=a")));
    assertFalse(tree.isLeaf(new Dn("dc=b,dc=a")));
    assertTrue(tree.isLeaf(dn1));
    assertTrue(tree.isLeaf(dn2));
}
Also used : DnNode(org.apache.directory.api.ldap.util.tree.DnNode) Dn(org.apache.directory.api.ldap.model.name.Dn) Test(org.junit.Test)

Aggregations

Dn (org.apache.directory.api.ldap.model.name.Dn)307 Test (org.junit.Test)183 Rdn (org.apache.directory.api.ldap.model.name.Rdn)63 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)50 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)39 Entry (org.apache.directory.api.ldap.model.entry.Entry)34 DnNode (org.apache.directory.api.ldap.util.tree.DnNode)30 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)20 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)19 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)17 Modification (org.apache.directory.api.ldap.model.entry.Modification)17 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)16 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)10 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)10 ModifyRequest (org.apache.directory.api.ldap.model.message.ModifyRequest)10 Referral (org.apache.directory.api.ldap.model.message.Referral)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)8 Value (org.apache.directory.api.ldap.model.entry.Value)8