/[projects]/dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/AddressSearch.java
ViewVC logotype

Diff of /dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/AddressSearch.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2332 by torben, Sat Feb 21 13:39:56 2015 UTC revision 2358 by torben, Tue Feb 24 10:18:19 2015 UTC
# Line 1  Line 1 
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;
# Line 10  import java.util.Set; Line 13  import java.util.Set;
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;
# Line 26  public class AdressSearch { Line 31  public class AdressSearch {
31                    
32          private Map<String,Long> helperCache;          private Map<String,Long> helperCache;
33                    
34            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)  {
# Line 49  public class AdressSearch { Line 61  public class AdressSearch {
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                                    
# Line 65  public class AdressSearch { Line 79  public class AdressSearch {
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                  }                  }
# Line 259  public class AdressSearch { Line 277  public class AdressSearch {
277                  long stop = System.currentTimeMillis();                  long stop = System.currentTimeMillis();
278                  System.out.println("Build, stage3 elapsed: " + (stop-start3) );                  System.out.println("Build, stage3 elapsed: " + (stop-start3) );
279                  System.out.println("Build -- Gathering statistics");                  System.out.println("Build -- Gathering statistics");
280                                                    
                 int direkteCount = 0;  
                 int extendedCount = 0;  
                 int hundredePctCount = 0;  
                 int ikkeDaekketCount = 0;  
                   
281                  for (Address addr : alleAdresser) {                  for (Address addr : alleAdresser) {
282                          switch (addr.daekningsType) {                          switch (addr.daekningsType) {
283                          case DAEKNING_DIREKTE:                          case DAEKNING_DIREKTE:
284                                  direkteCount++;                                  stats.direkteCount++;
285                                  break;                                  break;
286                          case DAEKNING_UDVIDET:                          case DAEKNING_UDVIDET:
287                                  extendedCount++;                                  stats.extendedCount++;
288                                  break;                                  break;
289                          case DAEKNING_100PCT:                          case DAEKNING_100PCT:
290                                  hundredePctCount++;                                  stats.hundredePctCount++;
291                                  break;                                  break;
292                          default:                          default:
293                                  ikkeDaekketCount++;                                  stats.ikkeDaekketCount++;
294                          }                          }
295                  }                  }              
296                    
297                    
298                    stats.elapsed = stop-start1;            
299                    stats.buildTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format( new Date() );
300                                    
301                  System.out.println("Build: direkteCount: " + direkteCount);                  System.out.println("Build: direkteCount: " + stats.direkteCount);
302                  System.out.println("Build: extendedCount: " + extendedCount);                  System.out.println("Build: extendedCount: " + stats.extendedCount);
303                  System.out.println("Build: hundredePctCount: " + hundredePctCount);                  System.out.println("Build: hundredePctCount: " + stats.hundredePctCount);
304                  System.out.println("Build: ikkeDaekketCount: " + ikkeDaekketCount);                  System.out.println("Build: ikkeDaekketCount: " + stats.ikkeDaekketCount);
305                                    
306                  System.out.println("Build: Total Elapsed: " + (stop-start1) );                  System.out.println("Build: Total Elapsed: " + (stop-start1) );
307                  System.out.println("Build Completed");                  System.out.println("Build Completed");
308                                    
309          }          }
310                    
311            public DataStatisticsBean getStatistics() {
312                    return stats;
313            }
314            
315            public void clear() {
316                    searchPostnrVejnavnGadeid.clear();
317                    searchGadeidentAdresser.clear();
318                    alleAdresser.clear();
319                    helperCache.clear();
320            }
321            
322                    
323          private String calculateExtendedDaoRoute(ExtendedBean eb, Address orgAddress, Address targetAddress) {          private String calculateExtendedDaoRoute(ExtendedBean eb, Address orgAddress, Address targetAddress) {
324    
# Line 340  public class AdressSearch { Line 368  public class AdressSearch {
368                                  result.add(a);                                  result.add(a);
369                          }                          }
370                  }                  }
371                    Collections.sort(result );
372                  return result;                  return result;
373          }          }
374                    

Legend:
Removed from v.2332  
changed lines
  Added in v.2358

  ViewVC Help
Powered by ViewVC 1.1.20