View Javadoc

1   /**
2    * This file Copyright (c) 2008-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.rssaggregator.setup;
35  
36  import info.magnolia.dam.setup.migration.ChangeDataDmsReferenceToDamMigrationTask;
37  import info.magnolia.module.DefaultModuleVersionHandler;
38  import info.magnolia.module.InstallContext;
39  import info.magnolia.module.cache.RegisterWorkspaceForCacheFlushingTask;
40  import info.magnolia.module.delta.ArrayDelegateTask;
41  import info.magnolia.module.delta.BootstrapConditionally;
42  import info.magnolia.module.delta.BootstrapSingleModuleResource;
43  import info.magnolia.module.delta.BootstrapSingleResource;
44  import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
45  import info.magnolia.module.delta.CheckOrCreatePropertyTask;
46  import info.magnolia.module.delta.CreateNodeTask;
47  import info.magnolia.module.delta.DeltaBuilder;
48  import info.magnolia.module.delta.ModuleDependencyBootstrapTask;
49  import info.magnolia.module.delta.MoveNodeTask;
50  import info.magnolia.module.delta.NodeExistsDelegateTask;
51  import info.magnolia.module.delta.OrderNodeBeforeTask;
52  import info.magnolia.module.delta.PropertyExistsDelegateTask;
53  import info.magnolia.module.delta.RemoveNodeTask;
54  import info.magnolia.module.delta.SetPropertyTask;
55  import info.magnolia.module.delta.SetupModuleRepositoriesTask;
56  import info.magnolia.module.delta.Task;
57  import info.magnolia.module.model.Version;
58  import info.magnolia.module.rssaggregator.RSSAggregatorConstants;
59  import info.magnolia.repository.RepositoryConstants;
60  import info.magnolia.ui.admincentral.setup.ConvertAclToAppPermissionTask;
61  import info.magnolia.ui.framework.setup.SetWritePermissionForActionsTask;
62  
63  import java.util.ArrayList;
64  import java.util.Arrays;
65  import java.util.List;
66  
67  import javax.jcr.ImportUUIDBehavior;
68  
69  /**
70   * Version handler.
71   */
72  public class RSSAggregatorVersionHandler extends DefaultModuleVersionHandler {
73  
74      protected static final String RSSAGGREGATOR_APP_ACTIONS = "/modules/rssaggregator/apps/rssAggregator/subApps/browser/actions/";
75  
76      public RSSAggregatorVersionHandler() {
77  
78          register(DeltaBuilder.checkPrecondition("1.3", "2.0"));
79  
80          register(DeltaBuilder.update("1.4", "")
81                  .addTask(new BootstrapSingleResource("Planet feed component.", "", "/mgnl-bootstrap/rssaggregator/templates/components/config.modules.rssaggregator.templates.components.planetFeeds.xml"))
82                  .addTask(new BootstrapSingleResource("Planet feed statistics component.", "", "/mgnl-bootstrap/rssaggregator/templates/components/config.modules.rssaggregator.templates.components.feedStatistics.xml"))
83                  .addTask(new BootstrapSingleResource("Planet feed subcriptions component.", "", "/mgnl-bootstrap/rssaggregator/templates/components/config.modules.rssaggregator.templates.components.feedSubscriptions.xml"))
84                  // settings for feed syndication
85                  .addTask(new BootstrapSingleResource("Virtual URI mapping for planet feeds.", "", "/mgnl-bootstrap/rssaggregator/config.modules.rssaggregator.virtualURIMapping.planetFeeds.xml"))
86                  .addTask(new BootstrapSingleResource("Feed generator for planet feeds.", "", "/mgnl-bootstrap/rssaggregator/config/feedGenerators/config.modules.rssaggregator.config.feedGenerators.planet.xml"))
87                  .addTask(new BootstrapSingleResource("Feed syndication component.", "", "/mgnl-bootstrap/rssaggregator/templates/components/config.modules.rssaggregator.templates.components.feedSyndication.xml"))
88                  // planet commands
89                  .addTask(new BootstrapConditionally("Commands for planet RSS.", "", "/mgnl-bootstrap/rssaggregator/config/commands/config.modules.rssaggregator.commands.xml"))
90                  .addTask(new BootstrapConditionally("Scheduled job for planet archive.", "", "/mgnl-bootstrap/rssaggregator/config/commands/config.modules.scheduler.config.jobs.generatePlanetData.xml"))
91                  .addTask(new BootstrapConditionally("Scheduled job for planet statistics.", "", "/mgnl-bootstrap/rssaggregator/config/commands/config.modules.scheduler.config.jobs.collectPlanetStatistics.xml"))
92                  // add config options for planet
93                  .addTask(new CreateNodeTask("Planet feed options.", "Add options for planet feeds to the RSSAggregator module.",
94                          RepositoryConstants.CONFIG, "/modules/rssaggregator/config", "planetOptions", "mgnl:contentNode"))
95                  .addTask(new CheckOrCreatePropertyTask("Option for relevant months to be included in statistics", "",
96                          RepositoryConstants.CONFIG, "/modules/rssaggregator/config/planetOptions", "lastMonthsIncluded", "3"))
97                  // move virtualURImappings to rssaggregator module from adminInterface
98                  .addTask(new MoveNodeTask("Move rssFeeds node.", "Move rssFeeds node to rssaggregator module.", "config", "/modules/adminInterface/virtualURIMapping/rssFeeds", "/modules/rssaggregator/virtualURIMapping/rssFeeds", false)));
99  
100         register(DeltaBuilder.update("1.4.3", "")
101                 .addTask(new ArrayDelegateTask("Bootstrap missing components",
102                         new NodeExistsDelegateTask("", "", RepositoryConstants.CONFIG, "/modules/rssaggregator/templates/components/combinedFeedsParagraph",
103                                 new CheckAndModifyPropertyValueTask("Change templateScript", "Change templateScript of combinedFeedsParagraphs", RepositoryConstants.CONFIG, "/modules/rssaggregator/templates/components/combinedFeedsParagraph", "templateScript", "/info/magnolia/module/rssaggregator/paragraphs/combinedFeed.ftl", "/rssaggregator/components/combinedFeed.ftl"),
104                                 new BootstrapSingleResource("Bootstrap component", "Bootstrap combinedFeedsParagraph", "/mgnl-bootstrap/rssaggregator/templates/components/config.modules.rssaggregator.templates.components.combinedFeedsParagraph.xml", ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING)
105                         ),
106                         new NodeExistsDelegateTask("", "", RepositoryConstants.CONFIG, "/modules/rssaggregator/templates/components/feedListParagraph",
107                                 new CheckAndModifyPropertyValueTask("Change templateScript", "Change templateScript of feedListParagraph", RepositoryConstants.CONFIG, "/modules/rssaggregator/templates/components/feedListParagraph", "templateScript", "/info/magnolia/module/rssaggregator/paragraphs/feedList.ftl", "/rssaggregator/components/feedList.ftl"),
108                                 new BootstrapSingleResource("Bootstrap component", "Bootstrap feedListParagraph", "/mgnl-bootstrap/rssaggregator/templates/components/config.modules.rssaggregator.templates.components.feedListParagraph.xml", ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING)
109                         )
110                         )
111                 )
112                 .addTask(new NodeExistsDelegateTask("Add property", "Add property backup to rssaggregator importer", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator",
113                         new PropertyExistsDelegateTask("", "", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator", "backup", null,
114                                 new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator", "backup", Boolean.TRUE)
115                         )
116                         )
117                 ));
118 
119         register(DeltaBuilder.update("2.0", "")
120                 .addTask(new RemoveNodeTask("Remove old page", "Remove old adminInterface page", RepositoryConstants.CONFIG, "/modules/adminInterface/pages/rssaggregator"))
121                 .addTask(new RemoveNodeTask("Remove old menu", "Remove old adminInterface menu", RepositoryConstants.CONFIG, "/modules/adminInterface/config/menu/coonfiguration/rssaggregator")));
122 
123         register(DeltaBuilder.update("2.0.2", "")
124                 .addTask(new ArrayDelegateTask("Bootstrap missing components",
125                         new NodeExistsDelegateTask("", "", RepositoryConstants.CONFIG, "/modules/rssaggregator/templates/components/combinedFeedsParagraph",
126                                 new CheckAndModifyPropertyValueTask("Change templateScript", "Change templateScript of combinedFeedsParagraphs", RepositoryConstants.CONFIG, "/modules/rssaggregator/templates/components/combinedFeedsParagraph", "templateScript", "/info/magnolia/module/rssaggregator/paragraphs/combinedFeed.ftl", "/rssaggregator/components/combinedFeed.ftl"),
127                                 new BootstrapSingleResource("Bootstrap component", "Bootstrap combinedFeedsParagraph", "/mgnl-bootstrap/rssaggregator/templates/components/config.modules.rssaggregator.templates.components.combinedFeedsParagraph.xml", ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING)
128                         ),
129                         new NodeExistsDelegateTask("", "", RepositoryConstants.CONFIG, "/modules/rssaggregator/templates/components/feedListParagraph",
130                                 new CheckAndModifyPropertyValueTask("Change templateScript", "Change templateScript of feedListParagraph", RepositoryConstants.CONFIG, "/modules/rssaggregator/templates/components/feedListParagraph", "templateScript", "/info/magnolia/module/rssaggregator/paragraphs/feedList.ftl", "/rssaggregator/components/feedList.ftl"),
131                                 new BootstrapSingleResource("Bootstrap component", "Bootstrap feedListParagraph", "/mgnl-bootstrap/rssaggregator/templates/components/config.modules.rssaggregator.templates.components.feedListParagraph.xml", ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING)
132                         )
133                         )
134                 )
135 
136         );
137         register(DeltaBuilder.update("2.0.3", "")
138                 .addTask(new NodeExistsDelegateTask("Add property", "Add property backup to rssaggregator importer", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator",
139                         new PropertyExistsDelegateTask("", "", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator", "backup", null,
140                                 new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator", "backup", Boolean.TRUE)
141                         )
142                         )));
143         register(DeltaBuilder.update("2.2", "")
144                 .addTask(new PropertyExistsDelegateTask("Add property", "Add property backup to rssaggregator importer", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator", "backup", null,
145                         new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator", "backup", Boolean.TRUE)))
146 
147                 .addTask(new PropertyExistsDelegateTask("Set property", "Set workspace for scheduler jobs", RepositoryConstants.CONFIG, "/modules/scheduler/config/jobs/generatePlanetData/params", "repository",
148                         new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/scheduler/config/jobs/generatePlanetData/params", "repository", RSSAggregatorConstants.WORKSPACE), null))
149 
150                 .addTask(new PropertyExistsDelegateTask("Set property", "Set workspace for scheduler jobs", RepositoryConstants.CONFIG, "/modules/scheduler/config/jobs/collectPlanetStatistics/params", "repository",
151                         new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/scheduler/config/jobs/collectPlanetStatistics/params", "repository", RSSAggregatorConstants.WORKSPACE), null))
152 
153                 .addTask(new PropertyExistsDelegateTask("Set property", "Set workspace for rss importer", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator/targets/main", "targetPath",
154                         new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator/targets/main", "targetPath", "/"), null))
155 
156                 .addTask(new PropertyExistsDelegateTask("Set property", "Set workspace for rss importer", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator", "repository",
157                         new SetPropertyTask("", RepositoryConstants.CONFIG, "/modules/data/config/importers/rssaggregator", "repository", RSSAggregatorConstants.WORKSPACE), null))
158 
159                 // Get rid of old artifacts
160                 .addTask(new RemoveNodeTask("Remove page", "Remove old adminInterface page", "config", "/modules/rssaggregator/pages"))
161                 .addTask(new RemoveNodeTask("Remove old app", "Delete old app from app launcher if exists", "config", "/modules/ui-admincentral/config/appLauncherLayout/data/apps/RssAggregatorApp"))
162                 .addTask(new RemoveNodeTask("Remove old dialogs", "Remove old adminInterface dialogs", "config", "/modules/rssaggregator/dialogs"))
163                 .addTask(new RemoveNodeTask("Remove old dialogs", "Remove RSSAggregator dialog from data", "config", "/modules/data/dialogs/RssAggregator"))
164                 .addTask(new RemoveNodeTask("Remove rss aggregator tree", "Remove RSSAggregator tree from data module", "config", "/modules/data/trees/RssAggregator"))
165                 .addTask(new RemoveNodeTask("Remove rss aggregator type", "Remove RSSAggregator type from data module", "config", "/modules/data/config/types/RssAggregator"))
166                 .addTask(new RemoveNodeTask("Remove rss aggregator menu", "Remove RSSAggregator menu from adminInterface-legacy module", "config", "/modules/adminInterface/config/menu/data/RssAggregator"))
167 
168                 // Bootstrap new rssaggregator app
169                 .addTask(new BootstrapSingleModuleResource("Bootstrap app", "Bootstrap rssaggregator app", "app/config.modules.rssaggregator.apps.xml"))
170                 .addTask(new BootstrapSingleModuleResource("Add app to app-launcher", "Add rssaggregator app to App Launcher", "app/config.modules.ui-admincentral.config.appLauncherLayout.groups.manage.apps.rssAggregator.xml"))
171                 .addTask(new BootstrapSingleModuleResource("Bootstrap dialogs", "Remove old adminInterface dialogs", "dialogs/config.modules.rssaggregator.dialogs.xml"))
172                 .addTask(new RSSAggregatorDataTypeMigrationTask("Migrate data", "Migrate RSS Aggregator data to RSS workspace", "/rssaggregator", "/", RSSAggregatorConstants.WORKSPACE))
173                 .addTask(new ChangeDataDmsReferenceToDamMigrationTask("Migrate Hackergotchi user pics", "Migrate user pics from DMS to DAM", RSSAggregatorConstants.WORKSPACE, Arrays.asList("/"), "", ""))
174                 .addTask(new SetupModuleRepositoriesTask())
175                 .addTask(new ConvertAclToAppPermissionTask("Convert ACLs to permissions for 'rssAggregator' app", "Convert ACL permissions to dms to new 'assets' app permissions",
176                         "/modules/adminInterface/config/menu/data/RssAggregator", "/modules/rssaggregator/apps/rssAggregator", false))
177                 .addTask(new NodeExistsDelegateTask("Reorder RSS in MANAGE group", "This reorders the RSS app before Config in the Manage group of the applauncher.", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps/configuration",
178                         new OrderNodeBeforeTask("", "", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps/rssAggregator", "configuration"))));
179 
180         register(DeltaBuilder.update("2.2.1", "")
181                 .addTask(new RemovePropertyIfExists("Forbid nested RSS-Aggregators in 'add action' availability", "", RepositoryConstants.CONFIG, "/modules/rssaggregator/apps/rssAggregator/subApps/browser/actions/addRSSAggregator/availability/nodeTypes/", "rssFeed")));
182 
183         register(DeltaBuilder.update("2.2.2", "")
184                 .addTask(new NodeExistsDelegateTask("Delete old app from app launcher if exists", "Delete old app from app launcher if exists", RepositoryConstants.CONFIG,
185                         "/modules/ui-admincentral/config/appLauncherLayout/groups/data/apps/RssAggregatorApp",
186                         new RemoveNodeTask("Delete old app from app launcher", "Delete old app from app launcher", RepositoryConstants.CONFIG,
187                                 "/modules/ui-admincentral/config/appLauncherLayout/groups/data/apps/RssAggregatorApp"))));
188 
189         register(DeltaBuilder.update("2.2.4", "")
190                 .addTask(new RegisterWorkspaceForCacheFlushingTask("rss"))
191                 .addTask(new RenameFilterFieldsPropertiesTask())
192                 .addTask(new SetWritePermissionForActionsTask(RSSAGGREGATOR_APP_ACTIONS, new String[] { "addFolder", "editFolder", "addRSSAggregator", "delete", "editRSSAggregator", "import", "restorePreviousVersion", "confirmDeleteRSSAggregator", "activate", "deactivate", "activateDeleted" })));
193 
194     }
195 
196     @Override
197     protected List<Task> getExtraInstallTasks(InstallContext installContext) {
198         List<Task> tasks = new ArrayList<Task>();
199         tasks.add(new ModuleDependencyBootstrapTask("observation"));
200         tasks.addAll(super.getExtraInstallTasks(installContext));
201         tasks.add(new NodeExistsDelegateTask("Reorder RSS in MANAGE group", "This reorders the RSS app before Config in the Manage group of the applauncher.", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps/configuration",
202                 new OrderNodeBeforeTask("", "", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/manage/apps/rssAggregator", "configuration")));
203         tasks.add(new RegisterWorkspaceForCacheFlushingTask("rss"));
204         return tasks;
205     }
206 
207     @Override
208     protected List<Task> getDefaultUpdateTasks(Version forVersion) {
209         final List<Task> tasks = new ArrayList<Task>();
210         tasks.addAll(super.getDefaultUpdateTasks(forVersion));
211         return tasks;
212     }
213 }