Search in sources :

Example 6 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project syncope by apache.

the class LoggerLogic method listAuditEvents.

@PreAuthorize("hasRole('" + StandardEntitlement.AUDIT_LIST + "') or hasRole('" + StandardEntitlement.NOTIFICATION_LIST + "')")
public List<EventCategoryTO> listAuditEvents() {
    // use set to avoid duplications or null elements
    Set<EventCategoryTO> events = new HashSet<>();
    try {
        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
        MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(SystemPropertyUtils.resolvePlaceholders(this.getClass().getPackage().getName())) + "/**/*.class";
        Resource[] resources = resourcePatternResolver.getResources(packageSearchPath);
        for (Resource resource : resources) {
            if (resource.isReadable()) {
                final MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(resource);
                final Class<?> clazz = Class.forName(metadataReader.getClassMetadata().getClassName());
                if (clazz.isAnnotationPresent(Component.class) && AbstractLogic.class.isAssignableFrom(clazz)) {
                    EventCategoryTO eventCategoryTO = new EventCategoryTO();
                    eventCategoryTO.setCategory(clazz.getSimpleName());
                    for (Method method : clazz.getDeclaredMethods()) {
                        if (Modifier.isPublic(method.getModifiers()) && !eventCategoryTO.getEvents().contains(method.getName())) {
                            eventCategoryTO.getEvents().add(method.getName());
                        }
                    }
                    events.add(eventCategoryTO);
                }
            }
        }
        // SYNCOPE-608
        EventCategoryTO authenticationControllerEvents = new EventCategoryTO();
        authenticationControllerEvents.setCategory(AuditElements.AUTHENTICATION_CATEGORY);
        authenticationControllerEvents.getEvents().add(AuditElements.LOGIN_EVENT);
        events.add(authenticationControllerEvents);
        events.add(new EventCategoryTO(EventCategoryType.PROPAGATION));
        events.add(new EventCategoryTO(EventCategoryType.PULL));
        events.add(new EventCategoryTO(EventCategoryType.PUSH));
        for (AnyTypeKind anyTypeKind : AnyTypeKind.values()) {
            resourceDAO.findAll().forEach(resource -> {
                EventCategoryTO propEventCategoryTO = new EventCategoryTO(EventCategoryType.PROPAGATION);
                EventCategoryTO pullEventCategoryTO = new EventCategoryTO(EventCategoryType.PULL);
                EventCategoryTO pushEventCategoryTO = new EventCategoryTO(EventCategoryType.PUSH);
                propEventCategoryTO.setCategory(anyTypeKind.name().toLowerCase());
                propEventCategoryTO.setSubcategory(resource.getKey());
                pullEventCategoryTO.setCategory(anyTypeKind.name().toLowerCase());
                pushEventCategoryTO.setCategory(anyTypeKind.name().toLowerCase());
                pullEventCategoryTO.setSubcategory(resource.getKey());
                pushEventCategoryTO.setSubcategory(resource.getKey());
                for (ResourceOperation resourceOperation : ResourceOperation.values()) {
                    propEventCategoryTO.getEvents().add(resourceOperation.name().toLowerCase());
                }
                pullEventCategoryTO.getEvents().add(ResourceOperation.DELETE.name().toLowerCase());
                for (UnmatchingRule unmatching : UnmatchingRule.values()) {
                    String event = UnmatchingRule.toEventName(unmatching);
                    pullEventCategoryTO.getEvents().add(event);
                    pushEventCategoryTO.getEvents().add(event);
                }
                for (MatchingRule matching : MatchingRule.values()) {
                    String event = MatchingRule.toEventName(matching);
                    pullEventCategoryTO.getEvents().add(event);
                    pushEventCategoryTO.getEvents().add(event);
                }
                events.add(propEventCategoryTO);
                events.add(pullEventCategoryTO);
                events.add(pushEventCategoryTO);
            });
        }
        EventCategoryTO eventCategoryTO = new EventCategoryTO(EventCategoryType.TASK);
        eventCategoryTO.setCategory(PullJobDelegate.class.getSimpleName());
        events.add(eventCategoryTO);
        eventCategoryTO = new EventCategoryTO(EventCategoryType.TASK);
        eventCategoryTO.setCategory(PushJobDelegate.class.getSimpleName());
        events.add(eventCategoryTO);
    } catch (Exception e) {
        LOG.error("Failure retrieving audit/notification events", e);
    }
    return new ArrayList<>(events);
}
Also used : PullJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PullJobDelegate) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) PushJobDelegate(org.apache.syncope.core.provisioning.java.pushpull.PushJobDelegate) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) MetadataReader(org.springframework.core.type.classreading.MetadataReader) CachingMetadataReaderFactory(org.springframework.core.type.classreading.CachingMetadataReaderFactory) Method(java.lang.reflect.Method) EventCategoryTO(org.apache.syncope.common.lib.log.EventCategoryTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) UnmatchingRule(org.apache.syncope.common.lib.types.UnmatchingRule) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) Component(org.springframework.stereotype.Component) MatchingRule(org.apache.syncope.common.lib.types.MatchingRule) HashSet(java.util.HashSet) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project lavagna by digitalfondue.

