PageRenderTime 10ms CodeModel.GetById 8ms app.highlight 92ms RepoModel.GetById 1ms app.codeStats 0ms

/src/main/java/com/sogou/qadev/service/cynthia/bean/impl/FlowImpl.java

https://github.com/desktopqa/Cynthia
Java | 1660 lines | 933 code | 209 blank | 518 comment | 227 complexity | 47d277f048997fdf63b2ad3b021289bf MD5 | raw file
   1package com.sogou.qadev.service.cynthia.bean.impl;
   2
   3import java.util.Arrays;
   4import java.util.HashMap;
   5import java.util.HashSet;
   6import java.util.Iterator;
   7import java.util.LinkedHashMap;
   8import java.util.LinkedHashSet;
   9import java.util.List;
  10import java.util.Map;
  11import java.util.Set;
  12
  13import org.w3c.dom.Document;
  14import org.w3c.dom.Node;
  15
  16import bsh.This;
  17
  18import com.sogou.qadev.service.cynthia.bean.Action;
  19import com.sogou.qadev.service.cynthia.bean.ActionRole;
  20import com.sogou.qadev.service.cynthia.bean.Flow;
  21import com.sogou.qadev.service.cynthia.bean.Right;
  22import com.sogou.qadev.service.cynthia.bean.Role;
  23import com.sogou.qadev.service.cynthia.bean.Stat;
  24import com.sogou.qadev.service.cynthia.bean.UUID;
  25import com.sogou.qadev.service.cynthia.bean.UserInfo;
  26import com.sogou.qadev.service.cynthia.factory.DataAccessFactory;
  27import com.sogou.qadev.service.cynthia.service.ConfigManager;
  28import com.sogou.qadev.service.cynthia.service.DataAccessSession;
  29import com.sogou.qadev.service.cynthia.service.ProjectInvolveManager;
  30import com.sogou.qadev.service.cynthia.util.ArrayUtil;
  31import com.sogou.qadev.service.cynthia.util.CynthiaUtil;
  32import com.sogou.qadev.service.cynthia.util.XMLUtil;
  33
  34/**
  35 * @description:flow
  36 * @author:liming
  37 * @mail:liming@sogou-inc.com
  38 * @date:2014-5-6 下午2:15:06
  39 * @version:v1.0
  40 */
  41public class FlowImpl implements Flow{
  42	
  43	private static final long serialVersionUID = -1L;
  44	private Map<UUID, Action> actionMap = new HashMap<UUID, Action>();
  45	private Set<ActionRole> actionRoleSet = new HashSet<ActionRole>();
  46	/**
  47	 * flow createuser
  48	 */
  49	private String createUser = "";
  50	/**
  51	 * flow id
  52	 */
  53	private UUID id = null;
  54	private boolean isProFlow = false;  //是否项目管理相关流程
  55	/**
  56	 * flow name
  57	 */
  58	private String name = null;
  59	
  60	private Set<Right> rightSet = new HashSet<Right>();
  61
  62	private Map<UUID, Role> roleMap = new HashMap<UUID, Role>();
  63
  64	private Map<UUID, Stat> statMap = new HashMap<UUID, Stat>();
  65	/**
  66	 * 
  67	 * <h1> Title:</h1>
  68	 * <p> Description:init flow from root</p>
  69	 * @date:2014-5-6 
  70	 * @param root
  71	 * @param createUser
  72	 */
  73	public FlowImpl(org.w3c.dom.Node root,String createUser){
  74		this.createUser = createUser;
  75		DataAccessFactory daf = DataAccessFactory.getInstance();
  76
  77		Node flowNode = XMLUtil.getSingleNode(root, "flow");
  78
  79		this.id = daf.createUUID(XMLUtil.getSingleNodeTextContent(flowNode, "id"));
  80		this.name = XMLUtil.getSingleNodeTextContent(flowNode, "name");
  81		this.isProFlow = Boolean.parseBoolean(XMLUtil.getSingleNodeTextContent(flowNode, "isProFlow"));
  82		List<org.w3c.dom.Node> statNodeList = XMLUtil.getNodes(flowNode, "stats/stat");
  83		for(org.w3c.dom.Node statNode : statNodeList){
  84			UUID statId = daf.createUUID(XMLUtil.getSingleNodeTextContent(statNode, "id"));
  85			String statName = XMLUtil.getSingleNodeTextContent(statNode, "name");
  86
  87			StatImpl statImpl = new StatImpl(statId, this.id);
  88			statImpl.setName(statName);
  89
  90			this.statMap.put(statId, statImpl);
  91		}
  92
  93		List<org.w3c.dom.Node> actionNodeList = XMLUtil.getNodes(flowNode, "actions/action");
  94		for(org.w3c.dom.Node actionNode : actionNodeList){
  95			UUID actionId = daf.createUUID(XMLUtil.getSingleNodeTextContent(actionNode, "id"));
  96			String actionName = XMLUtil.getSingleNodeTextContent(actionNode, "name");
  97			String assignToMore = XMLUtil.getSingleNodeTextContent(actionNode, "assignToMore");
  98			UUID beginStatId = daf.createUUID(XMLUtil.getSingleNodeTextContent(actionNode, "startStatId"));
  99			UUID endStatId = daf.createUUID(XMLUtil.getSingleNodeTextContent(actionNode, "endStatId"));
 100
 101			ActionImpl actionImpl = new ActionImpl(actionId, this.id);
 102			actionImpl.setName(actionName);
 103			actionImpl.setBeginStatId(beginStatId);
 104			actionImpl.setEndStatId(endStatId);
 105			actionImpl.setAssignToMore(CynthiaUtil.isNull(assignToMore) ? false : assignToMore.equals("true"));
 106			
 107			this.actionMap.put(actionId, actionImpl);
 108		}
 109
 110		List<org.w3c.dom.Node> roleNodeList = XMLUtil.getNodes(flowNode, "roles/role");
 111		for(org.w3c.dom.Node roleNode : roleNodeList){
 112			UUID roleId	= daf.createUUID(XMLUtil.getSingleNodeTextContent(roleNode, "id"));
 113			String roleName = XMLUtil.getSingleNodeTextContent(roleNode, "name");
 114
 115			RoleImpl roleImpl = new RoleImpl(roleId, this.id);
 116			roleImpl.setName(roleName);
 117
 118			this.roleMap.put(roleId, roleImpl);
 119		}
 120
 121		List<org.w3c.dom.Node> actionRoleNodeList = XMLUtil.getNodes(flowNode, "actionRoles/actionRole");
 122		for(org.w3c.dom.Node actionRoleNode : actionRoleNodeList){
 123			UUID actionId = daf.createUUID(XMLUtil.getSingleNodeTextContent(actionRoleNode, "actionId"));
 124			UUID roleId = daf.createUUID(XMLUtil.getSingleNodeTextContent(actionRoleNode, "roleId"));
 125
 126			this.actionRoleSet.add(new ActionRole(actionId, roleId));
 127		}
 128
 129		List<org.w3c.dom.Node> rightNodeList = XMLUtil.getNodes(flowNode, "rights/right");
 130		for(org.w3c.dom.Node rightNode : rightNodeList){
 131			String username = XMLUtil.getSingleNodeTextContent(rightNode, "username");
 132			String nickname = CynthiaUtil.getUserAlias(username);
 133			UUID roleId = daf.createUUID(XMLUtil.getSingleNodeTextContent(rightNode, "roleId"));
 134			UUID templateId = daf.createUUID(XMLUtil.getSingleNodeTextContent(rightNode, "templateId"));
 135			if (templateId == null) {
 136				continue;
 137			}
 138			this.rightSet.add(new Right(username, templateId, roleId,nickname));
 139		}
 140	}
 141
 142	public FlowImpl(UUID id){
 143		this.id = id;
 144	}
 145
 146	/**
 147	 * (non-Javadoc)
 148	 * <p> Title:addAction</p>
 149	 * <p> Description:TODO</p>
 150	 * @param beginStatId
 151	 * @param endStatId
 152	 * @return
 153	 * @see com.sogou.qadev.service.cynthia.bean.Flow#addAction(com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
 154	 */
 155	public Action addAction(UUID beginStatId, UUID endStatId){
 156		UUID actionId = DataAccessFactory.getInstance().newUUID("ACTI");
 157		ActionImpl action = new ActionImpl(actionId, this.id);
 158		action.setBeginStatId(beginStatId);
 159		action.setEndStatId(endStatId);
 160		this.actionMap.put(actionId, action);
 161
 162		return action;
 163	}
 164
 165	/**
 166	 * (non-Javadoc)
 167	 * <p> Title:addActionRole</p>
 168	 * <p> Description:TODO</p>
 169	 * @param actionId
 170	 * @param roleId
 171	 * @see com.sogou.qadev.service.cynthia.bean.Flow#addActionRole(com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
 172	 */
 173	public void addActionRole(UUID actionId, UUID roleId){
 174		this.actionRoleSet.add(new ActionRole(actionId, roleId));
 175	}
 176
 177	/**
 178	 * (non-Javadoc)
 179	 * <p> Title:addRight</p>
 180	 * <p> Description:TODO</p>
 181	 * @param right
 182	 * @see com.sogou.qadev.service.cynthia.bean.Flow#addRight(com.sogou.qadev.service.cynthia.bean.Right)
 183	 */
 184	public void addRight(Right right){
 185		this.rightSet.add(right);
 186	}
 187
 188	/**
 189	 * (non-Javadoc)
 190	 * <p> Title:addRight</p>
 191	 * <p> Description:TODO</p>
 192	 * @param username
 193	 * @param templateId
 194	 * @param roleId
 195	 * @see com.sogou.qadev.service.cynthia.bean.Flow#addRight(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
 196	 */
 197	public void addRight(String username, UUID templateId, UUID roleId){
 198		String nickname = CynthiaUtil.getUserAlias(username);
 199		this.rightSet.add(new Right(username, templateId, roleId,nickname));
 200	}
 201	
 202	/**
 203	 * (non-Javadoc)
 204	 * <p> Title:addRole</p>
 205	 * <p> Description:TODO</p>
 206	 * @return
 207	 * @see com.sogou.qadev.service.cynthia.bean.Flow#addRole()
 208	 */
 209	public Role addRole(){
 210		UUID roleId = DataAccessFactory.getInstance().newUUID("ROLE");
 211		RoleImpl role = new RoleImpl(roleId, this.id);
 212		this.roleMap.put(roleId, role);
 213
 214		return role;
 215	}
 216
 217	/**
 218	 * (non-Javadoc)
 219	 * <p> Title:addStat</p>
 220	 * <p> Description:TODO</p>
 221	 * @return
 222	 * @see com.sogou.qadev.service.cynthia.bean.Flow#addStat()
 223	 */
 224	public Stat addStat(){
 225		UUID statId = DataAccessFactory.getInstance().newUUID("STAT");
 226		StatImpl statImpl = new StatImpl(statId, this.id);
 227		this.statMap.put(statId, statImpl);
 228
 229		return statImpl;
 230	}
 231
 232	/**
 233	 * (non-Javadoc)
 234	 * <p> Title:authenticate</p>
 235	 * <p> Description:TODO</p>
 236	 * @param username
 237	 * @param templateId
 238	 * @param actionId
 239	 * @return
 240	 * @see com.sogou.qadev.service.cynthia.bean.Flow#authenticate(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
 241	 */
 242	public boolean authenticate(String username, UUID templateId, UUID actionId){
 243		if (username.indexOf(",") != -1) {
 244			username = username.split(",")[0];
 245		}
 246		Action[] actionArray = this.queryUserNodeBeginActions(username, templateId);
 247		for(Action action : actionArray){
 248			if(action.getId().equals(actionId)){
 249				return true;
 250			}
 251		}
 252
 253		return false;
 254	}
 255	
 256	/**
 257	 * (non-Javadoc)
 258	 * <p> Title:authenticate</p>
 259	 * <p> Description:TODO</p>
 260	 * @param username
 261	 * @param templateId
 262	 * @param statId
 263	 * @param actionId
 264	 * @return
 265	 * @see com.sogou.qadev.service.cynthia.bean.Flow#authenticate(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
 266	 */
 267	public boolean authenticate(String username, UUID templateId, UUID statId, UUID actionId){
 268		if (username.indexOf(",") != -1) {
 269			username = username.split(",")[0];
 270		}
 271		Action[] actionArray = this.queryUserNodeStatActions(username, templateId, statId);
 272		for(Action action : actionArray){
 273			if(action.getId().equals(actionId)){
 274				return true;
 275			}
 276		}
 277
 278		return false;
 279	}
 280
 281	/**
 282	 * (non-Javadoc)
 283	 * <p> Title:clone</p>
 284	 * <p> Description:flow clone</p>
 285	 * @return
 286	 * @see java.lang.Object#clone()
 287	 */
 288	public Flow clone(){
 289		FlowImpl flowImpl = new FlowImpl(this.id);
 290		flowImpl.name = this.name;
 291		flowImpl.isProFlow = this.isProFlow;
 292		flowImpl.createUser = this.createUser;
 293
 294		for(UUID statId : this.statMap.keySet()){
 295			flowImpl.statMap.put(statId, this.statMap.get(statId).clone());
 296		}
 297
 298		for(UUID actionId : this.actionMap.keySet()){
 299			flowImpl.actionMap.put(actionId, this.actionMap.get(actionId).clone());
 300		}
 301
 302		for(UUID roleId : this.roleMap.keySet()){
 303			flowImpl.roleMap.put(roleId, this.roleMap.get(roleId).clone());
 304		}
 305
 306		for(Right right : this.rightSet){
 307			flowImpl.rightSet.add(right);
 308		}
 309
 310		for(ActionRole actionRole : this.actionRoleSet){
 311			flowImpl.actionRoleSet.add(actionRole);
 312		}
 313
 314		return flowImpl;
 315	}
 316
 317	/**
 318	 * (non-Javadoc)
 319	 * <p> Title:equals</p>
 320	 * <p> Description:TODO</p>
 321	 * @param obj
 322	 * @return
 323	 * @see java.lang.Object#equals(java.lang.Object)
 324	 */
 325	public boolean equals(Object obj){
 326		return this.id.equals(((FlowImpl)obj).id);
 327	}
 328	/**
 329	 * (non-Javadoc)
 330	 * <p> Title:getAction</p>
 331	 * <p> Description:TODO</p>
 332	 * @param actionName
 333	 * @return
 334	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getAction(java.lang.String)
 335	 */
 336	public Action getAction(String actionName){
 337		for(Action action : this.actionMap.values()){
 338			if(action.getName().equals(actionName)){
 339				return action;
 340			}
 341		}
 342
 343		return null;
 344	}
 345
 346	/**
 347	 * (non-Javadoc)
 348	 * <p> Title:getAction</p>
 349	 * <p> Description:TODO</p>
 350	 * @param actionId
 351	 * @return
 352	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getAction(com.sogou.qadev.service.cynthia.bean.UUID)
 353	 */
 354	public Action getAction(UUID actionId){
 355		return this.actionMap.get(actionId);
 356	}
 357
 358	/**
 359	 * (non-Javadoc)
 360	 * <p> Title:getActionMap</p>
 361	 * @return
 362	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getActionMap()
 363	 */
 364	public Map<UUID, Action> getActionMap() {
 365		return this.actionMap;
 366	}
 367
 368	/**
 369	 * (non-Javadoc)
 370	 * <p> Title:getActionRoleSet</p>
 371	 * @return
 372	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getActionRoleSet()
 373	 */
 374	public Set<ActionRole> getActionRoleSet() {
 375		return this.actionRoleSet;
 376	}
 377	
 378	/**
 379	 * (non-Javadoc)
 380	 * <p> Title:getActions</p>
 381	 * <p> Description:TODO</p>
 382	 * @return
 383	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getActions()
 384	 */
 385	public Action[] getActions(){
 386		return this.actionMap.values().toArray(new Action[this.actionMap.size()]);
 387	}
 388
 389	/**
 390	 * (non-Javadoc)
 391	 * <p> Title:getBeginStats</p>
 392	 * <p> Description:TODO</p>
 393	 * @return
 394	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getBeginStats()
 395	 */
 396	public Stat[] getBeginStats(){
 397		HashSet<Stat> statSet = new HashSet<Stat>();
 398		for(Action action : this.actionMap.values()){
 399			if(action.getBeginStatId() != null){
 400				continue;
 401			}
 402
 403			Stat endStat = this.statMap.get(action.getEndStatId());
 404			if(endStat != null){
 405				statSet.add(endStat);
 406			}
 407		}
 408
 409		return statSet.toArray(new Stat[statSet.size()]);
 410	}
 411
 412	@Override
 413	public String getCreateUser() {
 414		return this.createUser;
 415	}
 416
 417	/**
 418	 * (non-Javadoc)
 419	 * <p> Title:getEndActions</p>
 420	 * <p> Description:TODO</p>
 421	 * @return
 422	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getEndActions()
 423	 */
 424	public Action[] getEndActions(){
 425		Stat[] endStats = getEndStats();
 426		HashSet<Action> actionSet = new HashSet<Action>();
 427		for(Stat stat : endStats){
 428			for(Action action : this.actionMap.values()){
 429				if(action.getEndStatId()!=null&&action.getEndStatId().equals(stat.getId()))
 430					actionSet.add(action);
 431			}
 432		}
 433
 434		return actionSet.toArray(new Action[actionSet.size()]);
 435	}
 436
 437	/**
 438	 * (non-Javadoc)
 439	 * <p> Title:getEndStats</p>
 440	 * <p> Description:TODO</p>
 441	 * @return
 442	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getEndStats()
 443	 */
 444	public Stat[] getEndStats(){
 445		HashSet<Stat> statSet = new HashSet<Stat>();
 446		for(Stat stat : this.statMap.values()){
 447			boolean isEnd = true;
 448			for(Action action : this.actionMap.values()){
 449				if(action.getBeginStatId() != null && action.getBeginStatId().equals(stat.getId())){
 450					isEnd = false;
 451					break;
 452				}
 453			}
 454
 455			if(isEnd){
 456				statSet.add(stat);
 457			}
 458		}
 459
 460		return statSet.toArray(new Stat[statSet.size()]);
 461	}
 462
 463	@Override
 464	public UUID getId(){
 465		return this.id;
 466	}
 467	
 468	@Override
 469	public String getName(){
 470		return this.name;
 471	}
 472
 473	@Override
 474	public Set<Right> getRightSet() {
 475		return this.rightSet;
 476	}
 477
 478	/**
 479	 * (non-Javadoc)
 480	 * <p> Title:getRole</p>
 481	 * <p> Description:TODO</p>
 482	 * @param roleName
 483	 * @return
 484	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getRole(java.lang.String)
 485	 */
 486	public Role getRole(String roleName){
 487		for(Role role : this.roleMap.values()){
 488			if(role.getName().equals(roleName)){
 489				return role;
 490			}
 491		}
 492
 493		return null;
 494	}
 495
 496	/**
 497	 * (non-Javadoc)
 498	 * <p> Title:getRole</p>
 499	 * <p> Description:TODO</p>
 500	 * @param roleId
 501	 * @return
 502	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getRole(com.sogou.qadev.service.cynthia.bean.UUID)
 503	 */
 504	public Role getRole(UUID roleId){
 505		return this.roleMap.get(roleId);
 506	}
 507
 508	@Override
 509	public Map<UUID, Role> getRoleMap() {
 510		return this.roleMap;
 511	}
 512
 513	/**
 514	 * (non-Javadoc)
 515	 * <p> Title:getRoles</p>
 516	 * <p> Description:TODO</p>
 517	 * @return
 518	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getRoles()
 519	 */
 520	public Role[] getRoles(){
 521		if (ConfigManager.getProjectInvolved() && this.isProFlow) {
 522			return ProjectInvolveManager.getInstance().getAllRole(this.createUser).toArray(new Role[0]);
 523		}else {
 524			return this.roleMap.values().toArray(new Role[this.roleMap.size()]);
 525		}
 526	}
 527
 528	/**
 529	 * (non-Javadoc)
 530	 * <p> Title:getStartActions</p>
 531	 * @return
 532	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getStartActions()
 533	 */
 534	public Set<Action> getStartActions(){
 535		HashSet<Action> actionSet = new HashSet<Action>();
 536		for(Action action : this.actionMap.values()){
 537			if(action.getBeginStatId()==null)
 538				actionSet.add(action);
 539		}
 540
 541		return actionSet;
 542	}
 543
 544	/**
 545	 * (non-Javadoc)
 546	 * <p> Title:getStat</p>
 547	 * <p> Description:TODO</p>
 548	 * @param statName
 549	 * @return
 550	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getStat(java.lang.String)
 551	 */
 552	public Stat getStat(String statName){
 553		for(Stat stat : this.statMap.values()){
 554			if(stat.getName().equals(statName)){
 555				return stat;
 556			}
 557		}
 558
 559		return null;
 560	}
 561
 562	public Stat getStat(UUID statId){
 563		return this.statMap.get(statId);
 564	}
 565
 566	@Override
 567	public Map<UUID, Stat> getStatMap() {
 568		return this.statMap;
 569	}
 570
 571	/**
 572	 * (non-Javadoc)
 573	 * <p> Title:getStats</p>
 574	 * <p> Description:TODO</p>
 575	 * @return
 576	 * @see com.sogou.qadev.service.cynthia.bean.Flow#getStats()
 577	 */
 578	public Stat[] getStats(){
 579		return this.statMap.values().toArray(new Stat[this.statMap.size()]);
 580	}
 581
 582	/**
 583	 * (non-Javadoc)
 584	 * <p> Title:hasActionRole</p>
 585	 * <p> Description:TODO</p>
 586	 * @param actionId
 587	 * @param roleId
 588	 * @return
 589	 * @see com.sogou.qadev.service.cynthia.bean.Flow#hasActionRole(com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
 590	 */
 591	public boolean hasActionRole(UUID actionId, UUID roleId){
 592		return this.actionRoleSet.contains(new ActionRole(actionId, roleId));
 593	}
 594
 595	public int hashCode(){
 596		return this.id.hashCode();
 597	}
 598
 599	/**
 600	 * (non-Javadoc)
 601	 * <p> Title:hasRight</p>
 602	 * <p> Description:TODO</p>
 603	 * @param username
 604	 * @param templateId
 605	 * @param roleId
 606	 * @return
 607	 * @see com.sogou.qadev.service.cynthia.bean.Flow#hasRight(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
 608	 */
 609	public boolean hasRight(String username, UUID templateId, UUID roleId){
 610		if (this.isProFlow) {
 611			return ProjectInvolveManager.getInstance().isUserInRole(username, roleId);
 612		}else {
 613			String nickname = CynthiaUtil.getUserAlias(username);
 614			if (username.indexOf(",") != -1) {
 615				username = username.split(",")[0];
 616			}
 617			return this.rightSet.contains(new Right(username, templateId, roleId,nickname));
 618		}
 619	}
 620
 621	/**
 622	 * (non-Javadoc)
 623	 * <p> Title:isActionEveryoneRole</p>
 624	 * <p> Description:TODO</p>
 625	 * @param actionId
 626	 * @return
 627	 * @see com.sogou.qadev.service.cynthia.bean.Flow#isActionEveryoneRole(com.sogou.qadev.service.cynthia.bean.UUID)
 628	 */
 629	public boolean isActionEveryoneRole(UUID actionId){
 630		for(ActionRole actionRole : this.actionRoleSet){
 631			if(actionRole.actionId.equals(actionId) && actionRole.roleId.equals(Role.everyoneUUID)){
 632				return true;
 633			}
 634		}
 635
 636		return false;
 637	}
 638
 639	/**
 640	 * (non-Javadoc)
 641	 * <p> Title:isDeleteActionAllow</p>
 642	 * <p> Description:TODO</p>
 643	 * @param user
 644	 * @param templateId
 645	 * @return
 646	 * @see com.sogou.qadev.service.cynthia.bean.Flow#isDeleteActionAllow(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID)
 647	 */
 648	@Override
 649	public boolean isDeleteActionAllow(String user, UUID templateId) {
 650		if(isActionEveryoneRole(Action.deleteUUID))
 651			return true;
 652
 653		Role[] roleArray = queryUserNodeRoles(user, templateId);
 654		if(roleArray != null)
 655		{
 656			for(Role role : roleArray)
 657			{
 658				if(isRoleDeleteAction(role.getId()))
 659					return true;
 660			}
 661		}
 662		return false;
 663	}
 664
 665	/**
 666	 * (non-Javadoc)
 667	 * <p> Title:isEditActionAllow</p>
 668	 * <p> Description:TODO</p>
 669	 * @param user
 670	 * @param templateId
 671	 * @param assignUser
 672	 * @param actionUser
 673	 * @return
 674	 * @see com.sogou.qadev.service.cynthia.bean.Flow#isEditActionAllow(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID, java.lang.String, java.lang.String)
 675	 */
 676	public boolean isEditActionAllow(String user, UUID templateId, String assignUser, String actionUser)
 677	{
 678		if(isActionEveryoneRole(Action.editUUID))
 679			return true;
 680
 681		Role[] roleArray = queryUserNodeRoles(user, templateId);
 682		if(roleArray != null)
 683		{
 684			for(Role role : roleArray)
 685			{
 686				if(isRoleEditAction(role.getId()))
 687					return true;
 688			}
 689		}
 690
 691		Set<UUID> roleIdSet = new HashSet<UUID>();
 692		if(roleArray != null)
 693		{
 694			for(Role role : roleArray)
 695				roleIdSet.add(role.getId());
 696		}
 697
 698		return false;
 699	}
 700	
 701	public boolean isProFlow() {
 702		return isProFlow;
 703	}
 704
 705	/**
 706	 * (non-Javadoc)
 707	 * <p> Title:isReadActionAllow</p>
 708	 * <p> Description:TODO</p>
 709	 * @param user
 710	 * @param templateId
 711	 * @param assignUser
 712	 * @param logUserArray
 713	 * @return
 714	 * @see com.sogou.qadev.service.cynthia.bean.Flow#isReadActionAllow(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID, java.lang.String, java.lang.String[])
 715	 */
 716	public boolean isReadActionAllow(String user, UUID templateId, String assignUser, String[] logUserArray)
 717	{
 718		if(isActionEveryoneRole(Action.readUUID))
 719			return true;
 720
 721		Role[] roleArray = queryUserNodeRoles(user, templateId);
 722		if(roleArray != null)
 723		{
 724			for(Role role : roleArray)
 725			{
 726				if(isRoleReadAction(role.getId()))
 727					return true;
 728			}
 729		}
 730
 731		Set<UUID> roleIdSet = new HashSet<UUID>();
 732		if(roleArray != null)
 733		{
 734			for(Role role : roleArray)
 735				roleIdSet.add(role.getId());
 736		}
 737
 738		if(assignUser != null)
 739		{
 740			Role[] assignUserRoleArray = queryUserNodeRoles(assignUser, templateId);
 741			if(assignUserRoleArray != null)
 742			{
 743				for(Role assignUserRole : assignUserRoleArray)
 744				{
 745					if(roleIdSet.contains(assignUserRole.getId()))
 746						return true;
 747				}
 748			}
 749		}
 750
 751		for(String logUser : logUserArray)
 752		{
 753			Role[] logUserRoleArray = queryUserNodeRoles(logUser, templateId);
 754			if(logUserRoleArray != null)
 755			{
 756				for(Role logUserRole : logUserRoleArray)
 757				{
 758					if(roleIdSet.contains(logUserRole.getId()))
 759						return true;
 760				}
 761			}
 762		}
 763
 764		return false;
 765	}
 766
 767	/**
 768	 * (non-Javadoc)
 769	 * <p> Title:isRoleDeleteAction</p>
 770	 * <p> Description:TODO</p>
 771	 * @param roleId
 772	 * @return
 773	 * @see com.sogou.qadev.service.cynthia.bean.Flow#isRoleDeleteAction(com.sogou.qadev.service.cynthia.bean.UUID)
 774	 */
 775	public boolean isRoleDeleteAction(UUID roleId) {
 776		for(ActionRole actionRole : this.actionRoleSet){
 777			if(actionRole.roleId.equals(roleId) && actionRole.actionId.equals(Action.deleteUUID)){
 778				return true;
 779			}
 780		}
 781
 782		return false;
 783	}
 784	
 785	/**
 786	 * (non-Javadoc)
 787	 * <p> Title:isRoleEditAction</p>
 788	 * <p> Description:TODO</p>
 789	 * @param roleId
 790	 * @return
 791	 * @see com.sogou.qadev.service.cynthia.bean.Flow#isRoleEditAction(com.sogou.qadev.service.cynthia.bean.UUID)
 792	 */
 793	public boolean isRoleEditAction(UUID roleId){
 794		for(ActionRole actionRole : this.actionRoleSet){
 795			if(actionRole.roleId.equals(roleId) && actionRole.actionId.equals(Action.editUUID)){
 796				return true;
 797			}
 798		}
 799		return false;
 800	}
 801
 802	/**
 803	 * (non-Javadoc)
 804	 * <p> Title:isRoleReadAction</p>
 805	 * <p> Description:TODO</p>
 806	 * @param roleId
 807	 * @return
 808	 * @see com.sogou.qadev.service.cynthia.bean.Flow#isRoleReadAction(com.sogou.qadev.service.cynthia.bean.UUID)
 809	 */
 810	public boolean isRoleReadAction(UUID roleId){
 811		for(ActionRole actionRole : this.actionRoleSet){
 812			if(actionRole.roleId.equals(roleId) && actionRole.actionId.equals(Action.readUUID)){
 813				return true;
 814			}
 815		}
 816
 817		return false;
 818	}
 819
 820	/**
 821	 * (non-Javadoc)
 822	 * <p> Title:queryActionRoles</p>
 823	 * <p> Description:TODO</p>
 824	 * @param actionId
 825	 * @return
 826	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryActionRoles(com.sogou.qadev.service.cynthia.bean.UUID)
 827	 */
 828	public Role[] queryActionRoles(UUID actionId){
 829		if (this.isProFlow) {
 830			return ProjectInvolveManager.getInstance().queryActionRoles(this.createUser, this, actionId);
 831		}else {
 832			Set<Role> roleSet = new HashSet<Role>();
 833
 834			for(ActionRole actionRole : this.actionRoleSet){
 835				if(actionRole.actionId.equals(actionId)){
 836					Role role = this.roleMap.get(actionRole.roleId);
 837					if(role != null){
 838						roleSet.add(role);
 839					}
 840				}
 841			}
 842
 843			return roleSet.toArray(new Role[roleSet.size()]);
 844		}
 845	}
 846
 847	@Override
 848	public Set<Action> queryActionsByStartStatId(UUID statId){
 849		Set<Action> allActions = new HashSet<Action>();
 850		for (Action action : this.getActions()) {
 851			if (action.getBeginStatId() != null && action.getBeginStatId().equals(statId)) {
 852				allActions.add(action);
 853			}
 854		}
 855		return allActions;
 856	}
 857	
 858	@Override
 859	public Set<Action> queryActionsByEndStatId(UUID statId){
 860		Set<Action> allActions = new HashSet<Action>();
 861		for (Action action : this.getActions()) {
 862			if (action.getEndStatId() != null && action.getEndStatId().equals(statId)) {
 863				allActions.add(action);
 864			}
 865		}
 866		return allActions;
 867	}
 868	
 869	@Override
 870	public String queryNextActionRoleIdsByActionId(UUID actionId){
 871		Action action = getAction(actionId);
 872		if (action == null) {
 873			return "";
 874		}
 875		
 876		Set<String> allRoleSet = new HashSet<String>();
 877		
 878		Set<Action> allActions = queryActionsByStartStatId(action.getEndStatId());
 879		for (Action action2 : allActions) {
 880			for(ActionRole actionRole : this.actionRoleSet){
 881				if(actionRole.actionId.equals(action2.getId())){
 882					allRoleSet.add(actionRole.getRoleId().getValue());
 883				}
 884			}
 885		}
 886		return ArrayUtil.strArray2String(allRoleSet.toArray(new String[0]));
 887	}
 888	
 889	
 890	@Override
 891	public String queryNextActionRoleIdsByStatId(UUID statId){
 892		Set<String> allRoleSet = new HashSet<String>();
 893		Set<Action> allActions = queryActionsByStartStatId(statId);
 894		for (Action action : allActions) {
 895			for(ActionRole actionRole : this.actionRoleSet){
 896				if(actionRole.actionId.equals(action.getId())){
 897					allRoleSet.add(actionRole.getRoleId().getValue());
 898				}
 899			}
 900		}
 901		return ArrayUtil.strArray2String(allRoleSet.toArray(new String[0]));
 902	}
 903	
 904	@Override
 905	public String queryActionRoleIds(UUID actionId){
 906		StringBuffer roleIds = new StringBuffer();
 907		
 908		for(ActionRole actionRole : this.actionRoleSet){
 909			if(actionRole.actionId.equals(actionId)){
 910				roleIds.append(roleIds.length() > 0 ? "," : "").append(actionRole.getRoleId().getValue());
 911			}
 912		}
 913		return roleIds.toString();
 914	}
 915	
 916	
 917	/**
 918	 * (non-Javadoc)
 919	 * <p> Title:queryAllQuitUserInfo</p>
 920	 * <p> Description:TODO</p>
 921	 * @param roleId
 922	 * @return
 923	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryAllQuitUserInfo(com.sogou.qadev.service.cynthia.bean.UUID)
 924	 */
 925	@Override
 926	public List<UserInfo> queryAllQuitUserInfo(UUID roleId) {
 927		Set<String> allRoleUser = queryAllUserByRole(roleId);
 928		DataAccessSession das = DataAccessFactory.getInstance().getSysDas();
 929		return das.queryAllUserInfo(allRoleUser.toArray(new String[0]),true);
 930	}
 931
 932	/**
 933	 * (non-Javadoc)
 934	 * <p> Title:queryAllUser</p>
 935	 * <p> Description:TODO</p>
 936	 * @return
 937	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryAllUser()
 938	 */
 939	public Set<String> queryAllUser(){
 940		Set<String> allUser = new HashSet<String>();
 941		for (Right right : this.rightSet) {
 942			allUser.add(right.getUsername());
 943		}
 944		return allUser;
 945	}
 946
 947	/**
 948	 * (non-Javadoc)
 949	 * <p> Title:queryAllUserByRole</p>
 950	 * <p> Description:TODO</p>
 951	 * @param roleId
 952	 * @return
 953	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryAllUserByRole(com.sogou.qadev.service.cynthia.bean.UUID)
 954	 */
 955	public Set<String> queryAllUserByRole(UUID roleId){
 956		Set<String> allUser = new HashSet<String>();
 957		for (Right right : this.rightSet) {
 958			if (right.roleId.equals(roleId)) {
 959				allUser.add(right.getUsername());
 960			}
 961		}
 962		return allUser;
 963	}
 964
 965	/**
 966	 * (non-Javadoc)
 967	 * <p> Title:queryAllUserInfo</p>
 968	 * <p> Description:TODO</p>
 969	 * @return
 970	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryAllUserInfo()
 971	 */
 972	@Override
 973	public List<UserInfo> queryAllUserInfo() {
 974		Set<String> allRoleUser = queryAllUser();
 975		DataAccessSession das = DataAccessFactory.getInstance().getSysDas();
 976		return das.queryAllUserInfo(allRoleUser.toArray(new String[0]),false);
 977	}
 978
 979	/**
 980	 * (non-Javadoc)
 981	 * <p> Title:queryAllUserInfo</p>
 982	 * <p> Description:TODO</p>
 983	 * @param roleId
 984	 * @return
 985	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryAllUserInfo(com.sogou.qadev.service.cynthia.bean.UUID)
 986	 */
 987	@Override
 988	public List<UserInfo> queryAllUserInfo(UUID roleId) {
 989		Set<String> allRoleUser = queryAllUserByRole(roleId);
 990		DataAccessSession das = DataAccessFactory.getInstance().getSysDas();
 991		return das.queryAllUserInfo(allRoleUser.toArray(new String[0]),false);
 992	}
 993
 994	/**
 995	 * (non-Javadoc)
 996	 * <p> Title:queryBeginActions</p>
 997	 * <p> Description:TODO</p>
 998	 * @return
 999	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryBeginActions()
1000	 */
1001	public Action[] queryBeginActions(){
1002		Set<Action> actionSet = new LinkedHashSet<Action>();
1003
1004		for(Action action : this.actionMap.values()){
1005			if(action.getBeginStatId() == null){
1006				actionSet.add(action);
1007			}
1008		}
1009
1010		return actionSet.toArray(new Action[actionSet.size()]);
1011	}
1012
1013	
1014	public boolean isEndAction(UUID actionId){
1015		for (Action action : this.getEndActions()) {
1016			if (action != null && action.getId().equals(actionId)) {
1017				return true;
1018			}
1019		}
1020		return false;
1021	}
1022	
1023	/**
1024	 * (non-Javadoc)
1025	 * <p> Title:queryEditActionRoles</p>
1026	 * <p> Description:TODO</p>
1027	 * @return
1028	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryEditActionRoles()
1029	 */
1030	public Role[] queryEditActionRoles()
1031	{
1032		if (this.isProFlow) {
1033			return ProjectInvolveManager.getInstance().getAllRole(this.createUser).toArray(new Role[0]);
1034		}else {
1035			if(this.actionRoleSet == null)
1036				return new Role[0];
1037
1038			Set<Role> roleSet = new LinkedHashSet<Role>();
1039
1040			for(ActionRole actionRole : this.actionRoleSet)
1041			{
1042				if(!actionRole.actionId.equals(Action.editUUID))
1043					continue;
1044
1045				Role role = this.roleMap.get(actionRole.roleId);
1046				if(role != null)
1047					roleSet.add(role);
1048			}
1049
1050			return roleSet.toArray(new Role[0]);
1051		}
1052	}
1053
1054	/**
1055	 * (non-Javadoc)
1056	 * <p> Title:queryEveryoneRoleActions</p>
1057	 * <p> Description:TODO</p>
1058	 * @return
1059	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryEveryoneRoleActions()
1060	 */
1061	public Action[] queryEveryoneRoleActions()
1062	{
1063		if(this.actionRoleSet == null)
1064			return new Action[0];
1065
1066		Set<Action> actionSet = new LinkedHashSet<Action>();
1067
1068		for(ActionRole actionRole : this.actionRoleSet)
1069		{
1070			if(!actionRole.roleId.equals(Role.everyoneUUID))
1071				continue;
1072
1073			Action action = this.actionMap.get(actionRole.actionId);
1074			if(action != null)
1075				actionSet.add(action);
1076		}
1077
1078		return actionSet.toArray(new Action[0]);
1079	}
1080
1081	/**
1082	 * (non-Javadoc)
1083	 * <p> Title:queryNodeRoles</p>
1084	 * <p> Description:TODO</p>
1085	 * @param templateId
1086	 * @return
1087	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryNodeRoles(com.sogou.qadev.service.cynthia.bean.UUID)
1088	 */
1089	public Role[] queryNodeRoles(UUID templateId)
1090	{
1091		Map<UUID, Role> roleMap = new LinkedHashMap<UUID, Role>();
1092		for(Right right: this.rightSet)
1093		{
1094			if(right.templateId.equals(templateId))
1095			{
1096				Role role = this.roleMap.get(right.roleId);
1097				if(role != null)
1098					roleMap.put(role.getId(), role);
1099			}
1100		}
1101
1102		return roleMap.values().toArray(new Role[0]);
1103	}
1104
1105	/**
1106	 * (non-Javadoc)
1107	 * <p> Title:queryNodeRoleUsers</p>
1108	 * <p> Description:TODO</p>
1109	 * @param templateId
1110	 * @param roleId
1111	 * @return
1112	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryNodeRoleUsers(com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
1113	 */
1114	public String[] queryNodeRoleUsers(UUID templateId, UUID roleId)
1115	{
1116		HashSet<String> userSet = new HashSet<String>();
1117		for (Right right : this.rightSet)
1118		{
1119			if(right.templateId.equals(templateId) && right.roleId.equals(roleId))
1120				userSet.add(right.username);
1121		}
1122
1123		return userSet.toArray(new String[0]);
1124	}
1125
1126	/**
1127	 * (non-Javadoc)
1128	 * <p> Title:queryNodeStatAssignUsers</p>
1129	 * <p> Description:TODO</p>
1130	 * @param templateId
1131	 * @param statId
1132	 * @return
1133	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryNodeStatAssignUsers(com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
1134	 */
1135	public String[] queryNodeStatAssignUsers(UUID templateId, UUID statId){
1136		Set<UUID> roleIdSet = new HashSet<UUID>();
1137
1138		Action[] actionArray = this.queryStatActions(statId);
1139		for(Action action : actionArray){
1140			Role[] roleArray = this.queryActionRoles(action.getId());
1141			for(Role role : roleArray){
1142				roleIdSet.add(role.getId());
1143			}
1144		}
1145
1146		Set<String> userSet = new HashSet<String>();
1147
1148		for(Right right : this.rightSet){
1149			if(right.templateId.equals(templateId) && roleIdSet.contains(right.roleId)){
1150				userSet.add(right.username);
1151			}
1152		}
1153
1154		String[] allUser = userSet.toArray(new String[userSet.size()]);
1155		
1156		Arrays.sort(allUser);
1157		
1158		return allUser;
1159	}
1160
1161	/**
1162	 * (non-Javadoc)
1163	 * <p> Title:queryNodeUserRight</p>
1164	 * @param templateId
1165	 * @return
1166	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryNodeUserRight(com.sogou.qadev.service.cynthia.bean.UUID)
1167	 */
1168	public Right[] queryNodeUserRight(UUID templateId){
1169		HashSet<Right> userSet = new HashSet<Right>();
1170		for (Right right : this.rightSet)
1171		{
1172			if(right.templateId.equals(templateId))
1173				userSet.add(right);
1174		}
1175		
1176		Right[] userRights = userSet.toArray(new Right[userSet.size()]);
1177		Arrays.sort(userRights);
1178		return userRights;
1179	}
1180
1181	/**
1182	 * (non-Javadoc)
1183	 * <p> Title:queryNodeUsers</p>
1184	 * <p> Description:TODO</p>
1185	 * @param templateId
1186	 * @return
1187	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryNodeUsers(com.sogou.qadev.service.cynthia.bean.UUID)
1188	 */
1189	public String[] queryNodeUsers(UUID templateId)
1190	{
1191		HashSet<String> userSet = new HashSet<String>();
1192		for (Right right : this.rightSet)
1193		{
1194			if(right.templateId.equals(templateId))
1195				userSet.add(right.username);
1196		}
1197		
1198		String[] userArray = userSet.toArray(new String[userSet.size()]);
1199		Arrays.sort(userArray);
1200		return userArray;
1201	}
1202
1203	/**
1204	 * (non-Javadoc)
1205	 * <p> Title:queryReadActionRoles</p>
1206	 * <p> Description:TODO</p>
1207	 * @return
1208	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryReadActionRoles()
1209	 */
1210	public Role[] queryReadActionRoles()
1211	{
1212		if(this.actionRoleSet == null)
1213			return new Role[0];
1214
1215		Set<Role> roleSet = new LinkedHashSet<Role>();
1216
1217		for(ActionRole actionRole : this.actionRoleSet)
1218		{
1219			if(!actionRole.actionId.equals(Action.readUUID))
1220				continue;
1221
1222			Role role = this.roleMap.get(actionRole.roleId);
1223			if(role != null)
1224				roleSet.add(role);
1225		}
1226
1227		return roleSet.toArray(new Role[0]);
1228	}
1229	
1230	/**
1231	 * (non-Javadoc)
1232	 * <p> Title:queryRightsByRole</p>
1233	 * <p> Description:TODO</p>
1234	 * @param roleId
1235	 * @return
1236	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryRightsByRole(com.sogou.qadev.service.cynthia.bean.UUID)
1237	 */
1238	@Override
1239	public Set<Right> queryRightsByRole(UUID roleId) {
1240		Set<Right> allRightSet = new HashSet<Right>();
1241		for (Right right : this.rightSet) {
1242			if (right.roleId.equals(roleId)) {
1243				allRightSet.add(right);
1244			}
1245		}
1246		return allRightSet;
1247	}
1248
1249	@Override
1250	public Set<Right> queryRightsByRole(UUID roleId, UUID templateId) {
1251		
1252		Set<Right> allRightSet = new HashSet<Right>();
1253		for (Right right : this.rightSet) {
1254			if (right.roleId.equals(roleId) && right.templateId.equals(templateId)) {
1255				allRightSet.add(right);
1256			}
1257		}
1258		return allRightSet;
1259	}
1260
1261	/**
1262	 * (non-Javadoc)
1263	 * <p> Title:queryRoleActions</p>
1264	 * <p> Description:TODO</p>
1265	 * @param roleId
1266	 * @return
1267	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryRoleActions(com.sogou.qadev.service.cynthia.bean.UUID)
1268	 */
1269	public Action[] queryRoleActions(UUID roleId){
1270		Set<Action> actionSet = new HashSet<Action>();
1271
1272		for(ActionRole actionRole : this.actionRoleSet){
1273			if(actionRole.roleId.equals(roleId)){
1274				Action action = this.actionMap.get(actionRole.actionId);
1275				if(action != null){
1276					actionSet.add(action);
1277				}
1278			}
1279		}
1280
1281		return actionSet.toArray(new Action[actionSet.size()]);
1282	}
1283
1284	/**
1285	 * (non-Javadoc)
1286	 * <p> Title:queryStatActions</p>
1287	 * <p> Description:TODO</p>
1288	 * @param statId
1289	 * @return
1290	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryStatActions(com.sogou.qadev.service.cynthia.bean.UUID)
1291	 */
1292	public Action[] queryStatActions(UUID statId){
1293		Set<Action> actionSet = new HashSet<Action>();
1294
1295		for(Action action : this.actionMap.values()){
1296			if(action.getBeginStatId() != null && action.getBeginStatId().equals(statId)){
1297				actionSet.add(action);
1298			}
1299		}
1300		return actionSet.toArray(new Action[actionSet.size()]);
1301	}
1302
1303	/**
1304	 * (non-Javadoc)
1305	 * <p> Title:queryUserNodeBeginActions</p>
1306	 * <p> Description:TODO</p>
1307	 * @param username
1308	 * @param templateId
1309	 * @return
1310	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryUserNodeBeginActions(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID)
1311	 */
1312	public Action[] queryUserNodeBeginActions(String username, UUID templateId)
1313	{
1314		if(username == null || templateId == null)
1315			return new Action[0];
1316
1317		//TODO 根据角色来处理
1318		if (isProFlow) {
1319			return this.getStartActions().toArray(new Action[0]);
1320		}
1321		
1322		Role[] roleArray = this.queryUserNodeRoles(username, templateId);
1323		if(roleArray == null)
1324			return new Action[0];
1325
1326		Map<UUID, Action> actionMap = new LinkedHashMap<UUID, Action>();
1327
1328		for(Role role : roleArray)
1329		{
1330			Action[] actionArray = this.queryRoleActions(role.getId());
1331			if(actionArray == null)
1332				continue;
1333
1334			for(Action action : actionArray)
1335			{
1336				if(action.getBeginStatId() == null)
1337					actionMap.put(action.getId(), action);
1338			}
1339		}
1340
1341		Action[] beginActionArray = queryBeginActions();
1342		for(int i = 0; beginActionArray != null && i < beginActionArray.length; i++)
1343		{
1344			if(isActionEveryoneRole(beginActionArray[i].getId()))   //取消everyone控制
1345				actionMap.put(beginActionArray[i].getId(), beginActionArray[i]);
1346		}
1347
1348		return actionMap.values().toArray(new Action[0]);
1349	}
1350
1351	/**
1352	 * (non-Javadoc)
1353	 * <p> Title:queryUserNodeRoles</p>
1354	 * <p> Description:TODO</p>
1355	 * @param user
1356	 * @param templateId
1357	 * @return
1358	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryUserNodeRoles(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID)
1359	 */
1360	public Role[] queryUserNodeRoles(String user, UUID templateId)
1361	{
1362		if (this.isProFlow && ConfigManager.getProjectInvolved()) {
1363			return ProjectInvolveManager.getInstance().getAllRole(user).toArray(new Role[0]);
1364		}else {
1365			if (user.indexOf(",") != -1) {
1366				user = user.split(",")[0];
1367			}
1368			Set<Role> roleSet = new LinkedHashSet<Role>();
1369
1370			for(Right right: this.rightSet)
1371			{
1372				if(right.username.equals(user) && right.templateId.equals(templateId))
1373				{
1374					Role role = this.roleMap.get(right.roleId);
1375					if(role != null)
1376						roleSet.add(role);
1377				}
1378			}
1379
1380			return roleSet.toArray(new Role[0]);
1381		}
1382	}
1383
1384	/**
1385	 * (non-Javadoc)
1386	 * <p> Title:queryUserNodeStatActions</p>
1387	 * <p> Description:TODO</p>
1388	 * @param username
1389	 * @param templateId
1390	 * @param statId
1391	 * @return
1392	 * @see com.sogou.qadev.service.cynthia.bean.Flow#queryUserNodeStatActions(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
1393	 */
1394	public Action[] queryUserNodeStatActions(String username, UUID templateId, UUID statId){
1395		if (username.indexOf(",") != -1) {
1396			username = username.split(",")[0];
1397		}
1398		Set<Action> actionSet = new HashSet<Action>();
1399
1400		Role[] roleArray = this.queryUserNodeRoles(username, templateId);
1401		for(Role role : roleArray){
1402			Action[] actionArray = this.queryRoleActions(role.getId());
1403			for(Action action : actionArray){
1404				if(action.getBeginStatId() != null && action.getBeginStatId().equals(statId)){
1405					actionSet.add(action);
1406				}
1407			}
1408		}
1409
1410		Action[] statActionArray = this.queryStatActions(statId);
1411		for(Action action : statActionArray){
1412			if(this.isActionEveryoneRole(action.getId())){
1413				actionSet.add(action);
1414			}
1415		}
1416
1417		return actionSet.toArray(new Action[actionSet.size()]);
1418	}
1419
1420	/**
1421	 * (non-Javadoc)
1422	 * <p> Title:removeAction</p>
1423	 * <p> Description:TODO</p>
1424	 * @param actionId
1425	 * @see com.sogou.qadev.service.cynthia.bean.Flow#removeAction(com.sogou.qadev.service.cynthia.bean.UUID)
1426	 */
1427	public void removeAction(UUID actionId){
1428		this.actionMap.remove(actionId);
1429	}
1430
1431	/**
1432	 * (non-Javadoc)
1433	 * <p> Title:removeActionRole</p>
1434	 * <p> Description:TODO</p>
1435	 * @param actionId
1436	 * @param roleId
1437	 * @see com.sogou.qadev.service.cynthia.bean.Flow#removeActionRole(com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
1438	 */
1439	public void removeActionRole(UUID actionId, UUID roleId){
1440		this.actionRoleSet.remove(new ActionRole(actionId, roleId));
1441	}
1442
1443	/**
1444	 * (non-Javadoc)
1445	 * <p> Title:removeRight</p>
1446	 * <p> Description:TODO</p>
1447	 * @param username
1448	 * @see com.sogou.qadev.service.cynthia.bean.Flow#removeRight(java.lang.String)
1449	 */
1450	public void removeRight(String username) {
1451		Iterator it=this.rightSet.iterator();
1452		while(it.hasNext())
1453		{
1454			Right rt = (Right)it.next();
1455			if(rt.username.equals(username)){
1456				it.remove();
1457			}
1458		}
1459	}
1460
1461	/**
1462	 * (non-Javadoc)
1463	 * <p> Title:removeRight</p>
1464	 * <p> Description:TODO</p>
1465	 * @param username
1466	 * @param templateId
1467	 * @param roleId
1468	 * @see com.sogou.qadev.service.cynthia.bean.Flow#removeRight(java.lang.String, com.sogou.qadev.service.cynthia.bean.UUID, com.sogou.qadev.service.cynthia.bean.UUID)
1469	 */
1470	public void removeRight(String username, UUID templateId, UUID roleId){
1471		String nickname = CynthiaUtil.getUserAlias(username);
1472		this.rightSet.remove(new Right(username, templateId, roleId,nickname));
1473	}
1474
1475	/**
1476	 * (non-Javadoc)
1477	 * <p> Title:removeRole</p>
1478	 * <p> Description:TODO</p>
1479	 * @param roleId
1480	 * @see com.sogou.qadev.service.cynthia.bean.Flow#removeRole(com.sogou.qadev.service.cynthia.bean.UUID)
1481	 */
1482	public void removeRole(UUID roleId){
1483		this.roleMap.remove(roleId);
1484	}
1485
1486	/**
1487	 * (non-Javadoc)
1488	 * <p> Title:removeStat</p>
1489	 * <p> Description:TODO</p>
1490	 * @param statId
1491	 * @see com.sogou.qadev.service.cynthia.bean.Flow#removeStat(com.sogou.qadev.service.cynthia.bean.UUID)
1492	 */
1493	public void removeStat(UUID statId){
1494		this.statMap.remove(statId);
1495	}
1496
1497	@Override
1498	public void setActionMap(Map<UUID, Action> actionMap) {
1499		this.actionMap = actionMap;
1500	}
1501
1502	@Override
1503	public void setActionRoleSet(Set<ActionRole> actionRoleSet) {
1504		this.actionRoleSet = actionRoleSet;
1505	}
1506
1507	@Override
1508	public void setCreateUser(String userName) {
1509		this.createUser = userName;
1510	}
1511
1512	@Override
1513	public void setName(String name){
1514		this.name = name;
1515	}
1516
1517	public void setProFlow(boolean isProFlow) {
1518		this.isProFlow = isProFlow;
1519	}
1520	
1521	@Override
1522	public void setRightSet(Set<Right> rightSet) {
1523		this.rightSet = rightSet;
1524	}
1525	
1526	@Override
1527	public void setRoleMap(Map<UUID, Role> roleMap) {
1528		this.roleMap = roleMap;
1529	}
1530	
1531	@Override
1532	public void setStatMap(Map<UUID, Stat> statMap) {
1533		this.statMap = statMap;
1534	}
1535	
1536	/**
1537	 * (non-Javadoc)
1538	 * <p> Title:toXMLDocument</p>
1539	 * <p> Description:TODO</p>
1540	 * @return
1541	 * @throws Exception
1542	 * @see com.sogou.qadev.service.cynthia.bean.BaseType#toXMLDocument()
1543	 */
1544	public Document toXMLDocument() throws Exception{
1545		return XMLUtil.string2Document(toXMLString(), "UTF-8");
1546	}
1547
1548	/**
1549	 * (non-Javadoc)
1550	 * <p> Title:toXMLString</p>
1551	 * <p> Description:TODO</p>
1552	 * @return
1553	 * @throws Exception
1554	 * @see com.sogou.qadev.service.cynthia.bean.BaseType#toXMLString()
1555	 */
1556	public String toXMLString() throws Exception{
1557		StringBuffer xmlb = new StringBuffer();
1558		xmlb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
1559		xmlb.append("<flow>");
1560		xmlb.append("<id>").append(this.id).append("</id>");
1561		xmlb.append("<name>").append(XMLUtil.toSafeXMLString(this.name)).append("</name>");
1562		xmlb.append("<isProFlow>").append(XMLUtil.toSafeXMLString(String.valueOf(this.isProFlow))).append("</isProFlow>");
1563
1564		if(this.statMap.size() == 0){
1565			xmlb.append("<stats/>");
1566		}
1567		else{
1568			xmlb.append("<stats>");
1569
1570			for(Stat stat : this.statMap.values()){
1571				xmlb.append("<stat>");
1572				xmlb.append("<id>").append(stat.getId()).append("</id>");
1573				xmlb.append("<name>").append(XMLUtil.toSafeXMLString(stat.getName())).append("</name>");
1574				xmlb.append("</stat>");
1575			}
1576
1577			xmlb.append("</stats>");
1578		}
1579
1580		if(this.actionMap.size() == 0){
1581			xmlb.append("<actions/>");
1582		}else{
1583			xmlb.append("<actions>");
1584
1585			for(Action action : this.actionMap.values()){
1586				xmlb.append("<action>");
1587				xmlb.append("<id>").append(action.getId()).append("</id>");
1588				xmlb.append("<name>").append(XMLUtil.toSafeXMLString(action.getName())).append("</name>");
1589
1590				if(action.getBeginStatId() == null){
1591					xmlb.append("<startStatId/>");
1592				}else{
1593					xmlb.append("<startStatId>").append(action.getBeginStatId()).append("</startStatId>");
1594				}
1595
1596				if(action.getEndStatId() == null){
1597					xmlb.append("<endStatId/>");
1598				}else{
1599					xmlb.append("<endStatId>").append(action.getEndStatId()).append("</endStatId>");
1600				}
1601
1602				xmlb.append("<assignToMore>").append(action.getAssignToMore()).append("</assignToMore>");
1603				xmlb.append("</action>");
1604			}
1605
1606			xmlb.append("</actions>");
1607		}
1608
1609		if(this.roleMap.size() == 0){
1610			xmlb.append("<roles/>");
1611		}else{
1612			xmlb.append("<roles>");
1613
1614			for(Role role : this.roleMap.values()){
1615				xmlb.append("<role>");
1616				xmlb.append("<id>").append(role.getId()).append("</id>");
1617				xmlb.append("<name>").append(XMLUtil.toSafeXMLString(role.getName())).append("</name>");
1618				xmlb.append("</role>");
1619			}
1620
1621			xmlb.append("</roles>");
1622		}
1623
1624		if(this.actionRoleSet.size() == 0){
1625			xmlb.append("<actionRoles/>");
1626		}else{
1627			xmlb.append("<actionRoles>");
1628
1629			for(ActionRole actionRole : this.actionRoleSet){
1630				xmlb.append("<actionRole>");
1631				xmlb.append("<actionId>").append(actionRole.actionId).append("</actionId>");
1632				xmlb.append("<roleId>").append(actionRole.roleId).append("</roleId>");
1633				xmlb.append("</actionRole>");
1634			}
1635
1636			xmlb.append("</actionRoles>");
1637		}
1638
1639		if(this.rightSet.size() == 0){
1640			xmlb.append("<rights/>");
1641		}else{
1642			xmlb.append("<rights>");
1643
1644			for(Right right : this.rightSet){
1645				xmlb.append("<right>");
1646				xmlb.append("<username>").append(XMLUtil.toSafeXMLString(right.username)).append("</username>");
1647				xmlb.append("<templateId>").append(right.templateId).append("</templateId>");
1648				xmlb.append("<roleId>").append(right.roleId).append("</roleId>");
1649				xmlb.append("</right>");
1650			}
1651
1652			xmlb.append("</rights>");
1653		}
1654
1655		xmlb.append("</flow>");
1656
1657		return xmlb.toString();
1658	}
1659
1660}