Skip to content

Commit

Permalink
Merge pull request #293 from nlnwa/issue292_time-bounded-queries
Browse files Browse the repository at this point in the history
Fix for #292 Date range queries
  • Loading branch information
Kristinn Sigurðsson committed Nov 9, 2015
2 parents 18a5c1c + 0fee6a5 commit 54eba3d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
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));
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

0 comments on commit 54eba3d

Please sign in to comment.