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.io.IOException;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.jdom2.Element;
26  import org.jdom2.JDOMException;
27  import org.mycore.common.MCRConstants;
28  import org.mycore.datamodel.metadata.MCRMetadataManager;
29  import org.mycore.datamodel.metadata.MCRObjectID;
30  import org.mycore.orcid.MCRORCIDException;
31  import org.mycore.orcid.MCRORCIDProfile;
32  import org.xml.sax.SAXException;
33  
34  /**
35   * Represents a single "work", that means a publication within the "works" section of an ORCID profile,
36   * from a single source.
37   *
38   * @author Frank L\u00FCtzenkirchen
39   */
40  public class MCRWork {
41  
42      private MCRORCIDProfile orcid;
43  
44      private String putCode;
45  
46      private Element mods;
47  
48      private MCRWorkSource source;
49  
50      MCRWork(MCRORCIDProfile orcid, String putCode) {
51          this.orcid = orcid;
52          this.putCode = putCode;
53      }
54  
55      /**
56       * Returns the put code, which is the unique identifier of this work within the ORCID profile
57       */
58      public String getPutCode() {
59          return putCode;
60      }
61  
62      /**
63       * Returns the client application that created this work entry.
64       */
65      public MCRWorkSource getSource() {
66          return source;
67      }
68  
69      void setSource(MCRWorkSource source) {
70          this.source = source;
71      }
72  
73      /**
74       * Returns the MODS representation of the work's publication data
75       */
76      public Element getMODS() {
77          return mods;
78      }
79  
80      void setMODS(Element mods) {
81          this.mods = mods;
82      }
83  
84      /**
85       * Returns all mods:identifier elements of this work.
86       */
87      public List<Element> getIdentifiers() {
88          List<Element> identifiers = getMODS().getChildren("identifier", MCRConstants.MODS_NAMESPACE);
89          return Collections.unmodifiableList(identifiers);
90      }
91  
92      /**
93       * Fetches the work's details with the complete publication data from the ORCID profile.
94       * Initially, only the work summary was fetched.
95       */
96      public void fetchDetails() throws JDOMException, IOException, SAXException {
97          orcid.getFetcher().fetchDetails(this);
98      }
99  
100     /**
101      * If this work's source is this MyCoRe application,
102      * updates the work in the remote ORCID profile from the local MyCoRe object
103      */
104     public void update(MCRObjectID objectID) throws IOException, SAXException, JDOMException {
105         if (!source.isThisApplication()) {
106             throw new MCRORCIDException("can not update that work, is not from us");
107         }
108         if (!MCRMetadataManager.exists(objectID)) {
109             throw new MCRORCIDException("can not update that work, object " + objectID + " does not exist locally");
110         }
111         orcid.getPublisher().update(this, objectID);
112     }
113 
114     /** Deletes this work from the remote ORCID profile */
115     public void delete() throws IOException, JDOMException, SAXException {
116         if (!source.isThisApplication()) {
117             throw new MCRORCIDException("can not delete that work, is not from us");
118         }
119         orcid.getPublisher().delete(this);
120     }
121 }