Permalink
Browse files

Added type parameter for RestLiResponseEnvelope to RestLiResponseData…

… 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
Xiao Ma committed Aug 19, 2017
1 parent 26c9fc0 commit 6f57067edf594aab8411c8112464a4b383d42dee
Showing with 2,131 additions and 1,901 deletions.
  1. +10 −1 CHANGELOG
  2. +5 −3 build_script/cleanGenerated.gradle
  3. +1 −1 gradle.properties
  4. +10 −18 restli-common/src/main/java/com/linkedin/restli/common/IdEntityResponse.java
  5. +7 −4 restli-int-test/src/test/java/com/linkedin/restli/examples/TestFilters.java
  6. +3 −3 restli-int-test/src/test/java/com/linkedin/restli/examples/TestReturnEntityWithCreate.java
  7. +69 −149 ...testutils/src/main/java/com/linkedin/restli/internal/server/response/ResponseDataBuilderUtil.java
  8. +39 −40 ...utils/src/test/java/com/linkedin/restli/internal/server/response/TestResponseDataBuilderUtil.java
  9. +5 −1 restli-server/build.gradle
  10. +2 −4 restli-server/src/main/java/com/linkedin/restli/internal/server/RestLiCallback.java
  11. +3 −4 restli-server/src/main/java/com/linkedin/restli/internal/server/filter/FilterChainCallback.java
  12. +3 −3 restli-server/src/main/java/com/linkedin/restli/internal/server/filter/FilterChainCallbackImpl.java
  13. +1 −1 restli-server/src/main/java/com/linkedin/restli/internal/server/filter/RestLiFilterChain.java
  14. +31 −19 ...li-server/src/main/java/com/linkedin/restli/internal/server/filter/RestLiFilterChainIterator.java
  15. +11 −35 .../src/main/java/com/linkedin/restli/internal/server/filter/RestLiFilterResponseContextFactory.java
  16. +25 −23 restli-server/src/main/java/com/linkedin/restli/internal/server/methods/MethodAdapterRegistry.java
  17. +7 −10 restli-server/src/main/java/com/linkedin/restli/internal/server/response/ActionResponseBuilder.java
  18. +11 −4 restli-server/src/main/java/com/linkedin/restli/internal/server/response/ActionResponseEnvelope.java
  19. +14 −24 ...server/src/main/java/com/linkedin/restli/internal/server/response/BatchCreateResponseBuilder.java
  20. +11 −21 ...erver/src/main/java/com/linkedin/restli/internal/server/response/BatchCreateResponseEnvelope.java
  21. +41 −0 ...server/src/main/java/com/linkedin/restli/internal/server/response/BatchDeleteResponseBuilder.java
  22. +9 −2 ...erver/src/main/java/com/linkedin/restli/internal/server/response/BatchDeleteResponseEnvelope.java
  23. +14 −17 ...li-server/src/main/java/com/linkedin/restli/internal/server/response/BatchGetResponseBuilder.java
  24. +10 −4 ...i-server/src/main/java/com/linkedin/restli/internal/server/response/BatchGetResponseEnvelope.java
  25. +41 −0 ...src/main/java/com/linkedin/restli/internal/server/response/BatchPartialUpdateResponseBuilder.java
  26. +10 −5 ...rc/main/java/com/linkedin/restli/internal/server/response/BatchPartialUpdateResponseEnvelope.java
  27. +198 −0 restli-server/src/main/java/com/linkedin/restli/internal/server/response/BatchResponseBuilder.java
  28. +10 −6 restli-server/src/main/java/com/linkedin/restli/internal/server/response/BatchResponseEnvelope.java
  29. +18 −168 ...server/src/main/java/com/linkedin/restli/internal/server/response/BatchUpdateResponseBuilder.java
  30. +10 −4 ...erver/src/main/java/com/linkedin/restli/internal/server/response/BatchUpdateResponseEnvelope.java
  31. +30 −40 ...-server/src/main/java/com/linkedin/restli/internal/server/response/CollectionResponseBuilder.java
  32. +18 −11 ...server/src/main/java/com/linkedin/restli/internal/server/response/CollectionResponseEnvelope.java
  33. +18 −16 restli-server/src/main/java/com/linkedin/restli/internal/server/response/CreateResponseBuilder.java
  34. +10 −16 restli-server/src/main/java/com/linkedin/restli/internal/server/response/CreateResponseEnvelope.java
  35. +35 −0 restli-server/src/main/java/com/linkedin/restli/internal/server/response/DeleteResponseBuilder.java
  36. +9 −7 restli-server/src/main/java/com/linkedin/restli/internal/server/response/DeleteResponseEnvelope.java
  37. +62 −0 restli-server/src/main/java/com/linkedin/restli/internal/server/response/EmptyResponseBuilder.java
  38. +9 −8 restli-server/src/main/java/com/linkedin/restli/internal/server/response/EmptyResponseEnvelope.java
  39. +0 −64 restli-server/src/main/java/com/linkedin/restli/internal/server/response/EnvelopeBuilderUtil.java
  40. +55 −28 restli-server/src/main/java/com/linkedin/restli/internal/server/response/ErrorResponseBuilder.java
  41. +40 −0 restli-server/src/main/java/com/linkedin/restli/internal/server/response/FinderResponseBuilder.java
  42. +12 −7 restli-server/src/main/java/com/linkedin/restli/internal/server/response/FinderResponseEnvelope.java
  43. +41 −0 restli-server/src/main/java/com/linkedin/restli/internal/server/response/GetAllResponseBuilder.java
  44. +12 −7 restli-server/src/main/java/com/linkedin/restli/internal/server/response/GetAllResponseEnvelope.java
  45. +11 −10 restli-server/src/main/java/com/linkedin/restli/internal/server/response/GetResponseBuilder.java
  46. +10 −3 restli-server/src/main/java/com/linkedin/restli/internal/server/response/GetResponseEnvelope.java
  47. +9 −7 ...li-server/src/main/java/com/linkedin/restli/internal/server/response/OptionsResponseEnvelope.java
  48. +35 −0 ...rver/src/main/java/com/linkedin/restli/internal/server/response/PartialUpdateResponseBuilder.java
  49. +9 −7 ...ver/src/main/java/com/linkedin/restli/internal/server/response/PartialUpdateResponseEnvelope.java
  50. +12 −6 restli-server/src/main/java/com/linkedin/restli/internal/server/response/RecordResponseEnvelope.java
  51. +7 −7 restli-server/src/main/java/com/linkedin/restli/internal/server/response/RestLiResponseBuilder.java
  52. +41 −138 restli-server/src/main/java/com/linkedin/restli/internal/server/response/RestLiResponseDataImpl.java
  53. +57 −16 restli-server/src/main/java/com/linkedin/restli/internal/server/response/RestLiResponseEnvelope.java
  54. +28 −38 restli-server/src/main/java/com/linkedin/restli/internal/server/response/RestLiResponseHandler.java
  55. +5 −33 restli-server/src/main/java/com/linkedin/restli/internal/server/response/UpdateResponseBuilder.java
  56. +9 −7 restli-server/src/main/java/com/linkedin/restli/internal/server/response/UpdateResponseEnvelope.java
  57. +2 −1 restli-server/src/main/java/com/linkedin/restli/server/CreateKVResponse.java
  58. +49 −1 restli-server/src/main/java/com/linkedin/restli/server/RestLiResponseData.java
  59. +23 −8 restli-server/src/main/java/com/linkedin/restli/server/RestLiServer.java
  60. +26 −0 restli-server/src/main/java/com/linkedin/restli/server/RestLiServiceException.java
  61. +1 −4 restli-server/src/main/java/com/linkedin/restli/server/filter/FilterResponseContext.java
  62. +1 −1 ...li-server/src/main/java/com/linkedin/restli/server/multiplexer/MultiplexedRequestHandlerImpl.java
  63. +1 −3 restli-server/src/main/java/com/linkedin/restli/server/util/FileClassNameScanner.java
  64. +20 −12 restli-server/src/main/java/com/linkedin/restli/server/validation/RestLiValidationFilter.java
  65. +33 −21 restli-server/src/test/java/com/linkedin/restli/internal/server/filter/TestRestLiFilterChain.java
  66. +5 −6 ...-server/src/test/java/com/linkedin/restli/internal/server/response/TestActionResponseBuilder.java
  67. +17 −18 ...er/src/test/java/com/linkedin/restli/internal/server/response/TestBatchCreateResponseBuilder.java
  68. +47 −49 ...erver/src/test/java/com/linkedin/restli/internal/server/response/TestBatchGetResponseBuilder.java
  69. +97 −128 ...er/src/test/java/com/linkedin/restli/internal/server/response/TestBatchUpdateResponseBuilder.java
  70. +84 −78 ...ver/src/test/java/com/linkedin/restli/internal/server/response/TestCollectionResponseBuilder.java
  71. +16 −16 ...-server/src/test/java/com/linkedin/restli/internal/server/response/TestCreateResponseBuilder.java
  72. +3 −5 ...i-server/src/test/java/com/linkedin/restli/internal/server/response/TestErrorResponseBuilder.java
  73. +10 −10 restli-server/src/test/java/com/linkedin/restli/internal/server/response/TestGetResponseBuilder.java
  74. +162 −210 restli-server/src/test/java/com/linkedin/restli/internal/server/response/TestRestLiCallback.java
  75. +17 −18 ...est/java/com/linkedin/restli/internal/server/response/TestRestLiFilterResponseContextFactory.java
  76. +137 −151 restli-server/src/test/java/com/linkedin/restli/internal/server/response/TestRestLiResponseData.java
  77. +43 −10 ...server/src/test/java/com/linkedin/restli/internal/server/response/TestRestLiResponseEnvelope.java
  78. +32 −10 ...-server/src/test/java/com/linkedin/restli/internal/server/response/TestUpdateResponseBuilder.java
  79. +41 −41 restli-server/src/test/java/com/linkedin/restli/server/test/TestRestLiMethodInvocation.java
  80. +51 −50 restli-server/src/test/java/com/linkedin/restli/server/test/TestRestLiResponseHandler.java
