15 |
import dk.daoas.adressevedligehold.beans.Address; |
import dk.daoas.adressevedligehold.beans.Address; |
16 |
import dk.daoas.adressevedligehold.beans.Address.AddressState; |
import dk.daoas.adressevedligehold.beans.Address.AddressState; |
17 |
import dk.daoas.adressevedligehold.db.DatabaseLayerImplementation; |
import dk.daoas.adressevedligehold.db.DatabaseLayerImplementation; |
18 |
|
import dk.daoas.adressevedligehold.tasks.TaskLogger; |
19 |
import dk.daoas.adressevedligehold.util.DeduplicateHelper; |
import dk.daoas.adressevedligehold.util.DeduplicateHelper; |
20 |
import dk.daoas.adressevedligehold.util.MiscUtils; |
import dk.daoas.adressevedligehold.util.MiscUtils; |
21 |
import dk.daoas.adressevedligehold.util.TimingHelper; |
import dk.daoas.adressevedligehold.util.TimingHelper; |
29 |
|
|
30 |
public class AddressManager { |
public class AddressManager { |
31 |
|
|
32 |
|
private TaskLogger logger = TaskLogger.getInstance(); |
33 |
|
|
34 |
|
|
35 |
List<Address> addressList; |
List<Address> addressList; |
36 |
|
|
37 |
Map<Integer, TreeMap<Short, ArrayList<Address>> > searchStructure; |
Map<Integer, TreeMap<Short, ArrayList<Address>> > searchStructure; |
38 |
|
|
39 |
ArrayList<AddressSourceEntry> afvisteEntries = new ArrayList<AddressSourceEntry>(); |
ArrayList<AddressSourceEntry> rejectedEntries = new ArrayList<AddressSourceEntry>(); |
40 |
|
|
41 |
|
Map<Integer,String> unknownStreets = new TreeMap<Integer, String>(); |
42 |
|
|
43 |
Map<Short,Short> dbkBaneMap = new TreeMap<Short,Short>(); |
Map<Short,Short> dbkBaneMap = new TreeMap<Short,Short>(); |
44 |
|
|
87 |
list.trimToSize(); |
list.trimToSize(); |
88 |
} |
} |
89 |
|
|
90 |
System.out.println("AddressManager ready, elapsed " + timer.getElapsed() + "ms"); |
logger.info("AddressManager ready, elapsed " + timer.getElapsed() + "ms"); |
91 |
|
|
92 |
|
|
93 |
} |
} |
184 |
continue; |
continue; |
185 |
} |
} |
186 |
|
|
187 |
System.out.println(addr.state + ": " + addr.toStringExtended() ); |
logger.info(addr.state + ": " + addr.toStringExtended() ); |
188 |
System.out.println(addr.getRuteString() ); |
logger.info(addr.getRuteString() ); |
189 |
|
|
190 |
if (count++ > 50) |
if (count++ > 50) |
191 |
return; |
return; |
193 |
} |
} |
194 |
|
|
195 |
public void writeBackChanges() { |
public void writeBackChanges() { |
196 |
System.out.println("Writing back changes"); |
logger.info("Writing back changes"); |
197 |
TimingHelper timer = new TimingHelper(); |
TimingHelper timer = new TimingHelper(); |
198 |
|
|
199 |
List<Address> updates = new ArrayList<Address>(1024*1024); |
List<Address> updates = new ArrayList<Address>(1024*1024); |
211 |
DatabaseLayerImplementation db = new DatabaseLayerImplementation(); |
DatabaseLayerImplementation db = new DatabaseLayerImplementation(); |
212 |
|
|
213 |
db.updateAddresses(updates); |
db.updateAddresses(updates); |
214 |
|
db.saveNewAddresses(inserts); |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
System.out.println("Writeback done: elapsed " + timer.getElapsed() + "ms."); |
logger.info("Writeback done: elapsed " + timer.getElapsed() + "ms."); |
219 |
} |
} |
220 |
|
|
221 |
|
|
230 |
private void visitSingle(AddressSourceEntry entry) { |
private void visitSingle(AddressSourceEntry entry) { |
231 |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
232 |
if (gade == null) { |
if (gade == null) { |
233 |
|
if (! unknownStreets.containsKey(entry.gadeid)) { |
234 |
|
unknownStreets.put(entry.gadeid, entry.vejnavn); |
235 |
|
} |
236 |
|
|
237 |
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 |
238 |
return; |
return; |
239 |
} |
} |
260 |
|
|
261 |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
262 |
if (gade == null) { |
if (gade == null) { |
263 |
System.out.println("[Range] Ukendt gadeID " + entry); |
if (! unknownStreets.containsKey(entry.gadeid)) { |
264 |
|
unknownStreets.put(entry.gadeid, entry.vejnavn); |
265 |
|
} |
266 |
|
|
267 |
|
logger.info("[Range] Ukendt gadeID " + entry); |
268 |
return; |
return; |
269 |
} |
} |
270 |
|
|
303 |
|
|
304 |
private void updateAddress(Address addr, AddressSourceEntry entry) { |
private void updateAddress(Address addr, AddressSourceEntry entry) { |
305 |
if ( addr.distributor != null && addr.distributor.equals(entry.distributor) == false) { |
if ( addr.distributor != null && addr.distributor.equals(entry.distributor) == false) { |
306 |
afvisteEntries.add(entry); |
rejectedEntries.add(entry); |
307 |
System.out.println("Afviser " + entry); |
logger.info("Afviser " + entry); |
308 |
return; |
return; |
309 |
} |
} |
310 |
|
|
326 |
} |
} |
327 |
} |
} |
328 |
} else { |
} else { |
329 |
System.out.println( "Double visit monday " + addr); |
logger.info( "Double visit monday " + addr); |
330 |
} |
} |
331 |
|
|
332 |
} |
} |
348 |
} |
} |
349 |
} |
} |
350 |
} else { |
} else { |
351 |
System.out.println( "Double visit tuesday " + addr); |
logger.info( "Double visit tuesday " + addr); |
352 |
} |
} |
353 |
} |
} |
354 |
|
|
368 |
} |
} |
369 |
} |
} |
370 |
} else { |
} else { |
371 |
System.out.println( "Double visit wednesday " + addr); |
logger.info( "Double visit wednesday " + addr); |
372 |
} |
} |
373 |
} |
} |
374 |
|
|
390 |
} |
} |
391 |
} |
} |
392 |
} else { |
} else { |
393 |
System.out.println( "Double visit thursday " + addr); |
logger.info( "Double visit thursday " + addr); |
394 |
} |
} |
395 |
} |
} |
396 |
|
|
411 |
} |
} |
412 |
} |
} |
413 |
} else { |
} else { |
414 |
System.out.println( "Double visit friday " + addr); |
logger.info( "Double visit friday " + addr); |
415 |
} |
} |
416 |
} |
} |
417 |
|
|
433 |
} |
} |
434 |
} |
} |
435 |
} else { |
} else { |
436 |
System.out.println( "Double visit saturday " + addr); |
logger.info( "Double visit saturday " + addr); |
437 |
} |
} |
438 |
} |
} |
439 |
|
|
454 |
} |
} |
455 |
} |
} |
456 |
} else { |
} else { |
457 |
System.out.println( "Double visit sunday " + addr); |
logger.info( "Double visit sunday " + addr); |
458 |
} |
} |
459 |
} |
} |
460 |
|
|
491 |
if (entry.kommunekode < 100) { |
if (entry.kommunekode < 100) { |
492 |
return; |
return; |
493 |
} |
} |
494 |
if (Short.parseShort(Integer.toString(entry.gadeid).substring(0, 4)) != entry.postnr) { |
|
495 |
|
if (entry.gadeid == 0) { |
496 |
|
return; |
497 |
|
} |
498 |
|
|
499 |
|
String gadeidStr = Integer.toString(entry.gadeid); |
500 |
|
if (gadeidStr.length() != 9) { |
501 |
|
return; |
502 |
|
} |
503 |
|
if (Short.parseShort(gadeidStr.substring(0, 4)) != entry.postnr) { |
504 |
return; //gadeid / postnr mismatch |
return; //gadeid / postnr mismatch |
505 |
} |
} |
506 |
|
|
507 |
|
|
508 |
|
|
509 |
System.out.println("Opretter adresse ud fra " + entry); |
logger.info("Opretter adresse ud fra " + entry); |
510 |
|
|
511 |
Address a = new Address(); |
Address a = new Address(); |
512 |
a.state = AddressState.CREATED; |
a.state = AddressState.CREATED; |
620 |
bane = 204; |
bane = 204; |
621 |
break; |
break; |
622 |
default: |
default: |
623 |
throw new RuntimeException("Ukendt distributor" + a.distributor); //Silence findBugs |
throw new RuntimeException("Ukendt distributor: " + a.distributor); //Silence findBugs |
624 |
} |
} |
625 |
|
|
626 |
if (bane == null) { |
if (bane == null) { |
627 |
throw new RuntimeException("Ukendt bane for postnr" + a.postnr); |
throw new RuntimeException("Ukendt bane for postnr: " + a.postnr); |
628 |
} |
} |
629 |
|
|
630 |
if (a.dbkBane != bane) { |
if (a.dbkBane != bane) { |
639 |
return Collections.unmodifiableList(addressList); |
return Collections.unmodifiableList(addressList); |
640 |
} |
} |
641 |
|
|
642 |
|
public Map<Integer,String> getUnknownStreets() { |
643 |
|
return Collections.unmodifiableMap( unknownStreets ); |
644 |
|
} |
645 |
|
|
646 |
|
|
647 |
|
|
648 |
public int getAfvistAntal() { |
public int getRejectedCount() { |
649 |
return afvisteEntries.size(); |
return rejectedEntries.size(); |
650 |
} |
} |
651 |
|
|
652 |
} |
} |