forked from fanruan/design
vito
3 years ago
21 changed files with 169 additions and 1064 deletions
@ -1,253 +0,0 @@ |
|||||||
package com.fr.design.mainframe.template.info; |
|
||||||
|
|
||||||
import com.fr.config.MarketConfig; |
|
||||||
import com.fr.design.DesignerEnvManager; |
|
||||||
import com.fr.design.mainframe.burying.point.AbstractPointInfo; |
|
||||||
import com.fr.general.CloudCenter; |
|
||||||
import com.fr.json.JSON; |
|
||||||
import com.fr.json.JSONFactory; |
|
||||||
import com.fr.json.JSONObject; |
|
||||||
import com.fr.stable.StringUtils; |
|
||||||
import com.fr.stable.xml.XMLPrintWriter; |
|
||||||
import com.fr.stable.xml.XMLableReader; |
|
||||||
import com.fr.third.joda.time.DateTime; |
|
||||||
|
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* 对应一张模版的记录 |
|
||||||
* Created by plough on 2019/4/18. |
|
||||||
*/ |
|
||||||
public class TemplateInfo extends AbstractPointInfo { |
|
||||||
static final String XML_TAG = "TemplateInfo"; |
|
||||||
private static final String SIMPLE_DATE_PATTRN = "yyyy-MM-dd HH:mm"; |
|
||||||
|
|
||||||
private static final String CONSUMING_URL = CloudCenter.getInstance().acquireUrlByKind("tempinfo.consuming") + "/single"; |
|
||||||
private static final String PROCESS_URL = CloudCenter.getInstance().acquireUrlByKind("tempinfo.process") + "/single"; |
|
||||||
|
|
||||||
private static final String XML_PROCESS_MAP = "processMap"; |
|
||||||
private static final String XML_CONSUMING_MAP = "consumingMap"; |
|
||||||
private static final String ATTR_DAY_COUNT = "day_count"; |
|
||||||
private static final String ATTR_TEMPLATE_ID = "templateID"; |
|
||||||
private static final String ATTR_ORIGIN_ID = "originID"; |
|
||||||
private static final String ATTR_PROCESS = "process"; |
|
||||||
private static final String ATTR_FLOAT_COUNT = "float_count"; |
|
||||||
private static final String ATTR_WIDGET_COUNT = "widget_count"; |
|
||||||
private static final String ATTR_CELL_COUNT = "cell_count"; |
|
||||||
private static final String ATTR_BLOCK_COUNT = "block_count"; |
|
||||||
private static final String ATTR_REPORT_TYPE = "report_type"; |
|
||||||
private static final String ATTR_CREATE_TIME = "create_time"; |
|
||||||
private static final String ATTR_UUID = "uuid"; |
|
||||||
private static final String ATTR_UID = "uid"; |
|
||||||
private static final String ATTR_SAVE_RECORD = "saveRecord"; |
|
||||||
private static final String ATTR_PARA_APPLY = "paraApply"; |
|
||||||
private static final String ATTR_COMPONENTS_INFO = "components_info"; |
|
||||||
private static final String ATTR_REUSE_CMP_LIST = "reuseCmptList"; |
|
||||||
|
|
||||||
|
|
||||||
private static final String TEST_TEMPLATE_FLAG = "test_template"; |
|
||||||
private static final int VALID_CELL_COUNT = 5; // 有效报表模板的格子数
|
|
||||||
private static final int VALID_WIDGET_COUNT = 5; // 有效报表模板的控件数
|
|
||||||
|
|
||||||
private String templateID = StringUtils.EMPTY; |
|
||||||
private String originID = StringUtils.EMPTY; |
|
||||||
// todo: processMap 和 consumingMap 还可以再拆解为小类,以后继续重构
|
|
||||||
private Map<String, Object> processMap = new HashMap<>(); |
|
||||||
private Map<String, Object> consumingMap = new HashMap<>(); |
|
||||||
|
|
||||||
private TemplateInfo() { |
|
||||||
} |
|
||||||
|
|
||||||
private TemplateInfo(String templateID, String originID) { |
|
||||||
this.templateID = templateID; |
|
||||||
this.originID = originID; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected String key() { |
|
||||||
return templateID; |
|
||||||
} |
|
||||||
|
|
||||||
public static TemplateInfo newInstanceByRead(XMLableReader reader) { |
|
||||||
TemplateInfo templateInfo = new TemplateInfo(); |
|
||||||
reader.readXMLObject(templateInfo); |
|
||||||
return templateInfo; |
|
||||||
} |
|
||||||
|
|
||||||
public static TemplateInfo newInstance(String templateID) { |
|
||||||
return newInstance(templateID, StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY); |
|
||||||
} |
|
||||||
|
|
||||||
public static TemplateInfo newInstance(String templateID, String originID, String saveRecord) { |
|
||||||
String createTime = DateTime.now().toString(SIMPLE_DATE_PATTRN); |
|
||||||
return newInstance(templateID, originID, saveRecord, createTime); |
|
||||||
} |
|
||||||
|
|
||||||
public static TemplateInfo newInstance(String templateID, String originID, String saveRecord, String createTime) { |
|
||||||
HashMap<String, Object> consumingMap = new HashMap<>(); |
|
||||||
|
|
||||||
String uuid = DesignerEnvManager.getEnvManager().getUUID(); |
|
||||||
MarketConfig config = MarketConfig.getInstance(); |
|
||||||
consumingMap.put(ATTR_UUID, uuid); |
|
||||||
consumingMap.put(ATTR_TEMPLATE_ID, templateID); |
|
||||||
consumingMap.put(ATTR_ORIGIN_ID, originID); |
|
||||||
consumingMap.put(ATTR_CREATE_TIME, createTime); |
|
||||||
consumingMap.put(ATTR_UID, config.getBBSAttr().getBbsUid()); |
|
||||||
consumingMap.put(ATTR_SAVE_RECORD, saveRecord); |
|
||||||
|
|
||||||
TemplateInfo templateInfo = new TemplateInfo(templateID, originID); |
|
||||||
templateInfo.consumingMap = consumingMap; |
|
||||||
|
|
||||||
return templateInfo; |
|
||||||
} |
|
||||||
|
|
||||||
String getTemplateID() { |
|
||||||
return templateID; |
|
||||||
} |
|
||||||
|
|
||||||
public String getTemplateInfoID() { |
|
||||||
return templateID + "_" + getSaveTime(); |
|
||||||
} |
|
||||||
|
|
||||||
public long getSaveTime() { |
|
||||||
String saveRecord = (String) consumingMap.get(ATTR_SAVE_RECORD); |
|
||||||
JSONObject jo = JSONFactory.createJSON(JSON.OBJECT, saveRecord); |
|
||||||
return jo.getLong("time"); |
|
||||||
} |
|
||||||
|
|
||||||
public String getTemplateCreateTime() { |
|
||||||
return (String) consumingMap.get(ATTR_CREATE_TIME); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
public void writeXML(XMLPrintWriter writer) { |
|
||||||
writer.startTAG(XML_TAG); |
|
||||||
if (StringUtils.isNotEmpty(templateID)) { |
|
||||||
writer.attr(ATTR_TEMPLATE_ID, this.templateID); |
|
||||||
} |
|
||||||
if (StringUtils.isNotEmpty(originID)) { |
|
||||||
writer.attr(ATTR_ORIGIN_ID, this.originID); |
|
||||||
} |
|
||||||
if (idleDayCount >= 0) { |
|
||||||
writer.attr(ATTR_DAY_COUNT, this.idleDayCount); |
|
||||||
} |
|
||||||
writer.attr(TEST_TEMPLATE_FLAG, this.testTemplate); |
|
||||||
writeProcessMap(writer); |
|
||||||
writeConsumingMap(writer); |
|
||||||
|
|
||||||
writer.end(); |
|
||||||
} |
|
||||||
|
|
||||||
private void writeProcessMap(XMLPrintWriter writer) { |
|
||||||
writer.startTAG(XML_PROCESS_MAP); |
|
||||||
writer.attr(ATTR_PROCESS, (String) processMap.get(ATTR_PROCESS)); |
|
||||||
writer.attr(ATTR_FLOAT_COUNT, (int) processMap.get(ATTR_FLOAT_COUNT)); |
|
||||||
writer.attr(ATTR_WIDGET_COUNT, (int) processMap.get(ATTR_WIDGET_COUNT)); |
|
||||||
writer.attr(ATTR_CELL_COUNT, (int) processMap.get(ATTR_CELL_COUNT)); |
|
||||||
writer.attr(ATTR_BLOCK_COUNT, (int) processMap.get(ATTR_BLOCK_COUNT)); |
|
||||||
writer.attr(ATTR_REPORT_TYPE, (int) processMap.get(ATTR_REPORT_TYPE)); |
|
||||||
writer.attr(ATTR_PARA_APPLY, (int) processMap.get(ATTR_PARA_APPLY)); |
|
||||||
writer.attr(ATTR_COMPONENTS_INFO, (String) processMap.get(ATTR_COMPONENTS_INFO)); |
|
||||||
writer.attr(ATTR_REUSE_CMP_LIST, (String) processMap.get(ATTR_REUSE_CMP_LIST)); |
|
||||||
writer.end(); |
|
||||||
} |
|
||||||
|
|
||||||
private void writeConsumingMap(XMLPrintWriter writer) { |
|
||||||
writer.startTAG(XML_CONSUMING_MAP); |
|
||||||
writer.attr(ATTR_CREATE_TIME, (String) consumingMap.get(ATTR_CREATE_TIME)); |
|
||||||
writer.attr(ATTR_UUID, (String) consumingMap.get(ATTR_UUID)); |
|
||||||
writer.attr(ATTR_UID, (int) consumingMap.get(ATTR_UID)); |
|
||||||
writer.attr(ATTR_SAVE_RECORD, (String) consumingMap.get(ATTR_SAVE_RECORD)); |
|
||||||
writer.end(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void readXML(XMLableReader reader) { |
|
||||||
if (!reader.isChildNode()) { |
|
||||||
idleDayCount = reader.getAttrAsInt(ATTR_DAY_COUNT, 0); |
|
||||||
testTemplate = reader.getAttrAsBoolean(TEST_TEMPLATE_FLAG, false); |
|
||||||
templateID = reader.getAttrAsString(ATTR_TEMPLATE_ID, StringUtils.EMPTY); |
|
||||||
originID = reader.getAttrAsString(ATTR_ORIGIN_ID, StringUtils.EMPTY); |
|
||||||
} else { |
|
||||||
try { |
|
||||||
String name = reader.getTagName(); |
|
||||||
if (XML_PROCESS_MAP.equals(name)) { |
|
||||||
processMap.put(ATTR_PROCESS, reader.getAttrAsString(ATTR_PROCESS, StringUtils.EMPTY)); |
|
||||||
processMap.put(ATTR_FLOAT_COUNT, reader.getAttrAsInt(ATTR_FLOAT_COUNT, 0)); |
|
||||||
processMap.put(ATTR_WIDGET_COUNT, reader.getAttrAsInt(ATTR_WIDGET_COUNT, 0)); |
|
||||||
processMap.put(ATTR_CELL_COUNT, reader.getAttrAsInt(ATTR_CELL_COUNT, 0)); |
|
||||||
processMap.put(ATTR_BLOCK_COUNT, reader.getAttrAsInt(ATTR_BLOCK_COUNT, 0)); |
|
||||||
processMap.put(ATTR_REPORT_TYPE, reader.getAttrAsInt(ATTR_REPORT_TYPE, 0)); |
|
||||||
processMap.put(ATTR_PARA_APPLY, reader.getAttrAsInt(ATTR_PARA_APPLY, 0)); |
|
||||||
processMap.put(ATTR_COMPONENTS_INFO, reader.getAttrAsString(ATTR_COMPONENTS_INFO, StringUtils.EMPTY)); |
|
||||||
processMap.put(ATTR_REUSE_CMP_LIST, reader.getAttrAsString(ATTR_REUSE_CMP_LIST, StringUtils.EMPTY)); |
|
||||||
processMap.put(ATTR_TEMPLATE_ID, templateID); |
|
||||||
} else if (XML_CONSUMING_MAP.equals(name)) { |
|
||||||
consumingMap.put(ATTR_CREATE_TIME, reader.getAttrAsString(ATTR_CREATE_TIME, StringUtils.EMPTY)); |
|
||||||
consumingMap.put(ATTR_TEMPLATE_ID, templateID); |
|
||||||
consumingMap.put(ATTR_ORIGIN_ID, originID); |
|
||||||
consumingMap.put(ATTR_UUID, reader.getAttrAsString(ATTR_UUID, StringUtils.EMPTY)); |
|
||||||
consumingMap.put(ATTR_UID, reader.getAttrAsInt(ATTR_UID, 0)); |
|
||||||
consumingMap.put(ATTR_SAVE_RECORD, reader.getAttrAsString(ATTR_SAVE_RECORD, StringUtils.EMPTY)); |
|
||||||
} |
|
||||||
} catch (Exception ex) { |
|
||||||
// 什么也不做,使用默认值
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean isTestTemplate() { |
|
||||||
return testTemplate; |
|
||||||
} |
|
||||||
|
|
||||||
public static boolean isTestTemplate(int reportType, int cellCount, int floatCount, int blockCount, int widgetCount) { |
|
||||||
boolean isTestTemplate; |
|
||||||
if (reportType == 0) { // 普通报表
|
|
||||||
isTestTemplate = cellCount <= VALID_CELL_COUNT && floatCount <= 1 && widgetCount <= VALID_WIDGET_COUNT; |
|
||||||
} else if (reportType == 1) { // 聚合报表
|
|
||||||
isTestTemplate = blockCount <= 1 && widgetCount <= VALID_WIDGET_COUNT; |
|
||||||
} else { // 表单(reportType == 2)
|
|
||||||
isTestTemplate = widgetCount <= 1; |
|
||||||
} |
|
||||||
return isTestTemplate; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected boolean isComplete() { |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public Map<String, String> getSendInfo() { |
|
||||||
Map<String, String> sendMap = new HashMap<>(); |
|
||||||
sendMap.put(CONSUMING_URL, JSONFactory.createJSON(JSON.OBJECT, consumingMap).toString()); |
|
||||||
sendMap.put(PROCESS_URL, JSONFactory.createJSON(JSON.OBJECT, processMap).toString()); |
|
||||||
return sendMap; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
void updateProcessMap(TemplateProcessInfo processInfo) { |
|
||||||
HashMap<String, Object> processMap = new HashMap<>(); |
|
||||||
|
|
||||||
// 暂不支持模版制作过程的收集
|
|
||||||
processMap.put(ATTR_PROCESS, StringUtils.EMPTY); |
|
||||||
|
|
||||||
processMap.put(ATTR_REPORT_TYPE, processInfo.getReportType()); |
|
||||||
processMap.put(ATTR_CELL_COUNT, processInfo.getCellCount()); |
|
||||||
processMap.put(ATTR_FLOAT_COUNT, processInfo.getFloatCount()); |
|
||||||
processMap.put(ATTR_BLOCK_COUNT, processInfo.getBlockCount()); |
|
||||||
processMap.put(ATTR_WIDGET_COUNT, processInfo.getWidgetCount()); |
|
||||||
processMap.put(ATTR_PARA_APPLY, processInfo.useParaPane() ? 1 : 0); |
|
||||||
processMap.put(ATTR_COMPONENTS_INFO, processInfo.getComponentsInfo().toString()); |
|
||||||
processMap.put(ATTR_REUSE_CMP_LIST, processInfo.getReuseCmpList().toString()); |
|
||||||
this.processMap = processMap; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
int getIdleDayCount() { |
|
||||||
return this.idleDayCount; |
|
||||||
} |
|
||||||
} |
|
@ -1,210 +0,0 @@ |
|||||||
package com.fr.design.mainframe.template.info; |
|
||||||
|
|
||||||
import com.fr.design.mainframe.burying.point.AbstractPointCollector; |
|
||||||
import com.fr.design.mainframe.burying.point.AbstractPointInfo; |
|
||||||
import com.fr.json.JSON; |
|
||||||
import com.fr.json.JSONFactory; |
|
||||||
import com.fr.json.JSONObject; |
|
||||||
import com.fr.stable.StringUtils; |
|
||||||
import com.fr.stable.xml.XMLPrintWriter; |
|
||||||
import com.fr.stable.xml.XMLableReader; |
|
||||||
|
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.concurrent.ConcurrentHashMap; |
|
||||||
|
|
||||||
/** |
|
||||||
* 做模板的过程和耗时收集,辅助类 |
|
||||||
* Created by plough on 2017/2/21. |
|
||||||
*/ |
|
||||||
public class TemplateInfoCollector extends AbstractPointCollector<TemplateInfo> { |
|
||||||
private static final String XML_TAG = "TplInfo"; |
|
||||||
private static final String XML_TEMPLATE_INFO_LIST = "TemplateInfoList"; |
|
||||||
private static final String XML_FILE_NAME = "tpl.info"; |
|
||||||
private static TemplateInfoCollector instance; |
|
||||||
private DesignerOpenHistory designerOpenHistory = DesignerOpenHistory.getInstance(); |
|
||||||
//记录指定模板最新的模板耗时信息ID
|
|
||||||
private Map<String, Long> latestTemplateInfo; |
|
||||||
|
|
||||||
private TemplateInfoCollector() { |
|
||||||
super(); |
|
||||||
} |
|
||||||
|
|
||||||
public static TemplateInfoCollector getInstance() { |
|
||||||
if (instance == null) { |
|
||||||
instance = new TemplateInfoCollector(); |
|
||||||
} |
|
||||||
return instance; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 根据模板ID是否在收集列表中,判断是否需要收集当前模板的信息 |
|
||||||
*/ |
|
||||||
public boolean contains(String templateID) { |
|
||||||
return StringUtils.isNotEmpty(templateID) && latestTemplateInfo.containsKey(templateID); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 收集模板信息。如果之前没有记录,则新增;如果已有记录,则更新。 |
|
||||||
* 同时将最新数据保存到文件中。 |
|
||||||
* |
|
||||||
* @param templateID 模版id |
|
||||||
* @param originID 模版的原始id,仅对另存为的模版有效,对于非另存为的模版,值总是为空 |
|
||||||
* @param processInfo 包含模版的一些基本信息(如模版类型、包含控件数量等) |
|
||||||
* @param timeConsume 本次制作耗时,单位为 s |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public void collectInfo(String templateID, String originID, TemplateProcessInfo processInfo, int timeConsume) { |
|
||||||
if (!shouldCollectInfo()) { |
|
||||||
return; |
|
||||||
} |
|
||||||
long saveTime = System.currentTimeMillis(); |
|
||||||
|
|
||||||
TemplateInfo templateInfo = createTemplateInfo(templateID, originID, saveTime, timeConsume); |
|
||||||
|
|
||||||
pointInfoMap.put(templateInfo.getTemplateInfoID(), templateInfo); |
|
||||||
|
|
||||||
//更新下此模板最新保存记录
|
|
||||||
updateLatestTemplateInfo(templateID, saveTime); |
|
||||||
|
|
||||||
// 收集模版基本信息
|
|
||||||
templateInfo.updateProcessMap(processInfo); |
|
||||||
//设置是否是测试模板
|
|
||||||
templateInfo.setTestTemplate(processInfo.isTestTemplate()); |
|
||||||
// 刷新闲置日计数器
|
|
||||||
templateInfo.resetIdleDayCount(); |
|
||||||
|
|
||||||
|
|
||||||
// 每次更新之后,都同步到暂存文件中
|
|
||||||
saveInfo(); |
|
||||||
} |
|
||||||
|
|
||||||
private TemplateInfo createTemplateInfo(String templateID, String originID, long saveTime, int timeConsume){ |
|
||||||
JSONObject saveRecord = JSONFactory.createJSON(JSON.OBJECT); |
|
||||||
saveRecord.put("time", saveTime); |
|
||||||
saveRecord.put("consume", timeConsume); |
|
||||||
if (this.contains(templateID)){ |
|
||||||
return TemplateInfo.newInstance(templateID, originID, saveRecord.toString(), getTemplateCreateTime(templateID)); |
|
||||||
} |
|
||||||
return TemplateInfo.newInstance(templateID, originID, saveRecord.toString()); |
|
||||||
} |
|
||||||
|
|
||||||
private String getTemplateCreateTime(String templateID) { |
|
||||||
long latestSaveTime = latestTemplateInfo.get(templateID); |
|
||||||
TemplateInfo latestTemplateInfo = pointInfoMap.get(templateID + "_" + latestSaveTime); |
|
||||||
return latestTemplateInfo.getTemplateCreateTime(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 更新 day_count:打开设计器却未编辑模板的连续日子 |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected void addIdleDayCount() { |
|
||||||
// 判断今天是否第一次打开设计器,为了防止同一天内,多次 addIdleDayCount
|
|
||||||
if (designerOpenHistory.hasOpenedToday()) { |
|
||||||
return; |
|
||||||
} |
|
||||||
for (TemplateInfo templateInfo : pointInfoMap.values()) { |
|
||||||
templateInfo.addIdleDayCountByOne(); |
|
||||||
} |
|
||||||
designerOpenHistory.update(); |
|
||||||
} |
|
||||||
|
|
||||||
private void updateLatestTemplateInfo(TemplateInfo templateInfo) { |
|
||||||
String templateID = templateInfo.getTemplateID(); |
|
||||||
if (latestTemplateInfo.containsKey(templateID)) { |
|
||||||
long latestSaveTime = latestTemplateInfo.get(templateID); |
|
||||||
updateLatestTemplateInfo(templateID, Math.max(latestSaveTime, templateInfo.getSaveTime())); |
|
||||||
} else { |
|
||||||
updateLatestTemplateInfo(templateID, templateInfo.getSaveTime()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void updateLatestTemplateInfo(String templateID, long saveTime) { |
|
||||||
latestTemplateInfo.put(templateID, saveTime); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void readXML(XMLableReader reader) { |
|
||||||
if (reader.isChildNode()) { |
|
||||||
try { |
|
||||||
String name = reader.getTagName(); |
|
||||||
if (DesignerOpenHistory.XML_TAG.equals(name)) { |
|
||||||
if (designerOpenHistory == null) { |
|
||||||
designerOpenHistory = DesignerOpenHistory.getInstance(); |
|
||||||
} |
|
||||||
reader.readXMLObject(designerOpenHistory); |
|
||||||
} else if (TemplateInfo.XML_TAG.equals(name)) { |
|
||||||
TemplateInfo templateInfo = TemplateInfo.newInstanceByRead(reader); |
|
||||||
updateLatestTemplateInfo(templateInfo); |
|
||||||
pointInfoMap.put(templateInfo.getTemplateInfoID(), templateInfo); |
|
||||||
} |
|
||||||
} catch (Exception ex) { |
|
||||||
// 什么也不做,使用默认值
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void writeXML(XMLPrintWriter writer) { |
|
||||||
writer.startTAG(XML_TAG); |
|
||||||
|
|
||||||
designerOpenHistory.writeXML(writer); |
|
||||||
|
|
||||||
writer.startTAG(XML_TEMPLATE_INFO_LIST); |
|
||||||
for (TemplateInfo templateInfo : pointInfoMap.values()) { |
|
||||||
templateInfo.writeXML(writer); |
|
||||||
} |
|
||||||
writer.end(); |
|
||||||
|
|
||||||
writer.end(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* 获取缓存文件存放路径 |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected String getInfoFilePath() { |
|
||||||
return XML_FILE_NAME; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void sendPointInfo() { |
|
||||||
addIdleDayCount(); |
|
||||||
List<String> removeList = new ArrayList<>(); |
|
||||||
List<String> sendList = new ArrayList<>(); |
|
||||||
for (String latestTemplateInfokey : latestTemplateInfo.keySet()) { |
|
||||||
AbstractPointInfo pointInfo = pointInfoMap.get(latestTemplateInfokey + "_" + latestTemplateInfo.get(latestTemplateInfokey)); |
|
||||||
if (pointInfo.isTestTemplate()) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
for (String key : pointInfoMap.keySet()) { |
|
||||||
if (key.startsWith(latestTemplateInfokey)) { |
|
||||||
sendList.add(key); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
// 发送记录
|
|
||||||
for (String key : sendList) { |
|
||||||
if (SendHelper.sendPointInfo(pointInfoMap.get(key))) { |
|
||||||
removeList.add(key); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// 清空记录
|
|
||||||
for (String key : removeList) { |
|
||||||
pointInfoMap.remove(key); |
|
||||||
} |
|
||||||
|
|
||||||
saveInfo(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
@Override |
|
||||||
protected void loadFromFile() { |
|
||||||
latestTemplateInfo = new ConcurrentHashMap<>(); |
|
||||||
super.loadFromFile(); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,38 +1,7 @@ |
|||||||
package com.fr.design.mainframe.template.info; |
package com.fr.design.mainframe.template.info; |
||||||
|
|
||||||
import com.fr.invoke.Reflect; |
|
||||||
import com.fr.json.JSONObject; |
|
||||||
import com.fr.stable.xml.XMLableReader; |
|
||||||
import com.fr.third.javax.xml.stream.XMLStreamException; |
|
||||||
|
|
||||||
import java.io.StringReader; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue; |
|
||||||
|
|
||||||
/** |
/** |
||||||
* Created by plough on 2019/4/25. |
* Created by plough on 2019/4/25. |
||||||
*/ |
*/ |
||||||
public class SendHelperTest { |
public class SendHelperTest { |
||||||
private static final String CONSUMING_URL = "http://cloud.fanruan.com/api/monitor/record_of_reports_consuming/single"; |
|
||||||
private static final String PROCESS_URL = "http://cloud.fanruan.com/api/monitor/record_of_reports_process/single"; |
|
||||||
|
|
||||||
private static final String NORMAL_INFO = "<TemplateInfo templateID=\"16a988ce-8529-42f5-b17c-2ee849355071\" day_count=\"9\">\n" + |
|
||||||
"<processMap process=\"\" float_count=\"0\" widget_count=\"0\" cell_count=\"1\" block_count=\"0\" report_type=\"0\"/>\n" + |
|
||||||
"<consumingMap activitykey=\"2e0ea413-fa9c241e0-9723-4354fce51e81\" jar_time=\"不是安装版本\" create_time=\"2019-03-26 16:13\" uuid=\"476ca2cc-f789-4c5d-8e89-ef146580775c\" time_consume=\"129\" version=\"10.0\" username=\"plough\"/>\n" + |
|
||||||
"</TemplateInfo>"; |
|
||||||
|
|
||||||
// 只在调试的时候运行,不需要每次都自动运行
|
|
||||||
public static void main(String[] args) throws XMLStreamException { |
|
||||||
StringReader sr = new StringReader(NORMAL_INFO); |
|
||||||
XMLableReader xmlReader = XMLableReader.createXMLableReader(sr); |
|
||||||
TemplateInfo templateInfo = TemplateInfo.newInstanceByRead(xmlReader); |
|
||||||
Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
Map processMap = Reflect.on(templateInfo).field("processMap").get(); |
|
||||||
boolean res = Reflect.on(SendHelper.class).call("sendSinglePointInfo", CONSUMING_URL, new JSONObject(consumingMap).toString()).get(); |
|
||||||
assertTrue(res); |
|
||||||
|
|
||||||
boolean res2 = Reflect.on(SendHelper.class).call("sendSinglePointInfo", PROCESS_URL, new JSONObject(processMap).toString()).get(); |
|
||||||
assertTrue(res2); |
|
||||||
} |
|
||||||
} |
} |
||||||
|
@ -1,252 +0,0 @@ |
|||||||
package com.fr.design.mainframe.template.info; |
|
||||||
|
|
||||||
import com.fr.config.MarketConfig; |
|
||||||
import com.fr.design.DesignerEnvManager; |
|
||||||
import com.fr.invoke.Reflect; |
|
||||||
import com.fr.json.JSON; |
|
||||||
import com.fr.json.JSONArray; |
|
||||||
import com.fr.json.JSONFactory; |
|
||||||
import com.fr.stable.ProductConstants; |
|
||||||
import com.fr.stable.StringUtils; |
|
||||||
import com.fr.third.org.apache.commons.io.FileUtils; |
|
||||||
import org.easymock.EasyMock; |
|
||||||
import org.junit.After; |
|
||||||
import org.junit.Assert; |
|
||||||
import org.junit.Before; |
|
||||||
import org.junit.Test; |
|
||||||
import org.junit.runner.RunWith; |
|
||||||
import org.powermock.api.easymock.PowerMock; |
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest; |
|
||||||
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; |
|
||||||
import org.powermock.modules.junit4.PowerMockRunner; |
|
||||||
|
|
||||||
import java.io.File; |
|
||||||
import java.io.IOException; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
import static com.fr.design.mainframe.template.info.TemplateInfoTestHelper.assertJsonStringEquals; |
|
||||||
import static com.fr.design.mainframe.template.info.TemplateInfoTestHelper.setUpMockForNewInstance; |
|
||||||
import static org.junit.Assert.assertEquals; |
|
||||||
import static org.junit.Assert.assertTrue; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by plough on 2019/4/18. |
|
||||||
*/ |
|
||||||
@RunWith(PowerMockRunner.class) |
|
||||||
@PrepareForTest({ProductConstants.class, MarketConfig.class, DesignerEnvManager.class}) |
|
||||||
@SuppressStaticInitializationFor({"com.fr.jvm.assist.FineAssist"}) |
|
||||||
public class TemplateInfoCollectorTest { |
|
||||||
private String filePath; |
|
||||||
private String initialFileContent; |
|
||||||
private TemplateProcessInfo mockProcessInfo; |
|
||||||
|
|
||||||
@Before |
|
||||||
public void setUp() throws IOException { |
|
||||||
PowerMock.mockStatic(ProductConstants.class); |
|
||||||
|
|
||||||
filePath = getClass().getResource("tpl.info").getPath(); |
|
||||||
String dirPath = filePath.substring(0, filePath.indexOf("tpl.info")); |
|
||||||
EasyMock.expect(ProductConstants.getEnvHome()).andReturn(dirPath).anyTimes(); |
|
||||||
EasyMock.replay(); |
|
||||||
PowerMock.replayAll(); |
|
||||||
|
|
||||||
mockProcessInfo = EasyMock.mock(TemplateProcessInfo.class); |
|
||||||
EasyMock.expect(mockProcessInfo.getBlockCount()).andReturn(3).anyTimes(); |
|
||||||
EasyMock.expect(mockProcessInfo.getCellCount()).andReturn(13).anyTimes(); |
|
||||||
EasyMock.expect(mockProcessInfo.getFloatCount()).andReturn(1).anyTimes(); |
|
||||||
EasyMock.expect(mockProcessInfo.getReportType()).andReturn(0).anyTimes(); |
|
||||||
EasyMock.expect(mockProcessInfo.getWidgetCount()).andReturn(0).anyTimes(); |
|
||||||
EasyMock.expect(mockProcessInfo.useParaPane()).andReturn(false).anyTimes(); |
|
||||||
EasyMock.expect(mockProcessInfo.getComponentsInfo()).andReturn(new JSONArray()).anyTimes(); |
|
||||||
EasyMock.expect(mockProcessInfo.isTestTemplate()).andReturn(true).anyTimes(); |
|
||||||
EasyMock.expect(mockProcessInfo.getReuseCmpList()).andReturn(JSONArray.create().add("reuse-id-1")).anyTimes(); |
|
||||||
EasyMock.replay(mockProcessInfo); |
|
||||||
|
|
||||||
// 缓存 tpl.info
|
|
||||||
initialFileContent = FileUtils.readFileToString(new File(filePath), "utf-8"); |
|
||||||
|
|
||||||
Reflect.on(TemplateInfoCollector.class).set("instance", null); |
|
||||||
// 后执行 testReadXML 用例时,之前保留的单例会造成影响
|
|
||||||
Reflect.on(DesignerOpenHistory.class).set("singleton", null); |
|
||||||
} |
|
||||||
|
|
||||||
@After |
|
||||||
public void tearDown() throws IOException { |
|
||||||
// 恢复 tpl.info
|
|
||||||
FileUtils.writeStringToFile(new File(filePath), initialFileContent, "utf-8"); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testReadXML() { |
|
||||||
assertEquals(",,", DesignerOpenHistory.getInstance().toString()); |
|
||||||
|
|
||||||
TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); |
|
||||||
|
|
||||||
assertEquals("2020-05-07,2020-05-06,2020-04-30", DesignerOpenHistory.getInstance().toString()); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testCollectInfo() throws Exception { |
|
||||||
setUpMockForNewInstance(); |
|
||||||
TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); |
|
||||||
|
|
||||||
String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; |
|
||||||
int timeConsume = 200; |
|
||||||
|
|
||||||
collector.collectInfo(templateID, StringUtils.EMPTY, mockProcessInfo, timeConsume); |
|
||||||
|
|
||||||
// 检查是否写入成功
|
|
||||||
Reflect.on(collector).call("loadFromFile"); |
|
||||||
TemplateInfo templateInfo = getTemplateInfoByID(templateID); |
|
||||||
|
|
||||||
Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
Map processMap = Reflect.on(templateInfo).field("processMap").get(); |
|
||||||
|
|
||||||
assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," + |
|
||||||
"\"cell_count\":13,\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," + |
|
||||||
"\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\",\"reuseCmptList\":\"[\\\"reuse-id-1\\\"]\"" + |
|
||||||
"}", |
|
||||||
JSONFactory.createJSON(JSON.OBJECT, processMap).toString()); |
|
||||||
|
|
||||||
Assert.assertEquals(71113, consumingMap.get("uid")); |
|
||||||
Assert.assertEquals("2020-05-07 17:25", consumingMap.get("create_time")); |
|
||||||
Assert.assertEquals("e5d7dbb2-d1df-43d4-b974-67acb5ecbffa", consumingMap.get("templateID")); |
|
||||||
Assert.assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testCollectInfoForNewTemplate() throws Exception { |
|
||||||
setUpMockForNewInstance(); |
|
||||||
|
|
||||||
TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); |
|
||||||
|
|
||||||
String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; |
|
||||||
int timeConsume = 200; |
|
||||||
|
|
||||||
collector.collectInfo(templateID, StringUtils.EMPTY, mockProcessInfo, timeConsume); |
|
||||||
|
|
||||||
// 检查是否写入成功
|
|
||||||
Reflect.on(collector).call("loadFromFile"); |
|
||||||
assertTrue(collector.contains(templateID)); |
|
||||||
|
|
||||||
TemplateInfo templateInfo = getTemplateInfoByID(templateID); |
|
||||||
Map processMap = Reflect.on(templateInfo).field("processMap").get(); |
|
||||||
|
|
||||||
assertEquals(templateID, templateInfo.getTemplateID()); |
|
||||||
|
|
||||||
assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," + |
|
||||||
"\"cell_count\":13,\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," + |
|
||||||
"\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\",\"reuseCmptList\":\"[\\\"reuse-id-1\\\"]\"" + |
|
||||||
"}", JSONFactory.createJSON(JSON.OBJECT, processMap).toString()); |
|
||||||
|
|
||||||
Map<String, Object> consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
Assert.assertEquals(71113, consumingMap.get("uid")); |
|
||||||
Assert.assertEquals("2020-05-07 17:25", consumingMap.get("create_time")); |
|
||||||
Assert.assertEquals("e5d7dbb2-d1df-43d4-b974-67acb5ecbffa", consumingMap.get("templateID")); |
|
||||||
Assert.assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testCollectInfoWhenSaveAs() throws Exception { |
|
||||||
setUpMockForNewInstance(); |
|
||||||
|
|
||||||
TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); |
|
||||||
|
|
||||||
String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; |
|
||||||
String originID = "16a988ce-8529-42f5-b17c-2ee849355071"; |
|
||||||
int timeConsume = 200; |
|
||||||
|
|
||||||
collector.collectInfo(templateID, originID, mockProcessInfo, timeConsume); |
|
||||||
|
|
||||||
// 检查是否写入成功
|
|
||||||
Reflect.on(collector).call("loadFromFile"); |
|
||||||
TemplateInfo templateInfo = getTemplateInfoByID(templateID); |
|
||||||
Map processMap = Reflect.on(templateInfo).field("processMap").get(); |
|
||||||
|
|
||||||
assertJsonStringEquals("{\"process\":\"\",\"float_count\":1,\"widget_count\":0," + |
|
||||||
"\"cell_count\":13,\"paraApply\":0,\"block_count\":3,\"report_type\":0,\"components_info\":\"[]\"," + |
|
||||||
"\"templateID\":\"e5d7dbb2-d1df-43d4-b974-67acb5ecbffa\",\"reuseCmptList\":\"[\\\"reuse-id-1\\\"]\"" + |
|
||||||
"}", JSONFactory.createJSON(JSON.OBJECT, processMap).toString()); |
|
||||||
|
|
||||||
Map<String, Object> consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
Assert.assertEquals(71113, consumingMap.get("uid")); |
|
||||||
Assert.assertEquals("2020-05-07 17:25", consumingMap.get("create_time")); |
|
||||||
Assert.assertEquals("e5d7dbb2-d1df-43d4-b974-67acb5ecbffa", consumingMap.get("templateID")); |
|
||||||
Assert.assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); |
|
||||||
Assert.assertEquals("16a988ce-8529-42f5-b17c-2ee849355071", consumingMap.get("originID")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testCollectInfoWhenSaveAsWithNoTrackOriginID() throws Exception { |
|
||||||
setUpMockForNewInstance(); |
|
||||||
|
|
||||||
TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); |
|
||||||
|
|
||||||
String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; |
|
||||||
String originID = "3kha8jcs-31xw-42f5-h2ww-2ee84935312z"; |
|
||||||
int timeConsume = 200; |
|
||||||
|
|
||||||
collector.collectInfo(templateID, originID, mockProcessInfo, timeConsume); |
|
||||||
|
|
||||||
TemplateInfo templateInfo = getTemplateInfoByID(templateID); |
|
||||||
assertEquals(templateID, templateInfo.getTemplateID()); |
|
||||||
|
|
||||||
Map<String, Object> consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
Assert.assertEquals(71113, consumingMap.get("uid")); |
|
||||||
Assert.assertEquals("2020-05-07 17:25", consumingMap.get("create_time")); |
|
||||||
Assert.assertEquals("e5d7dbb2-d1df-43d4-b974-67acb5ecbffa", consumingMap.get("templateID")); |
|
||||||
Assert.assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); |
|
||||||
Assert.assertEquals("3kha8jcs-31xw-42f5-h2ww-2ee84935312z", consumingMap.get("originID")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testAddIdleDateCount() { |
|
||||||
String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; |
|
||||||
TemplateInfoCollector collecter = TemplateInfoCollector.getInstance(); |
|
||||||
TemplateInfo templateInfo = getTemplateInfoByID(templateID); |
|
||||||
|
|
||||||
assertEquals(0, templateInfo.getIdleDayCount()); |
|
||||||
|
|
||||||
Reflect.on(collecter).call("addIdleDayCount"); |
|
||||||
assertEquals(1, templateInfo.getIdleDayCount()); |
|
||||||
|
|
||||||
// 同一天内多次调用无效
|
|
||||||
Reflect.on(collecter).call("addIdleDayCount"); |
|
||||||
assertEquals(1, templateInfo.getIdleDayCount()); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testContains() { |
|
||||||
TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); |
|
||||||
String templateID1 = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; |
|
||||||
Assert.assertTrue(collector.contains(templateID1)); |
|
||||||
String templateID2 = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffb"; |
|
||||||
Assert.assertFalse(collector.contains(templateID2)); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testGetTemplateCreateTime() throws Exception { |
|
||||||
setUpMockForNewInstance(); |
|
||||||
TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); |
|
||||||
String templateID = "e5d7dbb2-d1df-43d4-b974-67acb5ecbffa"; |
|
||||||
String createTime = Reflect.on(collector).call("getTemplateCreateTime", templateID).get(); |
|
||||||
Assert.assertEquals("2020-05-07 17:25", createTime); |
|
||||||
|
|
||||||
templateID = "2521d03c-b238-41a5-9a1d-2498efff3a97"; |
|
||||||
createTime = Reflect.on(collector).call("getTemplateCreateTime", templateID).get(); |
|
||||||
Assert.assertEquals("2020-05-07 17:45", createTime); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
private TemplateInfo getTemplateInfoByID(String templateID) { |
|
||||||
TemplateInfoCollector collector = TemplateInfoCollector.getInstance(); |
|
||||||
Map<String, Long> latestTemplateInfo = Reflect.on(collector).field("latestTemplateInfo").get(); |
|
||||||
Map<String, TemplateInfo> pointInfoMap = Reflect.on(collector).field("pointInfoMap").get(); |
|
||||||
if (latestTemplateInfo.containsKey(templateID)) { |
|
||||||
long latestSaveTime = latestTemplateInfo.get(templateID); |
|
||||||
return pointInfoMap.get(templateID + "_" + latestSaveTime); |
|
||||||
} else { |
|
||||||
return TemplateInfo.newInstance(templateID); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,143 +0,0 @@ |
|||||||
package com.fr.design.mainframe.template.info; |
|
||||||
|
|
||||||
import com.fr.config.MarketConfig; |
|
||||||
import com.fr.design.DesignerEnvManager; |
|
||||||
import com.fr.invoke.Reflect; |
|
||||||
import com.fr.json.JSON; |
|
||||||
import com.fr.json.JSONFactory; |
|
||||||
import com.fr.json.JSONObject; |
|
||||||
import com.fr.stable.StringUtils; |
|
||||||
import com.fr.stable.xml.XMLableReader; |
|
||||||
import com.fr.third.javax.xml.stream.XMLStreamException; |
|
||||||
import org.junit.Assert; |
|
||||||
import org.junit.Before; |
|
||||||
import org.junit.Test; |
|
||||||
import org.junit.runner.RunWith; |
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest; |
|
||||||
import org.powermock.modules.junit4.PowerMockRunner; |
|
||||||
|
|
||||||
import java.io.StringReader; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
import static com.fr.design.mainframe.template.info.TemplateInfoTestHelper.assertJsonStringEquals; |
|
||||||
import static com.fr.design.mainframe.template.info.TemplateInfoTestHelper.setUpMockForNewInstance; |
|
||||||
import static org.junit.Assert.assertEquals; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by plough on 2019/4/19. |
|
||||||
*/ |
|
||||||
@RunWith(PowerMockRunner.class) |
|
||||||
@PrepareForTest({MarketConfig.class, DesignerEnvManager.class}) |
|
||||||
public class TemplateInfoTest { |
|
||||||
|
|
||||||
private static final String NORMAL_INFO = "<TemplateInfo templateID=\"aac1139e-018b-4481-867a-a18fc6d6f3e6\" day_count=\"0\" test_template=\"true\">\n" + |
|
||||||
"<processMap process=\"\" float_count=\"0\" widget_count=\"0\" cell_count=\"3\" block_count=\"0\" report_type=\"0\" paraApply=\"0\" components_info=\"[]\"/>\n" + |
|
||||||
"<consumingMap create_time=\"2020-05-07 17:28\" uuid=\"6b6699ff-ec63-43b0-9deb-b580a5f10411\" uid=\"71113\" saveRecord=\"{"time":1588843693000,"consume":4}\"/>\n" + |
|
||||||
"</TemplateInfo>"; |
|
||||||
|
|
||||||
private static final String SAVE_AS_INFO = "<TemplateInfo templateID=\"2521d03c-b238-41a5-9a1d-2498efff3a97\" originID=\"aac1139e-018b-4481-867a-a18fc6d6f3e6\" day_count=\"0\" test_template=\"true\">\n" + |
|
||||||
"<processMap process=\"\" float_count=\"0\" widget_count=\"0\" cell_count=\"3\" block_count=\"0\" report_type=\"0\" paraApply=\"0\" components_info=\"[]\"/>\n" + |
|
||||||
"<consumingMap create_time=\"2020-05-07 17:45\" uuid=\"6b6699ff-ec63-43b0-9deb-b580a5f10411\" uid=\"71113\" saveRecord=\"{"time":1588844751000,"consume":1058}\"/>\n" + |
|
||||||
"</TemplateInfo>"; |
|
||||||
|
|
||||||
private TemplateInfo templateInfo; |
|
||||||
private TemplateInfo templateInfoSaveAs; // 另存为的模版记录
|
|
||||||
|
|
||||||
@Before |
|
||||||
public void setUp() throws XMLStreamException { |
|
||||||
templateInfo = createTemplateInfo(NORMAL_INFO); |
|
||||||
templateInfoSaveAs = createTemplateInfo(SAVE_AS_INFO); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testNewInstance() throws Exception { |
|
||||||
setUpMockForNewInstance(); |
|
||||||
|
|
||||||
String templateID = "24avc8n2-1iq8-iuj2-wx24-8yy0i8132302"; |
|
||||||
TemplateInfo templateInfo = TemplateInfo.newInstance(templateID); |
|
||||||
assertEquals(templateID, templateInfo.getTemplateID()); |
|
||||||
assertEquals(StringUtils.EMPTY, Reflect.on(templateInfo).field("originID").get()); |
|
||||||
assertEquals(0, (int) Reflect.on(templateInfo).field("idleDayCount").get()); |
|
||||||
assertEquals(false, templateInfo.isTestTemplate()); |
|
||||||
|
|
||||||
Map<String, Object> consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
assertEquals(templateID, consumingMap.get("templateID")); |
|
||||||
assertEquals(StringUtils.EMPTY, consumingMap.get("originID")); |
|
||||||
assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); |
|
||||||
assertEquals(71113, consumingMap.get("uid")); |
|
||||||
assertEquals(StringUtils.EMPTY, consumingMap.get("saveRecord")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testNewInstanceWithMoreArgs() throws Exception { |
|
||||||
setUpMockForNewInstance(); |
|
||||||
|
|
||||||
String templateID = "24121212-u2c8-ncd2-82nx-8ud0i8138888"; |
|
||||||
String originID = "24avc8n2-1iq8-iuj2-wx24-8yy0i8132302"; |
|
||||||
String saveRecord = "{\"time\";:1588843629000,\"consume\":81}"; |
|
||||||
String createTime = "2020-05-07 17:25"; |
|
||||||
TemplateInfo templateInfo = TemplateInfo.newInstance(templateID, originID, saveRecord, createTime); |
|
||||||
assertEquals(templateID, templateInfo.getTemplateID()); |
|
||||||
assertEquals(originID, Reflect.on(templateInfo).field("originID").get()); |
|
||||||
assertEquals(0, (int) Reflect.on(templateInfo).field("idleDayCount").get()); |
|
||||||
assertEquals(false, templateInfo.isTestTemplate()); |
|
||||||
|
|
||||||
Map<String, Object> consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
assertEquals(templateID, consumingMap.get("templateID")); |
|
||||||
assertEquals(originID, consumingMap.get("originID")); |
|
||||||
assertEquals("6b6699ff-ec63-43b0-9deb-b580a5f10411", consumingMap.get("uuid")); |
|
||||||
assertEquals(71113, consumingMap.get("uid")); |
|
||||||
assertEquals(saveRecord, consumingMap.get("saveRecord")); |
|
||||||
assertEquals(createTime, consumingMap.get("create_time")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testGetTemplateID() { |
|
||||||
assertEquals("aac1139e-018b-4481-867a-a18fc6d6f3e6", templateInfo.getTemplateID()); |
|
||||||
assertEquals("2521d03c-b238-41a5-9a1d-2498efff3a97", templateInfoSaveAs.getTemplateID()); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testGetSendInfo() { |
|
||||||
|
|
||||||
Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
Map processMap = Reflect.on(templateInfo).field("processMap").get(); |
|
||||||
Map consumingMap1 = Reflect.on(templateInfoSaveAs).field("consumingMap").get(); |
|
||||||
Map processMap1 = Reflect.on(templateInfoSaveAs).field("processMap").get(); |
|
||||||
assertJsonStringEquals("{\"uid\":71113,\"originID\":\"\",\"create_time\":\"2020-05-07 17:28\"," + |
|
||||||
"\"saveRecord\":\"{\\\"time\\\":1588843693000,\\\"consume\\\":4}\"," + |
|
||||||
"\"templateID\":\"aac1139e-018b-4481-867a-a18fc6d6f3e6\"," + |
|
||||||
"\"uuid\":\"6b6699ff-ec63-43b0-9deb-b580a5f10411\"}", JSONFactory.createJSON(JSON.OBJECT, consumingMap).toString()); |
|
||||||
|
|
||||||
assertJsonStringEquals("{\"uid\":71113,\"originID\":\"aac1139e-018b-4481-867a-a18fc6d6f3e6\"," + |
|
||||||
"\"create_time\":\"2020-05-07 17:45\",\"saveRecord\":\"{\\\"time\\\":1588844751000,\\\"consume\\\":1058}\"," + |
|
||||||
"\"templateID\":\"2521d03c-b238-41a5-9a1d-2498efff3a97\"," + |
|
||||||
"\"uuid\":\"6b6699ff-ec63-43b0-9deb-b580a5f10411\"}", JSONFactory.createJSON(JSON.OBJECT, consumingMap1).toString()); |
|
||||||
assertJsonStringEquals("{\"process\":\"\",\"float_count\":0,\"widget_count\":0,\"cell_count\":3," + |
|
||||||
"\"paraApply\":0,\"block_count\":0,\"report_type\":0,\"components_info\":\"[]\"," + |
|
||||||
"\"templateID\":\"aac1139e-018b-4481-867a-a18fc6d6f3e6\"}", JSONFactory.createJSON(JSON.OBJECT, processMap).toString()); |
|
||||||
assertJsonStringEquals("{\"process\":\"\",\"float_count\":0,\"widget_count\":0,\"cell_count\":3," + |
|
||||||
"\"paraApply\":0,\"block_count\":0,\"report_type\":0,\"components_info\":\"[]\"," + |
|
||||||
"\"templateID\":\"2521d03c-b238-41a5-9a1d-2498efff3a97\"}", JSONFactory.createJSON(JSON.OBJECT, processMap1).toString()); |
|
||||||
} |
|
||||||
|
|
||||||
private TemplateInfo createTemplateInfo(String xmlContent) throws XMLStreamException { |
|
||||||
StringReader sr = new StringReader(xmlContent); |
|
||||||
XMLableReader xmlReader = XMLableReader.createXMLableReader(sr); |
|
||||||
return TemplateInfo.newInstanceByRead(xmlReader); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testGetSaveTime() { |
|
||||||
Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
String saveRecord = (String) consumingMap.get("saveRecord"); |
|
||||||
JSONObject object = JSONFactory.createJSON(JSON.OBJECT, saveRecord); |
|
||||||
Assert.assertEquals(1588843693000L, object.optLong("time")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
public void testGetTemplateCreateTime() { |
|
||||||
Map consumingMap = Reflect.on(templateInfo).field("consumingMap").get(); |
|
||||||
Assert.assertEquals("2020-05-07 17:28", (String) consumingMap.get("create_time")); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue