Clover icon

Magnolia REST Tools 2.0-rc1

  1. Project Clover database Mon Oct 30 2017 16:31:56 CET
  2. Package info.magnolia.rest.tools.setup

File RestToolsModuleVersionHandler.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
8
3
1
120
67
3
0.38
2.67
3
1

Classes

Class Line # Actions
RestToolsModuleVersionHandler 66 8 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /**
2    * This file Copyright (c) 2013-2017 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.rest.tools.setup;
35   
36    import static info.magnolia.nodebuilder.Ops.*;
37   
38    import info.magnolia.cms.security.Permission;
39    import info.magnolia.jcr.util.NodeTypes;
40    import info.magnolia.module.DefaultModuleVersionHandler;
41    import info.magnolia.module.InstallContext;
42    import info.magnolia.module.delta.AddPermissionTask;
43    import info.magnolia.module.delta.CheckAndModifyPropertyValueTask;
44    import info.magnolia.module.delta.Delta;
45    import info.magnolia.module.delta.DeltaBuilder;
46    import info.magnolia.module.delta.PropertyValueDelegateTask;
47    import info.magnolia.module.delta.RemovePermissionTask;
48    import info.magnolia.module.delta.RenameNodeTask;
49    import info.magnolia.module.delta.SetPropertyTask;
50    import info.magnolia.module.delta.Task;
51    import info.magnolia.nodebuilder.task.ErrorHandling;
52    import info.magnolia.nodebuilder.task.NodeBuilderTask;
53    import info.magnolia.repository.RepositoryConstants;
54    import info.magnolia.rest.RestDispatcherServlet;
55    import info.magnolia.rest.tools.SwaggerRestDispatcherServlet;
56   
57    import java.util.ArrayList;
58    import java.util.List;
59   
60    import io.swagger.jaxrs.listing.ApiListingResource;
61    import io.swagger.jaxrs.listing.SwaggerSerializers;
62   
63    /**
64    * Module version handler.
65    */
 
66    public class RestToolsModuleVersionHandler extends DefaultModuleVersionHandler {
67   
68    private final static String REST_DISPATCHER_SERVLET_PATH = "/server/filters/servlets/RestDispatcherServlet";
69    private final static String PATH_TO_REST_INTEGRATION_MODULE = "/modules/rest-integration";
70   
 
71  2 toggle public RestToolsModuleVersionHandler() {
72  2 super();
73   
74  2 register(getDeltaFor1_2_0());
75    }
76   
 
77  2 toggle private Delta getDeltaFor1_2_0() {
78  2 return DeltaBuilder.update("1.2.0", "Update to 1.2.0")
79    .addTask(new SetPropertyTask("Update apiDeclarationProvider class for new Swagger version",
80    RepositoryConstants.CONFIG, PATH_TO_REST_INTEGRATION_MODULE + "/config/additionalProviders/apiDeclarationProvider", "providerClass", ApiListingResource.class.getName()))
81    .addTask(new SetPropertyTask("Update resourceListingProvider class for new Swagger version",
82    RepositoryConstants.CONFIG, PATH_TO_REST_INTEGRATION_MODULE + "/config/additionalProviders/resourceListingProvider", "providerClass", SwaggerSerializers.class.getName()))
83    .addTask(new RenameNodeTask("Rename additional provider node 'apiDeclarationProvider' to 'apiListingResource'",
84    RepositoryConstants.CONFIG, PATH_TO_REST_INTEGRATION_MODULE + "/config/additionalProviders", "apiDeclarationProvider", "apiListingResource", true))
85    .addTask(new RenameNodeTask("Rename additional provider node 'resourceListingProvider' to 'swaggerSerializers'",
86    RepositoryConstants.CONFIG, PATH_TO_REST_INTEGRATION_MODULE + "/config/additionalProviders", "resourceListingProvider", "swaggerSerializers", true))
87    .addTask(new PropertyValueDelegateTask("Update Swagger API version in configuration", "/modules/rest-tools/config", "apiVersion", "1.0.0", true,
88    new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/rest-tools/config", "apiVersion", "1.5.4")))
89    .addTask(new RemovePermissionTask("Remove old swagger doc access in 'rest' role (/.rest/api-docs*)", "rest", "uri", "/.rest/api-docs*", Permission.ALL))
90    .addTask(new AddPermissionTask("Enable swagger doc access in 'rest' role (/.rest/swagger*)", "rest", "uri", "/.rest/swagger*", Permission.ALL, false))
91    .addTask(new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/rest-tools/apps/restTools/subApps/apiDocs", "url", "/.resources/rest-tools/webresources/swagger-ui/index.html"));
92    }
93   
 
94  1 toggle @Override
95    protected List<Task> getExtraInstallTasks(InstallContext installContext) {
96  1 List<Task> list = new ArrayList<Task>();
97   
98  1 list.add(new CheckAndModifyPropertyValueTask("Replace dispatcher servlet", "Replace default dispatcher servlet with API-aware dispatcher servlet", RepositoryConstants.CONFIG,
99    REST_DISPATCHER_SERVLET_PATH, "servletClass", RestDispatcherServlet.class.getName(), SwaggerRestDispatcherServlet.class.getName()));
100   
101    // Allow web access to '/.rest/api-docs' in role 'rest'
102  1 list.add(new AddPermissionTask("Update 'rest-editor' role", "Allows access to the REST API documentation interface residing under '/.rest/swagger' in role 'rest-editor'.", "rest-editor", "uri", "/.rest/swagger*", Permission.ALL, false));
103   
104    // Add additional providers to integration module
105  1 list.add(new NodeBuilderTask("Add additional providers", "Adds additional providers to rest-integration module config (needed for API documentation)", ErrorHandling.logging,
106    RepositoryConstants.CONFIG, PATH_TO_REST_INTEGRATION_MODULE + "/config",
107    getNode("additionalProviders").then(
108    addNode("apiListingResource", NodeTypes.ContentNode.NAME).then(
109    addProperty("providerClass", ApiListingResource.class.getName())
110    ),
111    addNode("swaggerSerializers", NodeTypes.ContentNode.NAME).then(
112    addProperty("providerClass", SwaggerSerializers.class.getName())
113    )
114    )
115    ));
116   
117  1 return list;
118    }
119   
120    }