View Javadoc
1   /*
2    * This file is part of ***  M y C o R e  ***
3    * See http://www.mycore.de/ for details.
4    *
5    * MyCoRe is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    *
10   * MyCoRe is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with MyCoRe.  If not, see <http://www.gnu.org/licenses/>.
17   */
18  
19  package org.mycore.mods.enrichment;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  /**
25   * A data source is able to return publication data in MODS format
26   * for a given publication identifier. A data source may support more than
27   * one identifier, e.g. DOI and PubMed ID for PubMed as a data source:
28   *
29   * MCR.MODS.EnrichmentResolver.DataSource.PubMed.IdentifierTypes=doi pubmed
30   *
31   * For each supported identifier type, the data source has a resolver URI 
32   * that returns MODS data for that identifier type. 
33   * 
34   * Depending on the global configuration property  
35   * MCR.MODS.EnrichmentResolver.DefaultStopOnFirstResult=true|false
36   * a data source will stop retrieving data after any first identifier 
37   * returned valid data, or will continue to retrieve data for all identifiers
38   * it is configured for.
39   * 
40   * This global configuration can be overwritten per data source, e.g.
41   * MCR.MODS.EnrichmentResolver.DataSource.ZDB.StopOnFirstResult=false
42   *   
43   * @see MCRIdentifierResolver
44   *
45   * @author Frank L\u00FCtzenkirchen
46   */
47  class MCRDataSource {
48  
49      private String sourceID;
50  
51      private boolean stopOnFirstResult = true;
52  
53      private List<MCRIdentifierResolver> resolvers = new ArrayList<>();
54  
55      MCRDataSource(String sourceID, boolean stopOnFirstResult) {
56          this.sourceID = sourceID;
57          this.stopOnFirstResult = stopOnFirstResult;
58      }
59  
60      boolean shouldStopOnFirstResult() {
61          return stopOnFirstResult;
62      }
63  
64      void addResolver(MCRIdentifierResolver resolver) {
65          resolvers.add(resolver);
66      }
67  
68      /** Returns all resolvers to get publication data for a given identifier */
69      List<MCRIdentifierResolver> getResolvers() {
70          return resolvers;
71      }
72  
73      String getID() {
74          return sourceID;
75      }
76  
77      public String toString() {
78          return "data source " + sourceID;
79      }
80  }