Clover icon

Magnolia Resources Module 2.4.2

  1. Project Clover database Fri Nov 6 2015 16:15:26 CET
  2. Package info.magnolia.module.resources.setup

File ResourcesModuleVersionHandler.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
52% of files have more coverage

Code metrics

0
25
4
1
170
110
4
0.16
6.25
4
1

Classes

Class Line # Actions
ResourcesModuleVersionHandler 68 25 0% 4 9
0.689655269%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    /**
2    * This file Copyright (c) 2008-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.module.resources.setup;
35   
36    import info.magnolia.cms.security.Permission;
37    import info.magnolia.cms.security.Role;
38    import info.magnolia.cms.security.RoleManager;
39    import info.magnolia.cms.security.Security;
40    import info.magnolia.module.InstallContext;
41    import info.magnolia.module.delta.AbstractTask;
42    import info.magnolia.module.delta.ArrayDelegateTask;
43    import info.magnolia.module.delta.BootstrapConditionally;
44    import info.magnolia.module.delta.BootstrapSingleResource;
45    import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
46    import info.magnolia.module.delta.DeltaBuilder;
47    import info.magnolia.module.delta.ModuleDependencyBootstrapTask;
48    import info.magnolia.module.delta.NodeExistsDelegateTask;
49    import info.magnolia.module.delta.PropertyValueDelegateTask;
50    import info.magnolia.module.delta.RegisterServletTask;
51    import info.magnolia.module.delta.RemoveNodeTask;
52    import info.magnolia.module.delta.RemovePropertyTask;
53    import info.magnolia.module.delta.SetPropertyTask;
54    import info.magnolia.module.delta.Task;
55    import info.magnolia.module.delta.TaskExecutionException;
56    import info.magnolia.module.model.ServletDefinition;
57    import info.magnolia.module.resources.ResourceTypes;
58    import info.magnolia.module.resources.ResourcesModule;
59    import info.magnolia.repository.RepositoryConstants;
60   
61    import java.util.ArrayList;
62    import java.util.Arrays;
63    import java.util.List;
64   
65    /**
66    * Version handler of resources module.
67    */
 
