1 package org.tigris.scarab.actions.admin; 2 3 48 49 import org.apache.fulcrum.intake.model.Group; 50 import org.apache.torque.TorqueException; 51 import org.apache.torque.util.Criteria; 52 import org.apache.turbine.RunData; 53 import org.apache.turbine.TemplateContext; 54 import org.apache.turbine.tool.IntakeTool; 55 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 56 import org.tigris.scarab.om.Attribute; 57 import org.tigris.scarab.om.AttributeManager; 58 import org.tigris.scarab.om.ConditionManager; 59 import org.tigris.scarab.om.ConditionPeer; 60 import org.tigris.scarab.om.Module; 61 import org.tigris.scarab.om.RModuleAttribute; 62 import org.tigris.scarab.om.RModuleAttributeManager; 63 import org.tigris.scarab.om.RModuleAttributePeer; 64 import org.tigris.scarab.om.RModuleIssueType; 65 import org.tigris.scarab.om.RModuleIssueTypeManager; 66 import org.tigris.scarab.om.RModuleIssueTypePeer; 67 import org.tigris.scarab.om.Transition; 68 import org.tigris.scarab.om.TransitionManager; 69 import org.tigris.scarab.tools.ScarabRequestTool; 70 import org.tigris.scarab.util.ScarabConstants; 71 72 public class ConditionEdit extends RequireLoginFirstAction 73 { 74 private int transitionId; 75 private int moduleId; 76 private int attributeId; 77 private int issueTypeId; 78 79 public void doDelete(RunData data, TemplateContext context) throws TorqueException, Exception 80 { 81 IntakeTool intake = getIntakeTool(context); 82 Group attrGroup = intake.get("ConditionEdit", IntakeTool.DEFAULT_KEY); 83 data.getParameters().remove(attrGroup.get("ConditionsArray").getKey()); 84 updateObject(data, context, null); 85 } 86 87 private void delete(RunData data) throws TorqueException, Exception 88 { 89 int nObjectType = data.getParameters().getInt("obj_type"); 90 Criteria crit = new Criteria(); 91 switch (nObjectType) 92 { 93 case ScarabConstants.TRANSITION_OBJECT: 94 crit.add(ConditionPeer.TRANSITION_ID, data.getParameters().getInt("transition_id")); 95 break; 96 case ScarabConstants.GLOBAL_ATTRIBUTE_OBJECT: 97 crit.add(ConditionPeer.ATTRIBUTE_ID, data.getParameters().getInt("attId")); 98 crit.add(ConditionPeer.MODULE_ID, 0); 99 crit.add(ConditionPeer.ISSUE_TYPE_ID, 0); 100 break; 101 case ScarabConstants.MODULE_ATTRIBUTE_OBJECT: 102 crit.add(ConditionPeer.ATTRIBUTE_ID, data.getParameters().getInt("attId")); 103 crit.add(ConditionPeer.MODULE_ID, data.getParameters().getInt("module_id")); 104 crit.add(ConditionPeer.ISSUE_TYPE_ID, data.getParameters().getInt("issueTypeId")); 105 break; 106 } 107 ConditionPeer.doDelete(crit); 108 ConditionManager.clear(); 109 TransitionManager.clear(); 110 } 111 112 private void updateObject(RunData data, TemplateContext context, Integer aConditions[]) throws Exception 113 { 114 ScarabRequestTool scarabR = getScarabRequestTool(context); 115 switch (data.getParameters().getInt("obj_type")) 116 { 117 case ScarabConstants.TRANSITION_OBJECT: 118 Transition transition = scarabR.getTransition(data.getParameters().getInteger("transition_id")); 119 transition.setConditionsArray(aConditions); 120 transition.save(); 121 break; 122 case ScarabConstants.GLOBAL_ATTRIBUTE_OBJECT: 123 Attribute attribute = scarabR.getAttribute(data.getParameters().getInteger("attId")); 124 attribute.setConditionsArray(aConditions); 125 attribute.save(); 126 break; 127 case ScarabConstants.MODULE_ATTRIBUTE_OBJECT: 128 Module module = scarabR.getCurrentModule(); 129 RModuleAttribute rma = RModuleAttributePeer.retrieveByPK(data.getParameters().getInteger("moduleId"), data.getParameters().getInteger("attId"), data.getParameters().getInteger("issueTypeId")); 130 rma.setConditionsArray(aConditions); 131 RModuleAttributeManager.clear(); 132 ConditionManager.clear(); 133 rma.save(); 134 break; 135 case ScarabConstants.BLOCKED_MODULE_ISSUE_TYPE_OBJECT: 136 RModuleIssueType rmit = RModuleIssueTypePeer.retrieveByPK(scarabR.getCurrentModule().getModuleId(), data.getParameters().getInteger("issuetypeid")); 137 rmit.setConditionsArray(aConditions); 138 rmit.save(); 139 RModuleIssueTypeManager.clear(); 140 ConditionManager.clear(); 141 break; 142 } 143 AttributeManager.clear(); 144 } 145 146 public void doSave(RunData data, TemplateContext context) throws Exception 147 { 148 this.delete(data); 149 IntakeTool intake = getIntakeTool(context); 150 Group attrGroup = intake.get("ConditionEdit", IntakeTool.DEFAULT_KEY); 151 Integer aConditions[] = ((Integer [])attrGroup.get("ConditionsArray").getValue()); 152 updateObject(data, context, aConditions); 153 154 } 155 156 public void doCancel(RunData data, TemplateContext context) throws Exception 157 { 158 String lastTemplate = getCancelTemplate(data); 159 if (lastTemplate != null) 160 { 161 setTarget(data, lastTemplate); 162 } 163 else 164 { 165 super.doCancel(data, context); 166 } 167 } 168 } 169 170 | Popular Tags |