View Javadoc
1   /**
2    * This file Copyright (c) 2020 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.pages.app.setup;
35  
36  import info.magnolia.jcr.util.NodeTypes;
37  import info.magnolia.module.DefaultModuleVersionHandler;
38  import info.magnolia.module.InstallContext;
39  import info.magnolia.module.delta.ArrayDelegateTask;
40  import info.magnolia.module.delta.CheckOrCreatePropertyTask;
41  import info.magnolia.module.delta.CreateNodeTask;
42  import info.magnolia.module.delta.DeltaBuilder;
43  import info.magnolia.module.delta.HasPropertyDelegateTask;
44  import info.magnolia.module.delta.IsModuleInstalledOrRegistered;
45  import info.magnolia.module.delta.NodeExistsDelegateTask;
46  import info.magnolia.module.delta.OrderNodeToFirstPositionTask;
47  import info.magnolia.module.delta.RemoveNodeTask;
48  import info.magnolia.module.delta.RemovePropertyTask;
49  import info.magnolia.module.delta.Task;
50  
51  import java.util.Collections;
52  import java.util.List;
53  
54  import org.apache.commons.lang3.StringUtils;
55  
56  /**
57   * Version handler for the Pages app module.
58   */
59  public class PagesAppModuleVersionHandler extends DefaultModuleVersionHandler {
60      public static final String PAGES_APP_ID = "pages-app";
61      public static final String OLD_PAGES_APP_ID = "pages";
62      public static final String EDIT_APPS_PATH = "/modules/ui-admincentral/config/appLauncherLayout/groups/edit/apps/";
63      public static final String HIDDEN_APPS_PATH = "/modules/ui-admincentral/config/appLauncherLayout/hiddenApps/";
64  
65      public PagesAppModuleVersionHandler() {
66          super();
67          register(DeltaBuilder.update("6.2", "Configuration update for Pages app 6.2")
68                               .addTask(addPagesAppToFirstPositionOfEditApps())
69                               .addTask(hideM5PagesApp())
70          );
71          register(DeltaBuilder.update("6.2.7", "")
72                  .addTask(new RemoveNodeTask("Remove JCR applauncher config", EDIT_APPS_PATH + PAGES_APP_ID))
73          );
74      }
75  
76      @Override
77      protected List<Task> getExtraInstallTasks(InstallContext installContext) {
78          return Collections.singletonList(hideM5PagesApp());
79      }
80  
81      private ArrayDelegateTask addPagesAppToFirstPositionOfEditApps() {
82          ArrayDelegateTask addToFirstTask = new ArrayDelegateTask("Add Pages App to first position of Edit Apps Group");
83  
84          // Add if missing
85          addToFirstTask.addTask(new NodeExistsDelegateTask("Add " + EDIT_APPS_PATH + PAGES_APP_ID +" if missing", EDIT_APPS_PATH + PAGES_APP_ID, null, new CreateNodeTask(EDIT_APPS_PATH + PAGES_APP_ID + " is missing", EDIT_APPS_PATH, PAGES_APP_ID, NodeTypes.ContentNode.NAME)));
86  
87          // Move to first position of Edit Apps Group
88          addToFirstTask.addTask(new OrderNodeToFirstPositionTask("Move " + PAGES_APP_ID + " to first position of " + EDIT_APPS_PATH, StringUtils.removeStart(EDIT_APPS_PATH + PAGES_APP_ID, "/")));
89  
90          return addToFirstTask;
91      }
92  
93      private IsModuleInstalledOrRegistered hideM5PagesApp(){
94          return new IsModuleInstalledOrRegistered("Hide M5 Pages app", OLD_PAGES_APP_ID,
95                  // if was bundled, then move to hidden
96                  new CheckOrCreatePropertyTask("Move " + OLD_PAGES_APP_ID + " to Admin Central Launcher - Hidden Apps Group", HIDDEN_APPS_PATH, OLD_PAGES_APP_ID, OLD_PAGES_APP_ID),
97                  // was not bundled, then remove out of applauncher if exist
98                  new ArrayDelegateTask("Remove " + OLD_PAGES_APP_ID + " from AppLauncher if existing",
99                          new NodeExistsDelegateTask("Remove " + OLD_PAGES_APP_ID + " from Edit Apps Group if existing", EDIT_APPS_PATH + OLD_PAGES_APP_ID, new RemoveNodeTask("", EDIT_APPS_PATH + OLD_PAGES_APP_ID)
100                         ),
101                         new HasPropertyDelegateTask("Remove " + OLD_PAGES_APP_ID + " property from Hidden Apps Group if existing", HIDDEN_APPS_PATH, OLD_PAGES_APP_ID, new RemovePropertyTask("", HIDDEN_APPS_PATH, OLD_PAGES_APP_ID)
102                         )
103                 )
104         );
105     }
106 }