Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
fuyue82
o2oa
提交
89370d90
o2oa
项目概览
fuyue82
/
o2oa
与 Fork 源项目一致
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
89370d90
编写于
11月 11, 2020
作者:
Z
zhourui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化invoke执行,尽量走缓存
上级
685bf057
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
415 addition
and
223 deletion
+415
-223
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/jaxrs/work/BaseAction.java
...essplatform/service/processing/jaxrs/work/BaseAction.java
+149
-147
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/ActionExecute.java
...java/com/x/program/center/jaxrs/invoke/ActionExecute.java
+95
-76
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/ActionExecute2.java
...ava/com/x/program/center/jaxrs/invoke/ActionExecute2.java
+171
-0
未找到文件。
o2server/x_processplatform_service_processing/src/main/java/com/x/processplatform/service/processing/jaxrs/work/BaseAction.java
浏览文件 @
89370d90
...
...
@@ -23,152 +23,154 @@ import com.x.query.core.entity.Item;
abstract
class
BaseAction
extends
StandardJaxrsAction
{
protected
boolean
cascadeDeleteWorkBeginButNotCommit
(
Business
business
,
Work
work
)
throws
Exception
{
if
(
business
.
work
().
listWithJob
(
work
.
getJob
()).
size
()
>
1
)
{
List
<
String
>
taskIds
=
business
.
entityManagerContainer
().
idsEqual
(
Task
.
class
,
Task
.
work_FIELDNAME
,
work
.
getId
());
if
(
ListTools
.
isNotEmpty
(
taskIds
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Task
.
class
);
business
.
entityManagerContainer
().
delete
(
Task
.
class
,
taskIds
);
}
business
.
entityManagerContainer
().
beginTransaction
(
Work
.
class
);
business
.
entityManagerContainer
().
remove
(
work
,
CheckRemoveType
.
all
);
business
.
entityManagerContainer
().
commit
();
return
false
;
}
else
{
deleteTask
(
business
,
work
.
getJob
());
deleteTaskCompleted
(
business
,
work
.
getJob
());
deleteRead
(
business
,
work
.
getJob
());
deleteReadCompleted
(
business
,
work
.
getJob
());
deleteReview
(
business
,
work
.
getJob
());
deleteAttachment
(
business
,
work
.
getJob
());
deleteWorkLog
(
business
,
work
.
getJob
());
deleteItem
(
business
,
work
.
getJob
());
deleteDocumentVersion
(
business
,
work
.
getJob
());
deleteRecord
(
business
,
work
.
getJob
());
deleteWork
(
business
,
work
);
return
true
;
}
}
private
void
deleteTask
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Task
.
class
,
Task
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Task
.
class
);
for
(
Task
o
:
business
.
entityManagerContainer
().
list
(
Task
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
task_delete
(
o
);
}
}
}
private
void
deleteTaskCompleted
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
TaskCompleted
.
class
,
TaskCompleted
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
TaskCompleted
.
class
);
for
(
TaskCompleted
o
:
business
.
entityManagerContainer
().
list
(
TaskCompleted
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
taskCompleted_delete
(
o
);
}
}
}
private
void
deleteRead
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Read
.
class
,
Read
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Read
.
class
);
for
(
Read
o
:
business
.
entityManagerContainer
().
list
(
Read
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
read_delete
(
o
);
}
}
}
private
void
deleteReadCompleted
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
ReadCompleted
.
class
,
ReadCompleted
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
ReadCompleted
.
class
);
for
(
ReadCompleted
o
:
business
.
entityManagerContainer
().
list
(
ReadCompleted
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
readCompleted_delete
(
o
);
}
}
}
private
void
deleteReview
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Review
.
class
,
Review
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Review
.
class
);
business
.
entityManagerContainer
().
delete
(
Review
.
class
,
ids
);
}
}
private
void
deleteAttachment
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Attachment
.
class
,
Attachment
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Attachment
.
class
);
Attachment
obj
;
for
(
String
id
:
ids
)
{
obj
=
business
.
entityManagerContainer
().
find
(
id
,
Attachment
.
class
);
if
(
null
!=
obj
)
{
StorageMapping
mapping
=
ThisApplication
.
context
().
storageMappings
().
get
(
Attachment
.
class
,
obj
.
getStorage
());
if
(
null
!=
mapping
)
{
obj
.
deleteContent
(
mapping
);
}
business
.
entityManagerContainer
().
remove
(
obj
,
CheckRemoveType
.
all
);
}
}
}
}
private
void
deleteWorkLog
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
WorkLog
.
class
,
WorkLog
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
WorkLog
.
class
);
business
.
entityManagerContainer
().
delete
(
WorkLog
.
class
,
ids
);
}
}
private
void
deleteItem
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Item
.
class
,
Item
.
bundle_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Item
.
class
);
business
.
entityManagerContainer
().
delete
(
Item
.
class
,
ids
);
}
}
private
void
deleteWork
(
Business
business
,
Work
work
)
throws
Exception
{
business
.
entityManagerContainer
().
beginTransaction
(
Work
.
class
);
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqualAndNotEqual
(
Work
.
class
,
Work
.
job_FIELDNAME
,
work
.
getJob
(),
Work
.
id_FIELDNAME
,
work
.
getId
());
if
(
ListTools
.
isNotEmpty
(
ids
))
{
for
(
Work
o
:
business
.
entityManagerContainer
().
list
(
Work
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
work_delete
(
o
);
}
}
business
.
entityManagerContainer
().
remove
(
work
);
MessageFactory
.
work_delete
(
work
);
}
private
void
deleteDocumentVersion
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
DocumentVersion
.
class
,
DocumentVersion
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
DocumentVersion
.
class
);
business
.
entityManagerContainer
().
delete
(
DocumentVersion
.
class
,
ids
);
}
}
private
void
deleteRecord
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Record
.
class
,
Record
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Record
.
class
);
business
.
entityManagerContainer
().
delete
(
Record
.
class
,
ids
);
}
}
protected
boolean
cascadeDeleteWorkBeginButNotCommit
(
Business
business
,
Work
work
)
throws
Exception
{
if
(
business
.
work
().
listWithJob
(
work
.
getJob
()).
size
()
>
1
)
{
List
<
String
>
taskIds
=
business
.
entityManagerContainer
().
idsEqual
(
Task
.
class
,
Task
.
work_FIELDNAME
,
work
.
getId
());
if
(
ListTools
.
isNotEmpty
(
taskIds
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Task
.
class
);
for
(
Task
o
:
business
.
entityManagerContainer
().
list
(
Task
.
class
,
taskIds
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
task_delete
(
o
);
}
}
business
.
entityManagerContainer
().
beginTransaction
(
Work
.
class
);
business
.
entityManagerContainer
().
remove
(
work
,
CheckRemoveType
.
all
);
return
false
;
}
else
{
deleteTask
(
business
,
work
.
getJob
());
deleteTaskCompleted
(
business
,
work
.
getJob
());
deleteRead
(
business
,
work
.
getJob
());
deleteReadCompleted
(
business
,
work
.
getJob
());
deleteReview
(
business
,
work
.
getJob
());
deleteAttachment
(
business
,
work
.
getJob
());
deleteWorkLog
(
business
,
work
.
getJob
());
deleteItem
(
business
,
work
.
getJob
());
deleteDocumentVersion
(
business
,
work
.
getJob
());
deleteRecord
(
business
,
work
.
getJob
());
deleteWork
(
business
,
work
);
return
true
;
}
}
private
void
deleteTask
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Task
.
class
,
Task
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Task
.
class
);
for
(
Task
o
:
business
.
entityManagerContainer
().
list
(
Task
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
task_delete
(
o
);
}
}
}
private
void
deleteTaskCompleted
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
TaskCompleted
.
class
,
TaskCompleted
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
TaskCompleted
.
class
);
for
(
TaskCompleted
o
:
business
.
entityManagerContainer
().
list
(
TaskCompleted
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
taskCompleted_delete
(
o
);
}
}
}
private
void
deleteRead
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Read
.
class
,
Read
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Read
.
class
);
for
(
Read
o
:
business
.
entityManagerContainer
().
list
(
Read
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
read_delete
(
o
);
}
}
}
private
void
deleteReadCompleted
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
ReadCompleted
.
class
,
ReadCompleted
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
ReadCompleted
.
class
);
for
(
ReadCompleted
o
:
business
.
entityManagerContainer
().
list
(
ReadCompleted
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
readCompleted_delete
(
o
);
}
}
}
private
void
deleteReview
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Review
.
class
,
Review
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Review
.
class
);
business
.
entityManagerContainer
().
delete
(
Review
.
class
,
ids
);
}
}
private
void
deleteAttachment
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Attachment
.
class
,
Attachment
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Attachment
.
class
);
Attachment
obj
;
for
(
String
id
:
ids
)
{
obj
=
business
.
entityManagerContainer
().
find
(
id
,
Attachment
.
class
);
if
(
null
!=
obj
)
{
StorageMapping
mapping
=
ThisApplication
.
context
().
storageMappings
().
get
(
Attachment
.
class
,
obj
.
getStorage
());
if
(
null
!=
mapping
)
{
obj
.
deleteContent
(
mapping
);
}
business
.
entityManagerContainer
().
remove
(
obj
,
CheckRemoveType
.
all
);
}
}
}
}
private
void
deleteWorkLog
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
WorkLog
.
class
,
WorkLog
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
WorkLog
.
class
);
business
.
entityManagerContainer
().
delete
(
WorkLog
.
class
,
ids
);
}
}
private
void
deleteItem
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Item
.
class
,
Item
.
bundle_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Item
.
class
);
business
.
entityManagerContainer
().
delete
(
Item
.
class
,
ids
);
}
}
private
void
deleteWork
(
Business
business
,
Work
work
)
throws
Exception
{
business
.
entityManagerContainer
().
beginTransaction
(
Work
.
class
);
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqualAndNotEqual
(
Work
.
class
,
Work
.
job_FIELDNAME
,
work
.
getJob
(),
Work
.
id_FIELDNAME
,
work
.
getId
());
if
(
ListTools
.
isNotEmpty
(
ids
))
{
for
(
Work
o
:
business
.
entityManagerContainer
().
list
(
Work
.
class
,
ids
))
{
business
.
entityManagerContainer
().
remove
(
o
);
MessageFactory
.
work_delete
(
o
);
}
}
business
.
entityManagerContainer
().
remove
(
work
);
MessageFactory
.
work_delete
(
work
);
}
private
void
deleteDocumentVersion
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
DocumentVersion
.
class
,
DocumentVersion
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
DocumentVersion
.
class
);
business
.
entityManagerContainer
().
delete
(
DocumentVersion
.
class
,
ids
);
}
}
private
void
deleteRecord
(
Business
business
,
String
job
)
throws
Exception
{
List
<
String
>
ids
=
business
.
entityManagerContainer
().
idsEqual
(
Record
.
class
,
Record
.
job_FIELDNAME
,
job
);
if
(
ListTools
.
isNotEmpty
(
ids
))
{
business
.
entityManagerContainer
().
beginTransaction
(
Record
.
class
);
business
.
entityManagerContainer
().
delete
(
Record
.
class
,
ids
);
}
}
}
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/ActionExecute.java
浏览文件 @
89370d90
package
com.x.program.center.jaxrs.invoke
;
import
java.util.Date
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.regex.Matcher
;
...
...
@@ -12,7 +11,6 @@ import javax.script.ScriptContext;
import
javax.script.SimpleScriptContext
;
import
javax.servlet.http.HttpServletRequest
;
import
com.x.base.core.project.cache.CacheManager
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -21,7 +19,8 @@ import com.x.base.core.container.EntityManagerContainer;
import
com.x.base.core.container.factory.EntityManagerContainerFactory
;
import
com.x.base.core.project.cache.Cache.CacheCategory
;
import
com.x.base.core.project.cache.Cache.CacheKey
;
import
com.x.base.core.entity.annotation.CheckPersistType
;
import
com.x.base.core.project.cache.CacheManager
;
import
com.x.base.core.project.exception.ExceptionEntityNotExist
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.jaxrs.WoContentType
;
...
...
@@ -44,86 +43,104 @@ class ActionExecute extends BaseAction {
ActionResult
<
Object
>
execute
(
HttpServletRequest
request
,
EffectivePerson
effectivePerson
,
String
flag
,
JsonElement
jsonElement
)
throws
Exception
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
ActionResult
<
Object
>
result
=
new
ActionResult
<>();
Invoke
invoke
=
emc
.
flag
(
flag
,
Invoke
.
class
);
if
(
null
==
invoke
)
{
throw
new
ExceptionInvokeNotExist
(
flag
);
}
if
(!
BooleanUtils
.
isTrue
(
invoke
.
getEnable
()))
{
throw
new
ExceptionNotEnable
(
invoke
.
getName
());
}
if
(
StringUtils
.
isNotEmpty
(
invoke
.
getRemoteAddrRegex
()))
{
Matcher
matcher
=
Pattern
.
compile
(
invoke
.
getRemoteAddrRegex
()).
matcher
(
request
.
getRemoteAddr
());
if
(!
matcher
.
find
())
{
throw
new
ExceptionInvalidRemoteAddr
(
request
.
getRemoteAddr
(),
invoke
.
getName
());
}
}
emc
.
beginTransaction
(
Invoke
.
class
);
invoke
.
setLastStartTime
(
new
Date
());
emc
.
commit
();
CacheCategory
cacheCategory
=
new
CacheCategory
(
Invoke
.
class
);
CacheKey
cacheKey
=
new
CacheKey
(
ActionExecute
.
class
,
invoke
.
getId
());
CompiledScript
compiledScript
=
null
;
Optional
<?>
optional
=
CacheManager
.
get
(
cacheCategory
,
cacheKey
);
if
(
optional
.
isPresent
())
{
compiledScript
=
(
CompiledScript
)
optional
.
get
();
}
else
{
compiledScript
=
ScriptFactory
.
compile
(
invoke
.
getText
());
CacheManager
.
put
(
cacheCategory
,
cacheKey
,
compiledScript
);
}
ScriptContext
scriptContext
=
new
SimpleScriptContext
();
Bindings
bindings
=
scriptContext
.
getBindings
(
ScriptContext
.
ENGINE_SCOPE
);
Resources
resources
=
new
Resources
();
resources
.
setEntityManagerContainer
(
emc
);
resources
.
setContext
(
ThisApplication
.
context
());
resources
.
setOrganization
(
new
Organization
(
ThisApplication
.
context
()));
resources
.
setWebservicesClient
(
new
WebservicesClient
());
resources
.
setApplications
(
ThisApplication
.
context
().
applications
());
bindings
.
put
(
ScriptFactory
.
BINDING_NAME_RESOURCES
,
resources
);
bindings
.
put
(
"requestText"
,
gson
.
toJson
(
jsonElement
));
bindings
.
put
(
"request"
,
request
);
bindings
.
put
(
"effectivePerson"
,
effectivePerson
);
bindings
.
put
(
ScriptFactory
.
BINDING_NAME_APPLICATIONS
,
ThisApplication
.
context
().
applications
());
CustomResponse
customResponse
=
new
CustomResponse
();
bindings
.
put
(
"customResponse"
,
customResponse
);
Wo
wo
=
new
Wo
();
try
{
ScriptFactory
.
initialServiceScriptText
().
eval
(
scriptContext
);
Object
o
=
compiledScript
.
eval
(
scriptContext
);
if
(
StringUtils
.
equals
(
"seeOther"
,
customResponse
.
type
))
{
WoSeeOther
woSeeOther
=
new
WoSeeOther
(
Objects
.
toString
(
customResponse
.
value
,
""
));
result
.
setData
(
woSeeOther
);
}
else
if
(
StringUtils
.
equals
(
"temporaryRedirect"
,
customResponse
.
type
))
{
WoTemporaryRedirect
woTemporaryRedirect
=
new
WoTemporaryRedirect
(
Objects
.
toString
(
customResponse
.
value
,
""
));
result
.
setData
(
woTemporaryRedirect
);
}
else
{
if
(
null
!=
customResponse
.
value
)
{
if
(
StringUtils
.
isNotEmpty
(
customResponse
.
contentType
))
{
result
.
setData
(
new
WoContentType
(
customResponse
.
value
,
customResponse
.
contentType
));
}
else
if
(
customResponse
.
value
instanceof
WoText
)
{
result
.
setData
(
customResponse
.
value
);
}
else
{
wo
.
setValue
(
customResponse
.
value
);
result
.
setData
(
wo
);
}
CacheCategory
cacheCategory
=
new
CacheCategory
(
Invoke
.
class
);
Invoke
invoke
=
this
.
get
(
cacheCategory
,
flag
);
if
(
null
==
invoke
)
{
throw
new
ExceptionEntityNotExist
(
flag
,
Invoke
.
class
);
}
if
(!
BooleanUtils
.
isTrue
(
invoke
.
getEnable
()))
{
throw
new
ExceptionNotEnable
(
invoke
.
getName
());
}
if
(
StringUtils
.
isNotEmpty
(
invoke
.
getRemoteAddrRegex
()))
{
Matcher
matcher
=
Pattern
.
compile
(
invoke
.
getRemoteAddrRegex
()).
matcher
(
request
.
getRemoteAddr
());
if
(!
matcher
.
find
())
{
throw
new
ExceptionInvalidRemoteAddr
(
request
.
getRemoteAddr
(),
invoke
.
getName
());
}
}
ActionResult
<
Object
>
result
=
new
ActionResult
<>();
CompiledScript
compiledScript
=
this
.
getCompiledScript
(
cacheCategory
,
invoke
);
ScriptContext
scriptContext
=
new
SimpleScriptContext
();
Bindings
bindings
=
scriptContext
.
getBindings
(
ScriptContext
.
ENGINE_SCOPE
);
Resources
resources
=
new
Resources
();
// 此方法不用装载emc
// resources.setEntityManagerContainer(emc);
resources
.
setContext
(
ThisApplication
.
context
());
resources
.
setOrganization
(
new
Organization
(
ThisApplication
.
context
()));
resources
.
setWebservicesClient
(
new
WebservicesClient
());
resources
.
setApplications
(
ThisApplication
.
context
().
applications
());
bindings
.
put
(
ScriptFactory
.
BINDING_NAME_RESOURCES
,
resources
);
bindings
.
put
(
"requestText"
,
gson
.
toJson
(
jsonElement
));
bindings
.
put
(
"request"
,
request
);
bindings
.
put
(
"effectivePerson"
,
effectivePerson
);
bindings
.
put
(
ScriptFactory
.
BINDING_NAME_APPLICATIONS
,
ThisApplication
.
context
().
applications
());
CustomResponse
customResponse
=
new
CustomResponse
();
bindings
.
put
(
"customResponse"
,
customResponse
);
Wo
wo
=
new
Wo
();
try
{
ScriptFactory
.
initialServiceScriptText
().
eval
(
scriptContext
);
Object
o
=
compiledScript
.
eval
(
scriptContext
);
if
(
StringUtils
.
equals
(
"seeOther"
,
customResponse
.
type
))
{
WoSeeOther
woSeeOther
=
new
WoSeeOther
(
Objects
.
toString
(
customResponse
.
value
,
""
));
result
.
setData
(
woSeeOther
);
}
else
if
(
StringUtils
.
equals
(
"temporaryRedirect"
,
customResponse
.
type
))
{
WoTemporaryRedirect
woTemporaryRedirect
=
new
WoTemporaryRedirect
(
Objects
.
toString
(
customResponse
.
value
,
""
));
result
.
setData
(
woTemporaryRedirect
);
}
else
{
if
(
null
!=
customResponse
.
value
)
{
if
(
StringUtils
.
isNotEmpty
(
customResponse
.
contentType
))
{
result
.
setData
(
new
WoContentType
(
customResponse
.
value
,
customResponse
.
contentType
));
}
else
if
(
customResponse
.
value
instanceof
WoText
)
{
result
.
setData
(
customResponse
.
value
);
}
else
{
wo
.
setValue
(
o
);
wo
.
setValue
(
customResponse
.
value
);
result
.
setData
(
wo
);
}
}
else
{
wo
.
setValue
(
o
);
result
.
setData
(
wo
);
}
}
catch
(
Exception
e
)
{
throw
new
ExceptionExecuteError
(
invoke
.
getName
(),
e
);
}
emc
.
beginTransaction
(
Invoke
.
class
);
invoke
.
setLastEndTime
(
new
Date
());
emc
.
check
(
invoke
,
CheckPersistType
.
all
);
emc
.
commit
();
return
result
;
}
catch
(
Exception
e
)
{
throw
new
ExceptionExecuteError
(
invoke
.
getName
(),
e
);
}
return
result
;
}
private
Invoke
get
(
CacheCategory
cacheCategory
,
String
flag
)
throws
Exception
{
CacheKey
cacheKey
=
new
CacheKey
(
ActionExecute
.
class
,
flag
);
Optional
<?>
optional
=
CacheManager
.
get
(
cacheCategory
,
cacheKey
);
if
(
optional
.
isPresent
())
{
return
(
Invoke
)
optional
.
get
();
}
else
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Invoke
invoke
=
emc
.
flag
(
flag
,
Invoke
.
class
);
if
(
null
!=
invoke
)
{
CacheManager
.
put
(
cacheCategory
,
cacheKey
,
invoke
);
}
return
invoke
;
}
}
}
private
CompiledScript
getCompiledScript
(
CacheCategory
cacheCategory
,
Invoke
invoke
)
throws
Exception
{
CacheKey
cacheKey
=
new
CacheKey
(
ActionExecute
.
class
,
"CompiledScript"
,
invoke
.
getId
());
CompiledScript
compiledScript
=
null
;
Optional
<?>
optional
=
CacheManager
.
get
(
cacheCategory
,
cacheKey
);
if
(
optional
.
isPresent
())
{
compiledScript
=
(
CompiledScript
)
optional
.
get
();
}
else
{
compiledScript
=
ScriptFactory
.
compile
(
invoke
.
getText
());
CacheManager
.
put
(
cacheCategory
,
cacheKey
,
compiledScript
);
}
return
compiledScript
;
}
public
static
class
CustomResponse
{
...
...
@@ -154,6 +171,8 @@ class ActionExecute extends BaseAction {
public
static
class
Wo
extends
WoValue
{
private
static
final
long
serialVersionUID
=
-
2253926744723217590L
;
}
public
static
class
Resources
extends
AbstractResources
{
...
...
o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/invoke/ActionExecute2.java
0 → 100644
浏览文件 @
89370d90
package
com.x.program.center.jaxrs.invoke
;
import
java.util.Date
;
import
java.util.Objects
;
import
java.util.Optional
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
javax.script.Bindings
;
import
javax.script.CompiledScript
;
import
javax.script.ScriptContext
;
import
javax.script.SimpleScriptContext
;
import
javax.servlet.http.HttpServletRequest
;
import
com.x.base.core.project.cache.CacheManager
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
com.google.gson.JsonElement
;
import
com.x.base.core.container.EntityManagerContainer
;
import
com.x.base.core.container.factory.EntityManagerContainerFactory
;
import
com.x.base.core.project.cache.Cache.CacheCategory
;
import
com.x.base.core.project.cache.Cache.CacheKey
;
import
com.x.base.core.entity.annotation.CheckPersistType
;
import
com.x.base.core.project.http.ActionResult
;
import
com.x.base.core.project.http.EffectivePerson
;
import
com.x.base.core.project.jaxrs.WoContentType
;
import
com.x.base.core.project.jaxrs.WoSeeOther
;
import
com.x.base.core.project.jaxrs.WoTemporaryRedirect
;
import
com.x.base.core.project.jaxrs.WoText
;
import
com.x.base.core.project.jaxrs.WoValue
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.script.AbstractResources
;
import
com.x.base.core.project.script.ScriptFactory
;
import
com.x.base.core.project.webservices.WebservicesClient
;
import
com.x.organization.core.express.Organization
;
import
com.x.program.center.ThisApplication
;
import
com.x.program.center.core.entity.Invoke
;
class
ActionExecute2
extends
BaseAction
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ActionExecute2
.
class
);
ActionResult
<
Object
>
execute
(
HttpServletRequest
request
,
EffectivePerson
effectivePerson
,
String
flag
,
JsonElement
jsonElement
)
throws
Exception
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
ActionResult
<
Object
>
result
=
new
ActionResult
<>();
Invoke
invoke
=
emc
.
flag
(
flag
,
Invoke
.
class
);
if
(
null
==
invoke
)
{
throw
new
ExceptionInvokeNotExist
(
flag
);
}
if
(!
BooleanUtils
.
isTrue
(
invoke
.
getEnable
()))
{
throw
new
ExceptionNotEnable
(
invoke
.
getName
());
}
if
(
StringUtils
.
isNotEmpty
(
invoke
.
getRemoteAddrRegex
()))
{
Matcher
matcher
=
Pattern
.
compile
(
invoke
.
getRemoteAddrRegex
()).
matcher
(
request
.
getRemoteAddr
());
if
(!
matcher
.
find
())
{
throw
new
ExceptionInvalidRemoteAddr
(
request
.
getRemoteAddr
(),
invoke
.
getName
());
}
}
emc
.
beginTransaction
(
Invoke
.
class
);
invoke
.
setLastStartTime
(
new
Date
());
emc
.
commit
();
CacheCategory
cacheCategory
=
new
CacheCategory
(
Invoke
.
class
);
CacheKey
cacheKey
=
new
CacheKey
(
ActionExecute2
.
class
,
invoke
.
getId
());
CompiledScript
compiledScript
=
null
;
Optional
<?>
optional
=
CacheManager
.
get
(
cacheCategory
,
cacheKey
);
if
(
optional
.
isPresent
())
{
compiledScript
=
(
CompiledScript
)
optional
.
get
();
}
else
{
compiledScript
=
ScriptFactory
.
compile
(
invoke
.
getText
());
CacheManager
.
put
(
cacheCategory
,
cacheKey
,
compiledScript
);
}
ScriptContext
scriptContext
=
new
SimpleScriptContext
();
Bindings
bindings
=
scriptContext
.
getBindings
(
ScriptContext
.
ENGINE_SCOPE
);
Resources
resources
=
new
Resources
();
resources
.
setEntityManagerContainer
(
emc
);
resources
.
setContext
(
ThisApplication
.
context
());
resources
.
setOrganization
(
new
Organization
(
ThisApplication
.
context
()));
resources
.
setWebservicesClient
(
new
WebservicesClient
());
resources
.
setApplications
(
ThisApplication
.
context
().
applications
());
bindings
.
put
(
ScriptFactory
.
BINDING_NAME_RESOURCES
,
resources
);
bindings
.
put
(
"requestText"
,
gson
.
toJson
(
jsonElement
));
bindings
.
put
(
"request"
,
request
);
bindings
.
put
(
"effectivePerson"
,
effectivePerson
);
bindings
.
put
(
ScriptFactory
.
BINDING_NAME_APPLICATIONS
,
ThisApplication
.
context
().
applications
());
CustomResponse
customResponse
=
new
CustomResponse
();
bindings
.
put
(
"customResponse"
,
customResponse
);
Wo
wo
=
new
Wo
();
try
{
ScriptFactory
.
initialServiceScriptText
().
eval
(
scriptContext
);
Object
o
=
compiledScript
.
eval
(
scriptContext
);
if
(
StringUtils
.
equals
(
"seeOther"
,
customResponse
.
type
))
{
WoSeeOther
woSeeOther
=
new
WoSeeOther
(
Objects
.
toString
(
customResponse
.
value
,
""
));
result
.
setData
(
woSeeOther
);
}
else
if
(
StringUtils
.
equals
(
"temporaryRedirect"
,
customResponse
.
type
))
{
WoTemporaryRedirect
woTemporaryRedirect
=
new
WoTemporaryRedirect
(
Objects
.
toString
(
customResponse
.
value
,
""
));
result
.
setData
(
woTemporaryRedirect
);
}
else
{
if
(
null
!=
customResponse
.
value
)
{
if
(
StringUtils
.
isNotEmpty
(
customResponse
.
contentType
))
{
result
.
setData
(
new
WoContentType
(
customResponse
.
value
,
customResponse
.
contentType
));
}
else
if
(
customResponse
.
value
instanceof
WoText
)
{
result
.
setData
(
customResponse
.
value
);
}
else
{
wo
.
setValue
(
customResponse
.
value
);
result
.
setData
(
wo
);
}
}
else
{
wo
.
setValue
(
o
);
result
.
setData
(
wo
);
}
}
}
catch
(
Exception
e
)
{
throw
new
ExceptionExecuteError
(
invoke
.
getName
(),
e
);
}
emc
.
beginTransaction
(
Invoke
.
class
);
invoke
.
setLastEndTime
(
new
Date
());
emc
.
check
(
invoke
,
CheckPersistType
.
all
);
emc
.
commit
();
return
result
;
}
}
public
static
class
CustomResponse
{
protected
String
type
=
null
;
protected
Object
value
;
protected
String
contentType
;
public
void
seeOther
(
String
url
)
{
this
.
type
=
"seeOther"
;
this
.
value
=
url
;
}
public
void
temporaryRedirect
(
String
url
)
{
this
.
type
=
"temporaryRedirect"
;
this
.
value
=
url
;
}
public
void
setBody
(
Object
obj
)
{
this
.
value
=
obj
;
}
public
void
setBody
(
Object
obj
,
String
contentType
)
{
this
.
value
=
obj
;
this
.
contentType
=
contentType
;
}
}
public
static
class
Wo
extends
WoValue
{
}
public
static
class
Resources
extends
AbstractResources
{
private
Organization
organization
;
public
Organization
getOrganization
()
{
return
organization
;
}
public
void
setOrganization
(
Organization
organization
)
{
this
.
organization
=
organization
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录