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
postprocessing
Fedora Metadata Extractor
Commits
6c93a52c
Commit
6c93a52c
authored
Jul 20, 2020
by
Jonas Waeber
Browse files
Update event message
parent
40b93481
Changes
3
Show whitespace changes
Inline
Side-by-side
helm-charts/values.yaml
View file @
6c93a52c
...
...
@@ -10,5 +10,5 @@ tag: "latest"
deploymentName
:
fedora-metadata-extractor
kafkaConfigs
:
prod-kafka-bootstrap-servers
fedoraConfigs
:
prod-fedora-configs
outputTopic
:
fedora-
metadata-extractor-json-
output
outputTopic
:
fedora-output
inputTopic
:
fedora-events
\ No newline at end of file
src/main/kotlin/KafkaTopology.kt
View file @
6c93a52c
...
...
@@ -25,7 +25,6 @@ import org.apache.jena.rdf.model.ModelFactory
import
org.apache.jena.rdf.model.Property
import
org.apache.jena.rdf.model.Resource
import
org.apache.jena.rdf.model.impl.SelectorImpl
import
org.apache.jena.rdf.model.impl.StatementImpl
import
org.apache.jena.riot.Lang
import
org.apache.jena.riot.RDFDataMgr
import
org.apache.kafka.streams.StreamsBuilder
...
...
@@ -37,6 +36,7 @@ import org.memobase.fedora.RdfResponseTypes
import
org.memobase.model.EventMessage
import
org.memobase.rdf.*
import
org.memobase.settings.SettingsLoader
import
rdf.MB
import
java.io.StringWriter
import
java.net.URI
import
java.nio.charset.StandardCharsets
...
...
@@ -67,34 +67,41 @@ class KafkaTopology(
.
mapValues
{
value
->
parseMessage
(
value
)
}
.
branch
(
// TODO: Add actual values.
Predicate
{
_
,
value
->
value
.
objectTypes
==
"rico:Record"
},
Predicate
{
_
,
value
->
value
.
objectTypes
==
"rico:CorporateBody"
||
value
.
objectTypes
==
"rico:RecordSet"
}
Predicate
{
_
,
value
->
value
.
objectType
==
"rico:Record"
},
Predicate
{
_
,
value
->
value
.
objectType
==
"rico:CorporateBody"
},
Predicate
{
_
,
value
->
value
.
objectType
==
"rico:RecordSet"
}
)
objectBranches
[
0
]
.
mapValues
{
value
->
requestPrimaryResource
(
value
)
}
.
mapValues
{
value
->
parseModel
(
value
)
}
.
mapValues
{
value
->
add
Status
(
value
)
}
.
mapValues
{
value
->
add
EventType
(
value
)
}
.
mapValues
{
value
->
requestAdditionalRecordResources
(
value
)
}
.
mapValues
{
value
->
filterFedoraProperties
(
value
)
}
.
mapValues
{
value
->
writeModel
(
value
)
}
.
to
(
settings
.
outputTopic
)
.
to
(
settings
.
outputTopic
+
"-json-records"
)
objectBranches
[
1
]
.
mapValues
{
value
->
requestPrimaryResource
(
value
)
}
.
mapValues
{
value
->
parseModel
(
value
)
}
.
mapValues
{
value
->
add
Status
(
value
)
}
.
mapValues
{
value
->
add
EventType
(
value
)
}
.
mapValues
{
value
->
filterFedoraProperties
(
value
)
}
.
mapValues
{
value
->
writeModel
(
value
)
}
.
to
(
settings
.
outputTopic
)
.
to
(
settings
.
outputTopic
+
"-json-institutions"
)
objectBranches
[
2
]
.
mapValues
{
value
->
requestPrimaryResource
(
value
)
}
.
mapValues
{
value
->
parseModel
(
value
)
}
.
mapValues
{
value
->
addEventType
(
value
)
}
.
mapValues
{
value
->
filterFedoraProperties
(
value
)
}
.
mapValues
{
value
->
writeModel
(
value
)
}
.
to
(
settings
.
outputTopic
+
"-json-record-sets"
)
return
builder
.
build
()
}
private
fun
parseMessage
(
data
:
String
):
EventMessage
{
// can we assume that this is always correct? or should we handle parse errors?
return
objectMapper
.
readValue
(
data
,
EventMessage
::
class
.
java
)
}
...
...
@@ -110,15 +117,15 @@ class KafkaTopology(
}
/**
* Adds the
status
of the event message to the core resources.
* Core resources are rico:Record, rico:CorporateBody (for institutions)
and
rico:RecordSet.
* Adds the
type
of the event message to the core resources.
* Core resources are rico:Record, rico:CorporateBody (for institutions)
,
rico:RecordSet
and rico:Instantiations
.
* Downstream services should remove this property before publishing the data to the outside world!
*/
private
fun
add
Status
(
input
:
Pair
<
EventMessage
,
Model
>):
Model
{
listOf
(
RICO
.
Record
,
RICO
.
CorporateBody
,
RICO
.
RecordSet
).
forEach
{
private
fun
add
EventType
(
input
:
Pair
<
EventMessage
,
Model
>):
Model
{
listOf
(
RICO
.
Record
,
RICO
.
CorporateBody
,
RICO
.
RecordSet
,
RICO
.
Instantiation
).
forEach
{
val
record
=
input
.
second
.
listSubjectsWithProperty
(
RDF
.
type
,
it
).
toList
()
if
(
record
.
isNotEmpty
())
{
record
[
0
].
addProperty
(
NS
.
hasStatus
,
input
.
first
.
eventType
)
record
[
0
].
addProperty
(
MB
.
eventType
,
input
.
first
.
eventType
)
}
}
return
input
.
second
...
...
src/main/kotlin/model/EventMessage.kt
View file @
6c93a52c
...
...
@@ -5,6 +5,6 @@ data class EventMessage(
val
eventTimestamp
:
String
,
val
eventType
:
String
,
val
objectPath
:
String
,
val
object
Id
:
String
,
val
object
Types
:
String
val
object
Type
:
String
,
val
object
Version
:
String
?
=
null
)
\ 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