Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
fuyue82
o2oa
提交
7f9f245e
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,发现更多精彩内容 >>
提交
7f9f245e
编写于
6月 03, 2021
作者:
Z
zhourui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加Attachment V2UploadWorkOrWorkCompleted
上级
84044be5
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
249 addition
and
0 deletion
+249
-0
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/AttachmentAction.java
...m/assemble/surface/jaxrs/attachment/AttachmentAction.java
+23
-0
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/V2UploadWorkOrWorkCompleted.java
...surface/jaxrs/attachment/V2UploadWorkOrWorkCompleted.java
+226
-0
未找到文件。
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/AttachmentAction.java
浏览文件 @
7f9f245e
...
...
@@ -1327,4 +1327,27 @@ public class AttachmentAction extends StandardJaxrsAction {
asyncResponse
.
resume
(
ResponseFactory
.
getEntityTagActionResultResponse
(
request
,
result
));
}
@JaxrsMethodDescribe
(
value
=
"V2_根据work或workCompleted上传附件,如果同名附件存在则替换."
,
action
=
V2UploadWorkOrWorkCompleted
.
class
)
@GET
@Path
(
"v2/upload/workorworkcompleted/{workOrWorkCompleted}"
)
@Produces
(
HttpMediaType
.
APPLICATION_JSON_UTF_8
)
@Consumes
(
MediaType
.
MULTIPART_FORM_DATA
)
public
void
V2UploadWorkOrWorkCompleted
(
FormDataMultiPart
form
,
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
@JaxrsParameterDescribe
(
"工作或已完成工作标识"
)
@PathParam
(
"workOrWorkCompleted"
)
String
workOrWorkCompleted
,
@JaxrsParameterDescribe
(
"位置"
)
@FormDataParam
(
"site"
)
String
site
,
@JaxrsParameterDescribe
(
"附件名称"
)
@FormDataParam
(
FILENAME_FIELD
)
String
fileName
,
@FormDataParam
(
FILE_FIELD
)
byte
[]
bytes
,
@FormDataParam
(
FILE_FIELD
)
final
FormDataContentDisposition
disposition
)
{
ActionResult
<
V2UploadWorkOrWorkCompleted
.
Wo
>
result
=
new
ActionResult
<>();
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
try
{
result
=
new
V2UploadWorkOrWorkCompleted
().
execute
(
effectivePerson
,
workOrWorkCompleted
,
site
,
fileName
,
bytes
,
disposition
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
,
effectivePerson
,
request
,
null
);
result
.
error
(
e
);
}
asyncResponse
.
resume
(
ResponseFactory
.
getEntityTagActionResultResponse
(
request
,
result
));
}
}
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/V2UploadWorkOrWorkCompleted.java
0 → 100644
浏览文件 @
7f9f245e
package
com.x.processplatform.assemble.surface.jaxrs.attachment
;
import
java.util.List
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.tika.Tika
;
import
org.glassfish.jersey.media.multipart.FormDataContentDisposition
;
import
com.x.base.core.container.EntityManagerContainer
;
import
com.x.base.core.container.factory.EntityManagerContainerFactory
;
import
com.x.base.core.entity.annotation.CheckPersistType
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.config.StorageMapping
;
import
com.x.base.core.project.exception.ExceptionAccessDenied
;
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.WoId
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.tools.ExtractTextTools
;
import
com.x.processplatform.assemble.surface.Business
;
import
com.x.processplatform.assemble.surface.ThisApplication
;
import
com.x.processplatform.assemble.surface.WorkControl
;
import
com.x.processplatform.core.entity.content.Attachment
;
import
com.x.processplatform.core.entity.content.Work
;
import
com.x.processplatform.core.entity.content.WorkCompleted
;
import
com.x.processplatform.core.entity.element.End
;
import
com.x.processplatform.core.entity.element.Process
;
class
V2UploadWorkOrWorkCompleted
extends
BaseAction
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
V2UploadWorkOrWorkCompleted
.
class
);
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
String
workOrWorkCompleted
,
String
site
,
String
fileName
,
byte
[]
bytes
,
FormDataContentDisposition
disposition
)
throws
Exception
{
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
Wo
wo
=
new
Wo
();
Work
work
=
null
;
WorkCompleted
workCompleted
=
null
;
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
work
=
emc
.
find
(
workOrWorkCompleted
,
Work
.
class
);
if
(
null
==
work
)
{
workCompleted
=
emc
.
flag
(
workOrWorkCompleted
,
WorkCompleted
.
class
);
}
}
CompletableFuture
<
Boolean
>
checkControlFuture
=
this
.
readableWithWorkOrWorkCompletedFuture
(
effectivePerson
,
workOrWorkCompleted
);
if
(
BooleanUtils
.
isFalse
(
checkControlFuture
.
get
(
Config
.
processPlatform
().
getAsynchronousTimeout
(),
TimeUnit
.
SECONDS
)))
{
throw
new
ExceptionAccessDenied
(
effectivePerson
,
workOrWorkCompleted
);
}
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Business
business
=
new
Business
(
emc
);
work
=
emc
.
find
(
workOrWorkCompleted
,
Work
.
class
);
if
(
null
==
work
)
{
workCompleted
=
emc
.
flag
(
workOrWorkCompleted
,
WorkCompleted
.
class
);
}
if
(
null
!=
work
)
{
wo
.
setId
(
uploadWork
(
business
,
effectivePerson
,
work
,
site
,
fileName
,
bytes
,
disposition
));
}
else
if
(
null
!=
workCompleted
)
{
wo
.
setId
(
uploadWorkCompleted
(
business
,
effectivePerson
,
workCompleted
,
site
,
fileName
,
bytes
,
disposition
));
}
}
result
.
setData
(
wo
);
return
result
;
}
private
String
uploadWork
(
Business
business
,
EffectivePerson
effectivePerson
,
Work
work
,
String
site
,
String
fileName
,
byte
[]
bytes
,
FormDataContentDisposition
disposition
)
throws
Exception
{
WoControl
control
=
business
.
getControl
(
effectivePerson
,
work
,
WoControl
.
class
);
if
(
BooleanUtils
.
isNotTrue
(
control
.
getAllowSave
()))
{
throw
new
ExceptionAccessDenied
(
effectivePerson
,
work
);
}
if
(
StringUtils
.
isEmpty
(
fileName
))
{
fileName
=
this
.
fileName
(
disposition
);
}
fileName
=
this
.
adjustFileName
(
business
,
work
.
getJob
(),
fileName
);
this
.
verifyConstraint
(
bytes
.
length
,
fileName
,
null
);
Attachment
attachment
=
business
.
entityManagerContainer
().
firstEqualAndEqualAndEqual
(
Attachment
.
class
,
Attachment
.
job_FIELDNAME
,
work
.
getJob
(),
Attachment
.
name_FIELDNAME
,
fileName
,
Attachment
.
site_FIELDNAME
,
site
);
if
(
null
!=
attachment
)
{
StorageMapping
mapping
=
ThisApplication
.
context
().
storageMappings
().
get
(
Attachment
.
class
,
attachment
.
getStorage
());
attachment
.
updateContent
(
mapping
,
bytes
,
fileName
);
attachment
.
setType
((
new
Tika
()).
detect
(
bytes
,
fileName
));
this
.
updateText
(
attachment
,
bytes
);
business
.
entityManagerContainer
().
beginTransaction
(
Attachment
.
class
);
business
.
entityManagerContainer
().
check
(
attachment
,
CheckPersistType
.
all
);
business
.
entityManagerContainer
().
commit
();
}
else
{
StorageMapping
mapping
=
ThisApplication
.
context
().
storageMappings
().
random
(
Attachment
.
class
);
attachment
=
this
.
concreteAttachmentOfWork
(
work
,
effectivePerson
,
site
);
attachment
.
saveContent
(
mapping
,
bytes
,
fileName
);
attachment
.
setType
((
new
Tika
()).
detect
(
bytes
,
fileName
));
this
.
updateText
(
attachment
,
bytes
);
business
.
entityManagerContainer
().
beginTransaction
(
Attachment
.
class
);
business
.
entityManagerContainer
().
persist
(
attachment
,
CheckPersistType
.
all
);
business
.
entityManagerContainer
().
commit
();
}
return
attachment
.
getId
();
}
private
String
uploadWorkCompleted
(
Business
business
,
EffectivePerson
effectivePerson
,
WorkCompleted
workCompleted
,
String
site
,
String
fileName
,
byte
[]
bytes
,
FormDataContentDisposition
disposition
)
throws
Exception
{
if
(
BooleanUtils
.
isNotTrue
(
business
.
canManageApplicationOrProcess
(
effectivePerson
,
workCompleted
.
getApplication
(),
workCompleted
.
getProcess
())))
{
throw
new
ExceptionAccessDenied
(
effectivePerson
);
}
if
(
StringUtils
.
isEmpty
(
fileName
))
{
fileName
=
this
.
fileName
(
disposition
);
}
fileName
=
this
.
adjustFileName
(
business
,
workCompleted
.
getJob
(),
fileName
);
this
.
verifyConstraint
(
bytes
.
length
,
fileName
,
null
);
Attachment
attachment
=
business
.
entityManagerContainer
().
firstEqualAndEqualAndEqual
(
Attachment
.
class
,
Attachment
.
job_FIELDNAME
,
workCompleted
.
getJob
(),
Attachment
.
name_FIELDNAME
,
fileName
,
Attachment
.
site_FIELDNAME
,
site
);
if
(
null
!=
attachment
)
{
StorageMapping
mapping
=
ThisApplication
.
context
().
storageMappings
().
get
(
Attachment
.
class
,
attachment
.
getStorage
());
attachment
.
updateContent
(
mapping
,
bytes
,
fileName
);
attachment
.
setType
((
new
Tika
()).
detect
(
bytes
,
fileName
));
this
.
updateText
(
attachment
,
bytes
);
business
.
entityManagerContainer
().
beginTransaction
(
Attachment
.
class
);
business
.
entityManagerContainer
().
check
(
attachment
,
CheckPersistType
.
all
);
business
.
entityManagerContainer
().
commit
();
}
else
{
// 用于标识状态的结束节点
Process
process
=
business
.
process
().
pick
(
workCompleted
.
getProcess
());
if
(
null
==
process
)
{
throw
new
ExceptionEntityNotExist
(
workCompleted
.
getProcess
(),
Process
.
class
);
}
List
<
End
>
ends
=
business
.
end
().
listWithProcess
(
process
);
if
(
ends
.
isEmpty
())
{
throw
new
ExceptionEndNotExist
(
process
.
getId
());
}
StorageMapping
mapping
=
ThisApplication
.
context
().
storageMappings
().
random
(
Attachment
.
class
);
attachment
=
this
.
concreteAttachmentOfWorkCompleted
(
workCompleted
,
effectivePerson
,
site
,
ends
.
get
(
0
));
attachment
.
saveContent
(
mapping
,
bytes
,
fileName
);
attachment
.
setType
((
new
Tika
()).
detect
(
bytes
,
fileName
));
business
.
entityManagerContainer
().
beginTransaction
(
Attachment
.
class
);
business
.
entityManagerContainer
().
persist
(
attachment
,
CheckPersistType
.
all
);
business
.
entityManagerContainer
().
commit
();
return
attachment
.
getId
();
}
return
attachment
.
getId
();
}
private
void
updateText
(
Attachment
attachment
,
byte
[]
bytes
)
throws
Exception
{
if
(
BooleanUtils
.
isTrue
(
Config
.
query
().
getExtractImage
())
&&
BooleanUtils
.
isTrue
(
ExtractTextTools
.
supportImage
(
attachment
.
getName
()))
&&
ExtractTextTools
.
available
(
bytes
))
{
attachment
.
setText
(
ExtractTextTools
.
image
(
bytes
));
}
}
private
Attachment
concreteAttachmentOfWork
(
Work
work
,
EffectivePerson
effectivePerson
,
String
site
)
{
Attachment
attachment
=
new
Attachment
();
attachment
.
setCompleted
(
false
);
attachment
.
setPerson
(
effectivePerson
.
getDistinguishedName
());
attachment
.
setLastUpdatePerson
(
effectivePerson
.
getDistinguishedName
());
attachment
.
setSite
(
site
);
attachment
.
setWorkCreateTime
(
work
.
getCreateTime
());
attachment
.
setApplication
(
work
.
getApplication
());
attachment
.
setProcess
(
work
.
getProcess
());
attachment
.
setJob
(
work
.
getJob
());
attachment
.
setActivity
(
work
.
getActivity
());
attachment
.
setActivityName
(
work
.
getActivityName
());
attachment
.
setActivityToken
(
work
.
getActivityToken
());
attachment
.
setActivityType
(
work
.
getActivityType
());
return
attachment
;
}
private
Attachment
concreteAttachmentOfWorkCompleted
(
WorkCompleted
workCompleted
,
EffectivePerson
effectivePerson
,
String
site
,
End
end
)
throws
Exception
{
Attachment
attachment
=
new
Attachment
();
attachment
.
setCompleted
(
true
);
attachment
.
setPerson
(
effectivePerson
.
getDistinguishedName
());
attachment
.
setLastUpdatePerson
(
effectivePerson
.
getDistinguishedName
());
attachment
.
setSite
(
site
);
attachment
.
setWorkCreateTime
(
workCompleted
.
getCreateTime
());
attachment
.
setApplication
(
workCompleted
.
getApplication
());
attachment
.
setProcess
(
workCompleted
.
getProcess
());
attachment
.
setJob
(
workCompleted
.
getJob
());
attachment
.
setActivity
(
end
.
getId
());
attachment
.
setActivityName
(
end
.
getName
());
attachment
.
setActivityToken
(
end
.
getId
());
attachment
.
setActivityType
(
end
.
getActivityType
());
return
attachment
;
}
protected
CompletableFuture
<
Boolean
>
readableWithWorkOrWorkCompletedFuture
(
EffectivePerson
effectivePerson
,
String
flag
)
{
return
CompletableFuture
.
supplyAsync
(()
->
{
Boolean
value
=
false
;
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Business
business
=
new
Business
(
emc
);
value
=
business
.
readableWithWorkOrWorkCompleted
(
effectivePerson
,
flag
,
new
ExceptionEntityNotExist
(
flag
));
}
catch
(
Exception
e
)
{
logger
.
error
(
e
);
}
return
value
;
});
}
public
static
class
Wo
extends
WoId
{
private
static
final
long
serialVersionUID
=
-
1370726528985836188L
;
}
public
static
class
WoControl
extends
WorkControl
{
private
static
final
long
serialVersionUID
=
547408977744326609L
;
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录