Commit 106151bb authored by Jonas Waeber's avatar Jonas Waeber
Browse files

Fix check locator filter.

parent 418ee28b
Pipeline #23282 failed with stages
in 2 minutes and 32 seconds
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
package org.memobase package org.memobase
import ch.memobase.rdf.EBUCORE
import ch.memobase.rdf.NS import ch.memobase.rdf.NS
import com.beust.klaxon.JsonObject import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
...@@ -173,7 +172,7 @@ class DocumentsSearchDocBuilder( ...@@ -173,7 +172,7 @@ class DocumentsSearchDocBuilder(
"" ""
} }
val addLocator = Filter.checkLocator(digitalObject, accessDigital) val addLocator = Filter.checkLocator(digitalObject)
val digitalObjectValues = digitalObject.let { val digitalObjectValues = digitalObject.let {
if (it != null) { if (it != null) {
......
...@@ -22,7 +22,6 @@ import ch.memobase.rdf.EBUCORE ...@@ -22,7 +22,6 @@ 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")
...@@ -82,15 +81,7 @@ object Filter { ...@@ -82,15 +81,7 @@ object Filter {
} }
} }
fun checkLocator(digitalObject: JsonObject?, accessDigital: List<FacetContainer>): Boolean { fun checkLocator(digitalObject: JsonObject?): Boolean {
return if (digitalObject != null) { return digitalObject?.containsKey(EBUCORE.locator.localName) ?: false
if (digitalObject.containsKey(EBUCORE.locator.localName)) {
accessDigital.any { it.facet?.contains("public") ?: false }
} else {
false
}
} else {
false
}
} }
} }
...@@ -5,14 +5,12 @@ import org.assertj.core.api.Assertions.assertThat ...@@ -5,14 +5,12 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import org.memobase.helpers.Filter import org.memobase.helpers.Filter
import org.memobase.model.FacetContainer
import org.memobase.model.LanguageContainer
@TestInstance(TestInstance.Lifecycle.PER_CLASS) @TestInstance(TestInstance.Lifecycle.PER_CLASS)
class TestCheckLocator { class TestCheckLocator {
@Test @Test
fun `test check locator no digital object`() { fun `test check locator no digital object`() {
val result = Filter.checkLocator(null, emptyList()) val result = Filter.checkLocator(null)
assertThat(result).isFalse() assertThat(result).isFalse()
} }
...@@ -21,33 +19,17 @@ class TestCheckLocator { ...@@ -21,33 +19,17 @@ class TestCheckLocator {
val result = Filter.checkLocator(json { val result = Filter.checkLocator(json {
obj( obj(
) )
}, emptyList()) })
assertThat(result).isFalse() assertThat(result).isFalse()
} }
@Test @Test
fun `test check locator digital object has locator no access`() { fun `test check locator digital object has locator`() {
val result = Filter.checkLocator(json { val result = Filter.checkLocator(json {
obj( obj(
Pair("locator", "https://example.org") 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() 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