public abstract class ApiRequestImpl extends Object implements ApiRequest
| Modifier and Type | Field and Description |
|---|---|
protected long |
asyncAfter |
protected javax.ws.rs.core.Response.ResponseBuilder |
builder |
protected static String |
COMMA_AFTER_BRACKET_PATTERN |
protected ResponseFormatType |
format |
protected Pagination<?> |
pagination |
protected Optional<PaginationParameters> |
paginationParameters |
protected javax.ws.rs.core.UriInfo |
uriInfo |
ASYNCHRONOUS_ASYNC_AFTER_VALUE, SYNCHRONOUS_ASYNC_AFTER_VALUE| Modifier | Constructor and Description |
|---|---|
protected |
ApiRequestImpl(ResponseFormatType format,
long asyncAfter,
Optional<PaginationParameters> paginationParameters,
javax.ws.rs.core.UriInfo uriInfo,
javax.ws.rs.core.Response.ResponseBuilder builder)
All argument constructor, meant to be used for rewriting apiRequest.
|
|
ApiRequestImpl(String format,
String asyncAfter,
String perPage,
String page,
javax.ws.rs.core.UriInfo uriInfo)
Parses the API request URL and generates the API request object.
|
|
ApiRequestImpl(String format,
String perPage,
String page,
javax.ws.rs.core.UriInfo uriInfo)
Parses the API request URL and generates the API request object.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addPageLink(PaginationLink link,
int pageNumber)
Add page links to the header of the response builder.
|
protected void |
addPageLink(PaginationLink link,
Pagination<?> pages)
Add page links to the header of the response builder.
|
protected ResponseFormatType |
generateAcceptFormat(String format)
Generates the format in which the response data is expected.
|
protected long |
generateAsyncAfter(String asyncAfterString)
Parses the asyncAfter parameter into a long describing how long the user is willing to wait for the results of a
synchronous request before the request should become asynchronous.
|
protected LinkedHashSet<Dimension> |
generateDimensions(List<javax.ws.rs.core.PathSegment> apiDimensions,
DimensionDictionary dimensionDictionary)
Extracts the list of dimension names from the url dimension path segments and generates a set of dimension
objects based on it.
|
ApiFilters |
generateFilters(String filterQuery,
LogicalTable table,
DimensionDictionary dimensionDictionary)
Generates filter objects on the based on the filter query in the api request.
|
protected Granularity |
generateGranularity(String granularity,
org.joda.time.DateTimeZone dateTimeZone,
GranularityParser granularityParser)
Generate a Granularity instance based on a path element.
|
protected Granularity |
generateGranularity(String granularity,
GranularityParser granularityParser)
Generate a Granularity instance based on a path element.
|
protected static Set<org.joda.time.Interval> |
generateIntervals(org.joda.time.DateTime now,
String apiIntervalQuery,
Granularity granularity,
org.joda.time.format.DateTimeFormatter dateTimeFormatter)
Extracts the set of intervals from the api request.
|
protected static Set<org.joda.time.Interval> |
generateIntervals(String apiIntervalQuery,
Granularity granularity,
org.joda.time.format.DateTimeFormatter dateTimeFormatter)
Extracts the set of intervals from the api request.
|
protected LinkedHashSet<LogicalMetric> |
generateLogicalMetrics(String apiMetricQuery,
MetricDictionary metricDictionary)
Extracts the list of metrics from the url metric query string and generates a set of LogicalMetrics.
|
protected String |
generateMetricName(String filterString)
Given a single dimension filter string, generate a metric name extension.
|
protected Optional<PaginationParameters> |
generatePaginationParameters(String perPage,
String page)
Builds the paginationParameters object, if the request provides both a perPage and page field.
|
protected LogicalTable |
generateTable(String tableName,
Granularity granularity,
LogicalTableDictionary logicalTableDictionary)
Extracts a specific logical table object given a valid table name and a valid granularity.
|
protected org.joda.time.DateTimeZone |
generateTimeZone(String timeZoneId,
org.joda.time.DateTimeZone systemTimeZone)
Get the timezone for the request.
|
<T> Function<Collection<T>,AllPagesPagination<T>> |
getAllPagesPaginationFactory(PaginationParameters paginationParameters)
This method returns a Function that can basically take a Collection and return an instance of
AllPagesPagination.
|
static org.joda.time.DateTime |
getAsDateTime(org.joda.time.DateTime now,
Granularity granularity,
String dateText,
org.joda.time.format.DateTimeFormatter timeFormatter)
Get datetime from the given input text based on granularity.
|
long |
getAsyncAfter()
Returns how long the user is willing to wait before a request should go asynchronous.
|
javax.ws.rs.core.Response.ResponseBuilder |
getBuilder()
Get the response builder associated with this request.
|
PaginationParameters |
getDefaultPagination()
Get the default pagination parameters for this type of API request.
|
ResponseFormatType |
getFormat()
Get the type of the requested response format.
|
<T> Stream<T> |
getPage(Collection<T> data)
Deprecated.
Pagination is moving to a Stream and pushing creation of the page to a more general
method (
getPage(Pagination)) to allow for more flexibility
in how pagination is done. |
<T> Stream<T> |
getPage(Pagination<T> pagination)
Add links to the response builder and return a stream with the requested page from the raw data.
|
Pagination<?> |
getPagination()
Get the pagination object associated with this request.
|
Optional<PaginationParameters> |
getPaginationParameters()
Get the requested pagination parameters.
|
javax.ws.rs.core.UriInfo |
getUriInfo()
Get the uri info.
|
protected void |
validateMetrics(Set<LogicalMetric> logicalMetrics,
LogicalTable table)
Validate that all metrics are part of the logical table.
|
protected void |
validateRequestDimensions(Set<Dimension> requestDimensions,
LogicalTable table)
Ensure all request dimensions are part of the logical table.
|
protected static void |
validateTimeAlignment(Granularity granularity,
Set<org.joda.time.Interval> intervals)
Throw an exception if any of the intervals are not accepted by this granularity.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgenerateDateTimeFormatterprotected static final String COMMA_AFTER_BRACKET_PATTERN
protected final ResponseFormatType format
protected final Optional<PaginationParameters> paginationParameters
protected final javax.ws.rs.core.UriInfo uriInfo
protected final javax.ws.rs.core.Response.ResponseBuilder builder
protected Pagination<?> pagination
protected final long asyncAfter
public ApiRequestImpl(String format, String asyncAfter, @NotNull String perPage, @NotNull String page, javax.ws.rs.core.UriInfo uriInfo) throws BadApiRequestException
format - response data format JSON or CSV. Default is JSON.asyncAfter - How long the user is willing to wait for a synchronous request in milliseconds, if null
defaults to the system config default_asyncAfterperPage - number of rows to display per page of results. If present in the original request, must be a
positive integer. If not present, must be the empty string.page - desired page of results. If present in the original request, must be a positive integer. If not
present, must be the empty string.uriInfo - The URI of the request object.BadApiRequestException - if pagination parameters in the API request are not positive integers.public ApiRequestImpl(String format, @NotNull String perPage, @NotNull String page, javax.ws.rs.core.UriInfo uriInfo) throws BadApiRequestException
format - response data format JSON or CSV. Default is JSON.perPage - number of rows to display per page of results. If present in the original request, must be a
positive integer. If not present, must be the empty string.page - desired page of results. If present in the original request, must be a positive integer. If not
present, must be the empty string.uriInfo - The URI of the request object.BadApiRequestException - if pagination parameters in the API request are not positive integers.protected ApiRequestImpl(ResponseFormatType format, long asyncAfter, Optional<PaginationParameters> paginationParameters, javax.ws.rs.core.UriInfo uriInfo, javax.ws.rs.core.Response.ResponseBuilder builder)
format - The format of the responseasyncAfter - How long the user is willing to wait for a synchronous request, in millisecondspaginationParameters - The parameters used to describe paginationuriInfo - The uri detailsbuilder - The response builder for this requestprotected Granularity generateGranularity(@NotNull String granularity, @NotNull org.joda.time.DateTimeZone dateTimeZone, @NotNull GranularityParser granularityParser) throws BadApiRequestException
granularity - A string representation of the granularitydateTimeZone - The time zone to use for this granularitygranularityParser - The parser for granularityBadApiRequestException - if the string matches no meaningful granularityprotected Granularity generateGranularity(String granularity, GranularityParser granularityParser) throws BadApiRequestException
granularity - A string representation of the granularitygranularityParser - The parser for granularityBadApiRequestException - if the string matches no meaningful granularityprotected LinkedHashSet<Dimension> generateDimensions(List<javax.ws.rs.core.PathSegment> apiDimensions, DimensionDictionary dimensionDictionary) throws BadApiRequestException
apiDimensions - Dimension path segments from the URL.dimensionDictionary - Dimension dictionary contains the map of valid dimension names and dimension objects.BadApiRequestException - if an invalid dimension is requested.protected void validateRequestDimensions(Set<Dimension> requestDimensions, LogicalTable table) throws BadApiRequestException
requestDimensions - The dimensions being requestedtable - The logical table being checkedBadApiRequestException - if any of the dimensions do not match the logical tableprotected String generateMetricName(String filterString)
filterString - Single dimension filter string.protected LinkedHashSet<LogicalMetric> generateLogicalMetrics(String apiMetricQuery, MetricDictionary metricDictionary)
If the query contains undefined metrics, BadApiRequestException will be
thrown.
apiMetricQuery - URL query string containing the metrics separated by ','metricDictionary - Metric dictionary contains the map of valid metric names and logical metric objectsprotected void validateMetrics(Set<LogicalMetric> logicalMetrics, LogicalTable table) throws BadApiRequestException
logicalMetrics - The set of metrics being validatedtable - The logical table for the requestBadApiRequestException - if the requested metrics are not in the logical tableprotected static Set<org.joda.time.Interval> generateIntervals(String apiIntervalQuery, Granularity granularity, org.joda.time.format.DateTimeFormatter dateTimeFormatter) throws BadApiRequestException
apiIntervalQuery - API string containing the intervals in ISO 8601 format, values separated by ','.granularity - The granularity to generate the date based on period or macros.dateTimeFormatter - The formatter to parse date time interval segmentsBadApiRequestException - if the requested interval is not found.protected static Set<org.joda.time.Interval> generateIntervals(org.joda.time.DateTime now, String apiIntervalQuery, Granularity granularity, org.joda.time.format.DateTimeFormatter dateTimeFormatter) throws BadApiRequestException
now - The 'now' for which time macros will be relatively calculatedapiIntervalQuery - API string containing the intervals in ISO 8601 format, values separated by ','.granularity - The granularity to generate the date based on period or macros.dateTimeFormatter - The formatter to parse date time interval segmentsBadApiRequestException - if the requested interval is not found.public ApiFilters generateFilters(String filterQuery, LogicalTable table, DimensionDictionary dimensionDictionary) throws BadApiRequestException
filterQuery - Expects a URL filter query String in the format:
(dimension name).(fieldname)-(operation):[?(value or comma separated values)]?table - The logical table for the data requestdimensionDictionary - DimensionDictionaryBadApiRequestException - if the filter query string does not match required syntax, or the filter
contains a 'startsWith' or 'contains' operation while the BardFeatureFlag.DATA_STARTS_WITH_CONTAINS_ENABLED is
off.public static org.joda.time.DateTime getAsDateTime(org.joda.time.DateTime now,
Granularity granularity,
String dateText,
org.joda.time.format.DateTimeFormatter timeFormatter)
throws BadApiRequestException
now - current datetime to compute the floored date based on granularitygranularity - granularity to truncate the given date to.dateText - start/end date text which could be actual date or macrostimeFormatter - a time zone adjusted date time formatterBadApiRequestException - if the granularity is "all" and a macro is usedprotected org.joda.time.DateTimeZone generateTimeZone(String timeZoneId, org.joda.time.DateTimeZone systemTimeZone)
timeZoneId - String of the TimeZone IDsystemTimeZone - TimeZone of the system to use if there is no timeZoneIdprotected static void validateTimeAlignment(Granularity granularity, Set<org.joda.time.Interval> intervals) throws BadApiRequestException
granularity - The granularity whose alignment is being tested.intervals - The intervals being tested.BadApiRequestException - if the granularity does not align to the intervalsprotected ResponseFormatType generateAcceptFormat(String format) throws BadApiRequestException
format - Expects a URL format query String.BadApiRequestException - if the requested format is not found.protected Optional<PaginationParameters> generatePaginationParameters(String perPage, String page) throws BadApiRequestException
perPage - The number of rows per page.page - The page to display.BadApiRequestException - if 'perPage' or 'page' is not a positive integer, or if either one is empty
string but not both.protected LogicalTable generateTable(String tableName, Granularity granularity, LogicalTableDictionary logicalTableDictionary) throws BadApiRequestException
tableName - logical table corresponding to the table name specified in the URLgranularity - logical table corresponding to the table name specified in the URLlogicalTableDictionary - Logical table dictionary contains the map of valid table names and table objects.BadApiRequestException - Invalid table exception if the table dictionary returns a null.public ResponseFormatType getFormat()
ApiRequestgetFormat in interface ApiRequestpublic Optional<PaginationParameters> getPaginationParameters()
ApiRequestgetPaginationParameters in interface ApiRequestpublic javax.ws.rs.core.UriInfo getUriInfo()
ApiRequestgetUriInfo in interface ApiRequestpublic Pagination<?> getPagination()
ApiRequestApiRequest.getPage(java.util.Collection<T>)getPagination in interface ApiRequestpublic long getAsyncAfter()
ApiRequestgetAsyncAfter in interface ApiRequestpublic javax.ws.rs.core.Response.ResponseBuilder getBuilder()
ApiRequestgetBuilder in interface ApiRequestpublic PaginationParameters getDefaultPagination()
ApiRequestgetDefaultPagination in interface ApiRequestprotected void addPageLink(PaginationLink link, Pagination<?> pages)
link - The type of the link to add.pages - The paginated set of results containing the pages being linked to.protected void addPageLink(PaginationLink link, int pageNumber)
link - The type of the link to add.pageNumber - Number of the page to add the link for.@Deprecated public <T> Stream<T> getPage(Collection<T> data)
getPage(Pagination)) to allow for more flexibility
in how pagination is done.getPage in interface ApiRequestT - The type of the collection elementsdata - The data to be paginated.public <T> Stream<T> getPage(Pagination<T> pagination)
getPage in interface ApiRequestT - The type of the collection elementspagination - The pagination objectpublic <T> Function<Collection<T>,AllPagesPagination<T>> getAllPagesPaginationFactory(PaginationParameters paginationParameters)
T - The type of items in the Collection which needs to be paginatedpaginationParameters - The PaginationParameters to be used to generate AllPagesPagination instanceprotected long generateAsyncAfter(String asyncAfterString) throws BadApiRequestException
asyncAfterString - asyncAfter should be either a string representation of a long, or the String neverBadApiRequestException - if asyncAfterString is neither the string representation of a natural number, nor
neverCopyright © 2016–2018 Yahoo! Inc.. All rights reserved.