Commit 418ee28b authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Add test for locator filter.

parent 5bcb9fce
Pipeline #22934 passed with stages
in 5 minutes and 43 seconds
...@@ -173,15 +173,7 @@ class DocumentsSearchDocBuilder( ...@@ -173,15 +173,7 @@ class DocumentsSearchDocBuilder(
"" ""
} }
val addLocator = if (digitalObject != null) { val addLocator = Filter.checkLocator(digitalObject, accessDigital)
if (digitalObject.containsKey(EBUCORE.locator.localName)) {
accessDigital.any { it.facet?.contains("public") ?: false }
} else {
false
}
} else {
false
}
val digitalObjectValues = digitalObject.let { val digitalObjectValues = digitalObject.let {
if (it != null) { if (it != null) {
......
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
package org.memobase.helpers package org.memobase.helpers
import ch.memobase.rdf.EBUCORE
import com.beust.klaxon.JsonArray import com.beust.klaxon.JsonArray
import com.beust.klaxon.JsonObject import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.memobase.model.FacetContainer
object Filter { object Filter {
private val log = LogManager.getLogger("SearchDocFilter") private val log = LogManager.getLogger("SearchDocFilter")
...@@ -79,4 +81,16 @@ object Filter { ...@@ -79,4 +81,16 @@ object Filter {
} }
} }
} }
fun checkLocator(digitalObject: JsonObject?, accessDigital: List<FacetContainer>): Boolean {
return if (digitalObject != null) {
if (digitalObject.containsKey(EBUCORE.locator.localName)) {
accessDigital.any { it.facet?.contains("public") ?: false }
} else {
false
}
} else {
false
}
}
} }
package org.memobase
import com.beust.klaxon.json
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.memobase.helpers.Filter
import org.memobase.model.FacetContainer
import org.memobase.model.LanguageContainer
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestCheckLocator {
@Test
fun `test check locator no digital object`() {
val result = Filter.checkLocator(null, emptyList())
assertThat(result).isFalse()
}
@Test
fun `test check locator digital object no locator`() {
val result = Filter.checkLocator(json {
obj(
)
}, emptyList())
assertThat(result).isFalse()
}
@Test
fun `test check locator digital object has locator no access`() {
val result = Filter.checkLocator(json {
obj(
Pair("locator", "https://example.org")
)
}, emptyList())
assertThat(result).isFalse()
}
@Test
fun `test check locator digital object has locator and public access`() {
val result = Filter.checkLocator(
json {
obj(
Pair("locator", "https://example.org")
)
}, listOf(
FacetContainer(LanguageContainer.EMPTY, filter = null, facet = listOf("public"))
)
)
assertThat(result).isTrue()
}
}
\ No newline at end of file
Markdown is supported
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