1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.datamodel.common;
20
21 import java.io.IOException;
22 import java.util.Date;
23 import java.util.stream.Stream;
24
25 import org.jdom2.JDOMException;
26 import org.mycore.common.MCRUsageException;
27 import org.mycore.common.content.MCRContent;
28
29 import jakarta.xml.bind.annotation.XmlAccessType;
30 import jakarta.xml.bind.annotation.XmlAccessorType;
31 import jakarta.xml.bind.annotation.XmlAttribute;
32 import jakarta.xml.bind.annotation.XmlRootElement;
33 import jakarta.xml.bind.annotation.XmlTransient;
34
35
36
37
38
39
40
41 @XmlRootElement(name = "revision")
42 @XmlAccessorType(XmlAccessType.FIELD)
43 public abstract class MCRAbstractMetadataVersion<T> {
44
45 protected enum Type {
46 created(MCRAbstractMetadataVersion.CREATED),
47 modified(MCRAbstractMetadataVersion.UPDATED),
48 deleted(MCRAbstractMetadataVersion.DELETED);
49
50 private final char charValue;
51
52 Type(char a) {
53 this.charValue = a;
54 }
55
56 public static Type fromValue(char a) {
57 return Stream.of(values()).filter(t -> t.charValue == a)
58 .findAny()
59 .orElseThrow(IllegalArgumentException::new);
60 }
61 }
62
63
64
65
66 @XmlTransient
67 protected T vm;
68
69
70
71
72 @XmlAttribute(name = "r")
73 protected String revision;
74
75
76
77
78 @XmlAttribute
79 protected String user;
80
81
82
83
84 @XmlAttribute
85 protected Date date;
86
87
88
89
90 @XmlAttribute()
91 protected Type type;
92
93
94
95
96 public static final char CREATED = 'A';
97
98
99
100
101 public static final char UPDATED = 'M';
102
103
104
105
106 public static final char DELETED = 'D';
107
108
109 @SuppressWarnings("unused")
110 private MCRAbstractMetadataVersion() {
111 }
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 public MCRAbstractMetadataVersion(T vm, String revision, String user, Date date, char type) {
128 this.vm = vm;
129 this.revision = revision;
130 this.user = user;
131 this.date = date;
132 this.type = Type.fromValue(type);
133 }
134
135
136
137
138
139
140 public T getMetadataObject() {
141 return vm;
142 }
143
144
145
146
147
148
149
150
151 public char getType() {
152 return type.charValue;
153 }
154
155
156
157
158
159
160 public String getRevision() {
161 return revision;
162 }
163
164
165
166
167
168
169 public String getUser() {
170 return user;
171 }
172
173
174
175
176
177
178 public Date getDate() {
179 return date;
180 }
181
182
183
184
185
186
187
188
189 abstract public MCRContent retrieve() throws IOException;
190
191
192
193
194
195
196
197 abstract public void restore() throws IOException, JDOMException;
198 }