Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
97f1a582
Commit
97f1a582
authored
3 months ago
by
Riegel
Browse files
Options
Download
Email Patches
Plain Diff
Feat: Add support for zip-file validation to CLI
parent
c44bc917
Pipeline
#10590
passed with stage
in 2 minutes and 44 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/utils/ArchivePacker.java
+14
-0
...ava/de/hft/stuttgart/citydoctor2/utils/ArchivePacker.java
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/CityDoctorValidation.java
+43
-3
...va/de/hft/stuttgart/citydoctor2/CityDoctorValidation.java
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/Checker.java
+13
-5
...main/java/de/hft/stuttgart/citydoctor2/check/Checker.java
CityDoctorParent/CityDoctorValidation/src/test/java/de/hft/stuttgart/citydoctor2/check/CheckerTest.java
+16
-6
.../java/de/hft/stuttgart/citydoctor2/check/CheckerTest.java
with
86 additions
and
14 deletions
+86
-14
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/utils/ArchivePacker.java
+
14
-
0
View file @
97f1a582
...
@@ -80,4 +80,18 @@ public class ArchivePacker {
...
@@ -80,4 +80,18 @@ public class ArchivePacker {
}
}
}
}
public
static
void
packAndDeleteDirectory
(
String
directoryPath
)
throws
IOException
{
Path
path
=
Path
.
of
(
directoryPath
);
if
(!
path
.
toFile
().
exists
())
{
throw
new
IllegalStateException
(
"Directory "
+
directoryPath
+
" does not exist"
);
}
if
(!
path
.
toFile
().
isDirectory
())
{
throw
new
IllegalStateException
(
"Path "
+
directoryPath
+
" is not a directory"
);
}
String
outputPath
=
path
.
getParent
().
resolve
(
path
.
getFileName
()
+
".zip"
).
toString
();
zipDirectory
(
outputPath
,
directoryPath
);
FileUtils
.
deleteDirectory
(
path
.
toFile
());
}
}
}
This diff is collapsed.
Click to expand it.
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/CityDoctorValidation.java
+
43
-
3
View file @
97f1a582
...
@@ -21,8 +21,10 @@ package de.hft.stuttgart.citydoctor2;
...
@@ -21,8 +21,10 @@ package de.hft.stuttgart.citydoctor2;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.file.Path
;
import
java.util.List
;
import
java.util.List
;
import
de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive
;
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
org.citygml4j.core.ade.ADEException
;
import
org.citygml4j.core.ade.ADEException
;
...
@@ -72,7 +74,7 @@ public class CityDoctorValidation {
...
@@ -72,7 +74,7 @@ public class CityDoctorValidation {
String
outputFile
=
getOutputFile
(
argParser
,
true
);
String
outputFile
=
getOutputFile
(
argParser
,
true
);
ValidationConfiguration
config
=
getValidationConfig
(
argParser
);
ValidationConfiguration
config
=
getValidationConfig
(
argParser
);
startValidationProcess
(
new
File
(
inputFile
)
,
xmlOutput
,
pdfOutput
,
config
,
outputFile
);
startValidationProcess
(
inputFile
,
xmlOutput
,
pdfOutput
,
config
,
outputFile
);
}
}
private
static
String
getOutputFile
(
ArgumentParser
argParser
,
boolean
optional
)
{
private
static
String
getOutputFile
(
ArgumentParser
argParser
,
boolean
optional
)
{
...
@@ -144,13 +146,28 @@ public class CityDoctorValidation {
...
@@ -144,13 +146,28 @@ public class CityDoctorValidation {
pdfOutputPath
=
pdfOutput
.
getAbsolutePath
();
pdfOutputPath
=
pdfOutput
.
getAbsolutePath
();
}
}
try
{
try
{
startValidation
Process
(
inputFile
,
xmlOutputPath
,
pdfOutputPath
,
config
,
null
);
start
File
Validation
(
inputFile
,
xmlOutputPath
,
pdfOutputPath
,
config
,
null
);
}
catch
(
CityDoctorWriteException
e
)
{
}
catch
(
CityDoctorWriteException
e
)
{
// this does not happen as no output file is specified
// this does not happen as no output file is specified
logger
.
catching
(
e
);
logger
.
catching
(
e
);
}
}
}
}
public
static
void
startValidationProcess
(
String
input
,
String
xmlOutput
,
String
pdfOutput
,
ValidationConfiguration
config
,
String
outputFile
)
throws
CityDoctorWriteException
,
CityGmlParseException
,
IOException
,
InvalidGmlFileException
{
File
inputFile
=
new
File
(
input
);
if
(!
inputFile
.
exists
())
{
logger
.
error
(
"Input file '{}' does not exist."
,
input
);
System
.
exit
(
1
);
}
if
(
inputFile
.
getName
().
endsWith
(
".gml"
))
{
startFileValidation
(
inputFile
,
xmlOutput
,
pdfOutput
,
config
,
outputFile
);
}
else
if
(
inputFile
.
getName
().
endsWith
(
".zip"
))
{
startZipValidation
(
input
,
xmlOutput
,
pdfOutput
,
config
,
outputFile
);
}
}
/**
/**
* This function will handle the complete validation process
* This function will handle the complete validation process
*
*
...
@@ -164,7 +181,7 @@ public class CityDoctorValidation {
...
@@ -164,7 +181,7 @@ public class CityDoctorValidation {
* @throws CityGMLBuilderException
* @throws CityGMLBuilderException
* @throws ADEException
* @throws ADEException
*/
*/
public
static
void
startValidation
Process
(
File
inputFile
,
String
xmlOutput
,
String
pdfOutput
,
public
static
void
start
File
Validation
(
File
inputFile
,
String
xmlOutput
,
String
pdfOutput
,
ValidationConfiguration
config
,
String
outputFile
)
throws
IOException
,
CityGmlParseException
,
ValidationConfiguration
config
,
String
outputFile
)
throws
IOException
,
CityGmlParseException
,
InvalidGmlFileException
,
CityDoctorWriteException
{
InvalidGmlFileException
,
CityDoctorWriteException
{
...
@@ -181,6 +198,29 @@ public class CityDoctorValidation {
...
@@ -181,6 +198,29 @@ public class CityDoctorValidation {
}
}
}
}
public
static
void
startZipValidation
(
String
inputZipFile
,
String
xmlOutput
,
String
pdfOutput
,
ValidationConfiguration
config
,
String
outputFile
)
throws
CityGmlParseException
,
IOException
{
xmlOutput
=
toDirectoryPath
(
xmlOutput
);
pdfOutput
=
toDirectoryPath
(
pdfOutput
);
outputFile
=
toDirectoryPath
(
outputFile
);
if
(
xmlOutput
==
null
&&
pdfOutput
==
null
&&
outputFile
==
null
)
{
logger
.
warn
(
"No output locations specified, results of validation will not be saved"
);
}
CityGmlZipArchive
archive
=
CityGmlZipArchive
.
register
(
inputZipFile
);
Checker
.
streamCheck
(
archive
,
xmlOutput
,
pdfOutput
,
config
,
outputFile
);
}
public
static
String
toDirectoryPath
(
String
input
)
{
if
(
input
==
null
)
{
return
null
;
}
String
parentDirectory
=
Path
.
of
(
input
).
getParent
().
toString
()
+
File
.
separator
;
String
name
=
Path
.
of
(
input
).
getFileName
().
toString
().
replaceFirst
(
"\\..+"
,
""
)
+
File
.
separator
;
File
f
=
new
File
(
parentDirectory
+
name
);
f
.
mkdir
();
return
f
.
getPath
()
+
File
.
separator
;
}
public
static
String
getPdfOutput
(
ArgumentParser
argParser
)
{
public
static
String
getPdfOutput
(
ArgumentParser
argParser
)
{
if
(
argParser
.
containsOption
(
"pdfreport"
))
{
if
(
argParser
.
containsOption
(
"pdfreport"
))
{
List
<
String
>
reportFiles
=
argParser
.
getValues
(
"pdfreport"
);
List
<
String
>
reportFiles
=
argParser
.
getValues
(
"pdfreport"
);
...
...
This diff is collapsed.
Click to expand it.
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/check/Checker.java
+
13
-
5
View file @
97f1a582
...
@@ -42,6 +42,7 @@ import de.hft.stuttgart.citydoctor2.reporting.XmlStreamReporter;
...
@@ -42,6 +42,7 @@ import de.hft.stuttgart.citydoctor2.reporting.XmlStreamReporter;
import
de.hft.stuttgart.citydoctor2.reporting.XmlValidationReporter
;
import
de.hft.stuttgart.citydoctor2.reporting.XmlValidationReporter
;
import
de.hft.stuttgart.citydoctor2.reporting.pdf.PdfReporter
;
import
de.hft.stuttgart.citydoctor2.reporting.pdf.PdfReporter
;
import
de.hft.stuttgart.citydoctor2.reporting.pdf.PdfStreamReporter
;
import
de.hft.stuttgart.citydoctor2.reporting.pdf.PdfStreamReporter
;
import
de.hft.stuttgart.citydoctor2.utils.ArchivePacker
;
import
de.hft.stuttgart.citydoctor2.utils.Localization
;
import
de.hft.stuttgart.citydoctor2.utils.Localization
;
import
de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive
;
import
de.hft.stuttgart.citydoctor2.zip.CityGmlZipArchive
;
import
de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry
;
import
de.hft.stuttgart.citydoctor2.zip.CityGmlZipEntry
;
...
@@ -740,17 +741,24 @@ public class Checker {
...
@@ -740,17 +741,24 @@ public class Checker {
return
hasUnusedDependency
;
return
hasUnusedDependency
;
}
}
public
static
void
streamCheck
(
CityGmlZipArchive
archive
,
String
xml
Output
,
String
pdf
Output
,
ValidationConfiguration
config
,
public
static
void
streamCheck
(
CityGmlZipArchive
archive
,
String
xml
Directory
,
String
pdf
Directory
,
ValidationConfiguration
config
,
String
output
File
)
throws
IOException
,
CityGmlParseException
{
String
output
Directory
)
throws
IOException
,
CityGmlParseException
{
streamCheck
(
archive
,
xml
Output
,
pdfOutput
,
config
,
null
,
output
File
);
streamCheck
(
archive
,
xml
Directory
,
pdfDirectory
,
config
,
null
,
output
Directory
);
}
}
public
static
void
streamCheck
(
CityGmlZipArchive
archive
,
String
xmlOutput
,
String
pdfOutput
,
ValidationConfiguration
config
,
public
static
void
streamCheck
(
CityGmlZipArchive
archive
,
String
xmlDirectory
,
String
pdfDirectory
,
ValidationConfiguration
config
,
FeatureCheckedListener
l
,
String
outputFile
)
throws
IOException
,
CityGmlParseException
{
FeatureCheckedListener
l
,
String
outputDirectory
)
throws
IOException
,
CityGmlParseException
{
for
(
CityGmlZipEntry
entry
:
archive
.
getEntries
())
{
for
(
CityGmlZipEntry
entry
:
archive
.
getEntries
())
{
String
xmlOutput
=
xmlDirectory
==
null
?
null
:
xmlDirectory
+
entry
.
getFileName
().
replaceFirst
(
"\\..+"
,
".xml"
);
String
pdfOutput
=
pdfDirectory
==
null
?
null
:
pdfDirectory
+
entry
.
getFileName
().
replaceFirst
(
"\\..+"
,
".pdf"
);
String
outputFile
=
outputDirectory
==
null
?
null
:
outputDirectory
+
entry
.
getFileName
();
streamCheck
(
entry
,
xmlOutput
,
pdfOutput
,
config
,
l
,
outputFile
);
streamCheck
(
entry
,
xmlOutput
,
pdfOutput
,
config
,
l
,
outputFile
);
}
}
if
(
outputDirectory
!=
null
)
{
ArchivePacker
.
packAndDeleteDirectory
(
outputDirectory
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
CityDoctorParent/CityDoctorValidation/src/test/java/de/hft/stuttgart/citydoctor2/check/CheckerTest.java
+
16
-
6
View file @
97f1a582
...
@@ -35,10 +35,11 @@ import org.junit.rules.TemporaryFolder;
...
@@ -35,10 +35,11 @@ import org.junit.rules.TemporaryFolder;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
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
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
/**
...
@@ -120,8 +121,8 @@ public class CheckerTest {
...
@@ -120,8 +121,8 @@ public class CheckerTest {
@Test
@Test
public
void
testCliZipChecking
()
throws
IOException
,
CityDoctorWriteException
,
CityGmlParseException
,
InvalidGmlFileException
{
public
void
testCliZipChecking
()
throws
IOException
,
CityDoctorWriteException
,
CityGmlParseException
,
InvalidGmlFileException
{
File
f
=
folder
.
newFile
(
"out.zip"
)
;
String
output
=
folder
.
getRoot
().
toPath
()
+
File
.
separator
+
"test"
;
Files
.
probeContentType
(
f
.
toPath
());
try
{
try
{
String
[]
args
=
new
String
[
6
];
String
[]
args
=
new
String
[
6
];
args
[
0
]
=
"-in"
;
args
[
0
]
=
"-in"
;
...
@@ -129,12 +130,21 @@ public class CheckerTest {
...
@@ -129,12 +130,21 @@ public class CheckerTest {
args
[
2
]
=
"-config"
;
args
[
2
]
=
"-config"
;
args
[
3
]
=
"src/test/resources/testConfigWithStreaming.yml"
;
args
[
3
]
=
"src/test/resources/testConfigWithStreaming.yml"
;
args
[
4
]
=
"-out"
;
args
[
4
]
=
"-out"
;
args
[
5
]
=
f
.
getAbsolutePath
()
;
args
[
5
]
=
output
+
File
.
separator
;
CityDoctorValidation
.
main
(
args
);
CityDoctorValidation
.
main
(
args
);
File
f
=
new
File
(
output
+
".zip"
);
assertTrue
(
f
.
exists
());
assertTrue
(
f
.
exists
());
CityGmlZipArchive
cgmlArch
=
CityGmlZipArchive
.
register
(
output
+
".zip"
);
assertNotNull
(
cgmlArch
);
cgmlArch
.
mountArchive
(
new
ParserConfiguration
(
8
,
false
));
assertEquals
(
5
,
cgmlArch
.
getEntries
().
size
());
for
(
CityGmlZipEntry
entry
:
cgmlArch
.
getEntries
())
{
assertNotNull
(
entry
);
assertNull
(
entry
.
getErrorType
());
}
}
finally
{
}
catch
(
CityGmlParseException
|
IOException
|
InvalidGmlFileException
|
CityDoctorWriteException
e
)
{
f
.
delete
()
;
throw
e
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets