1 |
package dk.daoas.adressevedligehold; |
package dk.daoas.adressevedligehold.coveragefileupload; |
2 |
|
|
3 |
import java.sql.SQLException; |
import java.sql.SQLException; |
4 |
import java.util.ArrayList; |
import java.util.ArrayList; |
11 |
|
|
12 |
import org.apache.commons.lang3.StringUtils; |
import org.apache.commons.lang3.StringUtils; |
13 |
|
|
|
import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType; |
|
14 |
import dk.daoas.adressevedligehold.beans.Address; |
import dk.daoas.adressevedligehold.beans.Address; |
15 |
import dk.daoas.adressevedligehold.beans.Address.AddressState; |
import dk.daoas.adressevedligehold.beans.Address.AddressState; |
16 |
import dk.daoas.adressevedligehold.db.DatabaseLayerImplementation; |
import dk.daoas.adressevedligehold.coveragefileupload.AddressSourceEntry.EntryType; |
17 |
|
import dk.daoas.adressevedligehold.db.DatabaseCoverageUpdate; |
18 |
import dk.daoas.adressevedligehold.tasks.TaskLogger; |
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; |
22 |
|
|
23 |
/* |
/* |
24 |
* TODO: håndtering af entry dupletter ! (+ rapportering af dem) |
* |
|
|
|
|
|
|
|
|
|
25 |
*/ |
*/ |
26 |
|
|
27 |
public class AddressManager { |
public class AddressManager { |
41 |
Map<Short,Short> dbkBaneMap = new TreeMap<Short,Short>(); |
Map<Short,Short> dbkBaneMap = new TreeMap<Short,Short>(); |
42 |
|
|
43 |
public AddressManager() throws SQLException { |
public AddressManager() throws SQLException { |
44 |
DatabaseLayerImplementation db = new DatabaseLayerImplementation(); |
DatabaseCoverageUpdate db = new DatabaseCoverageUpdate(); |
45 |
|
|
46 |
searchStructure = new TreeMap<Integer, TreeMap<Short, ArrayList<Address>> >(); |
searchStructure = new TreeMap<Integer, TreeMap<Short, ArrayList<Address>> >(); |
47 |
|
|
89 |
|
|
90 |
|
|
91 |
} |
} |
92 |
|
|
93 |
|
@SuppressWarnings("PMD.CollapsibleIfStatements") |
94 |
public void closeUnvisitedAddresses(String distributor, EntryUgedage ugedage) { |
public void closeUnvisitedAddresses(String distributor, EntryUgedage ugedage) { |
95 |
for (Address addr : addressList) { |
for (Address addr : addressList) { |
96 |
if (addr.distributor == null) |
if (addr.distributor == null) |
191 |
} |
} |
192 |
} |
} |
193 |
|
|
194 |
public void writeBackChanges() { |
public void writeBackChanges() throws Exception{ |
195 |
logger.info("Writing back changes"); |
logger.info("Writing back changes"); |
196 |
TimingHelper timer = new TimingHelper(); |
TimingHelper timer = new TimingHelper(); |
197 |
|
|
207 |
} |
} |
208 |
} |
} |
209 |
|
|
210 |
DatabaseLayerImplementation db = new DatabaseLayerImplementation(); |
DatabaseCoverageUpdate db = new DatabaseCoverageUpdate(); |
211 |
|
|
212 |
db.updateAddresses(updates); |
db.updateAddresses(updates); |
213 |
db.saveNewAddresses(inserts); |
db.saveNewAddresses(inserts); |
229 |
private void visitSingle(AddressSourceEntry entry) { |
private void visitSingle(AddressSourceEntry entry) { |
230 |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
231 |
if (gade == null) { |
if (gade == null) { |
232 |
|
/* No need to register unknown streets, since we create all entries that we can |
233 |
if (! unknownStreets.containsKey(entry.gadeid)) { |
if (! unknownStreets.containsKey(entry.gadeid)) { |
234 |
unknownStreets.put(entry.gadeid, entry.vejnavn); |
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; |
256 |
} |
} |
257 |
} |
} |
258 |
|
|
259 |
|
@SuppressWarnings("PMD.CollapsibleIfStatements") |
260 |
private void visitRange(AddressSourceEntry entry) { |
private void visitRange(AddressSourceEntry entry) { |
261 |
|
|
262 |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
TreeMap<Short, ArrayList<Address>> gade = searchStructure.get( entry.gadeid ); |
501 |
return; |
return; |
502 |
} |
} |
503 |
|
|
504 |
if (entry.husnr == 999) { |
if (entry.husnr == 999 || entry.husnr == 998) { //frasorter de to højest gyldige husnr - det er typisk special adresser |
505 |
return; |
return; |
506 |
} |
} |
507 |
|
|
523 |
return; |
return; |
524 |
} |
} |
525 |
|
|
526 |
|
if (entry.vejkode > 9999) { |
527 |
|
return; |
528 |
|
} |
529 |
|
|
530 |
if (entry.gadeid == 0) { |
if (entry.gadeid == 0) { |
531 |
return; |
return; |
532 |
} |
} |
598 |
|
|
599 |
private void updateDbkBane(Address a) { |
private void updateDbkBane(Address a) { |
600 |
List<Short> daoBane205 = Arrays.asList( new Short[] {7,10,11,12,12,14,15,16,18,19,20} ); |
List<Short> daoBane205 = Arrays.asList( new Short[] {7,10,11,12,12,14,15,16,18,19,20} ); |
601 |
|
|
602 |
|
|
603 |
Short bane = null; |
Short bane = null; |
604 |
|
|
605 |
switch (a.distributor) { |
switch (a.distributor) { |
608 |
break; |
break; |
609 |
case "DAO": |
case "DAO": |
610 |
String koreliste = MiscUtils.firstNonNull(a.korelisteMandag,a.korelisteLordag, a.korelisteSondag); //DAO har kun 3 dækningstyper |
String koreliste = MiscUtils.firstNonNull(a.korelisteMandag,a.korelisteLordag, a.korelisteSondag); //DAO har kun 3 dækningstyper |
611 |
short first2 = Short.parseShort( koreliste.substring(0,2) ); |
try { |
612 |
if ( daoBane205.contains(first2) ) { |
short first2 = Short.parseShort( koreliste.substring(0,2) ); |
613 |
bane = 205; |
if ( daoBane205.contains(first2) ) { |
614 |
} else if (first2 >= 24 && first2<=30) { |
bane = 205; |
615 |
bane = 201; |
} else if (first2 >= 24 && first2<=30) { |
616 |
} else { |
bane = 201; |
617 |
bane = 202; |
} else { |
618 |
|
bane = 202; |
619 |
|
} |
620 |
|
} catch (NumberFormatException e) { |
621 |
|
throw new RuntimeException("Error parsing koreliste '" + koreliste + "' for " + a); |
622 |
} |
} |
623 |
|
|
624 |
break; |
break; |