📄 documentaction.java
字号:
package cn.myapps.core.dynaform.document.action;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import cn.myapps.base.action.BaseAction;
import cn.myapps.base.action.ParamsTable;
import cn.myapps.base.dao.ValueObject;
import cn.myapps.constans.Environment;
import cn.myapps.constans.Web;
import cn.myapps.core.dynaform.document.ejb.Document;
import cn.myapps.core.dynaform.document.ejb.DocumentProcess;
import cn.myapps.core.dynaform.form.action.ImpropriateException;
import cn.myapps.core.dynaform.form.ejb.Form;
import cn.myapps.core.dynaform.form.ejb.FormProcess;
import cn.myapps.core.dynaform.form.ejb.FormProcessBean;
import cn.myapps.core.dynaform.form.ejb.ValidateMessage;
import cn.myapps.core.user.action.WebUser;
import cn.myapps.core.workflow.element.Node;
import cn.myapps.core.workflow.engine.StateMachine;
import cn.myapps.core.workflow.engine.StateMachineHelper;
import cn.myapps.core.workflow.storage.definition.ejb.BillDefiProcess;
import cn.myapps.core.workflow.storage.definition.ejb.BillDefiVO;
import cn.myapps.core.workflow.storage.runtime.ejb.ActorRT;
import cn.myapps.core.workflow.storage.runtime.ejb.FlowStateRT;
import cn.myapps.core.workflow.storage.runtime.ejb.NodeRT;
import cn.myapps.util.ProcessFactory;
import com.opensymphony.webwork.ServletActionContext;
public class DocumentAction extends BaseAction {
private static final long serialVersionUID = 1L;
private Collection _fieldSelect;
private String _docid;
private String _flowid;
private String formid;
private String parentid;
public String getParentid() {
return parentid;
}
public void setParentid(String parentid) {
this.parentid = parentid;
}
public String get_docid() throws Exception {
ValueObject doc = getContent();
if (doc != null)
return doc.getId();
else
return null;
}
public void set_docid(String _docid) throws Exception {
/*
* String[] docid = null; Document doc = null; if (_docid.indexOf(",") !=
* -1) { docid = _docid.trim().split(","); doc = (Document)
* proxy.doView(docid[1].trim()); } else { doc = (Document)
* proxy.doView(_docid); } setContent(doc);
*/
this._docid = _docid;
getContent().setId(_docid);
}
/*
* public String get_formname() { return _formname; }
*
* public void set_formname(String _formname) { this._formname = _formname; }
*/
public DocumentAction() throws ClassNotFoundException {
super(ProcessFactory.createProcess(DocumentProcess.class),
new Document());
}
public String doView() throws Exception {
String _docid = this.getParams().getParameterAsString("_docid");
ValueObject content = proxy.doView(_docid);
setContent(content);
return SUCCESS;
}
public String doNew() throws Exception {
createNewDoc();
return SUCCESS;
}
public String doNothing() throws Exception {
WebUser user = this.getUser();
ParamsTable params = getParams();
Document doc = (Document) getContent();
Document po = (Document) proxy.doView(getContent().getId());
if (po != null) {
doc.setChilds(po.getChilds());
doc.setState(po.getState());
doc.setFieldPermList(po.getFieldPermList());
doc.setParent(po.getParent());
doc.setSortId(po.getSortId());
}
FormProcessBean fb = (FormProcessBean) (ProcessFactory
.createProcess(FormProcess.class));
Form form = (Form) fb.doView(formid);
doc = form.createDocument(doc, params, getUser());
doc.setAuthor(user);
if (doc.getCreated() == null)
doc.setCreated(new Date());
doc.setLastmodified(new Date());
doc.setFlowid(get_flowid());
setContent(doc);
return SUCCESS;
}
public String doSave() throws Exception {
WebUser user = this.getUser();
ParamsTable params = getParams();
Document doc = (Document) getContent();
Document po = (Document) proxy.doView(getContent().getId());
if (po != null) {
doc.setChilds(po.getChilds());
doc.setState(po.getState());
doc.setFieldPermList(po.getFieldPermList());
doc.setParent(po.getParent());
doc.setSortId(po.getSortId());
doc.setAuthor(po.getAuthor());
}
FormProcessBean fb = (FormProcessBean) (ProcessFactory
.createProcess(FormProcess.class));
Form form = (Form) fb.doView(formid);
doc = form.createDocument(doc, params, getUser());
if(doc.getAuthor()==null)
doc.setAuthor(user);
if (doc.getCreated() == null)
doc.setCreated(new Date());
doc.setLastmodified(new Date());
doc.setFlowid(get_flowid());
setContent(doc);
Collection errors = form.validate(doc, params, user);
if (errors != null && errors.size() > 0) {
for (Iterator iter = errors.iterator(); iter.hasNext();) {
ValidateMessage err = (ValidateMessage) iter.next();
this.addFieldError(err.getFieldname(), err.getErrmessage());
}
return INPUT;
} else {
if (parentid != null && parentid.trim().length() > 0
&& !parentid.equals("null")) {
Document parent = (Document) (((DocumentProcess) proxy)
.doView(parentid));
doc.setParent(parent);
}
try {
super.doSave();
} catch (ImpropriateException ie) {
this.addFieldError("ImpropriateException", ie.getMessage());
} catch (Exception e) {
throw e;
}
// 文档无状态并有流程时开启流程
if (doc.getState() == null && doc.getParent() == null
&& _flowid != null && !_flowid.equals("")) {
startFlow();
}
}
return SUCCESS;
}
public String doSaveClose() throws Exception {
return doSave();
}
public String doSaveNew() throws Exception {
doSave();
createNewDoc();
return SUCCESS;
}
public String doSaveBack() throws Exception {
return doSave();
}
public void validate() {
Document currdoc = ((Document) this.getContent());
String _docid = currdoc.getId();
String parentid = this.getParams().getParameterAsString("parentid");
if (parentid != null && !parentid.equals("")) {
_docid = parentid;
}
String _flowid = "";
if (this.getParams().getParameterAsString("_flowid") != null) {
_flowid = this.getParams().getParameterAsString("_flowid");
}
if (_flowid.equals("") || _flowid == null) {
return;
}
try {
boolean isDocSaveUser = StateMachineHelper.isDocSaveUser(_docid,
_flowid, this.getUser());
if (!isDocSaveUser) {
if (_docid == null || _docid.equals("")) {
createNewDoc();
} else {
Document doc = (Document) (((DocumentProcess) proxy)
.doView(_docid));
setContent(doc);
}
addFieldError("isDocSaveUser",
"Current user couldn't save document");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 开启流程
*
* @throws Exception
*/
public void startFlow() throws Exception {
String _docid = ((Document) getContent()).getId();
StateMachineHelper helper = new StateMachineHelper(_docid, _flowid,
getEnvironment());
Collection firstNodeList = helper.getFirstNodeList(_docid, _flowid,
this.getUser());
String[] _nextids = new String[1];
String _currid = "";
if (firstNodeList != null) {
Iterator it = firstNodeList.iterator();
if (it.hasNext()) {
Node firstNode = (Node) it.next();
_nextids[0] = firstNode.id;
Collection startNodeList = helper.getStartNodeListByFirstNode(
_flowid, firstNode);
Iterator it2 = startNodeList.iterator();
if (it2.hasNext()) {
Node startNode = (Node) it2.next();
_currid = startNode.id;
}
}
}
BillDefiProcess process = (BillDefiProcess) ProcessFactory
.createProcess(BillDefiProcess.class);
BillDefiVO flowVO = (BillDefiVO) process.doView(_flowid);
StateMachine.doFlow(_docid, flowVO, _currid, _nextids, getUser(), "",
"", getEnvironment());
setFlowState(_docid, _flowid);
}
/**
* 设置当前Document的flowState
*/
public void setFlowState(String docid, String flowid) throws Exception {
Document doc = ((Document) this.getContent());
FlowStateRT flowState = StateMachine.getFlowStateRT(docid, flowid);
Collection nodertList = StateMachine.getAllNodeRT(docid, flowid);
// 获取所有ActorRT并添加到flowStateRT
for (Iterator iter = nodertList.iterator(); iter.hasNext();) {
NodeRT nodert = (NodeRT) iter.next();
flowState.getNoderts().add(nodert);
Collection actorList = nodert.getActorrts();
for (Iterator iterator = actorList.iterator(); iterator.hasNext();) {
ActorRT actorrt = (ActorRT) iterator.next();
flowState.getActors().add(actorrt);
}
}
doc.setState(flowState);
super.doSave();
}
public String getFormid() {
return formid;
}
public void setFormid(String formid) {
this.formid = formid;
}
public void createNewDoc() throws Exception {
FormProcessBean fb = (FormProcessBean) (ProcessFactory
.createProcess(FormProcess.class));
WebUser user = this.getUser();
ParamsTable params = new ParamsTable();
Form form = (Form) fb.doView(formid);
Document doc = form.createDocument(params, user);
doc.setAuthor(user);
setContent(doc);
super.doSave(); // 创建一条空记录
}
public String get_flowid() {
return _flowid;
}
public void set_flowid(String _flowid) {
String[] flowids = null;
if (_flowid.indexOf(",") != -1) { // 有多个parmeter时只获取一个
flowids = _flowid.trim().split(",");
_flowid = flowids[0];
}
this._flowid = _flowid;
}
public ParamsTable getParams() {
ParamsTable pm = ParamsTable.convertHTTP(ServletActionContext
.getRequest());
if (pm.getParameter("_pagelines") == null) {
pm.setParameter("_pagelines", Web.DEFAULT_LINES_PER_PAGE);
}
return pm;
}
public String doSelect() throws Exception {
String fieldName = this.getParams().getParameterAsString("fieldname");
String moduleid = this.getParams().getParameterAsString("s_module");
_fieldSelect = ((DocumentProcess) this.proxy).doQueryField(fieldName,
moduleid, getApplication());
return SUCCESS;
}
public Collection get_fieldSelect() {
return _fieldSelect;
}
public void set_fieldSelect(Collection select) {
_fieldSelect = select;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -