1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.datamodel.ifs2;
20
21 import java.io.IOException;
22 import java.util.Date;
23
24 import org.jdom2.JDOMException;
25 import org.mycore.common.MCRUsageException;
26 import org.mycore.common.content.MCRByteContent;
27 import org.mycore.common.content.MCRContent;
28 import org.mycore.common.content.streams.MCRByteArrayOutputStream;
29 import org.mycore.datamodel.common.MCRAbstractMetadataVersion;
30 import org.tmatesoft.svn.core.SVNException;
31 import org.tmatesoft.svn.core.io.SVNRepository;
32
33 import jakarta.xml.bind.annotation.XmlAccessType;
34 import jakarta.xml.bind.annotation.XmlAccessorType;
35 import jakarta.xml.bind.annotation.XmlRootElement;
36
37
38
39
40
41
42
43 @XmlRootElement(name = "revision")
44 @XmlAccessorType(XmlAccessType.FIELD)
45 public class MCRMetadataVersion extends MCRAbstractMetadataVersion<MCRVersionedMetadata> {
46
47 public MCRMetadataVersion(MCRVersionedMetadata vm, String revision, String user, Date date, char type) {
48 super(vm, revision, user, date, type);
49 }
50
51
52
53
54
55
56
57
58 @Override
59 public MCRContent retrieve() throws IOException {
60 if (getType() == DELETED) {
61 String msg = "You can not retrieve a deleted version, retrieve a previous version instead";
62 throw new MCRUsageException(msg);
63 }
64 try {
65 SVNRepository repository = vm.getStore().getRepository();
66 MCRByteArrayOutputStream baos = new MCRByteArrayOutputStream();
67 repository.getFile(vm.getStore().getSlotPath(vm.getID()), Long.parseLong(getRevision()), null, baos);
68 baos.close();
69 return new MCRByteContent(baos.getBuffer(), 0, baos.size(), getDate().getTime());
70 } catch (SVNException e) {
71 throw new IOException(e);
72 }
73 }
74
75
76
77
78
79
80
81 @Override
82 public void restore() throws IOException, JDOMException {
83 vm.update(retrieve());
84 }
85 }