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.orcid.works;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.jdom2.Element;
25  import org.mycore.mods.merger.MCRMergeTool;
26  
27  /**
28   * Represents a group of works as the activities:group element returned in the ORCID response to fetch work summaries.
29   * ORCID groups multiple works from different sources that are assumed to represent the same publication.
30   *
31   * @author Frank L\u00FCtzenkirchen
32   */
33  public class MCRGroupOfWorks {
34  
35      private List<MCRWork> works = new ArrayList<>();
36  
37      void add(MCRWork work) {
38          works.add(work);
39      }
40  
41      /**
42       * Returns the works grouped together here.
43       * All these work entries are assumed to represent the same publication, but from different sources.
44       */
45      public List<MCRWork> getWorks() {
46          return works;
47      }
48  
49      /**
50       * Returns a single mods:mods representation of the publication represented by this group.
51       * The MODS from each is merged together.
52       */
53      public Element buildMergedMODS() {
54          Element mods = works.get(0).getMODS().clone();
55          for (int i = 1; i < works.size(); i++) {
56              MCRMergeTool.merge(mods, works.get(i).getMODS());
57          }
58          return mods;
59      }
60  
61      public List<Element> buildUnmergedMODS() {
62          List<Element> modslist = new ArrayList<>();
63          for (MCRWork work : works) {
64              modslist.add(work.getMODS().detach());
65          }
66          return modslist;
67      }
68  }