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