From d2ff9e64f153ed5492078aeae41e35f25e33a69b Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 12 Aug 2024 18:12:20 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-114392=20FR-FBP=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E8=AE=BE=E8=AE=A1=E9=80=82=E9=85=8D=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E9=9B=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../preview/ConnectionInfoBeanHelper.java | 1 + .../adaptation/ReportAdaptationComponent.java | 156 ++++++++++++++++++ .../function/DesignDatasourceComponent.java | 2 +- 3 files changed, 158 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java b/designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java index 65770b2236..b2f8aad61b 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/preview/ConnectionInfoBeanHelper.java @@ -49,6 +49,7 @@ public class ConnectionInfoBeanHelper { bean.setConnectionType(JDBCConnectionProcessor.CONNECTION_TYPE); bean.setConnectionType(JDBCConnectionProcessor.KEY.getConnectionType(connection)); bean.setConnectionName(name); + bean.setConnectionId(name); bean.setCreator(connection.getCreator()); return bean; } else { diff --git a/designer-realize/src/main/java/com/fanruan/boot/adaptation/ReportAdaptationComponent.java b/designer-realize/src/main/java/com/fanruan/boot/adaptation/ReportAdaptationComponent.java index ecfce94222..d09e3db108 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/adaptation/ReportAdaptationComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/adaptation/ReportAdaptationComponent.java @@ -3,11 +3,50 @@ package com.fanruan.boot.adaptation; import com.fanruan.carina.Carina; import com.fanruan.carina.annotions.FineComponent; import com.fanruan.carina.annotions.Start; +import com.fanruan.plugins.resource.PluginResourceHelper; +import com.fanruan.portal.FinePortal; +import com.fanruan.portal.module.PortalModule; +import com.fr.base.ServerConfig; +import com.fr.decision.ExtraDecisionClassManager; +import com.fr.decision.base.VirtualFilterChain; +import com.fr.decision.fun.EmbedRequestFilterProvider; +import com.fr.decision.fun.GlobalRequestFilterProvider; +import com.fr.decision.fun.SystemOptionProvider; +import com.fr.decision.plugin.PluginControllerManager; +import com.fr.decision.portal.PluginPortalModuleDevice; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; import com.fr.general.I18nResource; import com.fr.general.InterProviderImpl; import com.fr.locale.InterMutableKey; import com.fr.locale.LocaleMarker; import com.fr.locale.LocaleScope; +import com.fr.plugin.ExtraClassManager; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.injectable.PluginModule; +import com.fr.plugin.observer.PluginEventType; +import com.fr.stable.StringUtils; +import com.fr.stable.collections.CollectionUtils; + +import javax.servlet.DispatcherType; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.FilterRegistration; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; /** * 用于内置服务器检查并适配其他FR服务细节的模块 @@ -26,8 +65,125 @@ public class ReportAdaptationComponent { @Start public void start() { checkI18n(); + // 注册插件定义的门户模块 + registerPluginModules(); + + //注册filter插件 + listenEmbedServletFilter(Carina.getApplicationContext().getServletContext()); + listenGlobalServletFilter(Carina.getApplicationContext().getServletContext()); + + // 插件controller注册 + PluginControllerManager.getInstance().init(); + } + + private void listenEmbedServletFilter(ServletContext servletContext) { + final Set set = new LinkedHashSet<>(ExtraDecisionClassManager.getInstance().getArray(EmbedRequestFilterProvider.MARK_STRING)); + final FilterConfig[] embedFilterConfig = new FilterConfig[1]; + com.fr.stable.Filter filter = new com.fr.stable.Filter() { + @Override + public boolean accept(PluginContext context) { + return context.contain(PluginModule.ExtraDecision, EmbedRequestFilterProvider.MARK_STRING); + } + }; + EventDispatcher.listen(PluginEventType.AfterRun, new Listener() { + + @Override + public void on(Event event, PluginContext context) { + Set providers = context.getRuntime().get(PluginModule.ExtraDecision, EmbedRequestFilterProvider.MARK_STRING); + providers.forEach(provider -> provider.init(embedFilterConfig[0])); + set.addAll(providers); + } + }, filter); + EventDispatcher.listen(PluginEventType.BeforeStop, new Listener() { + @Override + public void on(Event event, PluginContext context) { + Set providers = context.getRuntime().get(PluginModule.ExtraDecision, EmbedRequestFilterProvider.MARK_STRING); + providers.forEach(EmbedRequestFilterProvider::destroy); + set.removeAll(providers); + } + }, filter); + FilterRegistration.Dynamic servletFilter = servletContext.addFilter(ServerConfig.getInstance().getServletName(), new Filter() { + @Override + public void init(FilterConfig filterConfig) { + embedFilterConfig[0] = filterConfig; + for (EmbedRequestFilterProvider one : set) { + one.init(filterConfig); + } + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + VirtualFilterChain virtualFilterChain = new VirtualFilterChain(new ArrayList<>(set), filterChain); + virtualFilterChain.doFilter(servletRequest, servletResponse); + } + + @Override + public void destroy() { + for (EmbedRequestFilterProvider one : set) { + one.destroy(); + } + } + }); + EnumSet dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ERROR); + servletFilter.addMappingForUrlPatterns(dispatcherTypes, false, ServerConfig.getInstance().getServletMapping()); } + private void listenGlobalServletFilter(ServletContext servletContext) { + final Set set = ExtraDecisionClassManager.getInstance().getArray(GlobalRequestFilterProvider.MARK_STRING); + final Set sort = new TreeSet<>(set); + for (final GlobalRequestFilterProvider provider : sort) { + String externalFilterClassName = provider.externalFilterClassName(); + FilterRegistration.Dynamic servletFilter; + if (StringUtils.isBlank(externalFilterClassName)) { + servletFilter = servletContext.addFilter(provider.filterName(), new Filter() { + @Override + public void init(FilterConfig filterConfig) throws ServletException { + provider.init(filterConfig); + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + provider.doFilter((HttpServletRequest) servletRequest, (HttpServletResponse) servletResponse, filterChain); + } + + @Override + public void destroy() { + provider.destroy(); + } + }); + } else { + servletFilter = servletContext.addFilter(provider.filterName(), externalFilterClassName); + } + Map parameters = provider.initializationParameters(); + if (parameters != null) { + servletFilter.setInitParameters(provider.initializationParameters()); + } + EnumSet dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ERROR); + servletFilter.addMappingForUrlPatterns(dispatcherTypes, false, provider.urlPatterns()); + } + } + + private void registerPluginModules() { + // 注册插件模块 + try { + Set systemOptionProviders = ExtraClassManager.getInstance().getArray(SystemOptionProvider.XML_TAG); + if (!CollectionUtils.isEmpty(systemOptionProviders)) { + // 资源引入采用新的方式,WebCoalition接口不再继承使用,这里只处理模块注册 + for (SystemOptionProvider optionProvider : systemOptionProviders) { + PortalModule portalModule = PortalModule.create(optionProvider.id(), optionProvider.displayName()) + .sortIndex(optionProvider.sortIndex()) + .dynamicControl(m -> new PluginPortalModuleDevice(optionProvider.parentId(), m)); + + FinePortal.registerModule(optionProvider.parentId(), portalModule); + + // 插件资源注册 + PluginResourceHelper.getInstance().registerAtom2Portal(optionProvider); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } private void checkI18n() { for (LocaleMarker marker : Carina.getApplicationContext().group(InterMutableKey.class).getAll()) { if (marker.match(LocaleScope.SERVER)) { diff --git a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java index 66753db688..54d0eef1eb 100644 --- a/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java +++ b/designer-realize/src/main/java/com/fanruan/boot/env/function/DesignDatasourceComponent.java @@ -78,6 +78,6 @@ public class DesignDatasourceComponent extends DatasourceComponent { */ @Stop public void stop() { - super.stop(); + } }