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