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
7a51e009
Commit
7a51e009
authored
Jan 26, 2026
by
Luna Riegel
Browse files
Fix: Add null checking to GenericAttribute extraction
parent
6e669d57
Changes
1
Hide whitespace changes
Inline
Side-by-side
CityDoctorParent/CityDoctorModel/src/main/java/de/hft/stuttgart/citydoctor2/datastructure/GenericAttribute.java
View file @
7a51e009
...
@@ -9,6 +9,8 @@ import java.io.Serial;
...
@@ -9,6 +9,8 @@ import java.io.Serial;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
import
java.util.StringJoiner
;
import
java.util.function.Supplier
;
public
class
GenericAttribute
implements
Serializable
{
public
class
GenericAttribute
implements
Serializable
{
...
@@ -17,6 +19,7 @@ public class GenericAttribute implements Serializable {
...
@@ -17,6 +19,7 @@ public class GenericAttribute implements Serializable {
private
static
final
long
serialVersionUID
=
-
4101408947632132328L
;
private
static
final
long
serialVersionUID
=
-
4101408947632132328L
;
private
static
final
Logger
logger
=
LogManager
.
getLogger
(
GenericAttribute
.
class
);
private
static
final
Logger
logger
=
LogManager
.
getLogger
(
GenericAttribute
.
class
);
private
static
final
String
NULL_VALUE_STRING
=
"NULL OR INVALID VALUE"
;
private
final
AbstractGenericAttributeProperty
original
;
private
final
AbstractGenericAttributeProperty
original
;
...
@@ -24,6 +27,7 @@ public class GenericAttribute implements Serializable {
...
@@ -24,6 +27,7 @@ public class GenericAttribute implements Serializable {
private
String
name
;
private
String
name
;
private
String
value
;
private
String
value
;
public
GenericAttribute
(
AbstractGenericAttributeProperty
attributeProperty
)
{
public
GenericAttribute
(
AbstractGenericAttributeProperty
attributeProperty
)
{
original
=
attributeProperty
;
original
=
attributeProperty
;
if
(
attributeProperty
.
getObject
()
==
null
)
{
if
(
attributeProperty
.
getObject
()
==
null
)
{
...
@@ -34,40 +38,42 @@ public class GenericAttribute implements Serializable {
...
@@ -34,40 +38,42 @@ public class GenericAttribute implements Serializable {
if
(
attributeProperty
.
getObject
()
instanceof
StringAttribute
sa
)
{
if
(
attributeProperty
.
getObject
()
instanceof
StringAttribute
sa
)
{
type
=
"StringAttribute"
;
type
=
"StringAttribute"
;
value
=
String
.
format
(
"\"%s\""
,
sa
.
getValue
());
value
=
extractValue
(()
->
String
.
format
(
"\"%s\""
,
sa
.
getValue
())
)
;
}
else
if
(
attributeProperty
.
getObject
()
instanceof
IntAttribute
ia
)
{
}
else
if
(
attributeProperty
.
getObject
()
instanceof
IntAttribute
ia
)
{
type
=
"IntAttribute"
;
type
=
"IntAttribute"
;
value
=
ia
.
getValue
().
toString
();
value
=
extractValue
(()
->
ia
.
getValue
().
toString
()
)
;
}
else
if
(
attributeProperty
.
getObject
()
instanceof
DoubleAttribute
da
)
{
}
else
if
(
attributeProperty
.
getObject
()
instanceof
DoubleAttribute
da
)
{
type
=
"DoubleAttribute"
;
type
=
"DoubleAttribute"
;
value
=
da
.
getValue
().
toString
();
value
=
extractValue
(()
->
da
.
getValue
().
toString
()
)
;
}
else
if
(
attributeProperty
.
getObject
()
instanceof
DateAttribute
date
)
{
}
else
if
(
attributeProperty
.
getObject
()
instanceof
DateAttribute
date
)
{
type
=
"DateAttribute"
;
type
=
"DateAttribute"
;
value
=
date
.
getValue
().
toString
();
value
=
extractValue
(()
->
date
.
getValue
().
toString
()
)
;
}
else
if
(
attributeProperty
.
getObject
()
instanceof
UriAttribute
ua
)
{
}
else
if
(
attributeProperty
.
getObject
()
instanceof
UriAttribute
ua
)
{
type
=
"UriAttribute"
;
type
=
"UriAttribute"
;
value
=
ua
.
getValue
(
);
value
=
extractValue
(
ua:
:
getValue
);
}
else
if
(
attributeProperty
.
getObject
()
instanceof
MeasureAttribute
ma
)
{
}
else
if
(
attributeProperty
.
getObject
()
instanceof
MeasureAttribute
ma
)
{
type
=
"MeasureAttribute"
;
type
=
"MeasureAttribute"
;
value
=
String
.
format
(
"%s %s"
,
ma
.
getValue
().
getValue
().
toString
(),
ma
.
getValue
().
getUom
());
value
=
extractValue
(()
->
String
.
format
(
"%s %s"
,
ma
.
getValue
().
getValue
().
toString
(),
ma
.
getValue
().
getUom
()));
}
else
if
(
attributeProperty
.
getObject
()
instanceof
CodeAttribute
ca
)
{
}
else
if
(
attributeProperty
.
getObject
()
instanceof
CodeAttribute
ca
)
{
type
=
String
.
format
(
"CodeAttribute (%s)"
,
ca
.
getValue
().
getLanguage
());
type
=
String
.
format
(
"CodeAttribute (%s)"
,
ca
.
getValue
().
getLanguage
());
value
=
String
.
format
(
"'''%s''' %n CodeSpace: %s"
,
ca
.
getValue
().
getValue
(),
ca
.
getValue
().
getCodeSpace
());
value
=
extractValue
(()
->
String
.
format
(
"'''%s''' %n CodeSpace: %s"
,
ca
.
getValue
().
getValue
(),
ca
.
getValue
().
getCodeSpace
()));
}
else
if
(
attributeProperty
.
getObject
()
instanceof
GenericAttributeSet
gas
)
{
}
else
if
(
attributeProperty
.
getObject
()
instanceof
GenericAttributeSet
gas
)
{
type
=
"GenericAttributeSet"
;
type
=
"GenericAttributeSet"
;
List
<
AbstractGenericAttributeProperty
>
attributes
=
gas
.
getValue
();
List
<
AbstractGenericAttributeProperty
>
attributes
=
gas
.
getValue
();
StringBuilder
sb
=
new
StringBuilder
();
if
(
attributes
==
null
||
attributes
.
isEmpty
()){
sb
.
append
(
"{"
);
value
=
NULL_VALUE_STRING
;
return
;
}
StringJoiner
sj
=
new
StringJoiner
(
"; "
,
"{"
,
"}"
);
sj
.
setEmptyValue
(
"EMPTY_SET"
);
for
(
AbstractGenericAttributeProperty
attribute
:
attributes
)
{
for
(
AbstractGenericAttributeProperty
attribute
:
attributes
)
{
if
(
attribute
.
getObject
()
!=
null
)
{
if
(
attribute
.
getObject
()
!=
null
)
{
sb
.
append
(
attribute
.
getObject
().
getName
());
sj
.
add
(
String
.
format
(
"%1$s = %2$s"
,
attribute
.
getObject
().
getName
(),
attribute
.
getObject
().
getValue
()));
sb
.
append
(
" = "
);
sb
.
append
(
attribute
.
getObject
().
getValue
());
sb
.
append
(
"; "
);
}
}
}
}
sb
.
replace
(
sb
.
length
()
-
1
,
sb
.
length
(),
"}"
);
value
=
sj
.
toString
();
value
=
String
.
format
(
"'%s'"
,
sb
);
}
else
{
}
else
{
logger
.
warn
(
"GenericAttribute {} is of unknown type {}"
,
attributeProperty
,
attributeProperty
.
getObject
());
logger
.
warn
(
"GenericAttribute {} is of unknown type {}"
,
attributeProperty
,
attributeProperty
.
getObject
());
...
@@ -77,6 +83,14 @@ public class GenericAttribute implements Serializable {
...
@@ -77,6 +83,14 @@ public class GenericAttribute implements Serializable {
}
}
private
String
extractValue
(
Supplier
<
String
>
supply
){
try
{
return
supply
.
get
();
}
catch
(
NullPointerException
e
){
return
NULL_VALUE_STRING
;
}
}
public
AbstractGenericAttributeProperty
getOriginal
()
{
public
AbstractGenericAttributeProperty
getOriginal
()
{
return
original
;
return
original
;
}
}
...
...
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