GetRecordRunner.scala 1.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * 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.runner

25
26
import modules.{OAIContent, OaiRepository}
import org.swissbib.memobase.oai.common.validation.{CheckedGetRecordParameter, NoContentForQueryParameter, OAIErrorCode}
27
28
29
30
31
32
33
34
import org.swissbib.memobase.oai.response.{GetRecordResponse, OaiResponse}
import play.api.Configuration

import scala.util.{Failure, Success}

case class GetRecordRunner(parameter: CheckedGetRecordParameter) extends OaiRunner {
  override def run()(implicit config: Configuration, repository: OaiRepository): OaiResponse = {

35
    //noinspection ScalaStyle
36
    repository.getRecord(parameter.identifier,parameter.metadataPrefix) match {
37
      case Success(result: OAIContent) =>
38
        GetRecordResponse(config, repository, result,parameter)
39
40
41
42
43
44
45
46
      case Failure(exception) =>
        exception match {
          case _: GetRecordFailure => NoContentForQueryRunner(NoContentForQueryParameter(parameter.verb
            , parameter.allQueryParameter
            , OAIErrorCode.ID_DOES_NOT_EXIST)).run()
            //todo: make something useful for system errors
          case _  => ???
        }
47
48
49
    }
  }
}