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

Fix for #292 Date range queries #293

Merged
merged 1 commit into from
Nov 9, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,34 @@ public String toString() {
}
return toPrefixQueryString(wbRequest.getRequestUrl());
}

public String toPrefixQueryString(String url) {
return toQueryString(url) + STAR;
}

public String toQueryString(String url) {
String datespec = STAR;
if((wbRequest.getStartTimestamp() != null) &&
(wbRequest.getEndTimestamp() != null)) {
datespec = String.format("%s-%s%s",
wbRequest.getStartTimestamp(),wbRequest.getEndTimestamp(),
STAR);
}
return toString(datespec,url);

String exactDateTimestamp = getEmptyStringIfNull(wbRequest.get(WaybackRequest.REQUEST_EXACT_DATE));
Copy link
Member

Choose a reason for hiding this comment

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

60-68 should be indented

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is, but as a lot of other places in the code, it is a mixture of tabs and spaces.

String startTimestamp = getEmptyStringIfNull(wbRequest.getStartTimestamp());
String endTimestamp = getEmptyStringIfNull(wbRequest.getEndTimestamp());

if (!exactDateTimestamp.isEmpty()) {
datespec = exactDateTimestamp + STAR;
} else if (!startTimestamp.isEmpty() || !endTimestamp.isEmpty()) {
datespec = String.format("%s-%s%s", startTimestamp, endTimestamp, STAR);
}

return toString(datespec, url);
}

private String getEmptyStringIfNull(String string) {
if (string == null) {
return "";
} else {
return string;
}
}

public String toReplayString(String url) {
return toString(wbRequest.getReplayTimestamp(),url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ public WaybackRequest parse(HttpServletRequest httpRequest,
AccessPoint accessPoint) throws BetterRequestException {
WaybackRequest wbRequest = super.parse(httpRequest, accessPoint);
if (wbRequest != null) {
String replayTimestamp = wbRequest.getReplayTimestamp();
if ((replayTimestamp == null) || replayTimestamp.length() == 0) {
// lets call it a star query:
// TODO: should we clone?
wbRequest.setStartTimestamp(null);
wbRequest.setEndTimestamp(null);
}
String requestPath =
accessPoint.translateRequestPathQuery(httpRequest);
ArchivalUrl aUrl = new ArchivalUrl(wbRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PathDateRangeQueryRequestParser(BaseRequestParser wrapped) {
super(wrapped);
}

private final static Pattern TIMESTAMP_REGEX = Pattern.compile("(\\d{1,14})-(\\d{1,14})\\*");
private final static Pattern TIMESTAMP_REGEX = Pattern.compile("(\\d{0,14})-(\\d{0,14})\\*");

@Override
protected WaybackRequest parseDateUrl(String dateStr, String urlStr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PathPrefixDateRangeQueryRequestParser(BaseRequestParser wrapped) {
super(wrapped);
}

private final static Pattern TIMESTAMP_REGEX = Pattern.compile("(\\d{1,14})-(\\d{1,14})\\*");
private final static Pattern TIMESTAMP_REGEX = Pattern.compile("(\\d{0,14})-(\\d{0,14})\\*");

@Override
protected WaybackRequest parseDateUrl(String dateStr, String urlStr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ public void testToString_CaptureQuery_SpecificDateRange() {

assertEquals("20100101000000-20101231235959*/http://www.yahoo.com/", au.toString());

// same as "*" if either startTimestamp or endTimestamp is null
// Open ended date ranges
wbr.setEndTimestamp(null);
assertEquals("*/http://www.yahoo.com/", au.toString());
assertEquals("20100101000000-*/http://www.yahoo.com/", au.toString());

wbr.setStartTimestamp(null);
wbr.setEndTimestamp("20101231235959");
assertEquals("-20101231235959*/http://www.yahoo.com/", au.toString());

// Query for exact date
wbr.put(WaybackRequest.REQUEST_EXACT_DATE, "20100101000000");
assertEquals("20100101000000*/http://www.yahoo.com/", au.toString());
}

private WaybackRequest createReplayWaybackRequest() {
Expand Down