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

first test for deployment on k8s

parent 20fc2363
Pipeline #23466 passed with stage
in 2 minutes and 19 seconds
...@@ -154,7 +154,7 @@ trait ElasticsearchComponent extends OaiRepository { ...@@ -154,7 +154,7 @@ trait ElasticsearchComponent extends OaiRepository {
val getRequest = new GetRequest(index, identifier) val getRequest = new GetRequest(index, identifier)
val getResponse = client.get.get(getRequest, RequestOptions.DEFAULT) val getResponse = client.get.get(getRequest, RequestOptions.DEFAULT)
if (getResponse.getSource.isEmpty) { if (getResponse.isSourceEmpty) {
throw GetRecordFailure("record was not found") throw GetRecordFailure("record was not found")
} else { } else {
val hit = getResponse.getSource.asScala val hit = getResponse.getSource.asScala
......
/*
* generic OAI Server - agnostic in relation to the data repository
* initially created for memobase project
*
* Copyright (C) 2021 UB Basel
*
* 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.swissbib.memobase.oai.response
import modules.{OAIContent, OaiRepository}
import org.swissbib.memobase.oai.common.validation.{NoContentForQueryParameter, OAIErrorCode, OaiParameterBase}
import play.api.Configuration
import scala.xml.transform.{RewriteRule, RuleTransformer}
import scala.xml.{Elem, Node}
case class NoContentForQueryResponse (config: Configuration
,repository: OaiRepository
,parameter: NoContentForQueryParameter) extends OaiResponse(repository.oaiConfig
, parameter) {
override def toString: String = s"Ich bin eine no content response mit Header für : " +
s"${parameter.allQueryParameter.getOrElse("verb","")} "
override def createResponse: Seq[Node] = {
val oaiFrame = createOaiFrame
val verbBody: RewriteRule = new RewriteRule {
override def transform(n: Node): Seq[Node] = n match {
case elem: Elem if elem.label == "request" =>
elem ++ <error code={s"${parameter.errorCode}"}/>
case n => n
}
}
new RuleTransformer(verbBody).transform(oaiFrame)
}
}
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
package org.swissbib.memobase.oai.runner package org.swissbib.memobase.oai.runner
import modules.OaiRepository import modules.{OAIContent, OaiRepository}
import org.swissbib.memobase.oai.common.validation.CheckedGetRecordParameter import org.swissbib.memobase.oai.common.validation.{CheckedGetRecordParameter, NoContentForQueryParameter, OAIErrorCode}
import org.swissbib.memobase.oai.response.{GetRecordResponse, OaiResponse} import org.swissbib.memobase.oai.response.{GetRecordResponse, OaiResponse}
import play.api.Configuration import play.api.Configuration
...@@ -32,21 +32,18 @@ import scala.util.{Failure, Success} ...@@ -32,21 +32,18 @@ import scala.util.{Failure, Success}
case class GetRecordRunner(parameter: CheckedGetRecordParameter) extends OaiRunner { case class GetRecordRunner(parameter: CheckedGetRecordParameter) extends OaiRunner {
override def run()(implicit config: Configuration, repository: OaiRepository): OaiResponse = { override def run()(implicit config: Configuration, repository: OaiRepository): OaiResponse = {
//noinspection ScalaStyle
repository.getRecord(parameter.identifier,parameter.metadataPrefix) match { repository.getRecord(parameter.identifier,parameter.metadataPrefix) match {
case Success(result) => case Success(result: OAIContent) =>
GetRecordResponse(config, repository, result,parameter) GetRecordResponse(config, repository, result,parameter)
case Failure(exception) =>
case Failure(exception) => ??? exception match {
//GetRecordResponse(this,null) case _: GetRecordFailure => NoContentForQueryRunner(NoContentForQueryParameter(parameter.verb
/* , parameter.allQueryParameter
NoContentForQueryReq( , OAIErrorCode.ID_DOES_NOT_EXIST)).run()
config //todo: make something useful for system errors
,repository case _ => ???
, NoContentForQueryParameter(request.parameter.verb }
,request.parameter.allQueryParameter
, OAIErrorCode.ID_DOES_NOT_EXIST.code)).createResponse(config,repository)
*/
} }
} }
} }
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
package org.swissbib.memobase.oai.runner package org.swissbib.memobase.oai.runner
import modules.OaiRepository import modules.OaiRepository
import org.swissbib.memobase.oai.common.validation.{CheckedListIdentifiersParameter, CheckedListIdentifiersParameterExclusive} import org.swissbib.memobase.oai.common.validation.{CheckedListIdentifiersParameter, CheckedListIdentifiersParameterExclusive, NoContentForQueryParameter, OAIErrorCode}
import org.swissbib.memobase.oai.response.{ListIdentifiersResponse, OaiResponse} import org.swissbib.memobase.oai.response.{ListIdentifiersResponse, ListRecordsResponse, OaiResponse}
import play.api.Configuration import play.api.Configuration
import scala.util.{Failure, Success} import scala.util.{Failure, Success}
...@@ -41,12 +41,25 @@ case class ListIdentifiersRunner(parameter: CheckedListIdentifiersParameter) ext ...@@ -41,12 +41,25 @@ case class ListIdentifiersRunner(parameter: CheckedListIdentifiersParameter) ext
resumptionToken = Option.empty, resumptionToken = Option.empty,
metadataPrefix = parameter.metadataPrefix) match { metadataPrefix = parameter.metadataPrefix) match {
case Success(requestResult: ResultList) => case Success(requestResult: ResultList) =>
ListIdentifiersResponse(config,repository,requestResult, parameter) requestResult.result match {
//empty result
case Nil => NoContentForQueryRunner(NoContentForQueryParameter(parameter.verb
, parameter.allQueryParameter
,OAIErrorCode.NO_RECORDS_MATCH)).run()
//at least one result
case _ => ListIdentifiersResponse(config,repository,requestResult, parameter)
}
case Failure(exception) => ??? case Failure(exception) => ???
//todo: make something useful
//ListRecordsResponse(config,repository,null, repository.oaiConfig,parameter) //ListRecordsResponse(config,repository,null, repository.oaiConfig,parameter)
} }
} }
} }
...@@ -59,7 +72,15 @@ case class ListIdentifiersExclusiveRunner(parameter: CheckedListIdentifiersParam ...@@ -59,7 +72,15 @@ case class ListIdentifiersExclusiveRunner(parameter: CheckedListIdentifiersParam
set = Option.empty, set = Option.empty,
resumptionToken = Option(parameter.resumptionToken), resumptionToken = Option(parameter.resumptionToken),
metadataPrefix = "4711") match { metadataPrefix = "4711") match {
case Success(requestResult) => ListIdentifiersResponse(config,repository,requestResult, parameter) case Success(requestResult) =>
requestResult.result match {
//empty result although thi should not happen - one never knows...
case Nil => NoContentForQueryRunner(NoContentForQueryParameter(parameter.verb
, parameter.allQueryParameter
,OAIErrorCode.NO_RECORDS_MATCH)).run()
//at least one result
case _ => ListIdentifiersResponse(config,repository,requestResult, parameter)
}
case Failure(exception) => ??? //ListRecordsResponse(this, null) case Failure(exception) => ??? //ListRecordsResponse(this, null)
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
package org.swissbib.memobase.oai.runner package org.swissbib.memobase.oai.runner
import modules.OaiRepository import modules.OaiRepository
import org.swissbib.memobase.oai.common.validation.{CheckedListRecordsParameter, CheckedListRecordsParameterExclusive} import org.swissbib.memobase.oai.common.validation.{CheckedListRecordsParameter, CheckedListRecordsParameterExclusive, NoContentForQueryParameter, OAIErrorCode}
import org.swissbib.memobase.oai.response.{ListRecordsResponse, OaiResponse} import org.swissbib.memobase.oai.response.{ListRecordsResponse, OaiResponse}
import play.api.Configuration import play.api.Configuration
...@@ -42,7 +42,15 @@ case class ListRecordsRunner(parameter: CheckedListRecordsParameter) extends Oai ...@@ -42,7 +42,15 @@ case class ListRecordsRunner(parameter: CheckedListRecordsParameter) extends Oai
Option.empty, Option.empty,
parameter.metadataPrefix) match { parameter.metadataPrefix) match {
case Success(requestResult: ResultList) => case Success(requestResult: ResultList) =>
ListRecordsResponse(config,repository,requestResult, parameter) //todo: make it mor functional
requestResult.result match {
//no result
case Nil => NoContentForQueryRunner(NoContentForQueryParameter(parameter.verb
, parameter.allQueryParameter
,OAIErrorCode.NO_RECORDS_MATCH)).run()
//at least one result
case _ => ListRecordsResponse(config,repository,requestResult, parameter)
}
case Failure(exception) => ??? case Failure(exception) => ???
//ListRecordsResponse(config,repository,null, repository.oaiConfig,parameter) //ListRecordsResponse(config,repository,null, repository.oaiConfig,parameter)
} }
...@@ -51,8 +59,6 @@ case class ListRecordsRunner(parameter: CheckedListRecordsParameter) extends Oai ...@@ -51,8 +59,6 @@ case class ListRecordsRunner(parameter: CheckedListRecordsParameter) extends Oai
case class ListRecordsExclusiveRunner(parameter: CheckedListRecordsParameterExclusive) extends OaiRunner { case class ListRecordsExclusiveRunner(parameter: CheckedListRecordsParameterExclusive) extends OaiRunner {
override def run()(implicit config: Configuration, repository: OaiRepository): OaiResponse = { override def run()(implicit config: Configuration, repository: OaiRepository): OaiResponse = {
//todo: this is only for first implementation reasons to make it runnable
repository.listRecords( repository.listRecords(
from = Option.empty, from = Option.empty,
...@@ -60,7 +66,16 @@ case class ListRecordsExclusiveRunner(parameter: CheckedListRecordsParameterExcl ...@@ -60,7 +66,16 @@ case class ListRecordsExclusiveRunner(parameter: CheckedListRecordsParameterExcl
set = Option.empty, set = Option.empty,
resumptionToken = Option(parameter.resumptionToken), resumptionToken = Option(parameter.resumptionToken),
metadataPrefix = "4711") match { metadataPrefix = "4711") match {
case Success(requestResult) => ListRecordsResponse(config,repository,requestResult, parameter) case Success(requestResult) =>
requestResult.result match {
//no result - although this should not happen in reality
case Nil => NoContentForQueryRunner(NoContentForQueryParameter(parameter.verb
, parameter.allQueryParameter
,OAIErrorCode.NO_RECORDS_MATCH)).run()
//at least one result
case _ => ListRecordsResponse(config,repository,requestResult, parameter)
}
case Failure(exception) => ??? //ListRecordsResponse(this, null) case Failure(exception) => ??? //ListRecordsResponse(this, null)
} }
} }
......
...@@ -24,7 +24,7 @@ package org.swissbib.memobase.oai.runner ...@@ -24,7 +24,7 @@ package org.swissbib.memobase.oai.runner
import modules.OaiRepository import modules.OaiRepository
import org.swissbib.memobase.oai.common.validation.{BadArgumentsParameter, NoContentForQueryParameter} import org.swissbib.memobase.oai.common.validation.{BadArgumentsParameter, NoContentForQueryParameter}
import org.swissbib.memobase.oai.response.{BadArgumentsResponse, OaiResponse} import org.swissbib.memobase.oai.response.{BadArgumentsResponse, NoContentForQueryResponse, OaiResponse}
import play.api.Configuration import play.api.Configuration
...@@ -37,7 +37,8 @@ abstract class OaiRunner { ...@@ -37,7 +37,8 @@ abstract class OaiRunner {
case class NoContentForQueryRunner(parameter: NoContentForQueryParameter) extends OaiRunner { case class NoContentForQueryRunner(parameter: NoContentForQueryParameter) extends OaiRunner {
//todo: Es fehlt noch eine Response für no content //todo: Es fehlt noch eine Response für no content
override def run()(implicit config: Configuration, repository: OaiRepository): OaiResponse = ??? override def run()(implicit config: Configuration, repository: OaiRepository): OaiResponse =
NoContentForQueryResponse(config,repository,parameter)
} }
......
...@@ -23,8 +23,8 @@ elasticsearch { ...@@ -23,8 +23,8 @@ elasticsearch {
//template_prefix="production" //template_prefix="production"
//hosts: ["sb-ues5.swissbib.unibas.ch:8080","sb-ues6.swissbib.unibas.ch:8080","sb-ues7.swissbib.unibas.ch:8080","sb-ues8.swissbib.unibas.ch:8080"] //hosts: ["sb-ues5.swissbib.unibas.ch:8080","sb-ues6.swissbib.unibas.ch:8080","sb-ues7.swissbib.unibas.ch:8080","sb-ues8.swissbib.unibas.ch:8080"]
//hosts: ["mb-es1.memobase.unibas.ch:8080"] hosts: ["mb-es1.memobase.unibas.ch:8080"]
hosts: ["localhost:8080"] //hosts: ["localhost:8080"]
cluster: "test-memobase-search-cluster" # "weywot" cluster: "test-memobase-search-cluster" # "weywot"
index: "oai-v1" index: "oai-v1"
content: "application/json; charset=utf-8" content: "application/json; charset=utf-8"
......
...@@ -9,3 +9,8 @@ der Response type wird im Moment nach String umgesetzt - ein bisschen unschön. ...@@ -9,3 +9,8 @@ der Response type wird im Moment nach String umgesetzt - ein bisschen unschön.
[error] /home/swissbib/environment/code/swissbib.repositories/memoriav/gitlab/services/oai/app/controllers/OaiController.scala:44:9: Cannot write an instance of Seq[scala.xml.Node] to HTTP response. Try to define a Writeable[Seq[scala.xml.Node]] [error] /home/swissbib/environment/code/swissbib.repositories/memoriav/gitlab/services/oai/app/controllers/OaiController.scala:44:9: Cannot write an instance of Seq[scala.xml.Node] to HTTP response. Try to define a Writeable[Seq[scala.xml.Node]]
[error] Ok(response.createResponse).as("text/xml") [error] Ok(response.createResponse).as("text/xml")
*/ */
#### alte scala2 enumerations ansehen
https://pedrorijo.com/blog/scala-enums/
\ 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