1 |
package dk.daoas.daoadresseservice; |
package dk.daoas.daoadresseservice; |
2 |
|
|
3 |
import java.sql.SQLException; |
import java.sql.SQLException; |
4 |
|
import java.text.SimpleDateFormat; |
5 |
import java.util.ArrayList; |
import java.util.ArrayList; |
6 |
|
import java.util.Collections; |
7 |
|
import java.util.Date; |
8 |
import java.util.HashMap; |
import java.util.HashMap; |
9 |
import java.util.HashSet; |
import java.util.HashSet; |
10 |
import java.util.List; |
import java.util.List; |
13 |
import java.util.concurrent.ConcurrentHashMap; |
import java.util.concurrent.ConcurrentHashMap; |
14 |
|
|
15 |
import dk.daoas.daoadresseservice.AddressUtils.SplitResult; |
import dk.daoas.daoadresseservice.AddressUtils.SplitResult; |
16 |
|
import dk.daoas.daoadresseservice.admin.ServiceConfig; |
17 |
import dk.daoas.daoadresseservice.beans.Address; |
import dk.daoas.daoadresseservice.beans.Address; |
18 |
|
import dk.daoas.daoadresseservice.beans.DataStatisticsBean; |
19 |
import dk.daoas.daoadresseservice.beans.ExtendedBean; |
import dk.daoas.daoadresseservice.beans.ExtendedBean; |
20 |
import dk.daoas.daoadresseservice.beans.HundredePctBean; |
import dk.daoas.daoadresseservice.beans.HundredePctBean; |
21 |
import dk.daoas.daoadresseservice.beans.SearchResult; |
import dk.daoas.daoadresseservice.beans.SearchResult; |
31 |
|
|
32 |
private Map<String,Long> helperCache; |
private Map<String,Long> helperCache; |
33 |
|
|
34 |
|
private DataStatisticsBean stats = new DataStatisticsBean(); |
35 |
|
|
36 |
|
|
37 |
public SearchResult search(String postnrStr, String adresse) { |
public SearchResult search(ServiceConfig config, String postnrStr, String adresse) { |
38 |
|
|
39 |
int postnr=0; |
int postnr=0; |
40 |
boolean google = false; |
boolean google = false; |
71 |
|
|
72 |
|
|
73 |
if ( gadeident == null) { |
if ( gadeident == null) { |
74 |
String googleVej = GeocodeHelper.googleHelper(postnr, split.vej ); |
if (config.useGoogle) { |
75 |
google = true; |
String googleVej = GeocodeHelper.googleHelper(config, postnr, split.vej ); |
76 |
|
google = true; |
|
if (googleVej != null) { |
|
|
String googleVasket = AddressUtils.vaskVejnavn( googleVej ); |
|
|
gadeident = postnrVeje.get(googleVasket); |
|
77 |
|
|
78 |
if (gadeident != null) { |
if (googleVej != null) { |
79 |
helperCache.put(helperSearchKey, gadeident); |
String googleVasket = AddressUtils.vaskVejnavn( googleVej ); |
80 |
|
gadeident = postnrVeje.get(googleVasket); |
81 |
|
|
82 |
|
if (gadeident != null) { |
83 |
|
helperCache.put(helperSearchKey, gadeident); |
84 |
|
} |
85 |
} |
} |
86 |
} |
} |
87 |
} |
} |
88 |
|
|
89 |
if ( gadeident == null) { |
if ( gadeident == null) { |
90 |
String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej ); |
if (config.useOpenStreetMaps) { |
91 |
osm = true; |
String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej ); |
92 |
|
osm = true; |
|
if (osmVej != null) { |
|
|
String osmVasket = AddressUtils.vaskVejnavn( osmVej ); |
|
|
gadeident = postnrVeje.get(osmVasket); |
|
93 |
|
|
94 |
if (gadeident != null) { |
if (osmVej != null) { |
95 |
helperCache.put(helperSearchKey, gadeident); |
String osmVasket = AddressUtils.vaskVejnavn( osmVej ); |
96 |
|
gadeident = postnrVeje.get(osmVasket); |
97 |
|
|
98 |
|
if (gadeident != null) { |
99 |
|
helperCache.put(helperSearchKey, gadeident); |
100 |
|
} |
101 |
} |
} |
102 |
} |
} |
103 |
} |
} |
269 |
long stop = System.currentTimeMillis(); |
long stop = System.currentTimeMillis(); |
270 |
System.out.println("Build, stage3 elapsed: " + (stop-start3) ); |
System.out.println("Build, stage3 elapsed: " + (stop-start3) ); |
271 |
System.out.println("Build -- Gathering statistics"); |
System.out.println("Build -- Gathering statistics"); |
272 |
|
|
|
int direkteCount = 0; |
|
|
int extendedCount = 0; |
|
|
int hundredePctCount = 0; |
|
|
int ikkeDaekketCount = 0; |
|
|
|
|
273 |
for (Address addr : alleAdresser) { |
for (Address addr : alleAdresser) { |
274 |
switch (addr.daekningsType) { |
switch (addr.daekningsType) { |
275 |
case DAEKNING_DIREKTE: |
case DAEKNING_DIREKTE: |
276 |
direkteCount++; |
stats.direkteCount++; |
277 |
break; |
break; |
278 |
case DAEKNING_UDVIDET: |
case DAEKNING_UDVIDET: |
279 |
extendedCount++; |
stats.extendedCount++; |
280 |
break; |
break; |
281 |
case DAEKNING_100PCT: |
case DAEKNING_100PCT: |
282 |
hundredePctCount++; |
stats.hundredePctCount++; |
283 |
break; |
break; |
284 |
default: |
default: |
285 |
ikkeDaekketCount++; |
stats.ikkeDaekketCount++; |
286 |
} |
} |
287 |
} |
} |
288 |
|
|
289 |
System.out.println("Build: direkteCount: " + direkteCount); |
|
290 |
System.out.println("Build: extendedCount: " + extendedCount); |
stats.elapsed = stop-start1; |
291 |
System.out.println("Build: hundredePctCount: " + hundredePctCount); |
stats.buildTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format( new Date() ); |
292 |
System.out.println("Build: ikkeDaekketCount: " + ikkeDaekketCount); |
|
293 |
|
System.out.println("Build: direkteCount: " + stats.direkteCount); |
294 |
|
System.out.println("Build: extendedCount: " + stats.extendedCount); |
295 |
|
System.out.println("Build: hundredePctCount: " + stats.hundredePctCount); |
296 |
|
System.out.println("Build: ikkeDaekketCount: " + stats.ikkeDaekketCount); |
297 |
|
|
298 |
System.out.println("Build: Total Elapsed: " + (stop-start1) ); |
System.out.println("Build: Total Elapsed: " + (stop-start1) ); |
299 |
System.out.println("Build Completed"); |
System.out.println("Build Completed"); |
300 |
|
|
301 |
} |
} |
302 |
|
|
303 |
|
public DataStatisticsBean getStatistics() { |
304 |
|
return stats; |
305 |
|
} |
306 |
|
|
307 |
|
public void clear() { |
308 |
|
searchPostnrVejnavnGadeid.clear(); |
309 |
|
searchGadeidentAdresser.clear(); |
310 |
|
alleAdresser.clear(); |
311 |
|
helperCache.clear(); |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
private String calculateExtendedDaoRoute(ExtendedBean eb, Address orgAddress, Address targetAddress) { |
private String calculateExtendedDaoRoute(ExtendedBean eb, Address orgAddress, Address targetAddress) { |
316 |
|
|
360 |
result.add(a); |
result.add(a); |
361 |
} |
} |
362 |
} |
} |
363 |
|
Collections.sort(result ); |
364 |
return result; |
return result; |
365 |
} |
} |
366 |
|
|