View Javadoc

1   /**
2    * This file Copyright (c) 2013-2014 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.pages.setup;
35  
36  import static info.magnolia.nodebuilder.Ops.*;
37  
38  import info.magnolia.i18nsystem.setup.RemoveHardcodedI18nPropertiesFromDialogsTask;
39  import info.magnolia.i18nsystem.setup.RemoveHardcodedI18nPropertiesFromSubappsTask;
40  import info.magnolia.jcr.util.NodeTypes;
41  import info.magnolia.module.DefaultModuleVersionHandler;
42  import info.magnolia.module.InstallContext;
43  import info.magnolia.module.delta.ArrayDelegateTask;
44  import info.magnolia.module.delta.BootstrapConditionally;
45  import info.magnolia.module.delta.DeltaBuilder;
46  import info.magnolia.module.delta.IsModuleInstalledOrRegistered;
47  import info.magnolia.module.delta.NewPropertyTask;
48  import info.magnolia.module.delta.NodeExistsDelegateTask;
49  import info.magnolia.module.delta.OrderNodeAfterTask;
50  import info.magnolia.module.delta.PartialBootstrapTask;
51  import info.magnolia.module.delta.PropertyExistsDelegateTask;
52  import info.magnolia.module.delta.RemoveNodeTask;
53  import info.magnolia.module.delta.RemovePropertyTask;
54  import info.magnolia.module.delta.RenameNodesTask;
55  import info.magnolia.module.delta.SetPropertyTask;
56  import info.magnolia.module.delta.Task;
57  import info.magnolia.nodebuilder.task.ErrorHandling;
58  import info.magnolia.nodebuilder.task.NodeBuilderTask;
59  import info.magnolia.repository.RepositoryConstants;
60  import info.magnolia.ui.admincentral.setup.ConvertAclToAppPermissionTask;
61  import info.magnolia.ui.contentapp.ConfiguredContentAppDescriptor;
62  import info.magnolia.ui.contentapp.availability.IsNotVersionedDetailLocationRule;
63  import info.magnolia.ui.contentapp.browser.action.ShowVersionsActionDefinition;
64  import info.magnolia.ui.framework.setup.SetWritePermissionForActionsTask;
65  
66  import java.util.ArrayList;
67  import java.util.List;
68  
69  /**
70   * Version handler for the pages app module.
71   */
72  public class PagesModuleVersionHandler extends DefaultModuleVersionHandler {
73  
74      public PagesModuleVersionHandler() {
75          super();
76  
77          register(DeltaBuilder.update("5.0", "Configuration update for Magnolia 5.0")
78                  .addTask(new IsModuleInstalledOrRegistered("", "", "adminInterface",
79                          new BootstrapConditionally("Bootstrap activation commands", "Bootstraps the default activation and deletion commands which no longer reside under adminInterface.", "config.modules.pages.commands.xml")))
80                  .addTask(new ConvertAclToAppPermissionTask("Convert permissions for Pages app", "Convert ACL permissions for old 'Website' menu to new 'pages-app' permission", "/modules/adminInterface/config/menu/website", "/modules/pages/apps/pages", true)));
81  
82  
83          register(DeltaBuilder.update("5.0.1", "")
84                  .addTask(new NodeExistsDelegateTask("Remove dialog links Node", "Remove dialog definition in pages/dialogs/links", RepositoryConstants.CONFIG, "/modules/pages/dialogs/link",
85                          new RemoveNodeTask("Remove dialog links Node", "Remove dialog definition in pages/dialogs/links", RepositoryConstants.CONFIG, "/modules/pages/dialogs/link")))
86                  .addTask(new NodeExistsDelegateTask("Add title to CreatePage dialog", "", RepositoryConstants.CONFIG, "/modules/pages/dialogs/createPage/form",
87                          new NewPropertyTask("Add title to CreatePage dialog", "", RepositoryConstants.CONFIG, "/modules/pages/dialogs/createPage/form", "label", "pages.dialog.add_page"))));
88  
89          register(DeltaBuilder.update("5.0.2", "")
90                  // new action for confirmation
91                  .addTask(new PartialBootstrapTask("Add new confirmation action definition", "", "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actions/confirmDeletion"))
92  
93                  .addTask(new NodeExistsDelegateTask("Remove action availability from delete action", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/delete/availability",
94                          new RemoveNodeTask("", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/delete/availability")))
95                  .addTask(new PropertyExistsDelegateTask("Remove label for delete action", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/delete", "label",
96                          new RemovePropertyTask("", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/delete", "label")))
97                  .addTask(new PropertyExistsDelegateTask("Remove icon for delete action", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/delete", "icon",
98                          new RemovePropertyTask("", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/delete", "icon")))
99  
100                 // update actionbar for confirmation
101                 .addTask(new NodeExistsDelegateTask("Update actionbar configuration", "Rename action mapping to new confirmation action", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar",
102                         new RenameNodesTask("Rename action bar items", "Rename delete to confirmDeletion", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar", "delete", "confirmDeletion", NodeTypes.ContentNode.NAME))));
103 
104         register(DeltaBuilder.update("5.1", "")
105                 .addTask(new NodeExistsDelegateTask("", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/confirmDeletion",
106                         new NewPropertyTask("", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/confirmDeletion/availability", "multiple", true)))
107 
108                 // add show versions action
109                 // if module diff is installed, this task will create a second node showVersions
110                 // we'll handle the renaming of the correct node in module diff
111                 .addTask(new NodeBuilderTask("Create showVersions action", "", ErrorHandling.logging, RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions",
112                         addNode("showVersions", NodeTypes.ContentNode.NAME).then(
113                                 addProperty("class", ShowVersionsActionDefinition.class.getName()),
114                                 addProperty("icon", "icon-show-versions"),
115                                 addNode("availability", NodeTypes.ContentNode.NAME).then(
116                                         addProperty("ruleClass", "info.magnolia.ui.api.availability.HasVersionsRule")
117                                 )
118                         )
119                 ))
120                 // bootstrap versionActions to action bar if it doesn't exists already
121                 .addTask(new NodeExistsDelegateTask("Bootstrap actionbar section group for versionActions", "", RepositoryConstants.CONFIG, "/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions", null,
122                         new PartialBootstrapTask("", "", "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions")
123                 ))
124 
125                 // Remove hardcoded i18n properties, e.g. label, description, etc.
126                 .addTask(new RemoveHardcodedI18nPropertiesFromSubappsTask("pages"))
127 
128                 // cleanup pages commands
129                 .addTask(new NodeExistsDelegateTask("remove the activate command chain from pages app", "", RepositoryConstants.CONFIG, "/modules/pages/commands/website/activate",
130                         new RemoveNodeTask("", "", RepositoryConstants.CONFIG, "/modules/pages/commands/website/activate")))
131                 .addTask(new NodeExistsDelegateTask("remove the deactivate command chain from pages app", "", RepositoryConstants.CONFIG, "/modules/pages/commands/website/deactivate",
132                         new RemoveNodeTask("", "", RepositoryConstants.CONFIG, "/modules/pages/commands/website/deactivate")))
133 
134                 .addTask(new PartialBootstrapTask("Bootstrap new activate commands to website catalog.", "", "/mgnl-bootstrap/pages/config.modules.pages.commands.xml", "/commands/website/activate"))
135                 .addTask(new PartialBootstrapTask("Bootstrap new deactivate commands to website catalog.", "", "/mgnl-bootstrap/pages/config.modules.pages.commands.xml", "/commands/website/deactivate"))
136 
137                 // Add availability rules to detail view actions
138                 .addTask(new NodeBuilderTask("Add availability rule to edit action", "", ErrorHandling.logging, RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/detail/actions/edit",
139                         addNode("availability", NodeTypes.ContentNode.NAME).then(
140                                 addProperty("ruleClass", IsNotVersionedDetailLocationRule.class.getName())
141                         )
142                 ))
143                 .addTask(new NodeBuilderTask("Add availability rule to activate action", "", ErrorHandling.logging, RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/detail/actions/activate",
144                         addNode("availability", NodeTypes.ContentNode.NAME).then(
145                                 addProperty("ruleClass", IsNotVersionedDetailLocationRule.class.getName())
146                         )
147                 ))
148                 .addTask(new NodeBuilderTask("Add availability rule to deactivate action", "", ErrorHandling.logging, RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/detail/actions/deactivate",
149                         addNode("availability", NodeTypes.ContentNode.NAME).then(
150                                 addProperty("ruleClass", IsNotVersionedDetailLocationRule.class.getName())
151                         )
152                 ))
153 
154                 .addTask(new PartialBootstrapTask("Bootstrap move action in Pages app", "",
155                         "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actions/move"))
156                 .addTask(new PartialBootstrapTask("Bootstrap move action to Pages app actionbar", "Adds action move to folder/editingActions section in actionbar.",
157                         "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actionbar/sections/pageActions/groups/editingActions/items/move"))
158         );
159 
160         register(DeltaBuilder.update("5.1.1", "")
161                 .addTask(new NodeExistsDelegateTask("Add root availability to import", "Add root availability to import action in Pages app", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/import/availability",
162                         new NewPropertyTask("Add root availability to import", "Add root availability to import action in Pages app", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/import/availability", "root", true)))
163         );
164 
165         register(DeltaBuilder.update("5.2.2", "")
166                 .addTask(new RemoveHardcodedI18nPropertiesFromDialogsTask("pages"))
167                 .addTask(new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/pages/apps/pages", "class", ConfiguredContentAppDescriptor.class.getName()))
168                 .addTask(new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/import/availability", "root", "true"))
169                 .addTask(new PartialBootstrapTask("Bootstrap restore version action", "", "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actions/restoreVersion"))
170                 .addTask(new NodeExistsDelegateTask("Bootstrap restore version action to actionbar", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions/items",
171                         new ArrayDelegateTask("",
172                                 new PartialBootstrapTask("", "", "/mgnl-bootstrap/pages/config.modules.pages.apps.pages.xml", "/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions/items/restoreVersion"),
173                                 new NodeExistsDelegateTask("", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions/items/showVersions",
174                                     new OrderNodeAfterTask("", "", RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actionbar/sections/pageActions/groups/versionActions/items/restoreVersion", "showVersions")))))
175         );
176 
177         register(DeltaBuilder.update("5.2.3", "")
178                 .addTask(new SetWritePermissionForActionsTask("/modules/pages/apps/pages/subApps/browser/actions",
179                         new String[] { "add", "confirmDeletion", "edit", "editPageName", "editTemplate", "restorePreviousVersion", "import", "move", "restoreVersion" }))
180                 .addTask(new SetWritePermissionForActionsTask("/modules/pages/apps/pages/subApps/detail/actions", new String[] { "edit" }))
181         );
182         register(DeltaBuilder.update("5.2.5", "")
183                 .addTask(new IsModuleInstalledOrRegistered("Configure recursive activation and deletion as asynchronous", "scheduler", new ArrayDelegateTask("",
184                         new NodeExistsDelegateTask("Configure recursive activation as asynchronous", "/modules/pages/apps/pages/subApps/browser/actions/activateRecursive",
185                                 new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/activateRecursive", "asynchronous", "true")),
186                         new NodeExistsDelegateTask("Configure deletion as asynchronous", "/modules/pages/apps/pages/subApps/browser/actions/delete",
187                                 new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/delete", "asynchronous", "true"))
188                 ))));
189     }
190 
191     @Override
192     protected List<Task> getExtraInstallTasks(InstallContext installContext) {
193         List<Task> tasks = new ArrayList<Task>();
194         tasks.addAll(super.getExtraInstallTasks(installContext));
195         tasks.add(new IsModuleInstalledOrRegistered("Configure recursive activation and deletion as asynchronous", "scheduler", new ArrayDelegateTask("",
196                 new NodeExistsDelegateTask("Configure recursive activation as asynchronous", "/modules/pages/apps/pages/subApps/browser/actions/activateRecursive",
197                         new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/activateRecursive", "asynchronous", "true")),
198                 new NodeExistsDelegateTask("Configure deletion as asynchronous", "/modules/pages/apps/pages/subApps/browser/actions/delete",
199                         new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/pages/apps/pages/subApps/browser/actions/delete", "asynchronous", "true"))
200         )));
201         return tasks;
202     }
203 }