Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
Indexer
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
Indexer
Commits
b6b8692a
Commit
b6b8692a
authored
4 years ago
by
Sviatoslav Nekhaienko
Browse files
Options
Downloads
Patches
Plain Diff
refactoring
parent
9c16b949
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!60
Indexer to read from Schema Service as well as Storage Schema
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java
+48
-15
48 additions, 15 deletions
...up/osdu/indexer/schema/converter/PropertiesProcessor.java
with
48 additions
and
15 deletions
indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java
+
48
−
15
View file @
b6b8692a
...
...
@@ -25,6 +25,7 @@ import org.opengroup.osdu.indexer.schema.converter.tags.Definitions;
import
org.opengroup.osdu.indexer.schema.converter.tags.TypeProperty
;
import
java.util.*
;
import
java.util.function.Supplier
;
import
java.util.stream.Stream
;
public
class
PropertiesProcessor
{
...
...
@@ -33,6 +34,8 @@ public class PropertiesProcessor {
private
SchemaConverterConfig
schemaConverterConfig
;
private
static
final
String
DEF_PREFIX
=
"#/definitions/"
;
private
static
final
String
LINK_PREFIX
=
"^srn"
;
private
static
final
String
LINK_TYPE
=
"link"
;
private
final
Definitions
definitions
;
private
final
String
pathPrefix
;
...
...
@@ -46,7 +49,7 @@ public class PropertiesProcessor {
this
.
log
=
log
;
this
.
definitions
=
definitions
;
this
.
pathPrefix
=
pathPrefix
;
this
.
pathPrefixWithDot
=
Objects
.
isNull
(
pathPrefix
)
||
pathPrefix
.
isEmpty
()
?
""
:
pathPrefix
+
"."
;
this
.
pathPrefixWithDot
=
Objects
.
isNull
(
pathPrefix
)
||
pathPrefix
.
isEmpty
()
?
""
:
pathPrefix
+
"."
;
this
.
schemaConverterConfig
=
schemaConverterConfig
;
}
...
...
@@ -56,7 +59,7 @@ public class PropertiesProcessor {
String
ref
=
allOfItem
.
getRef
();
return
Objects
.
isNull
(
ref
)
?
allOfItem
.
getProperties
().
entrySet
().
stream
().
flatMap
(
this
::
processPropertyEntry
)
:
processRef
(
ref
);
allOfItem
.
getProperties
().
entrySet
().
stream
().
flatMap
(
this
::
processPropertyEntry
)
:
processRef
(
ref
);
}
public
Stream
<
Map
<
String
,
Object
>>
processRef
(
String
ref
)
{
...
...
@@ -79,8 +82,8 @@ public class PropertiesProcessor {
Definition
definition
=
definitions
.
getDefinition
(
definitionSubRef
);
Optional
.
ofNullable
(
definition
).
orElseThrow
(()
->
new
AppException
(
HttpStatus
.
SC_NOT_FOUND
,
"Failed to find definition:"
+
definitionSubRef
,
"Unknown definition:"
+
definitionSubRef
));
new
AppException
(
HttpStatus
.
SC_NOT_FOUND
,
"Failed to find definition:"
+
definitionSubRef
,
"Unknown definition:"
+
definitionSubRef
));
return
definition
.
getProperties
().
entrySet
().
stream
().
flatMap
(
this
::
processPropertyEntry
);
}
...
...
@@ -130,16 +133,46 @@ public class PropertiesProcessor {
protected
String
getTypeByDefinitionProperty
(
TypeProperty
definitionProperty
)
{
Preconditions
.
checkNotNull
(
definitionProperty
,
"definitionProperty cannot be null"
);
String
pattern
=
definitionProperty
.
getPattern
();
String
itemsPattern
=
definitionProperty
.
getItems
()
!=
null
?
definitionProperty
.
getItems
().
getPattern
()
:
null
;
String
format
=
definitionProperty
.
getFormat
();
String
itemsType
=
definitionProperty
.
getItems
()
!=
null
?
definitionProperty
.
getItems
().
getType
()
:
null
;
String
type
=
definitionProperty
.
getType
();
return
Objects
.
nonNull
(
pattern
)
&&
pattern
.
startsWith
(
"^srn"
)
?
"link"
:
Objects
.
nonNull
(
itemsPattern
)
&&
itemsPattern
.
startsWith
(
"^srn"
)
?
"link"
:
Objects
.
nonNull
(
format
)
?
schemaConverterConfig
.
getPrimitiveTypesMap
().
getOrDefault
(
format
,
format
)
:
Objects
.
nonNull
(
itemsType
)
?
schemaConverterConfig
.
getPrimitiveTypesMap
().
getOrDefault
(
itemsType
,
itemsType
)
:
schemaConverterConfig
.
getPrimitiveTypesMap
().
getOrDefault
(
type
,
type
);
return
Stream
.
of
(
getFromPattern
(
definitionProperty
.
getPattern
()),
getFromItemsPattern
(()
->
definitionProperty
.
getItems
()
!=
null
?
definitionProperty
.
getItems
().
getPattern
()
:
null
),
getFromFormat
(
definitionProperty:
:
getFormat
),
getFromItemsType
(()
->
definitionProperty
.
getItems
()
!=
null
?
definitionProperty
.
getItems
().
getType
()
:
null
))
.
filter
(
x
->
x
.
get
()
!=
null
)
.
findFirst
()
.
orElse
(
getFromType
(
definitionProperty:
:
getType
)).
get
();
}
protected
Supplier
<
String
>
getFromPattern
(
String
pattern
)
{
return
()
->
Objects
.
nonNull
(
pattern
)
&&
pattern
.
startsWith
(
LINK_PREFIX
)
?
LINK_TYPE
:
null
;
}
protected
Supplier
<
String
>
getFromItemsPattern
(
Supplier
<
String
>
itemsPatternSupplier
)
{
return
()
->
{
String
itemsPattern
=
itemsPatternSupplier
.
get
();
return
Objects
.
nonNull
(
itemsPattern
)
&&
itemsPattern
.
startsWith
(
LINK_PREFIX
)
?
LINK_TYPE
:
null
;
};
}
protected
Supplier
<
String
>
getFromType
(
Supplier
<
String
>
typeSupplier
)
{
return
()
->
{
String
type
=
typeSupplier
.
get
();
return
schemaConverterConfig
.
getPrimitiveTypesMap
().
getOrDefault
(
type
,
type
);
};
}
protected
Supplier
<
String
>
getFromFormat
(
Supplier
<
String
>
formatSupplier
){
return
()
->
{
String
format
=
formatSupplier
.
get
();;
return
Objects
.
nonNull
(
format
)
?
schemaConverterConfig
.
getPrimitiveTypesMap
().
getOrDefault
(
format
,
format
)
:
null
;
};
}
protected
Supplier
<
String
>
getFromItemsType
(
Supplier
<
String
>
itemsTypeSupplier
)
{
return
()
->
{
String
itemsType
=
itemsTypeSupplier
.
get
();
return
Objects
.
nonNull
(
itemsType
)
?
schemaConverterConfig
.
getPrimitiveTypesMap
().
getOrDefault
(
itemsType
,
itemsType
)
:
null
;
};
}
}
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