68    public class ResourcesModuleVersionHandler extends ResourcesVersionHandler {
69   
70    protected static final String INPLACE_TEMPLATING_APP_LAUNCHER_CONFIG = "/modules/ui-admincentral/config/appLauncherLayout/groups/stk/apps/inplace-templating";
71   
72    private final Task removeResourcesLegacyApp = new ArrayDelegateTask("Remove Legacy Resources app", "Removes old UI pages tree, dialogs and app launcher configuration.",
73    new RemoveNodeTask("Remove old UI", "Removes old UI pages.", RepositoryConstants.CONFIG, "/modules/resources/pages"),
74    new RemoveNodeTask("Remove old UI", "Removes old UI tree.", RepositoryConstants.CONFIG, "/modules/resources/trees"),
75    new RemoveNodeTask("Remove old UI", "Removes old UI edit dialog.", RepositoryConstants.CONFIG, "/modules/resources/dialogs"),
76    new RemovePropertyTask("Remove versionOnSave property", "", RepositoryConstants.CONFIG, "/modules/resources/config", "versionOnSave"),
77    new RemoveNodeTask("Remove old UI", "Remove legacy resources app config from ui-admincentral", RepositoryConstants.CONFIG, "/modules/ui-admincentral/apps/resourcesApp"),
78    new RemoveNodeTask("Remove old UI", "Remove legacy resources app from applauncher layout", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/stk/apps/resourcesApp"));
79   
 
80  9 toggle private Task addResourcesServletMapping() {
81  9 ServletDefinition servletDefinition = new ServletDefinition();
82  9 servletDefinition.setName("ResourcesServlet");
83  9 servletDefinition.setClassName("info.magnolia.module.resources.ResourcesServlet");
84  9 servletDefinition.setComment("a servlet used by the resources module");
85  9 servletDefinition.addMapping("/.resources/*");
86  9 return new RegisterServletTask(servletDefinition);
87    }
88   
 
89  9 toggle public ResourcesModuleVersionHandler() {
90   
91  9 register(DeltaBuilder.checkPrecondition("1.5", "2.0"));
92   
93  9 register(DeltaBuilder.update("1.5.1", "")
94    .addTask(new NodeExistsDelegateTask("Update samples", "Update samples if they should be installed", ResourcesModule.DEFAULT_WORKSPACE, "/sample-css/MetaData",
95    new CheckAndModifyPropertyValueTask("Update template", "Update template to new name", ResourcesModule.DEFAULT_WORKSPACE, "/sample-css/MetaData", "mgnl:template", ResourceTypes.PROCESSED_CSS_SUFFIX, ResourceTypes.PROCESSED_CSS))));
96   
97  9 register(DeltaBuilder.update("1.5.4", "")
98    .addTask(new CheckAndModifyPropertyValueTask(
99    "Update component class", "Update cms context attribute/componentClass in text resource renderer", "config",
100    "/modules/resources/renderers/textResource/contextAttributes/cms/", "componentClass", "info.magnolia.templating.freemarker.Directives",
101    "info.magnolia.templating.freemarker.ReadOnlyDirectives")));
102   
103  9 register(DeltaBuilder.update("1.5.5", "")
104    .addTask(new BootstrapConditionally("Register resource loader", "Allow registration of resource loaders under config/resourceLoaders node.", "/mgnl-bootstrap/resources/config/config.modules.resources.config.xml")));
105  9 register(DeltaBuilder.update("1.5.8", "")
106    .addTask(new BootstrapSingleResource("Config", "Commands configuration", "/mgnl-bootstrap/resources/commands/config.modules.resources.commands.xml")));
107   
108   
109  9 register(DeltaBuilder.update("2.0.1", "")
110    .addTask(new NodeExistsDelegateTask("Bootstrap Commands configuration if needed", "", RepositoryConstants.CONFIG, "/modules/resources/commands", null,
111    new BootstrapSingleResource("Bootstrap Commands configuration", "", "/mgnl-bootstrap/resources/commands/config.modules.resources.commands.xml")))
112    .addTask(new NodeExistsDelegateTask("Remove version command if existing", "", RepositoryConstants.CONFIG, "/modules/resources/commands/resources/versionResources/version",
113    new RemoveNodeTask("Remove version command", "", RepositoryConstants.CONFIG, "/modules/resources/commands/resources/versionResources/version"))));
114   
115  9 register(DeltaBuilder.update("2.0.2", "")
116    .addTask(new NodeExistsDelegateTask("Change extractComment commands class if existing", "", RepositoryConstants.CONFIG, "/modules/resources/commands/resources/versionResources/extractComment",
117    new CheckAndModifyPropertyValueTask("Update extractComment commands class", "Commands configuration", RepositoryConstants.CONFIG, "/modules/resources/commands/resources/versionResources/extractComment", "class",
118    Arrays.asList("info.magnolia.module.resources.commands.ExtractCommentCommand", "info.magnolia.module.admininterface.commands.ExtractCommentCommand"),
119    "info.magnolia.commands.impl.ExtractCommentCommand"))));
120   
121  9 register(DeltaBuilder.update("2.2", "")
122    .addTask(removeResourcesLegacyApp));
123   
124  9 register(DeltaBuilder.update("2.2.1", "")
125    .addTask(new RemoveNodeTask("Remove obsolete command", "Remove obsolete version command configuration", RepositoryConstants.CONFIG,
126    "/modules/resources/commands/resources/versionResources/version")));
127   
128  9 register(DeltaBuilder.update("2.2.2", "")
129    .addTask(new NodeExistsDelegateTask("Register observation for resources if not configured", "Register observation for resources if not configured", RepositoryConstants.CONFIG,
130    "/modules/observation/config/listenerConfigurations/versionResourcesOnChange", null,
131    new ModuleDependencyBootstrapTask("observation"))
132    ));
133   
134  9 register(DeltaBuilder.update("2.4", "")
135    .addTask(new NodeExistsDelegateTask("Yaml file resources template", "/modules/resources/templates",
136    new BootstrapSingleResource("", "Register template for Yaml file resources.", "/mgnl-bootstrap/resources/templates/config.modules.resources.templates.yaml.xml")))
137   
138    .addTask(new RemoveNodeTask("Removes ClasspathSpool servlet", "Removes ClasspathSpool servlet for URL mapping '/.resources'.", RepositoryConstants.CONFIG, "/server/filters/servlets/ClasspathSpoolServlet"))
139    .addTask(addResourcesServletMapping())
140    );
141   
142  9 register(DeltaBuilder.update("2.4.2", "")
143    .addTask(new ArrayDelegateTask("Change content type of JavaScript resources",
144    new PropertyValueDelegateTask("", "/modules/resources/templates/js", "contentType", "application/x-javascript", false,
145    new SetPropertyTask("config", "/modules/resources/templates/js", "contentType", "application/javascript")),
146    new PropertyValueDelegateTask("", "/modules/resources/templates/processedJs", "contentType", "application/x-javascript", false,
147    new SetPropertyTask("config", "/modules/resources/templates/processedJs", "contentType", "application/javascript"))))
148    .addTask(new TemplateMigrationTask(new NodeExistsDelegateTask("Remove app launcher configuration for inplace templating", INPLACE_TEMPLATING_APP_LAUNCHER_CONFIG,
149    new RemoveNodeTask("", INPLACE_TEMPLATING_APP_LAUNCHER_CONFIG))))
150    );
151    }
152   
 
153  0 toggle @Override
154    protected List<Task> getExtraInstallTasks(InstallContext installContext) {
155  0 final List<Task> tasks = new ArrayList<Task>();
156   
157  0 tasks.add(new AbstractTask("Anonymous permissions for resources", "Grants the anonymous user the read permission to the resources repository.") {
 
158  0 toggle @Override
159    public void execute(InstallContext ignored) throws TaskExecutionException {
160  0 RoleManager roleMan = Security.getRoleManager();
161  0 Role anonymous = roleMan.getRole("anonymous");
162  0 roleMan.addPermission(anonymous, "resources", "/*", Permission.READ);
163    }
164    });
165  0 tasks.add(new ModuleDependencyBootstrapTask("observation"));
166   
167  0 return tasks;
168    }
169   
170    }