List of usage examples for org.springframework.context.event ContextRefreshedEvent getApplicationContext
public final ApplicationContext getApplicationContext()
From source file:org.web4thejob.sandbox.orm.MyProjectsSampleDataInitializer.java
@Override public void onApplicationEvent(ContextRefreshedEvent event) { if (event.getApplicationContext().getParent() != null) { return;// do nothing if this is not the root context }/* w w w .ja v a2s. c o m*/ Date now = new Date(); Query query = ContextUtil.getEntityFactory().buildQuery(Task.class); query.addOrderBy(new Path("startTime")); List<Task> tasks = ContextUtil.getDRS().findByQuery(query); if (tasks.isEmpty()) return; Task olderTask = tasks.get(0); if (olderTask.getStartTime().after(now)) return; int num = 0; int daysOffset = (int) new Duration(olderTask.getStartTime().getTime(), now.getTime()).getStandardDays(); for (Task task : tasks) { num += 1; DateTime start = new DateTime(task.getStartTime().getTime()); task.setStartTime(start.plusDays(daysOffset).toDate()); DateTime end = new DateTime(task.getEndTime().getTime()); task.setEndTime(end.plusDays(daysOffset).toDate()); ContextUtil.getDWS().save(task); } logger.info(num + " tasks have been offset successfully."); }
From source file:org.web4thejob.orm.MappingInitializer.java
public void onApplicationEvent(ContextRefreshedEvent event) { if (event.getApplicationContext().getParent() != null) { return;// do nothing if this is not the root context }/*w w w. ja va 2 s . c o m*/ ContextUtil.getMRS().refreshMetaCache(); ensureAdministratorExists(); //in order to support unit testing of seperate modules (like ss3) if (ContextUtil.getMRS().getEntityMetadata(RenderScheme.class) != null) { createDefaultRenderSchemes(SchemeType.LIST_SCHEME); createDefaultRenderSchemes(SchemeType.ENTITY_SCHEME); } }
From source file:util.SampleDataProvider.java
@Override public void onApplicationEvent(ContextRefreshedEvent event) { if (!event.getApplicationContext().equals(applicationContext)) { return;//www . j a va2 s. c o m } LOG.info("Populating datasource using SQL file {}!", SQL_FILE); if (!called) { ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.setScripts(new Resource[] { new ClassPathResource(SQL_FILE) }); DatabasePopulatorUtils.execute(populator, dataSource); called = true; } }
From source file:net.firejack.platform.core.validation.constraint.RuleMapper.java
protected void onContextRefreshed(ContextRefreshedEvent event) { ApplicationContext context = event.getApplicationContext(); Map<String, Object> beans = context.getBeansWithAnnotation(RuleSource.class); for (Object bean : beans.values()) { Class<?> clazz = bean.getClass(); RuleSource ruleSource = clazz.getAnnotation(RuleSource.class); if (ruleSource != null) { if (StringUtils.isNotBlank(ruleSource.value())) { CONSTRAINT_LOCATIONS.put(ruleSource.value(), clazz); }//from w ww . ja v a2 s. c o m } } }
From source file:me.tfeng.toolbox.spring.BeanNameRegistry.java
@Override public void onApplicationEvent(ContextRefreshedEvent event) { ApplicationContext applicationContext = event.getApplicationContext(); Arrays.stream(applicationContext.getBeanDefinitionNames()).forEach(name -> { try {/* w w w. java 2 s . co m*/ beanMap.put(new ShadowKey(applicationContext.getBean(name)), name); } catch (NoSuchBeanDefinitionException e) { // Ignore. } }); }
From source file:am.ik.ws.colordic.app.bootstrap.SampleDataProvider.java
@Override public void onApplicationEvent(ContextRefreshedEvent event) { if (!event.getApplicationContext().equals(applicationContext)) { return;// ww w . jav a 2 s . c o m } LOG.info("Populating datasource using SQL file {}!", SQL_FILE); ResourceDatabasePopulator populator = new ResourceDatabasePopulator(); populator.setScripts(new Resource[] { new ClassPathResource(SQL_FILE) }); DatabasePopulatorUtils.execute(populator, dataSource); }
From source file:my.school.spring.beans.PostProxyInvokerContextListener.java
@Override public void onApplicationEvent(ContextRefreshedEvent event) { ApplicationContext context = event.getApplicationContext(); for (String beanName : context.getBeanDefinitionNames()) { final String beanClassName = beanFactory.getBeanDefinition(beanName).getBeanClassName(); if (beanClassName == null) { continue; }//from w ww . j a v a 2s .c om try { Class<?> originalClass = Class.forName(beanClassName); for (Method originalMethod : originalClass.getMethods()) { if (originalMethod.isAnnotationPresent(PostProxy.class)) { try { Object bean = context.getBean(beanName); Method currentMethod = bean.getClass().getMethod(originalMethod.getName(), originalMethod.getParameterTypes()); currentMethod.invoke(bean); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ex) { LOG.error(ex.getLocalizedMessage()); } } } } catch (NullPointerException | ClassNotFoundException ex) { LOG.warn("Failed to find bean's class: {} (bean name: {})", beanClassName, beanName); } } }
From source file:com.yqboots.dict.context.DataDictImportListener.java
/** * {@inheritDoc}/* w w w. j a v a2 s . c o m*/ */ @Override public void onApplicationEvent(final ContextRefreshedEvent event) { final ApplicationContext context = event.getApplicationContext(); final DataDictManager manager = context.getBean(DataDictManager.class); final DataDictProperties properties = context.getBean(DataDictProperties.class); if (!properties.isImportEnabled()) { return; } final String location = properties.getImportFileLocation(); if (StringUtils.isEmpty(location)) { LOG.warn("Data Dict Importing is enabled, but location was not set"); return; } try { final File file = ResourceUtils.getFile(location); try (final InputStream inputStream = new FileInputStream(file)) { manager.imports(inputStream); } } catch (IOException e) { LOG.error("Failed to import Data Dicts", e); } }
From source file:com.scase.core.listener.InitListener.java
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { if (servletContext != null && contextRefreshedEvent.getApplicationContext().getParent() == null) { String info = "I|n|i|t|i|a|l|i|z|i|n|g| |S|H|O|P|+|+| |" + systemVersion; logger.info(info.replace("|", "")); File installInitConfigFile = new File(servletContext.getRealPath(INSTALL_INIT_CONFIG_FILE_PATH)); if (installInitConfigFile.exists()) { cacheService.clear();/*www . jav a 2 s. c o m*/ staticService.buildAll(); // searchService.purge(); // searchService.index(); installInitConfigFile.delete(); } else { staticService.buildIndex(); staticService.buildOther(); } } }
From source file:net.groupbuy.listener.InitListener.java
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) { if (servletContext != null && contextRefreshedEvent.getApplicationContext().getParent() == null) { String info = "I|n|i|t|i|a|l|i|z|i|n|g| |S|H|O|P|+|+| |" + systemVersion; logger.info(info.replace("|", "")); File installInitConfigFile = new File(servletContext.getRealPath(INSTALL_INIT_CONFIG_FILE_PATH)); if (installInitConfigFile.exists()) { cacheService.clear();/*from ww w .ja v a2 s. c om*/ staticService.buildAll(); searchService.purge(); searchService.index(); installInitConfigFile.delete(); } else { staticService.buildIndex(); staticService.buildOther(); } } }