Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
Storage
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSDU
OSDU Data Platform
System
Storage
Commits
3b4b749f
Commit
3b4b749f
authored
2 years ago
by
Yauheni Lesnikau
Browse files
Options
Downloads
Patches
Plain Diff
fix CrsConversionService potential class cast issues
parent
5fd4fa47
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!513
fix CrsConversionService potential class cast issues
Pipeline
#138390
failed
2 years ago
Stage: review
Stage: build
Stage: coverage
Stage: containerize
Stage: scan
Stage: deploy
Stage: integration
Changes
2
Pipelines
7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
NOTICE
+2
-2
2 additions, 2 deletions
NOTICE
storage-core/src/main/java/org/opengroup/osdu/storage/conversion/CrsConversionService.java
+45
-32
45 additions, 32 deletions
...engroup/osdu/storage/conversion/CrsConversionService.java
with
47 additions
and
34 deletions
NOTICE
+
2
−
2
View file @
3b4b749f
...
...
@@ -393,7 +393,7 @@ The following software have components provided under the terms of this license:
- Jackson datatype: jdk8 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jdk8)
- Jackson module: Afterburner (from http://wiki.fasterxml.com/JacksonHome, https://github.com/FasterXML/jackson-modules-base)
- Jackson module: JAXB Annotations (from http://github.com/FasterXML/jackson-module-jaxb-annotations, http://wiki.fasterxml.com/JacksonJAXBAnnotations, https://github.com/FasterXML/jackson-modules-base)
- Jackson-annotations (from http://github.com/FasterXML/jackson, http://wiki.fasterxml.com/JacksonHome)
- Jackson-annotations (from http://github.com/FasterXML/jackson, http://wiki.fasterxml.com/JacksonHome
, https://github.com/FasterXML/jackson
)
- Jackson-core (from http://wiki.fasterxml.com/JacksonHome, https://github.com/FasterXML/jackson-core)
- Jackson-dataformat-XML (from http://wiki.fasterxml.com/JacksonExtensionXmlDataBinding, https://github.com/FasterXML/jackson-dataformat-xml)
- Jackson-dataformat-YAML (from http://wiki.fasterxml.com/JacksonExtensionYAML, https://github.com/FasterXML/jackson, https://github.com/FasterXML/jackson-dataformats-text)
...
...
@@ -538,7 +538,7 @@ The following software have components provided under the terms of this license:
- io.grpc:grpc-protobuf-lite (from https://github.com/grpc/grpc-java)
- io.grpc:grpc-stub (from https://github.com/grpc/grpc-java)
- ion-java (from https://github.com/amzn/ion-java/, https://github.com/amznlabs/ion-java/)
- jackson-databind (from http://github.com/FasterXML/jackson, http://wiki.fasterxml.com/JacksonHome)
- jackson-databind (from http://github.com/FasterXML/jackson, http://wiki.fasterxml.com/JacksonHome
, https://github.com/FasterXML/jackson
)
- java-cloudant (from https://cloudant.com)
- javatuples (from http://www.javatuples.org)
- javax.annotation-api (from http://jcp.org/en/jsr/detail?id=250)
...
...
This diff is collapsed.
Click to expand it.
storage-core/src/main/java/org/opengroup/osdu/storage/conversion/CrsConversionService.java
+
45
−
32
View file @
3b4b749f
...
...
@@ -34,6 +34,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.opengroup.osdu.core.common.model.http.DpsHeaders
;
import
org.opengroup.osdu.core.common.model.storage.ConversionStatus
;
import
org.opengroup.osdu.storage.di.SpringConfig
;
import
static
org
.
opengroup
.
osdu
.
core
.
common
.
Constants
.*;
import
static
org
.
opengroup
.
osdu
.
core
.
common
.
crs
.
CrsConversionServiceErrorMessages
.
MISSING_GEOMETRIES
;
import
static
org
.
opengroup
.
osdu
.
core
.
common
.
util
.
JsonUtils
.
jsonElementToString
;
@Service
...
...
@@ -139,18 +142,18 @@ public class CrsConversionService {
Iterator
<
String
>
keys
=
filteredObjects
.
keySet
().
iterator
();
while
(
keys
.
hasNext
())
{
String
attributeName
=
keys
.
next
();
JsonObject
asIngestedCoordinates
=
filteredObjects
.
getAsJsonObject
(
attributeName
).
getAsJsonObject
(
Constants
.
AS_INGESTED_COORDINATES
);
JsonObject
asIngestedCoordinates
=
filteredObjects
.
getAsJsonObject
(
attributeName
).
getAsJsonObject
(
AS_INGESTED_COORDINATES
);
if
(
asIngestedCoordinates
!=
null
)
{
GeoJsonFeatureCollection
fc
=
new
GeoJsonFeatureCollection
();
if
(
asIngestedCoordinates
.
has
(
Constants
.
TYPE
)
&&
(!
asIngestedCoordinates
.
get
(
Constants
.
TYPE
).
isJsonNull
()
))
fc
.
setType
(
asIngestedCoordinates
.
get
(
Constants
.
TYPE
).
getAsString
());
if
(
asIngestedCoordinates
.
has
(
Constants
.
PROPERTIES
)
&&
(!
asIngestedCoordinates
.
get
(
Constants
.
PROPERTIES
).
isJsonNull
()
))
fc
.
setProperties
(
asIngestedCoordinates
.
getAsJsonObject
(
Constants
.
PROPERTIES
));
if
(
asIngestedCoordinates
.
has
(
Constants
.
PERSISTABLE_REFERENCE_CRS
)
&&
(!
asIngestedCoordinates
.
get
(
Constants
.
PERSISTABLE_REFERENCE_CRS
)
.
isJsonNull
())
)
fc
.
setPersistableReferenceCrs
(
asIngestedCoordinates
.
get
(
Constants
.
PERSISTABLE_REFERENCE_CRS
).
getAsString
());
if
(
asIngestedCoordinates
.
has
(
Constants
.
COORDINATE_REFERENCE_SYSTEM_ID
)
&&
(!
asIngestedCoordinates
.
get
(
Constants
.
COORDINATE_REFERENCE_SYSTEM_ID
)
.
isJsonNull
())
)
fc
.
setCoordinateReferenceSystemID
(
asIngestedCoordinates
.
get
(
Constants
.
COORDINATE_REFERENCE_SYSTEM_ID
).
getAsString
());
if
(
asIngestedCoordinates
.
has
(
Constants
.
VERTICAL_UNIT_ID
)
&&
(!
asIngestedCoordinates
.
get
(
Constants
.
VERTICAL_UNIT_ID
)
.
isJsonNull
())
)
fc
.
setVerticalUnitID
(
asIngestedCoordinates
.
get
(
Constants
.
VERTICAL_UNIT_ID
).
getAsString
());
if
(
asIngestedCoordinates
.
has
(
Constants
.
PERSISTABLE_REFERENCE_UNIT_Z
)
&&
(!
asIngestedCoordinates
.
get
(
Constants
.
PERSISTABLE_REFERENCE_UNIT_Z
)
.
isJsonNull
())
)
fc
.
setPersistableReferenceUnitZ
(
asIngestedCoordinates
.
get
(
Constants
.
PERSISTABLE_REFERENCE_UNIT_Z
).
getAsString
());
if
(
asIngestedCoordinates
.
has
(
Constants
.
BBOX
)
&&
(!
asIngestedCoordinates
.
get
(
Constants
.
BBOX
).
isJsonNull
()
))
fc
.
setBbox
(
this
.
bboxValues
(
asIngestedCoordinates
.
getAsJsonArray
(
Constants
.
BBOX
)));
JsonArray
featuresArray
=
(
asIngestedCoordinates
.
has
(
Constants
.
FEATURES
)
&&
(!
asIngestedCoordinates
.
get
(
Constants
.
FEATURES
).
isJsonNull
())
)
?
asIngestedCoordinates
.
getAsJsonArray
(
Constants
.
FEATURES
)
:
null
;
if
(
isJsonObjectNotNull
(
asIngestedCoordinates
,
TYPE
))
fc
.
setType
(
asIngestedCoordinates
.
get
(
TYPE
).
getAsString
());
if
(
isJsonObjectNotNull
(
asIngestedCoordinates
,
PROPERTIES
)
&&
isPropertyJsonObject
(
asIngestedCoordinates
,
PROPERTIES
))
fc
.
setProperties
(
asIngestedCoordinates
.
getAsJsonObject
(
PROPERTIES
));
if
(
isJsonObjectNotNull
(
asIngestedCoordinates
,
PERSISTABLE_REFERENCE_CRS
))
fc
.
setPersistableReferenceCrs
(
asIngestedCoordinates
.
get
(
PERSISTABLE_REFERENCE_CRS
).
getAsString
());
if
(
isJsonObjectNotNull
(
asIngestedCoordinates
,
COORDINATE_REFERENCE_SYSTEM_ID
))
fc
.
setCoordinateReferenceSystemID
(
asIngestedCoordinates
.
get
(
COORDINATE_REFERENCE_SYSTEM_ID
).
getAsString
());
if
(
isJsonObjectNotNull
(
asIngestedCoordinates
,
VERTICAL_UNIT_ID
))
fc
.
setVerticalUnitID
(
asIngestedCoordinates
.
get
(
VERTICAL_UNIT_ID
).
getAsString
());
if
(
isJsonObjectNotNull
(
asIngestedCoordinates
,
PERSISTABLE_REFERENCE_UNIT_Z
))
fc
.
setPersistableReferenceUnitZ
(
asIngestedCoordinates
.
get
(
PERSISTABLE_REFERENCE_UNIT_Z
).
getAsString
());
if
(
isJsonObjectNotNull
(
asIngestedCoordinates
,
BBOX
)
&&
isPropertyJsonArray
(
asIngestedCoordinates
,
BBOX
))
fc
.
setBbox
(
this
.
bboxValues
(
asIngestedCoordinates
.
getAsJsonArray
(
BBOX
)));
JsonArray
featuresArray
=
isJsonObjectNotNull
(
asIngestedCoordinates
,
FEATURES
)
&&
isPropertyJsonArray
(
asIngestedCoordinates
,
FEATURES
)
?
asIngestedCoordinates
.
getAsJsonArray
(
FEATURES
)
:
null
;
if
(
featuresArray
==
null
||
featuresArray
.
size
()
==
0
)
{
statusBuilder
.
addError
(
CrsConversionServiceErrorMessages
.
MISSING_FEATURES
);
continue
;
...
...
@@ -617,39 +620,39 @@ public class CrsConversionService {
private
GeoJsonFeature
getFeature
(
JsonObject
featureItem
,
ConversionStatus
.
ConversionStatusBuilder
statusBuilder
)
{
GeoJsonFeature
feature
=
new
GeoJsonFeature
();
if
(
featureItem
.
has
(
Constants
.
TYPE
)
&&
(!
featureItem
.
get
(
Constants
.
TYPE
).
isJsonNull
()
))
feature
.
setType
(
featureItem
.
get
(
Constants
.
TYPE
).
getAsString
());
if
(
featureItem
.
has
(
Constants
.
PROPERTIES
)
&&
(!
featureItem
.
get
(
Constants
.
PROPERTIES
).
isJsonNull
()))
feature
.
setProperties
(
featureItem
.
getAsJsonObject
(
Constants
.
PROPERTIES
));
if
(
featureItem
.
has
(
Constants
.
BBOX
)
&&
(!
featureItem
.
get
(
Constants
.
BBOX
).
isJsonNull
()
))
feature
.
setBbox
(
this
.
bboxValues
(
featureItem
.
getAsJsonArray
(
Constants
.
BBOX
)));
if
(
isJsonObjectNotNull
(
featureItem
,
TYPE
))
feature
.
setType
(
featureItem
.
get
(
TYPE
).
getAsString
());
if
(
isJsonObjectNotNull
(
featureItem
,
PROPERTIES
)
&&
isPropertyJsonObject
(
featureItem
,
PROPERTIES
))
feature
.
setProperties
(
featureItem
.
getAsJsonObject
(
PROPERTIES
));
if
(
isJsonObjectNotNull
(
featureItem
,
BBOX
)
&&
isPropertyJsonArray
(
featureItem
,
BBOX
))
feature
.
setBbox
(
this
.
bboxValues
(
featureItem
.
getAsJsonArray
(
BBOX
)));
if
(
featureItem
.
has
(
Constants
.
GEOMETRY
)
&&
(!
featureItem
.
get
(
Constants
.
GEOMETRY
).
isJsonNull
()
))
{
JsonObject
geometry
=
featureItem
.
getAsJsonObject
(
Constants
.
GEOMETRY
);
String
geometryType
=
(
geometry
.
has
(
Constants
.
TYPE
)
&&
(!
geometry
.
get
(
Constants
.
TYPE
).
isJsonNull
())
)
?
geometry
.
get
(
Constants
.
TYPE
).
getAsString
()
:
""
;
if
(
isJsonObjectNotNull
(
featureItem
,
GEOMETRY
)
&&
isPropertyJsonObject
(
featureItem
,
GEOMETRY
))
{
JsonObject
geometry
=
featureItem
.
getAsJsonObject
(
GEOMETRY
);
String
geometryType
=
isJsonObjectNotNull
(
geometry
,
TYPE
)
?
geometry
.
get
(
TYPE
).
getAsString
()
:
""
;
if
(
geometryType
.
equals
(
Constants
.
ANY_CRS_GEOMETRY_COLLECTION
))
{
JsonArray
geometriesArray
=
(
geometry
.
has
(
Constants
.
GEOMETRIES
)
&&
(!
geometry
.
get
(
Constants
.
GEOMETRIES
).
isJsonNull
())
)
?
geometry
.
get
(
Constants
.
GEOMETRIES
).
getAsJsonArray
()
:
new
JsonArray
();
if
(
geometryType
.
equals
(
ANY_CRS_GEOMETRY_COLLECTION
))
{
JsonArray
geometriesArray
=
isJsonObjectNotNull
(
geometry
,
GEOMETRIES
)
&&
isPropertyJsonArray
(
geometry
,
GEOMETRIES
)
?
geometry
.
get
(
GEOMETRIES
).
getAsJsonArray
()
:
new
JsonArray
();
if
(
geometriesArray
==
null
||
geometriesArray
.
size
()
==
0
)
{
statusBuilder
.
addError
(
CrsConversionServiceErrorMessages
.
MISSING_GEOMETRIES
);
statusBuilder
.
addError
(
MISSING_GEOMETRIES
);
}
else
{
GeoJsonGeometryCollection
gc
=
new
GeoJsonGeometryCollection
();
GeoJsonBase
[]
geometries
=
new
GeoJsonBase
[
geometriesArray
.
size
()];
for
(
int
k
=
0
;
k
<
geometriesArray
.
size
();
k
++)
{
JsonObject
geometryObj
=
geometriesArray
.
get
(
k
).
getAsJsonObject
();
String
geometriesType
=
(
geometryObj
.
has
(
Constants
.
TYPE
)
&&
(!
geometryObj
.
get
(
Constants
.
TYPE
).
isJsonNull
())
)
?
geometryObj
.
get
(
Constants
.
TYPE
).
getAsString
()
:
""
;
JsonArray
coordinatesValues
=
(
geometryObj
.
has
(
Constants
.
COORDINATES
)
&&
(!
geometryObj
.
get
(
Constants
.
COORDINATES
).
isJsonNull
())
)
?
geometryObj
.
get
(
Constants
.
COORDINATES
).
getAsJsonArray
()
:
new
JsonArray
();
String
geometriesType
=
isJsonObjectNotNull
(
geometryObj
,
TYPE
)
?
geometryObj
.
get
(
TYPE
).
getAsString
()
:
""
;
JsonArray
coordinatesValues
=
isJsonObjectNotNull
(
geometryObj
,
COORDINATES
)
&&
isPropertyJsonArray
(
geometryObj
,
COORDINATES
)
?
geometryObj
.
get
(
COORDINATES
).
getAsJsonArray
()
:
new
JsonArray
();
JsonObject
gmCoordinatesObj
=
this
.
getCoordinates
(
coordinatesValues
,
statusBuilder
);
Gson
gson
=
new
Gson
();
switch
(
geometriesType
)
{
case
Constants
.
POINT
:
geometries
[
k
]
=
this
.
getGeoJsonPoint
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
case
POINT:
geometries
[
k
]
=
this
.
getGeoJsonPoint
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
break
;
case
Constants
.
MULTIPOINT
:
geometries
[
k
]
=
this
.
getGeoJsonMultiPoint
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
case
MULTIPOINT:
geometries
[
k
]
=
this
.
getGeoJsonMultiPoint
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
break
;
case
Constants
.
LINE_STRING
:
geometries
[
k
]
=
this
.
getGeoJsonLineString
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
case
LINE_STRING:
geometries
[
k
]
=
this
.
getGeoJsonLineString
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
break
;
case
Constants
.
MULTILINE_STRING
:
geometries
[
k
]
=
this
.
getGeoJsonMultiLineString
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
case
MULTILINE_STRING:
geometries
[
k
]
=
this
.
getGeoJsonMultiLineString
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
break
;
case
Constants
.
POLYGON
:
geometries
[
k
]
=
this
.
getGeoJsonPolygon
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
case
POLYGON:
geometries
[
k
]
=
this
.
getGeoJsonPolygon
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
break
;
case
Constants
.
MULTIPOLYGON
:
geometries
[
k
]
=
this
.
getGeoJsonMultiPolygon
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
case
MULTIPOLYGON:
geometries
[
k
]
=
this
.
getGeoJsonMultiPolygon
(
gson
,
gmCoordinatesObj
,
statusBuilder
);
break
;
default
:
statusBuilder
.
addError
(
String
.
format
(
CrsConversionServiceErrorMessages
.
INVALID_GEOMETRIES
,
geometriesType
));
break
;
...
...
@@ -660,7 +663,7 @@ public class CrsConversionService {
}
}
}
else
{
JsonArray
coordinatesValues
=
(
geometry
.
has
(
Constants
.
COORDINATES
)
&&
(!
geometry
.
get
(
Constants
.
COORDINATES
).
isJsonNull
())
)
?
geometry
.
get
(
Constants
.
COORDINATES
).
getAsJsonArray
()
:
new
JsonArray
();
JsonArray
coordinatesValues
=
isJsonObjectNotNull
(
geometry
,
COORDINATES
)
&&
isPropertyJsonArray
(
geometry
,
COORDINATES
)
?
geometry
.
get
(
COORDINATES
).
getAsJsonArray
()
:
new
JsonArray
();
JsonObject
coordinatesObj
=
this
.
getCoordinates
(
coordinatesValues
,
statusBuilder
);
this
.
setGeometry
(
geometryType
,
feature
,
coordinatesObj
,
statusBuilder
);
}
...
...
@@ -733,7 +736,7 @@ public class CrsConversionService {
private
JsonObject
getCoordinates
(
JsonArray
coordinates
,
ConversionStatus
.
ConversionStatusBuilder
statusBuilder
)
{
JsonObject
coordinatesObj
=
new
JsonObject
();
if
(
coordinates
.
size
()
>
0
)
{
coordinatesObj
.
add
(
Constants
.
COORDINATES
,
coordinates
);
coordinatesObj
.
add
(
COORDINATES
,
coordinates
);
}
else
{
statusBuilder
.
addError
(
CrsConversionServiceErrorMessages
.
MISSING_COORDINATES
);
}
...
...
@@ -747,6 +750,16 @@ public class CrsConversionService {
}
return
bbox
;
}
}
\ No newline at end of file
private
boolean
isJsonObjectNotNull
(
JsonObject
jsonObject
,
String
propertyName
){
return
jsonObject
.
has
(
propertyName
)
&&
!
jsonObject
.
get
(
propertyName
).
isJsonNull
();
}
private
boolean
isPropertyJsonObject
(
JsonObject
jsonObject
,
String
propertyName
)
{
return
jsonObject
.
get
(
propertyName
).
isJsonObject
();
}
private
boolean
isPropertyJsonArray
(
JsonObject
jsonObject
,
String
propertyName
)
{
return
jsonObject
.
get
(
propertyName
).
isJsonArray
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment