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.module.delta;
35
36 import info.magnolia.jcr.util.NodeTypes;
37 import info.magnolia.module.InstallContext;
38 import info.magnolia.repository.RepositoryConstants;
39
40 import javax.jcr.RepositoryException;
41 import javax.jcr.Session;
42 import javax.jcr.nodetype.NodeDefinition;
43 import javax.jcr.nodetype.NodeType;
44 import javax.jcr.nodetype.NodeTypeManager;
45
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48
49
50
51
52
53 public class NoSameNameSiblingsCondition extends AbstractCondition {
54
55 private static final Logger log = LoggerFactory.getLogger(NoSameNameSiblingsCondition.class);
56
57 public static final String[] NODETYPES = new String[] {
58 NodeTypes.Content.NAME,
59 NodeTypes.ContentNode.NAME,
60 NodeTypes.Folder.NAME,
61 NodeTypes.Page.NAME,
62 NodeTypes.Area.NAME,
63 NodeTypes.Component.NAME,
64 NodeTypes.User.NAME,
65 NodeTypes.Role.NAME,
66 NodeTypes.Group.NAME,
67 "mgnl:reserve"
68 };
69
70 public static final String[] WORKSPACES = new String[] {
71 RepositoryConstants.CONFIG,
72 RepositoryConstants.WEBSITE,
73 RepositoryConstants.USERS,
74 RepositoryConstants.USER_GROUPS,
75 RepositoryConstants.USER_ROLES,
76 RepositoryConstants.VERSION_STORE
77 };
78
79 public NoSameNameSiblingsCondition() {
80 super("Same name siblings must be not allowed.", "Ensures that same name siblings are not allowed in Magnolia node types.");
81 }
82
83 @Override
84 public boolean check(InstallContext installContext) {
85
86 try {
87 for (String workspace : WORKSPACES) {
88 Session session = installContext.getJCRSession(workspace);
89 NodeTypeManager ntManager = session.getWorkspace().getNodeTypeManager();
90 for (String nodetypeName : NODETYPES) {
91 NodeType nodetype = ntManager.getNodeType(nodetypeName);
92 for (NodeDefinition def : nodetype.getChildNodeDefinitions()) {
93 if (def.allowsSameNameSiblings()) {
94 log.error("Child definition of the [{}] node type in workspace [{}] allows same name siblings.", nodetypeName, workspace);
95 return false;
96 }
97 }
98 }
99 }
100 } catch (RepositoryException ex) {
101 log.error("Cannot verify that same name siblings are not allowed.", ex);
102 return false;
103 }
104
105 return true;
106 }
107
108 }