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

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

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

revision 2350 by torben, Mon Feb 23 15:11:39 2015 UTC revision 2381 by torben, Thu Feb 26 10:27:54 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    
15  import dk.daoas.daoadresseservice.AddressUtils.SplitResult;  import org.apache.commons.lang3.StringUtils;
16    
17  import dk.daoas.daoadresseservice.admin.ServiceConfig;  import dk.daoas.daoadresseservice.admin.ServiceConfig;
18  import dk.daoas.daoadresseservice.beans.Address;  import dk.daoas.daoadresseservice.beans.Address;
19  import dk.daoas.daoadresseservice.beans.DataStatisticsBean;  import dk.daoas.daoadresseservice.beans.DataStatisticsBean;
# Line 42  public class AdressSearch { Line 43  public class AdressSearch {
43                    
44          public SearchResult search(String postnrStr, String adresse)  {          public SearchResult search(String postnrStr, String adresse)  {
45                                    
46                    SearchResult result = new SearchResult();
47                    
48                  int postnr=0;                  int postnr=0;
49                  boolean google = false;  
                 boolean osm = false;  
50                  String helperSearchKey = "";                  String helperSearchKey = "";
51                                    
52                  try {                  try {
53                          postnr = Integer.parseInt(postnrStr);                          postnr = Integer.parseInt(postnrStr);
54                  } catch (Exception E) {                  } catch (Exception E) {
55                          return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);                          result.status = Status.ERROR_UNKNOWN_POSTAL;
56                            return result;
57                  }                                }              
58                                    
59                  Map<String,Long> postnrVeje = searchPostnrVejnavnGadeid.get(postnr);                                      Map<String,Long> postnrVeje = searchPostnrVejnavnGadeid.get(postnr);                    
60                                    
61                  if (postnrVeje == null) {                  if (postnrVeje == null) {
62                          return new SearchResult(Status.ERROR_UNKNOWN_POSTAL);                          result.status = Status.ERROR_UNKNOWN_POSTAL;
63                            return result;
64                  }                  }
65                                    
66                                    
67                  SplitResult split = AddressUtils.splitAdresse(adresse);                  result.splitResult = AddressUtils.splitAdresse(adresse);
68                  String vasketVejnavn = AddressUtils.vaskVejnavn( split.vej );                                                                            
69                                    
70                  if (split.husnr.length() == 0) {                  if (result.splitResult.husnr.length() == 0) {
71                          return new SearchResult(Status.ERROR_MISSING_HOUSENUMBER);                                                result.status = Status.ERROR_MISSING_HOUSENUMBER;
72                            return result;
73                  }                  }
74                                    
75                    String vasketVejnavn = AddressUtils.vaskVejnavn( result.splitResult.vej );
76                    
77                  Long gadeident =  postnrVeje.get(vasketVejnavn);                  Long gadeident =  postnrVeje.get(vasketVejnavn);
78                                    
79                                    
# Line 78  public class AdressSearch { Line 85  public class AdressSearch {
85                                    
86                  if ( gadeident == null) {                  if ( gadeident == null) {
87                          if (config.useGoogle) {                          if (config.useGoogle) {
88                                  String googleVej = GeocodeHelper.googleHelper(config, postnr, split.vej );                                  result.googleVej = GeocodeHelper.googleHelper(config, postnr, result.splitResult.vej );
89                                  google = true;                                  result.google = true;
90                                                                    
91                                  if (googleVej != null) {                                  if (result.googleVej != null) {
92                                          String googleVasket = AddressUtils.vaskVejnavn( googleVej );                                          String googleVasket = AddressUtils.vaskVejnavn( result.googleVej );
93                                          gadeident =  postnrVeje.get(googleVasket);                                          gadeident =  postnrVeje.get(googleVasket);
94                                                                                    
95                                          if (gadeident != null) {                                          if (gadeident != null) {
# Line 94  public class AdressSearch { Line 101  public class AdressSearch {
101                                    
102                  if ( gadeident == null) {                  if ( gadeident == null) {
103                          if (config.useOpenStreetMaps) {                          if (config.useOpenStreetMaps) {
104                                  String osmVej = GeocodeHelper.openstreetmapHelper(postnr, split.vej );                                  result.osmVej = GeocodeHelper.openstreetmapHelper(config, postnr, result.splitResult.vej );
105                                  osm = true;                                  result.osm = true;
106                                                                    
107                                  if (osmVej != null) {                                  if (result.osmVej != null) {
108                                          String osmVasket = AddressUtils.vaskVejnavn( osmVej );                                          String osmVasket = AddressUtils.vaskVejnavn( result.osmVej );
109                                          gadeident =  postnrVeje.get(osmVasket);                                          gadeident =  postnrVeje.get(osmVasket);
110                                                                                    
111                                          if (gadeident != null) {                                          if (gadeident != null) {
# Line 108  public class AdressSearch { Line 115  public class AdressSearch {
115                          }                          }
116                  }                  }
117                                    
118                  if (gadeident == null) {                  if (gadeident == null) {                        
119                          return new SearchResult(Status.ERROR_UNKNOWN_STREETNAME);                          result.status = Status.ERROR_UNKNOWN_STREETNAME;
120                            return result;
121                  }                  }
122                                    
123                  Map<String, Address> gade =  searchGadeidentAdresser.get(gadeident); //Denne søgning må ikke fejle                  Map<String, Address> gade = searchGadeidentAdresser.get(gadeident);
124                    if (gade == null) { //Denne søgning må ikke fejle
125                            result.status = Status.ERROR_INTERNAL;
126                            return result;                  
127                    }
128                                    
129                                    
130                  String husnrSearch = "" + split.husnr + split.litra;                  String husnrSearch = "" + result.splitResult.husnr + result.splitResult.litra;
131                  Address addr = gade.get(husnrSearch);                  Address addr = gade.get(husnrSearch);
132    
133                  if (addr == null) {                  if (addr == null) {
134                          return new SearchResult(Status.ERROR_UNKNOWN_ADDRESSPOINT);                          result.status = Status.ERROR_UNKNOWN_ADDRESSPOINT;
135                            return result;
136                  }                  }
137                                    
138                    result.address = addr;
139                    
140                    
141                    if ( StringUtils.equals(addr.distributor, "LUKKET") ) {                
142                            result.status = Status.STATUS_NOT_COVERED; //Skal vi have en special status til Lukkede adresser ?
143                            return result;
144                    }                              
145                    
146                  if (addr.daekningsType == DaekningsType.DAEKNING_IKKEDAEKKET) {                  if (addr.daekningsType == DaekningsType.DAEKNING_IKKEDAEKKET) {
147                          return new SearchResult(Status.STATUS_NOT_COVERED);                          result.status = Status.STATUS_NOT_COVERED;
148                            return result;
149                  }                  }
150    
151                                    
152                  if (addr.distributor.equals("LUKKET")) {                  result.status = Status.STATUS_OK;
153                          return new SearchResult(Status.STATUS_NOT_COVERED); //Skal vi have en special status til Lukkede adresser ?  
154                  }                                return result;
                   
                 SearchResult res = new SearchResult(addr);  
                 res.google = google;  
                 res.osm = osm;  
                 return res;  
155          }          }
156                    
157                    
# Line 425  public class AdressSearch { Line 443  public class AdressSearch {
443                  aliasSet.add(vejnavn.replace("skt", "sankt") );                  aliasSet.add(vejnavn.replace("skt", "sankt") );
444                                    
445                  aliasSet.add(vejnavn.replace("skt", "sct") );                  aliasSet.add(vejnavn.replace("skt", "sct") );
446                  aliasSet.add(vejnavn.replace("sct", "skt") );                    aliasSet.add(vejnavn.replace("sct", "skt") );
447                    
448                    
449                    //alternative måder at stave vej/gade/alle
450                    aliasSet.add(vejnavn.replace("vej", "ve") );
451                    aliasSet.add(vejnavn.replace("vej", "vj") );
452                    
453                    aliasSet.add(vejnavn.replace("alle", "all") );
454                    aliasSet.add(vejnavn.replace("allé", "all") );
455                    
456                    aliasSet.add(vejnavn.replace("gade", "gaed") );
457                    
458                                    
459                  // Opbyg æøå varianter over alle fundne aliaser                  // Opbyg æøå varianter over alle fundne aliaser
460                                    

Legend:
Removed from v.2350  
changed lines
  Added in v.2381

  ViewVC Help
Powered by ViewVC 1.1.20