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;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.File;
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.ZipFile;
import java.util.zip.ZipInputStream;
public class CityGmlZipEntry {
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 archivePath;
private CityDoctorModel model;
......@@ -40,8 +32,7 @@ public class CityGmlZipEntry {
cgzEntry.fileName = entry.getName();
cgzEntry.archivePath = archivePath;
if ((double) entry.getSize() /1024/1024 > 20) {
cgzEntry.erroneousEntry = true;
cgzEntry.errorType = ZipEntryErrorType.EXCESSIVE_FILESIZE;
return new ErroneousEntry(entry, ZipEntryErrorType.EXCESSIVE_FILESIZE);
} else {
try {
Files.copy(is, Path.of(tempDir.toString(), entry.getName()));
......@@ -49,21 +40,25 @@ public class CityGmlZipEntry {
cgzEntry.model = CityGmlParser.parseCityGmlFile(tempDir.toString() + File.separator + entry.getName(), config);
} catch (CityGmlParseException | InvalidGmlFileException e) {
logger.error(e);
cgzEntry.erroneousEntry = true;
cgzEntry.errorType = ZipEntryErrorType.INVALID_CITY_GML_FILE;
return new ErroneousEntry(entry, ZipEntryErrorType.INVALID_CITY_GML_FILE);
} catch (IOException e){
logger.error(e);
cgzEntry.erroneousEntry = true;
cgzEntry.errorType = ZipEntryErrorType.IO_ERROR;
return new ErroneousEntry(entry, ZipEntryErrorType.IO_ERROR);
}
}
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(){
if(erroneousEntry){
return;
}
Checker checker = new Checker(this.getModel());
checker.runChecks();
validated = true;
......@@ -73,31 +68,12 @@ public class CityGmlZipEntry {
return validated;
}
public void setIsLibraryObject(boolean isLibraryObject) {
this.isLibraryObject = isLibraryObject;
}
public String getFileName() {
return fileName;
}
public String getArchivePath() {
return archivePath;
}
public CityDoctorModel getModel() {
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