diff --git a/brouter-server/src/main/java/btools/server/RouteServer.java b/brouter-server/src/main/java/btools/server/RouteServer.java index bba52b3..1754129 100644 --- a/brouter-server/src/main/java/btools/server/RouteServer.java +++ b/brouter-server/src/main/java/btools/server/RouteServer.java @@ -173,7 +173,7 @@ public class RouteServer extends Thread } else if ( url.startsWith( "/brouter/suspects" ) ) { - writeHttpHeader(bw, "text/html"); + writeHttpHeader(bw, url.endsWith( ".json" ) ? "application/json" : "text/html"); SuspectManager.process( url, bw ); return; } diff --git a/brouter-server/src/main/java/btools/server/SuspectManager.java b/brouter-server/src/main/java/btools/server/SuspectManager.java index 418a89a..48d3ce8 100644 --- a/brouter-server/src/main/java/btools/server/SuspectManager.java +++ b/brouter-server/src/main/java/btools/server/SuspectManager.java @@ -56,11 +56,79 @@ public class SuspectManager extends Thread } } + public static void newAndConfirmedJson( BufferedWriter bw ) throws IOException + { + SuspectList suspects = getAllSuspects( new File( "worldsuspects.txt" ) ); + + bw.write( "{\n" ); + bw.write( "\"type\": \"FeatureCollection\",\n" ); + bw.write( "\"features\": [" ); + + int n = 0; + + for( int isuspect = 0; isuspect 0 ) + { + bw.write( "," ); + } + + int ilon = (int) ( id >> 32 ); + int ilat = (int) ( id & 0xffffffff ); + double dlon = ( ilon - 180000000 ) / 1000000.; + double dlat = ( ilat - 90000000 ) / 1000000.; + + int prio = suspects.prios[isuspect]; + int nprio = ( ( prio + 1 ) / 2 ) * 2; // normalize (no link prios) + String level = getLevelDecsription( nprio ); + + bw.write( "\n{\n" ); + bw.write( " \"id\": " + n + ",\n" ); + bw.write( " \"type\": \"Feature\",\n" ); + bw.write( " \"properties\": {\n" ); + bw.write( " \"issue_id\": " + id + ",\n" ); + bw.write( " \"Status\": \"" + status + "\",\n" ); + bw.write( " \"Level\": \"" + level + "\"\n" ); + bw.write( " },\n" ); + bw.write( " \"geometry\": {\n" ); + bw.write( " \"type\": \"Point\",\n" ); + bw.write( " \"coordinates\": [\n" ); + bw.write( " " + dlon + ",\n" ); + bw.write( " " + dlat + "\n" ); + bw.write( " ]\n" ); + bw.write( " }\n" ); + bw.write( "}" ); + + n++; + } + + bw.write( "\n ]\n" ); + bw.write( "}\n" ); + bw.flush(); + } + public static void process( String url, BufferedWriter bw ) throws IOException { - bw.write( "\n" ); - bw.write( "BRouter suspect manager. Help

\n" ); - StringTokenizer tk = new StringTokenizer( url, "/" ); tk.nextToken(); tk.nextToken(); @@ -71,7 +139,7 @@ public class SuspectManager extends Thread while ( tk.hasMoreTokens() ) { String c = tk.nextToken(); - if ( "all".equals( c ) || "new".equals( c ) || "confirmed".equals( c ) ) + if ( "all".equals( c ) || "new".equals( c ) || "confirmed".equals( c ) || "newandconfirmed.json".equals( c ) ) { filter = c; break; @@ -79,6 +147,15 @@ public class SuspectManager extends Thread country += "/" + c; } + if ( "newandconfirmed.json".equals( filter ) ) + { + newAndConfirmedJson( bw ); + return; + } + + bw.write( "\n" ); + bw.write( "BRouter suspect manager. Help

\n" ); + if ( filter == null ) // generate country list { bw.write( "\n" ); @@ -113,16 +190,19 @@ public class SuspectManager extends Thread return; } - File polyFile = new File( "worldpolys" + country + ".poly" ); - if ( !polyFile.exists() ) - { - bw.write( "polygon file for country '" + country + "' not found\n" ); - bw.write( "\n" ); - bw.flush(); - return; + Area polygon = null; + if ( !"/world".equals( country ) ) + { + File polyFile = new File( "worldpolys" + country + ".poly" ); + if ( !polyFile.exists() ) + { + bw.write( "polygon file for country '" + country + "' not found\n" ); + bw.write( "\n" ); + bw.flush(); + return; + } + polygon = new Area( polyFile ); } - - Area polygon = new Area( polyFile ); File suspectFile = new File( "worldsuspects.txt" ); if ( !suspectFile.exists() ) @@ -159,7 +239,7 @@ public class SuspectManager extends Thread { id = suspects.ids[isuspect]; - if ( !polygon.isInBoundingBox( id ) ) + if ( polygon != null && !polygon.isInBoundingBox( id ) ) { continue; // not in selected polygon (pre-check) } @@ -186,7 +266,7 @@ public class SuspectManager extends Thread continue; // that would be under current suspects } } - if ( !polygon.isInArea( id ) ) + if ( polygon != null && !polygon.isInArea( id ) ) { continue; // not in selected polygon } @@ -220,6 +300,7 @@ public class SuspectManager extends Thread else { new File( "falsepositives/" + id ).createNewFile(); + message = "Marked issue " + id + " as false-positive"; id = 0L; } } @@ -242,22 +323,19 @@ public class SuspectManager extends Thread { fixedMarker.createNewFile(); } - id = 0L; int hideDays = 0; if ( tk.hasMoreTokens() ) { String param = tk.nextToken(); hideDays = Integer.parseInt( param ); // hiding, not fixing + message = "Hide issue " + id + " for " + hideDays + " days"; } - else // touch the confirmed entry when marking fixed + else { - File confirmedEntry = new File( "confirmednegatives/" + id ); - if ( confirmedEntry.exists() ) - { - confirmedEntry.setLastModified( System.currentTimeMillis() ); - } + message = "Marked issue " + id + " as fixed"; } + id = 0L; fixedMarker.setLastModified( System.currentTimeMillis() + hideDays*86400000L ); } } @@ -340,9 +418,16 @@ public class SuspectManager extends Thread { bw.write( "mark as a confirmed issue

\n" ); } - bw.write( "

back to issue list

\n" ); + if ( polygon != null ) + { + bw.write( "

back to issue list

\n" ); + } } } + else if ( polygon == null ) + { + bw.write( message + "
\n" ); + } else { bw.write( filter + " suspect list for " + country + "\n" ); @@ -363,7 +448,7 @@ public class SuspectManager extends Thread } break; } - if ( !polygon.isInBoundingBox( id ) ) + if ( polygon != null && !polygon.isInBoundingBox( id ) ) { continue; // not in selected polygon (pre-check) } @@ -383,7 +468,7 @@ public class SuspectManager extends Thread { continue; // showing confirmed suspects only } - if ( !polygon.isInArea( id ) ) + if ( polygon != null && !polygon.isInArea( id ) ) { continue; // not in selected polygon } @@ -426,6 +511,7 @@ public class SuspectManager extends Thread int cnt; long[] ids; int[] prios; + boolean[] newOrConfirmed; long timestamp; SuspectList( int count, long time ) @@ -433,6 +519,7 @@ public class SuspectManager extends Thread cnt = count; ids = new long[cnt]; prios = new int[cnt]; + newOrConfirmed = new boolean[cnt]; timestamp = time; } } @@ -472,6 +559,9 @@ public class SuspectManager extends Thread prioCount[i] = pointer; pointer += cnt; } + + + // sort into suspect list allSuspects = new SuspectList( pointer, suspectFile.lastModified() ); @@ -487,6 +577,7 @@ public class SuspectManager extends Thread pointer = prioCount[nprio]++; allSuspects.ids[pointer] = id; allSuspects.prios[pointer] = prio; + allSuspects.newOrConfirmed[pointer] = new File( "confirmednegatives/" + id ).exists() || !(new File( "suspectarchive/" + id ).exists() ); } r.close(); return allSuspects;