the class ResourceController method addMessages.

private void addMessages(ServletContext context, OutputStream os, BeforeAfter ba) throws IOException {
    ba.before("i18n", context, os);
    // 
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources("classpath:io/lavagna/i18n/messages_*.properties");
    // 
    os.write(("window.io_lavagna=window.io_lavagna||{};window.io_lavagna.i18n=" + Json.GSON.toJson(fromResources(resources))).getBytes(StandardCharsets.UTF_8));
    ba.after("i18n", context, os);
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 8 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project webcert by sklintyg.

the class ClasspathSchemaResourceResolver method load.

public static InputStream load(String schemaSystemId) throws IOException {
    // Strip any relative path prefixes
    if (schemaSystemId.contains("/")) {
        schemaSystemId = schemaSystemId.substring(schemaSystemId.lastIndexOf('/') + 1);
    }
    // Do a wildcard classpath search..
    ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
    String searchPattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "/**/" + schemaSystemId;
    Resource[] resources = resourcePatternResolver.getResources(searchPattern);
    if ((resources == null) || (resources.length == 0)) {
        throw new RuntimeException("Could not find schema [" + schemaSystemId + "]");
    }
    // We found at least 1 matching systemId - they should all be identical.
    return resources[0].getInputStream();
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 9 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project spring-integration by spring-projects.

the class IntegrationRegistrar method registerIntegrationProperties.

/**
 * Register {@code integrationGlobalProperties} bean if necessary.
 * @param registry The {@link BeanDefinitionRegistry} to register additional {@link BeanDefinition}s.
 */
private void registerIntegrationProperties(BeanDefinitionRegistry registry) {
    boolean alreadyRegistered = false;
    if (registry instanceof ListableBeanFactory) {
        alreadyRegistered = ((ListableBeanFactory) registry).containsBean(IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME);
    } else {
        alreadyRegistered = registry.isBeanNameInUse(IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME);
    }
    if (!alreadyRegistered) {
        ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(this.classLoader);
        try {
            Resource[] defaultResources = resourceResolver.getResources("classpath*:META-INF/spring.integration.default.properties");
            Resource[] userResources = resourceResolver.getResources("classpath*:META-INF/spring.integration.properties");
            List<Resource> resources = new LinkedList<Resource>(Arrays.asList(defaultResources));
            resources.addAll(Arrays.asList(userResources));
            BeanDefinitionBuilder integrationPropertiesBuilder = BeanDefinitionBuilder.genericBeanDefinition(PropertiesFactoryBean.class).addPropertyValue("locations", resources);
            registry.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_GLOBAL_PROPERTIES_BEAN_NAME, integrationPropertiesBuilder.getBeanDefinition());
        } catch (IOException e) {
            logger.warn("Cannot load 'spring.integration.properties' Resources.", e);
        }
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PropertiesFactoryBean(org.springframework.beans.factory.config.PropertiesFactoryBean) IOException(java.io.IOException) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) LinkedList(java.util.LinkedList)

Example 10 with ResourcePatternResolver

use of org.springframework.core.io.support.ResourcePatternResolver in project modesti by jlsalmon.

the class WorkflowInitialiser method init.

public void init() throws IOException {
    log.info("Initialising workflow processes");
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(Thread.currentThread().getContextClassLoader());
    Resource[] processes = resolver.getResources(PROCESS_RESOURCE_PATTERN);
    for (Resource process : processes) {
        repositoryService.createDeployment().addInputStream(process.getFilename(), process.getInputStream()).deploy();
    }
}
Also used : PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourcePatternResolver(org.springframework.core.io.support.ResourcePatternResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Aggregations

ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)65 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)62 Resource (org.springframework.core.io.Resource)49 IOException (java.io.IOException)15 Bean (org.springframework.context.annotation.Bean)11 ArrayList (java.util.ArrayList)10 PageHelper (com.github.pagehelper.PageHelper)9 SqlSessionFactoryBean (org.mybatis.spring.SqlSessionFactoryBean)9 CachingMetadataReaderFactory (org.springframework.core.type.classreading.CachingMetadataReaderFactory)9 MetadataReader (org.springframework.core.type.classreading.MetadataReader)9 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)9 File (java.io.File)8 Properties (java.util.Properties)8 InputStream (java.io.InputStream)5 URL (java.net.URL)5 FileOutputStream (java.io.FileOutputStream)3 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)3 EventLoopGroup (io.netty.channel.EventLoopGroup)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 SocketChannel (io.netty.channel.socket.SocketChannel)2