Search in sources :

Example 11 with DeleteRequest

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);
    }
}
Also used : DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 12 with DeleteRequest

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);
}
Also used : DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest)

Example 13 with DeleteRequest

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()));
}
Also used : DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Control(org.apache.directory.api.ldap.model.message.Control) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 14 with DeleteRequest

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"));
}
Also used : Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 15 with DeleteRequest

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()));
}
Also used : DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Control(org.apache.directory.api.ldap.model.message.Control) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Aggregations

DeleteRequest (org.apache.directory.api.ldap.model.message.DeleteRequest)18 Test (org.junit.Test)11 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)9 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)9 Control (org.apache.directory.api.ldap.model.message.Control)7 DeleteRequestImpl (org.apache.directory.api.ldap.model.message.DeleteRequestImpl)7 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)5 DeleteResponse (org.apache.directory.api.ldap.model.message.DeleteResponse)5 DeleteRequestDecorator (org.apache.directory.api.ldap.codec.decorators.DeleteRequestDecorator)4 Dn (org.apache.directory.api.ldap.model.name.Dn)4 DecoderException (org.apache.directory.api.asn1.DecoderException)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)3 ByteBuffer (java.nio.ByteBuffer)2 EncoderException (org.apache.directory.api.asn1.EncoderException)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2 BatchRequestDsml (org.apache.directory.api.dsmlv2.request.BatchRequestDsml)2 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)2 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)2 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)2 AbandonRequest (org.apache.directory.api.ldap.model.message.AbandonRequest)2