Commit 2820bb18 authored by Jonas Waeber's avatar Jonas Waeber
Browse files
parent 33b6f98c
......@@ -20,11 +20,12 @@ package org.memobase.builder
import org.apache.jena.rdf.model.Resource
import org.memobase.builder.Instantiation
import org.memobase.helpers.StringHelpers
import org.memobase.rdf.NS
import org.memobase.rdf.RICO
class DigitalObject(id: String, institutionId: String, count: Int) : Instantiation(institutionId) {
override val resource: Resource = model.createResource(NS.mempo + institutionId + "-" + id + "-" + count)
override val resource: Resource = model.createResource(NS.mempo + institutionId + "-" + StringHelpers.normalizeId(id) + "-" + count)
init {
addRdfType(RICO.Instantiation)
resource.addProperty(RICO.type, "digitalObject")
......
......@@ -19,11 +19,12 @@
package org.memobase.builder
import org.apache.jena.rdf.model.Resource
import org.memobase.helpers.StringHelpers
import org.memobase.rdf.NS
import org.memobase.rdf.RICO
class PhysicalObject(id: String, institutionId: String, count: Int) : Instantiation(institutionId) {
override val resource: Resource = model.createResource(NS.mempo + institutionId + "-" + id + "-" + count)
override val resource: Resource = model.createResource(NS.mempo + institutionId + "-" + StringHelpers.normalizeId(id) + "-" + count)
init {
addRdfType(RICO.Instantiation)
resource.addProperty(RICO.type, "physicalObject")
......
......@@ -19,13 +19,14 @@
package org.memobase.builder
import org.apache.jena.rdf.model.Resource
import org.memobase.helpers.StringHelpers
import org.memobase.rdf.NS
import org.memobase.rdf.RICO
class Record(id: String, type: String, recordSetId: String, institutionId: String) :
RecordResource(institutionId) {
override val resource: Resource = model.createResource(NS.memr + institutionId + "-" + id)
override val resource: Resource = model.createResource(NS.memr + institutionId + "-" + StringHelpers.normalizeId(id))
init {
addRdfType(RICO.Record)
resource.addProperty(RICO.type, type)
......
/*
* 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.helpers
object StringHelpers {
private val whitespace = Regex("\\s+")
private val illegalCharacters = Regex("\\s*[/?@\\[\\]:#]+\\s*")
fun normalizeId(value: String): String {
return value
.trim()
.replace(illegalCharacters, "-")
.replace(whitespace, "_")
}
}
\ No newline at end of file
......@@ -31,6 +31,7 @@ import org.junit.jupiter.api.assertAll
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import org.memobase.builder.ResourceBuilder
import org.memobase.helpers.StringHelpers
import org.memobase.mapping.MappingConfig
import org.memobase.settings.SettingsLoader
import java.io.File
......@@ -136,4 +137,20 @@ class Tests {
}
@ParameterizedTest
@MethodSource("idExamples")
fun `test id normalization`(params: Pair<String, String>) {
val result = StringHelpers.normalizeId(params.first)
assertThat(result).isEqualTo(params.second)
}
private fun idExamples() = Stream.of(
Pair("J2.143#1996/386#414-3#1*", "J2.143-1996-386-414-3-1*"),
Pair(" IB Becker Audiovisuals / 2", "IB_Becker_Audiovisuals-2"),
Pair(" oisadi ", "oisadi"),
Pair("Test mit vielen spaces . jal", "Test_mit_vielen_spaces_._jal")
)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment