diff --git a/radar-admin/src/main/java/com/pgmmers/radar/controller/AbstractionApiController.java b/radar-admin/src/main/java/com/pgmmers/radar/controller/AbstractionApiController.java index ae493eb..7397f1d 100644 --- a/radar-admin/src/main/java/com/pgmmers/radar/controller/AbstractionApiController.java +++ b/radar-admin/src/main/java/com/pgmmers/radar/controller/AbstractionApiController.java @@ -18,7 +18,7 @@ import com.pgmmers.radar.service.common.CommonResult; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.service.engine.vo.DataColumnInfo; import com.pgmmers.radar.service.enums.DataType; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; import com.pgmmers.radar.service.model.AbstractionService; import com.pgmmers.radar.service.model.FieldService; import com.pgmmers.radar.service.model.PreItemService; @@ -26,18 +26,12 @@ import com.pgmmers.radar.vo.model.AbstractionVO; import com.pgmmers.radar.vo.model.FieldVO; import com.pgmmers.radar.vo.model.PreItemVO; import io.swagger.annotations.Api; -import java.util.ArrayList; -import java.util.List; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; @RestController @RequestMapping("/services/v1/abstraction") @Api(value = "AbstractionApi", description = "特征管理相关操作", tags = {"特征API"}) @@ -51,6 +45,9 @@ public class AbstractionApiController { @Autowired private PreItemService preItemService; + @Autowired + private PluginManagerV2 pluginManagerV2; + @GetMapping("/{id}") public CommonResult get(@PathVariable Long id) { CommonResult result = new CommonResult(); @@ -90,7 +87,7 @@ public class AbstractionApiController { List listPreItem = preItemService.listPreItem(modelId); if(listPreItem != null && listPreItem.size()!= 0){ for (PreItemVO preItem : listPreItem) { - PluginServiceV2 pt= PluginManager.pluginServiceMap().get(preItem.getPlugin()); + PluginServiceV2 pt= pluginManagerV2.pluginServiceMap(preItem.getPlugin()); if (StringUtils.isNotEmpty(pt.getType()) && pt.getType().equals("JSON")) { //load http request data JsonNode json = preItem.getConfigJson(); diff --git a/radar-admin/src/main/java/com/pgmmers/radar/controller/ActivationApiController.java b/radar-admin/src/main/java/com/pgmmers/radar/controller/ActivationApiController.java index 2decb53..9ba2a44 100644 --- a/radar-admin/src/main/java/com/pgmmers/radar/controller/ActivationApiController.java +++ b/radar-admin/src/main/java/com/pgmmers/radar/controller/ActivationApiController.java @@ -19,31 +19,16 @@ import com.pgmmers.radar.service.common.CommonResult; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.service.engine.vo.DataColumnInfo; import com.pgmmers.radar.service.enums.DataType; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; -import com.pgmmers.radar.service.model.AbstractionService; -import com.pgmmers.radar.service.model.ActivationService; -import com.pgmmers.radar.service.model.FieldService; -import com.pgmmers.radar.service.model.PreItemService; -import com.pgmmers.radar.service.model.RuleService; -import com.pgmmers.radar.vo.model.AbstractionVO; -import com.pgmmers.radar.vo.model.ActivationVO; -import com.pgmmers.radar.vo.model.FieldVO; -import com.pgmmers.radar.vo.model.PreItemVO; -import com.pgmmers.radar.vo.model.RuleVO; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; +import com.pgmmers.radar.service.model.*; +import com.pgmmers.radar.vo.model.*; import io.swagger.annotations.Api; -import java.util.ArrayList; -import java.util.List; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; @RestController @RequestMapping("/services/v1/activation") @Api(value = "ActivationApi", description = "策略集管理相关操作", tags = {"策略集API"}) @@ -60,6 +45,8 @@ public class ActivationApiController { private PreItemService preItemService; @Autowired private RuleService ruleService; + @Autowired + private PluginManagerV2 pluginManagerV2; @GetMapping("/{id}") public CommonResult get(@PathVariable Long id) { @@ -92,7 +79,7 @@ public class ActivationApiController { ds = new DataColumnInfo(DataType.PREITEMS.getDesc(), DataType.PREITEMS.getName()); List listPreItem = preItemService.listPreItem(modelId); for (PreItemVO preItem : listPreItem) { - PluginServiceV2 pt= PluginManager.pluginServiceMap().get(preItem.getPlugin()); + PluginServiceV2 pt = pluginManagerV2.pluginServiceMap(preItem.getPlugin()); if (StringUtils.isNotEmpty(pt.getType()) && pt.getType().equals("JSON")) { //load http request data JsonNode json = preItem.getConfigJson(); diff --git a/radar-admin/src/main/java/com/pgmmers/radar/controller/CommonApiController.java b/radar-admin/src/main/java/com/pgmmers/radar/controller/CommonApiController.java index 5e28dd6..65f135a 100644 --- a/radar-admin/src/main/java/com/pgmmers/radar/controller/CommonApiController.java +++ b/radar-admin/src/main/java/com/pgmmers/radar/controller/CommonApiController.java @@ -15,15 +15,12 @@ import com.alibaba.excel.util.IoUtils; import com.pgmmers.radar.enums.FieldType; import com.pgmmers.radar.service.cache.CacheService; import com.pgmmers.radar.service.common.CommonResult; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; import com.pgmmers.radar.util.CaptchaUtil; import com.pgmmers.radar.util.ZipUtils; import com.pgmmers.radar.vo.common.PluginVO; - import io.swagger.annotations.Api; import io.swagger.annotations.ApiParam; - -import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -41,6 +38,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.stream.Collectors; @RestController @RequestMapping("/services/v1/common") @@ -54,12 +52,14 @@ public class CommonApiController { @Autowired private CacheService cacheService; + @Autowired + private PluginManagerV2 pluginManagerV2; @GetMapping("/plugins") public CommonResult plugins() { CommonResult result = new CommonResult(); - List plugins=PluginManager.pluginServiceMap() + List plugins = pluginManagerV2.getPluginServiceMap() .values() .stream() .map(t-> new PluginVO(t.key(),t.pluginName(),t.desc())) diff --git a/radar-admin/src/main/java/com/pgmmers/radar/controller/EventApiController.java b/radar-admin/src/main/java/com/pgmmers/radar/controller/EventApiController.java index 191eab2..c56b99c 100644 --- a/radar-admin/src/main/java/com/pgmmers/radar/controller/EventApiController.java +++ b/radar-admin/src/main/java/com/pgmmers/radar/controller/EventApiController.java @@ -20,7 +20,7 @@ import com.pgmmers.radar.service.common.CommonResult; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.service.engine.vo.DataColumnInfo; import com.pgmmers.radar.service.enums.DataType; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; import com.pgmmers.radar.service.logs.EventService; import com.pgmmers.radar.service.model.ActivationService; import com.pgmmers.radar.service.model.FieldService; @@ -32,6 +32,13 @@ import com.pgmmers.radar.vo.model.FieldVO; import com.pgmmers.radar.vo.model.PreItemVO; import com.pgmmers.radar.vo.model.RuleVO; import io.swagger.annotations.Api; +import org.apache.poi.ss.usermodel.Workbook; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -39,17 +46,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import org.apache.poi.ss.usermodel.Workbook; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; /** * 以后会独立拆分到分析子项目里面去。 @@ -72,6 +68,8 @@ public class EventApiController { @Autowired private RuleService ruleService; + @Autowired + private PluginManagerV2 pluginManagerV2; @PostMapping("/query") @@ -192,7 +190,7 @@ public class EventApiController { if (!itemsIdMap.containsKey(item.getDestField())) { continue; } - PluginServiceV2 plugin= PluginManager.pluginServiceMap().get(item.getPlugin()); + PluginServiceV2 plugin = pluginManagerV2.pluginServiceMap(item.getPlugin()); String type = plugin.getType(); String meta = plugin.getMeta(); diff --git a/radar-engine/src/main/test/com/pgmmers/radar/dal/PluginTest.java b/radar-engine/src/main/test/com/pgmmers/radar/dal/PluginTest.java index b0d6e6c..5d81d2d 100644 --- a/radar-engine/src/main/test/com/pgmmers/radar/dal/PluginTest.java +++ b/radar-engine/src/main/test/com/pgmmers/radar/dal/PluginTest.java @@ -5,20 +5,23 @@ import com.pgmmers.radar.EngineApplication; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.service.engine.vo.Location; import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; import com.pgmmers.radar.vo.model.PreItemVO; -import java.util.Comparator; -import java.util.HashMap; -import java.util.Map; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpMethod; import org.springframework.test.context.junit4.SpringRunner; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map; + @SuppressWarnings("SpellCheckingInspection") @RunWith(SpringRunner.class) @@ -27,7 +30,19 @@ public class PluginTest { private static final Logger logger = LoggerFactory.getLogger(PluginTest.class); + @Autowired + private PluginManagerV2 pluginManagerV2; + @Test + public void pluginListV2() { + pluginManagerV2.getPluginServiceMap().values() + .stream() + .sorted(Comparator.comparing(PluginServiceV2::key)) + .forEach(t -> logger.info(t.info())); + } + + @Test + @Deprecated public void pluginList() { PluginManager.pluginServiceMap().values() .stream() @@ -35,6 +50,10 @@ public class PluginTest { .forEach(t -> logger.info(t.info())); } + + + + private Map jsonInfo; @Before diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/AntiFraudServiceImpl.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/AntiFraudServiceImpl.java index 107aa22..7fdfecc 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/AntiFraudServiceImpl.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/AntiFraudServiceImpl.java @@ -10,7 +10,7 @@ import com.pgmmers.radar.service.engine.vo.AbstractionResult; import com.pgmmers.radar.service.engine.vo.ActivationResult; import com.pgmmers.radar.service.engine.vo.AdaptationResult; import com.pgmmers.radar.service.engine.vo.AntiFraudProcessResult; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; import com.pgmmers.radar.service.model.ModelService; import com.pgmmers.radar.service.model.PreItemService; import com.pgmmers.radar.vo.model.PreItemVO; @@ -46,6 +46,9 @@ public class AntiFraudServiceImpl implements AntiFraudService { @Autowired private ModelService modelService; + @Autowired + private PluginManagerV2 pluginManagerV2; + @Override public CommonResult process(Long modelId, Map> context) { AntiFraudProcessResult analysisResult = new AntiFraudProcessResult(); @@ -110,7 +113,7 @@ public class AntiFraudServiceImpl implements AntiFraudService { continue; } String[] sourceField = item.getSourceField().split(","); - Object transfer = PluginManager.pluginServiceMap().get(item.getPlugin()).handle(item,jsonInfo,sourceField); + Object transfer = pluginManagerV2.pluginServiceMap(item.getPlugin()).handle(item,jsonInfo,sourceField); result.put(item.getDestField(), transfer); } return result; diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/ALLINONE.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/ALLINONE.java index 7181f58..7bec88a 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/ALLINONE.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/ALLINONE.java @@ -2,6 +2,7 @@ package com.pgmmers.radar.service.impl.engine.plugin; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.vo.model.PreItemVO; +import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.Map; @@ -10,6 +11,7 @@ import java.util.stream.Collectors; /** * author: wangcheng Date: 2020/5/19 Time: 上午11:45 Description: */ +@Component public class ALLINONE implements PluginServiceV2 { @Override diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/DATEFORMAT.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/DATEFORMAT.java index ce4654b..d6922ef 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/DATEFORMAT.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/DATEFORMAT.java @@ -4,8 +4,9 @@ import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.vo.model.PreItemVO; import java.util.Map; import org.apache.commons.lang3.time.DateFormatUtils; +import org.springframework.stereotype.Component; - +@Component public class DATEFORMAT implements PluginServiceV2 { @Override diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/GPS2LOCATION.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/GPS2LOCATION.java index 83837b1..d3d3c43 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/GPS2LOCATION.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/GPS2LOCATION.java @@ -13,6 +13,7 @@ import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Component; import java.util.Map; @@ -20,6 +21,7 @@ import java.util.Map; /** * author: wangcheng Date: 2020/5/19 Time: 上午11:44 Description: */ +@Component public class GPS2LOCATION implements PluginServiceV2 { private static final Logger logger = LoggerFactory.getLogger(GPS2LOCATION.class); diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/HTTP_UTIL.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/HTTP_UTIL.java index 53aa172..1bb186f 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/HTTP_UTIL.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/HTTP_UTIL.java @@ -12,11 +12,13 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; /** * author: wangcheng Date: 2020/5/19 Time: 上午11:47 Description: */ +@Component public class HTTP_UTIL implements PluginServiceV2 { private static final Logger logger = LoggerFactory.getLogger(HTTP_UTIL.class); diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/IP2LOCATION.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/IP2LOCATION.java index e2f6065..40e12a6 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/IP2LOCATION.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/IP2LOCATION.java @@ -4,19 +4,21 @@ import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.service.engine.vo.Location; import com.pgmmers.radar.service.impl.util.BeanUtils; import com.pgmmers.radar.vo.model.PreItemVO; -import java.util.Map; import org.lionsoul.ip2region.DataBlock; import org.lionsoul.ip2region.DbConfig; import org.lionsoul.ip2region.DbSearcher; import org.lionsoul.ip2region.Util; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import java.util.Map; +import java.util.Objects; +@Component public class IP2LOCATION implements PluginServiceV2 { private static final Logger logger = LoggerFactory.getLogger(IP2LOCATION.class); - private DbSearcher ipSearcher; @Override public Integer key() { @@ -38,16 +40,20 @@ public class IP2LOCATION implements PluginServiceV2 { return "[{\"column\":\"country\", \"title\":\"国家\", \"type\":\"STRING\"},{\"column\":\"province\", \"title\":\"省份\", \"type\":\"STRING\"},{\"column\":\"city\", \"title\":\"城市\", \"type\":\"STRING\"}]"; } - public IP2LOCATION() { + static DbSearcher getDbSearcher() { + final DbSearcher ipSearcher; try { String ipFilePath = BeanUtils.getApplicationContext().getEnvironment() .getProperty("ip2region.db.path"); DbConfig conf = new DbConfig(); + ipSearcher = new DbSearcher(conf, ipFilePath); logger.info("IP2LOCATION Plugin load success"); + return ipSearcher; } catch (Exception e) { logger.error("ip2region init failed", e); } + return null; } @Override @@ -59,7 +65,7 @@ public class IP2LOCATION implements PluginServiceV2 { return null; } try { - DataBlock block = ipSearcher.memorySearch(ip); + DataBlock block = Objects.requireNonNull(IP2LOCATION.getDbSearcher()).memorySearch(ip); String[] detail = block.getRegion().split("\\|"); location = new Location(); location.setCountry(detail[0]); diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/MOBILE2LOCATION.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/MOBILE2LOCATION.java index feb55bf..11ec93e 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/MOBILE2LOCATION.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/MOBILE2LOCATION.java @@ -8,10 +8,12 @@ import com.pgmmers.radar.vo.data.MobileInfoVO; import com.pgmmers.radar.vo.model.PreItemVO; import java.util.Map; import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Component; /** * author: wangcheng Date: 2020/5/19 Time: 上午11:46 Description: */ +@Component public class MOBILE2LOCATION implements PluginServiceV2 { @Override diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManager.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManager.java index f27de7e..25b9335 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManager.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManager.java @@ -1,12 +1,14 @@ package com.pgmmers.radar.service.impl.engine.plugin; import com.pgmmers.radar.service.engine.PluginServiceV2; +import org.springframework.core.io.support.SpringFactoriesLoader; + import java.util.Comparator; import java.util.Map; import java.util.stream.Collectors; -import org.springframework.core.io.support.SpringFactoriesLoader; +@Deprecated public class PluginManager { private PluginManager() { diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManagerV2.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManagerV2.java new file mode 100644 index 0000000..8fafd86 --- /dev/null +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/PluginManagerV2.java @@ -0,0 +1,35 @@ +package com.pgmmers.radar.service.impl.engine.plugin; + +import com.pgmmers.radar.service.engine.PluginServiceV2; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Service; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * + * @author Model + * @since 2022/1/27 11:29 + */ +@Service +public class PluginManagerV2 implements ApplicationContextAware { + + private final Map pluginServiceMap = new ConcurrentHashMap<>(); + + public PluginServiceV2 pluginServiceMap(String key){ + return pluginServiceMap.get(key); + } + + public Map getPluginServiceMap(){ + return pluginServiceMap; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + Map beansOfType = applicationContext.getBeansOfType(PluginServiceV2.class); + pluginServiceMap.putAll(beansOfType); + } +} diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/SENSITIVE_TIME.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/SENSITIVE_TIME.java index 7d9bb48..15aeee9 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/SENSITIVE_TIME.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/SENSITIVE_TIME.java @@ -2,12 +2,15 @@ package com.pgmmers.radar.service.impl.engine.plugin; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.vo.model.PreItemVO; +import org.springframework.stereotype.Component; + import java.util.Calendar; import java.util.Map; /** * author: wangcheng Date: 2020/5/19 Time: 上午11:46 Description: */ +@Component public class SENSITIVE_TIME implements PluginServiceV2 { @Override diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/SUBSTRING.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/SUBSTRING.java index 082e29d..13643f7 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/SUBSTRING.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/engine/plugin/SUBSTRING.java @@ -2,11 +2,14 @@ package com.pgmmers.radar.service.impl.engine.plugin; import com.pgmmers.radar.service.engine.PluginServiceV2; import com.pgmmers.radar.vo.model.PreItemVO; +import org.springframework.stereotype.Component; + import java.util.Map; /** * author: wangcheng Date: 2020/5/19 Time: 上午11:45 Description: */ +@Component public class SUBSTRING implements PluginServiceV2 { @Override diff --git a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/model/ModelServiceImpl.java b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/model/ModelServiceImpl.java index 361900c..b33e25a 100644 --- a/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/model/ModelServiceImpl.java +++ b/radar-service-impl/src/main/java/com/pgmmers/radar/service/impl/model/ModelServiceImpl.java @@ -14,22 +14,13 @@ import com.pgmmers.radar.service.cache.SubscribeHandle; import com.pgmmers.radar.service.common.CommonResult; import com.pgmmers.radar.service.data.MongoService; import com.pgmmers.radar.service.engine.PluginServiceV2; -import com.pgmmers.radar.service.impl.engine.plugin.PluginManager; +import com.pgmmers.radar.service.impl.engine.plugin.PluginManagerV2; import com.pgmmers.radar.service.model.ModelService; import com.pgmmers.radar.service.search.SearchEngineService; import com.pgmmers.radar.util.JsonUtils; import com.pgmmers.radar.vo.model.FieldVO; import com.pgmmers.radar.vo.model.ModelVO; import com.pgmmers.radar.vo.model.PreItemVO; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import javax.annotation.PostConstruct; import org.apache.commons.lang3.StringUtils; import org.bson.Document; import org.slf4j.Logger; @@ -38,6 +29,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + @Service public class ModelServiceImpl extends BaseLocalCacheService implements ModelService, @@ -62,6 +59,9 @@ public class ModelServiceImpl extends BaseLocalCacheService implements ModelServ @Autowired private MongoService mongoService; + @Autowired + private PluginManagerV2 pluginManagerV2; + // 维护GUID到modelId的映射 private Map guidMap; @@ -252,8 +252,7 @@ public class ModelServiceImpl extends BaseLocalCacheService implements ModelServ // pre item mapping JSONObject preItemJson = new JSONObject(); for (PreItemVO item : items) { - String pluginType = item.getPlugin(); - PluginServiceV2 plugin= PluginManager.pluginServiceMap().get(pluginType); + PluginServiceV2 plugin = pluginManagerV2.pluginServiceMap(item.getPlugin()); String columns = plugin.getMeta(); if (columns == null) { String fieldType = plugin.getType(); diff --git a/radar-service-impl/src/main/resources/META-INF/spring.factories b/radar-service-impl/src/main/resources/META-INF/spring.factories index 6722b47..fd40910 100644 --- a/radar-service-impl/src/main/resources/META-INF/spring.factories +++ b/radar-service-impl/src/main/resources/META-INF/spring.factories @@ -1,12 +1,4 @@ -com.pgmmers.radar.service.engine.PluginServiceV2=\ - com.pgmmers.radar.service.impl.engine.plugin.DATEFORMAT,\ - com.pgmmers.radar.service.impl.engine.plugin.ALLINONE,\ - com.pgmmers.radar.service.impl.engine.plugin.GPS2LOCATION,\ - com.pgmmers.radar.service.impl.engine.plugin.HTTP_UTIL,\ - com.pgmmers.radar.service.impl.engine.plugin.IP2LOCATION,\ - com.pgmmers.radar.service.impl.engine.plugin.MOBILE2LOCATION,\ - com.pgmmers.radar.service.impl.engine.plugin.SENSITIVE_TIME,\ - com.pgmmers.radar.service.impl.engine.plugin.SUBSTRING +