Search in sources :

Example 16 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project Activiti by Activiti.

the class Application method usersAndGroupsInitializer.

@Bean
InitializingBean usersAndGroupsInitializer(final IdentityService identityService) {
    return new InitializingBean() {

        @Override
        public void afterPropertiesSet() throws Exception {
            // install groups & users
            Group group = identityService.newGroup("user");
            group.setName("users");
            group.setType("security-role");
            identityService.saveGroup(group);
            User joram = identityService.newUser("jbarrez");
            joram.setFirstName("Joram");
            joram.setLastName("Barrez");
            joram.setPassword("password");
            identityService.saveUser(joram);
            User josh = identityService.newUser("jlong");
            josh.setFirstName("Josh");
            josh.setLastName("Long");
            josh.setPassword("password");
            identityService.saveUser(josh);
            identityService.createMembership("jbarrez", "user");
            identityService.createMembership("jlong", "user");
        }
    };
}
Also used : Group(org.activiti.engine.identity.Group) User(org.activiti.engine.identity.User) InitializingBean(org.springframework.beans.factory.InitializingBean) Bean(org.springframework.context.annotation.Bean) InitializingBean(org.springframework.beans.factory.InitializingBean)

Example 17 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project opennms by OpenNMS.

the class ReportDefinition method createReport.

/**
 * <p>createReport</p>
 *
 * @param resourceDao a {@link org.opennms.netmgt.dao.api.ResourceDao} object.
 * @param fetchStrategy an object.
 * @param filterDao a {@link org.opennms.netmgt.filter.api.FilterDao} object.
 * @return a {@link org.opennms.netmgt.statsd.ReportInstance} object.
 * @throws java.lang.Exception if any.
 */
public ReportInstance createReport(NodeDao nodeDao, ResourceDao resourceDao, MeasurementFetchStrategy fetchStrategy, FilterDao filterDao) throws Exception {
    Assert.notNull(resourceDao, "resourceDao argument must not be null");
    Assert.notNull(fetchStrategy, "fetchStrategy argument must not be null");
    Assert.notNull(filterDao, "filterDao argument must not be null");
    AttributeStatisticVisitorWithResults visitor;
    try {
        visitor = getReportClass().newInstance();
    } catch (Throwable e) {
        throw new DataAccessResourceFailureException("Could not instantiate visitor object; nested exception: " + e, e);
    }
    ReportInstance report;
    if (getReport().getPackage().getFilter() != null) {
        FilteredReportInstance thisReport = new FilteredReportInstance(visitor);
        thisReport.setNodeDao(nodeDao);
        thisReport.setResourceDao(resourceDao);
        thisReport.setFetchStrategy(fetchStrategy);
        thisReport.setFilterDao(filterDao);
        thisReport.setFilter(getReport().getPackage().getFilter());
        report = thisReport;
    } else {
        UnfilteredReportInstance thisReport = new UnfilteredReportInstance(visitor);
        thisReport.setResourceDao(resourceDao);
        thisReport.setFetchStrategy(fetchStrategy);
        report = thisReport;
    }
    report.setReportDefinition(this);
    report.setStartTime(getRelativeTime().getStart().getTime());
    report.setEndTime(getRelativeTime().getEnd().getTime());
    report.setCount(getCount());
    report.setConsolidationFunction(getConsolidationFunction());
    report.setResourceTypeMatch(getResourceTypeMatch());
    report.setAttributeMatch(getAttributeMatch());
    report.setResourceAttributeKey(m_resourceAttributeKey);
    report.setResourceAttributeValueMatch(m_resourceAttributeValueMatch);
    if (report instanceof InitializingBean) {
        ((InitializingBean) report).afterPropertiesSet();
    }
    return report;
}
Also used : DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) AttributeStatisticVisitorWithResults(org.opennms.netmgt.model.AttributeStatisticVisitorWithResults) InitializingBean(org.springframework.beans.factory.InitializingBean)

