/[projects]/dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/coveragefileupload/AddressSourceDAO.java
ViewVC logotype

Annotation of /dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/coveragefileupload/AddressSourceDAO.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2869 - (hide annotations) (download)
Thu Jan 28 16:21:36 2016 UTC (8 years, 4 months ago) by torben
Original Path: dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceDAO.java
File size: 2271 byte(s)
More refactoring
1 torben 2844 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 torben 2868 public class AddressSourceDAO extends AbstractAddressSource {
10 torben 2844
11     final static String DAO = "DAO";
12    
13    
14     public AddressSourceDAO(FileItem file) throws Exception {
15 torben 2868 super(file);
16 torben 2844
17     }
18    
19     @Override
20     public void validate() throws IOException {
21 torben 2869 super.validateWithHeader(17, ';');
22 torben 2844 }
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     //System.out.println(line);
37    
38     AddressSourceEntry entry = new AddressSourceEntry( EntryType.TypeAddressRange);
39     entry.distributor = DAO;
40    
41     String[] parts = line.split(";");
42 torben 2857 if (parts.length != 17) {
43     throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 17");
44     }
45    
46 torben 2844 entry.gadeid = Integer.parseInt( parts[0] );
47     entry.vejnavn = parts[1];
48     //String stednavn = parts[2]; //Ikke brugt
49     //String david = parts[3]; //Ikke brugt
50     entry.postnr = Short.parseShort( parts[4] );
51     short net = Short.parseShort( parts[5] );
52     entry.rute = dirigeringsCache.getInstance( parts[6].toUpperCase() ); //Nogle Bruter i gl inputfil kan stÃ¥ med lille b
53     entry.husnr = Short.parseShort( parts[7] );
54     entry.litra = parts[8];
55     entry.tilHusnr = Short.parseShort( parts[9] );
56     entry.tilLitra = parts[10];
57     //String sekvens = parts[11];
58     //String fraDato = parts[12];
59     //String tilDato = parts[13];
60     //short bane = Short.parseShort( parts[14] );
61     //String distributor = parts[15];
62     entry.koreliste = dirigeringsCache.getInstance( parts[16] );
63    
64     switch (net) {
65     case 5:
66     entry.ugedage = EntryUgedage.LOR;
67     break;
68     case 6:
69     entry.ugedage = EntryUgedage.MAN_FRE;
70     break;
71     case 7:
72     entry.ugedage = EntryUgedage.SON;
73     break;
74     default:
75     throw new IOException("Ukendt net" + net);
76     }
77    
78    
79     lineCount++;
80    
81     return entry;
82     }
83    
84     @Override
85     public String getDistributor() {
86     return DAO;
87     }
88    
89     }

  ViewVC Help
Powered by ViewVC 1.1.20