1 |
package dk.daoas.adressevedligehold;
|
2 |
|
3 |
import java.io.IOException;
|
4 |
|
5 |
import org.apache.commons.fileupload.FileItem;
|
6 |
|
7 |
import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType;
|
8 |
|
9 |
public class AddressSourceDAO extends AbstractAddressSource {
|
10 |
|
11 |
final static String DAO = "DAO";
|
12 |
|
13 |
|
14 |
public AddressSourceDAO(FileItem file) throws Exception {
|
15 |
super(file);
|
16 |
|
17 |
}
|
18 |
|
19 |
@Override
|
20 |
public void validate() throws IOException {
|
21 |
super.validateWithHeader(17, ';');
|
22 |
}
|
23 |
|
24 |
|
25 |
//TODO: Skal csv parsning klares med Apache Commons CSV ?
|
26 |
|
27 |
@Override
|
28 |
public AddressSourceEntry getNextEntry() throws IOException {
|
29 |
String line = br.readLine();
|
30 |
if (line == null) // end of file
|
31 |
return null;
|
32 |
|
33 |
if (line.trim().equals(""))
|
34 |
return null;
|
35 |
|
36 |
|
37 |
AddressSourceEntry entry = new AddressSourceEntry( EntryType.TypeAddressRange);
|
38 |
entry.distributor = DAO;
|
39 |
|
40 |
String[] parts = line.split(";");
|
41 |
if (parts.length != 17) {
|
42 |
throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 17");
|
43 |
}
|
44 |
|
45 |
entry.gadeid = Integer.parseInt( parts[0] );
|
46 |
entry.vejnavn = parts[1];
|
47 |
//String stednavn = parts[2]; //Ikke brugt
|
48 |
//String david = parts[3]; //Ikke brugt
|
49 |
entry.postnr = Short.parseShort( parts[4] );
|
50 |
short net = Short.parseShort( parts[5] );
|
51 |
entry.rute = dirigeringsCache.getInstance( parts[6].toUpperCase() ); //Nogle Bruter i gl inputfil kan stå med lille b
|
52 |
entry.husnr = Short.parseShort( parts[7] );
|
53 |
entry.litra = parts[8];
|
54 |
entry.tilHusnr = Short.parseShort( parts[9] );
|
55 |
entry.tilLitra = parts[10];
|
56 |
//String sekvens = parts[11];
|
57 |
//String fraDato = parts[12];
|
58 |
//String tilDato = parts[13];
|
59 |
//short bane = Short.parseShort( parts[14] );
|
60 |
//String distributor = parts[15];
|
61 |
entry.koreliste = dirigeringsCache.getInstance( parts[16] );
|
62 |
|
63 |
switch (net) {
|
64 |
case 5:
|
65 |
entry.ugedage = EntryUgedage.LOR;
|
66 |
break;
|
67 |
case 6:
|
68 |
entry.ugedage = EntryUgedage.MAN_FRE;
|
69 |
break;
|
70 |
case 7:
|
71 |
entry.ugedage = EntryUgedage.SON;
|
72 |
break;
|
73 |
default:
|
74 |
throw new IOException("Ukendt net" + net);
|
75 |
}
|
76 |
|
77 |
|
78 |
lineCount++;
|
79 |
|
80 |
return entry;
|
81 |
}
|
82 |
|
83 |
@Override
|
84 |
public String getDistributor() {
|
85 |
return DAO;
|
86 |
}
|
87 |
|
88 |
}
|