Record.kt 2.09 KB
Newer Older
Jonas Waeber's avatar
Jonas Waeber committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * mapper-service
 * Copyright (C) 2020 Memoriav
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package org.memobase.builder

21
import org.apache.jena.datatypes.RDFDatatype
Jonas Waeber's avatar
Jonas Waeber committed
22
import org.apache.jena.rdf.model.Resource
Jonas Waeber's avatar
Jonas Waeber committed
23
import org.memobase.helpers.StringHelpers
24
import org.memobase.mapping.KEYS
Jonas Waeber's avatar
Jonas Waeber committed
25
import org.memobase.rdf.NS
26
import org.memobase.rdf.RDA
Jonas Waeber's avatar
Jonas Waeber committed
27
import org.memobase.rdf.RICO
28
import rdf.MB
Jonas Waeber's avatar
Jonas Waeber committed
29

30
31
32
33
34
35
36
37
class Record(
    sourceId: String,
    type: String,
    recordSetId: String,
    institutionId: String,
    hasSponsoringAgent: Boolean,
    isPublished: Boolean
) :
Jonas Waeber's avatar
Jonas Waeber committed
38
39
    RecordResource(institutionId) {

Jonas Waeber's avatar
Jonas Waeber committed
40
41
    private val id = recordSetId + "-" + StringHelpers.normalizeId(sourceId)
    override val resource: Resource = model.createResource(NS.mbr + id)
42

Jonas Waeber's avatar
Jonas Waeber committed
43
44
    init {
        addRdfType(RICO.Record)
45
        resource.addProperty(RICO.type, type)
Jonas Waeber's avatar
Jonas Waeber committed
46
47
        resource.addProperty(RICO.isPartOf, recordSetUri(recordSetId))
        resource.addProperty(RICO.heldBy, institutionUri)
Jonas Waeber's avatar
Jonas Waeber committed
48
        addRicoConcept(KEYS.identifiers, "main", listOf(literal(id)))
49
50
51
        if (hasSponsoringAgent) {
            resource.addProperty(RDA.hasSponsoringAgentOfResource, model.createResource(KEYS.memoriavUri))
        }
52
        resource.addProperty(MB.isPublished, model.createTypedLiteral(isPublished))
Jonas Waeber's avatar
Jonas Waeber committed
53
54
55
56
57
58
    }

    fun addInstantiation(instantiation: Instantiation) {
        resource.addProperty(RICO.hasInstantiation, instantiation.resource)
    }

Jonas Waeber's avatar
Jonas Waeber committed
59
    private fun recordSetUri(id: String): Resource = model.createResource(uri(NS.mbrs, id))
Jonas Waeber's avatar
Jonas Waeber committed
60
}