mirror of
https://gitee.com/ssssssss-team/magic-api.git
synced 2026-05-31 11:01:57 +08:00
重新加载资源、数据源取消注册
This commit is contained in:
@@ -149,9 +149,16 @@ public class MagicWorkbenchController extends MagicController implements MagicEx
|
||||
return new JsonBean<>(Stream.of(Options.values()).map(item -> Arrays.asList(item.getValue(), item.getName(), item.getDefaultValue())).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@GetMapping("/reload")
|
||||
@ResponseBody
|
||||
public JsonBean<Boolean> reload(HttpServletRequest request) {
|
||||
isTrue(allowVisit(request, Authorization.RELOAD), PERMISSION_INVALID);
|
||||
MagicConfiguration.getMagicResourceService().refresh();
|
||||
return new JsonBean<>(true);
|
||||
}
|
||||
|
||||
@GetMapping("/search")
|
||||
@ResponseBody
|
||||
@Valid
|
||||
public JsonBean<List<Map<String, Object>>> search(String keyword, HttpServletRequest request) {
|
||||
if (StringUtils.isBlank(keyword)) {
|
||||
return new JsonBean<>(Collections.emptyList());
|
||||
|
||||
@@ -41,5 +41,9 @@ public enum Authorization {
|
||||
/**
|
||||
* 解锁动作
|
||||
*/
|
||||
UNLOCK
|
||||
}
|
||||
UNLOCK,
|
||||
/**
|
||||
* 重新加载
|
||||
*/
|
||||
RELOAD
|
||||
}
|
||||
|
||||
@@ -58,14 +58,15 @@ public abstract class AbstractMagicDynamicRegistry<T extends MagicEntity> implem
|
||||
}
|
||||
|
||||
@EventListener(condition = "#event.action == T(org.ssssssss.magicapi.event.EventAction).CLEAR")
|
||||
public void clear(MagicEvent event){
|
||||
public void clear(MagicEvent event) {
|
||||
Iterator<Map.Entry<String, MappingNode<T>>> iterator = mappings.entrySet().iterator();
|
||||
while (iterator.hasNext()){
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, MappingNode<T>> entry = iterator.next();
|
||||
unregister(entry.getValue());
|
||||
if (Objects.equals(entry.getKey(), entry.getValue().getEntity().getId())) {
|
||||
unregister(entry.getValue());
|
||||
}
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void processEvent(FileEvent event) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.ssssssss.magicapi.service.impl;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
@@ -46,7 +44,8 @@ public class DataSourceMagicDynamicRegistry extends AbstractMagicDynamicRegistry
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register(DataSourceInfo info) {
|
||||
protected boolean register(MappingNode<DataSourceInfo> mappingNode) {
|
||||
DataSourceInfo info = mappingNode.getEntity();
|
||||
Map<String, Object> properties = new HashMap<>(info.getProperties());
|
||||
properties.put("url", info.getUrl());
|
||||
properties.put("username", info.getUsername());
|
||||
@@ -62,10 +61,9 @@ public class DataSourceMagicDynamicRegistry extends AbstractMagicDynamicRegistry
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean unregister(DataSourceInfo info) {
|
||||
return magicDynamicDataSource.delete(info.getKey());
|
||||
protected void unregister(MappingNode<DataSourceInfo> mappingNode) {
|
||||
magicDynamicDataSource.delete(mappingNode.getMappingKey());
|
||||
}
|
||||
|
||||
// copy from DataSourceBuilder
|
||||
|
||||
Reference in New Issue
Block a user