package com.blueland.bpm.engine.config.model;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.bpmn.constants.BpmnXMLConstants;
import org.activiti.bpmn.model.CallActivity;
import org.activiti.bpmn.model.ExclusiveGateway;
import org.activiti.bpmn.model.FlowElement;
import org.activiti.bpmn.model.ScriptTask;
import org.activiti.bpmn.model.ServiceTask;
import org.activiti.bpmn.model.UserTask;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Length;

import com.blueland.bpm.common.base.BaseEntity;

/**
 * @author lw
 * @version 1.0
 * @since
 */

public class ActivityInfoConfig extends BaseEntity implements
		java.io.Serializable {
	private static final long serialVersionUID = 5454155825314635342L;

	// date formats

	// 可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	// columns START
	/**
	 * 流程环节定义ID db_column: ACTIVITY_DEF_ID
	 */
	@Length(max = 100)
	private String activityDefId;
	/**
	 * 流程环节定义名称 db_column: ACTIVITY_DEF_NAME
	 */
	@Length(max = 100)
	private String activityDefName;
	/**
	 * 流程环节状态名称(默认与环节名称一致) db_column: ACTIVITY_STATUS_NAME
	 */
	@Length(max = 100)
	private String activityStatusName;
	/**
	 * 流程定义ID db_column: PROCESS_DEF_ID
	 */
	@Length(max = 100)
	private String processDefId;
	/**
	 * 流程定义名称 db_column: PROCESS_DEF_NAME
	 */
	@Length(max = 100)
	private String processDefName;
	/**
	 * 流程环节表单URL db_column: ACTIVITY_PAGE_URL
	 */
	@Length(max = 500)
	private String activityPageUrl;
	/**
	 * 流程环节表单数据 db_column: ACTIVITY_PAGE_INFO
	 */
	@Length(max = 4000)
	private String activityPageInfo;
	/**
	 * 流程环节绑定操作权限ID,多个权限ID以#号分隔 db_column: ACTIVITY_OPERATION_ROLEID
	 */
	@Length(max = 4000)
	private String activityOperationRoleid;
	/**
	 * remark db_column: REMARK
	 */
	private List<ActivityOperatePower> activityOperatePowers;
	@Length(max = 500)
	private String remark;
	/**
	 * 环节跳转类型，AUTO：自动路径跳转；MANUAL：人工选择跳转、FREE：自由选择跳转
	 */
	private String jumpType;
	/**
	 * 环节跳转类型，AUTO：自动路径跳转；MANUAL：人工选择跳转、FREE：自由选择跳转
	 */
	private static final String JUMP_TYPE_AUTO = "AUTO";
	private static final String JUMP_TYPE_FREE = "FREE";
	private static final String JUMP_TYPE_MANUAL = "MANUAL";

	private boolean autoJumpType;
	private boolean freeJumpType;
	/**
	 * 环节排序
	 */
	private Integer activityOrder;
	/**
	 * 环节时限
	 */
	private Integer activityLimitTime;
	/**
	 * 是否显示意见输入区域,默认启用ENABLED,否则禁用DISABLE
	 */
	private String isShowIdea;
	/**
	 * 意见分栏
	 */
	private String ideaDisplayArea;
	/**
	 * 环节类型
	 */
	private String activityDefType;
	/**
	 *环节处理类型，单人\多人
	 */
	private String activityDefDealType;
	/**
	 * 环节子类型，through:流程贯穿,inside:内部流程
	 */
	private String activityDefChildType;
	/**
	 * 其它系统处理状态   0 不可处理；1 仅阅读；2可处理
	 */
	private String otherSysDealStatus;
	/**
	 * 是否是开始节点  是为Y  否为N
	 */
	private String isStartUserTask;
	
	
	public static String ACTIVITY_DEF_CHILD_TYPE_THROUGH="through";
	public static String ACTIVITY_DEF_CHILD_TYPE_INSIDE="inside";
	private String cprotocol;
	private String murl;
	private String mprotocol;
	private static Map activityDefTypeMap = new HashMap();
	static {
		activityDefTypeMap.put(BpmnXMLConstants.ELEMENT_TASK, "用户任务");
		activityDefTypeMap.put(BpmnXMLConstants.ELEMENT_TASK_SCRIPT, "脚本任务");
		activityDefTypeMap.put(BpmnXMLConstants.ELEMENT_TASK_SERVICE, "服务任务");
		activityDefTypeMap.put(BpmnXMLConstants.ELEMENT_CALL_ACTIVITY, "调用子流");
	}

	private List<DataObject> dataObjects;
	
	// columns END

	public static ActivityInfoConfig build(FlowElement fowElement, String procDefId,
			String procDefName) {
		ActivityInfoConfig actInfoConfig = new ActivityInfoConfig();
		actInfoConfig.setProcessDefId(procDefId);
		actInfoConfig.setProcessDefName(procDefName);
		actInfoConfig.setActivityDefId(fowElement.getId());
		actInfoConfig.setActivityDefName(fowElement.getName());
		if (UserTask.class.isInstance(fowElement)) {
			actInfoConfig.setJumpType("MANUAL");
			actInfoConfig.setActivityDefType(BpmnXMLConstants.ELEMENT_TASK_USER);
		} else if (ScriptTask.class.isInstance(fowElement)) {
			actInfoConfig.setJumpType("AUTO");
			actInfoConfig
					.setActivityDefType(BpmnXMLConstants.ELEMENT_TASK_SCRIPT);
		} else if (ServiceTask.class.isInstance(fowElement)) {
			actInfoConfig.setJumpType("AUTO");
			actInfoConfig
					.setActivityDefType(BpmnXMLConstants.ELEMENT_TASK_SERVICE);
		} else if (ExclusiveGateway.class.isInstance(fowElement)) {
			actInfoConfig.setJumpType("AUTO");
			actInfoConfig.setActivityDefType(BpmnXMLConstants.ELEMENT_GATEWAY_EXCLUSIVE);
		}else if (CallActivity.class.isInstance(fowElement)) {
			actInfoConfig.setJumpType("AUTO");
			actInfoConfig.setActivityDefType(BpmnXMLConstants.ELEMENT_CALL_ACTIVITY);
		}
		actInfoConfig.setActivityDefDealType("single");
		actInfoConfig.setIsShowIdea("ENABLED");
		actInfoConfig.setOtherSysDealStatus("yes");
		actInfoConfig.setCprotocol("hnzy:workitem");
		actInfoConfig.setMprotocol("none");
		
		return actInfoConfig;
	}
public static void main(String[] args) {
	
}

	public List<String> convertActivityOperationRoleid() {
		if (StringUtils.isEmpty(activityOperationRoleid)) {
			return null;
		}
		String[] activityOperationRoleids = null;
		if (activityOperationRoleid.indexOf(";") != -1) {
			activityOperationRoleids = activityOperationRoleid.split(";");
		} else {
			activityOperationRoleids = new String[] { activityOperationRoleid };
		}
		return Arrays.asList(activityOperationRoleids);
	}

	public boolean isAutoJumpType() {
		this.autoJumpType = "AUTO".equals(jumpType);
		return autoJumpType;
	}

	public boolean isFreeJumpType() {
		this.freeJumpType = "FREE".equals(jumpType);
		return freeJumpType;
	}

	public boolean isMulti() {
		return StringUtils.isEmpty(activityDefDealType) ? false : "multi"
				.equals(activityDefDealType);
	}

	public ActivityInfoConfig() {
	}

	public ActivityInfoConfig(String activityDefId, String processDefId) {
		this.activityDefId = activityDefId;
		this.processDefId = processDefId;
	}

	public void setActivityDefId(String value) {
		this.activityDefId = value;
	}

	public String getActivityDefId() {
		return this.activityDefId;
	}

	public void setActivityDefName(String value) {
		this.activityDefName = value;
	}

	public String getActivityDefName() {
		return this.activityDefName;
	}

	public void setProcessDefId(String value) {
		this.processDefId = value;
	}

	public String getProcessDefId() {
		return this.processDefId;
	}

	public void setProcessDefName(String value) {
		this.processDefName = value;
	}

	public String getProcessDefName() {
		return this.processDefName;
	}

	public void setActivityPageUrl(String value) {
		this.activityPageUrl = value;
	}

	public String getActivityPageUrl() {
		return this.activityPageUrl;
	}

	public void setActivityPageInfo(String value) {
		this.activityPageInfo = value;
	}

	public String getActivityPageInfo() {
		return this.activityPageInfo;
	}

	public void setActivityOperationRoleid(String value) {
		this.activityOperationRoleid = value;
	}

	public String getActivityOperationRoleid() {
		return this.activityOperationRoleid;
	}

	public Integer getActivityOrder() {
		return activityOrder;
	}

	public void setActivityOrder(Integer activityOrder) {
		this.activityOrder = activityOrder;
	}

	public void setRemark(String value) {
		this.remark = value;
	}

	public String getRemark() {
		return this.remark;
	}

	public Integer getActivityLimitTime() {
		return activityLimitTime;
	}

	public void setActivityLimitTime(Integer activityLimitTime) {
		this.activityLimitTime = activityLimitTime;
	}

	public String getActivityStatusName() {
		return activityStatusName;
	}

	public void setActivityStatusName(String activityStatusName) {
		this.activityStatusName = activityStatusName;
	}

	public List<ActivityOperatePower> getActivityOperatePowers() {
		return activityOperatePowers;
	}

	public void setActivityOperatePowers(
			List<ActivityOperatePower> activityOperatePowers) {
		this.activityOperatePowers = activityOperatePowers;
	}

	public void setJumpType(String jumpType) {
		this.jumpType = jumpType;
	}

	public String getIsShowIdea() {
		return isShowIdea;
	}

	public void setIsShowIdea(String isShowIdea) {
		this.isShowIdea = isShowIdea;
	}

	public String getJumpType() {
		return jumpType;
	}

	public String getIdeaDisplayArea() {
		return ideaDisplayArea;
	}

	public void setIdeaDisplayArea(String ideaDisplayArea) {
		this.ideaDisplayArea = ideaDisplayArea;
	}

	public String getActivityDefType() {
		return activityDefType;
	}

	public void setActivityDefType(String activityDefType) {
		this.activityDefType = activityDefType;
	}

	public List<DataObject> getDataObjects() {
		return dataObjects;
	}

	public void setDataObjects(List<DataObject> dataObjects) {
		this.dataObjects = dataObjects;
	}

	public String getActivityDefChildType() {
		return activityDefChildType;
	}

	public void setActivityDefChildType(String activityDefChildType) {
		this.activityDefChildType = activityDefChildType;
	}

	public String toString() {
		return ToStringBuilder.reflectionToString(this,
				ToStringStyle.MULTI_LINE_STYLE);
	}

	public String getActivityDefDealType() {
		return activityDefDealType;
	}

	public void setActivityDefDealType(String activityDefDealType) {
		this.activityDefDealType = activityDefDealType;
	}

	

	public String getCprotocol() {
		return cprotocol;
	}


	public void setCprotocol(String cprotocol) {
		this.cprotocol = cprotocol;
	}


	public String getMurl() {
		return murl;
	}


	public void setMurl(String murl) {
		this.murl = murl;
	}


	public String getMprotocol() {
		return mprotocol;
	}


	public void setMprotocol(String mprotocol) {
		this.mprotocol = mprotocol;
	}


	public int hashCode() {
		return new HashCodeBuilder().append(getActivityDefId())
				.append(getProcessDefId()).toHashCode();
	}

	public boolean equals(Object obj) {
		if (obj instanceof ActivityInfoConfig == false)
			return false;
		if (this == obj)
			return true;
		ActivityInfoConfig other = (ActivityInfoConfig) obj;
		return new EqualsBuilder()
				.append(getActivityDefId(), other.getActivityDefId())
				.append(getProcessDefId(), other.getProcessDefId()).isEquals();
	}


	public String getOtherSysDealStatus() {
		return otherSysDealStatus;
	}


	public void setOtherSysDealStatus(String otherSysDealStatus) {
		this.otherSysDealStatus = otherSysDealStatus;
	}


	public String getIsStartUserTask() {
		return isStartUserTask;
	}

	public void setIsStartUserTask(String isStartUserTask) {
		this.isStartUserTask = isStartUserTask;
	}
	
}

