--- dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/AddressSourceFD.java 2016/01/28 11:03:14 2861 +++ dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/coveragefileupload/AddressSourceFD.java 2016/04/26 17:37:56 3022 @@ -1,81 +1,31 @@ -package dk.daoas.adressevedligehold; +package dk.daoas.adressevedligehold.coveragefileupload; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.Charset; import java.util.List; import org.apache.commons.fileupload.FileItem; import com.google.common.base.Splitter; -import dk.daoas.adressevedligehold.AddressSourceEntry.EntryType; -import dk.daoas.adressevedligehold.util.DeduplicateHelper; +import dk.daoas.adressevedligehold.coveragefileupload.AddressSourceEntry.EntryType; -public class AddressSourceFD implements AddressSource { - - - DeduplicateHelper dirigeringsCache = new DeduplicateHelper(); - - FileItem file; - - InputStream is; - InputStreamReader isr; - BufferedReader br; - - int lineCount = 0; +public class AddressSourceFD extends AbstractAddressSource { + String filenameFirst2; public AddressSourceFD(FileItem file) throws Exception { - this.file = file; + super(file); filenameFirst2 = file.getName().substring(0, 2).toUpperCase(); } - - @Override - public String getFilename() { - return file.getName(); - } @Override public void validate() throws IOException { - try { - is = file.getInputStream(); - isr = new InputStreamReader(is, Charset.forName("ISO-8859-1") ); - br = new BufferedReader(isr); - - String line = br.readLine(); - - if (line == null) { - throw new IOException("Can't read 1st line - is file empty?"); - } - - String[] parts = line.split(";"); - if (parts.length != 9) { - throw new IOException("Not enough fields in CSV file. Found " + parts.length + ", expected 9"); - } - - - - } catch (Exception e) { - try { - br.close(); - isr.close(); - is.close(); - } catch (Exception e2) { - System.out.println("Error cleaning up resources"); - } - - throw e; // Re-throw - - } + super.validateWithHeader(9, ';'); } - //TODO: Skal csv parsning klares med Apache Commons CSV ? @Override public AddressSourceEntry getNextEntry() throws IOException { @@ -86,7 +36,6 @@ if (line.trim().equals("")) return null; - //System.out.println(line); AddressSourceEntry entry = new AddressSourceEntry( EntryType.TypeSingleAddress); entry.distributor = "FD"; @@ -131,22 +80,10 @@ public String getDistributor() { return "FD"; } - - @Override //AutoCloseable - public void close() throws Exception { - System.out.println("Closing FD after lines " + lineCount); - try { - br.close(); - isr.close(); - is.close(); - - file.delete(); - - } catch (Exception e) { - System.out.println("Error on closing " + e.getMessage() ); - } - - + + @Override + public boolean calculateDistances() { + return false; //FD skal IKKE beregne afstande } }