8 |
8 |
*/
|
9 |
9 |
package eu.etaxonomy.cdm.addon.config;
|
10 |
10 |
|
|
11 |
import java.io.IOException;
|
|
12 |
import java.util.Arrays;
|
|
13 |
import java.util.Properties;
|
|
14 |
|
11 |
15 |
import javax.servlet.annotation.WebServlet;
|
12 |
16 |
|
13 |
17 |
import org.apache.log4j.Logger;
|
|
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
19 |
import org.springframework.context.annotation.Bean;
|
14 |
20 |
import org.springframework.context.annotation.ComponentScan;
|
|
21 |
import org.springframework.context.annotation.ComponentScan.Filter;
|
15 |
22 |
import org.springframework.context.annotation.Configuration;
|
|
23 |
import org.springframework.context.annotation.FilterType;
|
|
24 |
import org.springframework.context.annotation.Lazy;
|
16 |
25 |
|
17 |
26 |
import com.vaadin.spring.annotation.EnableVaadin;
|
|
27 |
import com.vaadin.spring.annotation.SpringUI;
|
|
28 |
import com.vaadin.spring.annotation.UIScope;
|
18 |
29 |
import com.vaadin.spring.server.SpringVaadinServlet;
|
|
30 |
import com.vaadin.ui.UI;
|
19 |
31 |
|
|
32 |
import eu.etaxonomy.cdm.opt.config.DataSourceConfigurer;
|
20 |
33 |
import eu.etaxonomy.cdm.vaadin.security.annotation.EnableAnnotationBasedAccessControl;
|
|
34 |
import eu.etaxonomy.cdm.vaadin.ui.ConceptRelationshipUI;
|
|
35 |
import eu.etaxonomy.cdm.vaadin.ui.DistributionStatusUI;
|
|
36 |
import eu.etaxonomy.cdm.vaadin.ui.InactiveUIException;
|
|
37 |
import eu.etaxonomy.cdm.vaadin.ui.RegistrationUI;
|
|
38 |
import eu.etaxonomy.cdm.vaadin.ui.StatusEditorUI;
|
|
39 |
import eu.etaxonomy.cdm.vaadin.util.ConfigFileUtils;
|
21 |
40 |
import eu.etaxonomy.vaadin.ui.annotation.EnableVaadinSpringNavigation;
|
22 |
41 |
|
23 |
42 |
/**
|
... | ... | |
31 |
50 |
"eu.etaxonomy.cdm.vaadin",
|
32 |
51 |
"eu.etaxonomy.vaadin.ui",
|
33 |
52 |
"eu.etaxonomy.cdm.mock" // FIXME remove once mocks are no longer needed
|
34 |
|
})
|
|
53 |
},
|
|
54 |
// exclude UI classes, these are provided via the @Bean annotated methods below
|
|
55 |
excludeFilters={@Filter(
|
|
56 |
pattern="eu\\.etaxonomy\\.cdm\\.vaadin\\.ui\\..*",
|
|
57 |
type=FilterType.REGEX
|
|
58 |
)
|
|
59 |
})
|
35 |
60 |
@EnableVaadin // this imports VaadinConfiguration
|
36 |
61 |
@EnableVaadinSpringNavigation // activate the NavigationManagerBean
|
37 |
62 |
@EnableAnnotationBasedAccessControl // enable annotation based per view access control
|
38 |
63 |
public class CdmVaadinConfiguration {
|
39 |
64 |
|
|
65 |
/**
|
|
66 |
*
|
|
67 |
*/
|
|
68 |
private static final String CDM_VAADIN_UI_ACTIVATED = "cdm-vaadin.ui.activated";
|
|
69 |
|
40 |
70 |
public static final Logger logger = Logger.getLogger(CdmVaadinConfiguration.class);
|
41 |
71 |
|
|
72 |
@Autowired
|
|
73 |
@Lazy
|
|
74 |
//FIXME consider to set the instanceName (instanceID) in the spring environment to avoid a bean reference here
|
|
75 |
private DataSourceConfigurer dataSourceConfigurer;
|
|
76 |
|
42 |
77 |
/*
|
43 |
78 |
* NOTE: It is necessary to map the URLs starting with /VAADIN/* since none of the
|
44 |
79 |
* @WebServlets is mapped to the root path. It is sufficient to configure one of the
|
... | ... | |
46 |
81 |
*/
|
47 |
82 |
@WebServlet(value = {"/app/*", "/VAADIN/*"}, asyncSupported = true)
|
48 |
83 |
public static class Servlet extends SpringVaadinServlet {
|
|
84 |
|
|
85 |
private static final long serialVersionUID = -2615042297393028775L;
|
|
86 |
|
|
87 |
/**
|
|
88 |
*
|
|
89 |
@SuppressWarnings("serial")
|
|
90 |
@Override
|
|
91 |
protected void servletInitialized() throws ServletException {
|
|
92 |
getService().addSessionInitListener(new SessionInitListener() {
|
|
93 |
|
|
94 |
@Override
|
|
95 |
public void sessionInit(SessionInitEvent sessionInitEvent) throws ServiceException {
|
|
96 |
VaadinSession session = sessionInitEvent.getSession();
|
|
97 |
session.setErrorHandler(new DefaultErrorHandler(){
|
|
98 |
|
|
99 |
@Override
|
|
100 |
public void error(ErrorEvent errorEvent) {
|
|
101 |
if(errorEvent.getThrowable() instanceof InactiveUIException){
|
|
102 |
//TODO redirect to an ErrorUI or show and error Page
|
|
103 |
// better use Spring MVC Error handlers instead?
|
|
104 |
} else {
|
|
105 |
doDefault(errorEvent);
|
|
106 |
}
|
|
107 |
}
|
|
108 |
|
|
109 |
});
|
|
110 |
|
|
111 |
}});
|
|
112 |
|
|
113 |
}
|
|
114 |
*/
|
|
115 |
|
49 |
116 |
}
|
50 |
117 |
|
51 |
118 |
public CdmVaadinConfiguration() {
|
52 |
119 |
logger.debug("CdmVaadinConfiguration enabled");
|
53 |
120 |
}
|
54 |
121 |
|
|
122 |
@Bean
|
|
123 |
@UIScope
|
|
124 |
public ConceptRelationshipUI conceptRelationshipUI() throws InactiveUIException {
|
|
125 |
if(isUIEnabled(ConceptRelationshipUI.class)){
|
|
126 |
return new ConceptRelationshipUI();
|
|
127 |
}
|
|
128 |
return null;
|
|
129 |
}
|
|
130 |
|
|
131 |
@Bean
|
|
132 |
@UIScope
|
|
133 |
public RegistrationUI registrationUI() throws InactiveUIException {
|
|
134 |
if(isUIEnabled(RegistrationUI.class)){
|
|
135 |
return new RegistrationUI();
|
|
136 |
}
|
|
137 |
return null;
|
|
138 |
}
|
|
139 |
|
|
140 |
@Bean
|
|
141 |
@UIScope
|
|
142 |
public DistributionStatusUI distributionStatusUI() throws InactiveUIException {
|
|
143 |
if(isUIEnabled(DistributionStatusUI.class)){
|
|
144 |
return new DistributionStatusUI();
|
|
145 |
}
|
|
146 |
return null;
|
|
147 |
}
|
|
148 |
|
|
149 |
@Bean
|
|
150 |
@UIScope
|
|
151 |
public StatusEditorUI statusEditorUI() throws InactiveUIException {
|
|
152 |
if(isUIEnabled(StatusEditorUI.class)){
|
|
153 |
return new StatusEditorUI();
|
|
154 |
}
|
|
155 |
return null;
|
|
156 |
}
|
|
157 |
|
|
158 |
|
|
159 |
/**
|
|
160 |
* Checks if the ui class supplied is activated by listing it in the properties by its {@link SpringUI#path()} value.
|
|
161 |
*
|
|
162 |
* @param type
|
|
163 |
* @return
|
|
164 |
* @throws InactiveUIException
|
|
165 |
*/
|
|
166 |
private boolean isUIEnabled(Class<? extends UI>uiClass) throws InactiveUIException {
|
|
167 |
String path = uiClass.getAnnotation(SpringUI.class).path();
|
|
168 |
|
|
169 |
try {
|
|
170 |
Properties appProps = ConfigFileUtils.getApplicationProperties(dataSourceConfigurer.dataSourceProperties().getCurrentDataSourceId());
|
|
171 |
if(appProps.get(CDM_VAADIN_UI_ACTIVATED) != null){
|
|
172 |
String[] uiPaths = appProps.get(CDM_VAADIN_UI_ACTIVATED).toString().split("\\s*,\\s*");
|
|
173 |
return Arrays.asList(uiPaths).stream().anyMatch(p -> p.equals(path));
|
|
174 |
}
|
|
175 |
throw new InactiveUIException(path);
|
|
176 |
} catch (IOException e) {
|
|
177 |
logger.error("Error reading the vaadin ui properties file. File corrupted?. Stopping instance ...");
|
|
178 |
throw new RuntimeException(e);
|
|
179 |
}
|
|
180 |
}
|
|
181 |
|
55 |
182 |
|
56 |
183 |
}
|
fix #6628 UI enablement via per instance property files, UIs are now inactive per default