Skip to content

Commit

Permalink
Added type parameter for RestLiResponseEnvelope to RestLiResponseData…
Browse files Browse the repository at this point in the history
… and RestLiResponseDataImpl. Moved status and exception from RestLiResponseData to RestLiResponseEnvelope. This adds strong typing to response implementation and aligns with how data, status and exception are accessed.

Created subclasses for UpdateResponseBuilder, BatchUpdateResponseBuilder, and CollectionResponseBuilder to build responses for specific types.

Broke ErrorResponseBuilder from RestLiResponseBuilder hierarchy.

Removed type parameter for RestLiCallback and RestLiFilterResponseContextFactory.

Made IdEntityResponse to extend IdResponse.

RB=1076571
G=si-dev
R=kbalasub,nshankar,mnchen
A=mnchen
  • Loading branch information
Xiao Ma committed Sep 12, 2017
1 parent 26c9fc0 commit 6f57067
Show file tree
Hide file tree
Showing 80 changed files with 2,131 additions and 1,901 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,15 @@
14.0.13 15.0.1
------- -------


15.0.0
-------
(RB=1076571)
Added type parameter for RestLiResponseEnvelope to RestLiResponseData and RestLiResponseDataImpl.
Moved status and exception from RestLiResponseData to RestLiResponseEnvelope.
Created subclasses for UpdateResponseBuilder, BatchUpdateResponseBuilder, and CollectionResponseBuilder to build responses for specific types.
Broke ErrorResponseBuilder from RestLiResponseBuilder hierarchy.
Removed type parameter for RestLiCallback and RestLiFilterResponseContextFactory.
Made IdEntityResponse to extend IdResponse.


