Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
Import Process
Mapper Service
Commits
a1fe120a
Commit
a1fe120a
authored
Jul 16, 2020
by
Jonas Waeber
Browse files
Fix rico:Concept mapper
Duplicate keys are not allowed. Need to use lists if sections are needed twice or more.
parent
4665dc7f
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/mapping/MappingConfig.kt
View file @
a1fe120a
...
...
@@ -176,21 +176,32 @@ class MappingConfig(directory: String) {
private
fun
buildRicoConceptMappers
(
key
:
String
,
value
:
Any
?):
List
<
IFieldMapper
>
{
return
when
(
value
)
{
is
Map
<
*
,
*
>
->
{
value
.
entries
.
map
{
KEYS
.
ricoConceptCategoryToTypesMap
[
key
].
let
{
typeList
->
if
(
typeList
!=
null
)
parseFieldWithKeyValidation
(
key
,
it
as
Map
.
Entry
<
String
,
Any
>,
typeList
)
else
throw
InvalidMappingException
(
"Could not find a types configuration for field $key."
)
extractRicoConceptFields
(
key
,
value
as
Map
<
String
,
Any
>)
}
is
List
<
*
>
->
{
value
.
flatMap
{
if
(
it
is
Map
<
*
,
*
>)
{
extractRicoConceptFields
(
key
,
it
as
Map
<
String
,
Any
>)
}
else
{
throw
InvalidMappingException
(
"Expected a key-value map in section $key."
)
}
}.
map
{
RicoConceptMapper
(
key
,
it
)
}
}
else
->
throw
InvalidMappingException
(
"Expected a key-value map in section $key."
)
}
}
private
fun
extractRicoConceptFields
(
key
:
String
,
map
:
Map
<
String
,
Any
>):
List
<
IFieldMapper
>
{
return
map
.
entries
.
map
{
entry
->
KEYS
.
ricoConceptCategoryToTypesMap
[
key
].
let
{
typeList
->
if
(
typeList
!=
null
)
parseFieldWithKeyValidation
(
key
,
entry
,
typeList
)
else
throw
InvalidMappingException
(
"Could not find a types configuration for field $key."
)
}
}.
map
{
field
->
RicoConceptMapper
(
key
,
field
)
}
}
private
fun
buildAgentMapper
(
key
:
String
,
value
:
Any
?):
List
<
IFieldMapper
>
{
...
...
src/main/kotlin/mapping/YamlLoader.kt
View file @
a1fe120a
...
...
@@ -23,6 +23,7 @@ import org.memobase.settings.CustomEnvConfig
import
org.memobase.settings.MissingSettingException
import
org.snakeyaml.engine.v2.api.Load
import
org.snakeyaml.engine.v2.api.LoadSettings
import
org.snakeyaml.engine.v2.exceptions.DuplicateKeyException
import
org.snakeyaml.engine.v2.exceptions.MissingEnvironmentVariableException
import
java.nio.charset.Charset
import
java.nio.file.Files
...
...
@@ -37,7 +38,7 @@ class YamlLoader(private val directory: String) {
fun
load
():
Iterable
<
Any
>
{
val
settings
=
LoadSettings
.
builder
().
setAllowDuplicateKeys
(
true
).
setEnvConfig
(
Optional
.
of
(
CustomEnvConfig
())).
build
()
LoadSettings
.
builder
().
setEnvConfig
(
Optional
.
of
(
CustomEnvConfig
())).
build
()
val
load
=
Load
(
settings
)
return
try
{
val
data
=
readFiles
()
...
...
@@ -49,6 +50,9 @@ class YamlLoader(private val directory: String) {
throw
MissingSettingException
(
"env"
,
ex
.
localizedMessage
)
}
catch
(
ex
:
ClassCastException
)
{
throw
InvalidMappingException
(
"Top level structure of the mapping file must be a map!"
)
}
catch
(
ex
:
DuplicateKeyException
)
{
// TODO: Figure out why this exception is not properly caught...
throw
InvalidMappingException
(
"Duplicate Key Detected: ${ex.localizedMessage}."
)
}
}
}
\ No newline at end of file
src/test/kotlin/Tests.kt
View file @
a1fe120a
...
...
@@ -223,6 +223,20 @@ class Tests {
"Successfully created a record from source."
)
)
),
KafkaTestParams
(
6
,
"ID_1"
,
listOf
(
"https://memobase.ch/record/TEST-ID_1"
),
listOf
(
Report
(
"https://memobase.ch/record/TEST-ID_1"
,
"SUCCESS"
,
"Successfully created a record from source."
)
)
)
)
...
...
src/test/resources/kafkaTest6.yml
0 → 100644
View file @
a1fe120a
app
:
institutionId
:
"
TEST"
recordSetId
:
"
TEST_RECORD_SET"
configs
:
src/test/resources/kafkaTests/6/config
kafka
:
streams
:
bootstrap.servers
:
localhost:12345
application.id
:
test-clinet-1234
topic
:
in
:
test-topic-in
out
:
test-topic-out
process
:
test-topic-process
\ No newline at end of file
src/test/resources/kafkaTests/6/config/mapping.yml
0 → 100644
View file @
a1fe120a
record
:
uri
:
id
type
:
const
:
Foto
languages
:
# blank node rico:Language with type content or caption and relation rico:hasLanguage
-
content
:
fr
:
-
content1
-
content
:
fr
:
-
content2
-
caption
:
fr
:
-
caption1
src/test/resources/kafkaTests/6/input.json
0 → 100644
View file @
a1fe120a
{
"id"
:
"ID_1"
,
"content1"
:
"franz"
,
"content2"
:
"deutsch"
,
"caption1"
:
"english"
}
\ No newline at end of file
src/test/resources/kafkaTests/6/output1.nt
0 → 100644
View file @
a1fe120a
<https://memobase.ch/record/TEST-ID_1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Record> .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#hasLanguage> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#hasLanguage> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#hasLanguage> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#heldBy> <https://memobase.ch/institution/TEST> .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#identifiedBy> _:B .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#isPartOf> <https://memobase.ch/recordSet/TEST_RECORD_SET> .
<https://memobase.ch/record/TEST-ID_1> <https://www.ica.org/standards/RiC/ontology#type> "Foto" .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Identifier> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Language> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Language> .
_:B <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://www.ica.org/standards/RiC/ontology#Language> .
_:B <https://www.ica.org/standards/RiC/ontology#identifier> "https://memobase.ch/record/TEST-ID_1" .
_:B <https://www.ica.org/standards/RiC/ontology#name> "deutsch"@fr .
_:B <https://www.ica.org/standards/RiC/ontology#name> "english"@fr .
_:B <https://www.ica.org/standards/RiC/ontology#name> "franz"@fr .
_:B <https://www.ica.org/standards/RiC/ontology#type> "caption" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "content" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "content" .
_:B <https://www.ica.org/standards/RiC/ontology#type> "main" .
\ No newline at end of file
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