Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CityDoctor
CityDoctor2
Commits
a4e34abb
Commit
a4e34abb
authored
Feb 23, 2026
by
Luna Riegel
Browse files
Feat: Add parsing of args for db location and config
parent
30bade0a
Pipeline
#12344
passed with stage
in 2 minutes and 14 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/DatabaseSettings.java
View file @
a4e34abb
package
de.hft.stuttgart.citydoctor2.database
;
package
de.hft.stuttgart.citydoctor2.database
;
import
de.hft.stuttgart.citydoctor2.exceptions.EmbeddedDatabaseHandlerException
;
import
de.hft.stuttgart.citydoctor2.utils.Localization
;
import
de.hft.stuttgart.citydoctor2.utils.Localization
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
...
@@ -9,6 +10,7 @@ import java.io.File;
...
@@ -9,6 +10,7 @@ import java.io.File;
import
java.io.FileReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.nio.file.InvalidPathException
;
import
java.nio.file.InvalidPathException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.util.Properties
;
import
java.util.Properties
;
...
@@ -16,27 +18,47 @@ public final class DatabaseSettings {
...
@@ -16,27 +18,47 @@ public final class DatabaseSettings {
private
static
final
Logger
logger
=
LogManager
.
getLogger
(
DatabaseSettings
.
class
);
private
static
final
Logger
logger
=
LogManager
.
getLogger
(
DatabaseSettings
.
class
);
private
static
final
Properties
props
;
private
static
final
Properties
props
=
new
Properties
()
;
private
DatabaseSettings
()
{}
private
DatabaseSettings
()
{}
static
{
static
{
props
=
new
Properties
();
File
propFile
=
new
File
(
"DBSettings.properties"
);
File
propFile
=
new
File
(
"DBSettings.properties"
);
if
(
propFile
.
exists
())
{
if
(
propFile
.
exists
())
{
try
(
BufferedReader
bis
=
new
BufferedReader
(
new
FileReader
(
propFile
)))
{
loadPropertiesFromFile
(
propFile
);
props
.
load
(
bis
);
}
}
catch
(
IOException
e
)
{
}
logger
.
error
(
"Failed to load database settings"
,
e
);
}
public
static
void
loadPropertiesFromFile
(
File
file
)
throws
EmbeddedDatabaseHandlerException
{
try
(
BufferedReader
bis
=
new
BufferedReader
(
new
FileReader
(
file
)))
{
props
.
load
(
bis
);
}
catch
(
IOException
e
)
{
throw
new
EmbeddedDatabaseHandlerException
(
e
);
}
}
public
static
void
setDBLocation
(
String
dbLocation
)
throws
EmbeddedDatabaseHandlerException
{
Path
dbPath
=
Paths
.
get
(
dbLocation
).
toAbsolutePath
();
File
dbLocationFile
=
dbPath
.
toFile
();
if
(!
dbLocationFile
.
isFile
())
{
dbPath
=
dbPath
.
resolve
(
"cd_db"
);
}
Path
dbParentDirectoryPath
=
dbPath
.
getParent
();
if
(
dbParentDirectoryPath
.
toFile
().
mkdirs
()){
logger
.
trace
(
"Created parent directories for database location"
);
}
if
(!
dbParentDirectoryPath
.
toFile
().
canWrite
())
{
throw
new
EmbeddedDatabaseHandlerException
(
"Missing write permissions for database location:"
+
dbLocation
);
}
}
props
.
setProperty
(
"database.name"
,
dbPath
.
getFileName
().
toString
());
props
.
setProperty
(
"database.directory"
,
dbParentDirectoryPath
.
toAbsolutePath
().
toString
());
}
}
public
static
EmbeddedDatabaseConfiguration
getConfig
()
{
public
static
EmbeddedDatabaseConfiguration
getConfig
()
{
EmbeddedDatabaseConfiguration
defaultConfig
=
new
EmbeddedDatabaseConfiguration
();
EmbeddedDatabaseConfiguration
defaultConfig
=
new
EmbeddedDatabaseConfiguration
();
if
(
props
.
isEmpty
())
{
if
(
props
.
isEmpty
())
{
logger
.
debug
(
"No database settings found or specified, using default config"
);
logger
.
trace
(
"No database settings found or specified, using default config"
);
return
defaultConfig
;
return
defaultConfig
;
}
}
String
name
=
props
.
getProperty
(
"database.name"
);
String
name
=
props
.
getProperty
(
"database.name"
);
...
...
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/database/EmbeddedDatabaseConfiguration.java
View file @
a4e34abb
package
de.hft.stuttgart.citydoctor2.database
;
package
de.hft.stuttgart.citydoctor2.database
;
import
java.io.File
;
import
java.io.File
;
import
java.nio.file.Paths
;
import
java.util.StringJoiner
;
import
java.util.StringJoiner
;
/**
/**
...
@@ -51,7 +52,7 @@ public record EmbeddedDatabaseConfiguration(String databaseName, String database
...
@@ -51,7 +52,7 @@ public record EmbeddedDatabaseConfiguration(String databaseName, String database
}
}
public
String
getH2FileUrl
(){
public
String
getH2FileUrl
(){
return
wrapUrlWithH2JdbcDriver
(
databaseDirectory
+
databaseName
);
return
wrapUrlWithH2JdbcDriver
(
Paths
.
get
(
databaseDirectory
).
resolve
(
databaseName
)
.
toString
())
;
}
}
public
String
getH2ParametersSuffix
(){
public
String
getH2ParametersSuffix
(){
...
...
CityDoctorParent/CityDoctorModel/src/test/java/de/hft/stuttgart/citydoctor2/database/DatabaseSettingsTest.java
0 → 100644
View file @
a4e34abb
package
de.hft.stuttgart.citydoctor2.database
;
import
org.junit.jupiter.api.Test
;
public
class
DatabaseSettingsTest
{
public
void
testSetLocation
(){
String
tempdirectory
=
System
.
getProperty
(
"java.io.tmpdir"
);
DatabaseSettings
.
setDBLocation
(
tempdirectory
+
"/citydoctor"
);
}
}
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/CityDoctorValidation.java
View file @
a4e34abb
...
@@ -23,6 +23,7 @@ import java.io.FileNotFoundException;
...
@@ -23,6 +23,7 @@ import java.io.FileNotFoundException;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
import
de.hft.stuttgart.citydoctor2.database.DatabaseSettings
;
import
de.hft.stuttgart.citydoctor2.utils.Localization
;
import
de.hft.stuttgart.citydoctor2.utils.Localization
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.apache.logging.log4j.Logger
;
...
@@ -70,6 +71,8 @@ public class CityDoctorValidation {
...
@@ -70,6 +71,8 @@ public class CityDoctorValidation {
String
xmlOutput
=
getXmlOutput
(
argParser
);
String
xmlOutput
=
getXmlOutput
(
argParser
);
String
pdfOutput
=
getPdfOutput
(
argParser
);
String
pdfOutput
=
getPdfOutput
(
argParser
);
String
outputFile
=
getOutputFile
(
argParser
,
true
);
String
outputFile
=
getOutputFile
(
argParser
,
true
);
lookForDbConfigFileParameter
(
argParser
);
lookForDbLocationParameter
(
argParser
);
ValidationConfiguration
config
=
getValidationConfig
(
argParser
);
ValidationConfiguration
config
=
getValidationConfig
(
argParser
);
startValidationProcess
(
inputFile
,
xmlOutput
,
pdfOutput
,
config
,
outputFile
);
startValidationProcess
(
inputFile
,
xmlOutput
,
pdfOutput
,
config
,
outputFile
);
...
@@ -81,18 +84,42 @@ public class CityDoctorValidation {
...
@@ -81,18 +84,42 @@ public class CityDoctorValidation {
if
(
optional
)
{
if
(
optional
)
{
return
null
;
return
null
;
}
}
logger
.
error
(
Localization
.
getText
(
"CityDoctorValidation.noOutputFile"
));
logger
.
fatal
(
Localization
.
getText
(
"CityDoctorValidation.noOutputFile"
));
System
.
exit
(
11
);
System
.
exit
(
11
);
}
}
List
<
String
>
outFiles
=
argParser
.
getValues
(
"out"
);
List
<
String
>
outFiles
=
argParser
.
getValues
(
"out"
);
if
(
outFiles
.
size
()
!=
1
)
{
if
(
outFiles
.
size
()
!=
1
)
{
logger
.
error
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOneOutputFile"
));
logger
.
fatal
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOneOutputFile"
));
System
.
exit
(
12
);
System
.
exit
(
12
);
}
}
outputFile
=
outFiles
.
get
(
0
);
outputFile
=
outFiles
.
get
(
0
);
return
outputFile
;
return
outputFile
;
}
}
private
static
void
lookForDbConfigFileParameter
(
ArgumentParser
argParser
)
{
if
(!
argParser
.
containsOption
(
"db_config"
))
{
return
;
}
List
<
String
>
dbConfigFiles
=
argParser
.
getValues
(
"db_config"
);
if
(
dbConfigFiles
.
size
()
==
1
)
{
DatabaseSettings
.
loadPropertiesFromFile
(
new
File
(
dbConfigFiles
.
get
(
0
)));
}
else
if
(
dbConfigFiles
.
size
()
>
1
)
{
logger
.
warn
(
"More than one DB config file provided! Using standard config instead."
);
}
}
private
static
void
lookForDbLocationParameter
(
ArgumentParser
argParser
)
{
if
(!
argParser
.
containsOption
(
"db_location"
))
{
return
;
}
List
<
String
>
dbLocations
=
argParser
.
getValues
(
"db_location"
);
if
(
dbLocations
.
size
()
==
1
)
{
DatabaseSettings
.
setDBLocation
(
dbLocations
.
get
(
0
));
}
else
if
(
dbLocations
.
size
()
>
1
)
{
logger
.
warn
(
"More than one DB location provided! Using standard location instead."
);
}
}
/**
/**
* Validates the cityGML input file with a standard validation configuration.
* Validates the cityGML input file with a standard validation configuration.
*
*
...
@@ -202,7 +229,7 @@ public class CityDoctorValidation {
...
@@ -202,7 +229,7 @@ public class CityDoctorValidation {
if
(
argParser
.
containsOption
(
"pdfreport"
))
{
if
(
argParser
.
containsOption
(
"pdfreport"
))
{
List
<
String
>
reportFiles
=
argParser
.
getValues
(
"pdfreport"
);
List
<
String
>
reportFiles
=
argParser
.
getValues
(
"pdfreport"
);
if
(
reportFiles
.
size
()
!=
1
)
{
if
(
reportFiles
.
size
()
!=
1
)
{
logger
.
error
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOnePDFOutput"
));
logger
.
fatal
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOnePDFOutput"
));
System
.
exit
(
6
);
System
.
exit
(
6
);
}
}
return
reportFiles
.
get
(
0
);
return
reportFiles
.
get
(
0
);
...
@@ -214,7 +241,7 @@ public class CityDoctorValidation {
...
@@ -214,7 +241,7 @@ public class CityDoctorValidation {
if
(
argParser
.
containsOption
(
"xmlreport"
))
{
if
(
argParser
.
containsOption
(
"xmlreport"
))
{
List
<
String
>
reportFiles
=
argParser
.
getValues
(
"xmlreport"
);
List
<
String
>
reportFiles
=
argParser
.
getValues
(
"xmlreport"
);
if
(
reportFiles
.
size
()
!=
1
)
{
if
(
reportFiles
.
size
()
!=
1
)
{
logger
.
error
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOneXMLOutput"
));
logger
.
fatal
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOneXMLOutput"
));
System
.
exit
(
5
);
System
.
exit
(
5
);
}
}
return
reportFiles
.
get
(
0
);
return
reportFiles
.
get
(
0
);
...
@@ -231,7 +258,7 @@ public class CityDoctorValidation {
...
@@ -231,7 +258,7 @@ public class CityDoctorValidation {
if
(
argParser
.
containsOption
(
"config"
))
{
if
(
argParser
.
containsOption
(
"config"
))
{
List
<
String
>
configFiles
=
argParser
.
getValues
(
"config"
);
List
<
String
>
configFiles
=
argParser
.
getValues
(
"config"
);
if
(
configFiles
.
size
()
!=
1
)
{
if
(
configFiles
.
size
()
!=
1
)
{
logger
.
error
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOneConfigFile"
));
logger
.
fatal
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOneConfigFile"
));
System
.
exit
(
4
);
System
.
exit
(
4
);
}
}
return
ValidationConfiguration
.
loadValidationConfigFile
(
configFiles
.
get
(
0
));
return
ValidationConfiguration
.
loadValidationConfigFile
(
configFiles
.
get
(
0
));
...
@@ -240,7 +267,7 @@ public class CityDoctorValidation {
...
@@ -240,7 +267,7 @@ public class CityDoctorValidation {
logger
.
warn
(
Localization
.
getText
(
"CityDoctorValidation.loadingDefaultConfig"
));
logger
.
warn
(
Localization
.
getText
(
"CityDoctorValidation.loadingDefaultConfig"
));
return
ValidationConfiguration
.
loadStandardValidationConfig
();
return
ValidationConfiguration
.
loadStandardValidationConfig
();
}
else
{
}
else
{
logger
.
error
(
Localization
.
getText
(
"CityDoctorValidation.noConfig"
));
logger
.
fatal
(
Localization
.
getText
(
"CityDoctorValidation.noConfig"
));
System
.
exit
(
7
);
System
.
exit
(
7
);
return
null
;
return
null
;
}
}
...
@@ -252,7 +279,7 @@ public class CityDoctorValidation {
...
@@ -252,7 +279,7 @@ public class CityDoctorValidation {
if
(
argParser
.
containsOption
(
"out"
))
{
if
(
argParser
.
containsOption
(
"out"
))
{
List
<
String
>
outFiles
=
argParser
.
getValues
(
"out"
);
List
<
String
>
outFiles
=
argParser
.
getValues
(
"out"
);
if
(
outFiles
.
size
()
!=
1
)
{
if
(
outFiles
.
size
()
!=
1
)
{
logger
.
error
(
Localization
.
getText
(
"CityDoctorValidation.multipleOutputFiles"
));
logger
.
fatal
(
Localization
.
getText
(
"CityDoctorValidation.multipleOutputFiles"
));
System
.
exit
(
3
);
System
.
exit
(
3
);
}
}
return
outFiles
.
get
(
0
);
return
outFiles
.
get
(
0
);
...
@@ -271,12 +298,12 @@ public class CityDoctorValidation {
...
@@ -271,12 +298,12 @@ public class CityDoctorValidation {
if
(
optional
)
{
if
(
optional
)
{
return
null
;
return
null
;
}
}
logger
.
error
(
Localization
.
getText
(
"CityDoctorValidation.noInputFile"
));
logger
.
fatal
(
Localization
.
getText
(
"CityDoctorValidation.noInputFile"
));
System
.
exit
(
1
);
System
.
exit
(
1
);
}
}
List
<
String
>
inFiles
=
argParser
.
getValues
(
"in"
);
List
<
String
>
inFiles
=
argParser
.
getValues
(
"in"
);
if
(
inFiles
.
size
()
!=
1
)
{
if
(
inFiles
.
size
()
!=
1
)
{
logger
.
error
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOneInputFile"
));
logger
.
fatal
(
Localization
.
getText
(
"CityDoctorValidation.notExactlyOneInputFile"
));
System
.
exit
(
2
);
System
.
exit
(
2
);
}
}
inputFile
=
inFiles
.
get
(
0
);
inputFile
=
inFiles
.
get
(
0
);
...
...
CityDoctorParent/CityDoctorValidation/src/main/java/de/hft/stuttgart/citydoctor2/CityDoctorValidationCLI.java
View file @
a4e34abb
...
@@ -2,6 +2,7 @@ package de.hft.stuttgart.citydoctor2;
...
@@ -2,6 +2,7 @@ package de.hft.stuttgart.citydoctor2;
import
de.hft.stuttgart.citydoctor2.check.ValidationConfiguration
;
import
de.hft.stuttgart.citydoctor2.check.ValidationConfiguration
;
import
de.hft.stuttgart.citydoctor2.database.DatabaseSettings
;
import
de.hft.stuttgart.citydoctor2.exceptions.CityDoctorWriteException
;
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.InvalidGmlFileException
;
import
de.hft.stuttgart.citydoctor2.parser.InvalidGmlFileException
;
...
@@ -26,20 +27,30 @@ public class CityDoctorValidationCLI implements Runnable {
...
@@ -26,20 +27,30 @@ public class CityDoctorValidationCLI implements Runnable {
private
File
config
;
private
File
config
;
@Option
(
names
=
{
"-x"
,
"--xml"
,
"--xmlReport"
},
@Option
(
names
=
{
"-x"
,
"--xml"
,
"--xmlReport"
},
description
=
"Create a XML validation report at target location"
,
description
=
"Create
s
a XML validation report at target location"
,
defaultValue
=
Option
.
NULL_VALUE
)
defaultValue
=
Option
.
NULL_VALUE
)
private
String
xmlReport
;
private
String
xmlReport
;
@Option
(
names
=
{
"-p"
,
"--pdf"
,
"--pdfReport"
},
@Option
(
names
=
{
"-p"
,
"--pdf"
,
"--pdfReport"
},
description
=
"Create a PDF validation report at target location"
,
description
=
"Create
s
a PDF validation report at target location"
,
defaultValue
=
Option
.
NULL_VALUE
)
defaultValue
=
Option
.
NULL_VALUE
)
private
String
pdfReport
;
private
String
pdfReport
;
@Option
(
names
=
{
"-o"
,
"--out"
,
"--output"
},
@Option
(
names
=
{
"-o"
,
"--out"
,
"--output"
},
description
=
"Create a validated copy of the CityGML input with QualityADE at target location."
,
description
=
"Create
s
a validated copy of the CityGML input with QualityADE at target location."
,
defaultValue
=
Option
.
NULL_VALUE
)
defaultValue
=
Option
.
NULL_VALUE
)
private
String
output
;
private
String
output
;
@Option
(
names
=
{
"--db_location"
,
"--db_loc"
},
description
=
"Creates the embedded database file at target location instead of CityDoctor's working directory."
,
defaultValue
=
Option
.
NULL_VALUE
)
private
String
dbLocation
;
@Option
(
names
=
{
"-db"
,
"--db_config"
,
"--db_settings"
},
description
=
"Filepath to a .properties file for overriding the default configuration of the embedded database"
,
defaultValue
=
Option
.
NULL_VALUE
)
private
String
dbConfig
;
@Override
@Override
public
void
run
(){
public
void
run
(){
try
{
try
{
...
@@ -49,6 +60,12 @@ public class CityDoctorValidationCLI implements Runnable {
...
@@ -49,6 +60,12 @@ public class CityDoctorValidationCLI implements Runnable {
}
else
{
}
else
{
valConfig
=
ValidationConfiguration
.
loadValidationConfigFile
(
config
.
getAbsolutePath
());
valConfig
=
ValidationConfiguration
.
loadValidationConfigFile
(
config
.
getAbsolutePath
());
}
}
if
(
dbConfig
!=
null
){
DatabaseSettings
.
loadPropertiesFromFile
(
new
File
(
dbConfig
));
}
if
(
dbLocation
!=
null
)
{
DatabaseSettings
.
setDBLocation
(
dbLocation
);
}
CityDoctorValidation
.
startValidationProcess
(
input
,
xmlReport
,
pdfReport
,
valConfig
,
output
);
CityDoctorValidation
.
startValidationProcess
(
input
,
xmlReport
,
pdfReport
,
valConfig
,
output
);
}
catch
(
CityDoctorWriteException
|
CityGmlParseException
|
IOException
|
InvalidGmlFileException
e
)
{
}
catch
(
CityDoctorWriteException
|
CityGmlParseException
|
IOException
|
InvalidGmlFileException
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
...
...
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