Commit ead7a434 authored by Riegel's avatar Riegel
Browse files

Refactor: Extract faulty entry handling by subclassing

2 merge requests!28Version 3.17.0 Release,!26Add ZIP-archive support
Showing with 48 additions and 38 deletions
+48 -38
...@@ -9,23 +9,15 @@ import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration; ...@@ -9,23 +9,15 @@ import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
public class CityGmlZipEntry { public class CityGmlZipEntry {
private static final Logger logger = LogManager.getLogger(CityGmlZipEntry.class); private static final Logger logger = LogManager.getLogger(CityGmlZipEntry.class);
public enum ZipEntryErrorType {
INVALID_CITY_GML_FILE, EXCESSIVE_FILESIZE, IO_ERROR
}
private String fileName; private String fileName;
private String archivePath; private String archivePath;
private CityDoctorModel model; private CityDoctorModel model;
...@@ -40,8 +32,7 @@ public class CityGmlZipEntry { ...@@ -40,8 +32,7 @@ public class CityGmlZipEntry {
cgzEntry.fileName = entry.getName(); cgzEntry.fileName = entry.getName();
cgzEntry.archivePath = archivePath; cgzEntry.archivePath = archivePath;
if ((double) entry.getSize() /1024/1024 > 20) { if ((double) entry.getSize() /1024/1024 > 20) {
cgzEntry.erroneousEntry = true; return new ErroneousEntry(entry, ZipEntryErrorType.EXCESSIVE_FILESIZE);
cgzEntry.errorType = ZipEntryErrorType.EXCESSIVE_FILESIZE;
} else { } else {
try { try {
Files.copy(is, Path.of(tempDir.toString(), entry.getName())); Files.copy(is, Path.of(tempDir.toString(), entry.getName()));
...@@ -49,21 +40,25 @@ public class CityGmlZipEntry { ...@@ -49,21 +40,25 @@ public class CityGmlZipEntry {
cgzEntry.model = CityGmlParser.parseCityGmlFile(tempDir.toString() + File.separator + entry.getName(), config); cgzEntry.model = CityGmlParser.parseCityGmlFile(tempDir.toString() + File.separator + entry.getName(), config);
} catch (CityGmlParseException | InvalidGmlFileException e) { } catch (CityGmlParseException | InvalidGmlFileException e) {
logger.error(e); logger.error(e);
cgzEntry.erroneousEntry = true; return new ErroneousEntry(entry, ZipEntryErrorType.INVALID_CITY_GML_FILE);
cgzEntry.errorType = ZipEntryErrorType.INVALID_CITY_GML_FILE;
} catch (IOException e){ } catch (IOException e){
logger.error(e); logger.error(e);
cgzEntry.erroneousEntry = true; return new ErroneousEntry(entry, ZipEntryErrorType.IO_ERROR);
cgzEntry.errorType = ZipEntryErrorType.IO_ERROR;
} }
} }
return cgzEntry; return cgzEntry;
} }
private CityGmlZipEntry(String filename, CityDoctorModel model){
this.fileName = filename;
this.model = model;
}
protected CityGmlZipEntry(ZipEntry entry) {
this.fileName = entry.getName();
this.model = null;
}
public void validateModel(){ public void validateModel(){
if(erroneousEntry){
return;
}
Checker checker = new Checker(this.getModel()); Checker checker = new Checker(this.getModel());
checker.runChecks(); checker.runChecks();
validated = true; validated = true;
...@@ -73,31 +68,12 @@ public class CityGmlZipEntry { ...@@ -73,31 +68,12 @@ public class CityGmlZipEntry {
return validated; return validated;
} }
public void setIsLibraryObject(boolean isLibraryObject) {
this.isLibraryObject = isLibraryObject;
}
public String getFileName() { public String getFileName() {
return fileName; return fileName;
} }
public String getArchivePath() {
return archivePath;
}
public CityDoctorModel getModel() { public CityDoctorModel getModel() {
return model; return model;
} }
public ZipEntryErrorType getErrorType() {
return errorType;
}
public boolean isLibraryObject() {
return isLibraryObject;
}
public boolean isErroneousEntry() {
return erroneousEntry;
}
} }
package de.hft.stuttgart.citydoctor2.ziploader;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ErroneousEntry extends CityGmlZipEntry {
private ZipEntryErrorType errorType = null;
public ErroneousEntry(ZipEntry entry, ZipEntryErrorType errorType){
super(entry);
}
@Override
public void validateModel(){}
@Override
public CityDoctorModel getModel(){
return null;
}
public ZipEntryErrorType getErrorType() {
return errorType;
}
}
package de.hft.stuttgart.citydoctor2.ziploader;
public enum ZipEntryErrorType {
INVALID_CITY_GML_FILE, EXCESSIVE_FILESIZE, IO_ERROR
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment