Changeset 1180


Ignore:
Timestamp:
Aug 31, 2005, 3:24:49 PM (18 years ago)
Author:
Nicklas Nordborg
Message:

Added Job and made lots of changes to the ParameterType? and
ParameterValueData? classes

Location:
trunk
Files:
1 added
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/build.xml

    r1139 r1180  
    2121
    2222  <!-- set global properties for this build -->
     23  <property name="compilerarg" value="-Xlint:unchecked" />
    2324  <property name="base.version" value="pre2.0_demo" />
    2425  <property name="src" location="src" />
     
    176177      deprecation="true"
    177178      >
    178       <compilerarg value="-Xlint:unchecked" />
     179      <compilerarg value="${compilerarg}" />
    179180    </javac>
    180181    <copy todir="${core.build}">
     
    207208      encoding="ISO-8859-1"
    208209      >
    209       <compilerarg value="-Xlint:unchecked" />
     210      <compilerarg value="${compilerarg}" />
    210211    </javac>
    211212    <copy todir="${test.build}">
     
    259260      debug="true"
    260261      >
    261       <compilerarg value="-Xlint:unchecked" />
     262      <compilerarg value="${compilerarg}" />
    262263    </javac>
    263264    <copy todir="${migrate.build}">
     
    298299      deprecation="true"
    299300      >
    300       <compilerarg value="-Xlint:unchecked" />
     301      <compilerarg value="${compilerarg}" />
    301302    </javac>
    302303  </target>
     
    350351      deprecation="true"
    351352      >
    352       <compilerarg value="-Xlint:unchecked" />
     353      <compilerarg value="${compilerarg}" />
    353354    </javac>
    354355    <copy todir="${web.build}">
  • trunk/src/core/net/sf/basedb/core/AnnotationType.java

    r936 r1180  
    589589      have write permission
    590590    @throws InvalidDataException If the list contains values of the wrong type
    591       as checked by the {@link Type#isCorrectType(Object)} method
     591      as checked by the {@link Type#validate(List)} method
    592592  */
    593593  public void setValues(List<?> values)
     
    598598    Type valueType = getValueType();
    599599    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);
    613601    ParameterValueData<?> pv = getData().getEnumerationValues();
    614602    if (pv == null)
     
    749737    if (value == null) throw new InvalidUseOfNullException("value");
    750738    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);
    756740    if (valueType == Type.INT)
    757741    {
  • trunk/src/core/net/sf/basedb/core/DateParameterType.java

    r1138 r1180  
    3232  This class represent a parameter type that is a date.
    3333
    34   @author Samuel
     34  @author Samuel, Nicklas
    3535  @version 2.0
     36  @base.modified $Date$
    3637*/
    3738public class DateParameterType
     
    3940{
    4041  public DateParameterType()
     42  {}
     43
     44  /*
     45    From the Object class
     46    -------------------------------------------
     47  */
     48  public String toString()
    4149  {
    42     setHeight(1);
    43     setWidth(10);
     50    return "DateParameterType";
    4451  }
     52  // -------------------------------------------
    4553
    46 
     54  /*
     55    From the ParameterType class
     56    -------------------------------------------
     57  */
    4758  /**
    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
    5363  */
    54   public void validate(Object value)
     64  @Override
     65  Object getCheckedValue(Object value)
    5566    throws InvalidDataException
    5667  {
    5768    if (!(value instanceof Date))
    5869    {
    59       throw new InvalidDataException("Value is not a Date object.");
     70      throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not a 'Date'");
    6071    }
    61     if (value == null && getNotNull())
    62     {
    63       throw new InvalidDataException("Value is not allowed to be null.");
    64     }
     72    return value;
    6573  }
    66 
    6774 
     75  /**
     76    Create a new {@link DateParameterValueData} object.
     77  */
    6878  @Override
    69   public void setDefaultValue(Object defaultValue)
    70     throws InvalidDataException
     79  public DateParameterValueData newParameterValueData()
    7180  {
    72     DateParameterValueData value = new DateParameterValueData();
    73     value.setSingleValue(defaultValue);
    74     super.setDefaultValue(value);
     81    return new DateParameterValueData();
    7582  }
     83  // -------------------------------------------
    7684
    7785
    78   public String toString()
    79   {
    80     return "DateParameterType";
    81   }
    82 
    83   @Override
    84   public DateParameterValueData newParameterValueData(Object value)
    85     throws InvalidDataException
    86   {
    87     validate(value);
    88     return new DateParameterValueData((Date) value);
    89   }
    9086}
  • trunk/src/core/net/sf/basedb/core/FileParameterType.java

    r1138 r1180  
    3333  This class represent a parameter type that is a file.
    3434
    35   @author Samuel
     35  @author Samuel, Nicklas
    3636  @version 2.0
     37  @base.modified $Date$
    3738*/
    3839public class FileParameterType
     
    4748  {
    4849    this.mimeTypes = new ArrayList<MimeType>();
    49     setHeight(1);
    50     setWidth(25);
    5150  }
    5251
     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  */
    5366  /**
    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
    5971  */
    60   public void validate(Object value)
     72  @Override
     73  Object getCheckedValue(Object value)
    6174    throws InvalidDataException
    6275  {
    6376    if (!(value instanceof File))
    6477    {
    65       throw new InvalidDataException("Value is not a FileData object.");
     78      throw new InvalidDataException("Value '"+value+"' is a '"+value.getClass()+"', not a 'File'");
    6679    }
    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();
    8081  }
    8182 
    82   public String toString()
     83  /**
     84    Create a new {@link FileParameterValueData} object.
     85  */
     86  @Override
     87  public FileParameterValueData newParameterValueData()
    8388  {
    84     return "FileParameterType";
     89    return new FileParameterValueData();
    8590  }
     91  // -------------------------------------------
     92
    8693
    8794  /**
     
    116123  }
    117124
    118   @Override
    119   public FileParameterValueData newParameterValueData(Object value)
    120     throws InvalidDataException
    121   {
    122     validate(value);
    123     return new FileParameterValueData(((File) value).getData());
    124   }
    125125}
  • trunk/src/core/net/sf/basedb/core/FloatParameterType.java

    r1138 r1180  
    3333  allowed values.
    3434
    35   @author Samuel
     35  @author Samuel, Nicklas
    3636  @version 2.0
     37  @base.modified $Date$
    3738*/
    3839public class FloatParameterType
     
    5152
    5253  public FloatParameterType()
    53   {
    54     setHeight(1);
    55     setWidth(6);
    56   }
     54  {}
    5755
    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    -------------------------------------------
    6559  */
    66   public void validate(Object value)
    67     throws InvalidDataException
    68   {
    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   @Override
    94   public void setDefaultValue(Object defaultValue)
    95     throws InvalidDataException
    96   {
    97     FloatParameterValueData value = new FloatParameterValueData();
    98     value.setSingleValue(defaultValue);
    99     super.setDefaultValue(value);
    100   }
    101  
    102 
    10360  public String toString()
    10461  {
    10562    return "FloatParameterType: Lower " + lowerLimit + ", Upper " + upperLimit;
    10663  }
     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  // -------------------------------------------
    107108
    108109
     
    120121    @param lowerLimit The lowest valid value.
    121122  */
    122   public void setLowerLimit( Float lowerLimit )
     123  public void setLowerLimit(Float lowerLimit)
    123124  {
    124125    this.lowerLimit = lowerLimit;
     
    139140    @param upperLimit The highest valid value.
    140141  */
    141   public void setUpperLimit( Float upperLimit )
     142  public void setUpperLimit(Float upperLimit)
    142143  {
    143144    this.upperLimit = upperLimit;
    144145  }
    145146
    146 
    147   @Override
    148   public FloatParameterValueData newParameterValueData(Object value)
    149     throws InvalidDataException
    150   {
    151     validate(value);
    152     return new FloatParameterValueData((Float) value);
    153   }
    154147}
  • trunk/src/core/net/sf/basedb/core/IntegerParameterType.java

    r1138 r1180  
    3333  allowed values.
    3434
    35   @author Samuel
     35  @author Samuel, Nicklas
    3636  @version 2.0
     37  @base.modified $Date$
    3738*/
    3839public class IntegerParameterType
     
    5455  */
    5556  public IntegerParameterType()
    56   {
    57     setHeight(1);
    58     setWidth(6);
    59   }
     57  {}
    6058
    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    -------------------------------------------
    6862  */
    69   public void validate(Object value)
    70     throws InvalidDataException
    71   {
    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   @Override
    97   public void setDefaultValue(Object defaultValue)
    98     throws InvalidDataException
    99   {
    100     IntegerParameterValueData value = new IntegerParameterValueData();
    101     value.setSingleValue(defaultValue);
    102     super.setDefaultValue(value);
    103   }
    104  
    10563  public String toString()
    10664  {
    10765    return "IntegerParameterType: Lower " + lowerLimit + ", Upper " + upperLimit;
    10866  }
    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  // -------------------------------------------
    110110
    111111  /**
    112     Get the lowst valid value of the parameter.
    113     @return Lowst 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.
    114114    @hibernate.property column="`lowerLimit`" not-null="false"
    115115  */
     
    123123    @param lowerLimit The lowest valid value.
    124124  */
    125   public void setLowerLimit( Integer lowerLimit )
     125  public void setLowerLimit(Integer lowerLimit)
    126126  {
    127127    this.lowerLimit = lowerLimit;
     
    142142    @param upperLimit The highest valid value.
    143143  */
    144   public void setUpperLimit( Integer upperLimit )
     144  public void setUpperLimit(Integer upperLimit)
    145145  {
    146146    this.upperLimit = upperLimit;
    147147  }
    148148
    149 
    150   @Override
    151   public IntegerParameterValueData newParameterValueData(Object value)
    152     throws InvalidDataException
    153   {
    154     validate(value);
    155     return new IntegerParameterValueData((Integer) value);
    156   }
    157149}
  • trunk/src/core/net/sf/basedb/core/Item.java

    r1139 r1180  
    319319    The item is a {@link PluginConfiguration}
    320320  */
    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);
    322326
    323327
  • trunk/src/core/net/sf/basedb/core/ItemParameterType.java

    r1138 r1180  
    3737  to choose from.
    3838
    39   @author Samuel
     39  @author Samuel, Nicklas
    4040  @version 2.0
     41  @base.modified $Date$
    4142*/
    4243public class ItemParameterType<T extends BasicItem>
    43   extends ParameterType<ItemParameterValueData<T>>
     44  extends ParameterType<ItemParameterValueData>
    4445{
    4546  /**
     
    4849  private List<T> items;
    4950 
    50 
    5151  /**
    5252    Default constructor.
     
    5555  {
    5656    items = new ArrayList<T>();
    57     setHeight(1);
    58     setWidth(15);
    5957  }
    6058
     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  // -------------------------------------------
    6197
    6298  /**
     
    93129  }
    94130
    95 
    96   /**
    97     Validate parameter value. Checks if it is valid to
    98     the configuration.
    99     @param value The value to test.
    100     @throws InvalidDataException This exception is thrown
    101       if the value is invalid
    102   */
    103   @SuppressWarnings("unchecked")
    104   public void validate(Object value)
    105     throws InvalidDataException
    106   {
    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   @Override
    143   public void setDefaultValue(Object defaultValue)
    144     throws InvalidDataException
    145   {
    146     ItemParameterValueData<T> value = new ItemParameterValueData<T>();
    147     value.setSingleValue(defaultValue);
    148     super.setDefaultValue(value);
    149   }
    150 
    151 
    152   @SuppressWarnings("unchecked")
    153   @Override
    154   public ItemParameterValueData<T> newParameterValueData(Object value)
    155     throws InvalidDataException
    156   {
    157     validate(value);
    158     return new ItemParameterValueData<T>((T) value);
    159   }
    160131}
  • trunk/src/core/net/sf/basedb/core/Message.java

    r969 r1180  
    5959    @throws BaseException If there is an error
    6060  */
    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)
    6262    throws BaseException
    6363  {
     
    6868    m.setSender(fromUser);
    6969    m.getData().setTimeSent(new Date());
    70     // TODO - m.setJob(job)
     70    m.setJob(job);
    7171    return m;
    7272  }
     
    326326    @throws BaseException If there is another error
    327327  */
    328   /*
    329   TODO
    330328  public Job getJob()
    331329    throws PermissionDeniedException, BaseException
     
    333331    return getDbControl().getItem(Job.class, getData().getJob());
    334332  }
    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  }
    336339 
    337340  /**
  • trunk/src/core/net/sf/basedb/core/ParameterType.java

    r1157 r1180  
    2525package net.sf.basedb.core;
    2626
     27import net.sf.basedb.core.data.ParameterValueData;
     28
    2729import java.util.List;
    28 
    29 import net.sf.basedb.core.data.ParameterValueData;
     30import java.util.ArrayList;
     31
    3032
    3133/**
     
    146148  }
    147149
    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//  }
    171170
    172171  /**
     
    176175      if the <code>ParamterValue</code> is of wrong type.
    177176  */
    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
    187229  @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)
    192235    {
    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)
    196237      {
    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)));
    198244      }
    199245    }
    200246    else if (getNotNull())
    201247    {
    202        throw new InvalidDataException("The parameter list is not allowed to be null.");
     248       throw new InvalidUseOfNullException("values");
    203249    }
    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)
    214298    throws InvalidDataException;
    215299 
    216300  /**
    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();
    224305 
    225306}
  • trunk/src/core/net/sf/basedb/core/SpotImages.java

    r1157 r1180  
    387387    @param blueImageFile The file containing the image to be used for the blue channel
    388388      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
    390392    @throws PermissionDeniedException If the logged in user doesn't have write
    391393      permission for the raw bioassay or to the specified spot images file or doesn't have
     
    398400  */
    399401  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)
    401404    throws PermissionDeniedException, InvalidDataException, BaseException
    402405  {
     
    428431    {
    429432      // Set up the gamma correction table for 16 to 8 bit
     433      if (progress != null) progress.display(5, "Initialising...");
    430434      byte[] gammaCorrection = new byte[0x10000];
    431435      for (int i = 0; i < 0x10000; ++i)
     
    460464      Query<RawData> query = getRawBioAssay().getRawData();
    461465      query.add(Orders.asc(query.rootAlias()+".position"));
    462       ResultIterator<RawData> rawDataIterator = query.iterate();
    463466      final Float floatSpotsize = new Float(spotsize);
    464467      final float halfSpotsize = -spotsize / 2;
    465468      final int spotImagesPerImage = NUM_SPOT_IMAGES * NUM_SPOT_IMAGES;
     469      final int totalSpots = getRawBioAssay().getSpots();
    466470      int lastImageNumber = 0;
    467      
     471
    468472      // 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();
    469475      while (rawDataIterator.hasNext())
    470476      {
     
    479485        if (imageNumber != lastImageNumber)
    480486        {
     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          }
    481493          RenderedImage eightBitImage = convertTiffImage(outputImage, gammaCorrection);
    482494          saveImage(zipFileStream, "spots"+lastImageNumber+".jpg", eightBitImage, quality);
     
    517529      }
    518530 
     531      if (progress != null) progress.display(100, "Generating spot images ("+totalSpots+" done)...");
    519532      RenderedImage eightBitImage = convertTiffImage(outputImage, gammaCorrection);
    520533      saveImage(zipFileStream, "spots"+lastImageNumber+".jpg", eightBitImage, quality);
     
    525538      throw new BaseException(ex);
    526539    }
    527 
    528 
    529540  }
    530541 
     
    577588    if (data == null)  throw new InvalidUseOfNullException("data");
    578589    File spotImagesFile = getSpotImagesFile();
     590    if (spotImagesFile == null) throw new ItemNotFoundException("No spot images has been generated yet.");
    579591   
    580592    // Array to hold the generated spot images object
  • trunk/src/core/net/sf/basedb/core/TextParameterType.java

    r1138 r1180  
    4343
    4444  public TextParameterType()
     45  {}
     46
     47  /*
     48    From the Object class
     49    -------------------------------------------
     50  */
     51  public String toString()
    4552  {
    46     setHeight(1);
    47     setWidth(25);
     53    return "TextParameterType: MaxLength " + maxLength;
    4854  }
     55  // -------------------------------------------
    4956
     57  /*
     58    From the ParameterType class
     59    -------------------------------------------
     60  */
    5061  /**
    51     Validate parameter value. Checks if it is valid to
    52     the configuration.
    53     @param value The value to test.
    54     @throws InvalidDataException This exception is thrown
    55       if the value is invalid
     62    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
    5667  */
    57   public void validate(Object value)
     68  Object getCheckedValue(Object value)
    5869    throws InvalidDataException
    5970  {
    60     if (value != null)
     71    if (!(value instanceof String))
    6172    {
    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'");
    7274    }
    73     else if (getNotNull())
     75    String val = (String)value;
     76    if (maxLength != null && val.length() > maxLength)
    7477    {
    75       throw new InvalidDataException("Value is not allowed to be null.");
     78      throw new StringTooLongException("value", val, maxLength);
    7679    }
     80    return value;
    7781  }
    78 
     82  /**
     83    Create a new {@link TextParameterValueData} object.
     84  */
     85  @Override
     86  public TextParameterValueData newParameterValueData()
     87  {
     88    return new TextParameterValueData();
     89  }
     90  // -------------------------------------------
    7991
    8092  /**
     
    8698    return maxLength;
    8799  }
    88 
    89100  /**
    90101    Set the max length of the parameter.
     
    95106    this.maxLength = maxLength;
    96107  }
    97 
    98 
    99   public String toString()
    100   {
    101     return "TextParameterType: MaxLength " + maxLength;
    102   }
    103  
    104 
    105   @Override
    106   public void setDefaultValue(Object defaultValue)
    107     throws InvalidDataException
    108   {
    109     TextParameterValueData value = new TextParameterValueData();
    110     value.setSingleValue(defaultValue);
    111     super.setDefaultValue(value);
    112   }
    113 
    114   @Override
    115   public ParameterValueData<String> newParameterValueData(Object value)
    116     throws InvalidDataException
    117   {
    118     validate(value);
    119     if (maxLength != null && maxLength < 256)
    120       return new StringParameterValueData((String) value);
    121     return new TextParameterValueData((String) value);
    122   }
    123108}
  • trunk/src/core/net/sf/basedb/core/Type.java

    r1134 r1180  
    4242import java.util.Map;
    4343import java.util.HashMap;
     44import java.util.List;
    4445
    4546/**
     
    292293
    293294  /**
     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  /**
    294367    Check if the value is an object of the correct type.
    295368  */
  • trunk/src/core/net/sf/basedb/core/data/FileParameterValueData.java

    r1107 r1180  
    6767  }
    6868
    69   public String toString()
    70   {
    71     return values.toString();
    72   }
    7369}
  • trunk/src/core/net/sf/basedb/core/data/ItemParameterValueData.java

    r1107 r1180  
    3939  @base.modified $Date$
    4040*/
    41 public class ItemParameterValueData<T>
    42   extends ParameterValueData<T>
     41public class ItemParameterValueData
     42  extends ParameterValueData<BasicData>
    4343{
    4444  public ItemParameterValueData()
    4545  {}
    4646
    47   public ItemParameterValueData(T... values)
     47  public ItemParameterValueData(BasicData... values)
    4848  {
    4949    super(values);
    5050  }
    5151
    52   private List<T> values;
     52  private List<BasicData> values;
    5353  /**
    5454    @hibernate.bag table="`ItemValues`" lazy="true" cascade="all"
     
    5858    @hibernate.many-to-any-column name="`data_class_id`" not-null="true"
    5959  */
    60   public List<T> getValues()
     60  public List<BasicData> getValues()
    6161  {
    6262    if (values == null)
    6363    {
    64       values = new ArrayList<T>();
     64      values = new ArrayList<BasicData>();
    6565    }
    6666    return values;
    6767  }
    68   void setValues(List<T> values)
     68  void setValues(List<BasicData> values)
    6969  {
    7070    this.values = values;
    7171  }
    7272
    73   public String toString()
    74   {
    75     return values.toString();
    76   }
    7773}
  • trunk/src/core/net/sf/basedb/core/data/JobData.java

    r1172 r1180  
    2727import java.util.Date;
    2828import java.util.Set;
     29import java.util.Map;
     30import java.util.HashMap;
    2931
    3032/**
     
    4042public class JobData
    4143  extends OwnedData
     44  implements NameableData, RemovableData
    4245{
    4346
     
    4548  {}
    4649
     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
    4788  private PluginConfigurationData pluginConfiguration;
    4889  /**
    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.
    5092    @hibernate.many-to-one column="`pluginconfiguration_id`" not-null="false" outer-join="false" update="false"
    5193  */
     
    61103  private int status;
    62104  /**
    63     Get the status of the job. 0 = waiting, 1 = running, 2 = completed ok, 3 = error
     105    Get the status of the job. 1 = waiting, 2 = running, 3 = completed ok, 4 = error
    64106    @hibernate.property column="`status`" type="int" not-null="true"
    65107  */
     
    76118    The maximum allowed length of the status message.
    77119  */
    78   public static final int MAX_STATUS_MESSAGE_LENGTH = 255;
     120  public static final int MAX_STATUS_MESSAGE_LENGTH = 65535;
    79121  private String statusMessage;
    80122  /**
    81123    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"
    83125  */
    84126  public String getStatusMessage()
     
    159201  {
    160202    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;
    161221  }
    162222
  • trunk/src/core/net/sf/basedb/core/data/ParameterValueData.java

    r1138 r1180  
    3838*/
    3939public abstract class ParameterValueData<T>
     40  extends BasicData
    4041{
    4142  ParameterValueData()
     
    4748  }
    4849 
    49   private int id = 0;
    50   /**
    51     Get the id of the item. The id is automatically generated by the database
    52     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 item
    62   */
    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 another
    71     process or thread has modified the corresponding row in the databse since this item
    72     was loaded from the. If that is the case, this item can't be saved and an
    73     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 item
    83   */
    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// }
    8889
    8990  /**
  • trunk/src/core/net/sf/basedb/core/plugin/AbstractPlugin.java

    r1138 r1180  
    9999    {
    100100      PluginParameter type = it.next();
    101       List<?> value = request.getParameterValues(type.getName());
     101      List<?> values = request.getParameterValues(type.getName());
    102102      try
    103103      {
    104         type.getParameterType().validateParameterValues(value);
     104        type.getParameterType().validate(values);
    105105      }
    106106      // If invalid data, catch and add to error list.
  • trunk/src/test/TestMessage.java

    r833 r1180  
    6767      dc = TestUtil.getDbControl();
    6868      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);
    7070      if (setAll)
    7171      {
  • trunk/src/test/TestParameterType.java

    r1138 r1180  
    8686      TextParameterType textType = new TextParameterType();
    8787      textType.setMaxLength(37);
    88       textType.setDefaultValue(new TextParameterValueData("nothing"));
     88      textType.setDefaultValue("nothing");
    8989      parameters.add(textType);
    9090    }
    91     catch (InvalidDataException e)
     91    catch (InvalidDataException ex)
    9292    {
    9393      ok = false;
    94       write("++Testing parameter type creation FAILED");
     94      write("--Testing parameter type creation FAILED");
     95      ex.printStackTrace();
    9596    }
    9697   
     
    131132          IntegerParameterValueData intValue = new IntegerParameterValueData();
    132133          intValue.getValues().add(100);
    133           param.validateParameterValues(intValue.getValues());
     134          param.validate(intValue.getValues());
    134135          param.validate(new Integer(-234));
    135136         
     
    197198        }
    198199      }
    199       write("++Testing parameter type validation OK");
     200      write("--Testing parameter type validation OK");
    200201    }
    201202    catch (Throwable ex)
    202203    {
    203204      ok = false;
    204       write("++Testing parameter type validation FAILED");
     205      write("--Testing parameter type validation FAILED");
    205206      ex.printStackTrace();
    206207    }
  • trunk/src/test/TestReporterMapImport.java

    r1138 r1180  
    138138     
    139139     
    140       pr.setParameterValue("arrayDesign", new ItemParameterValueData<ArrayDesign>(ad));
    141       pr.setParameterValue("file", new ItemParameterValueData<File>(f));
     140      pr.setParameterValue("arrayDesign", null); // ad);
     141      pr.setParameterValue("file", null); //f);
    142142      if (reportertype_id != 0)
    143143      {
    144144        ReporterType rt = ReporterType.getById(dc, reportertype_id);
    145         pr.setParameterValue("reporterType", new ItemParameterValueData<ReporterType>(rt));
     145        pr.setParameterValue("reporterType", null); // rt);
    146146      }
    147147      try
  • trunk/src/test/TestSpotImages.java

    r1143 r1180  
    103103      time = System.currentTimeMillis();
    104104      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);
    106107      dc.commit();
    107108      time = System.currentTimeMillis()-time;
     
    274275    System.out.println(message);
    275276  }
     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  }
    276291}
    277292
Note: See TracChangeset for help on using the changeset viewer.