From e3de13bf7736c8d899d5446ab68974f8f7f1644f Mon Sep 17 00:00:00 2001 From: Asif Mansoor Amanullah Date: Fri, 22 Sep 2017 10:44:21 -0500 Subject: [PATCH] added constructor and wither for TablesApiRequest --- CHANGELOG.md | 4 + .../bard/webservice/web/TablesApiRequest.java | 91 +++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d6af53a8d..5ae8bf2c66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ Current ### Added: +- [Add Constructor and wither for TableApiRequest](https://github.com/yahoo/fili/pull/539) + * Making the TablesApiRequest similar to other ApiRequest classses so added an all argument constructor + and withers. The all argument constructor is made private since its used only by the withers. + - [Add Code Narc to validate Groovy style](https://github.com/yahoo/fili/pull/420) * Checkstyle is great, but it doesn't process Groovy. Code Narc is Checkstyle for Groovy, so we should totally use it. diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/web/TablesApiRequest.java b/fili-core/src/main/java/com/yahoo/bard/webservice/web/TablesApiRequest.java index d62d678ae2..a3d7730738 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/web/TablesApiRequest.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/web/TablesApiRequest.java @@ -19,6 +19,7 @@ import com.yahoo.bard.webservice.table.TableIdentifier; import com.yahoo.bard.webservice.web.apirequest.ApiRequestImpl; import com.yahoo.bard.webservice.web.util.BardConfigResources; +import com.yahoo.bard.webservice.web.util.PaginationParameters; import org.joda.time.Interval; import org.slf4j.Logger; @@ -30,12 +31,14 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.function.Function; import java.util.stream.Collectors; import javax.validation.constraints.NotNull; import javax.ws.rs.core.PathSegment; +import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; /** @@ -221,6 +224,44 @@ public TablesApiRequest( ); } + /** + * All argument constructor and its used primarily for withers - hence its private. + * + * @param format Response data format JSON or CSV. Default is JSON + * @param paginationParameters The parameters used to describe pagination + * @param uriInfo The URI of the request object + * @param builder The response builder for this request + * @param tables Set of logical tables + * @param table Logical table + * @param granularity Requested time granularity + * @param dimensions Grouping dimensions / Dimension constraint + * @param metrics Metrics constraint + * @param intervals Data / Time constraint + * @param filters Filter constraint + */ + private TablesApiRequest( + ResponseFormatType format, + Optional paginationParameters, + UriInfo uriInfo, + Response.ResponseBuilder builder, + Set tables, + LogicalTable table, + Granularity granularity, + Set dimensions, + Set metrics, + Set intervals, + Map> filters + ) { + super(format, SYNCHRONOUS_ASYNC_AFTER_VALUE, paginationParameters, uriInfo, builder); + this.tables = tables; + this.table = table; + this.granularity = granularity; + this.dimensions = dimensions; + this.metrics = metrics; + this.intervals = intervals; + this.filters = filters; + } + /** * No argument constructor, meant to be used only for testing. */ @@ -340,6 +381,56 @@ protected LinkedHashSet generateLogicalMetrics( } } + //CHECKSTYLE:OFF + public TablesApiRequest withFormat(ResponseFormatType format) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withPaginationParameters(Optional paginationParameters) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withUriInfo(UriInfo uriInfo) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withBuilder(Response.ResponseBuilder builder) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withTables(Set tables) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withTable(LogicalTable table) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withGranularity(Set tables) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withTables(Granularity granularity) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withDimensions(Set dimensions) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withMetrics(Set metrics) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withIntervals(Set intervals) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + + public TablesApiRequest withFilters(Map> filters) { + return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters); + } + //CHECKSTYLE:ON + public Set getTables() { return this.tables; }