Skip to content
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

added constructor and wither for tables api request #539

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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(
Copy link
Contributor

@QubitPi QubitPi Sep 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we making this private?
Why do we want an all-args constructor?
It would be nice to explain in change log as well as in JavaDoc of this constructor

ResponseFormatType format,
Optional<PaginationParameters> paginationParameters,
UriInfo uriInfo,
Response.ResponseBuilder builder,
Set<LogicalTable> tables,
LogicalTable table,
Granularity granularity,
Set<Dimension> dimensions,
Set<LogicalMetric> metrics,
Set<Interval> intervals,
Map<Dimension, Set<ApiFilter>> 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.
*/
Expand Down Expand Up @@ -340,6 +381,56 @@ protected LinkedHashSet<LogicalMetric> 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> 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<LogicalTable> 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<LogicalTable> 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<Dimension> dimensions) {
return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters);
}

public TablesApiRequest withMetrics(Set<LogicalMetric> metrics) {
return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters);
}

public TablesApiRequest withIntervals(Set<Interval> intervals) {
return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters);
}

public TablesApiRequest withFilters(Map<Dimension, Set<ApiFilter>> filters) {
return new TablesApiRequest(format, paginationParameters, uriInfo, builder, tables, table, granularity, dimensions, metrics, intervals, filters);
}
//CHECKSTYLE:ON

public Set<LogicalTable> getTables() {
return this.tables;
}
Expand Down