View Javadoc

1   /**
2    * This file Copyright (c) 2012-2013 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.module.googlesitemap.setup;
35  
36  import info.magnolia.cms.security.Permission;
37  import info.magnolia.module.DefaultModuleVersionHandler;
38  import info.magnolia.module.InstallContext;
39  import info.magnolia.module.delta.AddPermissionTask;
40  import info.magnolia.module.delta.ArrayDelegateTask;
41  import info.magnolia.module.delta.BootstrapSingleModuleResource;
42  import info.magnolia.module.delta.BootstrapSingleResourceAndOrderBefore;
43  import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
44  import info.magnolia.module.delta.DeltaBuilder;
45  import info.magnolia.module.delta.NewPropertyTask;
46  import info.magnolia.module.delta.NodeExistsDelegateTask;
47  import info.magnolia.module.delta.OrderNodeBeforeTask;
48  import info.magnolia.module.delta.RemoveNodeTask;
49  import info.magnolia.module.delta.RemovePropertyTask;
50  import info.magnolia.module.delta.SetPropertyTask;
51  import info.magnolia.module.delta.SetupModuleRepositoriesTask;
52  import info.magnolia.module.delta.Task;
53  import info.magnolia.module.googlesitemap.app.field.transformer.SiteMapTransformer;
54  import info.magnolia.module.googlesitemap.setup.migration.Removei18nKeysInSiteMapMigrationTask;
55  import info.magnolia.module.googlesitemap.setup.migration.SiteMapDefinitionMigrationTask;
56  import info.magnolia.module.googlesitemap.setup.migration.SiteMapDialogMigrationTask;
57  import info.magnolia.module.inplacetemplating.setup.TemplatesInstallTask;
58  import info.magnolia.repository.RepositoryConstants;
59  
60  import java.util.ArrayList;
61  import java.util.List;
62  
63  
64  /**
65   * Default version handler.
66   */
67  public class GoogleSiteMapVersionHandler extends DefaultModuleVersionHandler {
68  
69      public GoogleSiteMapVersionHandler() {
70          register(DeltaBuilder.update("1.2.1", "")
71                  .addTask(new RemoveNodeTask("Obsolete folder: templates", "Templates folder has to be removed", "config", "/modules/google-sitemap/templates"))
72                  .addTask(new RemoveNodeTask("Obsolete folder: dialog", "Dialogs folder has to be removed", "config", "/modules/google-sitemap/dialogs"))
73                  .addTask(new RemoveNodeTask("Obsolete SiteMap site sample definition", "", "website", "google-sitemap"))
74                  .addTask(new BootstrapSingleModuleResource("SiteMap new Config", "Setup Config", "config.modules.google-sitemap.config.xml"))
75                  .addTask(new BootstrapSingleModuleResource("SiteMap new Template", "Setup Template", "config.modules.google-sitemap.templates.xml")));
76  
77          register(DeltaBuilder.update("2.0", "")
78                  .addTask(new SiteMapDefinitionMigrationTask("Migrate M4.5 site map definition into the new App", "", RepositoryConstants.WEBSITE, "/"))
79                  .addTask(new SiteMapDialogMigrationTask("Migrate M4.5 dialog definition", "Create the new M5 dialog definition. Add actions, tabs and fields definition", "google-sitemap"))
80                  .addTask(new BootstrapSingleResourceAndOrderBefore("Bootstrap tab", "Bootstrap  site map properties tab",
81                          "/mgnl-bootstrap/google-sitemap/dialogs/config.modules.google-sitemap.dialogs.components.content.siteComponentTab.form.tabs.siteMap.xml", "tabSites"))
82                  .addTask(new BootstrapSingleModuleResource("SiteMap app", "Add SiteMap app", "app/config.modules.google-sitemap.apps.xml"))
83                  .addTask(new BootstrapSingleModuleResource("SiteMap app App Launcher", "Add SiteMap app to App Launcher", "app/config.modules.ui-admincentral.config.appLauncherLayout.groups.manage.apps.siteMaps.xml"))
84                  .addTask(new BootstrapSingleModuleResource("Field Types", "Install new field types", "fieldtypes/config.modules.google-sitemap.fieldTypes.xml"))
85                  .addTask(new BootstrapSingleModuleResource("Repository Mapping", "Add Google SiteMap worksapce mapping", "config/config.server.URI2RepositoryMapping.mappings.sitemaps.xml"))
86                  .addTask(new BootstrapSingleModuleResource("Virtual URI Mapping", "Add Google SiteMap virtual URI mapping", "virtualurimappings/config.modules.google-sitemap.virtualURIMapping.xml"))
87                  .addTask(new SetupModuleRepositoriesTask())
88                  .addTask(new AddPermissionTask("Anonymous permissions for the new workspace", "", "anonymous", "googleSitemaps", "/", Permission.READ, true))
89  
90                  .addTask(new NewPropertyTask("Add default value transformer", "Set a transformer that display the default field value in case the stored value is null", RepositoryConstants.CONFIG, "/modules/google-sitemap/dialogs/generic/controls/googleSiteMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapPriority", "transformerClass", SiteMapTransformer.class.getName()))
91                  .addTask(new NewPropertyTask("Add default value transformer", "Set a transformer that display the default field value in case the stored value is null", RepositoryConstants.CONFIG, "/modules/google-sitemap/dialogs/generic/controls/googleSiteMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapChangefreq", "transformerClass", SiteMapTransformer.class.getName()))
92                  .addTask(new NewPropertyTask("Add default value transformer", "Set a transformer that display the default field value in case the stored value is null", RepositoryConstants.CONFIG, "/modules/google-sitemap/dialogs/generic/controls/googleVirtualUriMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapPriority", "transformerClass", SiteMapTransformer.class.getName()))
93                  .addTask(new NewPropertyTask("Add default value transformer", "Set a transformer that display the default field value in case the stored value is null", RepositoryConstants.CONFIG, "/modules/google-sitemap/dialogs/generic/controls/googleVirtualUriMapTab/form/tabs/tabGoogleSitemapProps/fields/googleSitemapChangefreq", "transformerClass", SiteMapTransformer.class.getName()))
94  
95                  .addTask(new NodeExistsDelegateTask("Remove area definition from the pages templates", "Remove areas definition in /modules/google-sitemap/templates/pages/siteMapsConfiguration/areas", RepositoryConstants.CONFIG, "/modules/google-sitemap/templates/pages/siteMapsConfiguration/areas",
96                          new RemoveNodeTask("", "", RepositoryConstants.CONFIG, "/modules/google-sitemap/templates/pages/siteMapsConfiguration/areas")))
97                  .addTask(new NodeExistsDelegateTask("Remove components definition from templates", "Remove areas definition in /modules/google-sitemap/templates/components", RepositoryConstants.CONFIG, "/modules/google-sitemap/templates/components",
98                          new RemoveNodeTask("", "", RepositoryConstants.CONFIG, "/modules/google-sitemap/templates/components")))
99  
100                 .addTask(new Removei18nKeysInSiteMapMigrationTask("google-sitemap", "Remove M4.5 i18n support"))
101                 .addTask(new NodeExistsDelegateTask("Reorder Sitemaps in MANAGE group", "This reorders the Sitemaps app before Configuration in the Manage group of the applauncher.", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps/configuration",
102                         new OrderNodeBeforeTask("", "", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps/siteMaps", "configuration")))
103                 .addTask(new CheckAndModifyPropertyValueTask("Set Page template not visible", "", RepositoryConstants.CONFIG, "/modules/google-sitemap/templates/pages/siteMapsConfiguration", "visible", "true", "false"))
104         );
105 
106         register(DeltaBuilder.update("2.0.1", "")
107                 .addTask(new RemoveNodeTask("Remove dialog", "Remove obsolete dialog.", RepositoryConstants.CONFIG, "/modules/google-sitemap/dialogs/pages"))
108                 .addTask(new ArrayDelegateTask("Rename property", "Rename property [workspace] to [targetWorkspace].",
109                         new RemovePropertyTask("", "", RepositoryConstants.CONFIG, "/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/tabSites/fields/sites/field", "workspace"),
110                         new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/tabSites/fields/sites/field", "targetWorkspace", RepositoryConstants.WEBSITE)))
111                 .addTask(new RemovePropertyTask("Remove unused property", "Remove unused property called identifier.", RepositoryConstants.CONFIG, "/modules/google-sitemap/dialogs/components/content/siteComponentTab/form/tabs/tabSites/fields/sites/field", "identifier"))
112                 .addTask(new RemovePropertyTask("Remove unused property", "Remove unused property called dialog.", RepositoryConstants.CONFIG, "/modules/google-sitemap/templates/pages/siteMapsConfiguration", "dialog"))
113                 .addTask(new RemovePropertyTask("Remove unused property", "Remove unused property called sitemapType.", RepositoryConstants.CONFIG, "/modules/google-sitemap/templates/pages/siteMapsConfiguration", "sitemapType"))
114         );
115     }
116 
117     /**
118      * Export the FTL to the Resource folder menu from the Admin central.
119      */
120     @Override
121     protected List<Task> getExtraInstallTasks(InstallContext ctx) {
122         final List<Task> tasks = new ArrayList<Task>();
123         tasks.add(new TemplatesInstallTask("/sitemap/.*\\.ftl", true));
124         tasks.add(new AddPermissionTask("Anonymous permissions for the new workspace", "", "anonymous", "googleSitemaps", "/", Permission.READ, true));
125         tasks.add(new NodeExistsDelegateTask("Reorder Sitemaps in MANAGE group", "This reorders the Sitemaps app before Configuration in the Manage group of the applauncher.", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps/configuration",
126                 new OrderNodeBeforeTask("", "", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps/siteMaps", "configuration")));
127         return tasks;
128     }
129 }