Commit 671c277b authored by Riegel's avatar Riegel
Browse files

Style: Reformat code

Showing with 1564 additions and 1561 deletions
+1564 -1561
...@@ -5,12 +5,14 @@ import de.hft.stuttgart.citydoctor2.utils.ArchivePacker; ...@@ -5,12 +5,14 @@ import de.hft.stuttgart.citydoctor2.utils.ArchivePacker;
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.*; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serial;
import java.io.Serializable;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
...@@ -32,8 +34,7 @@ public class CityGmlZipArchive implements Serializable { ...@@ -32,8 +34,7 @@ public class CityGmlZipArchive implements Serializable {
CityGmlZipArchive cgmlArchive = new CityGmlZipArchive(Path.of(zipFile)); CityGmlZipArchive cgmlArchive = new CityGmlZipArchive(Path.of(zipFile));
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) { try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile))) {
ZipEntry ze; ZipEntry ze;
while ((ze = zis.getNextEntry()) != null ) while ((ze = zis.getNextEntry()) != null) {
{
if (ze.isDirectory()) { if (ze.isDirectory()) {
continue; continue;
} }
...@@ -49,9 +50,9 @@ public class CityGmlZipArchive implements Serializable { ...@@ -49,9 +50,9 @@ public class CityGmlZipArchive implements Serializable {
} }
} }
public void mountArchive(ParserConfiguration config){ public void mountArchive(ParserConfiguration config) {
try (ZipFile zip = new ZipFile(archivePath.toFile())) { try (ZipFile zip = new ZipFile(archivePath.toFile())) {
for (CityGmlZipEntry entry : entries){ for (CityGmlZipEntry entry : entries) {
entry.loadEntry(config); entry.loadEntry(config);
} }
} catch (IOException e) { } catch (IOException e) {
...@@ -59,9 +60,9 @@ public class CityGmlZipArchive implements Serializable { ...@@ -59,9 +60,9 @@ public class CityGmlZipArchive implements Serializable {
} }
} }
private CityGmlZipArchive(Path archivePath){ private CityGmlZipArchive(Path archivePath) {
this.archivePath = archivePath; this.archivePath = archivePath;
this.archiveNameRE = archivePath.getFileName().toString().replace(".zip","") + File.separator; this.archiveNameRE = archivePath.getFileName().toString().replace(".zip", "") + File.separator;
} }
private void setEntries(List<CityGmlZipEntry> entries) { private void setEntries(List<CityGmlZipEntry> entries) {
...@@ -69,16 +70,16 @@ public class CityGmlZipArchive implements Serializable { ...@@ -69,16 +70,16 @@ public class CityGmlZipArchive implements Serializable {
entries.forEach(e -> e.setArchive(this)); entries.forEach(e -> e.setArchive(this));
} }
public void exportToZipFile(String path) { public void exportToZipFile(String path) {
ArchivePacker.packArchive(path, this); ArchivePacker.packArchive(path, this);
} }
public CityGmlZipEntry getEntry(String fileName) { public CityGmlZipEntry getEntry(String fileName) {
fileName = stripArchivePath(fileName); fileName = stripArchivePath(fileName);
for(CityGmlZipEntry entry : entries){ for (CityGmlZipEntry entry : entries) {
String entryName = stripArchivePath(entry.getFileName()); String entryName = stripArchivePath(entry.getFileName());
if(entryName.equals(fileName)){ if (entryName.equals(fileName)) {
return entry; return entry;
} }
} }
......
...@@ -27,39 +27,39 @@ public class CityGmlZipEntry implements Serializable { ...@@ -27,39 +27,39 @@ public class CityGmlZipEntry implements Serializable {
private static final long MB = 1024 * 1024L; private static final long MB = 1024 * 1024L;
private ZipEntryErrorType errorType = null; private ZipEntryErrorType errorType = null;
public static CityGmlZipEntry of(ZipEntry entry,CityGmlZipArchive parentArchive, ParserConfiguration config){ public static CityGmlZipEntry of(ZipEntry entry, CityGmlZipArchive parentArchive, ParserConfiguration config) {
CityGmlZipEntry ze = CityGmlZipEntry.register(entry, parentArchive); CityGmlZipEntry ze = CityGmlZipEntry.register(entry, parentArchive);
ze.loadEntry(config); ze.loadEntry(config);
return ze; return ze;
} }
public void loadEntry(ParserConfiguration config){ public void loadEntry(ParserConfiguration config) {
if (decompressed){ if (decompressed) {
return; return;
} }
if (errorType != null){ if (errorType != null) {
logger.warn("Tried loading erroneous CityGmlZipEntry"); logger.warn("Tried loading erroneous CityGmlZipEntry");
return; return;
} }
try{ try {
this.model = CityGmlParser.parseCityGmlZipEntry(this, config); this.model = CityGmlParser.parseCityGmlZipEntry(this, config);
this.decompressed = true; this.decompressed = true;
} catch (CityGmlParseException | InvalidGmlFileException e) { } catch (CityGmlParseException | InvalidGmlFileException e) {
logger.error(e); logger.error(e);
this.errorType = ZipEntryErrorType.INVALID_CITY_GML_FILE; this.errorType = ZipEntryErrorType.INVALID_CITY_GML_FILE;
} catch (IOException e){ } catch (IOException e) {
logger.error(e); logger.error(e);
this.errorType = ZipEntryErrorType.IO_ERROR; this.errorType = ZipEntryErrorType.IO_ERROR;
} }
} }
public static CityGmlZipEntry register(ZipEntry entry, CityGmlZipArchive parentArchive){ public static CityGmlZipEntry register(ZipEntry entry, CityGmlZipArchive parentArchive) {
CityGmlZipEntry cgzEntry = new CityGmlZipEntry(entry, parentArchive,false); CityGmlZipEntry cgzEntry = new CityGmlZipEntry(entry, parentArchive, false);
try{ try {
if (!cgzEntry.entrySizeWithinMemoryLimits()) { if (!cgzEntry.entrySizeWithinMemoryLimits()) {
cgzEntry.errorType = ZipEntryErrorType.EXCESSIVE_FILESIZE; cgzEntry.errorType = ZipEntryErrorType.EXCESSIVE_FILESIZE;
} }
} catch (IOException e){ } catch (IOException e) {
logger.error(e); logger.error(e);
cgzEntry.errorType = ZipEntryErrorType.IO_ERROR; cgzEntry.errorType = ZipEntryErrorType.IO_ERROR;
} }
...@@ -67,11 +67,11 @@ public class CityGmlZipEntry implements Serializable { ...@@ -67,11 +67,11 @@ public class CityGmlZipEntry implements Serializable {
} }
private boolean entrySizeWithinMemoryLimits() throws IOException { private boolean entrySizeWithinMemoryLimits() throws IOException {
long memoryLimit = (long) Math.ceil(((double) Runtime.getRuntime().maxMemory() / MB)*0.9); long memoryLimit = (long) Math.ceil(((double) Runtime.getRuntime().maxMemory() / MB) * 0.9);
if (fileSize == -1L) { if (fileSize == -1L) {
try (CityGmlZipEntryFile entryFile = new CityGmlZipEntryFile(this)){ try (CityGmlZipEntryFile entryFile = new CityGmlZipEntryFile(this)) {
long filesize = entryFile.getFileSize(); long filesize = entryFile.getFileSize();
if (filesize != -1){ if (filesize != -1) {
this.fileSize = filesize; this.fileSize = filesize;
} else { } else {
return false; return false;
...@@ -83,9 +83,9 @@ public class CityGmlZipEntry implements Serializable { ...@@ -83,9 +83,9 @@ public class CityGmlZipEntry implements Serializable {
return memoryLimit > fileSize; return memoryLimit > fileSize;
} }
protected CityGmlZipEntry(ZipEntry entry,CityGmlZipArchive parentArchive, boolean decompressed) { protected CityGmlZipEntry(ZipEntry entry, CityGmlZipArchive parentArchive, boolean decompressed) {
this.fileName = entry.getName(); this.fileName = entry.getName();
if (entry.getSize() != -1){ if (entry.getSize() != -1) {
this.fileSize = entry.getSize(); this.fileSize = entry.getSize();
} }
this.model = null; this.model = null;
...@@ -93,15 +93,14 @@ public class CityGmlZipEntry implements Serializable { ...@@ -93,15 +93,14 @@ public class CityGmlZipEntry implements Serializable {
this.parentArchive = parentArchive; this.parentArchive = parentArchive;
} }
public void setArchive(CityGmlZipArchive archive){ public void setArchive(CityGmlZipArchive archive) {
parentArchive = archive; parentArchive = archive;
} }
public CityGmlZipArchive getArchive(){ public CityGmlZipArchive getArchive() {
return parentArchive; return parentArchive;
} }
public String getFileName() { public String getFileName() {
return fileName; return fileName;
} }
...@@ -118,7 +117,7 @@ public class CityGmlZipEntry implements Serializable { ...@@ -118,7 +117,7 @@ public class CityGmlZipEntry implements Serializable {
fileSize = size; fileSize = size;
} }
public long getFileSize(){ public long getFileSize() {
return fileSize; return fileSize;
} }
} }
...@@ -9,11 +9,14 @@ import java.io.IOException; ...@@ -9,11 +9,14 @@ import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class ZipTest { public class ZipTest {
ParserConfiguration config = new ParserConfiguration(8,false); ParserConfiguration config = new ParserConfiguration(8, false);
@Test @Test
...@@ -25,8 +28,8 @@ public class ZipTest { ...@@ -25,8 +28,8 @@ public class ZipTest {
checkMockArchive(cgmlArch); checkMockArchive(cgmlArch);
} }
private void checkMockArchive(CityGmlZipArchive cgmlArch){ private void checkMockArchive(CityGmlZipArchive cgmlArch) {
assertEquals(5,cgmlArch.getEntries().size()); assertEquals(5, cgmlArch.getEntries().size());
for (CityGmlZipEntry entry : cgmlArch.getEntries()) { for (CityGmlZipEntry entry : cgmlArch.getEntries()) {
assertNotNull(entry); assertNotNull(entry);
assertTrue(entry.getFileName().matches("^mock[1-5].gml$")); assertTrue(entry.getFileName().matches("^mock[1-5].gml$"));
...@@ -79,8 +82,8 @@ public class ZipTest { ...@@ -79,8 +82,8 @@ public class ZipTest {
} }
@Test @Test
public void testXMLValidation(){ public void testXMLValidation() {
ParserConfiguration valConfig = new ParserConfiguration(8,true); ParserConfiguration valConfig = new ParserConfiguration(8, true);
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/validate.zip"); CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/validate.zip");
assertNotNull(cgmlArch); assertNotNull(cgmlArch);
cgmlArch.mountArchive(valConfig); cgmlArch.mountArchive(valConfig);
...@@ -91,7 +94,7 @@ public class ZipTest { ...@@ -91,7 +94,7 @@ public class ZipTest {
@Test @Test
public void testImplicitParsing(){ public void testImplicitParsing() {
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/implicit.zip"); CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zip/implicit.zip");
assertNotNull(cgmlArch); assertNotNull(cgmlArch);
cgmlArch.mountArchive(config); cgmlArch.mountArchive(config);
......
/*- /*-
* Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart * Copyright 2020 Beuth Hochschule für Technik Berlin, Hochschule für Technik Stuttgart
* *
* This file is part of CityDoctor2. * This file is part of CityDoctor2.
* *
* CityDoctor2 is free software: you can redistribute it and/or modify * CityDoctor2 is free software: you can redistribute it and/or modify
...@@ -18,16 +18,6 @@ ...@@ -18,16 +18,6 @@
*/ */
package de.hft.stuttgart.citydoctor2.check; package de.hft.stuttgart.citydoctor2.check;
import java.io.File;
import java.io.IOException;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive;
import de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import de.hft.stuttgart.citydoctor2.CityDoctorValidation; import de.hft.stuttgart.citydoctor2.CityDoctorValidation;
import de.hft.stuttgart.citydoctor2.datastructure.Building; import de.hft.stuttgart.citydoctor2.datastructure.Building;
import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel; import de.hft.stuttgart.citydoctor2.datastructure.CityDoctorModel;
...@@ -35,99 +25,106 @@ import de.hft.stuttgart.citydoctor2.exceptions.CityDoctorWriteException; ...@@ -35,99 +25,106 @@ import de.hft.stuttgart.citydoctor2.exceptions.CityDoctorWriteException;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException; import de.hft.stuttgart.citydoctor2.parser.CityGmlParseException;
import de.hft.stuttgart.citydoctor2.parser.CityGmlParser; import de.hft.stuttgart.citydoctor2.parser.CityGmlParser;
import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException; import de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException;
import de.hft.stuttgart.citydoctor2.parser.ParserConfiguration;
import de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive;
import de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import java.io.IOException;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
*
* @author Matthias Betz * @author Matthias Betz
*
*/ */
public class CheckerTest { public class CheckerTest {
@Rule @Rule
public TemporaryFolder folder = new TemporaryFolder(); public TemporaryFolder folder = new TemporaryFolder();
@Test @Test
public void testSchematron() throws CityGmlParseException, InvalidGmlFileException { public void testSchematron() throws CityGmlParseException, InvalidGmlFileException {
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig(); ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
config.getRequirements().get(Requirement.R_SE_BS_ROOF_UNFRAGMENTED.toString()).setEnabled(false); config.getRequirements().get(Requirement.R_SE_BS_ROOF_UNFRAGMENTED.toString()).setEnabled(false);
config.setSchematronFilePathInGlobalParameters("src/test/resources/schematronTest.xml"); config.setSchematronFilePathInGlobalParameters("src/test/resources/schematronTest.xml");
CityDoctorModel model = CityGmlParser.parseCityGmlFile( CityDoctorModel model = CityGmlParser.parseCityGmlFile(
"src/test/resources/SimpleSolid_SrefBS_SchematronTest.gml", config.getParserConfiguration()); "src/test/resources/SimpleSolid_SrefBS_SchematronTest.gml", config.getParserConfiguration());
Checker checker = new Checker(config, model); Checker checker = new Checker(config, model);
checker.runChecks(); checker.runChecks();
for (Building b : model.getBuildings()) { for (Building b : model.getBuildings()) {
if (b.getGmlId().getGmlString().equals("_Simple_BD.1")) { if (b.getGmlId().getGmlString().equals("_Simple_BD.1")) {
assertTrue(b.containsAnyError()); assertTrue(b.containsAnyError());
} else { } else {
assertFalse(b.containsAnyError()); assertFalse(b.containsAnyError());
} }
} }
assertFalse(model.getGlobalErrors().isEmpty()); assertFalse(model.getGlobalErrors().isEmpty());
} }
@Test @Test
public void testChecker() throws CityGmlParseException, IOException, InvalidGmlFileException, CityDoctorWriteException { public void testChecker() throws CityGmlParseException, IOException, InvalidGmlFileException, CityDoctorWriteException {
File f = folder.newFile(); File f = folder.newFile();
File f2 = folder.newFile(); File f2 = folder.newFile();
try { try {
String[] args = new String[6]; String[] args = new String[6];
args[0] = "-in"; args[0] = "-in";
args[1] = "src/test/resources/QA-CS-CONCOMP.gml"; args[1] = "src/test/resources/QA-CS-CONCOMP.gml";
args[2] = "-xmlReport"; args[2] = "-xmlReport";
args[3] = f.getAbsolutePath(); args[3] = f.getAbsolutePath();
args[4] = "-pdfReport"; args[4] = "-pdfReport";
args[5] = f2.getAbsolutePath(); args[5] = f2.getAbsolutePath();
CityDoctorValidation.main(args); CityDoctorValidation.main(args);
assertTrue(f.exists()); assertTrue(f.exists());
assertTrue(f2.exists()); assertTrue(f2.exists());
} finally { } finally {
f.delete(); f.delete();
f2.delete(); f2.delete();
} }
} }
@Test @Test
public void testStreaming() throws CityGmlParseException, IOException, InvalidGmlFileException, CityDoctorWriteException { public void testStreaming() throws CityGmlParseException, IOException, InvalidGmlFileException, CityDoctorWriteException {
File f = folder.newFile(); File f = folder.newFile();
File f2 = folder.newFile(); File f2 = folder.newFile();
File f3 = folder.newFile(); File f3 = folder.newFile();
try { try {
String[] args = new String[10]; String[] args = new String[10];
args[0] = "-in"; args[0] = "-in";
args[1] = "src/test/resources/testarea.gml"; args[1] = "src/test/resources/testarea.gml";
args[2] = "-config"; args[2] = "-config";
args[3] = "src/test/resources/testConfigWithStreaming.yml"; args[3] = "src/test/resources/testConfigWithStreaming.yml";
args[4] = "-pdfReport"; args[4] = "-pdfReport";
args[5] = f.getAbsolutePath(); args[5] = f.getAbsolutePath();
args[6] = "-xmlReport"; args[6] = "-xmlReport";
args[7] = f2.getAbsolutePath(); args[7] = f2.getAbsolutePath();
args[8] = "-out"; args[8] = "-out";
args[9] = f3.getAbsolutePath(); args[9] = f3.getAbsolutePath();
CityDoctorValidation.main(args); CityDoctorValidation.main(args);
assertTrue(f.exists()); assertTrue(f.exists());
assertTrue(f2.exists()); assertTrue(f2.exists());
assertTrue(f3.exists()); assertTrue(f3.exists());
} finally { } finally {
f.delete(); f.delete();
f2.delete(); f2.delete();
f3.delete(); f3.delete();
} }
} }
@Test @Test
public void testZipEntryChecking() throws CityGmlParseException, IOException, InvalidGmlFileException, CityDoctorWriteException { public void testZipEntryChecking() throws CityGmlParseException, IOException, InvalidGmlFileException, CityDoctorWriteException {
CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zipArchive.zip"); CityGmlZipArchive cgmlArch = CityGmlZipArchive.register("src/test/resources/zipArchive.zip");
assertNotNull(cgmlArch); assertNotNull(cgmlArch);
cgmlArch.mountArchive(new ParserConfiguration(8,false)); cgmlArch.mountArchive(new ParserConfiguration(8, false));
ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig(); ValidationConfiguration config = ValidationConfiguration.loadStandardValidationConfig();
for (CityGmlZipEntry entry : cgmlArch.getEntries()){ for (CityGmlZipEntry entry : cgmlArch.getEntries()) {
Checker.streamCheck(entry, null, null, config, null ); Checker.streamCheck(entry, null, null, config, null);
} }
} }
} }
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