Author: kmorin Date: 2014-01-23 12:10:59 +0100 (Thu, 23 Jan 2014) New Revision: 20 Url: http://forge.codelutin.com/projects/wlo/repository/revisions/20 Log: fixes #3082 Formulaire de cr?\195?\169ation d'une esp?\195?\168ce commerciale refs #4175 Formulaire de cr?\195?\169ation d'un navire Modified: trunk/res/layout/commercial_species_form.xml trunk/res/layout/vessel_form.xml trunk/res/values-fr/strings.xml trunk/res/values/strings.xml trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java trunk/src/fr/ifremer/wlo/VesselFormActivity.java trunk/src/fr/ifremer/wlo/VesselsActivity.java trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java trunk/src/fr/ifremer/wlo/models/CommercialSpeciesModel.java trunk/src/fr/ifremer/wlo/models/VesselModel.java trunk/src/fr/ifremer/wlo/models/referentials/Mensuration.java trunk/src/fr/ifremer/wlo/storage/DataCache.java trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java Modified: trunk/res/layout/commercial_species_form.xml =================================================================== --- trunk/res/layout/commercial_species_form.xml 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/res/layout/commercial_species_form.xml 2014-01-23 11:10:59 UTC (rev 20) @@ -37,6 +37,32 @@ android:singleLine="true" android:hint="@string/undefined"/> + <TextView android:text="@string/commercial_species_form_precision" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + + <Spinner android:id="@+id/commercial_species_form_precision" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:singleLine="true" + android:hint="@string/undefined"/> + + <CheckBox android:id="@+id/commercial_species_form_species_mix" + android:text="@string/commercial_species_form_species_mix" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + + <TextView android:text="@string/commercial_species_form_sortCategory" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + + <fr.ifremer.wlo.utils.WloAutoCompleteTextView + android:id="@+id/commercial_species_form_sortCategory" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:singleLine="true" + android:hint="@string/undefined"/> + <TextView android:text="@string/commercial_species_form_state" android:layout_width="match_parent" android:layout_height="wrap_content"/> @@ -59,11 +85,6 @@ android:singleLine="true" android:hint="@string/undefined"/> - <CheckBox android:id="@+id/commercial_species_form_species_mix" - android:text="@string/commercial_species_form_species_mix" - android:layout_width="match_parent" - android:layout_height="wrap_content"/> - </LinearLayout> </ScrollView> Modified: trunk/res/layout/vessel_form.xml =================================================================== --- trunk/res/layout/vessel_form.xml 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/res/layout/vessel_form.xml 2014-01-23 11:10:59 UTC (rev 20) @@ -52,11 +52,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content"/> - <EditText android:id="@+id/vessel_form_landing_location" - android:hint="@string/undefined" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:singleLine="true"/> + <fr.ifremer.wlo.utils.WloAutoCompleteTextView + android:id="@+id/vessel_form_landing_location" + android:hint="@string/undefined" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:singleLine="true"/> </LinearLayout> Modified: trunk/res/values/strings.xml =================================================================== --- trunk/res/values/strings.xml 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/res/values/strings.xml 2014-01-23 11:10:59 UTC (rev 20) @@ -130,9 +130,11 @@ <string name="commercial_species_form_fao_code">FAO code</string> <string name="commercial_species_form_name">Name</string> <string name="commercial_species_form_measurement_method">Measurement method</string> + <string name="commercial_species_form_precision">Precision</string> <string name="commercial_species_form_species_mix">Species mix</string> <string name="commercial_species_form_state">State</string> <string name="commercial_species_form_presentation">Presentation</string> + <string name="commercial_species_form_sortCategory">Sort category</string> <string name="commercial_species_title">Commercial species</string> <string name="commercial_species_subtitle">Metier %s</string> <string name="add_commercial_species">Create a new commercial species</string> Modified: trunk/res/values-fr/strings.xml =================================================================== --- trunk/res/values-fr/strings.xml 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/res/values-fr/strings.xml 2014-01-23 11:10:59 UTC (rev 20) @@ -125,9 +125,11 @@ <string name="commercial_species_form_fao_code">Code FAO</string> <string name="commercial_species_form_name">Nom</string> <string name="commercial_species_form_measurement_method">Méthode de mensuration</string> + <string name="commercial_species_form_precision">Précision</string> <string name="commercial_species_form_species_mix">Mélange d\'espèces</string> <string name="commercial_species_form_state">État</string> <string name="commercial_species_form_presentation">Présentation</string> + <string name="commercial_species_form_sortCategory">Catégorie de tri</string> <string name="commercial_species_title">Espèces commerciales</string> <string name="commercial_species_subtitle">Métier %s</string> <string name="add_commercial_species">Créer une nouvelle espèce commerciale</string> Modified: trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/CommercialSpeciesFormActivity.java 2014-01-23 11:10:59 UTC (rev 20) @@ -2,7 +2,10 @@ import android.os.Bundle; import android.util.Log; +import android.view.View; +import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.Spinner; @@ -16,6 +19,7 @@ import fr.ifremer.wlo.storage.WloSqlOpenHelper; import java.util.List; +import java.util.Set; /** * @author kmorin <kmorin@codelutin.com> @@ -56,9 +60,32 @@ List<CommercialSpecies> commercialSpecies = Lists.newArrayList(DataCache.getAllCommercialSpecies(this)); initAutoCompleteTextView(R.id.commercial_species_form_fao_code, CommercialSpeciesModel.COLUMN_FAO_CODE, commercialSpecies); + if (model.getMeasurementMethod() == null) { + Mensuration defaultMensuration = DataCache.getDefaultMensuration(this); + model.setMeasurementMethod(defaultMensuration); + } List<Mensuration> mensurations = Lists.newArrayList(DataCache.getAllMensurations(this)); initAutoCompleteTextView(R.id.commercial_species_form_measurement_method, CommercialSpeciesModel.COLUMN_MEASUREMENT_METHOD, mensurations); + Spinner precisionSpinner = (Spinner) findViewById(R.id.commercial_species_form_precision); + ArrayAdapter<Mensuration.Precision> precisions = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, + Mensuration.Precision.values()); + precisionSpinner.setAdapter(precisions); + precisionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { + model.setPrecision((Mensuration.Precision) adapterView.getItemAtPosition(i)); + } + + @Override + public void onNothingSelected(AdapterView<?> adapterView) { + model.setPrecision(null); + } + }); + + Set<String> sortCategories = DataCache.getAllSortCategories(this); + initAutoCompleteTextView(R.id.commercial_species_form_sortCategory, CommercialSpeciesModel.COLUMN_SORT_CATEGORY, sortCategories); + List<State> states = Lists.newArrayList(DataCache.getAllStates(this)); initAutoCompleteTextView(R.id.commercial_species_form_state, CommercialSpeciesModel.COLUMN_STATE, states); @@ -70,12 +97,15 @@ speciesMixEditor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { - Log.d(TAG, "b : " + b + ", checked : " + compoundButton.isChecked()); model.setSpeciesMix(b); } }); } - + @Override + protected void saveModel() { + super.saveModel(); + DataCache.invalidateSortCategories(); + } } Modified: trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/ScientificSpeciesActivity.java 2014-01-23 11:10:59 UTC (rev 20) @@ -4,10 +4,13 @@ import android.database.Cursor; import android.support.v4.widget.SimpleCursorAdapter; import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; import android.view.View; import android.widget.ListView; import com.google.common.collect.Maps; import fr.ifremer.wlo.measurement.MeasurementActivity; +import fr.ifremer.wlo.models.CommercialSpeciesModel; import fr.ifremer.wlo.models.ScientificSpeciesModel; import fr.ifremer.wlo.utils.WloItemListViewBinder; @@ -29,6 +32,16 @@ } @Override + public boolean onCreateOptionsMenu(Menu menu) { + CommercialSpeciesModel parent = (CommercialSpeciesModel) parentModel; + if (parent.isSpeciesMix() || adapter.getCount() == 0) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.model_list_menu, menu); + } + return true; + } + + @Override protected Cursor getAllData() { Cursor cursor = woh.getAllScientificSpecies(parentModel.getId()); return cursor; Modified: trunk/src/fr/ifremer/wlo/VesselFormActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/VesselFormActivity.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/VesselFormActivity.java 2014-01-23 11:10:59 UTC (rev 20) @@ -65,8 +65,10 @@ initAutoCompleteTextView(R.id.vessel_form_registration_number, VesselModel.COLUMN_REGISTRATION_NUMBER, vesselCodes); initEditText(R.id.vessel_form_name, VesselModel.COLUMN_NAME); - initEditText(R.id.vessel_form_landing_location, VesselModel.COLUMN_LANDING_LOCATION); + List<Location> locations = Lists.newArrayList(DataCache.getAllLocations(this)); + initAutoCompleteTextView(R.id.vessel_form_landing_location, VesselModel.COLUMN_LANDING_LOCATION, locations); + EditText landingDateEditor = (EditText) findViewById(R.id.vessel_form_landing_date); // landing date Calendar landingDate = model.getLandingDate(); Modified: trunk/src/fr/ifremer/wlo/VesselsActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/VesselsActivity.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/VesselsActivity.java 2014-01-23 11:10:59 UTC (rev 20) @@ -29,7 +29,7 @@ @Override protected VesselModel createNewModel(Cursor cursor) { - return new VesselModel(cursor); + return new VesselModel(this, cursor); } @Override Modified: trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java =================================================================== --- trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/WloModelEditionActivity.java 2014-01-23 11:10:59 UTC (rev 20) @@ -13,6 +13,7 @@ import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.EditText; +import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import fr.ifremer.wlo.models.BaseModel; import fr.ifremer.wlo.models.HierarchicalModel; @@ -204,17 +205,18 @@ }); } - protected <R> void initAutoCompleteTextView(int autoCompleteTextViewId, final String attribute, List<R> data) { + protected <R> AutoCompleteTextView initAutoCompleteTextView(int autoCompleteTextViewId, final String attribute, Collection<R> data) { AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(autoCompleteTextViewId); initAutoCompleteTextView(autoCompleteTextView, attribute, data); + return autoCompleteTextView; } - protected <R> void initAutoCompleteTextView(AutoCompleteTextView autoCompleteTextView, final String attribute, List<R> data) { + protected <R> void initAutoCompleteTextView(AutoCompleteTextView autoCompleteTextView, final String attribute, Collection<R> data) { final Class clazz = model.getClass(); final String firtsLetterUpperCaseAttribute = attribute.substring(0, 1).toUpperCase() + attribute.substring(1); - ArrayAdapter<R> adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, data); + ArrayAdapter<R> adapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, Lists.newArrayList(data)); autoCompleteTextView.setAdapter(adapter); autoCompleteTextView.setThreshold(0); Modified: trunk/src/fr/ifremer/wlo/models/CommercialSpeciesModel.java =================================================================== --- trunk/src/fr/ifremer/wlo/models/CommercialSpeciesModel.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/models/CommercialSpeciesModel.java 2014-01-23 11:10:59 UTC (rev 20) @@ -11,6 +11,8 @@ import fr.ifremer.wlo.storage.DataCache; import fr.ifremer.wlo.utils.UIUtils; +import java.util.Set; + /** * @author kmorin <kmorin@codelutin.com> * @since 0.1 @@ -22,25 +24,31 @@ public static final String TABLE_NAME = "commercial_species"; public static final String COLUMN_FAO_CODE = "faoCode"; public static final String COLUMN_MEASUREMENT_METHOD = "measurementMethod"; + public static final String COLUMN_PRECISION = "precision"; + public static final String COLUMN_SPECIES_MIX = "speciesMix"; + public static final String COLUMN_SORT_CATEGORY = "sortCategory"; public static final String COLUMN_STATE = "state"; public static final String COLUMN_PRESENTATION = "presentation"; - public static final String COLUMN_SPECIES_MIX = "speciesMix"; public static final String COLUMN_METIER_ID = "metierId"; public static final String[] ALL_COLUMNS = new String[] { _ID, COLUMN_FAO_CODE, COLUMN_MEASUREMENT_METHOD, + COLUMN_PRECISION, + COLUMN_SPECIES_MIX, + COLUMN_SORT_CATEGORY, COLUMN_STATE, COLUMN_PRESENTATION, - COLUMN_SPECIES_MIX, COLUMN_METIER_ID }; protected CommercialSpecies faoCode; protected Mensuration measurementMethod; + protected Mensuration.Precision precision = Mensuration.Precision.CM1; + protected boolean speciesMix; + protected String sortCategory; protected State state; protected Presentation presentation; - protected boolean speciesMix; public CommercialSpeciesModel() { } @@ -51,11 +59,13 @@ faoCode = DataCache.getCommercialSpeciesById(context, faoCodeId); String measurementMethodId = cursor.getString(2); measurementMethod = DataCache.getMensurationById(context, measurementMethodId); - String stateId = cursor.getString(3); + precision = Mensuration.Precision.valueOf(cursor.getString(3)); + speciesMix = cursor.getShort(4) > 0; + sortCategory = cursor.getString(5); + String stateId = cursor.getString(6); state = DataCache.getStateById(context, stateId); - String presentationId = cursor.getString(4); + String presentationId = cursor.getString(7); presentation = DataCache.getPresentationById(context, presentationId); - speciesMix = cursor.getShort(5) > 0; } public CommercialSpecies getFaoCode() { @@ -74,6 +84,30 @@ this.measurementMethod = measurementMethod; } + public Mensuration.Precision getPrecision() { + return precision; + } + + public void setPrecision(Mensuration.Precision precision) { + this.precision = precision; + } + + public boolean isSpeciesMix() { + return speciesMix; + } + + public void setSpeciesMix(boolean speciesMix) { + this.speciesMix = speciesMix; + } + + public String getSortCategory() { + return sortCategory; + } + + public void setSortCategory(String sortCategory) { + this.sortCategory = sortCategory; + } + public State getState() { return state; } @@ -90,14 +124,6 @@ this.presentation = presentation; } - public boolean isSpeciesMix() { - return speciesMix; - } - - public void setSpeciesMix(boolean speciesMix) { - this.speciesMix = speciesMix; - } - @Override public String getTableName() { return TABLE_NAME; @@ -113,10 +139,21 @@ ContentValues value = super.convertIntoContentValues(); putValue(value, COLUMN_FAO_CODE, faoCode != null ? faoCode.getId() : null); putValue(value, COLUMN_MEASUREMENT_METHOD, measurementMethod != null ? measurementMethod.getId() : null); + putValue(value, COLUMN_PRECISION, precision.name()); + putValue(value, COLUMN_SPECIES_MIX, speciesMix ? 1 : 0); + putValue(value, COLUMN_SORT_CATEGORY, sortCategory); putValue(value, COLUMN_STATE, state != null ? state.getId() : null); putValue(value, COLUMN_PRESENTATION, presentation != null ? presentation.getId() : null); - putValue(value, COLUMN_SPECIES_MIX, speciesMix ? 1 : 0); putValue(value, COLUMN_METIER_ID, getParentId()); return value; } + + @Override + public Set<String> getRequiredFields() { + Set<String> result = super.getRequiredFields(); + result.add(COLUMN_FAO_CODE); + result.add(COLUMN_MEASUREMENT_METHOD); + result.add(COLUMN_PRECISION); + return result; + } } Modified: trunk/src/fr/ifremer/wlo/models/VesselModel.java =================================================================== --- trunk/src/fr/ifremer/wlo/models/VesselModel.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/models/VesselModel.java 2014-01-23 11:10:59 UTC (rev 20) @@ -1,8 +1,11 @@ package fr.ifremer.wlo.models; import android.content.ContentValues; +import android.content.Context; import android.database.Cursor; import android.util.Log; +import fr.ifremer.wlo.models.referentials.Location; +import fr.ifremer.wlo.storage.DataCache; import fr.ifremer.wlo.utils.UIUtils; import java.util.Calendar; @@ -33,17 +36,18 @@ protected String registrationNumber; protected String name; protected Calendar landingDate; - protected String landingLocation; + protected Location landingLocation; public VesselModel() { } - public VesselModel(Cursor cursor) { + public VesselModel(Context context, Cursor cursor) { super(cursor); registrationNumber = cursor.getString(1); name = cursor.getString(2); landingDate = UIUtils.getCalendarFromCursor(cursor, 3); - landingLocation = cursor.getString(4); + String landingLocationId = cursor.getString(4); + landingLocation = DataCache.getLocationById(context, landingLocationId); } public String getRegistrationNumber() { @@ -74,11 +78,11 @@ this.landingDate = landingDate; } - public String getLandingLocation() { + public Location getLandingLocation() { return landingLocation; } - public void setLandingLocation(String landingLocation) { + public void setLandingLocation(Location landingLocation) { this.landingLocation = landingLocation; } @@ -99,7 +103,7 @@ putValue(value, COLUMN_REGISTRATION_NUMBER, registrationNumber); putValue(value, COLUMN_NAME, name); putValue(value, COLUMN_LANDING_DATE, landingDate != null ? landingDate.getTimeInMillis() : null); - putValue(value, COLUMN_LANDING_LOCATION, landingLocation); + putValue(value, COLUMN_LANDING_LOCATION, landingLocation != null ? landingLocation.getId() : null); putValue(value, COLUMN_LOCATION_ID, getParentId()); return value; } Modified: trunk/src/fr/ifremer/wlo/models/referentials/Mensuration.java =================================================================== --- trunk/src/fr/ifremer/wlo/models/referentials/Mensuration.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/models/referentials/Mensuration.java 2014-01-23 11:10:59 UTC (rev 20) @@ -13,6 +13,27 @@ private static final String TAG = "Mensuration"; + public enum Precision { + CM1("1 cm"), + MM5("0.5 cm"), + MM1("1 mm"); + + private String label; + + private Precision(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + + @Override + public String toString() { + return label; + } + } + public static final String TABLE_NAME = "ref_mensurations"; public static final String COLUMN_CODE = "code"; public static final String COLUMN_LABEL = "label"; Modified: trunk/src/fr/ifremer/wlo/storage/DataCache.java =================================================================== --- trunk/src/fr/ifremer/wlo/storage/DataCache.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/storage/DataCache.java 2014-01-23 11:10:59 UTC (rev 20) @@ -6,6 +6,7 @@ import com.google.common.collect.HashBasedTable; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.common.collect.Table; import fr.ifremer.wlo.models.BaseModel; import fr.ifremer.wlo.models.referentials.Age; @@ -27,6 +28,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Set; /** * @author kmorin <kmorin@codelutin.com> @@ -34,17 +36,21 @@ */ public class DataCache { + public static final String DEFAULT_MENSURATION_CODE = "LT"; + protected static Map<String, Age> ages; protected static Map<String, CommercialSpecies> commercialSpecies; protected static Map<String, Gender> genders; protected static Map<String, Location> locations; protected static Map<String, Maturity> maturities; protected static Map<String, Mensuration> mensurations; + protected static Mensuration defaultMensuration; protected static Map<String, Metier> metiers; protected static Map<String, Presentation> presentations; protected static Map<String, ScientificSpecies> scientificSpecies; protected static Map<String, State> states; protected static Map<String, Vessel> vessels; + protected static Set<String> sortCategories; public static Collection<Age> getAllAges(Context context) { initAges(context); @@ -126,10 +132,19 @@ } public static Mensuration getMensurationById(Context context, String id) { - initGenders(context); + initMensurations(context); return mensurations.get(id); } + public static Mensuration getDefaultMensuration(Context context) { + if (defaultMensuration == null) { + initMensurations(context); + Map<String, Mensuration> mensurationsByCode = Maps.uniqueIndex(mensurations.values(), HasCode.GET_CODE_FUNCTION); + defaultMensuration = mensurationsByCode.get(DEFAULT_MENSURATION_CODE); + } + return defaultMensuration; + } + public static void invalidateMensurations() { mensurations = null; } @@ -182,6 +197,15 @@ scientificSpecies = null; } + public static Set<String> getAllSortCategories(Context context) { + initSortCategories(context); + return sortCategories; + } + + public static void invalidateSortCategories() { + sortCategories = null; + } + public static Collection<State> getAllStates(Context context) { initStates(context); List<State> result = Lists.newArrayList(states.values()); @@ -398,4 +422,20 @@ } } + protected static void initSortCategories(Context context) { + if (sortCategories == null) { + WloSqlOpenHelper soh = new WloSqlOpenHelper(context); + Cursor cursor = soh.getAllSortCategories(); + List<String> sc = WloSqlOpenHelper.transformCursorIntoCollection(cursor, + new Function<Cursor, String>() { + @Override + public String apply(Cursor cursor) { + return cursor.getString(0); + } + }); + sortCategories = Sets.newHashSet(sc); + soh.close(); + } + } + } Modified: trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java =================================================================== --- trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java 2014-01-23 09:26:45 UTC (rev 19) +++ trunk/src/fr/ifremer/wlo/storage/WloSqlOpenHelper.java 2014-01-23 11:10:59 UTC (rev 20) @@ -7,6 +7,7 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import fr.ifremer.wlo.models.BaseModel; import fr.ifremer.wlo.models.CommercialSpeciesModel; import fr.ifremer.wlo.models.ContextModel; @@ -27,6 +28,7 @@ import fr.ifremer.wlo.models.referentials.Vessel; import java.util.List; +import java.util.Set; import java.util.UUID; /** @@ -38,7 +40,7 @@ private static final String TAG = "WloOpenHelper"; public static final String DATABASE_NAME = "wlo.db"; - public static final int DATABASE_VERSION = 8; + public static final int DATABASE_VERSION = 9; public static final String TEXT_TYPE = " TEXT"; public static final String BIGINT_TYPE = " BIGINT"; @@ -46,8 +48,6 @@ public static final String COMMA_SEP = ","; public static final String NOT_NULL = " NOT NULL"; - //TODO foreign keys to referentials - //CONTEXT protected static final String SQL_CREATE_CONTEXTS = "CREATE TABLE " + ContextModel.TABLE_NAME + " (" + @@ -69,7 +69,9 @@ LocationModel.COLUMN_LOCATION + TEXT_TYPE + NOT_NULL + COMMA_SEP + LocationModel.COLUMN_CONTEXT_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP + "FOREIGN KEY(" + LocationModel.COLUMN_CONTEXT_ID + ") REFERENCES " + - ContextModel.TABLE_NAME + "(" + ContextModel._ID + ")" + + ContextModel.TABLE_NAME + "(" + ContextModel._ID + ")" + COMMA_SEP + + "FOREIGN KEY(" + LocationModel.COLUMN_LOCATION + ") REFERENCES " + + Location.TABLE_NAME + "(" + Location._ID + ")" + " )"; protected static final String SQL_DELETE_LOCATIONS = @@ -85,7 +87,9 @@ VesselModel.COLUMN_LANDING_LOCATION + TEXT_TYPE + COMMA_SEP + VesselModel.COLUMN_LOCATION_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP + "FOREIGN KEY(" + VesselModel.COLUMN_LOCATION_ID + ") REFERENCES " + - LocationModel.TABLE_NAME + "(" + LocationModel._ID + ")" + + LocationModel.TABLE_NAME + "(" + LocationModel._ID + ")" + COMMA_SEP + + "FOREIGN KEY(" + VesselModel.COLUMN_LANDING_LOCATION + ") REFERENCES " + + Location.TABLE_NAME + "(" + Location._ID + ")" + " )"; protected static final String SQL_DELETE_VESSELS = @@ -100,7 +104,9 @@ MetierModel.COLUMN_SAMPLE_ROW_CODE + TEXT_TYPE + COMMA_SEP + MetierModel.COLUMN_VESSEL_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP + "FOREIGN KEY(" + MetierModel.COLUMN_VESSEL_ID + ") REFERENCES " + - VesselModel.TABLE_NAME + "(" + VesselModel._ID + ")" + + VesselModel.TABLE_NAME + "(" + VesselModel._ID + ")" + COMMA_SEP + + "FOREIGN KEY(" + MetierModel.COLUMN_GEAR_SPECIES + ") REFERENCES " + + Metier.TABLE_NAME + "(" + Metier._ID + ")" + " )"; protected static final String SQL_DELETE_METIERS = @@ -112,12 +118,22 @@ CommercialSpeciesModel._ID + TEXT_TYPE + " PRIMARY KEY" + COMMA_SEP + CommercialSpeciesModel.COLUMN_FAO_CODE + TEXT_TYPE + COMMA_SEP + CommercialSpeciesModel.COLUMN_MEASUREMENT_METHOD + TEXT_TYPE + COMMA_SEP + + CommercialSpeciesModel.COLUMN_PRECISION + TEXT_TYPE + COMMA_SEP + + CommercialSpeciesModel.COLUMN_SPECIES_MIX + BYTE_TYPE + COMMA_SEP + + CommercialSpeciesModel.COLUMN_SORT_CATEGORY + TEXT_TYPE + COMMA_SEP + CommercialSpeciesModel.COLUMN_STATE + TEXT_TYPE + COMMA_SEP + CommercialSpeciesModel.COLUMN_PRESENTATION + TEXT_TYPE + COMMA_SEP + - CommercialSpeciesModel.COLUMN_SPECIES_MIX + BYTE_TYPE + COMMA_SEP + CommercialSpeciesModel.COLUMN_METIER_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP + "FOREIGN KEY(" + CommercialSpeciesModel.COLUMN_METIER_ID + ") REFERENCES " + - MetierModel.TABLE_NAME + "(" + MetierModel._ID + ")" + + MetierModel.TABLE_NAME + "(" + MetierModel._ID + ")" + COMMA_SEP + + "FOREIGN KEY(" + CommercialSpeciesModel.COLUMN_FAO_CODE + ") REFERENCES " + + CommercialSpecies.TABLE_NAME + "(" + CommercialSpecies._ID + ")" + COMMA_SEP + + "FOREIGN KEY(" + CommercialSpeciesModel.COLUMN_MEASUREMENT_METHOD + ") REFERENCES " + + Mensuration.TABLE_NAME + "(" + Mensuration._ID + ")" + COMMA_SEP + + "FOREIGN KEY(" + CommercialSpeciesModel.COLUMN_STATE + ") REFERENCES " + + State.TABLE_NAME + "(" + State._ID + ")" + COMMA_SEP + + "FOREIGN KEY(" + CommercialSpeciesModel.COLUMN_PRESENTATION + ") REFERENCES " + + Presentation.TABLE_NAME + "(" + Presentation._ID + ")" + " )"; protected static final String SQL_DELETE_COMMERCIAL_SPECIES = @@ -131,7 +147,9 @@ ScientificSpeciesModel.COLUMN_TAKING_ACTIVATION + BYTE_TYPE + COMMA_SEP + ScientificSpeciesModel.COLUMN_COMMERCIAL_SPECIES_ID + TEXT_TYPE + NOT_NULL + COMMA_SEP + "FOREIGN KEY(" + ScientificSpeciesModel.COLUMN_COMMERCIAL_SPECIES_ID + ") REFERENCES " + - CommercialSpeciesModel.TABLE_NAME + "(" + CommercialSpeciesModel._ID + ")" + + CommercialSpeciesModel.TABLE_NAME + "(" + CommercialSpeciesModel._ID + ")" + COMMA_SEP + + "FOREIGN KEY(" + ScientificSpeciesModel.COLUMN_NAME + ") REFERENCES " + + ScientificSpecies.TABLE_NAME + "(" + ScientificSpecies._ID + ")" + " )"; protected static final String SQL_DELETE_SCIENTIFIC_SPECIES = @@ -390,6 +408,13 @@ return cursor; } + public Cursor getAllSortCategories() { + SQLiteDatabase db = getReadableDatabase(); + Cursor cursor = db.query(CommercialSpeciesModel.TABLE_NAME, new String[]{ CommercialSpeciesModel.COLUMN_SORT_CATEGORY }, + null, null, null, null, null); + return cursor; + } + //SCIENTIFIC SPECIES public Cursor getAllScientificSpecies(String commercialSpeciesId) { @@ -537,8 +562,8 @@ List<E> result = Lists.newArrayList(); boolean cont = cursor.moveToFirst(); while (cont) { - E gender = function.apply(cursor); - result.add(gender); + E e = function.apply(cursor); + result.add(e); cont = cursor.moveToNext(); } return result;