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

Diff of /dao/DaoAdresseService/src/dk/daoas/daoadresseservice/AdressSearch.java

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

revision 2358 by torben, Tue Feb 24 10:18:19 2015 UTC revision 2359 by torben, Tue Feb 24 11:18:47 2015 UTC
# Line 12  import java.util.Map; Line 12  import java.util.Map;
12  import java.util.Set;  import java.util.Set;
13  import java.util.concurrent.ConcurrentHashMap;  import java.util.concurrent.ConcurrentHashMap;
14    
 import dk.daoas.daoadresseservice.AddressUtils.SplitResult;  
15  import dk.daoas.daoadresseservice.admin.ServiceConfig;  import dk.daoas.daoadresseservice.admin.ServiceConfig;
16  import dk.daoas.daoadresseservice.beans.Address;  import dk.daoas.daoadresseservice.beans.Address;
17  import dk.daoas.daoadresseservice.beans.DataStatisticsBean;  import dk.daoas.daoadresseservice.beans.DataStatisticsBean;
# Line 42  public class AdressSearch { Line 41  public class AdressSearch {
41                    
42          public SearchResult search(String postnrStr, String adresse)  {          public SearchResult search(String postnrStr, String adresse)  {
43                                    
44                    SearchResult result = new SearchResult();
45                    
46                  int postnr=0;                  int postnr=0;
47                  boolean google = false;  
                 boolean osm = false;  
48                  String helperSearchKey = "";                  String helperSearchKey = "";
49                                    
50                  try {                  try {
51                          postnr = Integer.parseInt(postnrStr);                          postnr = Integer.parseInt(postnrStr);
52                  } catch (Exception E) {                  } catch (Exception E) {
53                          return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);                          result.status = Status.ERROR_UNKNOWN_POSTAL;
54                            return result;
55                  }                                }              
56                                    
57                  Map<String,Long> postnrVeje = searchPostnrVejnavnGadeid.get(postnr);                                      Map<String,Long> postnrVeje = searchPostnrVejnavnGadeid.get(postnr);                    
58                                    
59                  if (postnrVeje == null) {                  if (postnrVeje == null) {
60                          return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);                          result.status = Status.ERROR_UNKNOWN_POSTAL;
61                            return result;
62                  }                  }
63                                    
64                                    
65                  SplitResult split = AddressUtils.splitAdresse(adresse);                  result.splitReult = AddressUtils.splitAdresse(adresse);
66                                                                                                    
67                                    
68                  if (split.husnr.length() == 0) {                  if (result.splitReult.husnr.length() == 0) {
69                          return new SearchResult(Status.ERROR_MISSING_HOUSENUMBER);                                                result.status = Status.ERROR_MISSING_HOUSENUMBER;
70                            return result;
71                  }                  }
72                                    
73                  String vasketVejnavn = AddressUtils.vaskVejnavn( split.vej );                  String vasketVejnavn = AddressUtils.vaskVejnavn( result.splitReult.vej );
74                                    
75                  Long gadeident =  postnrVeje.get(vasketVejnavn);                  Long gadeident =  postnrVeje.get(vasketVejnavn);
76                                    
# Line 80  public class AdressSearch { Line 83  public class AdressSearch {
83                                    
84                  if ( gadeident == null) {                  if ( gadeident == null) {
85                          if (config.useGoogle) {                          if (config.useGoogle) {
86                                  String googleVej = GeocodeHelper.googleHelper(config, postnr, split.vej );                                  result.googleVej = GeocodeHelper.googleHelper(config, postnr, result.splitReult.vej );
87                                  google = true;                                  result.google = true;
88                                                                    
89                                  if (googleVej != null) {                                  if (result.googleVej != null) {
90                                          String googleVasket = AddressUtils.vaskVejnavn( googleVej );                                          String googleVasket = AddressUtils.vaskVejnavn( result.googleVej );
91                                          gadeident =  postnrVeje.get(googleVasket);                                          gadeident =  postnrVeje.get(googleVasket);
92                                                                                    
93                                          if (gadeident != null) {                                          if (gadeident != null) {
# Line 96  public class AdressSearch { Line 99  public class AdressSearch {
99                                    
100                  if ( gadeident == null) {                  if ( gadeident == null) {
101                          if (config.useOpenStreetMaps) {                          if (config.useOpenStreetMaps) {
102                                  String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej );                                  result.osmVej = GeocodeHelper.openstreetmapHelper(postnr, result.splitReult.vej );
103                                  osm = true;                                  result.osm = true;
104                                                                    
105                                  if (osmVej != null) {                                  if (result.osmVej != null) {
106                                          String osmVasket = AddressUtils.vaskVejnavn( osmVej );                                          String osmVasket = AddressUtils.vaskVejnavn( result.osmVej );
107                                          gadeident =  postnrVeje.get(osmVasket);                                          gadeident =  postnrVeje.get(osmVasket);
108                                                                                    
109                                          if (gadeident != null) {                                          if (gadeident != null) {
# Line 110  public class AdressSearch { Line 113  public class AdressSearch {
113                          }                          }
114                  }                  }
115                                    
116                  if (gadeident == null) {                  if (gadeident == null) {                        
117                          return new SearchResult(Status.ERROR_UNKNOWN_STREETNAME);                          result.status = Status.ERROR_UNKNOWN_STREETNAME;
118                            return result;
119                  }                  }
120                                    
121                  Map<String, Address> gade =  searchGadeidentAdresser.get(gadeident); //Denne søgning må ikke fejle                  Map<String, Address> gade = searchGadeidentAdresser.get(gadeident);
122                    if (gade == null) { //Denne søgning må ikke fejle
123                            result.status = Status.ERROR_INTERNAL;
124                            return result;                  
125                    }
126                                    
127                                    
128                  String husnrSearch = "" + split.husnr + split.litra;                  String husnrSearch = "" + result.splitReult.husnr + result.splitReult.litra;
129                  Address addr = gade.get(husnrSearch);                  Address addr = gade.get(husnrSearch);
130    
131                  if (addr == null) {                  if (addr == null) {
132                          return new SearchResult(Status.ERROR_UNKNOWN_ADDRESSPOINT);                          result.status = Status.ERROR_UNKNOWN_ADDRESSPOINT;
133                            return result;
134                  }                  }
135                                    
136                    result.address = addr;
137                    
138                    if (addr.distributor.equals("LUKKET")) {                        
139                            result.status = Status.STATUS_NOT_COVERED; //Skal vi have en special status til Lukkede adresser ?
140                            return result;
141                    }                              
142                    
143                  if (addr.daekningsType == DaekningsType.DAEKNING_IKKEDAEKKET) {                  if (addr.daekningsType == DaekningsType.DAEKNING_IKKEDAEKKET) {
144                          return new SearchResult(Status.STATUS_NOT_COVERED);                          result.status = Status.STATUS_NOT_COVERED;
145                            return result;
146                  }                  }
147    
148                                    
149                  if (addr.distributor.equals("LUKKET")) {                  result.status = Status.STATUS_OK;
150                          return new SearchResult(Status.STATUS_NOT_COVERED); //Skal vi have en special status til Lukkede adresser ?  
151                  }                                return result;
                   
                 SearchResult res = new SearchResult(addr);  
                 res.google = google;  
                 res.osm = osm;  
                 return res;  
152          }          }
153                    
154                    

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

  ViewVC Help
Powered by ViewVC 1.1.20