Clover icon

Magnolia Module Cache APP 5.5.9

  1. Project Clover database Mon Nov 25 2019 16:51:22 CET
  2. Package info.magnolia.module.cache.app

File CacheToolsPresenter.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
16% of files have more coverage

Code metrics

0
41
5
1
150
95
8
0.2
8.2
5
1.6

Classes

Class Line # Actions
CacheToolsPresenter 63 41 0% 8 46
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2014-2018 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.cache.app;
35   
36    import info.magnolia.commands.CommandsManager;
37    import info.magnolia.context.MgnlContext;
38    import info.magnolia.i18nsystem.SimpleTranslator;
39    import info.magnolia.module.cache.commands.FlushCachesCommand;
40    import info.magnolia.module.cache.commands.FlushFromCachesByUUIDCommand;
41    import info.magnolia.module.cache.commands.FlushNamedCacheCommand;
42    import info.magnolia.objectfactory.ComponentProvider;
43    import info.magnolia.ui.api.app.SubAppContext;
44    import info.magnolia.ui.api.context.UiContext;
45    import info.magnolia.ui.dialog.formdialog.FormBuilder;
46    import info.magnolia.ui.form.definition.FormDefinition;
47    import info.magnolia.ui.vaadin.form.FormViewReduced;
48    import info.magnolia.ui.vaadin.overlay.MessageStyleTypeEnum;
49   
50    import java.util.HashMap;
51    import java.util.Map;
52   
53    import javax.inject.Inject;
54   
55    import org.slf4j.Logger;
56    import org.slf4j.LoggerFactory;
57   
58    import com.vaadin.data.util.PropertysetItem;
59   
60    /**
61    * Cache tools presenter.
62    */
 
63    public class CacheToolsPresenter implements CacheToolsView.Listener {
64   
65    private static final Logger log = LoggerFactory.getLogger(CacheToolsPresenter.class);
66   
67    private static final String CACHE_CATALOG = "cache";
68    private static final String FLUSH_ALL_COMMAND = "flushAll";
69    private static final String FLUSH_BY_UUID_COMMAND = "flushByUUID";
70    private static final String FLUSH_BY_NAME_COMMAND = "flushNamedCache";
71   
72    private final CacheToolsSubAppDescriptor cacheToolsSubApp;
73    private final CacheToolsView view;
74    private FormBuilder formBuilder;
75    private ComponentProvider componentProvider;
76    private final UiContext uiContext;
77    private CommandsManager commandsManager;
78    private final SimpleTranslator i18n;
79   
 
80  0 toggle @Inject
81    public CacheToolsPresenter(CacheToolsView view, FormBuilder formBuilder, ComponentProvider componentProvider, SubAppContext subAppContext, UiContext uiContext, CommandsManager commandsManager, SimpleTranslator i18n) {
82  0 this.view = view;
83  0 this.formBuilder = formBuilder;
84  0 this.componentProvider = componentProvider;
85  0 this.uiContext = uiContext;
86  0 this.commandsManager = commandsManager;
87  0 this.i18n = i18n;
88  0 cacheToolsSubApp = (CacheToolsSubAppDescriptor) subAppContext.getSubAppDescriptor();
89    }
90   
 
91  0 toggle public CacheToolsView start() {
92  0 Map<String, FormViewReduced> formViews = new HashMap<String, FormViewReduced>();
93   
94  0 FormDefinition formDefinition = cacheToolsSubApp.getFormDefinitions().get(CacheToolsView.FLUSH_BY_UUID_FORMVIEW);
95  0 FormViewReduced formViewReduced = componentProvider.getComponent(FormViewReduced.class);
96  0 formBuilder.buildReducedForm(formDefinition, formViewReduced, new PropertysetItem(), null);
97  0 formViews.put(CacheToolsView.FLUSH_BY_UUID_FORMVIEW, formViewReduced);
98   
99  0 formDefinition = cacheToolsSubApp.getFormDefinitions().get(CacheToolsView.FLUSH_BY_NAME_FORMVIEW);
100  0 formViewReduced = componentProvider.getComponent(FormViewReduced.class);
101  0 formBuilder.buildReducedForm(formDefinition, formViewReduced, new PropertysetItem(), null);
102  0 formViews.put(CacheToolsView.FLUSH_BY_NAME_FORMVIEW, formViewReduced);
103   
104  0 view.setFormViewsReduced(formViews);
105  0 view.build();
106  0 view.setListener(this);
107  0 return view;
108    }
109   
 
110  0 toggle @Override
111    public void flushCacheByUuid(String workspace, String uuid) {
112  0 FlushFromCachesByUUIDCommand command = (FlushFromCachesByUUIDCommand) commandsManager.getCommand(CACHE_CATALOG, FLUSH_BY_UUID_COMMAND);
113  0 command.setWorkspace(workspace);
114  0 command.setUuid(uuid);
115  0 try {
116  0 command.execute(MgnlContext.getInstance());
117  0 uiContext.openNotification(MessageStyleTypeEnum.INFO, true, i18n.translate("cacheTools.app.main.flushByUuid.success", uuid, workspace));
118    } catch (Exception e) {
119  0 log.warn("Unable to flush uuid {}@{} from cache.", workspace, uuid, e);
120  0 uiContext.openNotification(MessageStyleTypeEnum.ERROR, true, i18n.translate("cacheTools.app.main.flushByUuid.error", uuid, workspace));
121    }
122    }
123   
 
124  0 toggle @Override
125    public void flushCacheByName(String cacheName) {
126  0 FlushNamedCacheCommand command = (FlushNamedCacheCommand) commandsManager.getCommand(CACHE_CATALOG, FLUSH_BY_NAME_COMMAND);
127  0 command.setCacheName(cacheName);
128  0 try {
129  0 command.execute(MgnlContext.getInstance());
130  0 uiContext.openNotification(MessageStyleTypeEnum.INFO, true, i18n.translate("cacheTools.app.main.flushByName.success", cacheName));
131    } catch (Exception e) {
132  0 log.warn("Unable to flush cache {}.", cacheName, e);
133  0 uiContext.openNotification(MessageStyleTypeEnum.ERROR, true, i18n.translate("cacheTools.app.main.flushByName.error", cacheName));
134    }
135    }
136   
 
137  0 toggle @Override
138    public void flushAllCaches() {
139  0 FlushCachesCommand command = (FlushCachesCommand) commandsManager.getCommand(CACHE_CATALOG, FLUSH_ALL_COMMAND);
140  0 try {
141  0 command.execute(MgnlContext.getInstance());
142  0 uiContext.openNotification(MessageStyleTypeEnum.INFO, true, i18n.translate("cacheTools.app.main.flushAll.success"));
143    } catch (Exception e) {
144  0 log.warn("Unable to flush all caches.", e);
145  0 uiContext.openNotification(MessageStyleTypeEnum.ERROR, true, i18n.translate("cacheTools.app.main.flushAll.error"));
146    }
147    }
148   
149   
150    }