1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
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 |
|
|
62 |
|
|
|
|
| 0% |
Uncovered Elements: 46 (46) |
Complexity: 8 |
Complexity Density: 0.2 |
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
80 |
0 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
91 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
110 |
0 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
124 |
0 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
137 |
0 |
@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 |
|
} |