ListIdentifiersRunner.scala 3.17 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
25
/*
 * 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

import modules.OaiRepository
26
27
import org.swissbib.memobase.oai.common.validation.{CheckedListIdentifiersParameter, CheckedListIdentifiersParameterExclusive, NoContentForQueryParameter, OAIErrorCode}
import org.swissbib.memobase.oai.response.{ListIdentifiersResponse, ListRecordsResponse, OaiResponse}
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import play.api.Configuration

import scala.util.{Failure, Success}

//CheckedListIdentifiersParameter
case class ListIdentifiersRunner(parameter: CheckedListIdentifiersParameter) extends OaiRunner {

  override def run()(implicit config: Configuration, repository: OaiRepository): OaiResponse = {

    repository.listIdentiers(
      from = parameter.from,
      until = parameter.until,
      set = parameter.set,
      resumptionToken = Option.empty,
      metadataPrefix = parameter.metadataPrefix) match {
      case Success(requestResult: ResultList) =>
44
45
46
47
48
49
50
51
        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)
        }
52
      case Failure(exception) => ???
53
54
55

        //todo: make something useful

56
57
58
59
      //ListRecordsResponse(config,repository,null, repository.oaiConfig,parameter)

    }

60
61
62



63
64
65
66
67
68
69
70
71
72
73
74
  }
}

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

    repository.listIdentiers(
      from = Option.empty,
      until = Option.empty,
      set = Option.empty,
      resumptionToken = Option(parameter.resumptionToken),
      metadataPrefix = "4711") match {
75
76
77
78
79
80
81
82
83
      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)
        }
84
85
86
87
      case Failure(exception) => ??? //ListRecordsResponse(this, null)
    }

}