View Javadoc
1   /**
2    * This file Copyright (c) 2014-2015 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.resources.app.setup;
35  
36  import info.magnolia.jcr.util.NodeTypes;
37  import info.magnolia.module.InstallContext;
38  import info.magnolia.module.delta.AbstractRepositoryTask;
39  import info.magnolia.module.delta.ArrayDelegateTask;
40  import info.magnolia.module.delta.BootstrapSingleModuleResource;
41  import info.magnolia.module.delta.BootstrapSingleResource;
42  import info.magnolia.module.delta.ChangeNodeTypeTask;
43  import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
44  import info.magnolia.module.delta.CheckOrCreatePropertyTask;
45  import info.magnolia.module.delta.DeltaBuilder;
46  import info.magnolia.module.delta.NodeExistsDelegateTask;
47  import info.magnolia.module.delta.PartialBootstrapTask;
48  import info.magnolia.module.delta.PathExistenceDelegateTask;
49  import info.magnolia.module.delta.RemoveNodeTask;
50  import info.magnolia.module.delta.SetPropertyTask;
51  import info.magnolia.module.delta.TaskExecutionException;
52  import info.magnolia.module.resources.app.action.EditResourceActionDefinition;
53  import info.magnolia.module.resources.app.action.ShowResourceVersionsActionDefinition;
54  import info.magnolia.module.resources.setup.ResourcesVersionHandler;
55  import info.magnolia.repository.RepositoryConstants;
56  import info.magnolia.ui.admincentral.setup.ConvertAclToAppPermissionTask;
57  import info.magnolia.ui.contentapp.setup.for5_3.ContentAppMigrationTask;
58  import info.magnolia.ui.framework.setup.AddIsPublishedRuleToAllDeactivateActionsTask;
59  
60  import javax.jcr.RepositoryException;
61  
62  /**
63   * Version handler for Resources app module.
64   */
65  public class ResourcesAppModuleVersionHandler extends ResourcesVersionHandler {
66  
67      public ResourcesAppModuleVersionHandler() {
68          register(DeltaBuilder.update("2.0", "")
69                  .addTask(new ConvertAclToAppPermissionTask("Convert permissions for 'resources' app", "Convert ACL permissions for old 'Templating-kit/Resources' menu to new 'resources' app permission",
70                          "/modules/adminInterface/config/menu/templating-kit/resources ", "/modules/resources/apps/resources", true)));
71  
72          register(DeltaBuilder.update("2.2", "")
73                  .addTask(new BootstrapSingleResource("Bootstrap Resources app", "", "/mgnl-bootstrap-prior-2_3/resources/app/config.modules.resources.apps.xml"))
74                  .addTask(new BootstrapSingleResource("Add the app to the app launcher", "Adds the app to the app launcher menu.", "/mgnl-bootstrap/resources-app/config.modules.ui-admincentral.config.appLauncherLayout.groups.stk.apps.resources.xml"))
75                  .addTask(new BootstrapSingleResource("Bootstrap new resources dialogs", "", "/mgnl-bootstrap-prior-2_3/resources/app/config.modules.resources.dialogs.xml")));
76  
77          register(DeltaBuilder.update("2.2.1", "")
78                  .addTask(new ArrayDelegateTask("Add duplicate action", "Adds duplicate resource action.",
79                          new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_3/resources/app/config.modules.resources.apps.xml", "/apps/resources/subApps/browser/actions/duplicateResource"),
80                          new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_3/resources/app/config.modules.resources.apps.xml", "/apps/resources/subApps/browser/actionbar/sections/resource/groups/editActions/items/duplicateResource"))));
81  
82          register(DeltaBuilder.update("2.2.3", "")
83                  .addTask(new ArrayDelegateTask("Add editTemplate action", "Adds editTemplate of resource action.",
84                          new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_3/resources/app/config.modules.resources.apps.xml",
85                                  "/apps/resources/subApps/browser/actions/editTemplate"),
86                          new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_3/resources/app/config.modules.resources.apps.xml",
87                                  "/apps/resources/subApps/browser/actionbar/sections/resource/groups/editActions/items/editTemplate"),
88                          new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_4/resources/app/config.modules.resources.dialogs.xml",
89                                  "/dialogs/editTemplate")
90                  )));
91  
92          register(DeltaBuilder.update("2.2.4", "")
93                  .addTask(
94                          new ArrayDelegateTask("Add support for extension handling",
95                                  new NodeExistsDelegateTask("", "/modules/resources/apps/resources/subApps/binary/editor/form/tabs/content/fields/binary",
96                                          new ArrayDelegateTask("",
97                                                  new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/resources/apps/resources/subApps/binary/editor/form/tabs/content/fields/binary",
98                                                          "editFileFormat", Boolean.TRUE),
99                                                  new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/resources/apps/resources/subApps/binary/editor/form/tabs/content/fields/binary",
100                                                         "editFileName", Boolean.TRUE))),
101                                 new PartialBootstrapTask("Add extension field", "Add extension field to the resource subapps.", "/mgnl-bootstrap-prior-2_4/resources/app/config.modules.resources.apps.xml",
102                                         "/apps/resources/subApps/generic/code/editor/form/tabs/advanced/fields/extension"),
103                                 new SetPropertyTask(RepositoryConstants.CONFIG, "/server/URI2RepositoryMapping/mappings/resources", "class",
104                                         "info.magnolia.module.resources.mapping.URI2ResourcesRepositoryMapping")))
105         );
106 
107         register(DeltaBuilder.update("2.3", "")
108                 .addTask(new ContentAppMigrationTask("/modules/resources",
109                         new Class[] { EditResourceActionDefinition.class, ShowResourceVersionsActionDefinition.class })));
110 
111 
112         register(DeltaBuilder.update("2.3.1", "")
113                 .addTask(new NodeExistsDelegateTask("Replace ruleClass with rule", "Replaces editTemplate action availability rule.", RepositoryConstants.CONFIG, "/modules/resources/apps/resources/subApps/browser/actions/editTemplate/availability/ruleClass",
114                         new ArrayDelegateTask("",
115                                 new RemoveNodeTask("", "/modules/resources/apps/resources/subApps/browser/actions/editTemplate/availability/ruleClass"),
116                                 new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_4/resources/app/config.modules.resources.apps.xml", "/apps/resources/subApps/browser/actions/editTemplate/availability/rules")))));
117 
118 
119         register(DeltaBuilder.update("2.3.2", "")
120                 .addTask(new NodeExistsDelegateTask("Change nodeType of generic subapp", "", RepositoryConstants.CONFIG, "/modules/resources/apps/resources/subApps/generic",
121                         new ChangeNodeTypeTask("/modules/resources/apps/resources/subApps/generic", RepositoryConstants.CONFIG, NodeTypes.ContentNode.NAME)))
122                 .addTask(new PathExistenceDelegateTask("Add app for editing html resources", "", null,
123                         new String[]{"/modules/resources/dialogs/newResource/form/tabs/content/fields/mgnl-template/options", "/modules/resources/apps/resources/subApps/browser/actions/editResource/subAppMapping", "/modules/resources/templates"},
124                         new ArrayDelegateTask("",
125                                 new BootstrapSingleResource("", "", "/mgnl-bootstrap/resources/templates/config.modules.resources.templates.html.xml"),
126                                 new BootstrapSingleResource("", "", "/mgnl-bootstrap/resources/templates/config.modules.resources.templates.processedHtml.xml"),
127                                 new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_4/resources/app/config.modules.resources.apps.xml", "/apps/resources/subApps/html"),
128                                 new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_4/resources/app/config.modules.resources.apps.xml", "/apps/resources/subApps/generic/base/editor/form/tabs/content/fields/mgnl-template/options/html"),
129                                 new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_4/resources/app/config.modules.resources.apps.xml", "/apps/resources/subApps/generic/base/editor/form/tabs/content/fields/mgnl-template/options/processedHtml"),
130                                 new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_4/resources/app/config.modules.resources.dialogs.xml", "/dialogs/newResource/form/tabs/content/fields/mgnl-template/options/html"),
131                                 new PartialBootstrapTask("", "", "/mgnl-bootstrap-prior-2_4/resources/app/config.modules.resources.dialogs.xml", "/dialogs/newResource/form/tabs/content/fields/mgnl-template/options/processedHtml"),
132                                 new CheckOrCreatePropertyTask("", "/modules/resources/apps/resources/subApps/browser/actions/editResource/subAppMapping", "html", "html"),
133                                 new CheckOrCreatePropertyTask("", "/modules/resources/apps/resources/subApps/browser/actions/editResource/subAppMapping", "processedHtml", "html")))));
134 
135         register(DeltaBuilder.update("2.3.3", "")
136                 .addTask(new AddIsPublishedRuleToAllDeactivateActionsTask("", "/modules/resources/apps/")));
137 
138         register(DeltaBuilder.update("2.4", "")
139                 .addTask(new AbstractRepositoryTask("Create module node", "This is the first version where resources-app module is extracted from resources module; makes sure the module node gets created.") {
140                         @Override
141                         protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException {
142                                 installContext.getOrCreateCurrentModuleNode();
143                         }
144                 })
145                 .addTask(new UpdateResourcesAppConfigurationTask())
146 
147                 .addTask(new NodeExistsDelegateTask("", "/modules/resources-app/dialogs/editTemplate/form/tabs/tabTemplate/fields/template",
148                         new CheckAndModifyPropertyValueTask("/modules/resources-app/dialogs/editTemplate/form/tabs/tabTemplate/fields/template", "extends", "/modules/resources/apps/resources/subApps/generic/base/editor/form/tabs/content/fields/mgnl-template", "/modules/resources-app/apps/resources-legacy/subApps/generic/base/editor/form/tabs/content/fields/mgnl-template")))
149                 .addTask(new NodeExistsDelegateTask("", "/modules/resources-app/apps/resources-legacy/subApps/browser/actions/addResource",
150                         new CheckAndModifyPropertyValueTask("/modules/resources-app/apps/resources-legacy/subApps/browser/actions/addResource", "dialogName", "resources:newResource", "resources-app:newResource")))
151                 .addTask(new NodeExistsDelegateTask("", "/modules/resources-app/apps/resources-legacy/subApps/browser/actions/renameResource",
152                         new CheckAndModifyPropertyValueTask("/modules/resources-app/apps/resources-legacy/subApps/browser/actions/renameResource", "dialogName", "resources:renameResource", "resources-app:renameResource")))
153                 .addTask(new NodeExistsDelegateTask("", "/modules/resources-app/apps/resources-legacy/subApps/browser/actions/renameResource",
154                         new CheckAndModifyPropertyValueTask("/modules/resources-app/apps/resources-legacy/subApps/browser/actions/editTemplate", "dialogName", "resources:editTemplate", "resources-app:editTemplate")))
155                 .addTask(new NodeExistsDelegateTask("Yaml files sub-app", "/modules/resources-app/apps/resources-legacy/subApps",
156                         new PartialBootstrapTask("", "/mgnl-bootstrap/resources-app/resources-legacy/config.modules.resources-app.apps.resources-legacy.xml", "/resources-legacy/subApps/yaml")))
157                 .addTask(new NodeExistsDelegateTask("Yaml type dialog option", "/modules/resources-app/dialogs/newResource/form/tabs/content/fields/mgnl-template/options",
158                         new PartialBootstrapTask("", "/mgnl-bootstrap/resources-app/resources-legacy/config.modules.resources-app.dialogs.xml", "/dialogs/newResource/form/tabs/content/fields/mgnl-template/options/yaml")))
159                 .addTask(new NodeExistsDelegateTask("Yaml option in template list", "/modules/resources-app/apps/resources-legacy/subApps/generic/base/editor/form/tabs/content/fields/mgnl-template/options",
160                         new PartialBootstrapTask("", "/mgnl-bootstrap/resources-app/resources-legacy/config.modules.resources-app.apps.resources-legacy.xml", "/resources-legacy/subApps/generic/base/editor/form/tabs/content/fields/mgnl-template/options/yaml")))
161                 .addTask(new NodeExistsDelegateTask("Yaml mapping for editResource action", "/modules/resources-app/apps/resources-legacy/subApps/browser/actions/editResource/subAppMapping",
162                         new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/resources-app/apps/resources-legacy/subApps/browser/actions/editResource/subAppMapping", "yaml", "yaml")))
163 
164                 .addTask(new BootstrapSingleModuleResource("config.modules.resources-app.apps.resources.xml"))
165         );
166     }
167 
168 
169 }