1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
36
37
38
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
57
58 public String getPutCode() {
59 return putCode;
60 }
61
62
63
64
65 public MCRWorkSource getSource() {
66 return source;
67 }
68
69 void setSource(MCRWorkSource source) {
70 this.source = source;
71 }
72
73
74
75
76 public Element getMODS() {
77 return mods;
78 }
79
80 void setMODS(Element mods) {
81 this.mods = mods;
82 }
83
84
85
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
94
95
96 public void fetchDetails() throws JDOMException, IOException, SAXException {
97 orcid.getFetcher().fetchDetails(this);
98 }
99
100
101
102
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
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 }