ServletContext application = event.getServletContext();
//load logging system manually so that we get the placeholders ${} swapped out for real values
PropertyConfigurator.configure(application.getRealPath("/")+"/WEB-INF/log4j.miso.properties");
XmlWebApplicationContext context = (XmlWebApplicationContext)WebApplicationContextUtils.getRequiredWebApplicationContext(application);
//resolve property file configuration placeholders
MisoPropertyExporter exporter = (MisoPropertyExporter) context.getBean("propertyConfigurer");
Map<String, String> misoProperties = exporter.getResolvedProperties();
log.info("Checking MISO storage paths...");
String baseStoragePath = misoProperties.get("miso.baseDirectory");
context.getServletContext().setAttribute("miso.baseDirectory", baseStoragePath);
String taxonLookupEnabled = misoProperties.get("miso.taxonLookup.enabled");
context.getServletContext().setAttribute("taxonLookupEnabled", Boolean.parseBoolean(taxonLookupEnabled));
Map<String, String> dirchecks = MisoWebUtils.checkStorageDirectories(baseStoragePath);
if (dirchecks.keySet().contains("error")) {
log.error(dirchecks.get("error"));
}
else {
log.info(dirchecks.get("ok"));
}
//set headless property so JFreeChart doesn't try to use the X rendering system to generate images
System.setProperty("java.awt.headless", "true");
//set up naming schemes
MisoEntityNamingSchemeResolverService entityNamingSchemeResolverService = (MisoEntityNamingSchemeResolverService)context.getBean("entityNamingSchemeResolverService");
Collection<MisoNamingScheme<?>> mnss = entityNamingSchemeResolverService.getNamingSchemes();
MisoNameGeneratorResolverService nameGeneratorResolverService = (MisoNameGeneratorResolverService)context.getBean("nameGeneratorResolverService");
Collection<NameGenerator<?>> ngs = nameGeneratorResolverService.getNameGenerators();
for (MisoNamingScheme<?> mns : mnss) {
log.info("Got naming scheme: " + mns.getSchemeName());
String classname = mns.namingSchemeFor().getSimpleName().toLowerCase();
if (misoProperties.containsKey("miso.naming.scheme."+classname) && misoProperties.get("miso.naming.scheme."+classname).equals(mns.getSchemeName())) {
for (String key : misoProperties.keySet()) {
if (key.startsWith("miso.naming.generator."+classname)) {
String genprop = key.substring(key.lastIndexOf(".")+1);
NameGenerator ng = nameGeneratorResolverService.getNameGenerator(misoProperties.get("miso.naming.generator."+classname+"."+genprop));
if (ng != null) {
mns.registerCustomNameGenerator(genprop, ng);
}
}
}
if ("nameable".equals(classname)) {
log.info("Replacing default global namingScheme with " + mns.getSchemeName());
((DefaultListableBeanFactory)context.getBeanFactory()).removeBeanDefinition("namingScheme");
context.getBeanFactory().registerSingleton("namingScheme", mns);
}
else {
log.info("Replacing default "+classname+"NamingScheme with " + mns.getSchemeName());
((DefaultListableBeanFactory)context.getBeanFactory()).removeBeanDefinition(classname+"NamingScheme");
context.getBeanFactory().registerSingleton(classname+"NamingScheme", mns);
}
}
for (String key : misoProperties.keySet()) {
if (key.startsWith("miso.naming.validation."+classname)) {
String prop = key.substring(key.lastIndexOf(".")+1);
try {
mns.setValidationRegex(prop, misoProperties.get("miso.naming.validation."+classname+"."+prop));
}
catch (MisoNamingException e) {
log.error("Cannot set new validation regex for field '"+prop+"'. Reverting to default: " + e);
e.printStackTrace();
}
}
}
}
//set up printers
PrintManager printManager = (PrintManager)context.getBean("printManager");
Collection<PrintContext> pcs = printManager.getPrintContexts();
for (PrintContext pc : pcs) {
log.info(pc.getName() + " : " + pc.getDescription());
}
try {
Collection<MisoPrintService> mpss = printManager.listAllPrintServices();
for (MisoPrintService mps : mpss) {
log.info("Got print service: " + mps.toString());
}
}
catch (Exception e) {
log.error("Could not list print services. This does not bode well for printing.", e);
e.printStackTrace();
}
//set up Tag Barcode strategies
TagBarcodeStrategyResolverService tagBarcodeService = (TagBarcodeStrategyResolverService)context.getBean("tagBarcodeStrategyResolverService");
Collection<TagBarcodeStrategy> tbss = tagBarcodeService.getTagBarcodeStrategies();
for (TagBarcodeStrategy tbs : tbss) {
log.info("Got Tag Barcode Index service: " + tbs.getName());
}
//set up alerting
if ("true".equals(misoProperties.get("miso.alerting.enabled"))) {
//set up indexers and alerters
MisoRequestManager rm = new MisoRequestManager();
rm.setProjectStore((ProjectStore)context.getBean("projectStore"));
rm.setRunStore((RunStore)context.getBean("runStore"));
rm.setRunQcStore((RunQcStore) context.getBean("runQcStore"));
rm.setPoolStore((PoolStore)context.getBean("poolStore"));
SecurityManager sm = (com.eaglegenomics.simlims.core.manager.SecurityManager)context.getBean("securityManager");
RunAlertManager ram = (RunAlertManager)context.getBean("runAlertManager");
ram.setRequestManager(rm);
ram.setSecurityManager(sm);
ProjectAlertManager pam = (ProjectAlertManager)context.getBean("projectAlertManager");
pam.setRequestManager(rm);
pam.setSecurityManager(sm);
PoolAlertManager poam = (PoolAlertManager)context.getBean("poolAlertManager");
poam.setRequestManager(rm);
poam.setSecurityManager(sm);
}
if (misoProperties.containsKey("miso.db.caching.mappers.enabled")) {
boolean mapperCachingEnabled = Boolean.parseBoolean(misoProperties.get("miso.db.caching.mappers.enabled"));
//TODO do something with this - probably set caching throughout DAOs
}
if ("true".equals(misoProperties.get("miso.db.caching.precache.enabled"))) {
log.info("Precaching. This may take a while.");
try {
RequestManager rm = (RequestManager)context.getBean("requestManager");
User userdetails = new User("precacher", "none", true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_ADMIN,ROLE_INTERNAL"));
PreAuthenticatedAuthenticationToken newAuthentication = new PreAuthenticatedAuthenticationToken(userdetails, userdetails.getPassword(), userdetails.getAuthorities());
newAuthentication.setAuthenticated(true);
newAuthentication.setDetails(userdetails);
try {
SecurityContext sc = SecurityContextHolder.getContextHolderStrategy().getContext();
sc.setAuthentication(newAuthentication);
SecurityContextHolder.getContextHolderStrategy().setContext(sc);
}
catch (AuthenticationException a) {
a.printStackTrace();
}
log.info("\\_ projects...");
log.info("" + rm.listAllProjects().size());
log.info("\\_ samples...");
log.info("" + rm.listAllSamples().size());
log.info("\\_ libraries...");
log.info("" + rm.listAllLibraries().size());
log.info("\\_ dilutions...");
log.info("" + rm.listAllLibraryDilutions().size());
log.info("" + rm.listAllEmPcrDilutions().size());
log.info("\\_ pools...");
log.info("" + rm.listAllPools().size());
log.info("\\_ plates...");
log.info("" + rm.listAllPlates().size());
log.info("\\_ runs...");
log.info("" + rm.listAllRuns().size());
}
catch (IOException e) {
e.printStackTrace();
}
}
if ("true".equals(misoProperties.get("miso.issuetracker.enabled"))) {
String trackerType = misoProperties.get("miso.issuetracker.tracker");
if (trackerType != null && !"".equals(trackerType)) {
try {
IssueTrackerManager manager = IssueTrackerFactory.newInstance().getTrackerManager(trackerType);
if (manager != null) {
for (String key : misoProperties.keySet()) {
if (key.startsWith("miso.issuetracker."+trackerType)) {
String prop = key.substring(key.lastIndexOf(".")+1);
String methodName = "set"+ LimsUtils.capitalise(prop); //prop.substring(0,1).toUpperCase() + prop.substring(1);
Method m = manager.getClass().getDeclaredMethod(methodName, String.class);
m.invoke(manager, misoProperties.get(key));
}
}
((DefaultListableBeanFactory)context.getBeanFactory()).removeBeanDefinition("issueTrackerManager");
context.getBeanFactory().registerSingleton("issueTrackerManager", manager);
}
else {
log.error("No such issue tracker available with given type: " + trackerType);
}
}
catch (NoSuchMethodException e) {
log.error("Unable to start the defined issuetracker " + trackerType + ": " + e.getMessage());
e.printStackTrace();
}
catch (InvocationTargetException e) {
log.error("Unable to start the defined issuetracker " + trackerType + ": " + e.getMessage());
e.printStackTrace();
}
catch (IllegalAccessException e) {
log.error("Unable to start the defined issuetracker " + trackerType + ": " + e.getMessage());
e.printStackTrace();
}
}
}
if ("true".equals(misoProperties.get("miso.statsdb.enabled"))) {
try {
JndiObjectFactoryBean jndiBean = new JndiObjectFactoryBean();
jndiBean.setLookupOnStartup(true);
jndiBean.setResourceRef(true);
jndiBean.setJndiName("jdbc/STATSDB");
jndiBean.setExpectedType(javax.sql.DataSource.class);
jndiBean.afterPropertiesSet();
DataSource datasource = (DataSource)jndiBean.getObject();
JdbcTemplate template = new JdbcTemplate();
template.setDataSource(datasource);
template.setNativeJdbcExtractor(new CommonsDbcpNativeJdbcExtractor());
context.getBeanFactory().registerSingleton("statsInterfaceTemplate", template);
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
transactionManager.setDataSource(datasource);
context.getBeanFactory().registerSingleton("statsTransactionManager", transactionManager);
RunStatsManager rsm = new RunStatsManager(template);
context.getBeanFactory().registerSingleton("runStatsManager", rsm);
}
catch (NamingException e) {
log.error("Cannot initiate statsdb connection: " + e.getMessage());
e.printStackTrace();
}