Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a restli delete method for subresource to support soft deletion o…
Browse files Browse the repository at this point in the history
…f aspect
jywadhwani committed Nov 8, 2021
1 parent 0266fb0 commit 682c9fc
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import com.linkedin.restli.server.CreateResponse;
import com.linkedin.restli.server.PagingContext;
import com.linkedin.restli.server.PathKeys;
import com.linkedin.restli.server.UpdateResponse;
import com.linkedin.restli.server.annotations.PagingContextParam;
import com.linkedin.restli.server.annotations.RestMethod;
import com.linkedin.restli.server.annotations.ReturnEntity;
@@ -111,6 +112,22 @@ public Task<CreateResponse> create(@Nonnull ASPECT aspect) {
});
}

/**
* Soft deletes the latest version of aspect if it exists.
*
* @return {@link UpdateResponse} indicating the status code of the response.
*/
@RestMethod.Delete
@Nonnull
public Task<UpdateResponse> delete() {
return RestliUtils.toTask(() -> {
final URN urn = getUrn(getContext().getPathKeys());
final AuditStamp auditStamp = getAuditor().requestAuditStamp(getContext().getRawRequestContext());
getLocalDAO().delete(urn, this._aspectClass, auditStamp);
return new UpdateResponse(HttpStatus.S_200_OK);
});
}

/**
* Similar to {@link #create(RecordTemplate)} but uses a create lambda instead.
*/
Original file line number Diff line number Diff line change
@@ -112,6 +112,16 @@ public void testCreate() {
verifyNoMoreInteractions(_mockLocalDAO);
}

@Test
public void testSoftDelete() {

runAndWait(_resource.delete());

// this should test that delete method of DAO is being called once
verify(_mockLocalDAO, times(1)).delete(eq(ENTITY_URN), eq(AspectFoo.class), any(AuditStamp.class));
verifyNoMoreInteractions(_mockLocalDAO);
}

@Test
public void testCreateViaLambda() {
AspectFoo foo = new AspectFoo().setValue("foo");

0 comments on commit 682c9fc

Please sign in to comment.