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

Matthew Swift
03.39.2013 fd4afdb0fb705de12c6702065914abcb8f267aa6
CREST-692: Implement delete support

* implement basic delete support
2 files modified
49 ■■■■ changed files
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPCollectionResourceProvider.java 43 ●●●●● patch | view | raw | blame | history
opendj3/opendj-rest2ldap/src/test/java/org/forgerock/opendj/rest2ldap/BasicRequestsTest.java 6 ●●●● patch | view | raw | blame | history
opendj3/opendj-rest2ldap/src/main/java/org/forgerock/opendj/rest2ldap/LDAPCollectionResourceProvider.java
@@ -64,6 +64,7 @@
import org.forgerock.opendj.ldap.SearchScope;
import org.forgerock.opendj.ldap.controls.PostReadRequestControl;
import org.forgerock.opendj.ldap.controls.PostReadResponseControl;
import org.forgerock.opendj.ldap.controls.PreReadRequestControl;
import org.forgerock.opendj.ldap.controls.PreReadResponseControl;
import org.forgerock.opendj.ldap.requests.AddRequest;
import org.forgerock.opendj.ldap.requests.Requests;
@@ -71,6 +72,7 @@
import org.forgerock.opendj.ldap.responses.Result;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.ldap.responses.SearchResultReference;
import org.forgerock.opendj.ldif.ChangeRecord;
/**
 * A {@code CollectionResourceProvider} implementation which maps a JSON
@@ -162,7 +164,43 @@
    @Override
    public void deleteInstance(final ServerContext context, final String resourceId,
            final DeleteRequest request, final ResultHandler<Resource> handler) {
        handler.handleError(new NotSupportedException("Not yet implemented"));
        final Context c = wrap(context);
        final ResultHandler<Resource> h = wrap(c, handler);
        // FIXME: assertion and subtree delete controls.
        // Get connection then perform the search.
        c.run(h, new Runnable() {
            @Override
            public void run() {
                // Find the entry and then delete it.
                final SearchRequest searchRequest =
                        nameStrategy.createSearchRequest(c, getBaseDN(c), resourceId).addAttribute(
                                "1.1");
                c.getConnection().searchSingleEntryAsync(searchRequest,
                        new org.forgerock.opendj.ldap.ResultHandler<SearchResultEntry>() {
                            @Override
                            public void handleErrorResult(final ErrorResultException error) {
                                h.handleError(asResourceException(error));
                            }
                            @Override
                            public void handleResult(final SearchResultEntry entry) {
                                // Perform delete operation.
                                final ChangeRecord deleteRequest =
                                        Requests.newDeleteRequest(entry.getName());
                                if (config.readOnUpdatePolicy() == CONTROLS) {
                                    final String[] attributes =
                                            getLDAPAttributes(c, request.getFields());
                                    deleteRequest.addControl(PreReadRequestControl.newControl(
                                            false, attributes));
                                }
                                c.getConnection().applyChangeAsync(deleteRequest, null,
                                        postUpdateHandler(c, h));
                            }
                        });
            }
        });
    }
    @Override
@@ -195,8 +233,7 @@
                            h.handleResult(new QueryResult());
                        } else {
                            // Perform the search.
                            final String[] attributes =
                                    getLDAPAttributes(c, request.getFields());
                            final String[] attributes = getLDAPAttributes(c, request.getFields());
                            final SearchRequest request =
                                    Requests.newSearchRequest(getBaseDN(c),
                                            SearchScope.SINGLE_LEVEL, ldapFilter == Filter
opendj3/opendj-rest2ldap/src/test/java/org/forgerock/opendj/rest2ldap/BasicRequestsTest.java
@@ -50,7 +50,7 @@
    // so that we can check that the request handler is returning everything.
    // FIXME: factor out test for re-use as common test suite (e.g. for InMemoryBackend).
    @Test(enabled = false)
    @Test
    public void testDelete() throws Exception {
        final RequestHandler handler = newCollection(builder().build());
        final Connection connection = newInternalConnection(handler);
@@ -64,7 +64,7 @@
        }
    }
    @Test(enabled = false)
    @Test
    public void testDeleteMVCCMatch() throws Exception {
        final RequestHandler handler = newCollection(builder().build());
        final Connection connection = newInternalConnection(handler);
@@ -86,7 +86,7 @@
        connection.delete(c(), newDeleteRequest("/test1").setRevision("12346"));
    }
    @Test(expectedExceptions = NotFoundException.class, enabled = false)
    @Test(expectedExceptions = NotFoundException.class)
    public void testDeleteNotFound() throws Exception {
        final RequestHandler handler = newCollection(builder().build());
        final Connection connection = newInternalConnection(handler);