Revision a51b1d57
Added by Andreas Kohlbecker almost 6 years ago
src/main/java/eu/etaxonomy/cdm/addon/config/CdmVaadinConfiguration.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
import java.io.IOException; |
12 | 12 |
import java.util.Arrays; |
13 |
import java.util.List; |
|
13 | 14 |
import java.util.Properties; |
14 | 15 |
|
15 | 16 |
import javax.servlet.annotation.WebServlet; |
... | ... | |
25 | 26 |
import org.springframework.context.annotation.Configuration; |
26 | 27 |
import org.springframework.context.annotation.FilterType; |
27 | 28 |
import org.springframework.context.annotation.Lazy; |
29 |
import org.springframework.core.env.Environment; |
|
28 | 30 |
import org.springframework.security.authentication.AuthenticationProvider; |
29 | 31 |
|
30 | 32 |
import com.vaadin.spring.annotation.EnableVaadin; |
... | ... | |
68 | 70 |
@EnableVaadin // this imports VaadinConfiguration |
69 | 71 |
@EnableVaadinSpringNavigation // activate the NavigationManagerBean |
70 | 72 |
@EnableAnnotationBasedAccessControl // enable annotation based per view access control |
71 |
// @EnableTransactionManagement(mode=AdviceMode.ASPECTJ) // has no effect here |
|
72 | 73 |
public class CdmVaadinConfiguration implements ApplicationContextAware { |
73 | 74 |
|
74 |
/** |
|
75 |
*
|
|
76 |
*/ |
|
77 |
private static final String CDM_VAADIN_UI_ACTIVATED = "cdm-vaadin.ui.activated";
|
|
75 |
|
|
76 |
public static final String CDM_DATA_SOURCE_ID = "cdm.dataSource.id";
|
|
77 |
|
|
78 |
public static final String CDM_VAADIN_UI_ACTIVATED = "cdm-vaadin.ui.activated";
|
|
78 | 79 |
|
79 | 80 |
public static final Logger logger = Logger.getLogger(CdmVaadinConfiguration.class); |
80 | 81 |
|
82 |
@Autowired |
|
83 |
Environment env; |
|
84 |
|
|
81 | 85 |
@Autowired |
82 | 86 |
@Lazy |
83 | 87 |
//FIXME consider to set the instanceName (instanceID) in the spring environment to avoid a bean reference here |
88 |
// key CDM_DATA_SOURCE_ID is already declared here |
|
84 | 89 |
private DataSourceConfigurer dataSourceConfigurer; |
85 | 90 |
|
86 | 91 |
/* |
... | ... | |
93 | 98 |
|
94 | 99 |
private static final long serialVersionUID = -2615042297393028775L; |
95 | 100 |
|
101 |
|
|
96 | 102 |
/** |
97 | 103 |
* |
98 | 104 |
@SuppressWarnings("serial") |
... | ... | |
145 | 151 |
public AbstractDataInserter registrationRequiredDataInserter() throws BeansException{ |
146 | 152 |
if(isUIEnabled(RegistrationUI.class)){ |
147 | 153 |
RegistrationRequiredDataInserter inserter = new RegistrationRequiredDataInserter(); |
154 |
|
|
148 | 155 |
inserter.setRunAsAuthenticationProvider((AuthenticationProvider) applicationContext.getBean("runAsAuthenticationProvider")); |
149 | 156 |
inserter.setCdmRepository((CdmRepository) applicationContext.getBean("cdmRepository")); |
150 | 157 |
return inserter; |
... | ... | |
179 | 186 |
|
180 | 187 |
private ApplicationContext applicationContext; |
181 | 188 |
|
189 |
private List<String> activeUIpaths; |
|
190 |
|
|
182 | 191 |
//@formatter:off |
183 | 192 |
private static final String APP_FILE_CONTENT= |
184 | 193 |
"########################################################\n"+ |
... | ... | |
206 | 215 |
|
207 | 216 |
String path = uiClass.getAnnotation(SpringUI.class).path().trim(); |
208 | 217 |
|
209 |
try { |
|
210 |
if(appProps == null){ |
|
211 |
String currentDataSourceId = dataSourceConfigurer.dataSourceProperties().getCurrentDataSourceId(); |
|
212 |
appProps = new ConfigFileUtil() |
|
213 |
.setDefaultContent(APP_FILE_CONTENT) |
|
214 |
.getProperties(currentDataSourceId, PROPERTIES_NAME); |
|
215 |
} |
|
216 |
if(appProps.get(CDM_VAADIN_UI_ACTIVATED) != null){ |
|
217 |
String[] uiPaths = appProps.get(CDM_VAADIN_UI_ACTIVATED).toString().split("\\s*,\\s*"); |
|
218 |
if(Arrays.asList(uiPaths).stream().anyMatch(p -> p.trim().equals(path))){ |
|
219 |
return true; |
|
218 |
if(activeUIpaths == null){ |
|
219 |
try { |
|
220 |
String currentDataSourceId = env.getProperty(CDM_DATA_SOURCE_ID); |
|
221 |
String activatedVaadinUIs = env.getProperty(CDM_VAADIN_UI_ACTIVATED); |
|
222 |
if(activatedVaadinUIs == null){ |
|
223 |
// not in environment? Read it from the config file! |
|
224 |
if(appProps == null){ |
|
225 |
if(currentDataSourceId == null){ |
|
226 |
currentDataSourceId = dataSourceConfigurer.dataSourceProperties().getCurrentDataSourceId(); |
|
227 |
} |
|
228 |
appProps = new ConfigFileUtil() |
|
229 |
.setDefaultContent(APP_FILE_CONTENT) |
|
230 |
.getProperties(currentDataSourceId, PROPERTIES_NAME); |
|
231 |
} |
|
232 |
if(appProps.get(CDM_VAADIN_UI_ACTIVATED) != null){ |
|
233 |
activatedVaadinUIs = appProps.get(CDM_VAADIN_UI_ACTIVATED).toString(); |
|
234 |
} |
|
220 | 235 |
} |
236 |
if(activatedVaadinUIs != null) { |
|
237 |
String[] uiPaths = activatedVaadinUIs.split("\\s*,\\s*"); |
|
238 |
this.activeUIpaths = Arrays.asList(uiPaths); |
|
239 |
} |
|
240 |
} catch (IOException e) { |
|
241 |
logger.error("Error reading the vaadin ui properties file. File corrupted?. Stopping instance ..."); |
|
242 |
throw new RuntimeException(e); |
|
221 | 243 |
} |
222 |
return false; |
|
223 |
} catch (IOException e) { |
|
224 |
logger.error("Error reading the vaadin ui properties file. File corrupted?. Stopping instance ..."); |
|
225 |
throw new RuntimeException(e); |
|
226 | 244 |
} |
245 |
if(activeUIpaths.stream().anyMatch(p -> p.trim().equals(path))){ |
|
246 |
return true; |
|
247 |
} |
|
248 |
return false; |
|
249 |
|
|
227 | 250 |
} |
228 | 251 |
|
229 | 252 |
/** |
Also available in: Unified diff
CdmVaadinConfiguration with support for test classes to define enabled ui via environment variables