14.0.12 14.0.12
------- -------
Expand Down
8 changes: 5 additions & 3 deletions build_script/cleanGenerated.gradle
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ afterEvaluate {
if (!project.plugins.hasPlugin('pegasus')) if (!project.plugins.hasPlugin('pegasus'))
{ {
project.sourceSets.all { SourceSet sourceSet -> project.sourceSets.all { SourceSet sourceSet ->
final Task cleanGeneratedDirTask = project.task(sourceSet.getTaskName('clean', 'GeneratedDir')) << { final Task cleanGeneratedDirTask = project.task(sourceSet.getTaskName('clean', 'GeneratedDir')) {
project.delete(project.file(rootProject.ext.build.getDataTemplateOutDirPath(project, sourceSet)).parentFile) doLast {
project.delete(project.file(rootProject.ext.build.getRestModelOutDirPath(project, sourceSet)).parentFile) project.delete(project.file(rootProject.ext.build.getDataTemplateOutDirPath(project, sourceSet)).parentFile)
project.delete(project.file(rootProject.ext.build.getRestModelOutDirPath(project, sourceSet)).parentFile)
}
} }


// make clean tasks depend on deleting the generated directories // make clean tasks depend on deleting the generated directories
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
version=14.0.12 version=15.0.0
sonatypeUsername=please_set_in_home_dir_if_uploading_to_maven_central sonatypeUsername=please_set_in_home_dir_if_uploading_to_maven_central
sonatypePassword=please_set_in_home_dir_if_uploading_to_maven_central sonatypePassword=please_set_in_home_dir_if_uploading_to_maven_central
org.gradle.configureondemand=true org.gradle.configureondemand=true
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,43 +23,35 @@
* *
* @author Boyang Chen * @author Boyang Chen
*/ */
public class IdEntityResponse<K, V extends RecordTemplate> extends RecordTemplate public class IdEntityResponse<K, V extends RecordTemplate> extends IdResponse<K>
{ {
private K _key;
private V _entity; private V _entity;


public IdEntityResponse(K key, V entity) public IdEntityResponse(K key, V entity)
{ {
super(null, null); super(key);
_key = key;
_entity = entity; _entity = entity;
} }


public K getId() public V getEntity()
{
return _key;
}

public Object getEntity()
{ {
return _entity; return _entity;
} }


@Override @Override
public String toString() public String toString()
{ {
return "id: " + (_key == null ? "" : _key) + ", entity: " + (_entity == null ? "" : _entity); return "id: " + super.toString() + ", entity: " + (_entity == null ? "" : _entity);
} }


@Override @Override
public boolean equals(Object that) public boolean equals(Object obj)
{ {
if (that instanceof IdEntityResponse) if (obj instanceof IdEntityResponse)
{ {
IdEntityResponse<?, ?> thatIdResponse = (IdEntityResponse<?, ?>) that; IdEntityResponse<?, ?> that = (IdEntityResponse<?, ?>) obj;
boolean keyEquals = (this._key == null)? thatIdResponse._key == null : this._key.equals(thatIdResponse._key); return super.equals(that) &&
boolean entityEquals = (this._entity == null)? thatIdResponse._entity == null : this._entity.equals(thatIdResponse._entity); (this._entity == null ? that._entity == null : this._entity.equals(that._entity));
return keyEquals && entityEquals;
} }
else else
{ {
Expand All @@ -70,6 +62,6 @@ public boolean equals(Object that)
@Override @Override
public int hashCode() public int hashCode()
{ {
return (_key == null ? 0 : _key.hashCode()) + (_entity == null ? 0 : _entity.hashCode()); return super.hashCode() * 31 + (_entity == null ? 0 : _entity.hashCode());
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders; import com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders;
import com.linkedin.restli.examples.greetings.client.GreetingsTaskBuilders; import com.linkedin.restli.examples.greetings.client.GreetingsTaskBuilders;
import com.linkedin.restli.examples.greetings.client.GreetingsTaskRequestBuilders; import com.linkedin.restli.examples.greetings.client.GreetingsTaskRequestBuilders;
import com.linkedin.restli.internal.server.response.RecordResponseEnvelope;
import com.linkedin.restli.server.RestLiResponseData;
import com.linkedin.restli.server.RestLiServiceException; import com.linkedin.restli.server.RestLiServiceException;
import com.linkedin.restli.server.RoutingException; import com.linkedin.restli.server.RoutingException;
import com.linkedin.restli.server.filter.Filter; import com.linkedin.restli.server.filter.Filter;
Expand Down Expand Up @@ -399,6 +401,7 @@ public TestFilterWithResponse(RuntimeException responseFilterException)
} }


@Override @Override
@SuppressWarnings("unchecked")
public CompletableFuture<Void> onResponse(FilterRequestContext requestContext, public CompletableFuture<Void> onResponse(FilterRequestContext requestContext,
FilterResponseContext responseContext) FilterResponseContext responseContext)
{ {
Expand All @@ -410,7 +413,7 @@ public CompletableFuture<Void> onResponse(FilterRequestContext requestContext,
switch (responseContext.getResponseData().getResponseType()) switch (responseContext.getResponseData().getResponseType())
{ {
case SINGLE_ENTITY: case SINGLE_ENTITY:
entity = responseContext.getResponseData().getRecordResponseEnvelope().getRecord(); entity = ((RestLiResponseData<RecordResponseEnvelope>)responseContext.getResponseData()).getResponseEnvelope().getRecord();
break; break;
case STATUS_ONLY: case STATUS_ONLY:
entity = null; entity = null;
Expand All @@ -419,13 +422,13 @@ public CompletableFuture<Void> onResponse(FilterRequestContext requestContext,
throw new RuntimeException("Unexpected resolver type."); throw new RuntimeException("Unexpected resolver type.");
} }
if (entity != null && requestContext.getMethodType() == ResourceMethod.GET if (entity != null && requestContext.getMethodType() == ResourceMethod.GET
&& responseContext.getResponseData().getStatus() == HttpStatus.S_200_OK) && responseContext.getResponseData().getResponseEnvelope().getStatus() == HttpStatus.S_200_OK)
{ {
Greeting greeting = new Greeting(entity.data()); Greeting greeting = new Greeting(entity.data());
if (greeting.hasTone()) if (greeting.hasTone())
{ {
greeting.setTone(mapToneForOutgoingResponse(greeting.getTone())); greeting.setTone(mapToneForOutgoingResponse(greeting.getTone()));
responseContext.getResponseData().getRecordResponseEnvelope().setRecord(greeting, HttpStatus.S_200_OK); ((RestLiResponseData<RecordResponseEnvelope>)responseContext.getResponseData()).getResponseEnvelope().setRecord(greeting, HttpStatus.S_200_OK);
} }
} }
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
Expand All @@ -437,7 +440,7 @@ public CompletableFuture<Void> onError(Throwable t, final FilterRequestContext r
{ {
numErrors++; numErrors++;
if (requestContext.getMethodType() == ResourceMethod.CREATE if (requestContext.getMethodType() == ResourceMethod.CREATE
&& responseContext.getResponseData().getStatus() == REQ_FILTER_ERROR_STATUS) && responseContext.getResponseData().getResponseEnvelope().getStatus() == REQ_FILTER_ERROR_STATUS)
{ {
throw _responseFilterException; throw _responseFilterException;
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testCreateIdEntity(RestClient restClient, String expectedContentType
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType); Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
Assert.assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/" + builders.getPrimaryResource() + "/" + id); Assert.assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/" + builders.getPrimaryResource() + "/" + id);
Assert.assertEquals(id, Long.parseLong(stringId)); Assert.assertEquals(id, Long.parseLong(stringId));
Assert.assertEquals("second time!", ((Greeting) response.getEntity().getEntity()).getMessage()); Assert.assertEquals("second time!", response.getEntity().getEntity().getMessage());
} }


@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider") @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
Expand All @@ -102,8 +102,8 @@ public void testEntityWithProjection(RestClient restClient, String expectedConte
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType); Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
Assert.assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/" + builders.getPrimaryResource() + "/" + id + "?fields=tone,id"); Assert.assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/" + builders.getPrimaryResource() + "/" + id + "?fields=tone,id");
Assert.assertEquals(id, Long.parseLong(stringId)); Assert.assertEquals(id, Long.parseLong(stringId));
Assert.assertEquals(false, ((Greeting) response.getEntity().getEntity()).hasMessage()); Assert.assertEquals(false, response.getEntity().getEntity().hasMessage());
Assert.assertEquals(Tone.FRIENDLY, ((Greeting) response.getEntity().getEntity()).getTone()); Assert.assertEquals(Tone.FRIENDLY, response.getEntity().getEntity().getTone());
} }


@Test (dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider") @Test (dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
Expand Down
Loading

0 comments on commit 6f57067

Please sign in to comment.