Changeset 1180
- Timestamp:
- Aug 31, 2005, 3:24:49 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/build.xml
r1139 r1180 21 21 22 22 <!-- set global properties for this build --> 23 <property name="compilerarg" value="-Xlint:unchecked" /> 23 24 <property name="base.version" value="pre2.0_demo" /> 24 25 <property name="src" location="src" /> … … 176 177 deprecation="true" 177 178 > 178 <compilerarg value=" -Xlint:unchecked" />179 <compilerarg value="${compilerarg}" /> 179 180 </javac> 180 181 <copy todir="${core.build}"> … … 207 208 encoding="ISO-8859-1" 208 209 > 209 <compilerarg value=" -Xlint:unchecked" />210 <compilerarg value="${compilerarg}" /> 210 211 </javac> 211 212 <copy todir="${test.build}"> … … 259 260 debug="true" 260 261 > 261 <compilerarg value=" -Xlint:unchecked" />262 <compilerarg value="${compilerarg}" /> 262 263 </javac> 263 264 <copy todir="${migrate.build}"> … … 298 299 deprecation="true" 299 300 > 300 <compilerarg value=" -Xlint:unchecked" />301 <compilerarg value="${compilerarg}" /> 301 302 </javac> 302 303 </target> … … 350 351 deprecation="true" 351 352 > 352 <compilerarg value=" -Xlint:unchecked" />353 <compilerarg value="${compilerarg}" /> 353 354 </javac> 354 355 <copy todir="${web.build}"> -
trunk/src/core/net/sf/basedb/core/AnnotationType.java
r936 r1180 589 589 have write permission 590 590 @throws InvalidDataException If the list contains values of the wrong type 591 as checked by the {@link Type# isCorrectType(Object)} method591 as checked by the {@link Type#validate(List)} method 592 592 */ 593 593 public void setValues(List<?> values) … … 598 598 Type valueType = getValueType(); 599 599 int i = 0; 600 if (values != null) 601 { 602 for (Object value : values) 603 { 604 if (value == null) throw new InvalidUseOfNullException("values["+i+"]"); 605 if (!valueType.isCorrectType(value)) 606 { 607 throw new InvalidDataException("Value '"+value+"' is a "+ 608 value.getClass()+", not a "+valueType); 609 } 610 i++; 611 } 612 } 600 if (values != null) valueType.validate(values); 613 601 ParameterValueData<?> pv = getData().getEnumerationValues(); 614 602 if (pv == null) … … 749 737 if (value == null) throw new InvalidUseOfNullException("value"); 750 738 Type valueType = getValueType(); 751 if (!valueType.isCorrectType(value)) 752 { 753 throw new InvalidDataException("Value '"+value+"' is a "+ 754 value.getClass()+", not a "+valueType); 755 } 739 valueType.validate(value); 756 740 if (valueType == Type.INT) 757 741 { -
trunk/src/core/net/sf/basedb/core/DateParameterType.java
r1138 r1180 32 32 This class represent a parameter type that is a date. 33 33 34 @author Samuel 34 @author Samuel, Nicklas 35 35 @version 2.0 36 @base.modified $Date$ 36 37 */ 37 38 public class DateParameterType … … 39 40 { 40 41 public DateParameterType() 42 {} 43 44 /* 45 From the Object class 46 ------------------------------------------- 47 */ 48 public String toString() 41 49 { 42 setHeight(1); 43 setWidth(10); 50 return "DateParameterType"; 44 51 } 52 // ------------------------------------------- 45 53 46 54 /* 55 From the ParameterType class 56 ------------------------------------------- 57 */ 47 58 /** 48 Validate parameter value. Checks if it is valid to 49 the configuration. 50 @param value The value to test. 51 @throws InvalidDataException This exception is thrown 52 if the value is invalid 59 Checks if the value is a <code>Date</object> object. 60 @param value The value to test 61 @return The same value 62 @throws InvalidDataException If the value is not a date 53 63 */ 54 public void validate(Object value) 64 @Override 65 Object getCheckedValue(Object value) 55 66 throws InvalidDataException 56 67 { 57 68 if (!(value instanceof Date)) 58 69 { 59 throw new InvalidDataException("Value is not a Date object.");70 throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not a 'Date'"); 60 71 } 61 if (value == null && getNotNull()) 62 { 63 throw new InvalidDataException("Value is not allowed to be null."); 64 } 72 return value; 65 73 } 66 67 74 75 /** 76 Create a new {@link DateParameterValueData} object. 77 */ 68 78 @Override 69 public void setDefaultValue(Object defaultValue) 70 throws InvalidDataException 79 public DateParameterValueData newParameterValueData() 71 80 { 72 DateParameterValueData value = new DateParameterValueData(); 73 value.setSingleValue(defaultValue); 74 super.setDefaultValue(value); 81 return new DateParameterValueData(); 75 82 } 83 // ------------------------------------------- 76 84 77 85 78 public String toString()79 {80 return "DateParameterType";81 }82 83 @Override84 public DateParameterValueData newParameterValueData(Object value)85 throws InvalidDataException86 {87 validate(value);88 return new DateParameterValueData((Date) value);89 }90 86 } -
trunk/src/core/net/sf/basedb/core/FileParameterType.java
r1138 r1180 33 33 This class represent a parameter type that is a file. 34 34 35 @author Samuel 35 @author Samuel, Nicklas 36 36 @version 2.0 37 @base.modified $Date$ 37 38 */ 38 39 public class FileParameterType … … 47 48 { 48 49 this.mimeTypes = new ArrayList<MimeType>(); 49 setHeight(1);50 setWidth(25);51 50 } 52 51 52 /* 53 From the Object class 54 ------------------------------------------- 55 */ 56 public String toString() 57 { 58 return "FileParameterType"; 59 } 60 // ------------------------------------------- 61 62 /* 63 From the ParameterType class 64 ------------------------------------------- 65 */ 53 66 /** 54 Validate parameter value. Checks if it is valid to 55 the configuration. 56 @param value The value to test. 57 @throws InvalidDataException This exception is thrown 58 if the value is invalid 67 Check if the value is a {@link File} object. 68 @param value The value to test 69 @return The {@link FileData} object of the file 70 @throws InvalidDataException If the value isn't a file 59 71 */ 60 public void validate(Object value) 72 @Override 73 Object getCheckedValue(Object value) 61 74 throws InvalidDataException 62 75 { 63 76 if (!(value instanceof File)) 64 77 { 65 throw new InvalidDataException("Value is not a FileData object.");78 throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not a 'File'"); 66 79 } 67 if(value == null && getNotNull()) 68 { 69 throw new InvalidDataException("Value is not allowed to be null."); 70 } 71 } 72 73 @Override 74 public void setDefaultValue(Object defaultValue) 75 throws InvalidDataException 76 { 77 FileParameterValueData value = new FileParameterValueData(); 78 value.setSingleValue(defaultValue); 79 super.setDefaultValue(value); 80 return ((File)value).getData(); 80 81 } 81 82 82 public String toString() 83 /** 84 Create a new {@link FileParameterValueData} object. 85 */ 86 @Override 87 public FileParameterValueData newParameterValueData() 83 88 { 84 return "FileParameterType";89 return new FileParameterValueData(); 85 90 } 91 // ------------------------------------------- 92 86 93 87 94 /** … … 116 123 } 117 124 118 @Override119 public FileParameterValueData newParameterValueData(Object value)120 throws InvalidDataException121 {122 validate(value);123 return new FileParameterValueData(((File) value).getData());124 }125 125 } -
trunk/src/core/net/sf/basedb/core/FloatParameterType.java
r1138 r1180 33 33 allowed values. 34 34 35 @author Samuel 35 @author Samuel, Nicklas 36 36 @version 2.0 37 @base.modified $Date$ 37 38 */ 38 39 public class FloatParameterType … … 51 52 52 53 public FloatParameterType() 53 { 54 setHeight(1); 55 setWidth(6); 56 } 54 {} 57 55 58 59 /** 60 Validate parameter value. Checks if it is valid to 61 the configuration. 62 @param value The value to test. 63 @throws InvalidDataException This exception is thrown 64 if the value is invalid 56 /* 57 From the Object class 58 ------------------------------------------- 65 59 */ 66 public void validate(Object value)67 throws InvalidDataException68 {69 if (value != null)70 {71 if (!(value instanceof Float))72 {73 throw new InvalidDataException("Value is not a Float object.");74 }75 Float val = (Float)value;76 if (((lowerLimit != null) && (val.compareTo( lowerLimit ) < 0))77 ||78 (( upperLimit != null) && (val.compareTo(upperLimit ) > 0)))79 {80 throw new NumberOutOfRangeException(81 "value", val.floatValue(),82 lowerLimit == null ? Float.MIN_VALUE : lowerLimit.floatValue(),83 upperLimit == null ? Float.MAX_VALUE : upperLimit.floatValue()84 );85 }86 }87 else if (getNotNull())88 {89 throw new InvalidDataException("Value is not allowed to be null.");90 }91 }92 93 @Override94 public void setDefaultValue(Object defaultValue)95 throws InvalidDataException96 {97 FloatParameterValueData value = new FloatParameterValueData();98 value.setSingleValue(defaultValue);99 super.setDefaultValue(value);100 }101 102 103 60 public String toString() 104 61 { 105 62 return "FloatParameterType: Lower " + lowerLimit + ", Upper " + upperLimit; 106 63 } 64 // ------------------------------------------- 65 66 /* 67 From the ParameterType class 68 ------------------------------------------- 69 */ 70 /** 71 Checks if the value is a <code>Float</object> object 72 and is within the range given by the upper and lower limits if those are given. 73 @param value The value to test 74 @return The same value 75 @throws InvalidDataException If the value is not a float or outside 76 the range of allowed values 77 */ 78 @Override 79 Object getCheckedValue(Object value) 80 throws InvalidDataException 81 { 82 if (!(value instanceof Float)) 83 { 84 throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not a 'Float'"); 85 } 86 Float val = (Float)value; 87 if (((lowerLimit != null) && (val.compareTo( lowerLimit ) < 0)) 88 || 89 (( upperLimit != null) && (val.compareTo(upperLimit ) > 0))) 90 { 91 throw new NumberOutOfRangeException( 92 "value", val.floatValue(), 93 lowerLimit == null ? Float.MIN_VALUE : lowerLimit.floatValue(), 94 upperLimit == null ? Float.MAX_VALUE : upperLimit.floatValue() 95 ); 96 } 97 return value; 98 } 99 /** 100 Create a new {@link FloatParameterValueData} object. 101 */ 102 @Override 103 public FloatParameterValueData newParameterValueData() 104 { 105 return new FloatParameterValueData(); 106 } 107 // ------------------------------------------- 107 108 108 109 … … 120 121 @param lowerLimit The lowest valid value. 121 122 */ 122 public void setLowerLimit( Float lowerLimit)123 public void setLowerLimit(Float lowerLimit) 123 124 { 124 125 this.lowerLimit = lowerLimit; … … 139 140 @param upperLimit The highest valid value. 140 141 */ 141 public void setUpperLimit( Float upperLimit)142 public void setUpperLimit(Float upperLimit) 142 143 { 143 144 this.upperLimit = upperLimit; 144 145 } 145 146 146 147 @Override148 public FloatParameterValueData newParameterValueData(Object value)149 throws InvalidDataException150 {151 validate(value);152 return new FloatParameterValueData((Float) value);153 }154 147 } -
trunk/src/core/net/sf/basedb/core/IntegerParameterType.java
r1138 r1180 33 33 allowed values. 34 34 35 @author Samuel 35 @author Samuel, Nicklas 36 36 @version 2.0 37 @base.modified $Date$ 37 38 */ 38 39 public class IntegerParameterType … … 54 55 */ 55 56 public IntegerParameterType() 56 { 57 setHeight(1); 58 setWidth(6); 59 } 57 {} 60 58 61 62 /** 63 Validate parameter value. Checks if it is valid to 64 the configuration. 65 @param value The value to test. 66 @throws InvalidDataException This exception is thrown 67 if the value is invalid 59 /* 60 From the Object class 61 ------------------------------------------- 68 62 */ 69 public void validate(Object value)70 throws InvalidDataException71 {72 if (value != null)73 {74 if (!(value instanceof Integer))75 {76 throw new InvalidDataException("Value is not an Integer object.");77 }78 Integer val = (Integer)value;79 if (((lowerLimit != null) && (val.compareTo(lowerLimit) < 0 ))80 ||81 ((upperLimit != null) && (val.compareTo(upperLimit) > 0 )))82 {83 throw new NumberOutOfRangeException(84 "value", val.intValue(),85 lowerLimit == null ? Integer.MIN_VALUE : lowerLimit.intValue(),86 upperLimit == null ? Integer.MAX_VALUE : upperLimit.intValue()87 );88 }89 }90 else if (getNotNull())91 {92 throw new InvalidDataException("Value is not allowed to be null.");93 }94 }95 96 @Override97 public void setDefaultValue(Object defaultValue)98 throws InvalidDataException99 {100 IntegerParameterValueData value = new IntegerParameterValueData();101 value.setSingleValue(defaultValue);102 super.setDefaultValue(value);103 }104 105 63 public String toString() 106 64 { 107 65 return "IntegerParameterType: Lower " + lowerLimit + ", Upper " + upperLimit; 108 66 } 109 67 // ------------------------------------------- 68 69 /* 70 From the ParameterType class 71 ------------------------------------------- 72 */ 73 /** 74 Checks if the value is an <code>Integer</object> object 75 and is within the range given by the upper and lower limits if those are given. 76 @param value The value to test 77 @return The same value 78 @throws InvalidDataException If the value is not an integer or outside 79 the range of allowed values 80 */ 81 Object getCheckedValue(Object value) 82 throws InvalidDataException 83 { 84 if (!(value instanceof Integer)) 85 { 86 throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not an 'Integer'"); 87 } 88 Integer val = (Integer)value; 89 if (((lowerLimit != null) && (val.compareTo(lowerLimit) < 0 )) 90 || 91 ((upperLimit != null) && (val.compareTo(upperLimit) > 0 ))) 92 { 93 throw new NumberOutOfRangeException( 94 "value", val.intValue(), 95 lowerLimit == null ? Integer.MIN_VALUE : lowerLimit.intValue(), 96 upperLimit == null ? Integer.MAX_VALUE : upperLimit.intValue() 97 ); 98 } 99 return value; 100 } 101 /** 102 Create a new {@link IntegerParameterValueData} object. 103 */ 104 @Override 105 public IntegerParameterValueData newParameterValueData() 106 { 107 return new IntegerParameterValueData(); 108 } 109 // ------------------------------------------- 110 110 111 111 /** 112 Get the low st valid value of the parameter.113 @return Low st valid value or null if none is set.112 Get the lowest valid value of the parameter. 113 @return Lowest valid value or null if none is set. 114 114 @hibernate.property column="`lowerLimit`" not-null="false" 115 115 */ … … 123 123 @param lowerLimit The lowest valid value. 124 124 */ 125 public void setLowerLimit( Integer lowerLimit)125 public void setLowerLimit(Integer lowerLimit) 126 126 { 127 127 this.lowerLimit = lowerLimit; … … 142 142 @param upperLimit The highest valid value. 143 143 */ 144 public void setUpperLimit( Integer upperLimit)144 public void setUpperLimit(Integer upperLimit) 145 145 { 146 146 this.upperLimit = upperLimit; 147 147 } 148 148 149 150 @Override151 public IntegerParameterValueData newParameterValueData(Object value)152 throws InvalidDataException153 {154 validate(value);155 return new IntegerParameterValueData((Integer) value);156 }157 149 } -
trunk/src/core/net/sf/basedb/core/Item.java
r1139 r1180 319 319 The item is a {@link PluginConfiguration} 320 320 */ 321 PLUGINCONFIGURATION(282, "Plugin configuration", "plc", PluginConfiguration.class, PluginConfigurationData.class, DefinedPermissions.shareable); 321 PLUGINCONFIGURATION(282, "Plugin configuration", "plc", PluginConfiguration.class, PluginConfigurationData.class, DefinedPermissions.shareable), 322 /** 323 The item is a {@link Job} 324 */ 325 JOB(283, "Job", "job", Job.class, JobData.class, DefinedPermissions.ownable); 322 326 323 327 -
trunk/src/core/net/sf/basedb/core/ItemParameterType.java
r1138 r1180 37 37 to choose from. 38 38 39 @author Samuel 39 @author Samuel, Nicklas 40 40 @version 2.0 41 @base.modified $Date$ 41 42 */ 42 43 public class ItemParameterType<T extends BasicItem> 43 extends ParameterType<ItemParameterValueData <T>>44 extends ParameterType<ItemParameterValueData> 44 45 { 45 46 /** … … 48 49 private List<T> items; 49 50 50 51 51 /** 52 52 Default constructor. … … 55 55 { 56 56 items = new ArrayList<T>(); 57 setHeight(1);58 setWidth(15);59 57 } 60 58 59 /* 60 From the Object class 61 ------------------------------------------- 62 */ 63 public String toString() 64 { 65 return "ItemParameterType: Items=" + items; 66 } 67 // ------------------------------------------- 68 69 /* 70 From the ParameterType class 71 ------------------------------------------- 72 */ 73 @SuppressWarnings("unchecked") 74 Object getCheckedValue(Object value) 75 throws InvalidDataException 76 { 77 if (!(value instanceof BasicItem)) 78 { 79 throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not a 'BasicItem'"); 80 } 81 if (!items.contains(value)) 82 { 83 throw new InvalidDataException("The value '"+value+"' isn't in the list of allowed values."); 84 } 85 return ((BasicItem)value).getData(); 86 } 87 88 /** 89 Create a new {@link ItemParameterValueData} object. 90 */ 91 @Override 92 public ItemParameterValueData newParameterValueData() 93 { 94 return new ItemParameterValueData(); 95 } 96 // ------------------------------------------- 61 97 62 98 /** … … 93 129 } 94 130 95 96 /**97 Validate parameter value. Checks if it is valid to98 the configuration.99 @param value The value to test.100 @throws InvalidDataException This exception is thrown101 if the value is invalid102 */103 @SuppressWarnings("unchecked")104 public void validate(Object value)105 throws InvalidDataException106 {107 if (value != null)108 {109 if (!(value instanceof BasicItem))110 {111 throw new InvalidDataException("Value is not a BasicItem object.");112 }113 BasicItem<?> bdValue = (BasicItem)value;114 Iterator<T> it = items.iterator();115 boolean match = false;116 while (it.hasNext() && !match)117 {118 T bd = it.next();119 if (bdValue.getType() == bd.getType() && bdValue.getId() == bd.getId())120 {121 match = true;122 }123 }124 if (!match)125 {126 throw new InvalidDataException("The item isn't in the list.");127 }128 }129 else if (getNotNull())130 {131 throw new InvalidDataException("Value is not allowed to be null.");132 }133 }134 135 136 public String toString()137 {138 return "ItemListParameterType: Items" + items;139 }140 141 142 @Override143 public void setDefaultValue(Object defaultValue)144 throws InvalidDataException145 {146 ItemParameterValueData<T> value = new ItemParameterValueData<T>();147 value.setSingleValue(defaultValue);148 super.setDefaultValue(value);149 }150 151 152 @SuppressWarnings("unchecked")153 @Override154 public ItemParameterValueData<T> newParameterValueData(Object value)155 throws InvalidDataException156 {157 validate(value);158 return new ItemParameterValueData<T>((T) value);159 }160 131 } -
trunk/src/core/net/sf/basedb/core/Message.java
r969 r1180 59 59 @throws BaseException If there is an error 60 60 */ 61 public static Message getNew(DbControl dc, User to, String fromName, User fromUser ) // TODO -, Job job)61 public static Message getNew(DbControl dc, User to, String fromName, User fromUser, Job job) 62 62 throws BaseException 63 63 { … … 68 68 m.setSender(fromUser); 69 69 m.getData().setTimeSent(new Date()); 70 // TODO - m.setJob(job)70 m.setJob(job); 71 71 return m; 72 72 } … … 326 326 @throws BaseException If there is another error 327 327 */ 328 /*329 TODO330 328 public Job getJob() 331 329 throws PermissionDeniedException, BaseException … … 333 331 return getDbControl().getItem(Job.class, getData().getJob()); 334 332 } 335 */ 333 private void setJob(Job job) 334 throws PermissionDeniedException 335 { 336 if (job != null) job.checkPermission(Permission.READ); 337 getData().setJob(job == null ? null : job.getData()); 338 } 336 339 337 340 /** -
trunk/src/core/net/sf/basedb/core/ParameterType.java
r1157 r1180 25 25 package net.sf.basedb.core; 26 26 27 import net.sf.basedb.core.data.ParameterValueData; 28 27 29 import java.util.List; 28 29 import net.sf.basedb.core.data.ParameterValueData; 30 import java.util.ArrayList; 31 30 32 31 33 /** … … 146 148 } 147 149 148 149 /** 150 Get the default value. If there is no default value 151 set it will return null. 152 @return The default value or null if none i set. 153 */ 154 public P getDefaultValue() 155 { 156 return defaultValue; 157 } 158 159 /** 160 Sets the default value. 161 @param defaultValue The new default value. 162 @throws InvalidDataException This exception is thrown 163 if the value is of wrong type. 164 */ 165 public void setDefaultValue(P defaultValue) 166 throws InvalidDataException 167 { 168 validateParameterValues(defaultValue.getValues()); 169 this.defaultValue = defaultValue; 170 } 150 // /** 151 // Get the default value. If there is no default value 152 // set it will return null. 153 // @return The default value or null if none i set. 154 // */ 155 // private P getDefaultValue() 156 // { 157 // return defaultValue; 158 // } 159 // 160 // /** 161 // Sets the default value. 162 // @param defaultValue The new default value. 163 // @throws InvalidDataException This exception is thrown 164 // if the value is of wrong type. 165 // */ 166 // private void setDefaultValue(P defaultValue) 167 // { 168 // this.defaultValue = defaultValue; 169 // } 171 170 172 171 /** … … 176 175 if the <code>ParamterValue</code> is of wrong type. 177 176 */ 178 public abstract void setDefaultValue(Object defaultValue) 179 throws InvalidDataException; 180 181 /** 182 Validate the values in a <code>ParameterValueData</code>. 183 @param values A list of <code>ParameterValueData</code> to test 184 @throws InvalidDataException This exception is thrown 185 if the value is invalid -or- parameter is null. 186 */ 177 public void setDefaultValue(Object value) 178 throws InvalidDataException 179 { 180 this.defaultValue = newParameterValueData(value); 181 } 182 183 public void setDefaultValues(List<?> values) 184 throws InvalidDataException 185 { 186 this.defaultValue = newParameterValueData(values); 187 } 188 189 /** 190 Check if a value is valid according to the settings of this parameter type. 191 @param value The value to test 192 @throws InvalidDataException If the value is invalid 193 */ 194 public void validate(Object value) 195 throws InvalidDataException 196 { 197 internalValidate(value); 198 } 199 200 private Object internalValidate(Object value) 201 throws InvalidDataException 202 { 203 Object validatedValue = value; 204 if (value == null) 205 { 206 if (getNotNull()) throw new InvalidUseOfNullException("value"); 207 } 208 else 209 { 210 validatedValue = getCheckedValue(value); 211 } 212 return validatedValue; 213 } 214 215 216 /** 217 Check if a list of values contain invalid values. 218 @param values A list of objects to check 219 @throws InvalidDataException If the list contains too many values as 220 specified by the {@link #getMultiplicity()} setting or has invalid values 221 as checked by {@link #validate(Object)} 222 */ 223 public void validate(List<?> values) 224 throws InvalidDataException 225 { 226 internalValidate(values); 227 } 228 187 229 @SuppressWarnings("unchecked") 188 public void validateParameterValues(List<?> values) 189 throws InvalidDataException 190 { 191 if (values != null) 230 private List<Object> internalValidate(List<?> values) 231 throws InvalidDataException 232 { 233 ArrayList<Object> validatedValues = null; 234 if (values != null && values.size() > 0) 192 235 { 193 if (multiplicity > 0 && values.size() > multiplicity) throw new InvalidDataException("To many values in parameter value."); 194 if (values.size() < 1) throw new InvalidDataException("Parameter value must have at least one value."); 195 for (Object v : values) 236 if (multiplicity > 0 && values.size() > multiplicity) 196 237 { 197 validate(v); 238 throw new InvalidDataException("Too many values in parameter value."); 239 } 240 validatedValues = new ArrayList<Object>(values.size()); 241 for (int i = 0; i < values.size(); ++i) 242 { 243 validatedValues.add(i, getCheckedValue(values.get(i))); 198 244 } 199 245 } 200 246 else if (getNotNull()) 201 247 { 202 throw new Invalid DataException("The parameter list is not allowed to be null.");248 throw new InvalidUseOfNullException("values"); 203 249 } 204 } 205 206 /** 207 Validate a single value. Checks if it is valid to 208 the configuration of the type. 209 @param value The value to test. 210 @throws InvalidDataException This exception is thrown 211 if the value is invalid 212 */ 213 public abstract void validate(Object value) 250 return validatedValues; 251 } 252 253 /** 254 Create a new {@link ParameterValueData} subclass which is used to 255 store values of this value type in the database, and initialise 256 it with a single value. 257 @param value The value to initialise the <code>ParameterValueData</code> 258 object with 259 @throws InvalidDataException If the value is null or invalid 260 */ 261 public P newParameterValueData(Object value) 262 throws InvalidDataException 263 { 264 if (value == null) throw new InvalidUseOfNullException("value"); 265 Object validatedValue = internalValidate(value); 266 P pv = newParameterValueData(); 267 pv.setSingleValue(validatedValue); 268 return pv; 269 } 270 271 /** 272 Create a new {@link ParameterValueData} subclass which is used to 273 store values of this value type in the database, and initialise 274 it with a list of values. 275 @param values The values to initialise the <code>ParameterValueData</code> 276 object with 277 @throws InvalidDataException If the list is null or contains nulls or 278 invalid values 279 */ 280 public P newParameterValueData(List<?> values) 281 throws InvalidDataException 282 { 283 if (values == null) throw new InvalidUseOfNullException("values"); 284 List<Object> validatedValues = internalValidate(values); 285 P pv = newParameterValueData(); 286 pv.replaceValues(validatedValues); 287 return pv; 288 } 289 290 /** 291 Check that a value is correct according to the settings 292 specific for the subclass. The returned value is the value that 293 is used in {@link ParameterValueData} objects. 294 @return The value to insert into the database 295 @throws InvalidDataException If the value is invalid 296 */ 297 abstract Object getCheckedValue(Object value) 214 298 throws InvalidDataException; 215 299 216 300 /** 217 Creates a single value. 218 @param value The value to create. 219 @throws InvalidDataException This exception is thrown 220 if the value is invalid 221 */ 222 public abstract ParameterValueData<?> newParameterValueData(Object value) 223 throws InvalidDataException; 301 Create a new {@link ParameterValueData} subclass which is used to 302 store values of this value type in the database. 303 */ 304 public abstract P newParameterValueData(); 224 305 225 306 } -
trunk/src/core/net/sf/basedb/core/SpotImages.java
r1157 r1180 387 387 @param blueImageFile The file containing the image to be used for the blue channel 388 388 or null 389 389 @param progress A {@link ProgressReporter} object if the calling client is 390 interested in the progress or null if not 391 390 392 @throws PermissionDeniedException If the logged in user doesn't have write 391 393 permission for the raw bioassay or to the specified spot images file or doesn't have … … 398 400 */ 399 401 public void createSpotImages(File spotImagesFile, int xScale, int yScale, int xOffset, int yOffset, 400 int spotsize, float gamma, float quality, File redImageFile, File greenImageFile, File blueImageFile) 402 int spotsize, float gamma, float quality, File redImageFile, File greenImageFile, File blueImageFile, 403 ProgressReporter progress) 401 404 throws PermissionDeniedException, InvalidDataException, BaseException 402 405 { … … 428 431 { 429 432 // Set up the gamma correction table for 16 to 8 bit 433 if (progress != null) progress.display(5, "Initialising..."); 430 434 byte[] gammaCorrection = new byte[0x10000]; 431 435 for (int i = 0; i < 0x10000; ++i) … … 460 464 Query<RawData> query = getRawBioAssay().getRawData(); 461 465 query.add(Orders.asc(query.rootAlias()+".position")); 462 ResultIterator<RawData> rawDataIterator = query.iterate();463 466 final Float floatSpotsize = new Float(spotsize); 464 467 final float halfSpotsize = -spotsize / 2; 465 468 final int spotImagesPerImage = NUM_SPOT_IMAGES * NUM_SPOT_IMAGES; 469 final int totalSpots = getRawBioAssay().getSpots(); 466 470 int lastImageNumber = 0; 467 471 468 472 // Iterate over each raw data spot and create spot images 473 if (progress != null) progress.display(10, "Generating spot images (0 done)..."); 474 ResultIterator<RawData> rawDataIterator = query.iterate(); 469 475 while (rawDataIterator.hasNext()) 470 476 { … … 479 485 if (imageNumber != lastImageNumber) 480 486 { 487 if (progress != null) 488 { 489 int spotsDone = spotImagesPerImage*imageNumber; 490 int percent = 10 + 90 * spotsDone / totalSpots; 491 progress.display(percent, "Generating spot images ("+spotsDone+" done)..."); 492 } 481 493 RenderedImage eightBitImage = convertTiffImage(outputImage, gammaCorrection); 482 494 saveImage(zipFileStream, "spots"+lastImageNumber+".jpg", eightBitImage, quality); … … 517 529 } 518 530 531 if (progress != null) progress.display(100, "Generating spot images ("+totalSpots+" done)..."); 519 532 RenderedImage eightBitImage = convertTiffImage(outputImage, gammaCorrection); 520 533 saveImage(zipFileStream, "spots"+lastImageNumber+".jpg", eightBitImage, quality); … … 525 538 throw new BaseException(ex); 526 539 } 527 528 529 540 } 530 541 … … 577 588 if (data == null) throw new InvalidUseOfNullException("data"); 578 589 File spotImagesFile = getSpotImagesFile(); 590 if (spotImagesFile == null) throw new ItemNotFoundException("No spot images has been generated yet."); 579 591 580 592 // Array to hold the generated spot images object -
trunk/src/core/net/sf/basedb/core/TextParameterType.java
r1138 r1180 43 43 44 44 public TextParameterType() 45 {} 46 47 /* 48 From the Object class 49 ------------------------------------------- 50 */ 51 public String toString() 45 52 { 46 setHeight(1); 47 setWidth(25); 53 return "TextParameterType: MaxLength " + maxLength; 48 54 } 55 // ------------------------------------------- 49 56 57 /* 58 From the ParameterType class 59 ------------------------------------------- 60 */ 50 61 /** 51 Validate parameter value. Checks if it is valid to52 the configuration.53 @param value The value to test .54 @ throws InvalidDataException This exception is thrown55 if the value is invalid62 Checks if the value is a <code>String</object> object 63 and shorter than the maximum length. 64 @param value The value to test 65 @return The same value 66 @throws InvalidDataException If the value is not a string or too long 56 67 */ 57 public void validate(Object value)68 Object getCheckedValue(Object value) 58 69 throws InvalidDataException 59 70 { 60 if ( value != null)71 if (!(value instanceof String)) 61 72 { 62 if (!(value instanceof String)) 63 { 64 throw new InvalidDataException("Value is not a String object."); 65 } 66 67 String val = (String)value; 68 if (maxLength != null && val.length() > maxLength) 69 { 70 throw new StringTooLongException("value", val, maxLength); 71 } 73 throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not a 'String'"); 72 74 } 73 else if (getNotNull()) 75 String val = (String)value; 76 if (maxLength != null && val.length() > maxLength) 74 77 { 75 throw new InvalidDataException("Value is not allowed to be null.");78 throw new StringTooLongException("value", val, maxLength); 76 79 } 80 return value; 77 81 } 78 82 /** 83 Create a new {@link TextParameterValueData} object. 84 */ 85 @Override 86 public TextParameterValueData newParameterValueData() 87 { 88 return new TextParameterValueData(); 89 } 90 // ------------------------------------------- 79 91 80 92 /** … … 86 98 return maxLength; 87 99 } 88 89 100 /** 90 101 Set the max length of the parameter. … … 95 106 this.maxLength = maxLength; 96 107 } 97 98 99 public String toString()100 {101 return "TextParameterType: MaxLength " + maxLength;102 }103 104 105 @Override106 public void setDefaultValue(Object defaultValue)107 throws InvalidDataException108 {109 TextParameterValueData value = new TextParameterValueData();110 value.setSingleValue(defaultValue);111 super.setDefaultValue(value);112 }113 114 @Override115 public ParameterValueData<String> newParameterValueData(Object value)116 throws InvalidDataException117 {118 validate(value);119 if (maxLength != null && maxLength < 256)120 return new StringParameterValueData((String) value);121 return new TextParameterValueData((String) value);122 }123 108 } -
trunk/src/core/net/sf/basedb/core/Type.java
r1134 r1180 42 42 import java.util.Map; 43 43 import java.util.HashMap; 44 import java.util.List; 44 45 45 46 /** … … 292 293 293 294 /** 295 Check if an object is a value of the correct type. Null is allowed. 296 @throws InvalidDataException If the value isn't of the correct type 297 */ 298 public void validate(Object value) 299 throws InvalidDataException 300 { 301 if (value != null && !isCorrectType(value)) 302 { 303 throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not a '"+this+"'"); 304 } 305 } 306 307 /** 308 Check if a list of values contain only objects of the correct type. 309 @throws InvalidDataException If the list contains one or more nulls or 310 values of incorrect object type 311 */ 312 public void validate(List<?> values) 313 throws InvalidDataException 314 { 315 if (values == null || values.size() == 0) return; 316 int i = 0; 317 for (Object value : values) 318 { 319 if (value == null) throw new InvalidUseOfNullException("values["+i+"]"); 320 if (!isCorrectType(value)) 321 { 322 throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not a '"+this+"'"); 323 } 324 i++; 325 } 326 } 327 328 /** 329 Create a new {@link ParameterValueData} subclass which is used to 330 store values of this value type in the database, and initialise 331 it with a single value. 332 @param value The value to initialise the <code>ParameterValueData</code> 333 object with 334 @throws InvalidDataException If the value is null or not of the correct 335 object type 336 */ 337 public ParameterValueData<?> newParameterValueData(Object value) 338 throws InvalidDataException 339 { 340 if (value == null) throw new InvalidUseOfNullException("value"); 341 validate(value); 342 ParameterValueData<?> pv = newParameterValueData(); 343 pv.setSingleValue(value); 344 return pv; 345 } 346 347 /** 348 Create a new {@link ParameterValueData} subclass which is used to 349 store values of this value type in the database, and initialise 350 it with a list of values. 351 @param values The values to initialise the <code>ParameterValueData</code> 352 object with 353 @throws InvalidDataException If the list is null or contains nulls or values 354 of an incorrect object type 355 */ 356 public ParameterValueData newParameterValueData(List<?> values) 357 throws InvalidDataException 358 { 359 if (values == null) throw new InvalidUseOfNullException("values"); 360 validate(values); 361 ParameterValueData<?> pv = newParameterValueData(); 362 pv.replaceValues(values); 363 return pv; 364 } 365 366 /** 294 367 Check if the value is an object of the correct type. 295 368 */ -
trunk/src/core/net/sf/basedb/core/data/FileParameterValueData.java
r1107 r1180 67 67 } 68 68 69 public String toString()70 {71 return values.toString();72 }73 69 } -
trunk/src/core/net/sf/basedb/core/data/ItemParameterValueData.java
r1107 r1180 39 39 @base.modified $Date$ 40 40 */ 41 public class ItemParameterValueData <T>42 extends ParameterValueData< T>41 public class ItemParameterValueData 42 extends ParameterValueData<BasicData> 43 43 { 44 44 public ItemParameterValueData() 45 45 {} 46 46 47 public ItemParameterValueData( T... values)47 public ItemParameterValueData(BasicData... values) 48 48 { 49 49 super(values); 50 50 } 51 51 52 private List< T> values;52 private List<BasicData> values; 53 53 /** 54 54 @hibernate.bag table="`ItemValues`" lazy="true" cascade="all" … … 58 58 @hibernate.many-to-any-column name="`data_class_id`" not-null="true" 59 59 */ 60 public List< T> getValues()60 public List<BasicData> getValues() 61 61 { 62 62 if (values == null) 63 63 { 64 values = new ArrayList< T>();64 values = new ArrayList<BasicData>(); 65 65 } 66 66 return values; 67 67 } 68 void setValues(List< T> values)68 void setValues(List<BasicData> values) 69 69 { 70 70 this.values = values; 71 71 } 72 72 73 public String toString()74 {75 return values.toString();76 }77 73 } -
trunk/src/core/net/sf/basedb/core/data/JobData.java
r1172 r1180 27 27 import java.util.Date; 28 28 import java.util.Set; 29 import java.util.Map; 30 import java.util.HashMap; 29 31 30 32 /** … … 40 42 public class JobData 41 43 extends OwnedData 44 implements NameableData, RemovableData 42 45 { 43 46 … … 45 48 {} 46 49 50 /* 51 From the NameableData interface 52 ------------------------------------------- 53 */ 54 private String name; 55 public String getName() 56 { 57 return name; 58 } 59 public void setName(String name) 60 { 61 this.name = name; 62 } 63 private String description; 64 public String getDescription() 65 { 66 return description; 67 } 68 public void setDescription(String description) 69 { 70 this.description = description; 71 } 72 // ------------------------------------------- 73 /* 74 From the RemovableData interface 75 ------------------------------------------- 76 */ 77 private boolean removed; 78 public boolean isRemoved() 79 { 80 return removed; 81 } 82 public void setRemoved(boolean removed) 83 { 84 this.removed = removed; 85 } 86 // ------------------------------------------- 87 47 88 private PluginConfigurationData pluginConfiguration; 48 89 /** 49 The plugin configuration that defines the plugin to run. 90 The plugin configuration that defines the plugin to run, or null if the job isn't 91 exececuted by a plugin. 50 92 @hibernate.many-to-one column="`pluginconfiguration_id`" not-null="false" outer-join="false" update="false" 51 93 */ … … 61 103 private int status; 62 104 /** 63 Get the status of the job. 0 = waiting, 1 = running, 2 = completed ok, 3= error105 Get the status of the job. 1 = waiting, 2 = running, 3 = completed ok, 4 = error 64 106 @hibernate.property column="`status`" type="int" not-null="true" 65 107 */ … … 76 118 The maximum allowed length of the status message. 77 119 */ 78 public static final int MAX_STATUS_MESSAGE_LENGTH = 255;120 public static final int MAX_STATUS_MESSAGE_LENGTH = 65535; 79 121 private String statusMessage; 80 122 /** 81 123 Get a status message. 82 @hibernate.property column="`status_message`" type=" string" length="255" not-null="false"124 @hibernate.property column="`status_message`" type="text" not-null="false" 83 125 */ 84 126 public String getStatusMessage() … … 159 201 { 160 202 this.ended = ended; 203 } 204 205 private Map<String, ParameterValueData> parameters; 206 /** 207 The parameters for this job. 208 @hibernate.map table="`JobParameters`" lazy="true" cascade="all" 209 @hibernate.collection-key column="`job_id`" 210 @hibernate.collection-index column="`name`" type="string" length="255" 211 @hibernate.collection-many-to-many column="`value_id`" class="net.sf.basedb.core.data.ParameterValueData" 212 */ 213 public Map<String, ParameterValueData> getParameters() 214 { 215 if (parameters == null) parameters = new HashMap<String, ParameterValueData>(); 216 return parameters; 217 } 218 void setParameters(Map<String, ParameterValueData> parameters) 219 { 220 this.parameters = parameters; 161 221 } 162 222 -
trunk/src/core/net/sf/basedb/core/data/ParameterValueData.java
r1138 r1180 38 38 */ 39 39 public abstract class ParameterValueData<T> 40 extends BasicData 40 41 { 41 42 ParameterValueData() … … 47 48 } 48 49 49 private int id = 0;50 /**51 Get the id of the item. The id is automatically generated by the database52 the first time the item is saved to the database. A new item has the value 0.53 @hibernate.id column="`id`" type="int" generator-class="native" unsaved-value="0"54 */55 public int getId()56 {57 return id;58 }59 /**60 Set the id of the item. Only used by Hibernate.61 @param id The id of the item62 */63 void setId(int id)64 {65 this.id = id;66 }67 68 private int version = 0;69 /**70 Get the version of the item. This value is used by Hibernate to check if another71 process or thread has modified the corresponding row in the databse since this item72 was loaded from the. If that is the case, this item can't be saved and an73 exception will be thrown.74 @hibernate.version column="`version`" type="int"75 */76 public int getVersion()77 {78 return version;79 }80 /**81 Set the version of the item. Only used by Hibernate.82 @param version The version of the item83 */84 void setVersion(int version)85 {86 this.version = version;87 }50 // private int id = 0; 51 // /** 52 // Get the id of the item. The id is automatically generated by the database 53 // the first time the item is saved to the database. A new item has the value 0. 54 // @hibernate.id column="`id`" type="int" generator-class="native" unsaved-value="0" 55 // */ 56 // public int getId() 57 // { 58 // return id; 59 // } 60 // /** 61 // Set the id of the item. Only used by Hibernate. 62 // @param id The id of the item 63 // */ 64 // void setId(int id) 65 // { 66 // this.id = id; 67 // } 68 // 69 // private int version = 0; 70 // /** 71 // Get the version of the item. This value is used by Hibernate to check if another 72 // process or thread has modified the corresponding row in the databse since this item 73 // was loaded from the. If that is the case, this item can't be saved and an 74 // exception will be thrown. 75 // @hibernate.version column="`version`" type="int" 76 // */ 77 // public int getVersion() 78 // { 79 // return version; 80 // } 81 // /** 82 // Set the version of the item. Only used by Hibernate. 83 // @param version The version of the item 84 // */ 85 // void setVersion(int version) 86 // { 87 // this.version = version; 88 // } 88 89 89 90 /** -
trunk/src/core/net/sf/basedb/core/plugin/AbstractPlugin.java
r1138 r1180 99 99 { 100 100 PluginParameter type = it.next(); 101 List<?> value = request.getParameterValues(type.getName());101 List<?> values = request.getParameterValues(type.getName()); 102 102 try 103 103 { 104 type.getParameterType().validate ParameterValues(value);104 type.getParameterType().validate(values); 105 105 } 106 106 // If invalid data, catch and add to error list. -
trunk/src/test/TestMessage.java
r833 r1180 67 67 dc = TestUtil.getDbControl(); 68 68 User user = User.getById(dc, toUserId); 69 Message m = Message.getNew(dc, user, from, null );69 Message m = Message.getNew(dc, user, from, null, null); 70 70 if (setAll) 71 71 { -
trunk/src/test/TestParameterType.java
r1138 r1180 86 86 TextParameterType textType = new TextParameterType(); 87 87 textType.setMaxLength(37); 88 textType.setDefaultValue( new TextParameterValueData("nothing"));88 textType.setDefaultValue("nothing"); 89 89 parameters.add(textType); 90 90 } 91 catch (InvalidDataException e )91 catch (InvalidDataException ex) 92 92 { 93 93 ok = false; 94 write("++Testing parameter type creation FAILED"); 94 write("--Testing parameter type creation FAILED"); 95 ex.printStackTrace(); 95 96 } 96 97 … … 131 132 IntegerParameterValueData intValue = new IntegerParameterValueData(); 132 133 intValue.getValues().add(100); 133 param.validate ParameterValues(intValue.getValues());134 param.validate(intValue.getValues()); 134 135 param.validate(new Integer(-234)); 135 136 … … 197 198 } 198 199 } 199 write(" ++Testing parameter type validation OK");200 write("--Testing parameter type validation OK"); 200 201 } 201 202 catch (Throwable ex) 202 203 { 203 204 ok = false; 204 write(" ++Testing parameter type validation FAILED");205 write("--Testing parameter type validation FAILED"); 205 206 ex.printStackTrace(); 206 207 } -
trunk/src/test/TestReporterMapImport.java
r1138 r1180 138 138 139 139 140 pr.setParameterValue("arrayDesign", n ew ItemParameterValueData<ArrayDesign>(ad));141 pr.setParameterValue("file", n ew ItemParameterValueData<File>(f));140 pr.setParameterValue("arrayDesign", null); // ad); 141 pr.setParameterValue("file", null); //f); 142 142 if (reportertype_id != 0) 143 143 { 144 144 ReporterType rt = ReporterType.getById(dc, reportertype_id); 145 pr.setParameterValue("reporterType", n ew ItemParameterValueData<ReporterType>(rt));145 pr.setParameterValue("reporterType", null); // rt); 146 146 } 147 147 try -
trunk/src/test/TestSpotImages.java
r1143 r1180 103 103 time = System.currentTimeMillis(); 104 104 SpotImages si = rba.getSpotImages(); 105 si.createSpotImages(spots, 5, 5, 0, 0, 32, 1.8f, 0.75f, image, image, null); 105 ProgressReporter progress = TestUtil.getSilent() ? null : new ProgressReporterImpl(); 106 si.createSpotImages(spots, 5, 5, 0, 0, 32, 1.8f, 0.75f, image, image, null, progress); 106 107 dc.commit(); 107 108 time = System.currentTimeMillis()-time; … … 274 275 System.out.println(message); 275 276 } 277 278 static class ProgressReporterImpl 279 implements ProgressReporter 280 { 281 public void display(int percent, String message) 282 { 283 System.out.println("--SpotImages: "+message); 284 } 285 286 public void append(String message) 287 { 288 //System.out.println("--"+message); 289 } 290 } 276 291 } 277 292
Note: See TracChangeset
for help on using the changeset viewer.