Example 18 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project gravitee-management-rest-api by gravitee-io.

the class IdentityProviderManagerImpl method create.

private <T> T create(Plugin plugin, Class<T> identityClass, Map<String, Object> properties) {
    if (identityClass == null) {
        return null;
    }
    try {
        T identityObj = createInstance(identityClass);
        final Import annImport = identityClass.getAnnotation(Import.class);
        Set<Class<?>> configurations = (annImport != null) ? new HashSet<>(Arrays.asList(annImport.value())) : Collections.emptySet();
        ApplicationContext idpApplicationContext = pluginContextFactory.create(new AnnotationBasedPluginContextConfigurer(plugin) {

            @Override
            public Set<Class<?>> configurations() {
                return configurations;
            }

            @Override
            public ConfigurableEnvironment environment() {
                return new StandardEnvironment() {

                    @Override
                    protected void customizePropertySources(MutablePropertySources propertySources) {
                        propertySources.addFirst(new MapPropertySource(plugin.id(), properties));
                        super.customizePropertySources(propertySources);
                    }
                };
            }
        });
        idpApplicationContext.getAutowireCapableBeanFactory().autowireBean(identityObj);
        if (identityObj instanceof InitializingBean) {
            ((InitializingBean) identityObj).afterPropertiesSet();
        }
        return identityObj;
    } catch (Exception ex) {
        LOGGER.error("An unexpected error occurs while loading identity provider", ex);
        return null;
    }
}
Also used : Import(org.springframework.context.annotation.Import) AnnotationBasedPluginContextConfigurer(io.gravitee.plugin.core.internal.AnnotationBasedPluginContextConfigurer) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MapPropertySource(org.springframework.core.env.MapPropertySource) MutablePropertySources(org.springframework.core.env.MutablePropertySources) InitializingBean(org.springframework.beans.factory.InitializingBean) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 19 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project mica2 by obiba.

the class ExceptionHandlingAsyncTaskExecutor method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    if (executor instanceof InitializingBean) {
        InitializingBean bean = (InitializingBean) executor;
        bean.afterPropertiesSet();
    }
}
Also used : InitializingBean(org.springframework.beans.factory.InitializingBean)

Example 20 with InitializingBean

use of org.springframework.beans.factory.InitializingBean in project cuba by cuba-platform.

the class DesktopComponentsFactory method autowireContext.

protected void autowireContext(Component instance) {
    AutowireCapableBeanFactory autowireBeanFactory = applicationContext.getAutowireCapableBeanFactory();
    autowireBeanFactory.autowireBean(instance);
    if (instance instanceof ApplicationContextAware) {
        ((ApplicationContextAware) instance).setApplicationContext(applicationContext);
    }
    if (instance instanceof InitializingBean) {
        try {
            ((InitializingBean) instance).afterPropertiesSet();
        } catch (Exception e) {
            throw new RuntimeException("Unable to initialize Component - calling afterPropertiesSet for " + instance.getClass());
        }
    }
}
Also used : ApplicationContextAware(org.springframework.context.ApplicationContextAware) InitializingBean(org.springframework.beans.factory.InitializingBean) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) DevelopmentException(com.haulmont.cuba.core.global.DevelopmentException)

Aggregations

InitializingBean (org.springframework.beans.factory.InitializingBean)27 ApplicationContextAware (org.springframework.context.ApplicationContextAware)8 AutowireCapableBeanFactory (org.springframework.beans.factory.config.AutowireCapableBeanFactory)6 Bean (org.springframework.context.annotation.Bean)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 MessageChannel (org.springframework.messaging.MessageChannel)4 Function (java.util.function.Function)3 DisposableBean (org.springframework.beans.factory.DisposableBean)3 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)3 FluxMessageChannel (org.springframework.integration.channel.FluxMessageChannel)3 DevelopmentException (com.haulmont.cuba.core.global.DevelopmentException)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Supplier (java.util.function.Supplier)2 BeansException (org.springframework.beans.BeansException)2 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)2