⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myarticleaddsubaction.java

📁 一个很好的jbpm应用实例
💻 JAVA
字号:
package c20.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jbpm.JbpmConfiguration;
import org.jbpm.JbpmContext;
import org.jbpm.graph.def.ProcessDefinition;
import org.jbpm.graph.exe.ProcessInstance;
import org.jbpm.graph.exe.Token;

import c20.entity.Article;
import c20.entity.ArticleType;
import c20.service.ArticleService;
import c20.service.ArticleTypeService;
import c20.session.UserSession;
import c20.util.ConvertUtil;

/** 
 * 
 * 撰写文章操作Action类
 * @struts.action path="/myarticleaddsub" scope="request" validate="false"
 */
public class MyArticleAddSubAction extends Action{
    private static final Log log = LogFactory.getLog(MyArticleAddSubAction.class);
    /**
     * 文章服务接口实现对象
     */
    private ArticleService articleService;
    /**
     * 文章类型服务接口实现对象
     */
    private ArticleTypeService articleTypeService;
    /**
     * JBPM服务接口实现对象
     */
    private JbpmConfiguration jbpmConfiguration;
	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		log.debug("MyArticleAction.execute()");
		
		UserSession userSesssion = UserSession.getSession(request, response);
		//得到文章信息
		String stypeNo = request.getParameter("typeNo");
		int typeNo = ConvertUtil.convertInt(stypeNo);
		String articleName = request.getParameter("articleName");
		String content = request.getParameter("content");
		
		Article article = new Article();
		article.setArticleName(articleName);
		article.setContent(content);
		article.setState(Article.EDITED);
		article.setTypeNo(new Integer(typeNo));
		article.setUserNo(new Integer(userSesssion.getUserNo()));

		//得到相应的文章类型
		ArticleType articleType = articleTypeService.getArticleType(article.getTypeNo().intValue());

		//得到相应的流程定义,启动流程实例
		JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
		
		ProcessDefinition processDefinition = jbpmContext.getGraphSession().findLatestProcessDefinition(articleType.getPdName());
		ProcessInstance processInstance = new ProcessInstance(processDefinition);
		
		//让流程往下进行一步
		Token token = processInstance.getRootToken();
		token.signal();
		
		//保存流程实例与状态
		jbpmContext.save(processInstance);
		jbpmContext.save(token);
		jbpmContext.close();
		
		article.setPiId(processInstance.getId());
		
		//增加文章
		articleService.addArticle(article);
		
		
		return mapping.findForward("success");
	}
	/**
	 * 得到文章服务接口实现对象
	 * @return articleService
	 */
	public ArticleService getArticleService() {
		return articleService;
	}
	/**
	 * 设置文章服务接口实现对象
	 * @param articleService 要设置的 articleService
	 */
	public void setArticleService(ArticleService articleService) {
		this.articleService = articleService;
	}
	/**
	 * 得到文章类型服务接口实现对象
	 * @return articleTypeService
	 */
	public ArticleTypeService getArticleTypeService() {
		return articleTypeService;
	}
	/**
	 * 设置文章类型服务接口实现对象
	 * @param articleTypeService 要设置的 articleTypeService
	 */
	public void setArticleTypeService(ArticleTypeService articleTypeService) {
		this.articleTypeService = articleTypeService;
	}
	/**
	 * 得到JBPM服务接口实现对象
	 * @return jbpmConfiguration
	 */
	public JbpmConfiguration getJbpmConfiguration() {
		return jbpmConfiguration;
	}
	/**
	 * 设置JBPM服务接口实现对象
	 * @param jbpmConfiguration 要设置的 jbpmConfiguration
	 */
	public void setJbpmConfiguration(JbpmConfiguration jbpmConfiguration) {
		this.jbpmConfiguration = jbpmConfiguration;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -