File tree Expand file tree Collapse file tree 5 files changed +28
-34
lines changed
Expand file tree Collapse file tree 5 files changed +28
-34
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- import org .apache .commons .cli .CommandLine ;
2- import org .apache .commons .cli .HelpFormatter ;
3- import org .apache .commons .cli .MissingOptionException ;
4- import org .apache .commons .cli .ParseException ;
1+ import org .apache .commons .cli .*;
52
63import osm .util .OpenSenseMapHandler ;
74import util .Config ;
85
96import java .io .IOException ;
107
118public class Main {
12- public static void main (String [] args ) throws ParseException , IOException {
9+ public static void main (String [] args ) {
1310
1411 Config c = new Config ();
12+
1513 try {
1614 CommandLine config = c .parseArgs (args );
1715
1816 if (config .hasOption ("osm" )) {
1917 new OpenSenseMapHandler ().handleConfig (config );
2018 } else {
21- System .out .println ("No data source specified." );
22- System .out .println ("Please refer to the README." );
19+ System .out .println ("No data source specified.\n Please refer to the README." );
2320 }
24- } catch (MissingOptionException e ) {
25- c .printHelp ();
26- } catch (NullPointerException npe ){
21+ } catch (ParseException e ) {
2722 c .printHelp ();
23+ } catch (IOException e ) {
24+ e .printStackTrace ();
2825 }
2926 }
3027}
Original file line number Diff line number Diff line change 11package osm .util ;
22
33import org .apache .commons .cli .CommandLine ;
4- import org .apache .commons .cli .HelpFormatter ;
5- import org .apache .commons .cli .Option ;
6- import org .apache .commons .cli .Options ;
74import org .eclipse .rdf4j .model .Statement ;
85
96import osm .models .Location ;
1815public class OpenSenseMapHandler {
1916
2017 public void handleConfig (CommandLine config ) throws IOException {
21-
2218 SenseBox senseBox = OpenSenseMapApi .getSenseBox (config .getOptionValue ("osm" ));
2319
2420 List <Statement > statements = RdfConverter .convertSenseBoxToStatements (senseBox );
Original file line number Diff line number Diff line change @@ -18,19 +18,22 @@ public Config() {
1818 .desc ("Id of the SenseBox." )
1919 .build ());
2020
21- options .addOption (Option .builder ("measurements" )
21+ options .addOption (Option .builder ("m" )
22+ .longOpt ("measurements" )
2223 .required (false )
2324 .hasArg (false )
2425 .desc ("Set if measurements and locations should get collected." )
2526 .build ());
2627
27- options .addOption (Option .builder ("locations" )
28+ options .addOption (Option .builder ("l" )
29+ .longOpt ("locations" )
2830 .required (false )
2931 .hasArg (false )
3032 .desc ("Set if only locations should get collected." )
3133 .build ());
3234
33- options .addOption (Option .builder ("timerange" )
35+ options .addOption (Option .builder ("t" )
36+ .longOpt ("timerange" )
3437 .required (false )
3538 .hasArg (true )
3639 .numberOfArgs (2 )
@@ -39,7 +42,8 @@ public Config() {
3942 .desc ("Time range in witch data gets collected. (Example: 2019-05-01T00:00:00.000Z 2019-05-15T00:00:00.000Z)" )
4043 .build ());
4144
42- options .addOption (Option .builder ("path" )
45+ options .addOption (Option .builder ("p" )
46+ .longOpt ("path" )
4347 .required (true )
4448 .hasArg (true )
4549 .numberOfArgs (1 )
@@ -58,5 +62,4 @@ public void printHelp() {
5862 HelpFormatter hf = new HelpFormatter ();
5963 hf .printHelp ("OSM to RDF Parser " , options );
6064 }
61-
6265}
Original file line number Diff line number Diff line change 11package util ;
22
3+ import org .apache .commons .cli .MissingArgumentException ;
34import org .apache .commons .cli .UnrecognizedOptionException ;
45import org .junit .jupiter .api .Assertions ;
56import org .junit .jupiter .api .Test ;
@@ -23,9 +24,20 @@ public void testParseArgs() {
2324 public void testParseArgsWithUnknownParameter () {
2425 String [] args = new String []{
2526 "-osm" , "senseBoxId" ,
26- "-unknown" , "valueOfUnknown"
27+ "-unknown" , "valueOfUnknown" ,
28+ "-path" , "file.out"
2729 };
2830
2931 Assertions .assertThrows (UnrecognizedOptionException .class , () -> new Config ().parseArgs (args ));
3032 }
33+
34+ @ Test
35+ public void testParseArgsWithMissingArgument () {
36+ String [] args = new String []{
37+ "-osm" ,
38+ "-path" , "file.out"
39+ };
40+
41+ Assertions .assertThrows (MissingArgumentException .class , () -> new Config ().parseArgs (args ));
42+ }
3143}
You can’t perform that action at this time.
0 commit comments