1 |
package dk.daoas.adressevedligehold; |
package dk.daoas.adressevedligehold.fileupload; |
2 |
|
|
3 |
import java.io.IOException; |
import java.io.IOException; |
4 |
import java.util.List; |
import java.util.List; |
8 |
import com.google.common.base.CharMatcher; |
import com.google.common.base.CharMatcher; |
9 |
import com.google.common.base.Splitter; |
import com.google.common.base.Splitter; |
10 |
|
|
11 |
import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType; |
import dk.daoas.adressevedligehold.fileupload.AddressSourceEntry.EntryType; |
12 |
import dk.daoas.adressevedligehold.util.SafeParsers; |
import dk.daoas.adressevedligehold.util.SafeParsers; |
13 |
|
|
14 |
public class AddressSourceBK extends AbstractAddressSource { |
public class AddressSourceBK extends AbstractAddressSource { |
22 |
|
|
23 |
@Override |
@Override |
24 |
public void validate() throws IOException { |
public void validate() throws IOException { |
25 |
super.validatNoHeaderLine(14, ';'); |
super.validatNoHeaderLine(15, ';'); |
26 |
} |
} |
27 |
|
|
|
//TODO: Skal csv parsning klares med Apache Commons CSV ? |
|
28 |
|
|
29 |
@Override |
@Override |
30 |
public AddressSourceEntry getNextEntry() throws IOException { |
public AddressSourceEntry getNextEntry() throws IOException { |
35 |
if (line.trim().equals("")) |
if (line.trim().equals("")) |
36 |
return null; |
return null; |
37 |
|
|
|
//System.out.println(line); |
|
38 |
|
|
39 |
AddressSourceEntry entry = new AddressSourceEntry( EntryType.TypeSingleAddress); |
AddressSourceEntry entry = new AddressSourceEntry( EntryType.TypeSingleAddress); |
40 |
entry.distributor = "BK"; |
entry.distributor = "BK"; |
41 |
|
|
42 |
List<String> parts = splitter.splitToList(line); |
List<String> parts = splitter.splitToList(line); |
43 |
|
|
44 |
if (parts.size() != 14) { |
if (parts.size() != 15) { |
45 |
throw new IOException("Not enough fields in CSV file. Found " + parts.size() + ", expected 14"); |
throw new IOException("Wrong number of fields in CSV file. Found " + parts.size() + ", expected 15"); |
46 |
} |
} |
47 |
|
|
48 |
entry.postnr = Short.parseShort( parts.get(0) ); |
entry.postnr = Short.parseShort( parts.get(0) ); |
61 |
String foede = parts.get( 10 ); |
String foede = parts.get( 10 ); |
62 |
String jobnr = parts.get( 11 ); |
String jobnr = parts.get( 11 ); |
63 |
String tklaes = parts.get( 12 ); |
String tklaes = parts.get( 12 ); |
64 |
|
//String pris = parts.get( 13 );//bruges ikke |
65 |
|
//String blank = parts.get(14); //Bruges slet ikke - bk afslutter deres linier med en ; |
66 |
|
|
67 |
entry.rute = laesnr; |
entry.rute = laesnr; |
68 |
entry.koreliste = "/" + foede + "/" + tklaes + "/" + jobnr; |
entry.koreliste = "/" + foede + "/" + tklaes + "/" + jobnr; |
98 |
return "BK"; |
return "BK"; |
99 |
} |
} |
100 |
|
|
101 |
|
|
102 |
|
@Override |
103 |
|
public boolean calculateDistances() { |
104 |
|
return true; //BK skal beregne afstande |
105 |
|
} |
106 |
|
|
107 |
} |
} |