Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Schema
Commits
c4bd887d
Commit
c4bd887d
authored
Jan 27, 2021
by
ethiraj krishnamanaidu
Browse files
Merge branch 'slb-schema-resolve-fix' into 'master'
Fix related to schema resolve logic See merge request
!71
parents
c325c74d
732998bb
Pipeline
#23778
failed with stages
in 84 minutes and 2 seconds
Changes
4
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
schema-core/src/main/java/org/opengroup/osdu/schema/util/SchemaResolver.java
View file @
c4bd887d
...
...
@@ -11,6 +11,7 @@ import org.apache.http.client.methods.HttpGet;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.util.EntityUtils
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.opengroup.osdu.core.common.logging.JaxRsDpsLog
;
...
...
@@ -95,11 +96,25 @@ public class SchemaResolver {
jsonObject
.
put
(
key
,
value
);
}
else
if
(
jsonObject
.
get
(
key
)
instanceof
JSONObject
)
{
findAndResolveRef
((
JSONObject
)
jsonObject
.
get
(
key
),
refSchemas
);
}
else
if
(
jsonObject
.
get
(
key
)
instanceof
JSONArray
)
{
findAndResolveRef
(
jsonObject
.
getJSONArray
(
key
),
refSchemas
);
}
}
return
jsonObject
;
}
private
JSONArray
findAndResolveRef
(
JSONArray
jsonArray
,
Map
<
String
,
String
>
refSchemas
)
throws
BadRequestException
,
ApplicationException
{
for
(
Object
object
:
jsonArray
)
{
if
(
object
instanceof
JSONObject
)
{
findAndResolveRef
((
JSONObject
)
object
,
refSchemas
);
}
else
if
(
object
instanceof
JSONArray
)
{
findAndResolveRef
((
JSONArray
)
object
,
refSchemas
);
}
}
return
jsonArray
;
}
private
String
resolveRef
(
Object
object
,
Map
<
String
,
String
>
refSchemas
)
throws
BadRequestException
,
ApplicationException
{
String
value
=
String
.
valueOf
(
object
);
...
...
@@ -180,4 +195,4 @@ public class SchemaResolver {
}
return
true
;
}
}
\ No newline at end of file
}
schema-core/src/test/java/org/opengroup/osdu/schema/util/SchemaResolverTest.java
View file @
c4bd887d
...
...
@@ -55,6 +55,16 @@ public class SchemaResolverTest {
JSONAssert
.
assertEquals
(
resolvedSchema
,
schemaResolver
.
resolveSchema
(
orginalSchema
),
JSONCompareMode
.
LENIENT
);
}
@Test
public
void
testResolveSchema_ResolveRefForAttributeInJSONArray
()
throws
JSONException
,
BadRequestException
,
ApplicationException
,
NotFoundException
,
IOException
{
String
resolvedSchema
=
new
FileUtils
().
read
(
"/test_schema/resolvedSchema_Ref_AttributeInJsonArray.json"
);
String
orginalSchema
=
new
FileUtils
().
read
(
"/test_schema/originalSchemaWithRef_AttributeInJsonArray.json"
);
String
referenceSchema
=
new
FileUtils
().
read
(
"/test_schema/referenceSchema.json"
);
Mockito
.
when
(
schemaService
.
getSchema
(
"os:wks:anyCrsFeatureCollection.1.0"
)).
thenReturn
(
referenceSchema
);
JSONAssert
.
assertEquals
(
resolvedSchema
,
schemaResolver
.
resolveSchema
(
orginalSchema
),
JSONCompareMode
.
LENIENT
);
}
@Test
public
void
testResolveSchema_no_definitionblock
()
throws
JSONException
,
BadRequestException
,
ApplicationException
,
NotFoundException
,
IOException
{
...
...
schema-core/src/test/resources/test_schema/originalSchemaWithRef_AttributeInJsonArray.json
0 → 100644
View file @
c4bd887d
{
"$schema"
:
"http://json-schema.org/draft-07/schema#"
,
"x-os-lifecycle-state"
:
"published"
,
"description"
:
"The entity well."
,
"title"
:
"Well"
,
"type"
:
"object"
,
"definitions"
:
{},
"properties"
:
{
"locationOriginalCRS"
:
{
"description"
:
"The well's original location as AnyCrsFeatureCollection - a structure similar to but distinct from GeoJSON."
,
"title"
:
"Original CRS Location"
,
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0"
},
"allOf"
:
[
{
"$ref"
:
"#/definition/os:wks:well.1.0"
},
[
{
"$ref"
:
"os:wks:anyCrsFeatureCollection.1.0"
}
]
],
"locationWGS84"
:
{
"description"
:
"The well's location as GeoJSON FeatureCollection."
,
"title"
:
"WGS84 Location"
,
"$ref"
:
"https://geojson.org/schema/FeatureCollection.json"
,
"example"
:
{
"features"
:
[
{
"geometry"
:
{
"coordinates"
:
[
-92.11569999999999
,
29.8823
,
153.4779442519685
],
"type"
:
"Point"
},
"type"
:
"Feature"
,
"properties"
:
{
"name"
:
"Newton 2-31"
}
}
],
"type"
:
"FeatureCollection"
}
}
}
}
schema-core/src/test/resources/test_schema/resolvedSchema_Ref_AttributeInJsonArray.json
0 → 100644
View file @
c4bd887d
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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