Package org.fireflow.engine.impl

Source Code of org.fireflow.engine.impl.WorkItem

/**
* 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.Date;

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.taskinstance.DynamicAssignmentHandler;
import org.fireflow.engine.taskinstance.ITaskInstanceManager;
import org.fireflow.kernel.KernelException;

/**
* WorkItem generated by hbm2java
*/
@SuppressWarnings("serial")
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 claimedTime;
    private Date endTime;
    private String comments;
    private ITaskInstance taskInstance;
   
    private String taskInstanceId; //added by wangmj 20090922 供springjdbc实现类使用
    public String getTaskInstanceId(){
      return taskInstanceId;
    }
    public void setTaskInstanceId(String taskInstanceId){
      this.taskInstanceId=taskInstanceId;
    }
    protected transient RuntimeContext rtCtx = null;
    protected transient IWorkflowSession workflowSession = null;

    public void setRuntimeContext(RuntimeContext ctx) {
        this.rtCtx = ctx;
        if (this.taskInstance!=null){
          ((IRuntimeContextAware)taskInstance).setRuntimeContext(this.rtCtx);
        }
    }

    public RuntimeContext getRuntimeContext() {
        return this.rtCtx;
    }

    public WorkItem() {
    }

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

    /**
     * @param state
     * @param createdTime
     * @param signedTm
     * @param endTime
     * @param comments
     * @param taskInstance
     */
    public WorkItem(Integer state, Date createdTime, Date signedTm,
            Date endTime, String comments, TaskInstance taskInstance) {
        this.state = state;
        this.createdTime = createdTime;
        this.claimedTime = 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 getClaimedTime() {
        return this.claimedTime;
    }


    public void setClaimedTime(Date claimedTime) {
        this.claimedTime = claimedTime;
    }

    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() {
        return this.taskInstance;
    }

    public void setTaskInstance(ITaskInstance taskInstance) {
        this.taskInstance = taskInstance;
        this.taskInstanceId = taskInstance.getId();//added by wmj2003 20090924
    }

    public String getActorId() {
        return actorId;
    }

    public void setActorId(String actorId) {
        this.actorId = actorId;
    }

    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#withdraw()
     */
    public IWorkItem withdraw() throws EngineException, KernelException {
      if (this.workflowSession==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current workflow session is null.");
      }
      if (this.rtCtx==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current runtime context is null.");       
      }     
        ITaskInstanceManager taskInstanceMgr = this.rtCtx.getTaskInstanceManager();
        return taskInstanceMgr.withdrawWorkItem(this);
    }


    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#reject()
     */
    public void reject()throws EngineException, KernelException{
        reject(this.getComments());
    }
   
    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#reject(java.lang.String)
     */
    public void reject(String comments) throws EngineException, KernelException {
      if (this.workflowSession==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current workflow session is null.");
      }
      if (this.rtCtx==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current runtime context is null.");       
      }     
        ITaskInstanceManager taskInstanceMgr = this.rtCtx.getTaskInstanceManager();
        taskInstanceMgr.rejectWorkItem(this,comments);
    }
   
    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#complete()
     */
    public void complete() throws EngineException, KernelException {
        complete(null,this.getComments());
    }

    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#complete(java.lang.String)
     */
    public void complete(String comments) throws EngineException, KernelException {
        complete(null,comments);
    }

  /* (non-Javadoc)
   * @see org.fireflow.engine.IWorkItem#complete(org.fireflow.engine.taskinstance.DynamicAssignmentHandler, java.lang.String)
   */
  public void complete(DynamicAssignmentHandler dynamicAssignmentHandler, String comments)
      throws EngineException, KernelException {
      if (this.workflowSession==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current workflow session is null.");
      }
      if (this.rtCtx==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current runtime context is null.");       
      }

        if (this.getState().intValue() != IWorkItem.RUNNING) {
            TaskInstance thisTaskInst = (TaskInstance) this.getTaskInstance();
//      System.out.println("WorkItem的当前状态为"+this.getState()+",不可以执行complete操作。");
            throw new EngineException(thisTaskInst.getProcessInstanceId(), thisTaskInst.getWorkflowProcess(),
                    thisTaskInst.getTaskId(),
                    "Complete work item failed . The state of the work item [id=" + this.getId() + "] is " + this.getState());
        }     
     
      if (dynamicAssignmentHandler!=null){
        this.workflowSession.setDynamicAssignmentHandler(dynamicAssignmentHandler);
      }
        ITaskInstanceManager taskInstanceManager = this.rtCtx.getTaskInstanceManager();
        taskInstanceManager.completeWorkItem(this, null,comments);
  }
 
    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#reassignTo(java.lang.String)
     */
    public IWorkItem reassignTo(String actorId) throws EngineException{
        return reassignTo(actorId, this.getComments());
    }

    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#reassignTo(java.lang.String, java.lang.String)
     */
    public IWorkItem reassignTo(String actorId, String comments) throws EngineException{
      if (this.workflowSession==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current workflow session is null.");
      }
      if (this.rtCtx==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current runtime context is null.");       
      }
   
        ITaskInstanceManager manager = this.rtCtx.getTaskInstanceManager();
        return manager.reassignWorkItemTo(this, actorId, comments);
    }

    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#claim()
     */
    public IWorkItem claim() throws EngineException, KernelException {
      if (this.workflowSession==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current workflow session is null.");
      }
      if (this.rtCtx==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current runtime context is null.");       
      }
 
     
        ITaskInstanceManager taskInstanceMgr = rtCtx.getTaskInstanceManager();
        IWorkItem newWorkItem = taskInstanceMgr.claimWorkItem(this.getId(),this.getTaskInstance().getId());
       
        if (newWorkItem!=null){
          this.state = newWorkItem.getState();
          this.claimedTime = newWorkItem.getClaimedTime();
         
          ((IRuntimeContextAware)newWorkItem).setRuntimeContext(rtCtx);
          ((IWorkflowSessionAware)newWorkItem).setCurrentWorkflowSession(this.workflowSession);
        }else{
          this.state = IWorkItem.CANCELED;
        }
       
        return newWorkItem;
    }


    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#jumpTo(java.lang.String)
     */
    public void jumpTo(String activityId) throws EngineException, KernelException {
        jumpTo(activityId, null, this.getComments());
    }

    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#jumpTo(java.lang.String, java.lang.String)
     */
    public void jumpTo(String activityId, String comments) throws EngineException, KernelException {
        jumpTo(activityId, null, comments);
    }

    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#jumpTo(java.lang.String, org.fireflow.engine.taskinstance.DynamicAssignmentHandler, java.lang.String)
     */
    public void jumpTo(String targetActivityId, DynamicAssignmentHandler dynamicAssignmentHandler, String comments) throws EngineException, KernelException {
      if (this.workflowSession==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current workflow session is null.");
      }
      if (this.rtCtx==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current runtime context is null.");       
      }
      if (dynamicAssignmentHandler!=null){
        this.workflowSession.setDynamicAssignmentHandler(dynamicAssignmentHandler);
      }
        ITaskInstanceManager taskInstanceManager = this.rtCtx.getTaskInstanceManager();
        taskInstanceManager.completeWorkItemAndJumpTo(this, targetActivityId,comments);
    }
   
    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkItem#jumpToEx(java.lang.String, org.fireflow.engine.taskinstance.DynamicAssignmentHandler, java.lang.String)
     */
    public void jumpToEx(String targetActivityId, DynamicAssignmentHandler dynamicAssignmentHandler, String comments) throws EngineException, KernelException {
      if (this.workflowSession==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current workflow session is null.");
      }
      if (this.rtCtx==null){
        new EngineException(this.getTaskInstance().getProcessInstanceId(),
            this.getTaskInstance().getWorkflowProcess(),this.getTaskInstance().getTaskId(),
            "The current runtime context is null.");       
      }
      if (dynamicAssignmentHandler!=null){
        this.workflowSession.setDynamicAssignmentHandler(dynamicAssignmentHandler);
      }
        ITaskInstanceManager taskInstanceManager = this.rtCtx.getTaskInstanceManager();
        taskInstanceManager.completeWorkItemAndJumpToEx(this, targetActivityId,comments);
    }  

    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkflowSessionAware#getCurrentWorkflowSession()
     */
    public IWorkflowSession getCurrentWorkflowSession() {
        return this.workflowSession;
    }

    /* (non-Javadoc)
     * @see org.fireflow.engine.IWorkflowSessionAware#setCurrentWorkflowSession(org.fireflow.engine.IWorkflowSession)
     */
    public void setCurrentWorkflowSession(IWorkflowSession session) {
        this.workflowSession = session;
        if (this.taskInstance!=null){
          ((IWorkflowSessionAware)taskInstance).setCurrentWorkflowSession(this.workflowSession);
        }
    }
}
TOP

Related Classes of org.fireflow.engine.impl.WorkItem

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.