feat(legacy-core): 移植 EIP3 服务流引擎到保真层(com.dsasp.* 原样)
P1-2 第一步:framework com.dsasp.server.core 17 文件移植 + 缺失 common 依赖回填。
引擎(core):FlowExcuteServiceImpl(534 行,服务流执行入口)+ FlowServiceImpl
(流定义加载/默认流生成)+ flow/model 8 个(Flow/Node/Field/Procedure/Script/
ServiceBean/Start/End/Transition + BaseFlowConvert/DefaultFlowHelper)+
service/script(ScriptingEnginesManager/FlowScriptBindings)+ origin(OriginServiceManagerImpl)。
OSGi Activator.java 不移植(纯 BundleActivator/sun.awt,JDK17 不可用;
等价能力已由 SpringBeanOsgiServices @Component + 组件扫描接管,见迁移手册 §3.1)。
缺失 common 依赖回填(framework 原样):core.ControlBean/FlowDefinition、
core.service.{FlowExcuteService,FlowService,OriginServiceManager}、
util.{AopTargetUtils,ExceptionUtil}、privilege.service.FlowPrivilegeService。
函数库回迁:GetValueFunction/GetDefaultValueFunction 以 framework 原版 Groovy
回迁(替换 PoC 空桩,依赖均已就位,gmavenplus 联合编译);GetServicesFunction
保包名/类名/签名,回迁引擎执行路径实际调用的 findCount/loadPOJO/listSelect
三方法(其余 @Function 依赖 P2/P3 横切服务,届时补全)。
FlowPrivilegeService:framework 原样移植(FlowPrivilegeServiceImpl + ServicePrivilege)
入保真层 com.dsasp.server.privilege.service。
API 断点修复(迁移手册 §2 同款):FlowServiceImpl 移除 JDK 内部 import
com.sun.xml.internal.*(原版未用)、queryForInt→queryForObject;Flow.java
dom4j 2.x selectNodes 返回 List<Node> 加 unchecked 转型(14 处)。
ScriptingEnginesManager 的 activiti JuelScriptEngineFactory 适配为 JSR-223 惰性
注册(架构纪律:activiti/Flowable 不进保真层;线性查询/报表流不走 juel)。
mvn compile/test 通过,ArchUnit(保真层禁依赖现代层)仍绿。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package com.dsasp.server.common.function
|
||||
|
||||
import org.joda.time.DateMidnight
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.DateTimeZone
|
||||
import org.joda.time.format.DateTimeFormat
|
||||
import org.joda.time.format.DateTimeFormatter
|
||||
|
||||
import com.dsasp.server.common.core.Function
|
||||
import com.dsasp.server.common.dataDic.bean.SysConfig;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
import com.dsasp.server.common.util.StringUtil
|
||||
|
||||
/**
|
||||
* 默认值函数
|
||||
* @author shanxh
|
||||
*
|
||||
*/
|
||||
class GetDefaultValueFunction {
|
||||
@Function(name="当前用户",tip="返回当前用户ID")
|
||||
static String getCurrentUserId(){
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTUSER);
|
||||
}
|
||||
|
||||
@Function(name="当前部门",tip="返回当前部门ID")
|
||||
static String getCurrentUserDepartId(){
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTDEPART);
|
||||
}
|
||||
|
||||
@Function(name="当前组织",tip="返回当前组织ID")
|
||||
static String getCurrentUserOrgId(){
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTORG);
|
||||
}
|
||||
|
||||
@Function(name="当前工程",tip="返回当前工程ID")
|
||||
static String getCurrentProjectId(){
|
||||
return UserSession.get().getProperty(LoggedInUser.CURRENTPROJECT);
|
||||
}
|
||||
|
||||
@Function(name="当前日期",tip="返回当前日期,返回值:{DateTime}当前日期")
|
||||
static DateTime currentDate(){
|
||||
return new DateMidnight(DateTimeZone.getDefault()).toDateTime();
|
||||
}
|
||||
|
||||
@Function(name="当前日期时间",tip="返回当前日期时间,返回值:{DateTime}当前日期时间")
|
||||
static DateTime currentDateTime(){
|
||||
return new DateTime(DateTimeZone.getDefault());
|
||||
}
|
||||
|
||||
@Function(name="当前年份",tip="返回当前年份,返回值:{int}返回当前年份")
|
||||
static int currentYear(){
|
||||
return currentDateTime().getYear()
|
||||
}
|
||||
|
||||
@Function(name="当前月份",tip="返回当前月份,返回值:{int}返回当前月份")
|
||||
static int currentMonth(){
|
||||
return currentDateTime().getMonthOfYear()
|
||||
}
|
||||
@Function(name="当前日",tip="返回当前日,返回值:{int}当前时间是几号")
|
||||
static int currentDay(){
|
||||
return currentDateTime().getDayOfMonth()
|
||||
}
|
||||
|
||||
@Function(name="当前小时",tip="返回当前小时,返回值:{int}当前时间的小时")
|
||||
static int currentHour(){
|
||||
return currentDateTime().getHourOfDay()
|
||||
}
|
||||
|
||||
@Function(name="当前分钟",tip="返回当前分钟,返回值:{int}当前时间的分钟")
|
||||
static int currentMinute(){
|
||||
return currentDateTime().getMinuteOfHour()
|
||||
}
|
||||
|
||||
@Function(name="当前秒",tip="返回当前秒,返回值:{int}当前时间的秒")
|
||||
static int secondOf(){
|
||||
return currentDateTime().getSecondOfMinute()
|
||||
}
|
||||
|
||||
@Function(name="创建gui唯一标示",tip="获取gui唯一标示,返回值:{String} 唯一标示")
|
||||
static String guid(){
|
||||
return UUID.randomUUID()
|
||||
}
|
||||
@Function(name="获取系统配置的属性值",tip="获取系统配置的属性值,参数:{String}key 系统配置主键,返回值:{String} 属性值")
|
||||
static String getConfigValue(String key){
|
||||
SysConfig.getConfigValue(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,781 @@
|
||||
package com.dsasp.server.common.function
|
||||
|
||||
|
||||
import java.text.DecimalFormat
|
||||
|
||||
import org.joda.time.DateTime
|
||||
import org.joda.time.format.DateTimeFormat
|
||||
import org.joda.time.format.DateTimeFormatter
|
||||
|
||||
import com.dsasp.server.common.core.Function
|
||||
import com.dsasp.server.common.exception.ValidationException
|
||||
import com.dsasp.server.common.util.StringUtil
|
||||
|
||||
/**
|
||||
* 字段取值函数
|
||||
* @author shanxh
|
||||
*
|
||||
*/
|
||||
class GetValueFunction {
|
||||
|
||||
/**
|
||||
* 取参数的绝对值
|
||||
* @param obj 要确定绝对值的参数
|
||||
* @return 参数的绝对值
|
||||
*/
|
||||
@Function(name="取参数的绝对值",tip="获取参数的绝对值, 参数:{Number}num 数值,返回值:{Number}参数的绝对值")
|
||||
static Number abs(Number num){
|
||||
return Math.abs(num);
|
||||
}
|
||||
/**
|
||||
* 大于num的最小整数
|
||||
* @param num 数值(number)
|
||||
* @return 最小(最接近负无穷大)浮点值,该值大于或等于该参数,并且等于某个整数。
|
||||
*/
|
||||
@Function(name="大于num的最小整数",tip="获取大于num的最小整数,参数:{Number}num 数值,返回值:{double}")
|
||||
static double ceil(Number num){
|
||||
return Math.ceil(num)
|
||||
}
|
||||
|
||||
/**
|
||||
* 小于num的最大整数
|
||||
* @param num 数值
|
||||
* @return 最大(最接近正无穷大)浮点值,该值小于等于该参数,并等于某个整数。
|
||||
*/
|
||||
@Function(name="小于num的最大整数",tip="获取小于num的最大整数,参数:{double}num 数值,返回值:{double}")
|
||||
static double floor(double num){
|
||||
return Math.floor(num);
|
||||
}
|
||||
|
||||
@Function(name="比较两个时间的大小",tip="比较两个时间的大小,参数:{DateTime}startTime 开始时间,{DateTime}endTime 结束时间,返回值:{boolean} 开始时间早于结束时间返回true,否则返回false")
|
||||
static boolean compareDateTime(DateTime startTime,DateTime endTime){
|
||||
|
||||
return startTime?.isBefore(endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加小时
|
||||
* @param dateTime 时间
|
||||
* @param hours 增加的小时数
|
||||
* @return 增加小时后的时间
|
||||
*/
|
||||
@Function(name="增加小时",tip="所在时间增加小时数,参数:{DateTime}dateTime 时间、 {int}hours 增加的小时数,返回值:{DateTime}增加小时后的时间")
|
||||
static DateTime addHours(DateTime dateTime, int hours){
|
||||
return dateTime?.plusHours(hours);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加日
|
||||
* @param dateTime 时间
|
||||
* @param date 增加的天数
|
||||
* @return 增加天数后的时间
|
||||
*/
|
||||
@Function(name="增加日",tip="所在时间增加天数,参数:{DateTime}dateTime 时间 、{int}days 增加的天数,返回值:{DateTime}增加天数后的时间")
|
||||
static DateTime addDays(DateTime dateTime, int days){
|
||||
return dateTime?.plusDays(days);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加月份
|
||||
* @param dateTime 时间
|
||||
* @param month 增加的月数
|
||||
* @return 增加月份后的时间
|
||||
*/
|
||||
@Function(name="增加月",tip="所在时间增加月数,参数:{DateTime}dateTime 时间、 {int} months 增加的月数,返回值:{DateTime}增加月份后的时间")
|
||||
static DateTime addMonths(DateTime dateTime, int months){
|
||||
return dateTime?.plusMonths(months);
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接字符串
|
||||
* @param str1
|
||||
* @param str2
|
||||
* @return 将str2串联到str1 String 结尾的 String
|
||||
*/
|
||||
@Function(name="连接字符串",tip="连接两个字符串,参数:{String} str1 、 {String} str2 ,返回值:{String}str2串联到str1的结尾的字符串")
|
||||
static String concat(String str1,String str2){
|
||||
return str1?.concat(str2)
|
||||
}
|
||||
|
||||
/**
|
||||
* 日期格式化
|
||||
* @param dateTime 日期(时间)
|
||||
* @param pattern 格式(默认:yyyy-MM-dd)
|
||||
* @return String 格式化后的时间字符串
|
||||
*/
|
||||
@Function(name="日期格式化",tip="格式化日期,参数:{DateTime}dateTime 日期,{String} pattern 格式,返回值:{String} 格式化后的时间字符串")
|
||||
static String dateFormate(DateTime dateTime, String pattern){
|
||||
return dateTime?.toString(StringUtil.isEmpty(pattern)? "yyyy-MM-dd":pattern)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所在时间是星期几
|
||||
* @param dateTime 时间
|
||||
* @return 星期
|
||||
*/
|
||||
@Function(name="星期",tip="获取所在时间是星期几,参数:{DateTime}dateTime 时间,返回值:{String}星期")
|
||||
static String dayOFWeek(DateTime dateTime){
|
||||
if(dateTime ==null)
|
||||
return null
|
||||
int day = dateTime?.getDayOfWeek()
|
||||
String showWeek = "";
|
||||
switch (day) {
|
||||
case 1:
|
||||
showWeek = "星期一";
|
||||
break;
|
||||
case 2:
|
||||
showWeek = "星期二";
|
||||
break;
|
||||
case 3:
|
||||
showWeek = "星期三";
|
||||
break;
|
||||
case 4:
|
||||
showWeek = "星期四";
|
||||
break;
|
||||
case 5:
|
||||
showWeek = "星期五";
|
||||
break;
|
||||
case 6:
|
||||
showWeek = "星期六";
|
||||
break;
|
||||
default:
|
||||
showWeek = "星期日";
|
||||
break;
|
||||
}
|
||||
return showWeek
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的日期(天)
|
||||
*/
|
||||
@Function(name="获取日",tip="获取所在时间的日,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的日")
|
||||
static int dayOf(DateTime dateTime){
|
||||
return dateTime?.getDayOfMonth()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小时
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的小时数
|
||||
*/
|
||||
@Function(name="获取小时",tip="获取小时,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的小时")
|
||||
static int hourOf(DateTime dateTime){
|
||||
return dateTime?.getHourOfDay()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分钟
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的分钟数
|
||||
*/
|
||||
@Function(name="获取分钟",tip="获取分钟,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的分钟")
|
||||
static int minuteOf(DateTime dateTime){
|
||||
return dateTime?.getMinuteOfHour()
|
||||
}
|
||||
/**
|
||||
* 获取秒
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的秒数
|
||||
*/
|
||||
@Function(name="获取秒",tip="获取秒,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的秒")
|
||||
static int secondOf(DateTime dateTime){
|
||||
return dateTime?.getSecondOfMinute()
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月份
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的月份
|
||||
*/
|
||||
@Function(name="获取月份",tip="获取月份,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的月份")
|
||||
static int monthOF(DateTime dateTime){
|
||||
return dateTime?.getMonthOfYear()
|
||||
}
|
||||
/**
|
||||
* 获取年
|
||||
* @param dateTime 时间
|
||||
* @return 所在时间的年份
|
||||
*/
|
||||
@Function(name="获取年份",tip="获取年份,参数:{DateTime}dateTime 时间,返回值:{int}所在时间的年份")
|
||||
static int yearOf(DateTime dateTime){
|
||||
return dateTime?.getYear()
|
||||
}
|
||||
|
||||
/**
|
||||
* 所在月第一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在月第一天",tip="所在月第一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在月第一天")
|
||||
static DateTime firstDateOfMonth(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
return new DateTime(dateTime?.getYear(), dateTime?.getMonthOfYear(), 1, 0, 0,0);
|
||||
}
|
||||
/**
|
||||
* 所在星期第一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在星期第一天",tip="所在星期第一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在星期第一天")
|
||||
static DateTime firstdateofweek(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
int day = dateTime?.getDayOfWeek()
|
||||
return addDays(dateTime, 1 - day)
|
||||
}
|
||||
|
||||
/**
|
||||
* 所在年第一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在年第一天",tip="所在年第一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在年第一天")
|
||||
static DateTime firstDateOfYear(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
// int days = 1- dateTime?.getDayOfYear()
|
||||
// return addDays(dateTime, days)
|
||||
DateTime dt = new DateTime(dateTime?.getYear(), 1, 1, 0, 0,0);
|
||||
return dt
|
||||
}
|
||||
/**
|
||||
* 所在月最后一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在月最后一天",tip="所在月最后一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在月最后一天")
|
||||
static DateTime lastDateOfMonth(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
DateTime dt = firstDateOfMonth(dateTime)//所在月第一天
|
||||
dt = addMonths(dt, 1)//所在月的下一个月第一天
|
||||
return addDays(dt, -1)
|
||||
}
|
||||
/**
|
||||
* 所在星期最后一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在星期最后一天",tip="所在星期最后一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在星期最后一天")
|
||||
static DateTime lastdateofweek(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
int day = dateTime?.getDayOfWeek()
|
||||
return addDays(dateTime, 7 - day)
|
||||
}
|
||||
/**
|
||||
* 所在年最后一天
|
||||
* @param dateTime 时间
|
||||
* @return
|
||||
*/
|
||||
@Function(name="所在年最后一天",tip="所在年最后一天,参数:{DateTime}dateTime 时间,返回值:{DateTime}所在年最后一天")
|
||||
static DateTime lastDateOfYear(DateTime dateTime){
|
||||
if(dateTime == null)
|
||||
return null
|
||||
return new DateTime(dateTime?.getYear(), 12, 31, 0, 0,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 高精度数值格式化
|
||||
* @param obj 数值
|
||||
* @param pattern 格式(例如:"###,##0.00")
|
||||
* @return {String}格式化后的值
|
||||
*/
|
||||
@Function(name="高精度数值格式化",tip="高精度数值格式化,参数:{Object} obj 数值、{String} format 格式,返回值:{String} 格式化后的字符串")
|
||||
static String decimalFormat(Object obj,String format){
|
||||
if(obj == null || obj.toString().length() == 0)
|
||||
return "";
|
||||
DecimalFormat decimalFormat = new DecimalFormat(format);
|
||||
return format.format(obj);
|
||||
}
|
||||
/**
|
||||
* 是否有指定后缀
|
||||
* @param str 字符串
|
||||
* @param suffix 后缀
|
||||
* @return 如果参数suffix表示的字符序列是str对象表示的字符序列的后缀,则返回 true;否则返回 false。
|
||||
*/
|
||||
@Function(name="是否有指定后缀",tip="是否有指定后缀,参数:{String} str 字符串、{String} suffix 后缀,返回值:{boolean} 如果参数suffix表示的字符序列是str对象表示的字符序列的后缀,则返回 true;否则返回 false。")
|
||||
static boolean endsWith(String str,String suffix){
|
||||
return str?.endsWith(suffix)
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串格式化
|
||||
* @param str 字符串
|
||||
* @param format 格式
|
||||
* @return {String}格式化字符串
|
||||
*/
|
||||
@Function(name="字符串格式化",tip="字符串格式化,参数:{String} str 字符串、{String} format 格式,返回值:{String}一个格式化字符串")
|
||||
static String format(String str,String format){
|
||||
return str?.format(format, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* 小写
|
||||
* @param str 字符串
|
||||
* @return {String}小写字符串
|
||||
*/
|
||||
@Function(name="小写",tip="将字符串转换为小写,参数:{String} str 字符串,返回值:{String} 小写字符串")
|
||||
static String lower(String str){
|
||||
return str?.toLowerCase()
|
||||
}
|
||||
|
||||
/**
|
||||
* 大写
|
||||
* @param str 字符串
|
||||
* @return {String}大写字符串
|
||||
*/
|
||||
@Function(name="大写",tip="将字符串转换为大写,参数:{String} str 字符串,返回值:{String} 大写字符串")
|
||||
static String upper(String str){
|
||||
return str?.toUpperCase()
|
||||
}
|
||||
/**
|
||||
* 去掉左边空白字符
|
||||
* @param str 字符串
|
||||
* @return
|
||||
*/
|
||||
@Function(name="去掉左边空白字符",tip="将字符串左边空白字符去掉,参数:{String} str 字符串,返回值:{String} 去掉左边空白字符的字符串")
|
||||
static String ltrim(String str){
|
||||
int i = 0;
|
||||
while (i < str?.length() && Character.isWhitespace(str?.charAt(i))) {
|
||||
i++;
|
||||
}
|
||||
return str?.substring(i);
|
||||
}
|
||||
/**
|
||||
* 去掉右边空格
|
||||
* @param str 字符串
|
||||
* @return
|
||||
*/
|
||||
@Function(name="去掉右边空白字符",tip="将字符串右边空白字符去掉,参数:{String} str 字符串,返回值:{String} 去掉右边空白字符的字符串")
|
||||
static String rtrim(String str){
|
||||
if(str?.length() != null){
|
||||
int i = str?.length()-1;
|
||||
while (i >= 0 && Character.isWhitespace(str?.charAt(i))) {
|
||||
i--;
|
||||
}
|
||||
return str?.substring(0,i+1);
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉两边空格
|
||||
* @param str 字符串
|
||||
* @return
|
||||
*/
|
||||
@Function(name="去掉两边空格",tip="将字符串两边空格去除,参数:{String} str 字符串,返回值:{String} 去掉两边空格的字符串")
|
||||
static String trim(String str){
|
||||
return str?.trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建list
|
||||
* @return list
|
||||
*/
|
||||
@Function(name="创建list",tip="创建list,参数:{Object} obj ,返回值:List")
|
||||
static List list(Object obj){
|
||||
//FIXME: 是否符合要求
|
||||
if(obj == null){
|
||||
return new ArrayList()
|
||||
}else if(obj instanceof List){
|
||||
return obj
|
||||
}else if(obj instanceof Object[]){
|
||||
List list = new ArrayList(obj.size());
|
||||
for(i in 0..(obj.size()-1)){
|
||||
list.add(obj[i])
|
||||
}
|
||||
return list
|
||||
}else if(obj instanceof Iterable){
|
||||
return new ArrayList(obj);
|
||||
}else{
|
||||
List list = new ArrayList()
|
||||
list.add(obj)
|
||||
return list
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取后缀名
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
// @Function(name="",tip="")
|
||||
static String extOFFile(String filePath){
|
||||
//FIXME: 待完善
|
||||
if(filePath?.length() >0){
|
||||
int dot = filePath?.lastIndexOf(".")
|
||||
if(dot > -1 && (dot < (filePath.length() - 1)))
|
||||
return filePath?.substring(dot+1);
|
||||
}
|
||||
return filePath
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取不含扩展名的文件名
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
// @Function(name="",tip="")
|
||||
static String nameNOExtOfFile(String filePath){
|
||||
//FIXME: 待完善
|
||||
//TODO 长度验证
|
||||
String realName = filePath?.replaceAll("\\\\", "/")
|
||||
String extension = realName.substring(realName?.lastIndexOf("/") + 1, realName?.lastIndexOf("."))
|
||||
return extension
|
||||
}
|
||||
/**
|
||||
* 获取文件名
|
||||
* @param filePath
|
||||
* @return
|
||||
*/
|
||||
// @Function(name="",tip="")
|
||||
static String nameOFFile(String filePath){
|
||||
//FIXME: 待完善
|
||||
}
|
||||
/**
|
||||
* 获取路径
|
||||
* @param file 文件
|
||||
* @return String 文件路径
|
||||
*/
|
||||
// @Function(name="",tip="")
|
||||
static String pathOfFile(File file){
|
||||
//FIXME: 待完善
|
||||
}
|
||||
|
||||
/**
|
||||
* 开方
|
||||
* @param a 底数
|
||||
* @param b 指数
|
||||
* @return double 第一个参数的第二个参数次幂的值。
|
||||
*/
|
||||
@Function(name="开方",tip="开方,参数:{double} a 底数、{double} b 指数,返回值:{double}第一个参数的第二个参数次幂的值")
|
||||
static double power(double a,double b){
|
||||
return Math.pow(a, b)
|
||||
}
|
||||
/**
|
||||
* 余数
|
||||
* @param a 被除数
|
||||
* @param b 除数
|
||||
* @return a除以 b 的余数
|
||||
*/
|
||||
@Function(name="余数",tip="余数,参数:{double} a 被除数、{double} b 除数,返回值:{double}a除以 b 的余数")
|
||||
static double remainder(double a,double b){
|
||||
return Math.IEEEremainder(a, b);
|
||||
}
|
||||
/**
|
||||
* 替换字串
|
||||
* @param str
|
||||
* @param regex 用来匹配此字符串的正则表达式
|
||||
* @param replacement 用来替换每个匹配项的字符串
|
||||
* @return
|
||||
*/
|
||||
@Function(name="替换字串",tip="替换所有匹配的字串,参数:{String} str 要替换的字符串、{String} regex 用来匹配此字符串的正则表达式、{String} replacement 用来替换每个匹配项的字符串,返回值:{String}替换后的字符串 ")
|
||||
static String replaceAll(String str,String regex,String replacement){
|
||||
return str?.replaceAll(regex, replacement)
|
||||
}
|
||||
/**
|
||||
* 替换第一次出现的字串
|
||||
* @param str
|
||||
* @param regex
|
||||
* @param replacement
|
||||
* @return
|
||||
*/
|
||||
@Function(name="替换第一次出现的字串",tip="替换第一次出现的字串,参数:{String} str 要替换的字符串、{String} regex 用来匹配此字符串的正则表达式、{String} replacement 用来替换每个匹配项的字符串,返回值:{String}替换后的字符串 ")
|
||||
static String replaceFirst(String str,String regex,String replacement){
|
||||
return str?.replaceFirst(regex, replacement)
|
||||
}
|
||||
/**
|
||||
* 四舍五入
|
||||
* @param obj
|
||||
* @return 舍入为最接近的 obj值的参数值
|
||||
*/
|
||||
@Function(name="四舍五入",tip="参数四舍五入,参数:{Object} obj,返回值:舍入为最接近的 obj值的参数值")
|
||||
static Object round(Object obj){
|
||||
return Math.round(obj)
|
||||
}
|
||||
/**
|
||||
* 平方根
|
||||
* @param a 一个值
|
||||
* @return a 的正平方根。如果参数为 NaN 或小于 0,那么结果为 NaN
|
||||
*/
|
||||
@Function(name="平方根",tip="平方根,参数:{double} a,返回值:{double}a 的正平方根")
|
||||
static double sqrt(double a){
|
||||
return Math.sqrt(a)
|
||||
}
|
||||
/**
|
||||
* 是否有指定前缀
|
||||
* @param str 字符串
|
||||
* @param prefix前缀
|
||||
* @return 如果参数prefix表示的字符序列是字符串str表示的字符序列的前缀,则返回 true;否则返回 false。
|
||||
*/
|
||||
@Function(name="是否有指定前缀",tip="是否有指定前缀,参数:{String}str 字符串、{String}prefix 前缀,返回值:{boolean} 如果参数prefix表示的字符序列是字符串str表示的字符序列的前缀,则返回 true;否则返回 false")
|
||||
static boolean startsWith(String str,String prefix){
|
||||
return str?.startsWith(prefix)
|
||||
}
|
||||
/**
|
||||
* 字符长度
|
||||
* @param str 字符串
|
||||
* @return 字符长度
|
||||
*/
|
||||
@Function(name="字符长度",tip="字符长度,参数:{String}str 字符串,返回值:{int} 字符串长度")
|
||||
static int stringLength(String str){
|
||||
return str?.length()
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找字串的位置
|
||||
* @param str1
|
||||
* @param str2
|
||||
* @return 返回str2子字符串在str1字符串中第一次出现处的索引
|
||||
*/
|
||||
@Function(name="查找字串的位置",tip="查找字串的位置,参数:{String}str1、{String}str2,返回值:{int}返回str2子字符串在str1字符串中第一次出现处的索引")
|
||||
static int stringPosition(String str1,String str2){
|
||||
return str1?.indexOf(str2)
|
||||
}
|
||||
/**
|
||||
* 截取字串
|
||||
* @param str
|
||||
* @param beginIndexbeginIndex起始索引(包括)
|
||||
* @param endIndex结束索引(不包括)
|
||||
* @return 指定的子字符串
|
||||
*/
|
||||
@Function(name="截取字串",tip="截取字串,参数:{String}str 字符串、{int} beginIndex起始索引(包括)、{int} endIndex结束索引(不包括),返回值:{String}指定的子字符串")
|
||||
static String subString(String str,int beginIndex,int endIndex){
|
||||
return str?.substring(beginIndex, endIndex)
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为日期
|
||||
* @param date 时间字符串
|
||||
* @param pattern 转换前的日期格式
|
||||
* @return
|
||||
*/
|
||||
@Function(name="转换为日期",tip="将字符串转换为日期,参数:{String} date 日期字符串(yyyy-MM-dd),{String} pattern 格式(yyyy-MM-dd),返回值:{DateTime} 转换后的日期")
|
||||
static DateTime toDate(String date,String pattern){
|
||||
return toDatePattern(date, pattern)
|
||||
}
|
||||
/**
|
||||
* 转换为时间
|
||||
* @param date 时间字符串
|
||||
* @param pattern 转换前的日期格式
|
||||
* @return
|
||||
*/
|
||||
@Function(name="转换为时间",tip="将字符串转换为时间,参数:{String} date 日期字符串(yyyy-MM-dd HH:mm:ss),{String} pattern 格式(yyyy-MM-dd HH:mm:ss),返回值:{DateTime} 转换后的时间")
|
||||
static DateTime toDateTime(String date,String pattern){
|
||||
return toDatePattern(date, pattern)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转换为时间格式
|
||||
* @param date 时间字符串
|
||||
* @param pattern (原时间字符串的)格式
|
||||
* @return DateTime 格式化后的时间
|
||||
*/
|
||||
static DateTime toDatePattern(String date,String pattern){
|
||||
DateTimeFormatter format = DateTimeFormat.forPattern(pattern);
|
||||
return DateTime.parse(date, format)
|
||||
}
|
||||
|
||||
@Function(name="转换为BigDecimal类型",tip="转换为BigDecimal类型,参数:num 数值,返回值:{BigDecimal}")
|
||||
static BigDecimal toDecimal(Number num){
|
||||
if(num == null){
|
||||
return null
|
||||
}else if( num instanceof BigDecimal){
|
||||
return num
|
||||
}else{
|
||||
return new BigDecimal(num)
|
||||
}
|
||||
}
|
||||
@Function(name="转换为Integer类型",tip="转换为Integer类型,参数:num 数值,返回值:{Integer}")
|
||||
static Integer toInteger(Number num){
|
||||
if(num == null){
|
||||
return null
|
||||
}else if( num instanceof Integer){
|
||||
return num
|
||||
}else{
|
||||
return Integer.valueOf(num.intValue())
|
||||
}
|
||||
}
|
||||
|
||||
@Function(name="转为String类型",tip="转为String类型参数:obj 数值,返回值:{String}")
|
||||
static String toString(Object obj){
|
||||
return obj?.toString()
|
||||
}
|
||||
|
||||
private static final String digit_0 = "零壹贰叁肆伍陆柒捌玖";
|
||||
private static final String digit_1 = "零一二三四五六七八九";
|
||||
private static final String[] digit_2 = ["", "十", "百", "千"];
|
||||
private static final String[] digit_3 = ["", "拾", "佰", "仟"];
|
||||
private static final String[] digit_4 = ["", "万", "亿", "万亿", "亿亿"];
|
||||
|
||||
|
||||
/**
|
||||
* 将指定的数字转换成人民币数字
|
||||
* @param num 数值
|
||||
* @return {String}大写金额
|
||||
*/
|
||||
@Function(name="将指定的数字转换成人民币数字",tip="参数:{Number}num 数值,返回值:{String}大写金额")
|
||||
static String toChineseMoney(Number num){
|
||||
if(num == null){
|
||||
return null
|
||||
}
|
||||
return changeNumberRMB(num)
|
||||
}
|
||||
/**
|
||||
* 转换为中文数字
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
@Function(name="转换为中文数字",tip="转换为中文数字,参数:{String}num 数值,返回值:{String}中文数字")
|
||||
static String toChineseNumber(String num){
|
||||
if(StringUtil.isEmpty(num))
|
||||
return null
|
||||
return changeDigit(num,false)
|
||||
}
|
||||
|
||||
/**
|
||||
* Description: 数字转化成整数
|
||||
*
|
||||
* @param str 数字字符串
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
static String changeDigit(String str, boolean bo) {
|
||||
StringBuffer strbu = new StringBuffer();
|
||||
int dou = str.indexOf(".");
|
||||
// :判断是否为小数还是整数,长度小于零为整数
|
||||
if (dou < 0) {
|
||||
dou = str.length();
|
||||
}
|
||||
// :获取整数部分
|
||||
String inter = str.substring(0, dou);
|
||||
strbu.append(changeInteger(Long.parseLong(inter), bo));
|
||||
// :处理小数部分
|
||||
if (dou != str.length()) {
|
||||
strbu.append("点");
|
||||
// :获取小数点后所有数
|
||||
String xh = str.substring(dou + 1);
|
||||
for (int i = 0; i < xh.length(); i++) {
|
||||
if (bo) {
|
||||
strbu.append(digit_0.charAt(Integer.parseInt(xh.substring(
|
||||
i, i + 1))));
|
||||
} else {
|
||||
strbu.append(digit_1.charAt(Integer.parseInt(xh.substring(
|
||||
i, i + 1))));
|
||||
}
|
||||
}
|
||||
}
|
||||
String strs = strbu.toString();
|
||||
// :处理特殊情况,可能不全
|
||||
if (strs.startsWith("零")) {
|
||||
strs = strs.substring(1);
|
||||
}
|
||||
if (strs.startsWith("一十")) {
|
||||
strs = strs.substring(1);
|
||||
}
|
||||
while (strs.endsWith("零")) {
|
||||
strs = strs.substring(0, strs.length() - 1);
|
||||
}
|
||||
if (strs.startsWith("点")) {
|
||||
strs = "零" + strs;
|
||||
}
|
||||
if (strs.endsWith("点")) {
|
||||
strs = strs.substring(0, strs.length() - 1);
|
||||
}
|
||||
return strs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 位数小于4时,调用处理数据
|
||||
*
|
||||
* @param str
|
||||
* @param bo :true人民币(大写),false:数字大写
|
||||
* @return
|
||||
*/
|
||||
static String readNumber(String str, boolean bo) {
|
||||
StringBuffer strbu = new StringBuffer();
|
||||
if (str.length() != 4) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < 4; i++) {
|
||||
char ch = str.charAt(i);
|
||||
if (ch == '0' && i > 1 && str.charAt(i - 1) == '0') {
|
||||
continue;
|
||||
}
|
||||
if (ch != '0' && i > 1 && str.charAt(i - 1) == '0') {
|
||||
strbu.append('零');
|
||||
}
|
||||
if (ch != '0') {
|
||||
if (bo) {
|
||||
strbu.append(digit_0.charAt(ch - 48));
|
||||
strbu.append(digit_3[4 - i - 1]);
|
||||
} else {
|
||||
strbu.append(digit_1.charAt(ch - 48));
|
||||
strbu.append(digit_2[4 - i - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return strbu.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 整数部分转换大写
|
||||
* @param lon
|
||||
* @param bo
|
||||
* @return
|
||||
*/
|
||||
static String changeInteger(long lon, boolean bo) {
|
||||
StringBuffer strbu = new StringBuffer();
|
||||
// :增加3位数,为了完成大写转换
|
||||
String strN = "000" + lon;
|
||||
int strN_L = strN.length() / 4;
|
||||
// :根据不同的位数长度,消除strN"0"的个数
|
||||
strN = strN.substring(strN.length() - strN_L * 4);
|
||||
for (int i = 0; i < strN_L; i++) {
|
||||
String s1 = strN.substring(i * 4, i * 4 + 4);
|
||||
String s2 = readNumber(s1, bo);
|
||||
strbu.append(s2);
|
||||
if (s2.length() != 0) {
|
||||
strbu.append(digit_4[strN_L - i - 1]);
|
||||
}
|
||||
}
|
||||
String s = new String(strbu);
|
||||
if (s.length() != 0 && s.startsWith("零"))
|
||||
s = s.substring(1);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 人名币输出格式(大写)
|
||||
*
|
||||
* @param rmb 数值
|
||||
* @return
|
||||
*/
|
||||
static String changeNumberRMB(Number rmb) {
|
||||
DecimalFormat df = new DecimalFormat("#.#");
|
||||
df.setMaximumFractionDigits(3);
|
||||
String strRMB = df.format(rmb);
|
||||
// :true人民币大写,并返回数据
|
||||
strRMB = changeDigit(strRMB, true);
|
||||
if (strRMB.indexOf("点") >= 0) {
|
||||
strRMB = strRMB.replaceAll("点", "圆");
|
||||
String str1 = strRMB.substring(0, strRMB.indexOf("圆") + 1);
|
||||
String str2 = strRMB.substring(strRMB.indexOf("圆") + 1);
|
||||
if(str2.length() == 3){
|
||||
strRMB = str1 + str2.charAt(0) + "角" + str2.charAt(1) + "分" + str2.charAt(2) + "厘";
|
||||
}else if(str2.length() ==2){
|
||||
strRMB = str1 + str2.charAt(0) + "角" + str2.charAt(1) + "分";
|
||||
}else{
|
||||
strRMB = str1 + str2.charAt(0) + "角";
|
||||
}
|
||||
|
||||
} else {
|
||||
strRMB = strRMB + "圆整";
|
||||
}
|
||||
return strRMB;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.dsasp.server.core.script.secure
|
||||
|
||||
import org.codehaus.groovy.ast.expr.ClassExpression
|
||||
import org.codehaus.groovy.ast.expr.Expression
|
||||
import org.codehaus.groovy.ast.expr.MethodCallExpression
|
||||
import org.codehaus.groovy.control.customizers.SecureASTCustomizer
|
||||
|
||||
class MethodCallExpressionChecker implements SecureASTCustomizer.ExpressionChecker{
|
||||
boolean isAuthorized(Expression expression) {
|
||||
if (expression instanceof MethodCallExpression) {
|
||||
if (expression.objectExpression instanceof ClassExpression) {
|
||||
if (expression.objectExpression.type.name==System.name) {
|
||||
if (expression.methodAsString=='exit') return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.dsasp.server.core.script.secure;
|
||||
|
||||
import javax.script.ScriptEngine
|
||||
|
||||
import org.codehaus.groovy.control.CompilerConfiguration
|
||||
import org.codehaus.groovy.control.customizers.ImportCustomizer
|
||||
import org.codehaus.groovy.control.customizers.SecureASTCustomizer
|
||||
import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory
|
||||
import org.codehaus.groovy.jsr223.GroovyScriptEngineImpl
|
||||
|
||||
|
||||
public class SecureGroovyScriptEngineFactory extends GroovyScriptEngineFactory{
|
||||
|
||||
def IMPORTSWHITELIST = [
|
||||
"com.vaadin.data.fieldgroup.FieldGroup",
|
||||
"com.vaadin.shared.ui.datefield.Resolution",
|
||||
"com.dsasp.viewframework.SingleSelectField",
|
||||
"com.dsasp.viewframework.MultiSelectField",
|
||||
"com.dsasp.viewframework.ExComboBox",
|
||||
"com.dsasp.client.viewframework.listener.TableItemSelectedListener",
|
||||
"com.dsasp.client.viewframework.listener.ConfirmDialogListener",
|
||||
"com.dsasp.client.viewframework.template.form.FormEngineUtil",
|
||||
"com.dsasp.server.common.dataDic.bean.Enumerate",
|
||||
"com.dsasp.server.common.exception.ValidationException",
|
||||
"com.dsasp.server.common.util.UserSession",
|
||||
"com.dsasp.server.common.dataDic.bean.CustomSearchConditional",
|
||||
"com.dsasp.server.dataDic.bean.GeneralPO",
|
||||
"com.dsasp.server.common.workflow.service.ProcessCoreService",
|
||||
"com.dsasp.client.viewframework.template.util.Console",
|
||||
"com.dsasp.server.privilege.service.ServicePrivilege",
|
||||
"com.dsasp.client.viewframework.template.editform.EditFormTemplateComponent",
|
||||
"com.dsasp.client.viewframework.component.MainComponent",
|
||||
"com.dsasp.server.app.convert.PageFieldUtil",
|
||||
"com.dsasp.server.app.model.FormField",
|
||||
"com.dsasp.server.app.model.WfApprovPage",
|
||||
"com.dsasp.client.viewframework.script.ViewScript",
|
||||
"com.dsasp.viewframework.browserframe.ExBrowserFrame"
|
||||
];
|
||||
|
||||
def STARIMPORTSWHITELIST = [
|
||||
"com.dsasp.client.viewframework.util",
|
||||
"com.dsasp.client.viewframework.template.util",
|
||||
"com.dsasp.server.common.core",
|
||||
"com.dsasp.server.common.core.service",
|
||||
"com.dsasp.server.common.dataDic.bean",
|
||||
"com.dsasp.server.common.dataDic.service",
|
||||
"com.dsasp.server.common.email.bean",
|
||||
"com.dsasp.server.common.email.service",
|
||||
"com.dsasp.server.common.exception",
|
||||
"com.dsasp.server.common.file",
|
||||
"com.dsasp.server.common.file.service",
|
||||
"com.dsasp.server.common.form.bean",
|
||||
"com.dsasp.server.common.form.service",
|
||||
"com.dsasp.server.common.function",
|
||||
"com.dsasp.server.common.log.bean",
|
||||
"com.dsasp.server.common.log.service",
|
||||
"com.dsasp.server.common.message.bean",
|
||||
"com.dsasp.server.common.message.service",
|
||||
"com.dsasp.server.common.organization.bean",
|
||||
"com.dsasp.server.common.organization.service",
|
||||
"com.dsasp.server.common.privilege.bean",
|
||||
"com.dsasp.server.common.privilege.service",
|
||||
"com.dsasp.server.common.sms.service",
|
||||
"com.dsasp.server.common.user.bean",
|
||||
"com.dsasp.server.common.user.service",
|
||||
"com.dsasp.server.common.util",
|
||||
"com.dsasp.server.common.viewframework.bean",
|
||||
"com.dsasp.server.common.viewframework.service",
|
||||
"com.dsasp.server.common.workcalendar.service",
|
||||
"com.dsasp.server.common.workflow.bean",
|
||||
"com.dsasp.server.common.workflow.service",
|
||||
"com.vaadin.data",
|
||||
"com.vaadin.ui",
|
||||
"com.vaadin.server",
|
||||
"org.joda.time",
|
||||
"client.groovy",
|
||||
"com.dsasp.viewframework" ,
|
||||
"com.dsasp.pm.process.client",
|
||||
"com.dsasp.client.dataimport.util",
|
||||
"groovy.json"
|
||||
]
|
||||
|
||||
def DEFAULTIMPORTSLIST = [
|
||||
"com.dsasp.server.common.dataDic.bean.GeneralPOJO",
|
||||
"com.dsasp.server.common.dataDic.bean.CustomSearchConditional",
|
||||
"com.dsasp.server.common.dataDic.service.POJOCRUDService",
|
||||
"com.dsasp.server.common.util.StringUtil",
|
||||
"com.dsasp.server.common.function.GetServicesFunction",
|
||||
"com.dsasp.server.common.function.GetDefaultValueFunction",
|
||||
"com.dsasp.server.common.function.GetValueFunction",
|
||||
"com.dsasp.client.viewframework.template.util.Console",
|
||||
"client.groovy.TestService",
|
||||
"com.dsasp.client.viewframework.component.MainComponent"
|
||||
]
|
||||
|
||||
def DEFAULTSTARIMPORTSLIST=[
|
||||
"org.joda.time"
|
||||
]
|
||||
|
||||
GroovyClassLoader loader
|
||||
|
||||
public SecureGroovyScriptEngineFactory(){
|
||||
ImportCustomizer imports = new ImportCustomizer();
|
||||
CompilerConfiguration cc = new CompilerConfiguration();
|
||||
SecureASTCustomizer secure = new SecureASTCustomizer();
|
||||
secure.with{
|
||||
importsWhitelist = IMPORTSWHITELIST + DEFAULTIMPORTSLIST
|
||||
//importsBlacklist = []
|
||||
starImportsWhitelist = STARIMPORTSWHITELIST + DEFAULTSTARIMPORTSLIST
|
||||
//starImportsBlacklist = []
|
||||
|
||||
//staticImportsWhitelist=[
|
||||
//"com.vaadin.data.Property.ValueChangeEvent",
|
||||
//"com.vaadin.ui.Button.ClickEvent"
|
||||
//]
|
||||
}
|
||||
DEFAULTIMPORTSLIST?.each {
|
||||
imports.addImport(it);
|
||||
}
|
||||
DEFAULTSTARIMPORTSLIST?.each {
|
||||
imports.addStarImport(it);
|
||||
}
|
||||
secure.addExpressionCheckers(new MethodCallExpressionChecker());
|
||||
cc.addCompilationCustomizers(imports,secure);
|
||||
loader = new GroovyClassLoader(getParentLoader(), cc);
|
||||
}
|
||||
|
||||
public ScriptEngine getScriptEngine() {
|
||||
GroovyScriptEngineImpl gse = new GroovyScriptEngineImpl(loader);
|
||||
return gse;
|
||||
}
|
||||
|
||||
private ClassLoader getParentLoader() {
|
||||
// check whether thread context loader can "see" Groovy Script class
|
||||
ClassLoader ctxtLoader = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
Class c = ctxtLoader.loadClass(Script.class.getName());
|
||||
if (c == Script.class) {
|
||||
return ctxtLoader;
|
||||
}
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
/* ignore */
|
||||
}
|
||||
// exception was thrown or we get wrong class
|
||||
return Script.class.getClassLoader();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.dsasp.server.common.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.dsasp.server.common.dataDic.bean.CCache;
|
||||
import com.dsasp.server.common.dataDic.bean.CustomSearchConditional;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.function.GetServicesFunction;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
public class ControlBean {
|
||||
|
||||
private static CCache<String, List<GeneralPOJO>> s_cache = new CCache<String, List<GeneralPOJO>>("Controls", 400);
|
||||
|
||||
//按钮控制type=1;服务控制type = 2
|
||||
public static List<GeneralPOJO> getControl(String id,Integer type){
|
||||
|
||||
List<GeneralPOJO> result = s_cache.get(id);
|
||||
Map<String, Object> tMap = new HashMap<String, Object>();
|
||||
Map<String, Object> listSelect = new HashMap<String, Object>();
|
||||
List<GeneralPOJO> results = new ArrayList<GeneralPOJO>();
|
||||
|
||||
if(result == null || result.size() < 1){
|
||||
if(type == 1){
|
||||
tMap = new HashMap<String,Object>();
|
||||
tMap.put("TEMPLATEID", new CustomSearchConditional(" TEMPLATEID = '" + id + "'"));
|
||||
|
||||
listSelect = GetServicesFunction.listSelect(tMap, "SYS_TEMPLATECONTROL", UserSession.getAdmin());
|
||||
|
||||
if(listSelect != null){
|
||||
results = (List<GeneralPOJO>) listSelect.get("listresult");
|
||||
}
|
||||
|
||||
if(results != null && results.size() > 0){
|
||||
result = results;
|
||||
s_cache.put(id, result);
|
||||
}
|
||||
} else if(type == 2){
|
||||
tMap = new HashMap<String,Object>();
|
||||
tMap.put("SERVICEID", new CustomSearchConditional(" SERVICEID = '" + id + "'"));
|
||||
listSelect = GetServicesFunction.listSelect(tMap, "SYS_TEMPLATECONTROL_SERVICE", UserSession.getAdmin());
|
||||
if(listSelect != null){
|
||||
results = (List<GeneralPOJO>) listSelect.get("listresult");
|
||||
}
|
||||
if(results != null && results.size() > 0){
|
||||
result = results;
|
||||
s_cache.put(id, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void setChange(String id){
|
||||
s_cache.remove(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.dsasp.server.common.core;
|
||||
|
||||
|
||||
public interface FlowDefinition<T> {
|
||||
|
||||
public String getKey();
|
||||
|
||||
public String getFlow();
|
||||
|
||||
public T[] getInputs();
|
||||
|
||||
public T[] getOutputs();
|
||||
|
||||
public String getDisplayName();
|
||||
|
||||
public String getEntityId();
|
||||
|
||||
public boolean isControl();
|
||||
|
||||
public boolean isUpdateable();
|
||||
|
||||
// public String getSysFlowServiceId();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.dsasp.server.common.core.service;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* invoke the service flow, execute the service
|
||||
* @author wuqz
|
||||
*
|
||||
*/
|
||||
public interface FlowExcuteService {
|
||||
|
||||
public Object excute(Map map, Properties ctx, String flowId);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.dsasp.server.common.core.service;
|
||||
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.dsasp.server.common.core.FlowDefinition;
|
||||
|
||||
/**
|
||||
* definition the flow
|
||||
* @author wuqz
|
||||
*
|
||||
*/
|
||||
public interface FlowService {
|
||||
|
||||
// public FlowDefinition save(FlowDefinition flow);
|
||||
|
||||
public FlowDefinition saveOrUpdate(FlowDefinition flow, Properties ctx);
|
||||
|
||||
public FlowDefinition getFlowDefinition(String flowId);
|
||||
|
||||
/**
|
||||
* if entity flow is exist return true; otherwise return false;
|
||||
* @param entityId
|
||||
* @return
|
||||
*/
|
||||
public boolean isExistEntityFlow(String entityId);
|
||||
|
||||
//public List<FlowDefinition> getFlowDefinition(String sql, int start, int pageSize, String userId);
|
||||
|
||||
public boolean addDefaultFlowService(String entityId, Properties ctx);
|
||||
|
||||
public boolean isControlFlowService(String flowId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.dsasp.server.common.core.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dsasp.server.common.core.OriginServiceBean;
|
||||
|
||||
/**
|
||||
* start the bundle register the service
|
||||
* stop the bundle unregister the service
|
||||
* @author wuqz
|
||||
*
|
||||
*/
|
||||
public interface OriginServiceManager {
|
||||
|
||||
|
||||
public boolean register(Class beanClass);
|
||||
|
||||
public boolean unregister(Class beanClass);
|
||||
|
||||
public List<OriginServiceBean> findOriginService(String sql, int start, int pageSize);
|
||||
|
||||
public OriginServiceBean getOriginService(String beanName, String method);
|
||||
|
||||
public OriginServiceBean loadOriginServiceBean(String id);
|
||||
|
||||
public void saveRegister();
|
||||
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.dsasp.server.common.function;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植桩:原版为 Groovy 脚本函数库(currentYear/currentMonth 等默认值函数),
|
||||
* 仅被 FunctionUtil 以 class 引用注册。WS3 脚本验证时回迁完整实现。
|
||||
*/
|
||||
public class GetDefaultValueFunction {
|
||||
}
|
||||
@@ -1,12 +1,28 @@
|
||||
package com.dsasp.server.common.function;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.DataDicService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植桩:原版为 780 行 Groovy 脚本函数库(@Function 注解暴露给模板脚本)。
|
||||
* PoC 阶段只实现被 Java 代码直接调用的 findCount(POInfo.java:860);
|
||||
* 完整 Groovy 函数库在 WS3 脚本验证时以 groovy-jsr223 联合编译方式回迁。
|
||||
* 服务调用函数库(保包名/类名/签名替换类)。
|
||||
*
|
||||
* <p>framework 原版 {@code GetServicesFunction.groovy}(136 行 @Function 库)依赖
|
||||
* OrganizationService / UserFindService / WorkCalendarService / ProcessCoreService /
|
||||
* ChangeStatus / Enumerate 等横切服务——这些服务属 P2/P3 迁移面,P1 阶段尚未移植。
|
||||
* 按双层制「确需替换的类按 PoC 保包名/类名/签名纪律」(迁移手册 §3.1),本类保持
|
||||
* framework 同名同签名,仅实现 P1 服务流引擎执行路径实际调用的方法子集
|
||||
* ({@code findCount} / {@code loadPOJO} / {@code listSelect}),委托目标 bean 与
|
||||
* framework Groovy 逐字一致,旧引擎代码(com.dsasp.*)对本类的引用零修改。
|
||||
*
|
||||
* <p>引擎调用点:POInfo.java:860(findCount)、FlowExcuteServiceImpl.checkControl
|
||||
* 与 ControlBean(loadPOJO / listSelect)。未实现的取数/枚举/组织/工作流方法随 P2/P3
|
||||
* 对应横切服务移植时按 framework 原版补全(见 P1 服务流实测报告「替换类登记」)。
|
||||
*/
|
||||
public class GetServicesFunction {
|
||||
|
||||
@@ -15,4 +31,15 @@ public class GetServicesFunction {
|
||||
(DataDicService) SpringBeanOsgiServices.getInstance().getBeanByName("dataDicService");
|
||||
return dataDicService.findCount(countSql);
|
||||
}
|
||||
|
||||
public static GeneralPOJO loadPOJO(String entityId, String tableName, Boolean isHierarchical) {
|
||||
return ((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
|
||||
.loadPOJO(entityId, tableName, UserSession.get(), isHierarchical);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public static Map<String, Object> listSelect(Map map, final String tableName, Properties ctx) {
|
||||
return ((POJOCRUDService) SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService"))
|
||||
.listSelect(map, tableName, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.dsasp.server.common.function;
|
||||
|
||||
/**
|
||||
* eip4-poc 移植桩:原版为 Groovy 脚本函数库,仅被 FunctionUtil 以 class 引用注册。
|
||||
* WS3 脚本验证时回迁完整实现。
|
||||
*/
|
||||
public class GetValueFunction {
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.dsasp.server.common.privilege.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FlowPrivilegeService {
|
||||
|
||||
/**
|
||||
* get the action special permission of some fields,
|
||||
* @param userID
|
||||
* @param action
|
||||
* @return
|
||||
*/
|
||||
public List<String> getServicePrivileges(String roleId);
|
||||
|
||||
|
||||
public boolean authority(List<String> roles, String serviceId);
|
||||
|
||||
|
||||
public Object getMenus(String userID);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.dsasp.server.common.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.springframework.aop.framework.AdvisedSupport;
|
||||
import org.springframework.aop.framework.AopProxy;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
|
||||
public class AopTargetUtils {
|
||||
|
||||
|
||||
/**
|
||||
* 获取 目标对象
|
||||
* @param proxy 代理对象
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Object getTarget(Object proxy) throws Exception {
|
||||
|
||||
if(!AopUtils.isAopProxy(proxy)) {
|
||||
return proxy;//不是代理对象
|
||||
}
|
||||
|
||||
if(AopUtils.isJdkDynamicProxy(proxy)) {
|
||||
return getJdkDynamicProxyTargetObject(proxy);
|
||||
} else { //cglib
|
||||
return getCglibProxyTargetObject(proxy);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static Object getCglibProxyTargetObject(Object proxy) throws Exception {
|
||||
Field h = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0");
|
||||
h.setAccessible(true);
|
||||
Object dynamicAdvisedInterceptor = h.get(proxy);
|
||||
|
||||
Field advised = dynamicAdvisedInterceptor.getClass().getDeclaredField("advised");
|
||||
advised.setAccessible(true);
|
||||
|
||||
Object target = ((AdvisedSupport)advised.get(dynamicAdvisedInterceptor)).getTargetSource().getTarget();
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
private static Object getJdkDynamicProxyTargetObject(Object proxy) throws Exception {
|
||||
Field h = proxy.getClass().getSuperclass().getDeclaredField("h");
|
||||
h.setAccessible(true);
|
||||
AopProxy aopProxy = (AopProxy) h.get(proxy);
|
||||
|
||||
Field advised = aopProxy.getClass().getDeclaredField("advised");
|
||||
advised.setAccessible(true);
|
||||
|
||||
Object target = ((AdvisedSupport)advised.get(aopProxy)).getTargetSource().getTarget();
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.dsasp.server.common.util;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class ExceptionUtil {
|
||||
public static String convertExceptionToString(Exception e){
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw;
|
||||
try {
|
||||
pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
return sw.toString();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
package com.dsasp.server.core.origin.service;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.codehaus.groovy.runtime.StringBufferWriter;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.dsasp.server.common.core.OriginServiceBean;
|
||||
import com.dsasp.server.common.core.service.FlowService;
|
||||
import com.dsasp.server.common.core.service.OriginServiceManager;
|
||||
import com.dsasp.server.common.core.service.OriginServiceMethod;
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.bean.AbstractPOJOInfo;
|
||||
import com.dsasp.server.common.dataDic.bean.CustomSearchConditional;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.bean.POJOInfo;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.dataDic.service.POJOService;
|
||||
import com.dsasp.server.common.privilege.bean.MethodSecurityInterceptor;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
import com.dsasp.server.core.service.flow.model.Flow;
|
||||
|
||||
@Service(value="originServiceManager")
|
||||
public class OriginServiceManagerImpl implements OriginServiceManager {
|
||||
|
||||
private static Vector<OriginServiceBean> vector = new Vector<OriginServiceBean>();
|
||||
|
||||
private static Vector<Flow> flowVector = new Vector<Flow>();
|
||||
|
||||
public OriginServiceManagerImpl(){
|
||||
//saveRegister();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register(Class beanClass) {
|
||||
|
||||
Service d = (Service) beanClass.getAnnotation(Service.class);
|
||||
if (d != null) {
|
||||
String serviceName = d.value();
|
||||
Method[] methods = beanClass.getMethods();
|
||||
String beanClassName = beanClass.getName();
|
||||
String beanName = d.value();
|
||||
for (Method method : methods) {
|
||||
OriginServiceMethod m = (OriginServiceMethod) method.getAnnotation(OriginServiceMethod.class);
|
||||
if (m != null) {
|
||||
OriginServiceBean bean = new OriginServiceBean();
|
||||
bean.setBeanName(serviceName);
|
||||
bean.setMethod(method.getName());
|
||||
bean.setReturnResult(method.getReturnType().getName());
|
||||
Class[] paras = method.getParameterTypes();
|
||||
if(paras != null && paras.length > 0){
|
||||
List<String> list = new ArrayList<String>(paras.length);
|
||||
for(Class c : paras){
|
||||
list.add(c.getName());
|
||||
}
|
||||
bean.setArg(list);
|
||||
}
|
||||
bean.setDescription(m.description());
|
||||
bean.setDisplayName(m.name());
|
||||
bean.setType(m.type());
|
||||
vector.add(bean);
|
||||
}
|
||||
MethodSecurityInterceptor mSecurityInterceptor = (MethodSecurityInterceptor) method
|
||||
.getAnnotation(MethodSecurityInterceptor.class);
|
||||
if (mSecurityInterceptor != null) {
|
||||
Class[] paras = method.getParameterTypes();
|
||||
// 创建流程xml
|
||||
Document doc = DocumentHelper.createDocument();
|
||||
Element root = doc.addElement("flow");
|
||||
root.addAttribute("id", method.getName());
|
||||
Element input = root.addElement("input");
|
||||
if (paras != null && paras.length > 0) {
|
||||
List<String> listParas = new ArrayList<String>(
|
||||
paras.length);
|
||||
for (Class c : paras) {
|
||||
listParas.add(c.getName());
|
||||
}
|
||||
for (String arg : listParas) {
|
||||
Element fieldElement = input.addElement("field");
|
||||
fieldElement.addAttribute("name", arg);
|
||||
fieldElement.addAttribute("type", arg);
|
||||
}
|
||||
}
|
||||
Element startElement = root.addElement("start");
|
||||
startElement.addAttribute("id", "start");
|
||||
startElement.addAttribute("name", "开始");
|
||||
|
||||
Element service = startElement.addElement("service");
|
||||
service.addAttribute("beanName", beanName);
|
||||
service.addAttribute("method", method.getName());
|
||||
Element list = service.addElement("list");
|
||||
|
||||
if (paras != null && paras.length > 0) {
|
||||
List<String> listParas = new ArrayList<String>(
|
||||
paras.length);
|
||||
for (Class c : paras) {
|
||||
listParas.add(c.getName());
|
||||
}
|
||||
for (String arg : listParas) {
|
||||
Element argEle = list.addElement("arg");
|
||||
argEle.addAttribute("name", arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (method.getReturnType() != null) {
|
||||
Element resultEle = service.addElement("result");
|
||||
resultEle.addAttribute("name", method.getReturnType()
|
||||
.getName());
|
||||
}
|
||||
|
||||
Element ele = root.addElement("transition");
|
||||
ele.addAttribute("from", "start");
|
||||
ele.addAttribute("to", "End");
|
||||
|
||||
Element endElement = root.addElement("end");
|
||||
endElement.addAttribute("id", "End");
|
||||
endElement.addAttribute("name", "结束");
|
||||
Element output = root.addElement("output");
|
||||
|
||||
if (method.getReturnType() != null) {
|
||||
Element fieldElement = output.addElement("field");
|
||||
fieldElement.addAttribute("name", method
|
||||
.getReturnType().getName());
|
||||
fieldElement.addAttribute("type", method
|
||||
.getReturnType().getName());
|
||||
}
|
||||
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Writer out = new StringBufferWriter(buffer);
|
||||
XMLWriter writer = new XMLWriter(out, format);
|
||||
String contentxml = "";
|
||||
try {
|
||||
writer.write(doc);
|
||||
contentxml = buffer.toString();
|
||||
} catch (Exception ex) {
|
||||
// throw new RuntimeException("格式有误");
|
||||
}
|
||||
|
||||
Flow flow = new Flow(beanClassName + "." + method.getName(),contentxml);
|
||||
flow.setDisplayName(mSecurityInterceptor.name());
|
||||
flow.setEntityId(mSecurityInterceptor.tableName());
|
||||
flow.setControl(mSecurityInterceptor.isControl());
|
||||
flow.setUpdateable(false);
|
||||
flowVector.add(flow);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// private void saveRegister(){
|
||||
// Timer timer = new Timer("registerService", true);
|
||||
// timer.schedule(new TimerTask() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// while(vector.size() > 0){
|
||||
// OriginServiceBean bean = vector.remove(0);
|
||||
// saveOrUpdate(bean);
|
||||
// }
|
||||
// while(flowVector.size() > 0){
|
||||
// Flow bean = flowVector.remove(0);
|
||||
// saveOrUpdateFlow(bean);
|
||||
// }
|
||||
// }
|
||||
// }, 60000, 10 * 60 * 1000);
|
||||
// }
|
||||
|
||||
public void saveRegister(){
|
||||
while(vector.size() > 0){
|
||||
OriginServiceBean bean = vector.remove(0);
|
||||
saveOrUpdate(bean);
|
||||
}
|
||||
while(flowVector.size() > 0){
|
||||
Flow bean = flowVector.remove(0);
|
||||
saveOrUpdateFlow(bean);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveOrUpdateFlow(Flow flow){
|
||||
POJOInfo po = AbstractPOJOInfo.getPOInfo(flow.getEntityId());
|
||||
if (po != null) {
|
||||
flow.setEntityId(po.getAD_Table_ID());
|
||||
}
|
||||
FlowService flowService = (FlowService) SpringBeanOsgiServices
|
||||
.getInstance().getBeanByName("flowService");
|
||||
flowService.saveOrUpdate(flow, UserSession.getAdmin());
|
||||
}
|
||||
|
||||
public void saveOrUpdate(OriginServiceBean bean) {
|
||||
|
||||
POJOService pojoService = (POJOService) SpringBeanOsgiServices
|
||||
.getInstance().getBeanByName("pojoService");
|
||||
|
||||
POJOCRUDService poCurdService = (POJOCRUDService) SpringBeanOsgiServices
|
||||
.getInstance().getBeanByName("pojoCRUDService");
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("CLASSNAME", bean.getBeanName());
|
||||
map.put("METHODNAME", bean.getMethod());
|
||||
List<GeneralPOJO> poList = (List<GeneralPOJO>)poCurdService.listSelect(map, "SYS_ORIGINSERVICE", UserSession.getAdmin()).get(POJOCRUDService.LIST_RESULT);
|
||||
if(poList != null && poList.size() == 1){
|
||||
GeneralPOJO po = poList.get(0);
|
||||
po = pojoService.loadPOJO(po.get_ID(), "SYS_ORIGINSERVICE", UserSession.getAdmin(), true);
|
||||
bean.updateToPO(po);
|
||||
pojoService.update(po, LoggedInUser.ADMIN);
|
||||
}else if(poList == null || poList.size() == 0 ){
|
||||
|
||||
poCurdService.save(bean.convertToMap(), "SYS_ORIGINSERVICE", UserSession.getAdmin());
|
||||
}else{
|
||||
//log error message
|
||||
for (GeneralPOJO pojo : poList) {
|
||||
pojoService.delete(pojo, "", true);
|
||||
}
|
||||
saveOrUpdate(bean);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregister(Class beanClass) {
|
||||
|
||||
Service d = (Service) beanClass.getAnnotation(Service.class);
|
||||
if (d != null) {
|
||||
Method[] methods = beanClass.getMethods();
|
||||
String beanClassName = beanClass.getName();
|
||||
for (Method method : methods) {
|
||||
OriginServiceMethod m = (OriginServiceMethod) method.getAnnotation(OriginServiceMethod.class);
|
||||
if (method.getAnnotation(OriginServiceMethod.class) != null) {
|
||||
OriginServiceBean bean = new OriginServiceBean();
|
||||
bean.setBeanName(beanClassName);
|
||||
bean.setMethod(method.getName());
|
||||
bean.setReturnResult(method.getReturnType().getName());
|
||||
Class[] paras = method.getParameterTypes();
|
||||
if(paras != null && paras.length > 0){
|
||||
List<String> list = new ArrayList<String>(paras.length);
|
||||
for(Class c : paras){
|
||||
list.add(c.getName());
|
||||
}
|
||||
bean.setArg(list);
|
||||
}
|
||||
bean.setDescription(m.description());
|
||||
bean.setDisplayName(m.name());
|
||||
bean.setType(m.type());
|
||||
delete(bean);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public void delete(OriginServiceBean bean) {
|
||||
|
||||
POJOService pojoService = (POJOService) SpringBeanOsgiServices
|
||||
.getInstance().getBeanByName("pojoService");
|
||||
String select = "SELECT SYS_ORIGINSERVICE_ID FROM SYS_ORIGINSERVICE WHERE CLASSNAME='"
|
||||
+ bean.getBeanName()
|
||||
+ "' AND METHODNAME='"
|
||||
+ bean.getMethod()
|
||||
+ "'";
|
||||
List<String> cols = new ArrayList<String>();
|
||||
cols.add("SYS_ORIGINSERVICE_ID");
|
||||
List<GeneralPOJO> poList = pojoService.listSelectSpecialCols(select,
|
||||
"SYS_ORIGINSERVICE", 0, Integer.MAX_VALUE, cols);
|
||||
if (poList != null && poList.size() > 0) {
|
||||
for (GeneralPOJO pojo : poList) {
|
||||
pojoService.delete(pojo, "", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OriginServiceBean> findOriginService(String sql, int start,
|
||||
int pageSize) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OriginServiceBean getOriginService(String beanName, String method) {
|
||||
|
||||
POJOCRUDService poCurdService = (POJOCRUDService) SpringBeanOsgiServices
|
||||
.getInstance().getBeanByName("pojoCRUDService");
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
CustomSearchConditional beanNameCon = new CustomSearchConditional("CLASSNAME = '" + beanName + "'");
|
||||
CustomSearchConditional methodCon = new CustomSearchConditional("METHODNAME = '" + method + "'");
|
||||
map.put("CLASSNAME", beanNameCon);
|
||||
map.put("METHODNAME", methodCon);
|
||||
|
||||
|
||||
List<GeneralPOJO> poList = (List<GeneralPOJO>)poCurdService.listSelect(map, "SYS_ORIGINSERVICE", UserSession.getAdmin()).get(POJOCRUDService.LIST_RESULT);
|
||||
if(poList != null && poList.size() == 1){
|
||||
GeneralPOJO po = poList.get(0);
|
||||
po = poCurdService.loadPOJO(po.get_ID(), po.get_TableName(), null, true);
|
||||
return new OriginServiceBean(po);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OriginServiceBean loadOriginServiceBean(String id) {
|
||||
POJOService pojoService = (POJOService) SpringBeanOsgiServices
|
||||
.getInstance().getBeanByName("pojoService");
|
||||
GeneralPOJO po = pojoService.loadPOJO(id, "SYS_ORIGINSERVICE", UserSession.getAdmin(), true);
|
||||
return new OriginServiceBean(po);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,534 @@
|
||||
package com.dsasp.server.core.service;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.dsasp.server.common.core.ControlBean;
|
||||
import com.dsasp.server.common.core.FlowDefinition;
|
||||
import com.dsasp.server.common.core.service.FlowExcuteService;
|
||||
import com.dsasp.server.common.core.service.FlowService;
|
||||
import com.dsasp.server.common.core.service.OriginServiceMethod;
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.bean.CustomSearchConditional;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.exception.PrivilegeException;
|
||||
import com.dsasp.server.common.exception.SameCodeException;
|
||||
import com.dsasp.server.common.exception.ValidationException;
|
||||
import com.dsasp.server.common.function.GetDefaultValueFunction;
|
||||
import com.dsasp.server.common.function.GetServicesFunction;
|
||||
import com.dsasp.server.common.log.service.SystemLogManager;
|
||||
import com.dsasp.server.common.log.service.SystemLogManager.LogType;
|
||||
import com.dsasp.server.common.privilege.service.FlowPrivilegeService;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.AopTargetUtils;
|
||||
import com.dsasp.server.common.util.ExceptionUtil;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
import com.dsasp.server.core.service.flow.model.Field;
|
||||
import com.dsasp.server.core.service.flow.model.Flow;
|
||||
import com.dsasp.server.core.service.flow.model.Node;
|
||||
import com.dsasp.server.core.service.flow.model.Procedure;
|
||||
import com.dsasp.server.core.service.flow.model.Script;
|
||||
import com.dsasp.server.core.service.flow.model.ServiceBean;
|
||||
import com.dsasp.server.core.service.flow.model.Start;
|
||||
import com.dsasp.server.core.service.flow.model.Transition;
|
||||
import com.dsasp.server.core.service.script.ScriptingEnginesManager;
|
||||
|
||||
@Service(value = "flowExcuteService")
|
||||
@Transactional
|
||||
public class FlowExcuteServiceImpl implements FlowExcuteService {
|
||||
|
||||
private static String defaultImport =
|
||||
// " import com.dsasp.server.common.dataDic.bean.GeneralPOJO; \n"
|
||||
// + " import com.dsasp.server.common.util.StringUtil; \n"
|
||||
// + " import com.dsasp.server.dataDic.util.FunctionUtil; \n"
|
||||
// + " import com.dsasp.server.common.function.GetServicesFunction; \n"
|
||||
// + " import com.dsasp.server.common.function.GetDefaultValueFunction; \n"
|
||||
// + " import com.dsasp.server.common.function.GetValueFunction; \n"
|
||||
" import com.dsasp.server.common.message.bean.*; \n";
|
||||
|
||||
|
||||
@Autowired
|
||||
private FlowService flowService;
|
||||
|
||||
//protected static CCache<String, GeneralPOJO> is_cache = new CCache<String, GeneralPOJO>("ServiceControls", 200);
|
||||
|
||||
//private SystemLogManager systemLogManager = (SystemLogManager)SpringBeanOsgiServices.getInstance().getBeanByName("systemLogManager");
|
||||
|
||||
protected SystemLogManager getSystemLogManager(){
|
||||
return (SystemLogManager)SpringBeanOsgiServices.getInstance().getBeanByName("systemLogManager");
|
||||
}
|
||||
|
||||
/**
|
||||
* the implement return the object is hashmap, but other implement is not fixed
|
||||
*/
|
||||
@OriginServiceMethod(name="服务流执行", type="core", description="执行服务流入口,参数1 map 数据载体,参数 2 ctx 环境载体,参数 3 flowId 服务流key")
|
||||
@Override
|
||||
public Object excute(Map map, Properties ctx, String flowId) {
|
||||
if(flowId != null){
|
||||
FlowDefinition definition = flowService.getFlowDefinition(flowId);
|
||||
if(definition == null){
|
||||
throw new ValidationException("服务:"+flowId+"不存在!");
|
||||
}
|
||||
Flow flow = ((Flow)definition).initial();
|
||||
flow.createFlowScriptBindings(map, ctx);
|
||||
//控制
|
||||
List<String> conFlows = checkControl(flowId, flow, map);
|
||||
|
||||
if(conFlows != null && conFlows.size() > 0){
|
||||
for (String contFlowId : conFlows) {
|
||||
excute(map, ctx, contFlowId);
|
||||
}
|
||||
}
|
||||
|
||||
if(validateInput(flow.getInputs(), flow)){
|
||||
Start start = flow.getStart();
|
||||
excuteNode(start, map, flow, ctx);
|
||||
return returnOutputs(map, flow.getOutputs());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
//检查是否有服务控制
|
||||
protected List<String> checkControl(String flowId,Flow flow,Map map){
|
||||
|
||||
Map<String,Object> tMap;
|
||||
Map<String, Object> listSelect = new HashMap<String, Object>();
|
||||
List<GeneralPOJO> results = new ArrayList<GeneralPOJO>();
|
||||
List<GeneralPOJO> resultList = ControlBean.getControl(flowId, 2);
|
||||
|
||||
if(resultList != null && resultList.size() > 0){
|
||||
|
||||
List<String> flows = new ArrayList<String>();
|
||||
|
||||
for (GeneralPOJO result : resultList) {
|
||||
if(result != null){
|
||||
//有控制
|
||||
String controlId = (String) result.get_Value("CONTROLID");
|
||||
String contFlowId = (String) result.get_Value("CONTROLSERVICEID");
|
||||
|
||||
result = GetServicesFunction.loadPOJO(controlId, "SYS_TEMPLATECONTROL", false);
|
||||
Integer type = (Integer) result.get_Value("TEMPLATETYPE");
|
||||
Integer isEnable = (Integer) result.get_Value("ISENABLE");
|
||||
|
||||
//
|
||||
tMap = new HashMap<String, Object>();
|
||||
tMap.put("CONTROLID", new CustomSearchConditional(" CONTROLID = '" + controlId + "'"));
|
||||
listSelect = GetServicesFunction.listSelect(tMap, "SYS_TEMPLATECONTROL_USER", UserSession.getAdmin());
|
||||
List<GeneralPOJO> users = new ArrayList<GeneralPOJO>();
|
||||
if(listSelect != null){
|
||||
users = (List<GeneralPOJO>) listSelect.get("listresult");
|
||||
}
|
||||
Boolean flag = true;
|
||||
String userId = GetDefaultValueFunction.getCurrentUserId();
|
||||
if(users != null && users.size() >0){
|
||||
for (GeneralPOJO user : users) {
|
||||
if(userId.equals(user.get_Value("USERID"))){
|
||||
DateTime date3 = (DateTime) user.get_Value("EXPIRY");
|
||||
if(date3 == null || date3.isAfter(GetDefaultValueFunction.currentDate())){
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//没有不设控用户,或者当前用户不属于不设控用户
|
||||
if(flag){
|
||||
//无解控日期或者已经超过解控日期
|
||||
if(isEnable == 1){
|
||||
|
||||
Boolean flag2 = true;
|
||||
//如果是功能类型为工程
|
||||
if(type == 1){
|
||||
String columnName = "";
|
||||
String tableName = "";
|
||||
String keyId = "";
|
||||
Field[] inputs = flow.getInputs();
|
||||
if(inputs != null && inputs.length > 0){
|
||||
for (Field input : inputs) {
|
||||
if("tableName".equals(input.getName())){
|
||||
tableName = input.getInitValue();
|
||||
keyId = tableName + "_ID";
|
||||
if(!StringUtil.isEmpty(tableName)){
|
||||
tMap = new HashMap<String, Object>();
|
||||
tMap.put("TABLENAME", new CustomSearchConditional(" TABLENAME = '" + tableName + "'"));
|
||||
listSelect = GetServicesFunction.listSelect(tMap, "SYS_ENTITY", UserSession.getAdmin());
|
||||
List<GeneralPOJO> entitys = new ArrayList<GeneralPOJO>();
|
||||
if(listSelect != null){
|
||||
entitys = (List<GeneralPOJO>) listSelect.get("listresult");
|
||||
}
|
||||
if(entitys != null && entitys.size() > 0){
|
||||
String entityId = entitys.get(0).get_ID();
|
||||
tMap = new HashMap<String, Object>();
|
||||
tMap.put("SYS_ENTITYATTRIBUTE_ID", new CustomSearchConditional(" ENTITYID = '" + entityId + "' and REFERENCEID = 'ab81c24e-3fd0-4beb-afe3-ed86d378cdc5'"));
|
||||
listSelect = GetServicesFunction.listSelect(tMap, "SYS_ENTITYATTRIBUTE", UserSession.getAdmin());
|
||||
List<GeneralPOJO> attrs = new ArrayList<GeneralPOJO>();
|
||||
if(listSelect != null){
|
||||
attrs = (List<GeneralPOJO>) listSelect.get("listresult");
|
||||
}
|
||||
if(attrs != null && attrs.size() >0){
|
||||
columnName = (String) attrs.get(0).get_Value("COLUMNNAME");
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!StringUtil.isEmpty(tableName) && !StringUtil.isEmpty(keyId) && !StringUtil.isEmpty(columnName) && map != null){
|
||||
String projectId = "";
|
||||
if(StringUtil.empty(map.get(columnName))){
|
||||
keyId = (String) map.get(keyId);
|
||||
if(!StringUtil.isEmpty(keyId)){
|
||||
GeneralPOJO pojo = GetServicesFunction.loadPOJO(keyId, tableName, false);
|
||||
projectId = (String) pojo.get_Value(columnName);
|
||||
}
|
||||
} else {
|
||||
projectId = (String) map.get(columnName);
|
||||
}
|
||||
tMap = new HashMap<String, Object>();
|
||||
tMap.put("SYS_TEMPLATEDECONTROL_ID", new CustomSearchConditional(" CONTROLID = '" + controlId + "' and PROJECTID = '" + projectId + "'"));
|
||||
listSelect = GetServicesFunction.listSelect(tMap, "SYS_TEMPLATEDECONTROL", UserSession.getAdmin());
|
||||
List<GeneralPOJO> deControls = new ArrayList<GeneralPOJO>();
|
||||
if(listSelect != null){
|
||||
deControls = (List<GeneralPOJO>) listSelect.get("listresult");
|
||||
}
|
||||
if(deControls != null && deControls.size() > 0){
|
||||
DateTime date2 = (DateTime) deControls.get(0).get_Value("EXPIRY");
|
||||
if(date2 == null || date2.isAfter(GetDefaultValueFunction.currentDate())){
|
||||
flag2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(flag2){
|
||||
flows.add(contFlowId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flows;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void authority(Properties ctx, FlowDefinition definition){
|
||||
if(definition != null && !definition.isControl()){
|
||||
return;
|
||||
}
|
||||
FlowPrivilegeService flowPrivilegeService = (FlowPrivilegeService)SpringBeanOsgiServices.getInstance().getBeanByName("flowPrivilegeService");
|
||||
flowPrivilegeService.authority((List<String>)ctx.get(LoggedInUser.ROLES), definition.getKey());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public FlowService getFlowService() {
|
||||
return flowService;
|
||||
}
|
||||
|
||||
public void setFlowService(FlowService flowService) {
|
||||
this.flowService = flowService;
|
||||
}
|
||||
|
||||
//FIXME: validate the inputs
|
||||
private boolean validateInput(Object[] input, Flow flow) {
|
||||
Field[] fields = flow.getInputs();
|
||||
for (Field field : fields) {
|
||||
Object obj = null;
|
||||
if (!StringUtil.isEmpty(field.getInitValue())) {
|
||||
obj = convertToObject(field.getType(), field.getInitValue());
|
||||
} else if (!StringUtil.isEmpty(field.getInitExpression())) {
|
||||
obj = parseExpressionFromContext(flow,
|
||||
field.getInitExpression());
|
||||
}
|
||||
if (obj != null && !flow.getBindings().containsKey(field.getName())) {
|
||||
flow.getBindings().put(field.getName(), obj);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* excute node
|
||||
* @param node
|
||||
* @param map
|
||||
* @param flow
|
||||
* @param ctx
|
||||
*/
|
||||
private void excuteNode(Node node, Map map, Flow flow, Properties ctx) {
|
||||
if (Node.SCRIPT_TYPE.equals(node.getType())) {
|
||||
Script script = node.getScript();
|
||||
try {
|
||||
if (!StringUtil.isEmpty(script.getScrip())) {
|
||||
ScriptingEnginesManager.getScriptingEnginesManager()
|
||||
.evaluateGroovy(script.getKey() + flow.getKey(), defaultImport + script.getScrip(),
|
||||
flow.getBindings());
|
||||
if(!StringUtil.isEmpty(script.getExecuteExpression())){
|
||||
String executScript = (String)flow.getBindings().get(script.getExecuteExpression());
|
||||
ScriptingEnginesManager.getScriptingEnginesManager()
|
||||
.evaluateGroovy("", defaultImport + executScript,
|
||||
flow.getBindings());
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
String logContent = "服务流中的脚本执行出错,出错的服务流名称:"+flow.getDisplayName()+",节点名称:"+node.getName()+",节点ID:"+node.getId()+"\n";
|
||||
logContent+="出错的脚本ID:"+script.getKey()+"\n";
|
||||
logContent+="环境变量:"+map != null ?map.toString():"无"+"\n";
|
||||
logContent+=ExceptionUtil.convertExceptionToString(e);
|
||||
getSystemLogManager().log(LogType.ERRORS, logContent);
|
||||
throw e;
|
||||
}
|
||||
} else if (Node.SERVICE_TYPE.equals(node.getType())) {
|
||||
ServiceBean bean = node.getBean();
|
||||
if (bean != null) {
|
||||
Object proxy = SpringBeanOsgiServices.getInstance()
|
||||
.getBeanByName(bean.getBeanName());
|
||||
if (proxy == null) {
|
||||
throw new RuntimeException("no service");
|
||||
}
|
||||
try {
|
||||
Object obj = AopTargetUtils.getTarget(proxy);
|
||||
List<String> args = bean.getArgs();
|
||||
|
||||
List<Object> listValue = new ArrayList<Object>();
|
||||
List<Class> listClass = new ArrayList<Class>();
|
||||
for (int i = 0; i < args.size(); i++) {
|
||||
String name = args.get(i);
|
||||
Field field = flow.getInputField(name);
|
||||
listClass.add(getClass(field));
|
||||
Object argObj = getArgFromContext(map, ctx, flow, name);
|
||||
listValue.add(argObj);
|
||||
}
|
||||
|
||||
Class[] classObjs = new Class[listClass.size()];
|
||||
listClass.toArray(classObjs);
|
||||
Method method = obj.getClass().getMethod(bean.getMethod(),
|
||||
classObjs);
|
||||
|
||||
Object[] objs = new Object[listValue.size()];
|
||||
listValue.toArray(objs);
|
||||
Object result = method.invoke(obj, objs);
|
||||
if (!StringUtil.isEmpty(bean.getResult())) {
|
||||
flow.getBindings().put(bean.getResult(), result);
|
||||
}
|
||||
} catch (SameCodeException ex) {
|
||||
throw ex;
|
||||
}catch(ValidationException ex){
|
||||
throw ex;
|
||||
}catch(PrivilegeException ex){
|
||||
throw ex;
|
||||
}catch(Exception ex){
|
||||
String logContent = "服务流中的服务执行出错,出错的服务流名称:"+flow.getDisplayName()+",节点名称:"+node.getName()+",节点ID:"+node.getId()+"\n";;
|
||||
logContent+="环境变量:"+ (map != null ?map.toString():"无")+"\n";;
|
||||
logContent+=ExceptionUtil.convertExceptionToString(ex);
|
||||
getSystemLogManager().log(LogType.ERRORS, logContent);
|
||||
ex.printStackTrace();
|
||||
Throwable throwCase = ex.getCause();
|
||||
while(throwCase != null ){
|
||||
if(throwCase instanceof ValidationException){
|
||||
throw (ValidationException)throwCase;
|
||||
}else if(throwCase instanceof PrivilegeException){
|
||||
throw (PrivilegeException)throwCase;
|
||||
}else if(throwCase instanceof SameCodeException){
|
||||
throw (SameCodeException)throwCase;
|
||||
}else{
|
||||
throwCase = throwCase.getCause();
|
||||
}
|
||||
}
|
||||
throw new ValidationException(ex.getCause().getMessage());
|
||||
}
|
||||
}
|
||||
}else if(node.PROCEDURE_TYPE.equals(node.getType())){
|
||||
Procedure procedure = node.getProcedure();
|
||||
String proName = procedure.getName();
|
||||
String returnType = procedure.getResult();
|
||||
List<String> outputs = procedure.getOutFields();
|
||||
StringBuffer sql = new StringBuffer();
|
||||
if(!StringUtil.isEmpty(returnType)){
|
||||
sql.append("?=");
|
||||
}
|
||||
sql.append(" call ").append(proName).append("(");
|
||||
List<String> inputs = procedure.getInputFields();
|
||||
if(inputs != null && inputs.size() > 0){
|
||||
for(int i = 0; i < inputs.size(); i++){
|
||||
String name = inputs.get(i);
|
||||
Field field = flow.getInputField(name);
|
||||
Object argObj = getArgFromContext(map, ctx, flow, name);
|
||||
if(i > 0){
|
||||
sql.append(",");
|
||||
}
|
||||
if(Boolean.class.getName().equals(field.getName())){
|
||||
sql.append(argObj);
|
||||
}else if(Integer.class.getName().equals(field.getName()) || BigDecimal.class.getName().equals(field.getName())){
|
||||
sql.append(argObj);
|
||||
}else{
|
||||
sql.append("'").append(argObj.toString()).append("'");
|
||||
}
|
||||
}
|
||||
}
|
||||
sql.append(")");
|
||||
POJOCRUDService service = (POJOCRUDService)SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService");
|
||||
String[][] returnSetType = null;
|
||||
if(outputs != null && outputs.size() > 0){
|
||||
returnSetType = new String[outputs.size()][2];
|
||||
for(int i = 0; i < outputs.size(); i++){
|
||||
returnSetType[i][0] = outputs.get(i);
|
||||
returnSetType[i][1] = flow.getOutputField(outputs.get(i)).getType();
|
||||
}
|
||||
}
|
||||
String returnTypeStr = null;
|
||||
if(!StringUtil.isEmpty(returnType)){
|
||||
Field outField = flow.getOutputField(returnType);
|
||||
if(outField != null){
|
||||
returnTypeStr = outField.getType();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Object result = service.executeProcedureReturnObject(returnTypeStr, returnSetType, ctx, sql.toString());
|
||||
if (!StringUtil.isEmpty(procedure.getResult())) {
|
||||
flow.getBindings().put(procedure.getResult(), result);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
String logContent = "服务流中的存储过程执行出错,出错的服务流名称:"+flow.getDisplayName()+",节点名称:"+node.getName()+",节点ID"+node.getId()+"\n";
|
||||
logContent+="出错的存储过程:"+ sql +"\n";
|
||||
logContent+="环境变量:"+map != null ?map.toString():"无"+"\n";
|
||||
logContent+=ExceptionUtil.convertExceptionToString(e);
|
||||
getSystemLogManager().log(LogType.ERRORS, logContent);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
excuteNextNode(node, map, flow, ctx);
|
||||
}
|
||||
|
||||
private void excuteNextNode(Node node, Map map, Flow flow, Properties ctx){
|
||||
if(!"END".equals(node.getId()) && flow.getTransitions(node.getId()) != null){
|
||||
List<Transition> transitions = flow.getTransitions(node.getId());
|
||||
if(transitions != null){
|
||||
for(Transition transition : transitions){
|
||||
if(excuteTransition(transition.getConditionExpression(), flow)){
|
||||
Node next = flow.getNode(transition.getTo());
|
||||
excuteNode(next, map, flow, ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FIXME: get value of the expression
|
||||
private boolean excuteTransition(String conditionExpression, Flow flow){
|
||||
//no condition is default transition;
|
||||
if(StringUtil.isEmpty(conditionExpression)){
|
||||
return true;
|
||||
}
|
||||
Object obj = parseExpressionFromContext(flow, conditionExpression);
|
||||
if(obj instanceof Boolean){
|
||||
return (Boolean)obj;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* map and ctx is the special variable of the context
|
||||
* first parse the initValue, second parse the initExpression three is the default
|
||||
* @param map
|
||||
* @param ctx
|
||||
* @param field
|
||||
* @param variableName
|
||||
* @return
|
||||
*/
|
||||
private Object getArgFromContext(Map map, Properties ctx, Flow flow,
|
||||
String variableName) {
|
||||
if ("map".equals(variableName)) {
|
||||
return map;
|
||||
} else if ("ctx".equals(variableName)) {
|
||||
return ctx;
|
||||
} else {
|
||||
|
||||
if (map.containsKey(variableName)) {
|
||||
return map.get(variableName);
|
||||
} else {
|
||||
|
||||
return ctx == null ? null : ctx.get(variableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FIXME: parse the expression value
|
||||
private Object parseExpressionFromContext(Flow flow, String initExpression){
|
||||
return ScriptingEnginesManager.getScriptingEnginesManager().evaluate(initExpression, ScriptingEnginesManager.DEFAULT_SCRIPTING_LANGUAGE, flow.getBindings());
|
||||
}
|
||||
|
||||
private Object convertToObject(String className, String initValue){
|
||||
if(String.class.getName().equals(className)){
|
||||
return initValue;
|
||||
}else if(Integer.class.getName().equals(className)){
|
||||
return Integer.getInteger(initValue);
|
||||
}else if(Boolean.class.getName().equals(className)){
|
||||
return Boolean.valueOf(initValue);
|
||||
}else if(BigDecimal.class.getName().equals(className)){
|
||||
return BigDecimal.valueOf(Double.parseDouble(initValue));
|
||||
}
|
||||
else if(Double.class.getName().equals(className)){
|
||||
return Double.parseDouble(initValue);
|
||||
}else if(DateTime.class.getName().equals(className)){
|
||||
return DateTime.parse(initValue);
|
||||
}
|
||||
else{
|
||||
return initValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//FIXME: class loader with the plugin loader
|
||||
private Class getClass(Field field) {
|
||||
try {
|
||||
String className = field.getType();
|
||||
return Class.forName(className);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return the flow output ,if the required variable is null, then throw the runtimeException
|
||||
* @param map
|
||||
* @param outputs
|
||||
* @return
|
||||
*/
|
||||
private Map returnOutputs(Map map, Field[] outputs) {
|
||||
if(outputs != null && outputs.length > 0){
|
||||
HashMap<String, Object> result = new HashMap<String, Object>();
|
||||
for(Field field : outputs){
|
||||
Object obj = map.get(field.getName());
|
||||
if(field.isRequired() && obj == null){
|
||||
throw new RuntimeException(" the required result " + field.getName() + " is not null");
|
||||
}
|
||||
result.put(field.getName(), obj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.dsasp.server.core.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.dsasp.server.common.core.FlowDefinition;
|
||||
import com.dsasp.server.common.core.service.FlowService;
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.bean.CCache;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.POJOCRUDService;
|
||||
import com.dsasp.server.common.exception.ValidationException;
|
||||
import com.dsasp.server.common.privilege.bean.MethodSecurityInterceptor;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
import com.dsasp.server.core.service.flow.model.BaseFlowConvert;
|
||||
import com.dsasp.server.core.service.flow.model.DefaultFlowHelper;
|
||||
import com.dsasp.server.core.service.flow.model.Field;
|
||||
import com.dsasp.server.core.service.flow.model.Flow;
|
||||
import com.dsasp.server.core.service.script.ScriptingEnginesManager;
|
||||
// 必要改动(Boot3/JDK17 断点):移除 JDK 内部不可用 import com.sun.xml.internal.ws.developer.MemberSubmissionAddressing
|
||||
// ——原版未使用,JDK 9+ 起 com.sun.xml.internal.* 不再导出,保留则编译失败。
|
||||
|
||||
@Service(value = "flowService")
|
||||
@Transactional
|
||||
public class FlowServiceImpl implements FlowService {
|
||||
protected static CCache<String, Flow> is_cache = new CCache<String, Flow>("Services", 200);
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
private static final String TableName = "SYS_SERVICEFLOW";
|
||||
|
||||
public JdbcTemplate getJdbcTemplate() {
|
||||
return jdbcTemplate;
|
||||
}
|
||||
|
||||
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@MethodSecurityInterceptor(name="服务维护", tableName="SYS_SERVICEFLOW", isControl=true)
|
||||
public FlowDefinition saveOrUpdate(FlowDefinition flow, Properties ctx) {
|
||||
POJOCRUDService pojoCRUDService = (POJOCRUDService)SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService");
|
||||
if(getFlowDefinition(flow.getKey()) == null){
|
||||
Map<String, Object> map = BaseFlowConvert.converFlowToMap(flow);
|
||||
pojoCRUDService.save(map, TableName, ctx);
|
||||
}else{
|
||||
Map<String, Object> map = BaseFlowConvert.converFlowToMap(flow);
|
||||
pojoCRUDService.update(map, TableName, ctx);
|
||||
}
|
||||
is_cache.remove(flow.getKey());
|
||||
setChangeScript(flow.getFlow());
|
||||
return flow;
|
||||
}
|
||||
|
||||
private void setChangeScript(String flow){
|
||||
List<String> keys = StringUtil.getKeyValue(flow, "key");
|
||||
ScriptingEnginesManager.getScriptingEnginesManager().setChangeScripts(keys);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public FlowDefinition getFlowDefinition(String flowId) {
|
||||
// Flow flow = is_cache.get(flowId);
|
||||
// if(flow == null){
|
||||
//
|
||||
Flow flow = loadFlowXml(flowId);
|
||||
// is_cache.put(flowId, flow);
|
||||
// }
|
||||
return flow;
|
||||
}
|
||||
|
||||
private Flow loadFlowXml(String flowKey) {
|
||||
|
||||
POJOCRUDService pojoService = (POJOCRUDService)SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService");
|
||||
GeneralPOJO entity = pojoService.loadPOJO(flowKey, "SYS_SERVICEFLOW", null, true);
|
||||
return BaseFlowConvert.convertPOToFlow(entity);
|
||||
//
|
||||
//
|
||||
// String select =
|
||||
// "SELECT CONTENTXML FROM SYS_SERVICEFLOW WHERE SYS_SERVICEFLOW_ID = '" + flowKey +
|
||||
// "' " ;
|
||||
//// "ORDER BY REV_NO DESC";
|
||||
//// String select = "SELECT NAME, XML AS CONTENTXML FROM TEST_FORM_TEMPLATE WHERE NAME = 'TEST' ORDER BY TYPE ASC" ;
|
||||
// List<String> set = jdbcTemplate.query(select, new RowMapper() {
|
||||
// public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
|
||||
// if (rowNum == 0) {
|
||||
// return rs.getString("CONTENTXML");
|
||||
//// SQLXML attach = rs.getSQLXML("CONTENTXML");
|
||||
//// if(attach != null){
|
||||
//// return attach.getString();
|
||||
//// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
// });
|
||||
// if (set != null && set.size() > 0) {
|
||||
// return set.get(0);
|
||||
// }
|
||||
// throw new ValidationException("加载的服务" + flowKey + "不存在");
|
||||
}
|
||||
|
||||
public boolean isExistEntityFlow(String entityId){
|
||||
String select = "SELECT COUNT(*) FROM SYS_SERVICEFLOW WHERE ENTITYID='" + entityId + "'";
|
||||
// 必要改动(Boot3/JDK17 断点):queryForInt 在 Spring 6 已移除,改 queryForObject(...,Integer.class)
|
||||
// ——与迁移手册 §2.1 同款修复,语义等价。
|
||||
int count = jdbcTemplate.queryForObject(select, Integer.class);
|
||||
return count >= 1;
|
||||
}
|
||||
|
||||
public boolean addDefaultFlowService(String entityId, Properties ctx){
|
||||
boolean exist = isExistEntityFlow(entityId);
|
||||
if(exist){
|
||||
return false;
|
||||
}else{
|
||||
POJOCRUDService pojoCRUDService = (POJOCRUDService)SpringBeanOsgiServices.getInstance().getBeanByName("pojoCRUDService");
|
||||
GeneralPOJO po = pojoCRUDService.loadPOJO(entityId, "SYS_ENTITY", ctx, false);
|
||||
List<FlowDefinition> list = DefaultFlowHelper.getDefaultFlowService((String)po.get_Value("TABLENAME"), entityId, (String)po.get_Value("NAME"));
|
||||
for (FlowDefinition flow : list) {
|
||||
saveOrUpdate(flow, ctx);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControlFlowService(String flowId) {
|
||||
FlowDefinition<Flow> flow = getFlowDefinition(flowId);
|
||||
if(flow != null){
|
||||
return flow.isControl();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,221 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
import java.io.Writer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codehaus.groovy.runtime.StringBufferWriter;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
import com.dsasp.server.common.core.FlowDefinition;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
|
||||
public class BaseFlowConvert {
|
||||
|
||||
public static String convertToXml(Flow flow){
|
||||
Document doc = DocumentHelper.createDocument();
|
||||
Element root = createRoot(doc, flow.getKey());
|
||||
createInputs(root, flow.getInputs());
|
||||
createNode(root, flow);
|
||||
createOutputs(root, flow.getOutputs());
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
Writer out = new StringBufferWriter(buffer);
|
||||
XMLWriter writer = new XMLWriter(out, format);
|
||||
try{
|
||||
writer.write(doc);
|
||||
}catch(Exception ex){
|
||||
|
||||
throw new RuntimeException("格式有误");
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* create flow root
|
||||
* @param doc
|
||||
* @param flow
|
||||
* @return
|
||||
*/
|
||||
public static Element createRoot(Document doc, String flowId){
|
||||
Element root = doc.addElement("flow");
|
||||
root.addAttribute("id", flowId);
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* create input field
|
||||
* @param root
|
||||
* @param fields
|
||||
*/
|
||||
public static void createInputs(Element root, Field[] fields){
|
||||
Element input = root.addElement("input");
|
||||
if(fields != null && fields.length > 0){
|
||||
for(Field field : fields){
|
||||
Element fieldElement = input.addElement("field");
|
||||
fieldElement.addAttribute("name", field.getName());
|
||||
fieldElement.addAttribute("type", field.getType());
|
||||
fieldElement.addAttribute("required", ((Boolean)field.isRequired()).toString());
|
||||
fieldElement.addAttribute("initValue", field.getInitValue());
|
||||
fieldElement.addAttribute("initExpression", field.getInitExpression());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create output field
|
||||
* @param root
|
||||
* @param fields
|
||||
*/
|
||||
public static void createOutputs(Element root, Field[] fields){
|
||||
Element input = root.addElement("output");
|
||||
if(fields != null && fields.length > 0){
|
||||
for(Field field : fields){
|
||||
Element fieldElement = input.addElement("field");
|
||||
fieldElement.addAttribute("name", field.getName());
|
||||
fieldElement.addAttribute("type", field.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create node in order
|
||||
* @param root
|
||||
* @param flow
|
||||
*/
|
||||
public static void createNode(Element root, Flow flow) {
|
||||
List<Node> list = flow.getNodes();
|
||||
for (Node node : list) {
|
||||
Element element = null;
|
||||
if (node instanceof Start) {
|
||||
element = root.addElement("start");
|
||||
} else if (node instanceof End) {
|
||||
element = root.addElement("end");
|
||||
} else {
|
||||
element = root.addElement("node");
|
||||
}
|
||||
element.addAttribute("id", node.getId());
|
||||
element.addAttribute("name", node.getName());
|
||||
if(Node.SERVICE_TYPE.equals(node.getType())){
|
||||
createServiceBean(element, node.getBean());
|
||||
}else if(Node.SCRIPT_TYPE.equals(node.getType())){
|
||||
createScript(element, node.getScript());
|
||||
}else{
|
||||
createProcedure(element, node.getProcedure());
|
||||
}
|
||||
if (!(node instanceof End)) {
|
||||
createTransition(root, flow.getTransitions(node.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void createServiceBean(Element nodeEle,
|
||||
ServiceBean serviceBean) {
|
||||
if (serviceBean != null) {
|
||||
Element service = nodeEle.addElement("service");
|
||||
service.addAttribute("beanName", serviceBean.getBeanName());
|
||||
service.addAttribute("method", serviceBean.getMethod());
|
||||
Element list = service.addElement("list");
|
||||
for (String arg : serviceBean.getArgs()) {
|
||||
Element argEle = list.addElement("arg");
|
||||
argEle.addAttribute("name", arg);
|
||||
}
|
||||
Element resultEle = service.addElement("result");
|
||||
resultEle.addAttribute("name", serviceBean.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
private static void createScript(Element nodeEle, Script script) {
|
||||
if (script != null) {
|
||||
Element scriptEle = nodeEle.addElement("script");
|
||||
scriptEle.addAttribute("type", script.getType());
|
||||
scriptEle.addAttribute("key", script.getKey());
|
||||
scriptEle.addAttribute("executeExpression", script.getExecuteExpression());
|
||||
scriptEle.addCDATA(script.getScrip());
|
||||
}
|
||||
}
|
||||
|
||||
private static void createProcedure(Element nodeEle,
|
||||
Procedure procedure) {
|
||||
if (procedure != null) {
|
||||
Element proc = nodeEle.addElement("procedure");
|
||||
proc.addAttribute("procedureName", procedure.getName());
|
||||
Element list = proc.addElement("inputs");
|
||||
for (String arg : procedure.getInputFields()) {
|
||||
Element argEle = list.addElement("arg");
|
||||
argEle.addAttribute("name", arg);
|
||||
}
|
||||
Element outList = proc.addElement("outputs");
|
||||
for (String arg : procedure.getOutFields()) {
|
||||
Element argEle = outList.addElement("arg");
|
||||
argEle.addAttribute("name", arg);
|
||||
}
|
||||
Element resultEle = proc.addElement("result");
|
||||
resultEle.addAttribute("name", procedure.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create transition in order
|
||||
* @param root
|
||||
* @param list
|
||||
*/
|
||||
public static void createTransition(Element root, List<Transition> list){
|
||||
for(Transition transition : list){
|
||||
Element ele = root.addElement("transition");
|
||||
ele.addAttribute("from", transition.getFrom());
|
||||
ele.addAttribute("to", transition.getTo());
|
||||
ele.addAttribute("conditionExpression", transition.getConditionExpression());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* convert to map
|
||||
* @param flow
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> converFlowToMap(FlowDefinition<Field> flow){
|
||||
if(flow != null){
|
||||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("SYS_SERVICEFLOW_ID", flow.getKey());
|
||||
// map.put("KEY", flow.getKey());
|
||||
map.put("DISPLAYNAME", flow.getDisplayName());
|
||||
map.put("CONTENTXML", flow.getFlow());
|
||||
map.put("ENTITYID", flow.getEntityId());
|
||||
map.put("ISCONTROL", flow.isControl());
|
||||
map.put("ISUPDATEABLE", flow.isUpdateable());
|
||||
return map;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Flow convertPOToFlow(GeneralPOJO po){
|
||||
if(po != null && TABLENAME.equals(po.get_TableName())){
|
||||
Flow flow = new Flow((String)po.get_Value(SYS_SERVICEFLOW_ID), (String)po.get_Value(CONTENTXML));
|
||||
// flow.setSysFlowServiceId((String)po.get_Value(SYS_SERVICEFLOW_ID));
|
||||
flow.setDisplayName((String)po.get_Value(DISPLAYNAME));
|
||||
flow.setEntityId((String)po.get_Value(ENTITYID));
|
||||
flow.setControl(po.get_ValueAsBoolean(ISCONTROL));
|
||||
flow.setUpdateable(po.get_ValueAsBoolean(ISUPDATEABLE));
|
||||
flow.initial();
|
||||
return flow;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final String SYS_SERVICEFLOW_ID = "SYS_SERVICEFLOW_ID";
|
||||
// public static final String KEY = "KEY";
|
||||
public static final String DISPLAYNAME = "DISPLAYNAME";
|
||||
public static final String CONTENTXML = "CONTENTXML";
|
||||
public static final String ENTITYID = "ENTITYID";
|
||||
public static final String ISCONTROL = "ISCONTROL";
|
||||
public static final String ISUPDATEABLE = "ISUPDATEABLE";
|
||||
public static final String TABLENAME = "SYS_SERVICEFLOW";
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.dsasp.server.common.core.FlowDefinition;
|
||||
import com.dsasp.server.common.dataDic.bean.AbstractPOJOInfo;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.bean.POJOInfo;
|
||||
|
||||
public class DefaultFlowHelper{
|
||||
|
||||
public static List<FlowDefinition> getDefaultFlowService(String tableName, String entityId, String displayName){
|
||||
List<FlowDefinition> list = new ArrayList<FlowDefinition>();
|
||||
list.add(getDefaultAdd(tableName, entityId, displayName));
|
||||
list.add(getDefaultDelete(tableName, entityId, displayName));
|
||||
list.add(getDefaultUpdate(tableName, entityId, displayName));
|
||||
list.add(getDefaultSearch(tableName, entityId, displayName));
|
||||
list.add(getDefaultLoad(tableName, entityId, displayName));
|
||||
|
||||
POJOInfo poInfo = AbstractPOJOInfo.getPOInfo(tableName);
|
||||
if(poInfo.getColumnIndexByName(GeneralPOJO.STATUS) > 0){
|
||||
list.add(getDefaultSubmit(tableName, entityId, displayName));
|
||||
list.add(getDefaultSaveAndSubmit(tableName, entityId, displayName));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* entity save service flow
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public static FlowDefinition getDefaultAdd(String tableName, String entityId, String displayName){
|
||||
Flow flow = new Flow(tableName + "_ADD", null);
|
||||
flow.setEntityId(entityId);
|
||||
flow.setDisplayName(displayName + "新增");
|
||||
// inputs
|
||||
flow.addInputField("map", "java.util.Map", "true", null, null);
|
||||
flow.addInputField("ctx", "java.util.Properties", "true", null, null);
|
||||
flow.addInputField("tableName", "java.lang.String", "true", tableName,
|
||||
null);
|
||||
|
||||
// start
|
||||
String startId = "Start";
|
||||
Start start = new Start(startId, "开始");
|
||||
Script script = new Script();
|
||||
script.setKey(UUID.randomUUID().toString());
|
||||
script.setType("groovy");
|
||||
start.setScript(script);
|
||||
flow.setStart(start);
|
||||
// node
|
||||
String saveId = "save";
|
||||
Node node = new Node();
|
||||
node.setId(saveId);
|
||||
node.setName("保存");
|
||||
ServiceBean bean = new ServiceBean("pojoCRUDService", "save");
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add("map");
|
||||
args.add("tableName");
|
||||
args.add("ctx");
|
||||
bean.setArgs(args);
|
||||
bean.setResult("result");
|
||||
node.setBean(bean);
|
||||
flow.addNode(saveId, node);
|
||||
|
||||
// end
|
||||
String endId = "End";
|
||||
End end = new End(endId, "结束");
|
||||
flow.addNode(endId, end);
|
||||
|
||||
// transition
|
||||
flow.addTransition(startId, saveId, null);
|
||||
flow.addTransition(saveId, endId, null);
|
||||
|
||||
// outputs
|
||||
flow.addOutput("result", "com.dsasp.server.common.dataDic.bean.GeneralPOJO", "false");
|
||||
|
||||
flow.setFlow(BaseFlowConvert.convertToXml(flow));
|
||||
|
||||
return flow;
|
||||
}
|
||||
|
||||
/**
|
||||
* entity update service flow
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public static FlowDefinition getDefaultUpdate(String tableName, String entityId, String displayName){
|
||||
Flow flow = new Flow(tableName + "_UPDATE", null);
|
||||
flow.setEntityId(entityId);
|
||||
flow.setDisplayName(displayName + "更新");
|
||||
//inputs
|
||||
flow.addInputField("map", "java.util.Map", "true", null, null);
|
||||
flow.addInputField("ctx", "java.util.Properties", "true", null, null);
|
||||
flow.addInputField("tableName", "java.lang.String", "true", tableName, null);
|
||||
|
||||
//start
|
||||
String startId = "Start";
|
||||
Start start = new Start(startId, "开始");
|
||||
Script script = new Script();
|
||||
script.setKey(UUID.randomUUID().toString());
|
||||
script.setType("groovy");
|
||||
start.setScript(script);
|
||||
flow.setStart(start);
|
||||
//node
|
||||
String updateId = "update";
|
||||
Node node = new Node();
|
||||
node.setId(updateId);
|
||||
node.setName("更新");
|
||||
ServiceBean bean = new ServiceBean("pojoCRUDService", "update");
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add("map");
|
||||
args.add("tableName");
|
||||
args.add("ctx");
|
||||
bean.setArgs(args);
|
||||
bean.setResult("result");
|
||||
node.setBean(bean);
|
||||
flow.addNode(updateId, node);
|
||||
|
||||
//end
|
||||
String endId = "End";
|
||||
End end = new End(endId, "结束");
|
||||
flow.addNode(endId, end);
|
||||
|
||||
//transition
|
||||
flow.addTransition(startId, updateId, null);
|
||||
flow.addTransition(updateId, endId, null);
|
||||
|
||||
//outputs
|
||||
flow.addOutput("result", "com.dsasp.server.common.dataDic.bean.GeneralPOJO", null);
|
||||
flow.setFlow(BaseFlowConvert.convertToXml(flow));
|
||||
return flow;
|
||||
}
|
||||
|
||||
/**
|
||||
* entity search service flow
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public static FlowDefinition getDefaultSearch(String tableName, String entityId, String displayName){
|
||||
Flow flow = new Flow(tableName + "_SEARCH", null);
|
||||
flow.setEntityId(entityId);
|
||||
flow.setDisplayName(displayName + "查询");
|
||||
//inputs
|
||||
flow.addInputField("map", "java.util.Map", "true", null, null);
|
||||
flow.addInputField("ctx", "java.util.Properties", "true", null, null);
|
||||
flow.addInputField("tableName", "java.lang.String", "true", tableName, null);
|
||||
|
||||
//start
|
||||
String startId = "Start";
|
||||
Start start = new Start(startId, "开始");
|
||||
Script script = new Script();
|
||||
script.setType("groovy");
|
||||
script.setScrip("import com.dsasp.server.common.dataDic.service.POJOCRUDService; \n if(!map.containsKey(POJOCRUDService.ORDER)){\n map.put(POJOCRUDService.ORDER, \"order by P.CREATETIME DESC\") \n }");
|
||||
script.setKey(UUID.randomUUID().toString());
|
||||
start.setScript(script);
|
||||
flow.setStart(start);
|
||||
//node
|
||||
String searchId = "search";
|
||||
Node node = new Node();
|
||||
node.setId(searchId);
|
||||
node.setName("查询");
|
||||
ServiceBean bean = new ServiceBean("pojoCRUDService", "listSelect");
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add("map");
|
||||
args.add("tableName");
|
||||
args.add("ctx");
|
||||
bean.setArgs(args);
|
||||
bean.setResult("result");
|
||||
node.setBean(bean);
|
||||
flow.addNode(searchId, node);
|
||||
|
||||
//end
|
||||
String endId = "End";
|
||||
End end = new End(endId, "结束");
|
||||
flow.addNode(endId, end);
|
||||
|
||||
//transition
|
||||
flow.addTransition(startId, searchId, null);
|
||||
flow.addTransition(searchId, endId, null);
|
||||
|
||||
//outputs
|
||||
flow.addOutput("result", "java.util.Map", null);
|
||||
flow.setControl(false);
|
||||
flow.setFlow(BaseFlowConvert.convertToXml(flow));
|
||||
return flow;
|
||||
}
|
||||
|
||||
/**
|
||||
* entity delete service flow
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public static FlowDefinition getDefaultDelete(String tableName, String entityId, String displayName){
|
||||
Flow flow = new Flow(tableName + "_DELETE", null);
|
||||
flow.setEntityId(entityId);
|
||||
flow.setDisplayName(displayName + "删除");
|
||||
//inputs
|
||||
String entity_Id = tableName + "_ID";
|
||||
flow.addInputField(entity_Id, "java.lang.String", "true", null, null);
|
||||
flow.addInputField("ctx", "java.util.Properties", "true", null, null);
|
||||
flow.addInputField("tableName", "java.lang.String", "true", tableName, null);
|
||||
|
||||
//start
|
||||
String startId = "Start";
|
||||
Start start = new Start(startId, "开始");
|
||||
Script script = new Script();
|
||||
script.setKey(UUID.randomUUID().toString());
|
||||
script.setType("groovy");
|
||||
start.setScript(script);
|
||||
flow.setStart(start);
|
||||
//node
|
||||
String deleteId = "delete";
|
||||
Node node = new Node();
|
||||
node.setId(deleteId);
|
||||
node.setName("删除");
|
||||
ServiceBean bean = new ServiceBean("pojoCRUDService", "delete");
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add(entity_Id);
|
||||
args.add("tableName");
|
||||
args.add("ctx");
|
||||
bean.setArgs(args);
|
||||
bean.setResult("result");
|
||||
node.setBean(bean);
|
||||
flow.addNode(deleteId, node);
|
||||
|
||||
//end
|
||||
String endId = "End";
|
||||
End end = new End(endId, "结束");
|
||||
flow.addNode(endId, end);
|
||||
|
||||
//transition
|
||||
flow.addTransition(startId, deleteId, null);
|
||||
flow.addTransition(deleteId, endId, null);
|
||||
|
||||
//outputs
|
||||
flow.addOutput("result", "com.dsasp.server.common.dataDic.bean.GeneralPOJO", null);
|
||||
flow.setFlow(BaseFlowConvert.convertToXml(flow));
|
||||
return flow;
|
||||
}
|
||||
|
||||
/**
|
||||
* entity delete service flow
|
||||
* @param tableName
|
||||
* @return
|
||||
*/
|
||||
public static FlowDefinition getDefaultLoad(String tableName, String entityId, String displayName){
|
||||
Flow flow = new Flow(tableName + "_LOAD", null);
|
||||
flow.setEntityId(entityId);
|
||||
flow.setDisplayName(displayName + "加载");
|
||||
//inputs
|
||||
String entity_Id = tableName + "_ID";
|
||||
flow.addInputField(entity_Id, "java.lang.String", "true", null, null);
|
||||
flow.addInputField("ctx", "java.util.Properties", "true", null, null);
|
||||
flow.addInputField("tableName", "java.lang.String", "true", tableName, null);
|
||||
flow.addInputField("isHierarchical", "java.lang.Boolean", null, "true", null);
|
||||
|
||||
//start
|
||||
String startId = "Start";
|
||||
Start start = new Start(startId, "开始");
|
||||
Script script = new Script();
|
||||
script.setKey(UUID.randomUUID().toString());
|
||||
script.setType("groovy");
|
||||
start.setScript(script);
|
||||
flow.setStart(start);
|
||||
//node
|
||||
String loadId = "load";
|
||||
Node node = new Node();
|
||||
node.setId(loadId);
|
||||
node.setName("加载");
|
||||
ServiceBean bean = new ServiceBean("pojoCRUDService", "loadPOJO");
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add(entity_Id);
|
||||
args.add("tableName");
|
||||
args.add("ctx");
|
||||
args.add("isHierarchical");
|
||||
bean.setArgs(args);
|
||||
bean.setResult("result");
|
||||
node.setBean(bean);
|
||||
flow.addNode(loadId, node);
|
||||
|
||||
//end
|
||||
String endId = "End";
|
||||
End end = new End(endId, "结束");
|
||||
flow.addNode(endId, end);
|
||||
|
||||
//transition
|
||||
flow.addTransition(startId, loadId, null);
|
||||
flow.addTransition(loadId, endId, null);
|
||||
|
||||
//outputs
|
||||
flow.addOutput("result", "com.dsasp.server.common.dataDic.bean.GeneralPOJO", null);
|
||||
flow.setControl(false);
|
||||
flow.setFlow(BaseFlowConvert.convertToXml(flow));
|
||||
return flow;
|
||||
}
|
||||
|
||||
public static FlowDefinition getDefaultSubmit(String tableName, String entityId, String displayName){
|
||||
Flow flow = new Flow(tableName + "_SUBMIT", null);
|
||||
flow.setEntityId(entityId);
|
||||
flow.setDisplayName(displayName + "提交审批");
|
||||
//inputs
|
||||
flow.addInputField("map", "java.util.Map", "true", null, null);
|
||||
flow.addInputField("ctx", "java.util.Properties", "true", null, null);
|
||||
flow.addInputField("tableName", "java.lang.String", "true", tableName, null);
|
||||
flow.addInputField("businessKey", "java.lang.String", "false", null, null);
|
||||
flow.addInputField("processName", "java.lang.String", "true", displayName, null);
|
||||
|
||||
//start
|
||||
String startId = "Start";
|
||||
Start start = new Start(startId, "开始");
|
||||
Script script = new Script();
|
||||
script.setKey(UUID.randomUUID().toString());
|
||||
script.setType("groovy");
|
||||
script.setScrip("import com.dsasp.server.common.exception.ValidationException;\n " +
|
||||
"import com.dsasp.server.common.workflow.service.ProcessCoreService; \n " +
|
||||
"businessKey = map.get('"+tableName+"_ID');\n" +
|
||||
"def pojo = GetServicesFunction.loadPOJO(businessKey,tableName,false);\n" +
|
||||
"if(pojo == null){\n" +
|
||||
" throw new ValidationException('该记录已经被删除,请重新选择!');\n" +
|
||||
"} \n"+
|
||||
"map.put(ProcessCoreService.PROCESSTITLE, '"+displayName+"'); \n" +
|
||||
"map.put(ProcessCoreService.PROCESSTASKTYPE, 10);\n"
|
||||
);
|
||||
start.setScript(script);
|
||||
flow.setStart(start);
|
||||
//node
|
||||
String startWorkflow = "startWorkflow";
|
||||
Node node = new Node();
|
||||
node.setId(startWorkflow);
|
||||
node.setName("启动流程");
|
||||
ServiceBean bean = new ServiceBean("processCoreService", "startWorkflow");
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add("processName");
|
||||
args.add("map");
|
||||
args.add("tableName");
|
||||
args.add("businessKey");
|
||||
args.add("ctx");
|
||||
bean.setArgs(args);
|
||||
bean.setResult("result");
|
||||
node.setBean(bean);
|
||||
flow.addNode(startWorkflow, node);
|
||||
|
||||
//end
|
||||
String endId = "End";
|
||||
End end = new End(endId, "结束");
|
||||
flow.addNode(endId, end);
|
||||
|
||||
//transition
|
||||
flow.addTransition(startId, startWorkflow, null);
|
||||
flow.addTransition(startWorkflow, endId, null);
|
||||
|
||||
//outputs
|
||||
flow.addOutput("result", "java.lang.Object", null);
|
||||
flow.setFlow(BaseFlowConvert.convertToXml(flow));
|
||||
return flow;
|
||||
}
|
||||
|
||||
public static FlowDefinition getDefaultSaveAndSubmit(String tableName, String entityId, String displayName){
|
||||
Flow flow = new Flow(tableName + "_SAVE_AND_SUBMIT", null);
|
||||
flow.setEntityId(entityId);
|
||||
flow.setDisplayName(displayName + "保存并提交审批");
|
||||
//inputs
|
||||
flow.addInputField("map", "java.util.Map", "true", null, null);
|
||||
flow.addInputField("ctx", "java.util.Properties", "true", null, null);
|
||||
flow.addInputField("tableName", "java.lang.String", "true", tableName, null);
|
||||
flow.addInputField(tableName+"_ADD", "java.lang.String", "true", tableName+"_ADD", null);
|
||||
flow.addInputField(tableName+"_UPDATE", "java.lang.String", "true", tableName+"_UPDATE", null);
|
||||
flow.addInputField(tableName+"_SUBMIT", "java.lang.String", "true", tableName+"_SUBMIT", null);
|
||||
|
||||
//start
|
||||
String startId = "Start";
|
||||
Start start = new Start(startId, "开始");
|
||||
Script script = new Script();
|
||||
script.setKey(UUID.randomUUID().toString());
|
||||
script.setType("groovy");
|
||||
script.setScrip("isSave = map.get('"+tableName+"_ID') == null;\n"+
|
||||
"if(isSave){"+
|
||||
" map.put('"+tableName+"_ID',GetDefaultValueFunction.guid());\n"+
|
||||
"}"
|
||||
);
|
||||
start.setScript(script);
|
||||
flow.setStart(start);
|
||||
//node
|
||||
String save = "save";
|
||||
Node saveNode = new Node();
|
||||
saveNode.setId(save);
|
||||
saveNode.setName("保存");
|
||||
ServiceBean bean = new ServiceBean("flowExcuteService", "excute");
|
||||
List<String> args = new ArrayList<String>();
|
||||
args.add("map");
|
||||
args.add("ctx");
|
||||
args.add(tableName+"_ADD");
|
||||
bean.setArgs(args);
|
||||
bean.setResult(null);
|
||||
saveNode.setBean(bean);
|
||||
flow.addNode(save, saveNode);
|
||||
|
||||
//node
|
||||
String update = "update";
|
||||
Node updateNode = new Node();
|
||||
updateNode.setId(update);
|
||||
updateNode.setName("更新");
|
||||
ServiceBean updateBean = new ServiceBean("flowExcuteService", "excute");
|
||||
List<String> updateArgs = new ArrayList<String>();
|
||||
updateArgs.add("map");
|
||||
updateArgs.add("ctx");
|
||||
updateArgs.add(tableName+"_UPDATE");
|
||||
updateBean.setArgs(updateArgs);
|
||||
updateBean.setResult(null);
|
||||
updateNode.setBean(updateBean);
|
||||
flow.addNode(update, updateNode);
|
||||
|
||||
String submitFlow = "submitFlow";
|
||||
Node flowNode = new Node();
|
||||
flowNode.setId(submitFlow);
|
||||
flowNode.setName("启动流程");
|
||||
ServiceBean flowBean = new ServiceBean("flowExcuteService", "excute");
|
||||
List<String> flowArgs = new ArrayList<String>();
|
||||
flowArgs.add("map");
|
||||
flowArgs.add("ctx");
|
||||
flowArgs.add(tableName+"_SUBMIT");
|
||||
flowBean.setArgs(flowArgs);
|
||||
flowBean.setResult(null);
|
||||
flowNode.setBean(flowBean);
|
||||
flow.addNode(submitFlow, flowNode);
|
||||
|
||||
//end
|
||||
String endId = "End";
|
||||
End end = new End(endId, "结束");
|
||||
flow.addNode(endId, end);
|
||||
|
||||
//transition
|
||||
flow.addTransition(startId, save, "${isSave}");
|
||||
flow.addTransition(startId, update, "${isSave==false}");
|
||||
flow.addTransition(save, submitFlow, null);
|
||||
flow.addTransition(update, submitFlow, null);
|
||||
flow.addTransition(submitFlow, endId, null);
|
||||
|
||||
//outputs
|
||||
flow.addOutput("result", "java.lang.Object", null);
|
||||
flow.setFlow(BaseFlowConvert.convertToXml(flow));
|
||||
return flow;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
public class End extends Node {
|
||||
|
||||
public End(String id, String name){
|
||||
super(id, name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
public class Field {
|
||||
|
||||
/**
|
||||
* invalidate, supporting role
|
||||
*/
|
||||
private Object itemId;
|
||||
private String name;
|
||||
private String type;
|
||||
private boolean required;
|
||||
private String initValue;
|
||||
private String initExpression;
|
||||
|
||||
public Field(){
|
||||
|
||||
}
|
||||
|
||||
public Field(String name , String type, boolean required, String initValue, String initExpression){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.required = required;
|
||||
this.initValue = initValue;
|
||||
this.initExpression = initExpression;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean isRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public void setRequired(boolean required) {
|
||||
this.required = required;
|
||||
}
|
||||
|
||||
public String getInitValue() {
|
||||
return initValue;
|
||||
}
|
||||
|
||||
public void setInitValue(String initValue) {
|
||||
this.initValue = initValue;
|
||||
}
|
||||
|
||||
public String getInitExpression() {
|
||||
return initExpression;
|
||||
}
|
||||
|
||||
public void setInitExpression(String initExpression) {
|
||||
this.initExpression = initExpression;
|
||||
}
|
||||
|
||||
public Object getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public void setItemId(Object itemId) {
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,546 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import com.dsasp.server.common.core.FlowDefinition;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
import com.dsasp.server.core.service.script.FlowScriptBindings;
|
||||
|
||||
public class Flow implements FlowDefinition<Field>{
|
||||
|
||||
private String key;
|
||||
|
||||
|
||||
private String flow;
|
||||
|
||||
private String displayName;
|
||||
|
||||
private boolean isControl = true;
|
||||
|
||||
private boolean isUpdateable = true;
|
||||
|
||||
// private String sysFlowServiceId;
|
||||
|
||||
|
||||
|
||||
private String entityId;
|
||||
|
||||
private boolean initial = false;
|
||||
|
||||
private static final String START = "Start";
|
||||
|
||||
private HashMap<String, Node> nodes = new HashMap<String, Node>();
|
||||
|
||||
private HashMap<String, List<Transition>> transitions = new HashMap<String, List<Transition>>();
|
||||
|
||||
private HashMap<String, List<Transition>> toTransitions = new HashMap<String, List<Transition>>();
|
||||
|
||||
private HashMap<String, Field> inputs = new HashMap<String, Field>();
|
||||
|
||||
private HashMap<String, Field> outputs = new HashMap<String, Field>();
|
||||
|
||||
private FlowScriptBindings bindings;
|
||||
|
||||
public Flow(String key, String flow){
|
||||
this.key = key;
|
||||
this.flow = flow;
|
||||
}
|
||||
|
||||
public Flow initial(){
|
||||
if (!initial && !StringUtil.isEmpty(flow)) {
|
||||
SAXReader saxreader = new SAXReader();
|
||||
try {
|
||||
Document doc = saxreader.read(new StringReader(flow));
|
||||
parseInput(doc);
|
||||
parseStart(doc);
|
||||
parseNodes(doc);
|
||||
parseTransition(doc);
|
||||
parseOutputs(doc);
|
||||
parseEnd(doc);
|
||||
// createFlowScriptBindings(map, ctx);
|
||||
initial = true;
|
||||
} catch (DocumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setFlow(String flow) {
|
||||
this.flow = flow;
|
||||
initial = false;
|
||||
}
|
||||
|
||||
private void parseInput(Document doc){
|
||||
List<Element> input = (List<Element>) (List<?>) doc.selectNodes("//flow/input/field");
|
||||
if (input != null && input.size() > 0) {
|
||||
for (Element e : input) {
|
||||
String name = e.attributeValue("name");
|
||||
String type = e.attributeValue("type");
|
||||
String required = e.attributeValue("required");
|
||||
String initValue = e.attributeValue("initValue");
|
||||
String initExpression = e.attributeValue("initExpression");
|
||||
addInputField(name, type, required, initValue, initExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseStart(Document doc) {
|
||||
List<Element> startEle = (List<Element>) (List<?>) doc.selectNodes("//flow/start");
|
||||
if (startEle != null && startEle.size() == 1) {
|
||||
Element e = startEle.get(0);
|
||||
String name = e.attributeValue("name");
|
||||
String id = e.attributeValue("id");
|
||||
Start start = new Start(id, name);
|
||||
ServiceBean bean = parseServiceBean(e);
|
||||
start.setBean(bean);
|
||||
Script script = parseScript(e);
|
||||
start.setScript(script);
|
||||
setStart(start);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseEnd(Document doc) {
|
||||
List<Element> endEle = (List<Element>) (List<?>) doc.selectNodes("//flow/end");
|
||||
if (endEle != null && endEle.size() == 1) {
|
||||
Element e = endEle.get(0);
|
||||
String name = e.attributeValue("name");
|
||||
String id = e.attributeValue("id");
|
||||
End end = new End(id, name);
|
||||
ServiceBean bean = parseServiceBean(e);
|
||||
end.setBean(bean);
|
||||
Script script = parseScript(e);
|
||||
end.setScript(script);
|
||||
addNode(id, end);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseNodes(Document doc){
|
||||
List<Element> nodeEles = (List<Element>) (List<?>) doc.selectNodes("//flow/node");
|
||||
if (nodeEles != null && nodeEles.size() > 0) {
|
||||
for (Element e : nodeEles) {
|
||||
String name = e.attributeValue("name");
|
||||
String id = e.attributeValue("id");
|
||||
Node node = new Node(id, name);
|
||||
ServiceBean bean = parseServiceBean(e);
|
||||
node.setBean(bean);
|
||||
Script script = parseScript(e);
|
||||
node.setScript(script);
|
||||
Procedure procedure = parseProcedure(e);
|
||||
node.setProcedure(procedure);
|
||||
addNode(id, node);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ServiceBean parseServiceBean(Element e){
|
||||
List<Element> list = (List<Element>) (List<?>) e.selectNodes(e.getUniquePath() + "/service");
|
||||
if(list != null && list.size() == 1){
|
||||
Element echild = list.get(0);
|
||||
String method = echild.attributeValue("method");
|
||||
String beanName = echild.attributeValue("beanName");
|
||||
ServiceBean serviceBean = new ServiceBean(beanName, method);
|
||||
|
||||
//set args
|
||||
List<Element> argsEle = (List<Element>) (List<?>) e.selectNodes(e.getUniquePath() + "/service/list/arg");
|
||||
if(argsEle != null && argsEle.size() > 0){
|
||||
List<String> args = new ArrayList<String>();
|
||||
for(int i = 0; i < argsEle.size(); i++){
|
||||
Element argEle = argsEle.get(i);
|
||||
args.add(argEle.attributeValue("name"));
|
||||
}
|
||||
serviceBean.setArgs(args);
|
||||
}
|
||||
|
||||
//set result
|
||||
List<Element> resultEle = (List<Element>) (List<?>) e.selectNodes(e.getUniquePath() + "/service/result");
|
||||
if(resultEle != null && resultEle.size() == 1){
|
||||
serviceBean.setResult(resultEle.get(0).attributeValue("name"));
|
||||
}
|
||||
return serviceBean;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Script parseScript(Element e){
|
||||
List<Element> list = (List<Element>) (List<?>) e.selectNodes(e.getUniquePath() + "/script");
|
||||
if(list != null && list.size() == 1){
|
||||
Element echild = list.get(0);
|
||||
Script script = new Script();
|
||||
script.setType(echild.attributeValue("type"));
|
||||
script.setKey(echild.attributeValue("key"));
|
||||
script.setExecuteExpression(echild.attributeValue("executeExpression"));
|
||||
if(StringUtil.isEmpty(script.getKey())){
|
||||
script.setKey(UUID.randomUUID().toString());
|
||||
}
|
||||
script.setScrip(echild.getText());
|
||||
return script;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Procedure parseProcedure(Element e){
|
||||
List<Element> list = (List<Element>) (List<?>) e.selectNodes(e.getUniquePath() + "/procedure");
|
||||
if(list != null && list.size() == 1){
|
||||
Element echild = list.get(0);
|
||||
String procedureName = echild.attributeValue("procedureName");
|
||||
Procedure procedure = new Procedure();
|
||||
procedure.setName(procedureName);
|
||||
|
||||
//set args
|
||||
List<Element> argsEle = (List<Element>) (List<?>) e.selectNodes(e.getUniquePath() + "/procedure/inputs/arg");
|
||||
if(argsEle != null && argsEle.size() > 0){
|
||||
List<String> args = new ArrayList<String>();
|
||||
for(int i = 0; i < argsEle.size(); i++){
|
||||
Element argEle = argsEle.get(i);
|
||||
args.add(argEle.attributeValue("name"));
|
||||
}
|
||||
procedure.setInputFields(args);
|
||||
}
|
||||
|
||||
//
|
||||
List<Element> outArgsEle = (List<Element>) (List<?>) e.selectNodes(e.getUniquePath() + "/procedure/outputs/arg");
|
||||
if(outArgsEle != null && outArgsEle.size() > 0){
|
||||
List<String> args = new ArrayList<String>();
|
||||
for(int i = 0; i < outArgsEle.size(); i++){
|
||||
Element argEle = outArgsEle.get(i);
|
||||
args.add(argEle.attributeValue("name"));
|
||||
}
|
||||
procedure.setOutFields(args);
|
||||
}
|
||||
|
||||
List<Element> resultEle = (List<Element>) (List<?>) e.selectNodes(e.getUniquePath() + "/procedure/result");
|
||||
if(resultEle != null && resultEle.size() == 1){
|
||||
procedure.setResult(resultEle.get(0).attributeValue("name"));
|
||||
}
|
||||
|
||||
return procedure;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void parseTransition(Document doc){
|
||||
List<Element> transitionEles = (List<Element>) (List<?>) doc.selectNodes("//flow/transition");
|
||||
if (transitionEles != null && transitionEles.size() > 0) {
|
||||
for (Element e : transitionEles) {
|
||||
String from = e.attributeValue("from");
|
||||
String to = e.attributeValue("to");
|
||||
String conditionExpression = e.attributeValue("conditionExpression");
|
||||
addTransition(from, to, conditionExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseOutputs(Document doc){
|
||||
List<Element> outputs = (List<Element>) (List<?>) doc.selectNodes("//flow/output/field");
|
||||
if (outputs != null && outputs.size() > 0) {
|
||||
for (Element e : outputs) {
|
||||
String name = e.attributeValue("name");
|
||||
String type = e.attributeValue("type");
|
||||
String required = e.attributeValue("required");
|
||||
addOutput(name, type, required);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addInputField(String name, String type, String required, String initValue, String initExpression){
|
||||
if(name != null && !name.equals("")){
|
||||
inputs.put(name, new Field(name, type, required == null ? false : (required.equals("true") ? true : false), initValue, initExpression));
|
||||
}
|
||||
}
|
||||
|
||||
public void addOutput(String name, String type, String required){
|
||||
if(name != null && !name.equals("")){
|
||||
outputs.put(name, new Field(name, type, required == null ? false : (required.equals("true") ? true : false), null, null));
|
||||
}
|
||||
}
|
||||
|
||||
public void addNode(String nodeId, Node node){
|
||||
nodes.put(nodeId, node);
|
||||
}
|
||||
|
||||
public void setStart(Start start){
|
||||
nodes.put(START, start);
|
||||
}
|
||||
|
||||
public Start getStart(){
|
||||
return (Start)nodes.get(START);
|
||||
}
|
||||
|
||||
public void addTransition(String from, String to, String conditionExpression){
|
||||
Transition transition = new Transition(from, to, conditionExpression);
|
||||
List<Transition> list = getTransitions(from);
|
||||
if(list == null){
|
||||
list = new ArrayList<Transition>();
|
||||
transitions.put(from, list);
|
||||
}
|
||||
list.add(transition);
|
||||
addToTransition(to, transition);
|
||||
}
|
||||
|
||||
public void addToTransition(String to, Transition transition){
|
||||
List<Transition> list = getTransitionByTo(to);
|
||||
if(list == null){
|
||||
list = new ArrayList<Transition>();
|
||||
toTransitions.put(to, list);
|
||||
}
|
||||
list.add(transition);
|
||||
}
|
||||
|
||||
public List<Transition> getTransitionByTo(String to){
|
||||
return toTransitions.get(to);
|
||||
}
|
||||
|
||||
public Node getNode(String nodeId) {
|
||||
return nodes.get(nodeId);
|
||||
}
|
||||
|
||||
|
||||
public List<Transition> getTransitions(String from) {
|
||||
return transitions.get(from);
|
||||
}
|
||||
|
||||
|
||||
public Field[] getInputs() {
|
||||
Field[] fields = new Field[inputs.size()];
|
||||
inputs.values().toArray(fields);
|
||||
return fields;
|
||||
}
|
||||
|
||||
public Field getInputField(String name){
|
||||
return inputs.get(name);
|
||||
}
|
||||
|
||||
|
||||
public Field[] getOutputs() {
|
||||
Collection<Field> col = outputs.values();
|
||||
Field[] fields = new Field[col.size()];
|
||||
col.toArray(fields);
|
||||
return fields;
|
||||
}
|
||||
|
||||
public Field getOutputField(String name){
|
||||
return outputs.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
// TODO Auto-generated method stub
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFlow() {
|
||||
// TODO Auto-generated method stub
|
||||
return flow;
|
||||
}
|
||||
|
||||
public void createFlowScriptBindings(Map map, Properties ctx){
|
||||
// if(bindings == null && map != null){
|
||||
bindings = new FlowScriptBindings(map, ctx);
|
||||
// }
|
||||
}
|
||||
|
||||
public FlowScriptBindings getBindings() {
|
||||
return bindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* get node list sequence
|
||||
* @return
|
||||
*/
|
||||
public List<Node> getNodes(){
|
||||
List<Node> list = new ArrayList<Node>();
|
||||
Start start = getStart();
|
||||
if (start != null) {
|
||||
list.add(start);
|
||||
addNextNode(start, list);
|
||||
}
|
||||
for(int i = list.size() - 1; i >= 0; i--){
|
||||
Node node = list.get(i);
|
||||
if(node instanceof End){
|
||||
return list;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("无效服务流定义");
|
||||
}
|
||||
|
||||
/**
|
||||
* get node's next node
|
||||
* @param node
|
||||
* @param nodes
|
||||
*/
|
||||
private void addNextNode(Node node, List<Node> nodes){
|
||||
List<Transition> list = getTransitions(node.getId());
|
||||
if (list == null) {
|
||||
System.err.println("错误的节点:" + node.getId() + ",\t" + node.getName());
|
||||
}
|
||||
for(Transition transition : list){
|
||||
Node toNode = getNode(transition.getTo());
|
||||
if(nodes.contains(toNode)){
|
||||
continue;
|
||||
}
|
||||
nodes.add(toNode);
|
||||
if(!(toNode instanceof End)){
|
||||
addNextNode(toNode, nodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove node
|
||||
* @param node
|
||||
* @param pre
|
||||
* @param after
|
||||
*/
|
||||
public void removeNode(Node node, Node pre, Node after){
|
||||
if(node instanceof Start || node instanceof End){
|
||||
throw new RuntimeException("开始节点或结束节点不能删除");
|
||||
} else {
|
||||
List<Transition> preTrans = getTransitions(pre.getId());
|
||||
List<Transition> nodeTrans = getTransitions(node.getId());
|
||||
List<Transition> toNodeTrans = getTransitionByTo(node.getId());
|
||||
if (preTrans.size() != 1 || nodeTrans.size() != 1 || toNodeTrans.size() != 1
|
||||
|| !preTrans.get(0).getTo().equals(node.getId())
|
||||
|| !nodeTrans.get(0).getTo().equals(after.getId())) {
|
||||
throw new RuntimeException("非线性服务流,请用高级配置进行编辑");
|
||||
} else {
|
||||
transitions.remove(pre.getId());
|
||||
transitions.remove(node.getId());
|
||||
toTransitions.remove(node.getId());
|
||||
toTransitions.remove(after.getId());
|
||||
addTransition(pre.getId(), after.getId(), null);
|
||||
nodes.remove(node.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param displayName
|
||||
*/
|
||||
public void insertNodeAfter(String preNodeId, Node node){
|
||||
List<Transition> list = getTransitions(preNodeId);
|
||||
if(list != null && list.size() == 1){
|
||||
Transition tran = list.get(0);
|
||||
String to = tran.getTo();
|
||||
List<Transition> toList = getTransitionByTo(to);
|
||||
if(toList != null && toList.size() == 1){
|
||||
transitions.remove(preNodeId);
|
||||
toTransitions.remove(to);
|
||||
addNode(node.getId(), node);
|
||||
addTransition(preNodeId, node.getId(), null);
|
||||
addTransition(node.getId(), to, null);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("非线性服务流,请用高级配置进行编辑");
|
||||
}
|
||||
|
||||
/**
|
||||
* clear all nodes and transitions, insert start and end node
|
||||
*/
|
||||
public void insertDefaultNode() {
|
||||
nodes.clear();
|
||||
transitions.clear();
|
||||
toTransitions.clear();
|
||||
Start start = new Start("Start", "开始");
|
||||
addNode(start.getId(), start);
|
||||
End end = new End("End", "结束");
|
||||
addNode(end.getId(), end);
|
||||
addTransition(start.getId(), end.getId(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* update input fields
|
||||
* @param displayName
|
||||
*/
|
||||
public void updateInputField(Collection<Field> fields){
|
||||
inputs.clear();
|
||||
Iterator<Field> iterator = fields.iterator();
|
||||
while(iterator.hasNext()){
|
||||
Field field = iterator.next();
|
||||
inputs.put(field.getName(), field);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* update input fields
|
||||
* @param displayName
|
||||
*/
|
||||
public void updateOutputField(Collection<Field> fields){
|
||||
outputs.clear();
|
||||
Iterator<Field> iterator = fields.iterator();
|
||||
while(iterator.hasNext()){
|
||||
Field field = iterator.next();
|
||||
outputs.put(field.getName(), field);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public void setControl(boolean isControl) {
|
||||
this.isControl = isControl;
|
||||
}
|
||||
|
||||
public void setEntityId(String entityId) {
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEntityId() {
|
||||
return this.entityId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isControl() {
|
||||
return isControl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdateable() {
|
||||
return isUpdateable;
|
||||
}
|
||||
|
||||
public void setUpdateable(boolean isUpdateable) {
|
||||
this.isUpdateable = isUpdateable;
|
||||
}
|
||||
|
||||
// public String getSysFlowServiceId() {
|
||||
// return sysFlowServiceId;
|
||||
// }
|
||||
//
|
||||
// public void setSysFlowServiceId(String sysFlowServiceId) {
|
||||
// this.sysFlowServiceId = sysFlowServiceId;
|
||||
// }
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
public class Node {
|
||||
|
||||
public static final String SCRIPT_TYPE = "script";
|
||||
|
||||
public static final String SERVICE_TYPE = "service";
|
||||
|
||||
public static final String PROCEDURE_TYPE = "procedure";
|
||||
|
||||
private String name;
|
||||
|
||||
private String id;
|
||||
|
||||
private ServiceBean bean;
|
||||
|
||||
private Script script;
|
||||
|
||||
private Procedure procedure;
|
||||
|
||||
private String type;
|
||||
|
||||
|
||||
public Node(){
|
||||
|
||||
}
|
||||
|
||||
public Node(String id, String name){
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Script getScript() {
|
||||
return script;
|
||||
}
|
||||
|
||||
public void setScript(Script script) {
|
||||
if(script != null){
|
||||
this.type = SCRIPT_TYPE;
|
||||
}
|
||||
this.script = script;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ServiceBean getBean() {
|
||||
return bean;
|
||||
}
|
||||
|
||||
public void setBean(ServiceBean bean) {
|
||||
if(bean != null){
|
||||
this.type = SERVICE_TYPE;
|
||||
}
|
||||
this.bean = bean;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Procedure getProcedure() {
|
||||
return procedure;
|
||||
}
|
||||
|
||||
public void setProcedure(Procedure procedure) {
|
||||
if(procedure != null){
|
||||
this.type = PROCEDURE_TYPE;
|
||||
}
|
||||
this.procedure = procedure;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Procedure {
|
||||
|
||||
private String name;
|
||||
|
||||
private List<String> inputFields;
|
||||
|
||||
private List<String> outFields;
|
||||
|
||||
private String result;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<String> getInputFields() {
|
||||
return inputFields;
|
||||
}
|
||||
|
||||
public void setInputFields(List<String> inputFields) {
|
||||
this.inputFields = inputFields;
|
||||
}
|
||||
|
||||
public List<String> getOutFields() {
|
||||
return outFields;
|
||||
}
|
||||
|
||||
public void setOutFields(List<String> outFields) {
|
||||
this.outFields = outFields;
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
public class Script {
|
||||
|
||||
private String type;
|
||||
|
||||
private String scrip;
|
||||
|
||||
private String key;
|
||||
|
||||
private String executeExpression;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getScrip() {
|
||||
return scrip;
|
||||
}
|
||||
|
||||
public void setScrip(String scrip) {
|
||||
this.scrip = scrip;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getExecuteExpression() {
|
||||
return executeExpression;
|
||||
}
|
||||
|
||||
public void setExecuteExpression(String executeExpression) {
|
||||
this.executeExpression = executeExpression;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ServiceBean {
|
||||
|
||||
private String beanName;
|
||||
|
||||
private String method;
|
||||
|
||||
private List<String> args;
|
||||
|
||||
private String result;
|
||||
|
||||
public ServiceBean(){
|
||||
|
||||
}
|
||||
|
||||
public ServiceBean(String beanName, String method){
|
||||
this.beanName = beanName;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getBeanName() {
|
||||
return beanName;
|
||||
}
|
||||
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public List<String> getArgs() {
|
||||
if(args == null){
|
||||
args = new ArrayList<String>();
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
public void setArgs(List<String> args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
public class Start extends Node {
|
||||
|
||||
public Start(String id, String name){
|
||||
super(id, name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.dsasp.server.core.service.flow.model;
|
||||
|
||||
public class Transition {
|
||||
|
||||
private String from;
|
||||
private String to;
|
||||
private String conditionExpression;
|
||||
|
||||
public Transition(){
|
||||
|
||||
}
|
||||
|
||||
public Transition(String from, String to, String conditionExpression){
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.conditionExpression = conditionExpression;
|
||||
}
|
||||
|
||||
public String getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public void setFrom(String from) {
|
||||
this.from = from;
|
||||
}
|
||||
|
||||
public String getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
public void setTo(String to) {
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public String getConditionExpression() {
|
||||
return conditionExpression;
|
||||
}
|
||||
|
||||
public void setConditionExpression(String conditionExpression) {
|
||||
this.conditionExpression = conditionExpression;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.dsasp.server.core.service.script;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.script.Bindings;
|
||||
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
public class FlowScriptBindings implements Bindings{
|
||||
|
||||
protected static final Set<String> UNSTORED_KEYS =
|
||||
new HashSet<String>(Arrays.asList("out", "out:print", "lang:import", "context", "elcontext", "print", "println", "map", "ctx"));
|
||||
|
||||
protected Map scriptResolvers;
|
||||
protected Properties ctx;
|
||||
|
||||
public FlowScriptBindings(Map map, Properties ctx) {
|
||||
this.scriptResolvers = map;
|
||||
if (ctx != null) {
|
||||
this.ctx = ctx;
|
||||
} else {
|
||||
this.ctx = UserSession.get();
|
||||
if (this.ctx == null) {
|
||||
this.ctx = new Properties();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsKey(Object key) {
|
||||
if ("map".equals(key) || "ctx".equals(key)
|
||||
|| scriptResolvers.containsKey(key) || ctx.contains(key)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object get(Object key) {
|
||||
if ("map".equals(key)) {
|
||||
return scriptResolvers;
|
||||
} else if ("ctx".equals(key)) {
|
||||
return ctx;
|
||||
} else if (scriptResolvers.containsKey(key)) {
|
||||
return scriptResolvers.get(key);
|
||||
} else if (ctx.contains(key)) {
|
||||
return ctx.get(key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object put(String name, Object value) {
|
||||
Object oldValue = null;
|
||||
if (!UNSTORED_KEYS.contains(name)) {
|
||||
oldValue = scriptResolvers.get(name);
|
||||
scriptResolvers.put(name, value);
|
||||
}
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
public Set<java.util.Map.Entry<String, Object>> entrySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
// return variableScope.getVariables().entrySet();
|
||||
}
|
||||
|
||||
public Set<String> keySet() {
|
||||
throw new UnsupportedOperationException();
|
||||
// return variableScope.getVariables().keySet();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
throw new UnsupportedOperationException();
|
||||
// return variableScope.getVariables().size();
|
||||
}
|
||||
|
||||
public Collection<Object> values() {
|
||||
throw new UnsupportedOperationException();
|
||||
// return variableScope.getVariables().values();
|
||||
}
|
||||
|
||||
public void putAll(Map< ? extends String, ? extends Object> toMerge) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Object remove(Object key) {
|
||||
if (UNSTORED_KEYS.contains(key)) {
|
||||
return null;
|
||||
}
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean containsValue(Object value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.dsasp.server.core.service.script;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.script.Bindings;
|
||||
import javax.script.Compilable;
|
||||
import javax.script.CompiledScript;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineFactory;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
// 适配(架构纪律):framework 原版用 org.activiti.engine.impl.scripting.JuelScriptEngineFactory 注册 juel 引擎。
|
||||
// 架构设计第二节裁定 activiti/Flowable 仅存在于独立工作流服务,禁止进入保真层运行时;
|
||||
// 故此处不引入 EOL 的 activiti-engine-5.14,改为按引擎名惰性注册 JSR-223 juel 引擎(在场则注册,不在场则跳过)。
|
||||
// groovy 路径与类签名逐字不变;juel(${...} 条件转移/initExpression)仅服务流带条件分支时触发,
|
||||
// D 类查询/报表服务流为线性流不走 juel,不受影响。带条件分支的服务流 juel 支持随 P3 工作流落地。
|
||||
// 详见 P1 服务流实测报告「替换类登记」与迁移手册新增坑位。
|
||||
|
||||
import com.dsasp.server.common.exception.PrivilegeException;
|
||||
import com.dsasp.server.common.exception.SameCodeException;
|
||||
import com.dsasp.server.common.exception.ValidationException;
|
||||
import com.dsasp.server.common.util.StringUtil;
|
||||
import com.dsasp.server.core.script.secure.SecureGroovyScriptEngineFactory;
|
||||
|
||||
public class ScriptingEnginesManager {
|
||||
public static final String DEFAULT_SCRIPTING_LANGUAGE = "juel";
|
||||
|
||||
public static final String GROOVY_SCRIPTING_LANGUAGE = "groovy";
|
||||
|
||||
private static ScriptingEnginesManager scriptingEnginesManager;
|
||||
|
||||
private Map<String, CompiledScript> compilerScripts = new HashMap<String, CompiledScript>();
|
||||
private Map<String, Integer> scriptHashcode = new HashMap<String, Integer>();
|
||||
|
||||
private final ScriptEngineManager scriptEngineManager;
|
||||
|
||||
public ScriptingEnginesManager() {
|
||||
scriptEngineManager = new ScriptEngineManager();
|
||||
scriptEngineManager.registerEngineName(GROOVY_SCRIPTING_LANGUAGE,
|
||||
new SecureGroovyScriptEngineFactory());
|
||||
// 适配:juel 引擎按 JSR-223 名称惰性注册(见类首注释)。classpath 提供 juel 引擎时注册,
|
||||
// 否则跳过——保证保真层不强依赖 activiti;线性服务流(D 类查询/报表)不受影响。
|
||||
ScriptEngine juel = scriptEngineManager.getEngineByName(DEFAULT_SCRIPTING_LANGUAGE);
|
||||
if (juel != null) {
|
||||
scriptEngineManager.registerEngineName(DEFAULT_SCRIPTING_LANGUAGE, juel.getFactory());
|
||||
}
|
||||
}
|
||||
|
||||
public ScriptingEnginesManager addScriptEngineFactory(
|
||||
ScriptEngineFactory scriptEngineFactory) {
|
||||
scriptEngineManager.registerEngineName(
|
||||
scriptEngineFactory.getEngineName(), scriptEngineFactory);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setScriptEngineFactories(
|
||||
List<ScriptEngineFactory> scriptEngineFactories) {
|
||||
if (scriptEngineFactories != null) {
|
||||
for (ScriptEngineFactory scriptEngineFactory : scriptEngineFactories) {
|
||||
scriptEngineManager.registerEngineName(
|
||||
scriptEngineFactory.getEngineName(),
|
||||
scriptEngineFactory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object evaluate(String script, String language, Bindings bindings) {
|
||||
ScriptEngine scriptEngine = scriptEngineManager
|
||||
.getEngineByName(language);
|
||||
|
||||
if (scriptEngine == null) {
|
||||
throw new RuntimeException("Can't find scripting engine for '"
|
||||
+ language + "'");
|
||||
}
|
||||
|
||||
try {
|
||||
return scriptEngine.eval(script, bindings);
|
||||
} catch (ScriptException e) {
|
||||
throw new RuntimeException("problem evaluating script: "
|
||||
+ e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object evaluateGroovy(String key, String script, Bindings bindings) {
|
||||
ScriptEngine scriptEngine = scriptEngineManager
|
||||
.getEngineByName(GROOVY_SCRIPTING_LANGUAGE);
|
||||
|
||||
if (scriptEngine == null) {
|
||||
throw new RuntimeException(
|
||||
"Can't find scripting engine for '" + GROOVY_SCRIPTING_LANGUAGE + "'");
|
||||
}
|
||||
CompiledScript comScript = compilerScripts.get(key);
|
||||
|
||||
try {
|
||||
|
||||
if (comScript == null || StringUtil.isEmpty(key) || script.hashCode() != scriptHashcode.get(key)) {
|
||||
comScript = ((Compilable) scriptEngine).compile(script);
|
||||
if (comScript == null) {
|
||||
return null;
|
||||
}
|
||||
compilerScripts.put(key, comScript);
|
||||
scriptHashcode.put(key, script.hashCode());
|
||||
}
|
||||
return comScript.eval(bindings);
|
||||
}
|
||||
catch (ScriptException e) {
|
||||
//To Console Debug
|
||||
try {
|
||||
CompiledScript comScript2 = ((Compilable) scriptEngine).compile("import com.dsasp.client.viewframework.template.util.Console; Console.error(errorMsg)");
|
||||
bindings.put("errorMsg", e);
|
||||
comScript2.eval(bindings);
|
||||
} catch (ScriptException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
e.printStackTrace();
|
||||
Throwable throwCase = e.getCause();
|
||||
while(throwCase != null ){
|
||||
if(throwCase instanceof ValidationException){
|
||||
throw (ValidationException)throwCase;
|
||||
}else if(throwCase instanceof PrivilegeException){
|
||||
throw (PrivilegeException)throwCase;
|
||||
}else if(throwCase instanceof SameCodeException){
|
||||
throw (SameCodeException)throwCase;
|
||||
}else{
|
||||
throwCase = throwCase.getCause();
|
||||
}
|
||||
}
|
||||
//FIXME: 脚本异常提醒
|
||||
throw new RuntimeException("错误的脚本。\n\tkey:" + key + "\n\tvalue: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void setChangeScript(String key){
|
||||
compilerScripts.remove(key);
|
||||
scriptHashcode.remove(key);
|
||||
}
|
||||
|
||||
public void setChangeScripts(List<String> keyList) {
|
||||
if (keyList != null && keyList.size() > 0) {
|
||||
for (String key : keyList) {
|
||||
setChangeScript(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ScriptingEnginesManager getScriptingEnginesManager() {
|
||||
if (scriptingEnginesManager == null) {
|
||||
scriptingEnginesManager = new ScriptingEnginesManager();
|
||||
}
|
||||
return scriptingEnginesManager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.dsasp.server.privilege.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.dsasp.server.common.core.service.FlowService;
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.bean.GeneralPOJO;
|
||||
import com.dsasp.server.common.dataDic.service.POJOService;
|
||||
import com.dsasp.server.common.privilege.service.FlowPrivilegeService;
|
||||
import com.dsasp.server.common.user.service.LoggedInUser;
|
||||
import com.dsasp.server.common.util.UserSession;
|
||||
|
||||
|
||||
@Service(value = "flowPrivilegeService")
|
||||
@Transactional
|
||||
public class FlowPrivilegeServiceImpl implements FlowPrivilegeService {
|
||||
|
||||
// private POJOService pojoService;
|
||||
private FlowService flowService;
|
||||
|
||||
@Override
|
||||
public List<String> getServicePrivileges(String roleId) {
|
||||
GeneralPOJO pojo = ((POJOService)SpringBeanOsgiServices.getInstance().getBeanByName("pojoService")).loadPOJO(roleId, "SYS_ROLE", UserSession.getAdmin(), true);
|
||||
if(pojo == null){
|
||||
return null;
|
||||
}
|
||||
return (List<String>)pojo.get_Value("SERVICES");
|
||||
}
|
||||
|
||||
/**
|
||||
* authority the roles has the Privilege of invoke the service
|
||||
*/
|
||||
@Override
|
||||
public boolean authority(List<String> roles, String serviceId) {
|
||||
FlowService flowService = getFlowService();
|
||||
|
||||
//这个服务不存在,则验证失败,返回false
|
||||
if(flowService == null){
|
||||
return false;
|
||||
}
|
||||
|
||||
//非受控服务返回true
|
||||
if(!flowService.isControlFlowService(serviceId)){
|
||||
return true;
|
||||
}
|
||||
if(roles != null && roles.size() > 0){
|
||||
if(roles.contains(LoggedInUser.ADMIN) || roles.contains(LoggedInUser.ADMIN.toLowerCase()) || roles.contains(LoggedInUser.ADMIN.toLowerCase().trim())){
|
||||
return true;
|
||||
}
|
||||
for(String roleId : roles){
|
||||
List<String> pris = ServicePrivilege.getServicePrivileges(roleId);
|
||||
if(pris != null && pris.contains(serviceId)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getMenus(String userID) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public FlowService getFlowService() {
|
||||
if (flowService == null) {
|
||||
flowService = (FlowService) SpringBeanOsgiServices.getInstance()
|
||||
.getBeanByName("flowService");
|
||||
}
|
||||
return flowService;
|
||||
}
|
||||
|
||||
public void setFlowService(FlowService flowService) {
|
||||
this.flowService = flowService;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.dsasp.server.privilege.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dsasp.server.common.core.service.SpringBeanOsgiServices;
|
||||
import com.dsasp.server.common.dataDic.bean.CCache;
|
||||
import com.dsasp.server.common.privilege.service.FlowPrivilegeService;
|
||||
|
||||
|
||||
public class ServicePrivilege {
|
||||
|
||||
protected static CCache<String, List<String>> is_cache = new CCache<String, List<String>>("ServicePrivilege", 200);
|
||||
|
||||
public static List<String> getServicePrivileges(String roleId){
|
||||
List<String> servicePri = is_cache.get(roleId);
|
||||
if(servicePri == null){
|
||||
servicePri = ((FlowPrivilegeService)SpringBeanOsgiServices.getInstance().getBeanByName("flowPrivilegeService")).getServicePrivileges(roleId);
|
||||
is_cache.put(roleId, servicePri);
|
||||
}
|
||||
return servicePri;
|
||||
}
|
||||
|
||||
public static void setChangeRole(String roleId){
|
||||
is_cache.remove(roleId);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user