This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class S3FilesResource { | |
AmazonS3Client amazonS3Client; | |
// ... | |
@Path("/files") | |
public String listS3Files() { | |
StringBuilder html = new StringBuilder("<html><body>"); | |
List<S3ObjectSummary> files = this.amazonS3Client.listObjects("myBucket").getObjectSummaries(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class S3FilesResourceTest { | |
@Test | |
public void listFilesButNotDirectoriesAsHtml() throws Exception { | |
S3FilesResource resource = new S3FilesResource(/* pass AWS credentials ... */); | |
String html = resource.listS3Files(); | |
assertThat(html) | |
.contains("<a href='/content?fileName=/dir/file1.txt'>/dir/file1.txt</a>") | |
.contains("<a href='/content?fileName=/dir/another.txt'>/dir/another.txt</a>") | |
.doesNotContain("/dir/</a>"); // directories should be excluded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface S3Facade { | |
List<S3File> listObjects(String bucketName); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class S3FilesResourceTest { | |
private static class FakeS3Facade implements S3Facade { | |
List<S3File> fileList; | |
public List<S3File> listObjects(String bucketName) { | |
return fileList; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
# The client code | |
@my.route('/cleanjson/<collection>/') | |
def getcleanjson(collection): | |
cleandata = Cleanjson() | |
cleandata.get_mongojson(str(collection), "?s={'_id': 1}") | |
cleandata.parse_json(cleandata.rawjson) | |
return cleandata.cleanjson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
# The client code | |
@my.route('/cleanjson/<collection>/') | |
def getcleanjson(collection): | |
return Cleanjson().get_mongojson(str(collection), "?s={'_id': 1}", format=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface LogEntry { | |
Date getTimestamp(); | |
/** For dumping into a .tsv file to be imported into Hadoop */ | |
String toTabDelimitedString(); | |
String getSearchTerms(); | |
boolean hasSearchTerms(); | |
String[][] getColumns(); | |
String getKey(); | |
void mergeWith(LogEntry entry); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface LogEntry { | |
// same as before | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compare two series and add the delta to the data for the current period | |
augmentSeriesWithPreviousValues:function (seriesData, previousSeriesData) { | |
var series = seriesData.series; | |
seriesData.previous = []; | |
var previousSeries = previousSeriesData.series; | |
... // checks, computing maxRows, maxColumns, previousCategories | |
// that maps category name to series index (id) | |
for (var seriesId = 0; seriesId < series.length; seriesId++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set seriesData.previous to hold data series of the previous period | |
// so that we may compute deltas (e.g. +10%). | |
// We also ensure that all the series, previous and current, have the same | |
// number of data points, adding fake ones if necessary, so that the delta-computation | |
// code <tbd:add reference> doesn't blow up. There may be some data missing | |
// at the end of a period, for example because months have different numbers of days. | |
// The fake elements and also any other undefined values will default to [0,0], which | |
// should be OK with all (line,area,..) graphs and tables. | |
// E.x.: seriesData.series[0].data = [ [1,"12%"],[2,"22%"],..,[31,"18%"] ], | |
// the previous month had only 30 days so we add a fake element for day 31; |
OlderNewer