You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
4.5 KiB
138 lines
4.5 KiB
package com.fr.design.data; |
|
|
|
import com.fr.base.io.IOFile; |
|
import com.fr.design.file.HistoryTemplateListCache; |
|
import com.fr.design.mainframe.JTemplate; |
|
import com.fr.esd.core.strategy.config.StrategyConfig; |
|
import com.fr.esd.core.strategy.config.StrategyConfigHelper; |
|
import com.fr.esd.core.strategy.config.service.StrategyConfigService; |
|
import com.fr.esd.core.strategy.persistence.StrategyConfigsAttr; |
|
import com.fr.esd.event.DSMapping; |
|
import com.fr.esd.event.DsNameTarget; |
|
import com.fr.esd.event.StrategyEventsNotifier; |
|
import com.fr.esd.event.xml.XMLSavedHook; |
|
import com.fr.log.FineLoggerFactory; |
|
import com.fr.stable.StringUtils; |
|
import com.fr.workspace.WorkContext; |
|
|
|
import java.nio.file.Paths; |
|
import java.util.HashMap; |
|
import java.util.HashSet; |
|
import java.util.Map; |
|
import java.util.Set; |
|
|
|
/** |
|
* @author rinoux |
|
* @version 10.0 |
|
* Created by rinoux on 2020/10/28 |
|
*/ |
|
public class StrategyConfigAttrUtils { |
|
|
|
/** |
|
* 获取当前编辑模版的数据集缓存配置属性 |
|
* |
|
* @return |
|
*/ |
|
private static StrategyConfigsAttr getStrategyConfigsAttr() { |
|
StrategyConfigsAttr attr; |
|
JTemplate<?, ?> jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
if (jTemplate != null) { |
|
IOFile ioFile = (IOFile) jTemplate.getTarget(); |
|
|
|
attr = ioFile.getAttrMark(StrategyConfigsAttr.ATTR_MARK); |
|
if (attr == null) { |
|
attr = new StrategyConfigsAttr(); |
|
ioFile.addAttrMark(attr); |
|
} |
|
|
|
//新建模版此时不存在,不需要注册钩子 |
|
//不处理外部路径,保存到设计器才处理 |
|
String path = jTemplate.getPath(); |
|
if (attr.getXmlSavedHook() == null && !Paths.get(path).isAbsolute() && WorkContext.getWorkResource().exist(path)) { |
|
attr.setXmlSavedHook(new StrategyConfigsAttrSavedHook(jTemplate.getPath(), attr)); |
|
} |
|
return attr; |
|
} else { |
|
throw new IllegalStateException("[ESD]No editing template found."); |
|
} |
|
} |
|
|
|
|
|
/** |
|
* 获取模版数据集配置 |
|
* |
|
* @param dsName |
|
* @return |
|
*/ |
|
public static StrategyConfig getStrategyConfig(String dsName) { |
|
|
|
return getStrategyConfigsAttr().getStrategyConfig(dsName); |
|
} |
|
|
|
/** |
|
* 移除模版数据集配置 |
|
* |
|
* @param dsName |
|
* @return |
|
*/ |
|
public static StrategyConfig removeStrategyConfig(String dsName) { |
|
|
|
return getStrategyConfigsAttr().removeStrategyConfig(dsName); |
|
} |
|
|
|
/** |
|
* 添加模版数据集配置 |
|
* |
|
* @param strategyConfig |
|
*/ |
|
public static void addStrategyConfig(StrategyConfig strategyConfig) { |
|
|
|
getStrategyConfigsAttr().addStrategyConfig(strategyConfig); |
|
} |
|
|
|
|
|
private static class StrategyConfigsAttrSavedHook implements XMLSavedHook<StrategyConfigsAttr> { |
|
|
|
private static final long serialVersionUID = -8843201977112289321L; |
|
|
|
private final String tplPath; |
|
private final Map<String, StrategyConfig> origStrategyConfigs; |
|
|
|
public StrategyConfigsAttrSavedHook(String tplPath, StrategyConfigsAttr raw) { |
|
this.tplPath = tplPath; |
|
this.origStrategyConfigs = new HashMap<>(); |
|
this.initOrigStrategyConfigs(raw); |
|
} |
|
|
|
|
|
private void initOrigStrategyConfigs(StrategyConfigsAttr raw) { |
|
origStrategyConfigs.clear(); |
|
raw.getStrategyConfigs().forEach((k, v) -> { |
|
try { |
|
origStrategyConfigs.put(k, v.clone()); |
|
} catch (CloneNotSupportedException e) { |
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
} |
|
}); |
|
} |
|
|
|
@Override |
|
public void doAfterSaved(StrategyConfigsAttr saved) { |
|
|
|
FineLoggerFactory.getLogger().info("[ESD]Write StrategyConfigsAttr done, now check change."); |
|
Set<String> dsNames = new HashSet<>(); |
|
dsNames.addAll(origStrategyConfigs.keySet()); |
|
dsNames.addAll(saved.getStrategyConfigs().keySet()); |
|
|
|
if (StringUtils.isNotEmpty(tplPath)) { |
|
dsNames.forEach(dsName -> { |
|
if (StringUtils.isNotEmpty(dsName)) { |
|
StrategyEventsNotifier.compareAndFireConfigEvents(origStrategyConfigs.get(dsName), saved.getStrategyConfig(dsName), new DSMapping(tplPath, new DsNameTarget(dsName))); |
|
} |
|
}); |
|
} |
|
|
|
initOrigStrategyConfigs(saved); |
|
} |
|
} |
|
}
|
|
|