1 package org.tigris.scarab.workflow; 2 3 48 49 import org.tigris.scarab.om.*; 50 import org.tigris.scarab.util.Log; 51 52 import org.apache.torque.TorqueException; 53 import org.apache.fulcrum.security.entity.Role; 54 import org.apache.fulcrum.security.util.AccessControlList; 55 import org.apache.fulcrum.security.util.GroupSet; 56 import org.apache.fulcrum.security.TurbineSecurity; 57 import org.apache.fulcrum.security.entity.Group; 58 59 import java.util.Iterator ; 60 import java.util.List ; 61 62 76 public class CheapWorkflow extends DefaultWorkflow{ 77 78 83 public boolean canMakeTransition(ScarabUser user, 84 AttributeOption fromOption, AttributeOption toOption, Issue issue) 85 { 86 boolean result = false; 87 List allTransitions = null; 88 Module module = null; 89 try 90 { 91 if (fromOption.equals(toOption)) 92 { 93 result = true; 94 } 95 else 96 { 97 if (TransitionPeer.hasDefinedTransitions(toOption 98 .getAttribute())) 99 { 100 allTransitions = TransitionPeer.getTransitions(fromOption, 101 toOption); 102 allTransitions = filterConditionalTransitions(allTransitions, issue); 103 module = issue.getModule(); 104 Iterator iter = allTransitions.iterator(); 105 while (!result && iter.hasNext()) 106 { 107 Object obj = iter.next(); 108 Transition tran = (Transition) obj; 109 Role requiredRole = tran.getRole(); 110 if (requiredRole != null) 111 { try 114 { 115 List modules = user.getModules(); 116 AccessControlList acl = TurbineSecurity 117 .getACL(user); 118 GroupSet allGroups = TurbineSecurity 119 .getAllGroups(); 120 Group group = allGroups.getGroup(module 121 .getName()); 122 result = acl.hasRole(requiredRole, group); 123 } 124 catch (Exception e) 125 { 126 Log.get(this.getClass().getName()) 127 .error( 128 "canMakeTransition: getModules(): " 129 + e); 130 } 131 } 132 else 133 { 134 result = true; 135 } 136 } 137 } 138 else 139 { 140 result = true; 141 } 142 } 143 } 144 catch (TorqueException te) 145 { 146 Log.get(this.getClass().getName()) 147 .error("canMakeTransition: " + te); 148 } 149 return result; 150 } 151 152 161 public List filterConditionalTransitions(List transitions, Issue issue) throws TorqueException 162 { 163 try 164 { 165 boolean blockedIssue = issue.isBlocked(); 166 if (transitions != null) 167 { 168 for (int i=transitions.size()-1; i>=0; i--) 169 { 170 Transition tran = (Transition)transitions.get(i); 171 if (blockedIssue && tran.getDisabledIfBlocked()) 172 { 173 transitions.remove(i); 174 continue; 175 176 } 177 List conditions = tran.getConditions(); 178 if (null != conditions && conditions.size() > 0) 179 { 180 boolean bRemove = true; 181 for (Iterator itReq = conditions.iterator(); bRemove && itReq.hasNext(); ) 182 { 183 Condition cond = (Condition)itReq.next(); 184 Attribute requiredAttribute = cond.getAttributeOption().getAttribute(); 185 Integer optionId = cond.getOptionId(); 186 Integer issueOptionId = issue.getAttributeValue(requiredAttribute).getOptionId(); 187 if (issueOptionId != null && issueOptionId.equals(optionId)) 188 { 189 bRemove = false; 190 } 191 } 192 if (bRemove) 193 { 194 transitions.remove(i); 195 } 196 } 197 } 198 } 199 } 200 catch (Exception e) 201 { 202 Log.get().error("filterConditionalTransitions: " + e); 203 } 204 205 return transitions; 206 } 207 } 208 | Popular Tags |