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 @@
package org.memobase
import ch.memobase.rdf.EBUCORE
import ch.memobase.rdf.NS
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
......@@ -173,7 +172,7 @@ class DocumentsSearchDocBuilder(
""
}
val addLocator = Filter.checkLocator(digitalObject, accessDigital)
val addLocator = Filter.checkLocator(digitalObject)
val digitalObjectValues = digitalObject.let {
if (it != null) {
......@@ -282,7 +281,7 @@ class DocumentsSearchDocBuilder(
durationDigital = Extract.listOfStrings(digitalObject?.get("duration")),
colourDigital = Extract.listOfStrings(digitalObject?.get(KEYS.color)),
digitalObjectNote = Extract.languageContainer("descriptiveNote", digitalObject?.get("descriptiveNote")),
locator = if (addLocator) locator else null,
locator = if (addLocator) locator else null,
usageConditionsDigital = Extract.languageContainer(
"conditionsOfUse",
digitalObject?.get("conditionsOfUse")
......
......@@ -22,7 +22,6 @@ import ch.memobase.rdf.EBUCORE
import com.beust.klaxon.JsonArray
import com.beust.klaxon.JsonObject
import org.apache.logging.log4j.LogManager
import org.memobase.model.FacetContainer
object Filter {
private val log = LogManager.getLogger("SearchDocFilter")
......@@ -82,15 +81,7 @@ 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
}
fun checkLocator(digitalObject: JsonObject?): Boolean {
return digitalObject?.containsKey(EBUCORE.locator.localName) ?: false
}
}
......@@ -5,14 +5,12 @@ 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())
val result = Filter.checkLocator(null)
assertThat(result).isFalse()
}
......@@ -21,33 +19,17 @@ class TestCheckLocator {
val result = Filter.checkLocator(json {
obj(
)
}, emptyList())
})
assertThat(result).isFalse()
}
@Test
fun `test check locator digital object has locator no access`() {
fun `test check locator digital object has locator`() {
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