View
@@ -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
-------
@@ -18,9 +18,11 @@ afterEvaluate {
if (!project.plugins.hasPlugin('pegasus'))
{
project.sourceSets.all { SourceSet sourceSet ->
final Task cleanGeneratedDirTask = project.task(sourceSet.getTaskName('clean', 'GeneratedDir')) << {
project.delete(project.file(rootProject.ext.build.getDataTemplateOutDirPath(project, sourceSet)).parentFile)
project.delete(project.file(rootProject.ext.build.getRestModelOutDirPath(project, sourceSet)).parentFile)
final Task cleanGeneratedDirTask = project.task(sourceSet.getTaskName('clean', 'GeneratedDir')) {
doLast {
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
View
@@ -1,4 +1,4 @@
version=14.0.12
version=15.0.0
sonatypeUsername=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
@@ -23,43 +23,35 @@
*
* @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;
public IdEntityResponse(K key, V entity)
{
super(null, null);
_key = key;
super(key);
_entity = entity;
}
public K getId()
{
return _key;
}
public Object getEntity()
public V getEntity()
{
return _entity;
}
@Override
public String toString()
{
return "id: " + (_key == null ? "" : _key) + ", entity: " + (_entity == null ? "" : _entity);
return "id: " + super.toString() + ", entity: " + (_entity == null ? "" : _entity);
}
@Override
public boolean equals(Object that)
public boolean equals(Object obj)
{
if (that instanceof IdEntityResponse)
if (obj instanceof IdEntityResponse)
{
IdEntityResponse<?, ?> thatIdResponse = (IdEntityResponse<?, ?>) that;
boolean keyEquals = (this._key == null)? thatIdResponse._key == null : this._key.equals(thatIdResponse._key);
boolean entityEquals = (this._entity == null)? thatIdResponse._entity == null : this._entity.equals(thatIdResponse._entity);
return keyEquals && entityEquals;
IdEntityResponse<?, ?> that = (IdEntityResponse<?, ?>) obj;
return super.equals(that) &&
(this._entity == null ? that._entity == null : this._entity.equals(that._entity));
}
else
{
@@ -70,6 +62,6 @@ public boolean equals(Object that)
@Override
public int hashCode()
{
return (_key == null ? 0 : _key.hashCode()) + (_entity == null ? 0 : _entity.hashCode());
return super.hashCode() * 31 + (_entity == null ? 0 : _entity.hashCode());
}
}
@@ -44,6 +44,8 @@
import com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders;
import com.linkedin.restli.examples.greetings.client.GreetingsTaskBuilders;
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.RoutingException;
import com.linkedin.restli.server.filter.Filter;
@@ -399,6 +401,7 @@ public TestFilterWithResponse(RuntimeException responseFilterException)
}
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<Void> onResponse(FilterRequestContext requestContext,
FilterResponseContext responseContext)
{
@@ -410,7 +413,7 @@ public TestFilterWithResponse(RuntimeException responseFilterException)
switch (responseContext.getResponseData().getResponseType())
{
case SINGLE_ENTITY:
entity = responseContext.getResponseData().getRecordResponseEnvelope().getRecord();
entity = ((RestLiResponseData<RecordResponseEnvelope>)responseContext.getResponseData()).getResponseEnvelope().getRecord();
break;
case STATUS_ONLY:
entity = null;
@@ -419,13 +422,13 @@ public TestFilterWithResponse(RuntimeException responseFilterException)
throw new RuntimeException("Unexpected resolver type.");
}
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());
if (greeting.hasTone())
{
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);
@@ -437,7 +440,7 @@ public TestFilterWithResponse(RuntimeException responseFilterException)
{
numErrors++;
if (requestContext.getMethodType() == ResourceMethod.CREATE
&& responseContext.getResponseData().getStatus() == REQ_FILTER_ERROR_STATUS)
&& responseContext.getResponseData().getResponseEnvelope().getStatus() == REQ_FILTER_ERROR_STATUS)
{
throw _responseFilterException;
}
@@ -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_LOCATION), "/" + builders.getPrimaryResource() + "/" + id);
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")
@@ -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_LOCATION), "/" + builders.getPrimaryResource() + "/" + id + "?fields=tone,id");
Assert.assertEquals(id, Long.parseLong(stringId));
Assert.assertEquals(false, ((Greeting) response.getEntity().getEntity()).hasMessage());
Assert.assertEquals(Tone.FRIENDLY, ((Greeting) response.getEntity().getEntity()).getTone());
Assert.assertEquals(false, response.getEntity().getEntity().hasMessage());
Assert.assertEquals(Tone.FRIENDLY, response.getEntity().getEntity().getTone());
}
@Test (dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
Oops, something went wrong.

0 comments on commit 6f57067

Please sign in to comment.