use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class LdapNetworkConnection method deleteTree.
/**
* deletes the entry with the given Dn, and all its children
*
* @param dn the target entry's Dn
* @throws LdapException If the Dn is not valid or if the deletion failed
*/
public void deleteTree(Dn dn) throws LdapException {
String treeDeleteOid = "1.2.840.113556.1.4.805";
if (isControlSupported(treeDeleteOid)) {
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName(dn);
deleteRequest.addControl(new OpaqueControl(treeDeleteOid));
DeleteResponse deleteResponse = delete(deleteRequest);
processResponse(deleteResponse);
} else {
String msg = "The subtreeDelete control (1.2.840.113556.1.4.805) is not supported by the server\n" + " The deletion has been aborted";
LOG.error(msg);
throw new LdapException(msg);
}
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class LdapNetworkConnection method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(Dn dn) throws LdapException {
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName(dn);
DeleteResponse deleteResponse = delete(deleteRequest);
processResponse(deleteResponse);
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class DelRequestTest method testRequestWith1ControlBase64Value.
/**
* Test parsing of a request with a (optional) Control element
*/
@Test
public void testRequestWith1ControlBase64Value() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(DelRequestTest.class.getResource("request_with_1_control_base64_value.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
DeleteRequest delRequest = (DeleteRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = delRequest.getControls();
assertEquals(1, delRequest.getControls().size());
Control control = controls.get("1.2.840.113556.1.4.643");
assertNotNull(control);
assertTrue(control.isCritical());
assertEquals("1.2.840.113556.1.4.643", control.getOid());
assertEquals("DSMLv2.0 rocks!!", Strings.utf8ToString(((DsmlControl<?>) control).getValue()));
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class DelRequestTest method testRequestWithDn.
/**
* Test parsing of a request with the dn attribute
*/
@Test
public void testRequestWithDn() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(DelRequestTest.class.getResource("request_with_dn_attribute.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
DeleteRequest delRequest = (DeleteRequest) parser.getBatchRequest().getCurrentRequest();
assertTrue(delRequest.getName().equals("cn=Bob Rush,ou=Dev,dc=Example,dc=COM"));
}
use of org.apache.directory.api.ldap.model.message.DeleteRequest in project directory-ldap-api by apache.
the class DelRequestTest method testRequestWith2Controls.
/**
* Test parsing of a request with 2 (optional) Control elements
*/
@Test
public void testRequestWith2Controls() {
Dsmlv2Parser parser = null;
try {
parser = newParser();
parser.setInput(DelRequestTest.class.getResource("request_with_2_controls.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
DeleteRequest delRequest = (DeleteRequest) parser.getBatchRequest().getCurrentRequest();
Map<String, Control> controls = delRequest.getControls();
assertEquals(2, delRequest.getControls().size());
Control control = controls.get("1.2.840.113556.1.4.789");
assertNotNull(control);
assertFalse(control.isCritical());
assertEquals("1.2.840.113556.1.4.789", control.getOid());
assertEquals("Some other text", Strings.utf8ToString(((DsmlControl<?>) control).getValue()));
}
Aggregations