-
Notifications
You must be signed in to change notification settings - Fork 749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic timestamp request #321
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
ask-sdk-servlet-support/src/com/amazon/ask/servlet/verifiers/GenericTimestampRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.amazon.ask.servlet.verifiers; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.Objects; | ||
|
||
@JsonDeserialize( | ||
builder = GenericTimestampRequest.Builder.class | ||
) | ||
public class GenericTimestampRequest { | ||
@JsonProperty("type") | ||
protected String type = null; | ||
@JsonProperty("requestId") | ||
protected String requestId = null; | ||
@JsonProperty("timestamp") | ||
protected OffsetDateTime timestamp = null; | ||
|
||
|
||
public static GenericTimestampRequest.Builder builder() { | ||
return new GenericTimestampRequest.Builder(); | ||
} | ||
|
||
private GenericTimestampRequest(GenericTimestampRequest.Builder builder) { | ||
if (builder.requestId != null) { | ||
this.requestId = builder.requestId; | ||
} | ||
|
||
if (builder.timestamp != null) { | ||
this.timestamp = builder.timestamp; | ||
} | ||
|
||
if (builder.type != null) { | ||
this.type = builder.type; | ||
} | ||
} | ||
|
||
@JsonIgnore | ||
public String getType() { | ||
return this.type; | ||
} | ||
|
||
@JsonProperty("requestId") | ||
public String getRequestId() { | ||
return this.requestId; | ||
} | ||
|
||
@JsonProperty("timestamp") | ||
public OffsetDateTime getTimestamp() { | ||
return this.timestamp; | ||
} | ||
|
||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} else if (o != null && this.getClass() == o.getClass()) { | ||
GenericTimestampRequest request = (GenericTimestampRequest) o; | ||
return Objects.equals(this.type, request.type) && Objects.equals(this.requestId, request.requestId) && Objects.equals(this.timestamp, request.timestamp); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public int hashCode() { | ||
return Objects.hash(this.type, this.requestId, this.timestamp); | ||
} | ||
|
||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("class Request {\n"); | ||
sb.append(" type: ").append(this.toIndentedString(this.type)).append("\n"); | ||
sb.append(" requestId: ").append(this.toIndentedString(this.requestId)).append("\n"); | ||
sb.append(" timestamp: ").append(this.toIndentedString(this.timestamp)).append("\n"); | ||
sb.append("}"); | ||
return sb.toString(); | ||
} | ||
|
||
private String toIndentedString(Object o) { | ||
return o == null ? "null" : o.toString().replace("\n", "\n "); | ||
} | ||
|
||
public static class Builder { | ||
private String type; | ||
private String requestId; | ||
private OffsetDateTime timestamp; | ||
|
||
private Builder() { | ||
} | ||
|
||
@JsonProperty("requestId") | ||
public GenericTimestampRequest.Builder withRequestId(String requestId) { | ||
this.requestId = requestId; | ||
return this; | ||
} | ||
|
||
@JsonProperty("timestamp") | ||
public GenericTimestampRequest.Builder withTimestamp(OffsetDateTime timestamp) { | ||
this.timestamp = timestamp; | ||
return this; | ||
} | ||
|
||
@JsonProperty("type") | ||
public GenericTimestampRequest.Builder withType(String type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
public GenericTimestampRequest build() { | ||
return new GenericTimestampRequest(this); | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...servlet-support/src/com/amazon/ask/servlet/verifiers/GenericTimestampRequestEnvelope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.amazon.ask.servlet.verifiers; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import java.util.Objects; | ||
|
||
@JsonDeserialize( | ||
builder = GenericTimestampRequestEnvelope.Builder.class | ||
) | ||
public final class GenericTimestampRequestEnvelope { | ||
@JsonProperty("request") | ||
private GenericTimestampRequest request; | ||
|
||
public static GenericTimestampRequestEnvelope.Builder builder() { | ||
return new GenericTimestampRequestEnvelope.Builder(); | ||
} | ||
|
||
private GenericTimestampRequestEnvelope(GenericTimestampRequestEnvelope.Builder builder) { | ||
this.request = null; | ||
|
||
if (builder.request != null) { | ||
this.request = builder.request; | ||
} | ||
|
||
} | ||
|
||
@JsonProperty("request") | ||
public GenericTimestampRequest getRequest() { | ||
return this.request; | ||
} | ||
|
||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} else if (o != null && this.getClass() == o.getClass()) { | ||
GenericTimestampRequestEnvelope requestEnvelope = (GenericTimestampRequestEnvelope)o; | ||
return Objects.equals(this.request, requestEnvelope.request); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
public int hashCode() { | ||
return Objects.hash(this.request); | ||
} | ||
|
||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("class RequestEnvelope {\n"); | ||
sb.append(" request: ").append(this.toIndentedString(this.request)).append("\n"); | ||
sb.append("}"); | ||
return sb.toString(); | ||
} | ||
|
||
private String toIndentedString(Object o) { | ||
return o == null ? "null" : o.toString().replace("\n", "\n "); | ||
} | ||
|
||
public static class Builder { | ||
private GenericTimestampRequest request; | ||
|
||
private Builder() { | ||
} | ||
|
||
@JsonProperty("request") | ||
public GenericTimestampRequestEnvelope.Builder withRequest(GenericTimestampRequest request) { | ||
this.request = request; | ||
return this; | ||
} | ||
|
||
public GenericTimestampRequestEnvelope build() { | ||
return new GenericTimestampRequestEnvelope(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this belongs in the model package. We'd have to create some sort of base class and have RequestEnvelope inherit and extend. The models are autogenerated so we would have to make the change I believe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem is that when you deal with requests that are not present in the model package. I think that request validation should not rely on the model package - you should have anemic request class that should deserialize to fields required only by validation logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to some degree, I think this function should only extract what it needs. But that should be defined as a generic object in the model. Otherwise, we have two packages where a request is defined. i.e however unlikely, if the timestamp field moves/renamed, this would be hard to catch in the future.
so not entirely against this just need to think about this a bit more. Currently I see more pros in having this in the model than cons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the biggest problem here is that I cannot edit your template files since they're private. Also having a base class can be tricky when relying on builders to create objects.
I know that there is a defaultImpl property in Jackson: https://fasterxml.github.io/jackson-annotations/javadoc/2.6/com/fasterxml/jackson/annotation/JsonTypeInfo.html#defaultImpl()
So a request could be mapped to
UnknownRequest
that would have locale, type, request-id, and timestamp.