66
77import java .io .*;
88import java .time .LocalDateTime ;
9+ import java .util .ArrayList ;
910import java .util .List ;
10- import java .util .Vector ;
1111
1212public class QueryRequest extends Thread {
1313
14- private final List <Coords > coordinates ;
15- private final String date ;
14+ private List <Coords > coordinates ;
15+ private String date ;
1616 private String mapName ;
17- private final String requestedByID ;
17+ private String requestedByID ;
1818
19- private final LocalDateTime startTime = LocalDateTime .now ();
19+ private LocalDateTime startTime = LocalDateTime .now ();
2020 private LocalDateTime runtimeStart ;
2121 private LocalDateTime endTime ;
2222
2323 private QueryRequestStatus status = QueryRequestStatus .REQUESTED ;
2424
2525 private String errorMessage = "" ;
2626
27- private final String TAG ;
27+ private String TAG ;
2828 private String LOG = "" ;
2929
30- private final String osmDir ;
31- private final String mapDir ;
32- private final String sLogDir ;
30+ private String osmDir ;
31+ private String mapDir ;
32+ private String sLogDir ;
3333
34- private final String renderingParameter ;
35- private final String ohdmConverter ;
34+ private String renderingParameter ;
35+ private String ohdmConverter ;
3636
37- private final String javaJdkPath ;
38- private final String jdbcDriverPath ;
37+ private String javaJdkPath ;
38+ private String jdbcDriverPath ;
3939
4040 private String individualLogFile ;
4141
@@ -62,6 +62,23 @@ public QueryRequest(List<Coords> coordinates, String date, String mapName, Strin
6262 TAG = mapName + "_" + getRequestedByID () + "-Thread" ;
6363 }
6464
65+ public QueryRequest () {
66+
67+ }
68+
69+ public QueryRequest QueryRequest (String sLogDir , String mapName ) {
70+ this .individualLogFile = sLogDir + "/" + mapName + ".req" ;
71+ try {
72+ if (readIndivLogFile ())
73+ return this ;
74+ else {
75+ return new QueryRequest (null , null , null , null , null , null , null , null , null , null , null );
76+ }
77+ } catch (IOException e ) {
78+ return new QueryRequest (null , null , null , null , null , null , null , null , null , null , null );
79+ }
80+ }
81+
6582 public Coords [] getCoordinates () {
6683 return coordinates .toArray (new Coords [coordinates .size () - 1 ]);
6784 }
@@ -366,25 +383,27 @@ private void refreshIndivLogFile() throws IOException {
366383
367384 // indiv write
368385 output += "name : " + mapName + "\n " ;
369- output += "coords : " + getPrintableCoordsString ( " | " ) ;
386+ output += "coords : " + new Gson (). toJson ( coordinates ) + " \n " ;
370387 output += "date : " + date + "\n " ;
371388 output += "id : " + requestedByID + "\n " ;
372- output += "status : " + status + "\n " ;
389+ output += "status : " + new Gson (). toJson ( status ) + "\n " ;
373390 output += "-----------------------------------------------------------------------------------------------\n " ;
374- output += "startTime : " + startTime . toString ( ) + "\n " ;
375- output += "runTimeStart : " + runtimeStart . toString ( ) + "\n " ;
376- if (endTime != null ) { output += "endTime : " + endTime . toString ( ) + "\n " ; }
391+ output += "startTime : " + new Gson (). toJson ( startTime ) + "\n " ;
392+ if ( endTime != null ) { output += "runTimeStart : " + new Gson (). toJson ( runtimeStart ) + "\n " ; }
393+ if (endTime != null ) { output += "endTime : " + new Gson (). toJson ( endTime ) + "\n " ; }
377394 output += "-----------------------------------------------------------------------------------------------\n " ;
378395 output += "tagInLog : " + TAG + "\n " ;
379396 output += "-----------------------------------------------------------------------------------------------\n " ;
397+ output += "osmDir : " + osmDir + "\n " ;
398+ output += "mapDir : " + mapDir + "\n " ;
380399 output += "osmFile : " + osmDir + "/" + mapName + ".osm" + "\n " ;
381400 output += "mapFile : " + mapDir + "/" + mapName + ".map" + "\n " ;
382401 output += "renderParamFile : " + renderingParameter + "\n " ;
383402 output += "OHDMConverterFile : " + ohdmConverter + "\n " ;
384403 output += "javaPath : " + javaJdkPath + "\n " ;
385404 output += "jdbcPath : " + jdbcDriverPath + "\n \n " ;
386405 output += "-----------------------------------------------------------------------------------------------\n " ;
387- output += "current log : \n " + LOG ;
406+ output += "current log: \n " + LOG ;
388407 // end indiv write
389408
390409 BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (new File (individualLogFile ))));
@@ -393,6 +412,95 @@ private void refreshIndivLogFile() throws IOException {
393412 bw .close ();
394413 }
395414
415+ private boolean readIndivLogFile () throws IOException {
416+ File read = new File (individualLogFile );
417+ if (!read .exists ())
418+ return false ;
419+
420+ String fileContent = "" ;
421+ BufferedReader br = new BufferedReader (new InputStreamReader (new FileInputStream (read )));
422+ while (br .ready ())
423+ fileContent += br .readLine () + "\n " ;
424+
425+ for (String s :fileContent .split ("\n " )) {
426+ try {
427+ String [] split = s .split (": " );
428+ switch (split [0 ].trim ()) {
429+ case "name" :
430+ mapName = split [1 ].trim ();
431+ break ;
432+
433+ case "coords" :
434+ // Reverse the convertion from List to Json String---
435+ ArrayList listRecovered = new Gson ().fromJson (split [1 ], ArrayList .class );
436+ ArrayList <Coords > realListRec = new ArrayList <>();
437+ for (int i = 0 ; i < listRecovered .size (); i ++) {
438+ realListRec .add (new Gson ().fromJson (listRecovered .get (i ).toString (), Coords .class ));
439+ }
440+ // -------------------------------------------------
441+ coordinates = realListRec ;
442+ break ;
443+
444+ case "date" :
445+ date = split [1 ].trim ();
446+ break ;
447+
448+ case "id" :
449+ requestedByID = split [1 ].trim ();
450+ break ;
451+
452+ case "status" :
453+ status = new Gson ().fromJson (split [1 ], QueryRequestStatus .class );
454+ break ;
455+
456+ case "startTime" :
457+ startTime = new Gson ().fromJson (split [1 ], LocalDateTime .class );
458+ break ;
459+
460+ case "runTimeStart" :
461+ runtimeStart = new Gson ().fromJson (split [1 ], LocalDateTime .class );
462+ break ;
463+
464+ case "endTime" :
465+ endTime = new Gson ().fromJson (split [1 ], LocalDateTime .class );
466+ break ;
467+
468+ case "tagInLog" :
469+ TAG = split [1 ].trim ();
470+ break ;
471+
472+ case "osmDir" :
473+ osmDir = split [1 ].trim ();
474+ break ;
475+
476+ case "mapDir" :
477+ mapDir = split [1 ].trim ();
478+ break ;
479+
480+ case "renderParamFile" :
481+ renderingParameter = split [1 ].trim ();
482+ break ;
483+
484+ case "OHDMConverterFile" :
485+ ohdmConverter = split [1 ].trim ();
486+ break ;
487+
488+ case "javaPath" :
489+ javaJdkPath = split [1 ].trim ();
490+ break ;
491+
492+ case "jdbcPath" :
493+ jdbcDriverPath = split [1 ].trim ();
494+ break ;
495+
496+ }
497+ } catch (Exception e ) {
498+ Logger .instance .addLogEntry (LogType .ERROR , "init QueryFile" , "failed to read a specific value ... \n " + e .getStackTrace ()[0 ]);
499+ }
500+ }
501+ return true ;
502+ }
503+
396504 @ Override
397505 public String toString () {
398506 return mapName + " " + status .toString () + " " + StaticVariables .formatDateTimeDif (startTime , LocalDateTime .now ());
0 commit comments