Commit 73727084 authored by Günter Hipler's avatar Günter Hipler
Browse files

Implementation: ListMetadataFormats / ListSets

parent f5303f87
......@@ -60,8 +60,8 @@ class ElasticsearchClient @Inject()(
//collection conversions
//https://stackoverflow.com/questions/8301947/what-is-the-difference-between-javaconverters-and-javaconversions-in-scala
val oaiConfigSet = config.getStringList("oaiconfigs.sets").asScala.toSeq
val oaiConfigPrefixes = config.getStringList("oaiconfigs.metadataPrefix").asScala.toSeq
val oaiConfigSet = config.getObjectList("oaiconfigs.sets").asScala.toSeq
val oaiConfigPrefixes = config.getObjectList("oaiconfigs.metadataPrefix").asScala.toSeq
OaiConfig(
commonConfig,
......
package org.swissbib.memobase.oai.common.util
import com.typesafe.config.ConfigObject
case class OaiConfig(common: OaiCommonConfig,
identify: OaiIdentifyConfig,
sets: OaiConfigSets,
......@@ -20,7 +22,7 @@ case class OaiIdentifyConfig(earliestDatestamp: String,
protocolVersion: String
)
case class OaiConfigSets(sets: Seq[String])
case class OaiConfigSets(sets: Seq[ConfigObject])
case class OaiConfigMetadataPrefixes(prefixes: Seq[String])
case class OaiConfigMetadataPrefixes(prefixes: Seq[ConfigObject])
......@@ -24,7 +24,7 @@ case class OaiRequest(verb:OaiVerb,
**identifier** a required argument that specifies the unique identifier of the item in the repository from which the record must be disseminated.
**metadataPrefix** a required argument that specifies the metadataPrefix of the format that should be included in the metadata part of the returned record . A record should only be returned if the format specified by the metadataPrefix can be disseminated from the item identified by the value of the identifier argument. The metadata formats supported by a repository and for a particular record can be retrieved using the ListMetadataFormats request.
Error and Exception Conditions
Error and Exception Condi tions
badArgument - The request includes illegal arguments or is missing required arguments.
cannotDisseminateFormat - The value of the metadataPrefix argument is not supported by the item identified by the value of the identifier argument.
idDoesNotExist - The value of the identifier argument is unknown or illegal in this repository.
......
package org.swissbib.memobase.oai.response
import java.time.Instant
import com.typesafe.config.{ConfigObject, ConfigValue}
import org.swissbib.memobase.oai.common.util.OaiConfigSets
import org.swissbib.memobase.oai.runner.OaiRequestRunner
import scala.xml.{Elem, Node}
import scala.xml.transform.{RewriteRule, RuleTransformer}
......@@ -39,7 +43,7 @@ case class GetRecordResponse(override val oaiRequestRunner: OaiRequestRunner) ex
override def toString: String = s"Ich bin eine GetRecord response mit Header für : ${oaiRequestRunner.request.verb} "
override def createRequestTag: Elem =
<request verb="GetRecord">put the request arguments as text</request>
<request verb="GetRecord">{oaiRequestRunner.repository.oaiConfig.identify.baseUrl}</request>
override def createResponse: Seq[Node] = {
......@@ -56,7 +60,7 @@ case class IdentifyResponse(override val oaiRequestRunner: OaiRequestRunner) ext
override def toString: String = s"Ich bin eine Identify response mit Header für : ${oaiRequestRunner.request.verb} "
override def createRequestTag: Elem =
<request verb="Identify">{oaiRequestRunner.request.verb}</request>
<request verb="Identify">{oaiRequestRunner.repository.oaiConfig.identify.baseUrl}</request>
override def createResponse: Seq[Node] = {
......@@ -98,7 +102,7 @@ case class ListIdentifiersResponse(override val oaiRequestRunner: OaiRequestRunn
override def toString: String = s"Ich bin eine ListIdentifiers response mit Header für : ${oaiRequestRunner.request.verb} "
override def createRequestTag: Elem =
<request verb="ListIdentifiers">put the request arguments as text</request>
<request verb="ListIdentifiers">{oaiRequestRunner.repository.oaiConfig.identify.baseUrl}</request>
override def createResponse: Seq[Node] = {
......@@ -112,12 +116,38 @@ case class ListMetadaFormatsResponse(override val oaiRequestRunner: OaiRequestRu
override def toString: String = s"Ich bin eine ListMetadaFormats response mit Header für : ${oaiRequestRunner.request.verb} "
override def createRequestTag: Elem =
<request verb="ListMetadataFormats">put the request arguments as text</request>
<request verb="ListMetadataFormats">{oaiRequestRunner.repository.oaiConfig.identify.baseUrl}</request>
override def createResponse: Seq[Node] = {
//todo create the body using the executed action in repository
createOaiFrame
val oaiFrame = createOaiFrame
val sets: Seq[ConfigObject] = oaiRequestRunner.repository.oaiConfig.prefixes.prefixes
val configTuples = sets.map(f => (f.get("metadataPrefix"),
f.get("schema"),
f.get("metadataNamespace")))
val verbBody: RewriteRule = new RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
case elem: Elem if elem.label == "request" =>
elem ++ <ListMetadataFormats>
{configTuples.map(tuple =>
<metadataFormat>
<metadataPrefix>{tuple._1.unwrapped()}</metadataPrefix>
<schema>{tuple._2.unwrapped()}</schema>
<metadataNamespace>{tuple._2.unwrapped()}</metadataNamespace>
</metadataFormat>
)}
</ListMetadataFormats>
case n => n
}
}
new RuleTransformer(verbBody).transform(oaiFrame)
}
}
......@@ -126,7 +156,7 @@ case class ListRecordsResponse(override val oaiRequestRunner: OaiRequestRunner)
override def toString: String = s"Ich bin eine ListRecords response mit Header für : ${oaiRequestRunner.request.verb} "
override def createRequestTag: Elem =
<request verb="ListRecords">put the request arguments as text</request>
<request verb="ListRecords">{oaiRequestRunner.repository.oaiConfig.identify.baseUrl}</request>
override def createResponse: Seq[Node] = {
......@@ -140,12 +170,33 @@ case class ListSetsResponse(override val oaiRequestRunner: OaiRequestRunner) ext
override def toString: String = s"Ich bin eine ListSets response mit Header für : ${oaiRequestRunner.request.verb} "
override def createRequestTag: Elem =
<request verb="ListSets">put the request arguments as text</request>
<request verb="ListSets">{oaiRequestRunner.repository.oaiConfig.identify.baseUrl}</request>
override def createResponse: Seq[Node] = {
//todo create the body using the executed action in repository
createOaiFrame
val oaiFrame = createOaiFrame
val sets: Seq[ConfigObject] = oaiRequestRunner.repository.oaiConfig.sets.sets
val configTuples: Seq[(ConfigValue, ConfigValue)] = sets.map(f => (f.get("spec"),f.get("name")))
val verbBody: RewriteRule = new RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
case elem: Elem if elem.label == "request" =>
elem ++ <ListSets>
{configTuples.map(tuple =>
<set>
<setSpec>{tuple._1.unwrapped()}</setSpec>
<setName>{tuple._2.unwrapped()}</setName>
</set>
)}
</ListSets>
case n => n
}
}
new RuleTransformer(verbBody).transform(oaiFrame)
}
}
......
......@@ -37,8 +37,40 @@ oaiconfigs: {
xsi_schemaLocation: "http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"
}
sets: ["all"]
metadataPrefix: ["edm"]
sets: [
{
"spec": "allEuropeana"
"name": "resources relevant and defined for Europeana"
},
{
"spec": "srftagesschau"
"name": "Tagesschausendungen SRF"
},
{
"spec": "swiradio"
"name": "Radiobestand swissinfo"
}
]
metadataPrefix: [
{
"metadataPrefix": "edm"
"schema": "to be defined"
"metadataNamespace": "to be defined"
},
{
"metadataPrefix": "rico"
"schema": "to be defined"
"metadataNamespace": "to be defined"
}
]
identify: {
repositoryName: "memobase OAI repositories"
baseURL: "http://localhost:9000"
......
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