Yes, there is plenty more to do. I've tried to fill out more issues
in the projects issue tracker:
http://code.google.com/p/cropplanning/issues/list
Are you comfortable with SQL? There are a couple of SQL issues that
need some help.
Clayton
C
package CPS.Module;
import CPS.Data.CPSCrop;
import CPS.Data.CPSPlanting;
import java.util.ArrayList;
/**
* A simple interface for classes that provide the capabilty to import
* data to the file system.
*/
public interface CPSImporter {
public ArrayList<CPSCrop> importCropsAndVarieties( String filename );
public ArrayList<CPSPlanting> importCropPlan( String filename );
public String getImportFileDefaultExtension();
}
1. Importing crop and varieties worked great; good work!
2. Plantings not so much. How did you go about testing this? It
looks like the code for importing is running OK, but I get lots of
errors when I take the list of imported plantings and try to create
each of them in the DB. Did you get that to work? It looks like
there's a combination of bad design (on my part) and insufficitent
type checking (on your part). It looks like you're saving everything
to the planting objects as Strings (insufficient type checking) and
the abstract type/prototype system I was using isn't catching this
(bad design).
I would suggest you alter the setPlanting() method w/ a CASE statement
that groups INDEXes by type (booleans and dates at least) and then
does some further processing of these so that the value that's saved
using the set(...) method is correct for that property number. For
example:
switch ( INDEX ) {
case PROP_DATE_PLANT:
case PROP_DATE_TP:
case ....:
// parse the date into a Date object and then pass the Date object to set()
case PROP_DONE_PLANT:
case PROP_DONE_TP:
case DIRECT_SEED:
// parse the boolean value into a Boolean object ....
Shouldn't be a huge pain.
3. When you catch Exceptions or print error message, please make you
error messages a bit clearer than simply "wrong". A very simple way
is to just catch the exception and print a stack trace (via the
printStackTrace() method); that at least gives us information about
what went wrong.
But, like I said, importing Crops and Vars worked perfectly. Thanks again!
Clayton
C
My suggestion was not a giant switch statement like how you first
implemented the code. Rather, I was just suggesting that you use the
switch to catch the properties whose types you know. This is what I
meant:
private void setPlanting(CPSPlanting plant,final int INDEX,String value)
{
switch ( INDEX ) {
case CPSDataModelConstants.PROP_DATE_PLANT:
case CPSDataModelConstants.PROP_DATE_TP:
case CPSDataModelConstants.PROP_DATE_HARVEST:
plant.set( INDEX, CPSDateValidator.simpleParse( value ) );
return;
case CPSDataModelConstants.PROP_DONE_PLANTING:
case CPSDataModelConstants.PROP_DONE_TP:
case CPSDataModelConstants.PROP_DONE_HARVEST:
case CPSDataModelConstants.PROP_DIRECT_SEED:
case CPSDataModelConstants.PROP_FROST_HARDY:
plant.set( INDEX, new Boolean( value ));
return;
default:
plant.set(INDEX,value);
return;
}
}
I made the change. Please let me know what you think.
Clayton
private void setPlanting(CPSPlanting plant,final int INDEX,String value)
{
switch ( INDEX ) {
case CPSDataModelConstants.PROP_DATE_PLANT:
case CPSDataModelConstants.PROP_DATE_TP:
case CPSDataModelConstants.PROP_DATE_HARVEST:
plant.set( INDEX, CPSDateValidator.simpleParse( value ) );
return;
This debate about switches and such is interesting and I'm not sure
where to go with it. For instance, the way the code is written, we
don't technically NEED to have any of the "case"s for types other than
Date()s. Everything else seems to just work. (So we would only need
the "case" statements for Dates and all of the rest could be caught by
the "default".) So, the question is, do we rely on this and use
simpler, cleaner code, or should we do as you have done above and
prepare more complete and robust, though less clean and attractive,
code.
Any thoughts?
Clayton
I have putback sm_zl_kimi's code adding CSV import. I have done some
very quick testing and it appears to work. The only issues I noted
looked like they were more of an issue w/ export than with import.
If anyone has tried to checkout and use the code recently, they will
have gotten a ClassNotFound exception at runtime. This putback should
fix that.
Clayton
C