Skip to content
Snippets Groups Projects
Commit ddc73423 authored by gpawel's avatar gpawel
Browse files

SP-215 BIS-130: Standard technologies application context should include...

SP-215 BIS-130: Standard technologies application context should include needed parts depending on enabled-technologies property

SVN: 26283
parent 1ea71b0a
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2012 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.common.spring;
import java.util.ArrayList;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.AbstractRefreshableConfigApplicationContext;
/**
* Bootstrapper bean responsible for loading resources conditionally basing on property values.
* Normally properties are initialized by Spring after all beans are being instanced - this class
* workarounds this problem by refreshing the application context after properties are being loaded.
*
* @author Pawel Glyzewski
*/
public class Bootstrapper implements ApplicationContextAware, InitializingBean
{
private AbstractRefreshableConfigApplicationContext context;
private String[] configLocations;
private String[] conditionalConfigLocations;
public void setConfigLocation(final String configLocation)
{
this.configLocations = new String[]
{ configLocation };
}
public void setConditionalConfigLocations(final String[] conditionalConfigLocations)
{
this.conditionalConfigLocations = conditionalConfigLocations;
}
@Override
public void setApplicationContext(final ApplicationContext applicationContext)
throws BeansException
{
context = (AbstractRefreshableConfigApplicationContext) applicationContext;
}
@Override
public void afterPropertiesSet() throws Exception
{
ArrayList<String> allConfigLocations = new ArrayList<String>();
for (String configLocation : configLocations)
{
allConfigLocations.add(configLocation);
}
if (conditionalConfigLocations != null)
{
for (String conditionalConfigLocationString : conditionalConfigLocations)
{
int index = conditionalConfigLocationString.indexOf(":");
if (index != -1)
{
String condition = conditionalConfigLocationString.substring(0, index);
if (evaluateCondition(condition))
{
allConfigLocations
.add(conditionalConfigLocationString.substring(index + 1));
}
}
}
}
context.setConfigLocations(allConfigLocations.toArray(new String[allConfigLocations.size()]));
context.refresh();
}
private static boolean evaluateCondition(String condition)
{
if (condition.contains("~"))
{
int index = condition.indexOf("~");
String property = condition.substring(0, index);
String containedText = condition.substring(index + 1);
return property.contains(containedText);
}
return false;
}
}
......@@ -31,16 +31,3 @@ if [ -d "$DATA_TMPEXTRACT" ]; then
done
rm -rf "$DATA_TMPEXTRACT"
fi
APPLICATION_CONTEXT_FILE="$INSTALL_PATH/servers/openBIS-server/jetty/webapps/openbis/WEB-INF/classes/standard-technologies-applicationContext.xml"
if [ -f "$APPLICATION_CONTEXT_FILE" ]; then
tmpFile="$BASE/xxx.xml"
awk '/plugin-applicationContext/{gsub(/!*--/,"")}; 1' "$APPLICATION_CONTEXT_FILE" > "$tmpFile"
mv "$tmpFile" "$APPLICATION_CONTEXT_FILE"
awk '/plugin-applicationContext/{gsub(/import/,"!--import") gsub(/>/,"-->")}; 1' "$APPLICATION_CONTEXT_FILE" > "$tmpFile"
mv "$tmpFile" "$APPLICATION_CONTEXT_FILE"
for technology in $ENABLED_TECHNOLOGIES; do
awk -v technology=${technology/,/} 'index($0, technology){gsub(/!*--/,"")}; 1' "$APPLICATION_CONTEXT_FILE" > "$tmpFile"
mv "$tmpFile" "$APPLICATION_CONTEXT_FILE"
done
fi
\ No newline at end of file
......@@ -8,14 +8,22 @@
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
http://www.springframework.org/schema/context/spring-context-2.5.xsd
">
<import resource="applicationContext.xml"/>
<import resource="proteomics-plugin-applicationContext.xml"/>
<import resource="screening-plugin-applicationContext.xml"/>
<bean name="bootstrap" class="ch.systemsx.cisd.common.spring.Bootstrapper">
<property name="configLocation" value="classpath:applicationContext.xml" />
<property name="conditionalConfigLocations">
<list>
<value>${enabled-technologies}~proteomics:classpath:proteomics-plugin-applicationContext.xml</value>
<value>${enabled-technologies}~screening:classpath:screening-plugin-applicationContext.xml</value>
</list>
</property>
</bean>
<plugins:component-scan base-package="ch.systemsx.cisd.openbis" annotation-config="false">
<plugins:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</plugins:component-scan>
</beans>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment