1 package org.tigris.scarab.om; 2 3 48 49 import java.util.ArrayList ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 53 import org.apache.fulcrum.security.entity.Role; 54 import org.apache.fulcrum.security.impl.db.entity.TurbineRolePeer; 55 import org.apache.torque.NoRowsException; 56 import org.apache.torque.TooManyRowsException; 57 import org.apache.torque.TorqueException; 58 import org.apache.torque.manager.CacheListener; 59 import org.apache.torque.om.Persistent; 60 import org.apache.torque.util.Criteria; 61 import org.tigris.scarab.tools.ScarabLocalizationTool; 62 import org.tigris.scarab.tools.localization.L10NKeySet; 63 64 73 public class Transition extends org.tigris.scarab.om.BaseTransition 74 implements 75 Persistent, Conditioned 76 { 77 public Role getRole() 78 { 79 Role role = null; 80 try 81 { 82 role = TurbineRolePeer.retrieveByPK(this.getRoleId()); 83 } 84 catch (NoRowsException e) 85 { 86 } 88 catch (TooManyRowsException e) 89 { 90 } 92 catch (TorqueException e) 93 { 94 e.printStackTrace(); 95 } 96 return role; 97 } 98 99 public AttributeOption getFrom() 100 { 101 AttributeOption from = null; 102 if (null != this.getFromOptionId()) 103 { 104 try 105 { 106 from = AttributeOptionPeer.retrieveByPK(this.getFromOptionId()); 107 } 108 catch (NoRowsException e) 109 { 110 } 112 catch (TooManyRowsException e) 113 { 114 } 116 catch (TorqueException e) 117 { 118 e.printStackTrace(); 119 } 120 } 121 return from; 122 } 123 124 public AttributeOption getTo() 125 { 126 AttributeOption to = null; 127 try 128 { 129 to = AttributeOptionPeer.retrieveByPK(this.getToOptionId()); 130 } 131 catch (NoRowsException e) 132 { 133 } 135 catch (TooManyRowsException e) 136 { 137 } 139 catch (TorqueException e) 140 { 141 e.printStackTrace(); 142 } 143 return to; 144 } 145 146 public boolean isRequiredIf(Integer optionID) throws TorqueException 147 { 148 Condition cond = new Condition(); 149 cond.setAttributeId(null); 150 cond.setOptionId(optionID); 151 cond.setModuleId(null); 152 cond.setIssueTypeId(null); 153 cond.setTransitionId(this.getTransitionId()); 154 return this.getConditions().contains(cond); 155 } 156 157 public String getFromName() 158 { 159 String fromName = null; 160 AttributeOption from = this.getFrom(); 161 if (from == null) 162 { 163 ScarabLocalizationTool l10n = new ScarabLocalizationTool(); 164 fromName = l10n.get(L10NKeySet.TransitionsAnyOption); 165 } 166 else 167 { 168 fromName = from.getName(); 169 } 170 return fromName; 171 } 172 173 public String getToName() 174 { 175 String toName = null; 176 AttributeOption to = this.getTo(); 177 if (to == null) 178 { 179 ScarabLocalizationTool l10n = new ScarabLocalizationTool(); 180 toName = l10n.get(L10NKeySet.TransitionsAnyOption); 181 } 182 else 183 { 184 toName = to.getName(); 185 } 186 return toName; 187 } 188 189 public String getRoleName() 190 { 191 String roleName = null; 192 Role role = this.getRole(); 193 if (role == null) 194 { 195 ScarabLocalizationTool l10n = new ScarabLocalizationTool(); 196 roleName = l10n.get(L10NKeySet.TransitionsAnyRole); 197 } 198 else 199 { 200 roleName = role.getName(); 201 } 202 return roleName; 203 } 204 205 210 public Integer [] getConditionsArray() 211 { 212 List conditions = new ArrayList (); 213 Integer [] aIDs = null; 214 try 215 { 216 217 conditions = this.getConditions(); 218 aIDs = new Integer [conditions.size()]; 219 int i=0; 220 for (Iterator iter = conditions.iterator(); iter.hasNext(); i++) 221 { 222 aIDs[i] = (Integer )iter.next(); 223 } 224 } 225 catch (TorqueException e) 226 { 227 this.getLog().error("getConditionsArray: " + e); 228 } 229 return aIDs; 230 } 231 236 public void setConditionsArray(Integer aOptionId[]) throws Exception 237 { 238 Criteria crit = new Criteria(); 239 crit.add(ConditionPeer.ATTRIBUTE_ID, null); 240 crit.add(ConditionPeer.MODULE_ID, null); 241 crit.add(ConditionPeer.ISSUE_TYPE_ID, null); 242 crit.add(ConditionPeer.TRANSITION_ID, this.getTransitionId()); 243 ConditionPeer.doDelete(crit); 244 this.getConditions().clear(); 245 ConditionManager.clear(); 246 if (aOptionId != null) 247 { 248 for (int i=0; i<aOptionId.length; i++) 249 { 250 if (aOptionId[i].intValue() != 0) 251 { 252 Condition cond = new Condition(); 253 cond.setTransitionId(this.getTransitionId()); 254 cond.setOptionId(aOptionId[i]); 255 cond.setAttributeId(null); 256 cond.setModuleId(null); 257 cond.setIssueTypeId(null); 258 this.addCondition(cond); 259 cond.save(); 260 } 261 } 262 } 263 } 264 265 public boolean isConditioned() 266 { 267 boolean bRdo = false; 268 try { 269 bRdo = this.getConditions().size()>0; 270 } catch (TorqueException te) 271 { 272 } 274 return bRdo; 275 } 276 277 public String toString() 278 { 279 return this.getFromOptionId() + " -> " + this.getToOptionId() 280 + " (role: " + this.getRoleId() + ")"; 281 } 282 283 286 public void addedObject(Persistent arg0) 287 { 288 290 } 291 292 295 public void refreshedObject(Persistent arg0) 296 { 297 299 } 300 301 304 public List getInterestedFields() 305 { 306 return null; 308 } 309 310 } 311 312 | Popular Tags |