1 2 package org.tigris.scarab.om; 3 4 49 50 import java.util.List ; 51 import java.util.ArrayList ; 52 53 import org.apache.torque.om.Persistent; 54 import org.apache.torque.util.Criteria; 55 import org.tigris.scarab.util.Log; 56 57 62 public class RIssueTypeAttribute 63 extends org.tigris.scarab.om.BaseRIssueTypeAttribute 64 implements Persistent 65 { 66 73 public void setIsDefaultText(boolean b) 74 throws Exception 75 { 76 if (b && !getDefaultTextFlag()) 77 { 78 List rias = getIssueType().getRIssueTypeAttributes(false); 80 81 for (int i=0; i<rias.size(); i++) 83 { 84 RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i); 85 if (ria.getDefaultTextFlag()) 86 { 87 ria.setDefaultTextFlag(false); 88 ria.save(); 89 break; 90 } 91 } 92 } 93 setDefaultTextFlag(b); 94 } 95 96 104 public boolean getIsDefaultText() 105 throws Exception 106 { 107 boolean isDefault = getDefaultTextFlag(); 108 if (!isDefault && getAttribute().isTextAttribute()) 109 { 110 List rias = getIssueType().getRIssueTypeAttributes(); 112 113 boolean anotherIsDefault = false; 115 for (int i=0; i<rias.size(); i++) 116 { 117 RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i); 118 if (ria.getDefaultTextFlag()) 119 { 120 anotherIsDefault = true; 121 break; 122 } 123 } 124 125 if (!anotherIsDefault) 126 { 127 for (int i=0; i<rias.size(); i++) 129 { 130 RIssueTypeAttribute ria = (RIssueTypeAttribute)rias.get(i); 131 if (ria.getAttribute().isTextAttribute()) 132 { 133 if (ria.getAttributeId().equals(getAttributeId())) 134 { 135 isDefault = true; 136 } 137 else 138 { 139 anotherIsDefault = true; 140 } 141 142 break; 143 } 144 } 145 } 146 } 147 return isDefault; 148 } 149 150 public void delete() 151 throws Exception 152 { 153 if (Log.get().isDebugEnabled()) 154 { 155 Log.get().debug( 156 "Deleting SCARAB_R_ISSUETYPE_ATTRIBUTE where issuetype id=" 157 + getIssueTypeId() + " and attribute id=" + getAttributeId()); 158 } 159 Criteria c = new Criteria() 160 .add(RIssueTypeAttributePeer.ISSUE_TYPE_ID, getIssueTypeId()) 161 .add(RIssueTypeAttributePeer.ATTRIBUTE_ID, getAttributeId()); 162 RIssueTypeAttributePeer.doDelete(c); 163 Attribute attr = getAttribute(); 164 String attributeType = null; 165 attributeType = (attr.isUserAttribute() ? IssueType.USER : IssueType.NON_USER); 166 getIssueType().getRIssueTypeAttributes(false, attributeType).remove(this); 167 168 if (attr.isOptionAttribute()) 170 { 171 List optionList = getIssueType().getRIssueTypeOptions(attr, false); 172 if (optionList != null && !optionList.isEmpty()) 173 { 174 ArrayList optionIdList = new ArrayList (optionList.size()); 175 for (int i =0; i<optionList.size(); i++) 176 { 177 optionIdList.add(((RIssueTypeOption)optionList.get(i)).getOptionId()); 178 } 179 Criteria c2 = new Criteria() 180 .add(RIssueTypeOptionPeer.ISSUE_TYPE_ID, getIssueTypeId()) 181 .addIn(RIssueTypeOptionPeer.OPTION_ID, optionIdList); 182 RIssueTypeOptionPeer.doDelete(c2); 183 } 184 } 185 } 186 187 190 public RIssueTypeAttribute copyRia() 191 throws Exception 192 { 193 RIssueTypeAttribute ria = new RIssueTypeAttribute(); 194 ria.setIssueTypeId(getIssueTypeId()); 195 ria.setAttributeId(getAttributeId()); 196 ria.setActive(getActive()); 197 ria.setRequired(getRequired()); 198 ria.setOrder(getOrder()); 199 ria.setQuickSearch(getQuickSearch()); 200 ria.setDefaultTextFlag(getDefaultTextFlag()); 201 return ria; 202 } 203 } 204 | Popular Tags |