创建流程清单的ASLP,并且修改流程制度文件的接口调用
This commit is contained in:
parent
0228d036d6
commit
348cc955d3
@ -0,0 +1,147 @@
|
||||
package com.awspaas.user.apps.yili.reportform.cache;
|
||||
|
||||
import com.actionsoft.apps.coe.pal.processlist.constant.ProcessListConstant;
|
||||
import com.actionsoft.apps.coe.pal.processlist.model.ProcessListConfigModel;
|
||||
import com.actionsoft.apps.resource.plugin.profile.CachePluginProfile;
|
||||
import com.actionsoft.bpms.commons.cache.Cache;
|
||||
import com.actionsoft.bpms.commons.cache.CacheManager;
|
||||
import com.actionsoft.bpms.util.ConsolePrinter;
|
||||
import com.actionsoft.bpms.util.UtilString;
|
||||
import com.actionsoft.sdk.local.SDK;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.Namespace;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description 流程清单缓存model
|
||||
* @Created by sunlh
|
||||
* @Date 2020-05-17
|
||||
*/
|
||||
public class ProcessListConfigCache extends Cache<String, ProcessListConfigModel> {
|
||||
|
||||
/**
|
||||
* 构造方法,初始化一个新的缓存存储和缓存索引。如果该缓存对象扩展了缓存索引或自定义的集群同步动作,请在该构造方法中注册
|
||||
*
|
||||
* @param configuration 缓存插件注册配置对象
|
||||
*/
|
||||
public ProcessListConfigCache(CachePluginProfile configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
// 读取属性配置信息
|
||||
String json = getConfigJson();
|
||||
if (!UtilString.isEmpty(json)) {
|
||||
JSONObject configObj = JSONObject.parseObject(json);
|
||||
for (Map.Entry<String, Object> entry : configObj.entrySet()) {
|
||||
JSONObject obj = (JSONObject) entry.getValue();
|
||||
ProcessListConfigModel model = new ProcessListConfigModel();
|
||||
model.setWsId(obj.getString(ProcessListConfigModel.WS_ID));
|
||||
model.setCustomColumns(obj.getJSONArray(ProcessListConfigModel.CUSTOM_COLUMNS));
|
||||
model.setCreateUser(obj.getString(ProcessListConfigModel.CREATE_USER));
|
||||
model.setCreateDate((Timestamp) obj.getTimestamp(ProcessListConfigModel.CREATE_DATE));
|
||||
getCache().put(model.getWsId(), model);
|
||||
}
|
||||
}
|
||||
ConsolePrinter.info("[" + SDK.getAppAPI().getAppContext(ProcessListConstant.PROCESSLIST).getNameI18N() + "]Cache加载流程清单配置对象 [" + getCache().size() + "个]");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新配置信息(文件+缓存)
|
||||
* @param config 配置model
|
||||
*/
|
||||
public void update(ProcessListConfigModel config) {
|
||||
String json = getConfigJson();// 获取现有配置
|
||||
JSONObject configObj = new JSONObject();
|
||||
configObj.put(ProcessListConfigModel.WS_ID, config.getWsId());
|
||||
configObj.put(ProcessListConfigModel.CUSTOM_COLUMNS, config.getCustomColumns());
|
||||
configObj.put(ProcessListConfigModel.CREATE_USER, config.getCreateUser());
|
||||
configObj.put(ProcessListConfigModel.CREATE_DATE, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
JSONObject obj = new JSONObject();
|
||||
if (!UtilString.isEmpty(json)) {
|
||||
obj = JSONObject.parseObject(json);
|
||||
}
|
||||
obj.put(config.getWsId(), configObj);
|
||||
// 保存
|
||||
updateMmanifest(obj);
|
||||
// 更新缓存
|
||||
getCache().remove(config.getWsId());
|
||||
getCache().put(config.getWsId(), config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置信息
|
||||
* @return
|
||||
*/
|
||||
private String getConfigJson() {
|
||||
// 读取属性配置信息
|
||||
String manifestXml = "../apps/install/"+ ProcessListConstant.PROCESSLIST +"/manifest.xml";
|
||||
File manifestFile = new File(manifestXml);
|
||||
if (manifestFile.exists()) {
|
||||
try {
|
||||
Document doc = new SAXReader().read(manifestFile);
|
||||
Element root = doc.getRootElement();
|
||||
// 获取子节点
|
||||
Element configEle = root.element("config");
|
||||
if (configEle != null) {
|
||||
String config = configEle.getText();
|
||||
return config;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
SDK.getLogAPI().consoleErr("读取应用配置["+ manifestXml +"]失败");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置信息
|
||||
* @param obj
|
||||
*/
|
||||
private void updateMmanifest(JSONObject obj) {
|
||||
String manifestXml = "../apps/install/"+ ProcessListConstant.PROCESSLIST +"/manifest.xml";
|
||||
File manifestFile = new File(manifestXml);
|
||||
if (manifestFile.exists()) {
|
||||
try {
|
||||
Document doc = new SAXReader().read(manifestFile);
|
||||
Element root = doc.getRootElement();
|
||||
root.add(new Namespace("processlist", "http://www.w3.org/2001/XMLSchema"));
|
||||
// 获取子节点
|
||||
Element configEle = root.element("config");
|
||||
if (configEle == null) {
|
||||
configEle = root.addElement("processlist:config");
|
||||
}
|
||||
configEle.setText(obj.toString());
|
||||
try {
|
||||
XMLWriter writer = new XMLWriter(new FileOutputStream(manifestFile));
|
||||
writer.write(doc);
|
||||
writer.close();
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
SDK.getLogAPI().consoleErr("读取应用配置["+ manifestXml +"]失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ProcessListConfigCache getCache() {
|
||||
return (ProcessListConfigCache) CacheManager.getCache(ProcessListConfigCache.class);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user