33 |
|
|
34 |
Map<Integer, TreeMap<Short, ArrayList<Address>> > searchStructure; |
Map<Integer, TreeMap<Short, ArrayList<Address>> > searchStructure; |
35 |
|
|
36 |
ArrayList<AddressSourceEntry> afvisteEntries = new ArrayList<AddressSourceEntry>(); |
ArrayList<AddressSourceEntry> rejectedEntries = new ArrayList<AddressSourceEntry>(); |
37 |
|
|
38 |
|
Map<Integer,String> unknownStreets = new TreeMap<Integer, String>(); |
39 |
|
|
40 |
Map<Short,Short> dbkBaneMap = new TreeMap<Short,Short>(); |
Map<Short,Short> dbkBaneMap = new TreeMap<Short,Short>(); |
41 |
|
|
208 |
DatabaseLayerImplementation db = new DatabaseLayerImplementation(); |
DatabaseLayerImplementation db = new DatabaseLayerImplementation(); |
209 |
|
|
210 |
db.updateAddresses(updates); |
db.updateAddresses(updates); |
211 |
|
db.saveNewAddresses(inserts); |
212 |
|
|
213 |
|
|
214 |
|
|
227 |
private void visitSingle(AddressSourceEntry entry) { |
private void visitSingle(AddressSourceEntry entry) { |
228 |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
229 |
if (gade == null) { |
if (gade == null) { |
230 |
|
if (! unknownStreets.containsKey(entry.gadeid)) { |
231 |
|
unknownStreets.put(entry.gadeid, entry.vejnavn); |
232 |
|
} |
233 |
|
|
234 |
createFromEntry(entry); // if we get here there was no match - so we need to create it |
createFromEntry(entry); // if we get here there was no match - so we need to create it |
235 |
return; |
return; |
236 |
} |
} |
240 |
createFromEntry(entry); // if we get here there was no match - so we need to create it |
createFromEntry(entry); // if we get here there was no match - so we need to create it |
241 |
return; |
return; |
242 |
} |
} |
243 |
|
boolean found = false; |
244 |
for (Address addr : litraList) { |
for (Address addr : litraList) { |
245 |
if (addr.husnrbogstav.equals(entry.litra) ) { |
if (addr.husnrbogstav.equals(entry.litra) ) { |
246 |
updateAddress(addr, entry); |
updateAddress(addr, entry); |
247 |
return; //Done for now - no need to look at the rest of the list |
found = true; // 1 visit should be enough but as long as there's duplicates on gadeid+husnr+litra we will visit them all |
248 |
|
//when the issue with duplicates is resolved this should be reverted to a return or break |
249 |
} |
} |
250 |
} |
} |
251 |
|
if (found == false) { |
252 |
createFromEntry(entry); // if we get here there was no match - so we need to create it |
createFromEntry(entry); // if we get here there was no match - so we need to create it |
253 |
|
} |
254 |
} |
} |
255 |
|
|
256 |
private void visitRange(AddressSourceEntry entry) { |
private void visitRange(AddressSourceEntry entry) { |
257 |
|
|
258 |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
259 |
if (gade == null) { |
if (gade == null) { |
260 |
|
if (! unknownStreets.containsKey(entry.gadeid)) { |
261 |
|
unknownStreets.put(entry.gadeid, entry.vejnavn); |
262 |
|
} |
263 |
|
|
264 |
System.out.println("[Range] Ukendt gadeID " + entry); |
System.out.println("[Range] Ukendt gadeID " + entry); |
265 |
return; |
return; |
266 |
} |
} |
300 |
|
|
301 |
private void updateAddress(Address addr, AddressSourceEntry entry) { |
private void updateAddress(Address addr, AddressSourceEntry entry) { |
302 |
if ( addr.distributor != null && addr.distributor.equals(entry.distributor) == false) { |
if ( addr.distributor != null && addr.distributor.equals(entry.distributor) == false) { |
303 |
afvisteEntries.add(entry); |
rejectedEntries.add(entry); |
304 |
System.out.println("Afviser " + entry); |
System.out.println("Afviser " + entry); |
305 |
return; |
return; |
306 |
} |
} |
457 |
|
|
458 |
|
|
459 |
|
|
460 |
addr.visited = true; |
//addr.visited = true; |
461 |
if (addr.state == AddressState.NOT_CHANGED) { |
if (addr.state == AddressState.NOT_CHANGED) { |
462 |
if (addr.distributor == null) { |
if (addr.distributor == null) { |
463 |
addr.state = AddressState.OPENED; |
addr.state = AddressState.OPENED; |
485 |
if (entry.kommunekode == 0 || entry.vejkode == 0) { |
if (entry.kommunekode == 0 || entry.vejkode == 0) { |
486 |
return; |
return; |
487 |
} |
} |
488 |
|
if (entry.kommunekode < 100) { |
489 |
|
return; |
490 |
|
} |
491 |
|
|
492 |
|
String gadeidStr = Integer.toString(entry.gadeid); |
493 |
|
if (gadeidStr.length() != 9) { |
494 |
|
return; |
495 |
|
} |
496 |
|
if (Short.parseShort(gadeidStr.substring(0, 4)) != entry.postnr) { |
497 |
|
return; //gadeid / postnr mismatch |
498 |
|
} |
499 |
|
|
500 |
|
|
501 |
|
|
502 |
System.out.println("Opretter adresse ud fra " + entry); |
System.out.println("Opretter adresse ud fra " + entry); |
512 |
a.husnr = entry.husnr; |
a.husnr = entry.husnr; |
513 |
a.husnrbogstav = entry.litra; |
a.husnrbogstav = entry.litra; |
514 |
a.postnr = entry.postnr; |
a.postnr = entry.postnr; |
515 |
a.visited = true; |
//a.visited = true; |
516 |
|
|
517 |
if (entry.ugedage.mandag) { |
if (entry.ugedage.mandag) { |
518 |
a.ruteMandag = entry.rute; |
a.ruteMandag = entry.rute; |
611 |
break; |
break; |
612 |
case "NS": |
case "NS": |
613 |
bane = 204; |
bane = 204; |
614 |
break; |
break; |
615 |
|
default: |
616 |
|
throw new RuntimeException("Ukendt distributor" + a.distributor); //Silence findBugs |
617 |
} |
} |
618 |
|
|
619 |
if (bane == null) { |
if (bane == null) { |
632 |
return Collections.unmodifiableList(addressList); |
return Collections.unmodifiableList(addressList); |
633 |
} |
} |
634 |
|
|
635 |
|
public Map<Integer,String> getUnknownStreets() { |
636 |
|
return Collections.unmodifiableMap( unknownStreets ); |
637 |
|
} |
638 |
|
|
639 |
|
|
640 |
|
|
641 |
public int getAfvistAntal() { |
public int getRejectedCount() { |
642 |
return afvisteEntries.size(); |
return rejectedEntries.size(); |
643 |
} |
} |
644 |
|
|
645 |
} |
} |