1 18 19 package cowsultants.itracker.ejb.client.models; 20 21 import java.text.*; 22 import java.util.*; 23 24 import cowsultants.itracker.ejb.client.exceptions.*; 25 import cowsultants.itracker.ejb.client.resources.*; 26 import cowsultants.itracker.ejb.client.util.*; 27 28 public class IssueFieldModel extends GenericModel { 29 private CustomFieldModel customField; 30 private Integer customFieldId = new Integer (-1); 31 32 private String stringValue; 33 private int intValue; 34 private Date dateValue; 35 36 private Integer issueId; 37 38 public IssueFieldModel() { 39 } 40 41 public IssueFieldModel(CustomFieldModel field) { 42 this.customField = field; 43 this.customFieldId = field.getId(); 44 } 45 46 public IssueFieldModel(CustomFieldModel field, Integer issueId) { 47 this(field); 48 this.issueId = issueId; 49 } 50 51 54 public Integer getCustomFieldId() { 55 return (customField != null ? customField.getId() : customFieldId); 56 } 57 58 61 public void setCustomFieldId(Integer value) { 62 customFieldId = value; 63 } 64 65 public CustomFieldModel getCustomField() { 66 return customField; 67 } 68 69 public void setCustomField(CustomFieldModel value) { 70 customField = value; 71 } 72 73 78 public String getValue(Locale locale) { 79 return getValue(ITrackerResources.getBundle(locale), locale); 80 } 81 82 88 public String getValue(ResourceBundle bundle, Locale locale) { 89 if(customField == null) { 90 return ""; 91 } 92 93 if(customField.getFieldType() == CustomFieldUtilities.TYPE_INTEGER) { 94 return Integer.toString(getIntValue()); 95 } else if(customField.getFieldType() == CustomFieldUtilities.TYPE_DATE) { 96 try { 97 if(customField.getDateFormat() != CustomFieldUtilities.DATE_FORMAT_UNKNOWN) { 98 SimpleDateFormat sdf = new SimpleDateFormat(bundle.getString("itracker.dateformat." + customField.getDateFormat()), locale); 99 return sdf.format(getDateValue()); 100 } 101 } catch(Exception e) { 102 Logger.logDebug("Error parsing date value.", e); 103 } 104 } else { 105 return (getStringValue() == null ? "" : getStringValue()); 106 } 107 return ""; 108 } 109 110 117 public void setValue(String value, Locale locale) throws IssueException { 118 setValue(value, locale, ITrackerResources.getBundle(locale)); 119 } 120 121 129 public void setValue(String value, Locale locale, ResourceBundle bundle) throws IssueException { 130 if(value != null) { 131 if(customField.getFieldType() == CustomFieldUtilities.TYPE_INTEGER) { 132 try { 133 setIntValue(Integer.parseInt(value)); 134 } catch(NumberFormatException nfe) { 135 throw new IssueException("Invalid integer.", IssueException.TYPE_CF_PARSE_NUM); 136 } 137 } else if(customField.getFieldType() == CustomFieldUtilities.TYPE_DATE) { 138 try { 139 if(customField.getDateFormat() != CustomFieldUtilities.DATE_FORMAT_UNKNOWN) { 140 SimpleDateFormat sdf = new SimpleDateFormat(bundle.getString("itracker.dateformat." + customField.getDateFormat()), locale); 141 Date dateValue = sdf.parse(value); 142 if(dateValue != null) { 143 setDateValue(dateValue); 144 } else { 145 Logger.logDebug("Unable to set custom field date. Date value was null. Data was '" + value + "'"); 146 throw new IssueException("Invalid date.", IssueException.TYPE_CF_PARSE_DATE); 147 } 148 } 149 } catch(Exception e) { 150 Logger.logDebug("Unable to set custom field date. Exception: " + e.getMessage() + ". Data was '" + value + "'"); 151 throw new IssueException("Invalid date format.", IssueException.TYPE_CF_PARSE_DATE); 152 } 153 } else { 154 setStringValue(value); 155 } 156 } 157 } 158 159 public String getStringValue() { 160 return stringValue; 161 } 162 163 public void setStringValue(String value) { 164 stringValue = value; 165 } 166 167 public int getIntValue() { 168 return intValue; 169 } 170 171 public void setIntValue(int value) { 172 intValue = value; 173 } 174 175 public Date getDateValue() { 176 return dateValue; 177 } 178 179 public void setDateValue(Date value) { 180 dateValue = value; 181 } 182 183 public Integer getIssueId() { 184 return issueId; 185 } 186 187 public void setIssueId(Integer value) { 188 issueId = value; 189 } 190 } 191 | Popular Tags |