From be1f1af4da3ac415f61f9e6b02572c6c248337fc Mon Sep 17 00:00:00 2001 From: brett-matson Date: Tue, 19 Jan 2021 19:07:04 +1100 Subject: [PATCH 1/2] throw exceptions when they occur --- .../dumpfiles/DumpProcessingController.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/DumpProcessingController.java b/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/DumpProcessingController.java index 00eac59a9..467475b7d 100644 --- a/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/DumpProcessingController.java +++ b/wdtk-dumpfiles/src/main/java/org/wikidata/wdtk/dumpfiles/DumpProcessingController.java @@ -374,7 +374,8 @@ public Sites getSitesInformation() throws IOException { * @see DumpProcessingController#processDump(MwDumpFile) * @see DumpProcessingController#getMostRecentDump(DumpContentType) */ - public void processAllRecentRevisionDumps() { + public void processAllRecentRevisionDumps() + throws IOException, FileAlreadyExistsException { WmfDumpFileManager wmfDumpFileManager = getWmfDumpFileManager(); if (wmfDumpFileManager == null) { return; @@ -403,7 +404,8 @@ public void processAllRecentRevisionDumps() { * in WDTK 0.5 */ @Deprecated - public void processMostRecentDailyDump() { + public void processMostRecentDailyDump() + throws IOException, FileAlreadyExistsException { processDump(getMostRecentDump(DumpContentType.JSON)); } @@ -417,7 +419,8 @@ public void processMostRecentDailyDump() { * * @see DumpProcessingController#processAllRecentRevisionDumps() */ - public void processMostRecentMainDump() { + public void processMostRecentMainDump() + throws IOException, FileAlreadyExistsException { DumpContentType dumpContentType; if (this.preferCurrent) { dumpContentType = DumpContentType.CURRENT; @@ -438,7 +441,8 @@ public void processMostRecentMainDump() { * * @see DumpProcessingController#processAllRecentRevisionDumps() */ - public void processMostRecentJsonDump() { + public void processMostRecentJsonDump() + throws IOException, FileAlreadyExistsException { processDump(getMostRecentDump(DumpContentType.JSON)); } @@ -453,7 +457,8 @@ public void processMostRecentJsonDump() { * @param dumpFile * the dump to process */ - public void processDump(MwDumpFile dumpFile) { + public void processDump(MwDumpFile dumpFile) + throws IOException, FileAlreadyExistsException { if (dumpFile == null) { return; } @@ -495,7 +500,8 @@ public void processDump(MwDumpFile dumpFile) { */ @Deprecated public void processMostRecentDump(DumpContentType dumpContentType, - MwDumpFileProcessor dumpFileProcessor) { + MwDumpFileProcessor dumpFileProcessor) + throws IOException, FileAlreadyExistsException { MwDumpFile dumpFile = getMostRecentDump(dumpContentType); if (dumpFile != null) { processDumpFile(dumpFile, dumpFileProcessor); @@ -536,18 +542,23 @@ public MwDumpFile getMostRecentDump(DumpContentType dumpContentType) { * the dump file processor to use */ void processDumpFile(MwDumpFile dumpFile, - MwDumpFileProcessor dumpFileProcessor) { + MwDumpFileProcessor dumpFileProcessor) + throws IOException, FileAlreadyExistsException { try (InputStream inputStream = dumpFile.getDumpFileStream()) { dumpFileProcessor.processDumpFileContents(inputStream, dumpFile); } catch (FileAlreadyExistsException e) { - logger.error("Dump file " + String errorMessage = "Dump file " + dumpFile.toString() + " could not be processed since file " + e.getFile() - + " already exists. Try deleting the file or dumpfile directory to attempt a new download."); + + " already exists. Try deleting the file or dumpfile directory to attempt a new download."; + logger.error(errorMessage); + throw new FileAlreadyExistsException(errorMessage); } catch (IOException e) { - logger.error("Dump file " + dumpFile.toString() - + " could not be processed: " + e.toString()); + String errorMessage = "Dump file " + dumpFile.toString() + + " could not be processed: " + e.toString(); + logger.error(errorMessage); + throw new IOException(errorMessage); } } From 1a1299a261a303f8fa9ca4cc05488e6fcf2f224b Mon Sep 17 00:00:00 2001 From: brett-matson Date: Tue, 19 Jan 2021 19:23:25 +1100 Subject: [PATCH 2/2] declare that example main methods throw IOException --- .../wikidata/wdtk/examples/ClassPropertyUsageAnalyzer.java | 2 +- .../org/wikidata/wdtk/examples/EntityStatisticsProcessor.java | 2 +- .../main/java/org/wikidata/wdtk/examples/ExampleHelpers.java | 2 +- .../java/org/wikidata/wdtk/examples/GenderRatioProcessor.java | 2 +- .../org/wikidata/wdtk/examples/LifeExpectancyProcessor.java | 2 +- .../java/org/wikidata/wdtk/examples/LocalDumpFileExample.java | 2 +- .../main/java/org/wikidata/wdtk/examples/TutorialExample.java | 4 +++- .../java/org/wikidata/wdtk/examples/WorldMapProcessor.java | 2 +- 8 files changed, 10 insertions(+), 8 deletions(-) diff --git a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ClassPropertyUsageAnalyzer.java b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ClassPropertyUsageAnalyzer.java index 5447c69da..f67ead579 100644 --- a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ClassPropertyUsageAnalyzer.java +++ b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ClassPropertyUsageAnalyzer.java @@ -259,7 +259,7 @@ public int compare( * which dump file to use and whether to run in offline mode, modify the * settings in {@link ExampleHelpers}. */ - public static void main(String[] args) { + public static void main(String[] args) throws IOException { ExampleHelpers.configureLogging(); ClassPropertyUsageAnalyzer.printDocumentation(); diff --git a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java index 0856c8aaa..0f17f4ce4 100644 --- a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java +++ b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/EntityStatisticsProcessor.java @@ -96,7 +96,7 @@ static class UsageStatistics { * * @param args */ - public static void main(String[] args) { + public static void main(String[] args) throws IOException { ExampleHelpers.configureLogging(); EntityStatisticsProcessor.printDocumentation(); diff --git a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ExampleHelpers.java b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ExampleHelpers.java index b8c9f030a..b9df207e0 100644 --- a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ExampleHelpers.java +++ b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/ExampleHelpers.java @@ -117,7 +117,7 @@ public static void configureLogging() { * the object to use for processing entities in this dump */ public static void processEntitiesFromWikidataDump( - EntityDocumentProcessor entityDocumentProcessor) { + EntityDocumentProcessor entityDocumentProcessor) throws IOException { // Controller object for processing dumps: DumpProcessingController dumpProcessingController = new DumpProcessingController( diff --git a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java index 7af84231e..f66e3e02b 100644 --- a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java +++ b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/GenderRatioProcessor.java @@ -124,7 +124,7 @@ public int compare(SiteRecord o1, SiteRecord o2) { * results to a file. To change which dump file to use and whether to run in * offline mode, modify the settings in {@link ExampleHelpers}. */ - public static void main(String[] args) { + public static void main(String[] args) throws IOException { ExampleHelpers.configureLogging(); GenderRatioProcessor.printDocumentation(); diff --git a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/LifeExpectancyProcessor.java b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/LifeExpectancyProcessor.java index c8f9f89a2..0cdd12dfe 100644 --- a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/LifeExpectancyProcessor.java +++ b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/LifeExpectancyProcessor.java @@ -55,7 +55,7 @@ public class LifeExpectancyProcessor implements EntityDocumentProcessor { * offline mode, modify the settings in {@link ExampleHelpers}. * */ - public static void main(String[] args) { + public static void main(String[] args) throws IOException { ExampleHelpers.configureLogging(); LifeExpectancyProcessor.printDocumentation(); diff --git a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/LocalDumpFileExample.java b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/LocalDumpFileExample.java index 94d73c351..13512bc89 100644 --- a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/LocalDumpFileExample.java +++ b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/LocalDumpFileExample.java @@ -41,7 +41,7 @@ public class LocalDumpFileExample { */ private final static String DUMP_FILE = "./src/resources/sample-dump-20150815.json.gz"; - public static void main(String[] args) { + public static void main(String[] args) throws IOException { ExampleHelpers.configureLogging(); LocalDumpFileExample.printDocumentation(); diff --git a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/TutorialExample.java b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/TutorialExample.java index 381681378..957281dfb 100644 --- a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/TutorialExample.java +++ b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/TutorialExample.java @@ -20,6 +20,8 @@ * #L% */ +import java.io.IOException; + import org.wikidata.wdtk.datamodel.interfaces.EntityDocumentProcessor; import org.wikidata.wdtk.dumpfiles.DumpProcessingController; import org.wikidata.wdtk.dumpfiles.MwRevision; @@ -41,7 +43,7 @@ */ public class TutorialExample { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { ExampleHelpers.configureLogging(); // Controller object for processing dumps: diff --git a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java index 77ddac50d..0982bbcfd 100644 --- a/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java +++ b/wdtk-examples/src/main/java/org/wikidata/wdtk/examples/WorldMapProcessor.java @@ -103,7 +103,7 @@ public class WorldMapProcessor implements EntityDocumentProcessor { * * @param args */ - public static void main(String[] args) { + public static void main(String[] args) throws IOException { ExampleHelpers.configureLogging(); WorldMapProcessor.printDocumentation();