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.pages.setup;
35
36 import info.magnolia.jcr.util.NodeTypes;
37 import info.magnolia.jcr.util.NodeUtil;
38 import info.magnolia.module.InstallContext;
39 import info.magnolia.module.delta.AbstractRepositoryTask;
40 import info.magnolia.module.delta.ArrayDelegateTask;
41 import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
42 import info.magnolia.module.delta.NodeExistsDelegateTask;
43 import info.magnolia.module.delta.PartialBootstrapTask;
44 import info.magnolia.module.delta.RemoveNodeTask;
45 import info.magnolia.module.delta.SetPropertyTask;
46 import info.magnolia.module.delta.TaskExecutionException;
47 import info.magnolia.pages.app.action.DeleteComponentAction;
48 import info.magnolia.pages.app.action.DeletePageItemAction;
49 import info.magnolia.repository.RepositoryConstants;
50
51 import javax.jcr.Node;
52 import javax.jcr.RepositoryException;
53 import javax.jcr.Session;
54
55
56
57
58 public class UpdatePageEditorActionAvailability extends ArrayDelegateTask {
59
60 private String bootstrapFile = "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml";
61 private String[] actions = {"editArea", "addArea", "deleteArea", "editComponent", "addComponent", "deleteComponent", "startMoveComponent", "stopMoveComponent", "showPreviousVersion"};
62 private String[] actionbarSections = {"pagePreviewActions", "pageActions", "areaActions", "componentActions", "pageDeleteActions"};
63 private String[] obsoleteActionbarSections = {"editableAreaActions", "optionalAreaActions", "optionalEditableAreaActions"};
64 private String[] unusedActions = {"redo", "undo", "copyComponent", "pasteComponent"};
65
66
67 public UpdatePageEditorActionAvailability() {
68 super("Bootstrap availability rules to page editor actions and actionbar sections.");
69
70 bootstrapActionAvailability();
71 bootstrapActionbarSectionAvailability();
72 deleteObsoleteActionbarSections();
73 deleteUnusedAction();
74
75 addTask(new NodeExistsDelegateTask("Update deleteArea action.", "/modules/pages/apps/pages/subApps/detail/actions/deleteArea",
76 new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/detail/actions/deleteArea", "implementationClass", DeletePageItemAction.class.getName())));
77
78 addTask(new NodeExistsDelegateTask("Update deleteArea action.", "/modules/pages/apps/pages/subApps/detail/actions/deleteComponent",
79 new CheckAndModifyPropertyValueTask("/modules/pages/apps/pages/subApps/detail/actions/deleteComponent", "implementationClass", DeleteComponentAction.class.getName(), DeletePageItemAction.class.getName())));
80
81
82 addTask(new UpdateAreaSectionActionsTask());
83
84
85 addTask(new NodeExistsDelegateTask("Bootstrap new pageNodeAreaActions.", "/modules/pages/apps/pages/subApps/detail/actionbar/sections",
86 new PartialBootstrapTask("Bootstrap pageNodeAreaActions actionbar section.",
87 bootstrapFile,
88 "/pages/subApps/detail/actionbar/sections/pageNodeAreaActions"))
89 );
90
91 addTask(new NodeExistsDelegateTask("Bootstrap new editPageNodeArea action.", "/modules/pages/apps/pages/subApps/detail/actions/",
92 new PartialBootstrapTask("Bootstrap pageNodeAreaActions actionbar section.",
93 bootstrapFile,
94 "/pages/subApps/detail/actions/editPageNodeArea"))
95 );
96 }
97
98 private void deleteUnusedAction() {
99 for (String action : unusedActions) {
100 String actionPath = "/modules/pages/apps/pages/subApps/detail/actions/" + action;
101
102 addTask(new NodeExistsDelegateTask(String.format("Remove unused action: %s", action), actionPath,
103 new RemoveNodeTask("", actionPath))
104 );
105 }
106 }
107
108 private void bootstrapActionAvailability() {
109 for (String action : actions) {
110 String actionPath = "/pages/subApps/detail/actions/" + action;
111
112 addTask(new NodeExistsDelegateTask(String.format("Update action availability for %s action.", action), "/modules/pages/apps" + actionPath,
113 new PartialBootstrapTask(String.format("Bootstrap availability for %s action.", action),
114 bootstrapFile,
115 actionPath + "/availability"))
116 );
117 }
118 }
119
120 private void bootstrapActionbarSectionAvailability() {
121 for (String section : actionbarSections) {
122 String sectionPath = "/pages/subApps/detail/actionbar/sections/" + section;
123
124 addTask(new NodeExistsDelegateTask(String.format("Update action availability for %s section.", section), "/modules/pages/apps" + sectionPath,
125 new PartialBootstrapTask(String.format("Bootstrap availability for %s action.", section),
126 bootstrapFile,
127 sectionPath + "/availability"))
128 );
129 }
130 }
131
132 private void deleteObsoleteActionbarSections() {
133 for (String section : obsoleteActionbarSections) {
134 String sectionPath = "/modules/pages/apps/pages/subApps/detail/actionbar/sections/" + section;
135
136 addTask(new NodeExistsDelegateTask(String.format("Remove obsolete page editor actionbar section: %s", section), sectionPath,
137 new RemoveNodeTask("", sectionPath))
138 );
139 }
140 }
141
142
143
144
145 private class UpdateAreaSectionActionsTask extends AbstractRepositoryTask {
146
147 public UpdateAreaSectionActionsTask() {
148 super("Update page editor actionbar", "Add missing actions to areaActions section.");
149 }
150
151 @Override
152 protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException {
153 Session session = installContext.getJCRSession(RepositoryConstants.CONFIG);
154 String areaSection = "/modules/pages/apps/pages/subApps/detail/actionbar/sections/areaActions";
155
156 if (!session.nodeExists(areaSection)) {
157 return;
158 }
159 Node areaActions = session.getNode(areaSection);
160 Node groups = NodeUtil.createPath(areaActions, "groups", NodeTypes.ContentNode.NAME);
161
162 NodeUtil.createPath(groups, "editingActions/items/editArea", NodeTypes.ContentNode.NAME);
163 Node addingActions = NodeUtil.createPath(groups, "addingActions/items", NodeTypes.ContentNode.NAME);
164
165 NodeUtil.createPath(addingActions, "addArea", NodeTypes.ContentNode.NAME);
166 NodeUtil.createPath(addingActions, "deleteArea", NodeTypes.ContentNode.NAME);
167 NodeUtil.createPath(addingActions, "addComponent", NodeTypes.ContentNode.NAME);
168
169 }
170 }
171 }