Author: bleny Date: 2010-12-30 16:38:52 +0000 (Thu, 30 Dec 2010) New Revision: 872 Log: enable import/export for obsvente sampling plan Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/WaoCsvHeader.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java trunk/wao-business/src/test/resources/import/echantillonnage.csv Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/WaoCsvHeader.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/WaoCsvHeader.java 2010-12-30 16:06:30 UTC (rev 871) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/WaoCsvHeader.java 2010-12-30 16:38:52 UTC (rev 872) @@ -66,7 +66,7 @@ * used will be the same returned by datePattern * * @param date the date to be formatted - * @return + * @return the formatted date */ String format(Date date); } @@ -197,7 +197,8 @@ /** SampleRow average tide time **/ PLAN_DUREE_MOY(15, "Durée moyenne d'une marée (jours)"), /** SampleRow comment **/ - PLAN_COMMENT(17, "Commentaire"); + PLAN_COMMENT(17, "Commentaire"), + PLAN_STRATEGIE(18, "Stratégie d'échantillonage"); private int contactHeader; @@ -396,7 +397,7 @@ } public static String formatValidation(Boolean validation) { - String valid = ""; + String valid; if (validation == null) { valid = "N"; } else if (BooleanUtils.isTrue(validation)) { @@ -448,7 +449,7 @@ /** ActivityZone zoneId **/ TSECT_COD, /** ActivityZone zoneLibelle **/ - SECT_LIB; + SECT_LIB } public static String getHeaderForContactCsv(int index) { Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-12-30 16:06:30 UTC (rev 871) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-12-30 16:38:52 UTC (rev 872) @@ -35,11 +35,7 @@ import fr.ifremer.wao.WaoProperty; import fr.ifremer.wao.WaoQueryBuilder; import fr.ifremer.wao.WaoQueryHelper; -import fr.ifremer.wao.bean.ConnectedUser; -import fr.ifremer.wao.bean.FacadeRow; -import fr.ifremer.wao.bean.FacadeRowImpl; -import fr.ifremer.wao.bean.SamplingFilter; -import fr.ifremer.wao.bean.UserRole; +import fr.ifremer.wao.bean.*; import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.CompanyDAO; @@ -852,6 +848,7 @@ export.record(SAMPLING.PLAN_NB_OBSERV, numberFormat.format(row.getNbObservants())); export.record(SAMPLING.PLAN_DUREE_MOY, numberFormat.format(row.getAverageTideTime())); export.record(SAMPLING.PLAN_COMMENT, String.valueOf(row.getComment())); + export.record(SAMPLING.PLAN_STRATEGIE, row.getSamplingStrategy().name()); export.recordMonths(row); @@ -1072,9 +1069,14 @@ String comment = ImportHelper.read(reader, SAMPLING.PLAN_COMMENT); PeriodDates period = ImportHelper.readPeriod(reader, SAMPLING.PROGRAMME_DEBUT, SAMPLING.PROGRAMME_FIN); - String codeDCF5 = ImportHelper.read(reader, SAMPLING.METIER_CODE_DCF5); - codeDCF5 = codeDCF5.trim(); + + String samplingStrategyName = ImportHelper.read(reader, SAMPLING.PLAN_STRATEGIE); + if (StringUtils.isNotBlank(samplingStrategyName)) { + SamplingStrategy samplingStrategy = SamplingStrategy.valueOf(samplingStrategyName); + sampleRow.setSamplingStrategy(samplingStrategy); + } + sampleRow.setFishingZonesInfos(fishingZoneInfos); sampleRow.setNbObservants(nbObservants); sampleRow.setAverageTideTime(averageTideTime); @@ -1083,6 +1085,8 @@ sampleRow.setPeriodEnd(period.getThruDate()); sampleRow.setComment(comment); + String codeDCF5 = ImportHelper.read(reader, SAMPLING.METIER_CODE_DCF5); + codeDCF5 = codeDCF5.trim(); // a trick, nullSampleRow is just intantiated to user the parsing // of the codes in the CSV. This trick is needed cause if we use // sampleRow to do the parsing, parsed objects will be linked to @@ -1100,8 +1104,10 @@ sampleRow.addAllDCF5Code(parsed); // sampleRow.setDCF5Code(parsed); works fine too - // 16 fixed columns : 13 before months and 3 after - int nbFixedColumns = 16; + + + // 16 fixed columns : 13 before months and 4 after + int nbFixedColumns = 17; // Months begin at 14th column int firstMonthColumnId = 13; int nbTotalColumns = reader.getColumnCount(); Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2010-12-30 16:06:30 UTC (rev 871) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2010-12-30 16:38:52 UTC (rev 872) @@ -31,6 +31,7 @@ import fr.ifremer.wao.bean.FacadeRow; import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.bean.SamplingFilterImpl; +import fr.ifremer.wao.bean.SamplingStrategy; import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.CompanyDAO; @@ -613,6 +614,8 @@ Collection<DCF5Code> dcf5codes = row1.getDCF5Code(); assertEquals(1, dcf5codes.size()); + assertEquals(row1.getSamplingStrategy(), SamplingStrategy.SIMULTANEOUS_ALL_SPECIES); + transaction.closeContext(); } Modified: trunk/wao-business/src/test/resources/import/echantillonnage.csv =================================================================== --- trunk/wao-business/src/test/resources/import/echantillonnage.csv 2010-12-30 16:06:30 UTC (rev 871) +++ trunk/wao-business/src/test/resources/import/echantillonnage.csv 2010-12-30 16:38:52 UTC (rev 872) @@ -1,14 +1,14 @@ -"PLAN_CODE","SOCIETE_NOM","PECHE_DIVISION","PECHE_AUTRE","METIER_CODE_DCF5","METIER_MAILLAGE","METIER_TAILLE","METIER_AUTRE","METIER_LIBELLE","METIER_ESPECES","PROGRAMME_CODE","PROGRAMME_DEBUT","PROGRAMME_FIN",12/2009,01/2010,02/2010,03/2010,04/2010,05/2010,06/2010,07/2010,08/2010,09/2010,10/2010,11/2010,12/2010,01/2011,02/2011,03/2011,"PLAN_DUREE_MOY","PLAN_NB_OBSERV","PLAN_COMMENT" -"2010_1",TARTANPION,"IId / I",,"DRB_ALG",,,,,,"MA-2009",03/2010,01/2011,,,,0,0,0,0,0,0,0,2,0,0,4,,,"1,5",1,"Un petit commentaire" -"2010_2",,"IId",,"DRH_CAT et DRH_CRU",,,,"Fileyage","poissons tubes","MANY",01/2008,12/2008,,20,0,0,21,0,0,21,0,0,21,0,0,,,,1,1, -"2010_03",,"IId / IV",,"FAR",,,,"balottage en plein air","divers choses visqueuses","MA-2009",03/2010,01/2011,,,,0,22,0,0,25,0,0,21,0,0,25,,,2,1, -"2009_1",,"IId / IV",,"GTR_DEF et GNS_DEF","110-119",,,"Fileyage à poissons tubes","poissons plats","PPP2010",12/2009,10/2010,0,1,1,1,2,1,1,1,1,1,2,,,,,,1,1, -"2009_2",,"IId",,"GTR_DEF et GNS_DEF","9888-99",,,"Fileyage à sirènes ","nymphes","PPP2010",12/2009,10/2010,1,1,1,2,3,4,4,4,4,3,3,,,,,,1,1, -"2009_3",TARTANPION,"IV",,"GTR_MOL et GNS_FIN",,,,"Fileyages à baleines à bosse","chameaux","PPP2010",12/2009,10/2010,2,2,2,2,2,2,2,2,2,2,4,,,,,,1,1, -"2009_4",,"IId",,"PTB_ALG",">=190",">18",,"Chalutage de fond machiavélique","gadidés, divers","PPP2010",12/2009,10/2010,1,1,1,1,1,1,1,1,1,1,2,,,,,,3,2, -"2009_5",,"IId",,"PTB_ALG","70-1100",">1140",,"Plongeur de fond sous-marin","gadidés, divers","PPP2010",12/2009,10/2010,1,1,1,1,1,1,1,1,1,1,2,,,,,,3,2, -"2009_6",BIS,"I / IV",,"OT_DEF","70-1100",">1140",,"Leon","poissons plats","PPP2010",12/2009,10/2010,0,1,0,1,0,1,2,2,2,2,1,,,,,,3,2, -"2010_4",TARTANPION,"IId / IV",,"OT_DEF et PTB_ALG et DRH",,,,"Chalutage de fond","gadidés, poissons plats, divers","BLOB",01/2010,12/2010,,3,0,0,3,0,0,3,0,0,3,0,0,,,,3,1, -"2010_5",,,,"DRB",,,,"Kamoulox","merlu, poissons cerises, divers","MA-2009",03/2010,01/2011,,,,0,5,0,0,5,0,0,6,0,0,3,,,3,1, -"2010_10",,"I / IV",,"DRB","70-1100",,,"Kamoulox","merlu, poissons pommes, divers","MA-2009",03/2010,01/2011,,,,0,5,0,0,5,0,0,6,0,0,3,,,3,1, -"2010_11",,"I / IV",,"DRB_CSJ","70-1100",,,"Troubidou","merlu, poissons cerises","MA-2009",03/2010,01/2011,,,,0,5,0,0,5,0,0,6,0,0,3,,,3,1, +"PLAN_CODE","SOCIETE_NOM","PECHE_DIVISION","PECHE_AUTRE","METIER_CODE_DCF5","METIER_MAILLAGE","METIER_TAILLE","METIER_AUTRE","METIER_LIBELLE","METIER_ESPECES","PROGRAMME_CODE","PROGRAMME_DEBUT","PROGRAMME_FIN",12/2009,01/2010,02/2010,03/2010,04/2010,05/2010,06/2010,07/2010,08/2010,09/2010,10/2010,11/2010,12/2010,01/2011,02/2011,03/2011,"PLAN_DUREE_MOY","PLAN_NB_OBSERV","PLAN_COMMENT","PLAN_STRATEGIE" +"2010_1",TARTANPION,"IId / I",,"DRB_ALG",,,,,,"MA-2009",03/2010,01/2011,,,,0,0,0,0,0,0,0,2,0,0,4,,,"1,5",1,"Un petit commentaire",SIMULTANEOUS_ALL_SPECIES +"2010_2",,"IId",,"DRH_CAT et DRH_CRU",,,,"Fileyage","poissons tubes","MANY",01/2008,12/2008,,20,0,0,21,0,0,21,0,0,21,0,0,,,,1,1,, +"2010_03",,"IId / IV",,"FAR",,,,"balottage en plein air","divers choses visqueuses","MA-2009",03/2010,01/2011,,,,0,22,0,0,25,0,0,21,0,0,25,,,2,1,, +"2009_1",,"IId / IV",,"GTR_DEF et GNS_DEF","110-119",,,"Fileyage à poissons tubes","poissons plats","PPP2010",12/2009,10/2010,0,1,1,1,2,1,1,1,1,1,2,,,,,,1,1,, +"2009_2",,"IId",,"GTR_DEF et GNS_DEF","9888-99",,,"Fileyage à sirènes ","nymphes","PPP2010",12/2009,10/2010,1,1,1,2,3,4,4,4,4,3,3,,,,,,1,1,, +"2009_3",TARTANPION,"IV",,"GTR_MOL et GNS_FIN",,,,"Fileyages à baleines à bosse","chameaux","PPP2010",12/2009,10/2010,2,2,2,2,2,2,2,2,2,2,4,,,,,,1,1,, +"2009_4",,"IId",,"PTB_ALG",">=190",">18",,"Chalutage de fond machiavélique","gadidés, divers","PPP2010",12/2009,10/2010,1,1,1,1,1,1,1,1,1,1,2,,,,,,3,2,, +"2009_5",,"IId",,"PTB_ALG","70-1100",">1140",,"Plongeur de fond sous-marin","gadidés, divers","PPP2010",12/2009,10/2010,1,1,1,1,1,1,1,1,1,1,2,,,,,,3,2,, +"2009_6",BIS,"I / IV",,"OT_DEF","70-1100",">1140",,"Leon","poissons plats","PPP2010",12/2009,10/2010,0,1,0,1,0,1,2,2,2,2,1,,,,,,3,2,, +"2010_4",TARTANPION,"IId / IV",,"OT_DEF et PTB_ALG et DRH",,,,"Chalutage de fond","gadidés, poissons plats, divers","BLOB",01/2010,12/2010,,3,0,0,3,0,0,3,0,0,3,0,0,,,,3,1,, +"2010_5",,,,"DRB",,,,"Kamoulox","merlu, poissons cerises, divers","MA-2009",03/2010,01/2011,,,,0,5,0,0,5,0,0,6,0,0,3,,,3,1,, +"2010_10",,"I / IV",,"DRB","70-1100",,,"Kamoulox","merlu, poissons pommes, divers","MA-2009",03/2010,01/2011,,,,0,5,0,0,5,0,0,6,0,0,3,,,3,1,, +"2010_11",,"I / IV",,"DRB_CSJ","70-1100",,,"Troubidou","merlu, poissons cerises","MA-2009",03/2010,01/2011,,,,0,5,0,0,5,0,0,6,0,0,3,,,3,1,,