1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.cms.core.version;
35
36 import info.magnolia.jcr.decoration.ContentDecorator;
37 import info.magnolia.jcr.decoration.ContentDecoratorWorkspaceWrapper;
38 import info.magnolia.jcr.util.NodeTypes;
39 import info.magnolia.jcr.util.NodeUtil;
40
41 import javax.jcr.Node;
42 import javax.jcr.RepositoryException;
43 import javax.jcr.UnsupportedRepositoryOperationException;
44 import javax.jcr.Workspace;
45 import javax.jcr.version.VersionManager;
46
47
48
49
50 public class MgnlVersioningWorkspaceWrapper extends ContentDecoratorWorkspaceWrapper {
51
52 protected MgnlVersioningWorkspaceWrapper(Workspace workspace, ContentDecorator contentDecorator) {
53 super(workspace, contentDecorator);
54 }
55
56 @Override
57 public VersionManager getVersionManager() throws UnsupportedRepositoryOperationException, RepositoryException {
58 throw new UnsupportedOperationException("Don't use javax.jcr.version.VersionManager directly. Instead of it use info.magnolia.cms.core.version.VersionManager");
59 }
60
61 @Override
62 public void copy(String srcAbsPath, String destAbsPath) throws RepositoryException {
63 super.copy(srcAbsPath, destAbsPath);
64 removeHasVersionMixin(destAbsPath);
65 }
66
67 @Override
68 public void copy(String srcWorkspace, String srcAbsPath, String destAbsPath) throws RepositoryException {
69 super.copy(srcWorkspace, srcAbsPath, destAbsPath);
70 removeHasVersionMixin(destAbsPath);
71 }
72
73 private void removeHasVersionMixin(String destAbsPath) throws RepositoryException {
74 Node node = getSession().getNode(destAbsPath);
75 NodeUtil.visit(node, nodeToVisit -> {
76 if (NodeUtil.hasMixin(nodeToVisit, NodeTypes.HasVersion.NAME)) {
77 nodeToVisit.removeMixin(NodeTypes.HasVersion.NAME);
78 nodeToVisit.getSession().save();
79 }
80 });
81 }
82 }