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.about.app;
35
36 import static info.magnolia.about.app.AboutView.*;
37
38 import info.magnolia.cms.beans.config.ServerConfiguration;
39 import info.magnolia.cms.pddescriptor.ProductDescriptorExtractor;
40 import info.magnolia.i18nsystem.SimpleTranslator;
41 import info.magnolia.init.MagnoliaConfigurationProperties;
42 import info.magnolia.objectfactory.Components;
43
44 import javax.inject.Inject;
45
46 import org.apache.commons.lang3.StringUtils;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49
50 import com.vaadin.data.Item;
51 import com.vaadin.data.util.ObjectProperty;
52 import com.vaadin.data.util.PropertysetItem;
53
54
55
56
57 public class AboutPresenter {
58
59 private static final Logger log = LoggerFactory.getLogger(AboutPresenter.class);
60
61 static final String COMMUNITY_EDITION_I18N_KEY = "about.app.main.communityEdition";
62 static final String INSTANCE_AUTHOR_I18N_KEY = "about.app.main.instance.author";
63 static final String INSTANCE_PUBLIC_I18N_KEY = "about.app.main.instance.public";
64 static final String UNKNOWN_PROPERTY_I18N_KEY = "about.app.main.unknown";
65
66 protected final SimpleTranslator i18n;
67 private final String unknownProperty;
68
69 private final AboutView view;
70 private final InstanceConfigurationProvider configProvider;
71
72
73
74
75 @Deprecated
76 protected Item viewData = new PropertysetItem();
77
78 @Inject
79 public AboutPresenter(final AboutView view, final InstanceConfigurationProvider configProvider, final SimpleTranslator i18n) {
80 this.view = view;
81 this.configProvider = configProvider;
82 this.i18n = i18n;
83 this.unknownProperty = i18n.translate(UNKNOWN_PROPERTY_I18N_KEY);
84 }
85
86
87
88
89 @Deprecated
90 public AboutPresenter(AboutView view, ServerConfiguration serverConfiguration, MagnoliaConfigurationProperties magnoliaProperties, SimpleTranslator i18n, ProductDescriptorExtractor productDescriptorExtractor) {
91 this(view, Components.getComponent(InstanceConfigurationProvider.class), i18n);
92 }
93
94
95
96
97 @Deprecated
98 public AboutPresenter(AboutView view, ServerConfiguration serverConfiguration, MagnoliaConfigurationProperties magnoliaProperties, SimpleTranslator i18n) {
99 this(view, Components.getComponent(InstanceConfigurationProvider.class), i18n);
100 }
101
102 public AboutView start() {
103 Item viewData = getInstallationInfo();
104
105 if (!this.viewData.getItemPropertyIds().isEmpty()) {
106 this.viewData.getItemPropertyIds().forEach(
107 propertyId -> viewData.addItemProperty(propertyId,
108 AboutPresenter.this.viewData.getItemProperty(propertyId)));
109 }
110 view.setDataSource(viewData);
111 return view;
112 }
113
114 protected Item getInstallationInfo() {
115 PropertysetItem viewData = new PropertysetItem();
116
117 String mgnlEdition = getEditionName();
118 String mgnlVersion = configProvider.getMagnoliaVersion();
119 String authorInstance = configProvider.isAdmin() ?
120 i18n.translate(INSTANCE_AUTHOR_I18N_KEY) :
121 i18n.translate(INSTANCE_PUBLIC_I18N_KEY);
122
123
124 String osInfo = String.format("%s %s (%s)", configProvider.getOSName(),
125 configProvider.getOSVersion(), configProvider.getOSArch());
126 String javaInfo = String.format("%s %s (build %s)", configProvider.getJavaVendor(),
127 configProvider.getJavaVersion(), configProvider.getJavaRuntimeVersion());
128 String serverInfo = configProvider.getApplicationServer();
129
130 String dbInfo = configProvider.getDatabase();
131 String dbDriverInfo = configProvider.getDatabaseDriver();
132 if (StringUtils.isBlank(dbInfo)) {
133 dbInfo = i18n.translate(UNKNOWN_PROPERTY_I18N_KEY);
134 }
135 if (StringUtils.isBlank(dbDriverInfo)) {
136 dbInfo = i18n.translate(UNKNOWN_PROPERTY_I18N_KEY);
137 }
138
139 String jcrInfo = String.format("%s %s", configProvider.getJcrName(),
140 configProvider.getJcrVersion());
141
142
143 addItemProperty(viewData, MAGNOLIA_EDITION_KEY, mgnlEdition);
144 addItemProperty(viewData, MAGNOLIA_VERSION_KEY, mgnlVersion);
145 addItemProperty(viewData, MAGNOLIA_INSTANCE_KEY, authorInstance);
146 addItemProperty(viewData, OS_INFO_KEY, osInfo);
147 addItemProperty(viewData, JAVA_INFO_KEY, javaInfo);
148 addItemProperty(viewData, SERVER_INFO_KEY, serverInfo);
149 addItemProperty(viewData, JCR_INFO_KEY, jcrInfo);
150 addItemProperty(viewData, DB_INFO_KEY, dbInfo);
151 addItemProperty(viewData, DB_DRIVER_INFO_KEY, dbDriverInfo);
152
153 return viewData;
154 }
155
156
157
158
159 protected void addItemProperty(Item viewData, String key, String value) {
160 viewData.addItemProperty(key, new ObjectProperty<>(StringUtils.defaultIfBlank(value, unknownProperty)));
161 }
162
163
164
165
166 @Deprecated
167 protected void addViewProperty(String key, String value) {
168 viewData.addItemProperty(key, new ObjectProperty<>(StringUtils.defaultIfBlank(value, unknownProperty)));
169 }
170
171 protected AboutView getView() {
172 return view;
173 }
174
175 protected String getEditionName() {
176
177
178 return i18n.translate(AboutPresenter.COMMUNITY_EDITION_I18N_KEY);
179 }
180
181
182
183
184 @Deprecated
185 String[] getConnectionString() {
186 return configProvider.getConnectionString();
187 }
188
189
190
191
192 @Deprecated
193 String getRepoName() {
194 return configProvider.getRepositoryName();
195 }
196 }