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()));
}
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);
}
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);
}
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());
}
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));
}
Aggregations