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; |
import dk.daoas.daoadresseservice.beans.DataStatisticsBean; |
19 |
import dk.daoas.daoadresseservice.beans.ExtendedBean; |
import dk.daoas.daoadresseservice.beans.ExtendedBean; |
31 |
|
|
32 |
private Map<String,Long> helperCache; |
private Map<String,Long> helperCache; |
33 |
|
|
34 |
private DataStatisticsBean stats = new DataStatisticsBean(); |
private DataStatisticsBean stats = new DataStatisticsBean(); |
35 |
|
|
36 |
|
ServiceConfig config; |
37 |
|
|
38 |
|
public AdressSearch(ServiceConfig config) { |
39 |
|
this.config = config; |
40 |
|
} |
41 |
|
|
42 |
|
|
43 |
public SearchResult search(String postnrStr, String adresse) { |
public SearchResult search(String postnrStr, String adresse) { |
61 |
|
|
62 |
|
|
63 |
SplitResult split = AddressUtils.splitAdresse(adresse); |
SplitResult split = AddressUtils.splitAdresse(adresse); |
64 |
String vasketVejnavn = AddressUtils.vaskVejnavn( split.vej ); |
|
65 |
|
|
66 |
if (split.husnr.length() == 0) { |
if (split.husnr.length() == 0) { |
67 |
return new SearchResult(Status.ERROR_MISSING_HOUSENUMBER); |
return new SearchResult(Status.ERROR_MISSING_HOUSENUMBER); |
68 |
} |
} |
69 |
|
|
70 |
|
String vasketVejnavn = AddressUtils.vaskVejnavn( split.vej ); |
71 |
|
|
72 |
Long gadeident = postnrVeje.get(vasketVejnavn); |
Long gadeident = postnrVeje.get(vasketVejnavn); |
73 |
|
|
74 |
|
|
79 |
|
|
80 |
|
|
81 |
if ( gadeident == null) { |
if ( gadeident == null) { |
82 |
String googleVej = GeocodeHelper.googleHelper(postnr, split.vej ); |
if (config.useGoogle) { |
83 |
google = true; |
String googleVej = GeocodeHelper.googleHelper(config, postnr, split.vej ); |
84 |
|
google = true; |
|
if (googleVej != null) { |
|
|
String googleVasket = AddressUtils.vaskVejnavn( googleVej ); |
|
|
gadeident = postnrVeje.get(googleVasket); |
|
85 |
|
|
86 |
if (gadeident != null) { |
if (googleVej != null) { |
87 |
helperCache.put(helperSearchKey, gadeident); |
String googleVasket = AddressUtils.vaskVejnavn( googleVej ); |
88 |
|
gadeident = postnrVeje.get(googleVasket); |
89 |
|
|
90 |
|
if (gadeident != null) { |
91 |
|
helperCache.put(helperSearchKey, gadeident); |
92 |
|
} |
93 |
} |
} |
94 |
} |
} |
95 |
} |
} |
96 |
|
|
97 |
if ( gadeident == null) { |
if ( gadeident == null) { |
98 |
String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej ); |
if (config.useOpenStreetMaps) { |
99 |
osm = true; |
String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej ); |
100 |
|
osm = true; |
|
if (osmVej != null) { |
|
|
String osmVasket = AddressUtils.vaskVejnavn( osmVej ); |
|
|
gadeident = postnrVeje.get(osmVasket); |
|
101 |
|
|
102 |
if (gadeident != null) { |
if (osmVej != null) { |
103 |
helperCache.put(helperSearchKey, gadeident); |
String osmVasket = AddressUtils.vaskVejnavn( osmVej ); |
104 |
|
gadeident = postnrVeje.get(osmVasket); |
105 |
|
|
106 |
|
if (gadeident != null) { |
107 |
|
helperCache.put(helperSearchKey, gadeident); |
108 |
|
} |
109 |
} |
} |
110 |
} |
} |
111 |
} |
} |