workitem.java

来自「Fire-Workflow-Engine-All-In-One-20090208」· Java 代码 · 共 379 行 · 第 1/2 页

JAVA
379
字号
/**
 * Copyright 2007-2008 非也
 * All rights reserved. 
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation。
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses. *
 */
package org.fireflow.engine.impl;

// Generated Feb 23, 2008 12:04:21 AM by Hibernate Tools 3.2.0.b9
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.fireflow.engine.EngineException;
import org.fireflow.engine.IRuntimeContextAware;
import org.fireflow.engine.ITaskInstance;
import org.fireflow.engine.IWorkItem;
import org.fireflow.engine.IWorkflowSession;
import org.fireflow.engine.IWorkflowSessionAware;
import org.fireflow.engine.RuntimeContext;
import org.fireflow.engine.ou.DynamicAssignmentHandler;
import org.fireflow.engine.persistence.IPersistenceService;
import org.fireflow.kenel.IActivityInstance;
import org.fireflow.kenel.INetInstance;
import org.fireflow.kenel.KenelException;
import org.fireflow.model.Task;
import org.fireflow.model.WorkflowProcess;
import org.fireflow.model.net.Activity;
import org.fireflow.model.net.Synchronizer;
import org.fireflow.model.net.Transition;
import org.springframework.beans.BeanUtils;

/**
 * WorkItem generated by hbm2java
 */
public class WorkItem implements IWorkItem, IRuntimeContextAware, IWorkflowSessionAware,java.io.Serializable {

    private String actorId;
    private String id;
    private Integer state = null;
    private Date createdTime;
    private Date signedTime;
    private Date endTime;
    private String comments;
    private ITaskInstance taskInstance;

    protected RuntimeContext rtCtx = null;
    protected IWorkflowSession workflowSession = null;
    public void setRuntimeContext(RuntimeContext ctx){
        this.rtCtx = ctx;
    }    
    public RuntimeContext getRuntimeContext(){
        return this.rtCtx;
    }     
    public WorkItem() {
    }

    public WorkItem(TaskInstance taskInstance) {
        this.taskInstance = taskInstance;
    }

    public WorkItem(Integer state, Date createdTime, Date signedTm,
            Date endTime, String comments, TaskInstance taskInstance) {
        this.state = state;
        this.createdTime = createdTime;
        this.signedTime = signedTm;
        this.endTime = endTime;
        this.comments = comments;
        this.taskInstance = taskInstance;
    }

    public String getId() {
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getState() {
        return this.state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public Date getCreatedTime() {
        return this.createdTime;
    }

    public void setCreatedTime(Date createdTime) {
        this.createdTime = createdTime;
    }

    public Date getSignedTime() {
        return this.signedTime;
    }

    public void setSignedTime(Date acceptedTime) {
        this.signedTime = acceptedTime;
    }

    public Date getEndTime() {
        return this.endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getComments() {
        return this.comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public ITaskInstance getTaskInstance() {
        if (this.taskInstance!=null){
            ((IRuntimeContextAware)this.taskInstance).setRuntimeContext(rtCtx);
//            System.out.println("====Inside WorkItem.getTaskInstance() ,the workflow session is "+(this.workflowSession==null?0:this.workflowSession.hashCode()));
            if (this.workflowSession!=null){
                ((IWorkflowSessionAware)this.taskInstance).setCurrentWorkflowSession(this.workflowSession);
            }
        }
        return this.taskInstance;
    }

    public void setTaskInstance(ITaskInstance taskInstance) {
        this.taskInstance = taskInstance;
    }

    public String getActorId() {
        return actorId;
    }

    public void setActorId(String actorId) {
        this.actorId = actorId;
    }
    
    public void complete() throws EngineException, KenelException {
        complete(null);
    }

    protected void complete(IActivityInstance targetActivityInstance) throws EngineException, KenelException {
        if (this.getState().intValue() != IWorkItem.STARTED) {
//			System.out.println("WorkItem的当前状态为"+this.getState()+",不可以执行complete操作。");
            throw new EngineException("WorkItem的当前状态为" + this.getState() + ",不可以执行complete操作。");
        }
        
        IPersistenceService persistenceService = rtCtx.getPersistenceService();

        this.setState(IWorkItem.COMPLETED);
        this.setEndTime(rtCtx.getCalendarService().getSysDate());
        persistenceService.saveOrUpdateWorkItem(this);

        ((TaskInstance) this.getTaskInstance()).complete(targetActivityInstance);
    }




    public void reasignTo(String actorId) {
        reasignTo(actorId,comments);
    }
    

    public void reasignTo(String actorId,String comments){
        WorkItem wi = new WorkItem();
        BeanUtils.copyProperties(this, wi);
        wi.setActorId(actorId);
        wi.setComments(comments);
        wi.setCreatedTime(rtCtx.getCalendarService().getSysDate());
        rtCtx.getPersistenceService().saveOrUpdateWorkItem(wi);
        
        this.setState(IWorkItem.CANCELED);
        this.setEndTime(rtCtx.getCalendarService().getSysDate());
        rtCtx.getPersistenceService().saveOrUpdateWorkItem(this);

⌨️ 快捷键说明

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