Author: bleny Date: 2010-11-25 15:30:03 +0000 (Thu, 25 Nov 2010) New Revision: 801 Log: refactor DCF5 codes + migration + impact in code and tests Added: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/DCF5CodeImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/FishingGearDCFImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/TargetSpeciesDCFImpl.java Removed: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/DCFFiveCodeImpl.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ProfessionImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowLogImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ImportHelper.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java trunk/wao-business/src/main/xmi/wao.properties trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-business/src/test/java/fr/ifremer/wao/WaoMigrationCallBackTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ContactModelFactory.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java trunk/wao-ui/src/main/webapp/SamplingPlan.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-11-25 15:30:03 UTC (rev 801) @@ -26,7 +26,6 @@ import fr.ifremer.wao.bean.ContactState; import fr.ifremer.wao.bean.SynthesisId; -import fr.ifremer.wao.entity.DCFFiveCode; import org.hibernate.SQLQuery; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; @@ -443,36 +442,101 @@ @Override protected void createTablesForDCF5Code_1_6(List<String> queries) { - // create table IndicatorLog with author FK - queries.add("CREATE TABLE DCFFiveCode (" + + // create table FishingGearDCF + queries.add("CREATE TABLE FishingGearDCF (" + "topiaId CHARACTER VARYING(255) PRIMARY KEY," + "topiaVersion BIGINT NOT NULL," + "topiaCreateDate TIMESTAMP WITHOUT TIME ZONE NOT NULL," + - "fishingGearDCF CHARACTER VARYING(10) NOT NULL," + - "targetSpeciesDCF CHARACTER VARYING(10)," + + "code CHARACTER VARYING(10) NOT NULL," + + "UNIQUE (code));"); + queries.add("CREATE TABLE TargetSpeciesDCF (" + + "topiaId CHARACTER VARYING(255) PRIMARY KEY," + + "topiaVersion BIGINT NOT NULL," + + "topiaCreateDate TIMESTAMP WITHOUT TIME ZONE NOT NULL," + + "code CHARACTER VARYING(10) NOT NULL," + + "UNIQUE (code));"); + + queries.add("CREATE TABLE DCF5Code (" + + "topiaId CHARACTER VARYING(255) PRIMARY KEY," + + "topiaVersion BIGINT NOT NULL," + + "topiaCreateDate TIMESTAMP WITHOUT TIME ZONE NOT NULL," + + "FishingGearDCF CHARACTER VARYING(255) NOT NULL," + + "TargetSpeciesDCF CHARACTER VARYING(255)," + + "CONSTRAINT FishingGearDCF_fkey FOREIGN KEY (FishingGearDCF) " + + "REFERENCES FishingGearDCF (topiaid) MATCH SIMPLE " + + "ON UPDATE NO ACTION ON DELETE NO ACTION," + + "CONSTRAINT TargetSpeciesDCF_fkey FOREIGN KEY (TargetSpeciesDCF) " + + "REFERENCES TargetSpeciesDCF (topiaid) MATCH SIMPLE " + + "ON UPDATE NO ACTION ON DELETE NO ACTION," + "UNIQUE (fishingGearDCF, targetSpeciesDCF));"); - // *..* relation need an intermediate table - queries.add("CREATE TABLE dcf5code_profession (" + - "dcf5code character varying(255) NOT NULL," + - "Profession character varying(255) NOT NULL," + - "CONSTRAINT profession_fkey FOREIGN KEY (profession) " + - "REFERENCES Profession (topiaid) MATCH SIMPLE " + + // *..* relation need an intermediate table between sampleRow and dcf5code + queries.add("CREATE TABLE DCF5Code_SampleRow (" + + "DCF5Code character varying(255) NOT NULL," + + "SampleRow character varying(255) NOT NULL," + + "CONSTRAINT DCF5Code_fkey FOREIGN KEY (DCF5Code) " + + "REFERENCES DCF5Code (topiaid) MATCH SIMPLE " + "ON UPDATE NO ACTION ON DELETE NO ACTION," + - "CONSTRAINT dcffivecode_fkey FOREIGN KEY (dcf5code) " + - "REFERENCES DCFFiveCode (topiaid) MATCH SIMPLE " + + "CONSTRAINT SampleRow_fkey FOREIGN KEY (SampleRow) " + + "REFERENCES SampleRow (topiaid) MATCH SIMPLE " + "ON UPDATE NO ACTION ON DELETE NO ACTION);"); } - /** get Data to migrate. key is the topiaId of the profession (to be - * used as a foreign key) and value is the value of the field to split) - */ + @Override + protected Map<String, String> insertFishingGearDCF_1_6(List<String> queries) { + String topiaIdPrefix = "fr.ifremer.wao.entities.FishingGearDCF#1289321129111#798260963"; + int topiaVersion = 0; + String topiaCreateDateValue = "DATE '2010-11-24'"; + + Map<String, String> result = new HashMap<String, String>(); + + for (String code : gearCodesBase) { + String topiaId = topiaIdPrefix + code; + String sql = String.format("INSERT INTO FishingGearDCF (topiaId, topiaVersion, topiaCreateDate, code) " + + "VALUES ('%s', %s, %s, '%s');", + topiaId, + topiaVersion, + topiaCreateDateValue, + code); + queries.add(sql); + + result.put(code, topiaId); + } + + return result; + } + + @Override + protected Map<String, String> insertTargetSpeciesDCF_1_6(List<String> queries) { + String topiaIdPrefix = "fr.ifremer.wao.entities.TargetSpeciesDCF#1289321129111#798260963"; + int topiaVersion = 0; + String topiaCreateDateValue = "DATE '2010-11-24'"; + + Map<String, String> result = new HashMap<String, String>(); + + for (String code : speciesCodesBase) { + String topiaId = topiaIdPrefix + code; + String sql = String.format("INSERT INTO TargetSpeciesDCF (topiaId, topiaVersion, topiaCreateDate, code) " + + "VALUES ('%s', %s, %s, '%s');", + topiaId, + topiaVersion, + topiaCreateDateValue, + code); + queries.add(sql); + + result.put(code, topiaId); + } + + return result; + } + protected Map<String, String> getCodeDCF5ForMigration_1_6(TopiaContextImplementor tx) throws TopiaException { final Map<String, String> result = new HashMap<String, String>(); SQLQuery query = tx.getHibernate(). - createSQLQuery("SELECT topiaid, codedcf5 FROM Profession;"); + createSQLQuery("SELECT sr.topiaId, codedcf5 " + + "FROM SampleRow sr join Profession p on sr.profession = p.topiaId;"); List<Object[]> results = query.list(); @@ -485,29 +549,28 @@ return result; } + @Override + protected void insertDCFFiveCode_1_6(String codeTopiaId, String gearTopiaId, String speciesTopiaId, List<String> queries) { - @Override - protected void insertDCFFiveCode_1_6(String codeTopiaId, DCFFiveCode code, List<String> queries) { int topiaVersion = 0; String topiaCreateDateValue = "DATE '2010-11-09'"; - String sql = String.format("INSERT INTO DCFFiveCode (topiaId, topiaVersion, topiaCreateDate, fishingGearDCF, targetSpeciesDCF) " + + String sql = String.format("INSERT INTO DCF5Code (topiaId, topiaVersion, topiaCreateDate, fishingGearDCF, targetSpeciesDCF) " + "VALUES ('%s', %s, %s, '%s', %s);", codeTopiaId, topiaVersion, topiaCreateDateValue, - code.getFishingGearDCF(), - code.getTargetSpeciesDCF() == null ? "NULL" : "'" + code.getTargetSpeciesDCF() + "'"); + gearTopiaId, + speciesTopiaId == null ? "NULL" : "'" + speciesTopiaId + "'"); queries.add(sql); + } @Override - protected void insertSplitCodes_1_6(String professionTopiaId, - String codeTopiaId, - List<String> queries) { - String sql = String.format("INSERT INTO dcf5code_profession (Profession, dcf5code) " + + protected void insertSplitCodes_1_6(String sampleRowTopiaId, String codeTopiaId, List<String> queries) { + String sql = String.format("INSERT INTO DCF5Code_SampleRow (SampleRow, DCF5Code) " + "VALUES ('%s', '%s');", - professionTopiaId, codeTopiaId); + sampleRowTopiaId, codeTopiaId); queries.add(sql); } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-11-25 15:30:03 UTC (rev 801) @@ -24,8 +24,6 @@ package fr.ifremer.wao; -import fr.ifremer.wao.entity.DCFFiveCode; -import fr.ifremer.wao.entity.DCFFiveCodeImpl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaException; @@ -35,6 +33,7 @@ import org.nuiton.util.VersionUtil; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -90,11 +89,17 @@ protected abstract void createTablesForDCF5Code_1_6(List<String> queries); + protected abstract Map<String, String> insertFishingGearDCF_1_6(List<String> queries); + protected abstract Map<String, String> insertTargetSpeciesDCF_1_6(List<String> queries); + + /** get Data to migrate. key is the topiaId of the sample row (to be + * used as a foreign key) and value is the value of the field to split) + */ protected abstract Map<String, String> getCodeDCF5ForMigration_1_6(TopiaContextImplementor tx) throws TopiaException; - protected abstract void insertDCFFiveCode_1_6(String codeTopiaId, DCFFiveCode code, List<String> queries); + protected abstract void insertDCFFiveCode_1_6(String codeTopiaId, String gearTopiaId, String speciesTopiaId, List<String> queries); - protected abstract void insertSplitCodes_1_6(String professionTopiaId, String codeTopiaId, List<String> queries); + protected abstract void insertSplitCodes_1_6(String sampleRowTopiaId, String codeTopiaId, List<String> queries); protected abstract void removeCodeDCF5columnFromProfession_1_6(List<String> queries); @@ -238,6 +243,16 @@ executeSQL(tx, showSql, showProgression, strings); } + protected final String[] gearCodesBase = {"DRB", "DRH", "FAR", "FCN", "FG", + "FIX", "FPN", "FPO", "FSN", "FWR", "FYK", "GEN", "GES", "GN", "GNC", + "GND", "GNF", "GNS", "GT", "GTN", "GTR", "HAR", "HMD", "HMP", "HMX", + "LA", "LHM", "LHP", "LL", "LLD", "LLS", "LN", "LNB", "LNP", "LNS", + "LTL", "LX", "MIS", "NK", "OT", "OTB", "OTM", "OTT", "PS", "PS1", + "PS2", "PT", "PTB", "PTM", "RG", "SB", "SDN", "SPR", "SSC", "SV", + "SW", "TB", "TBB", "TBN", "TBS", "TM", "TMS", "TX"}; + protected final String[] speciesCodesBase = {"ALG", "CAT", "CRU", "CSJ", + "DEF", "DWS", "FIN", "LPF", "MOL", "SPF"}; + /** creates Indicator, IndicatorLevel, IndicatorLog tables and inserts * initial values. */ @@ -258,20 +273,32 @@ createTablesForDCF5Code_1_6(queries); + // map code to TopiaId + Map<String, String> gearCodes = insertFishingGearDCF_1_6(queries); + Map<String, String> speciesCodes = insertTargetSpeciesDCF_1_6(queries); + Map<String, String> codesDCF5ForMigration = getCodeDCF5ForMigration_1_6(tx); Set<String> insertedDCFFiveCode = new HashSet<String>(); for (Map.Entry<String, String> codeToMigrate : codesDCF5ForMigration.entrySet()) { // split the code String in multiple codes - List<DCFFiveCode> codes = splitCodeDCF5_1_6(codeToMigrate.getValue()); + List<String[]> codes = splitCodeDCF5_1_6(codeToMigrate.getValue()); // first, do the insert if needed - for (DCFFiveCode code : codes) { - String codeTopiaId = "fr.ifremer.wao.entities.DCFFiveCode#1289320029000#798260963" - + code.getFishingGearDCF() + code.getTargetSpeciesDCF(); + for (String[] code : codes) { + String codeTopiaId = "fr.ifremer.wao.entities.DCF5Code#1289320029000#798260963" + + code[0]; + if (code.length == 2) { + codeTopiaId += code[1]; + } if ( ! insertedDCFFiveCode.contains(codeTopiaId)) { - insertDCFFiveCode_1_6(codeTopiaId, code, queries); + String gearTopiaId = gearCodes.get(code[0]); + String speciesTopiaId = null; + if (code.length == 2) { + speciesTopiaId = speciesCodes.get(code[1]); + } + insertDCFFiveCode_1_6(codeTopiaId, gearTopiaId, speciesTopiaId, queries); insertedDCFFiveCode.add(codeTopiaId); } @@ -292,26 +319,41 @@ } /** given "XXX_YYY et ZZZ_", will split with " et " and with "_" to extract - * some DCFFiveCode entities + * some array like ["XXX", "YYY"], ["ZZZ"] */ - protected List<DCFFiveCode> splitCodeDCF5_1_6(String dcf5Code) { + protected List<String[]> splitCodeDCF5_1_6(String dcf5Code) { String codes[] = dcf5Code.split(" et "); - List<DCFFiveCode> result = new ArrayList<DCFFiveCode>(); + List<String[]> result = new ArrayList<String[]>(); for (String code : codes) { - String codeParts[] = code.split("_"); - DCFFiveCode dcfFiveCode = new DCFFiveCodeImpl(); - dcfFiveCode.setFishingGearDCF(codeParts[0]); - if (codeParts.length == 2 && ! codeParts[1].isEmpty()) { - dcfFiveCode.setTargetSpeciesDCF(codeParts[1]); + // code may be a bad legacy data, replace it to make valid code + String actualCode = code; + if (code.equals("GT?")) { + actualCode = "GT"; + } else if (code.equals("GN?")) { + actualCode = "GN"; + } else if (code.equals("DRBCJ")) { + actualCode = "DRB_CJ"; } + + String codeParts[] = actualCode.split("_"); + String[] dcfFiveCode; + if (codeParts.length == 1 || codeParts[1].isEmpty()) { + dcfFiveCode = new String[1]; + } else { + dcfFiveCode = new String[2]; + dcfFiveCode[1] = codeParts[1]; + } + dcfFiveCode[0] = codeParts[0]; result.add(dcfFiveCode); } if (log.isInfoEnabled()) { - log.info(String.format("line %s will be migrated to", - dcf5Code, result)); + log.info(String.format("line %s will be migrated to", dcf5Code)); + for (String[] code : result) { + log.info(Arrays.toString(code)); + } } return result; } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-11-25 15:30:03 UTC (rev 801) @@ -334,12 +334,12 @@ } if (filter.getFishingGearDCF() != null) { - query.addEquals(WaoQueryHelper.newDCFFiveCodeProperty().fishingGearDCF(), + query.addEquals(WaoQueryHelper.newDCF5CodeProperty().fishingGearDCF(), filter.getFishingGearDCF()); } if (filter.getTargetSpeciesDCF() != null) { - query.addEquals(WaoQueryHelper.newDCFFiveCodeProperty().targetSpeciesDCF(), + query.addEquals(WaoQueryHelper.newDCF5CodeProperty().targetSpeciesDCF(), filter.getTargetSpeciesDCF()); } Copied: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/DCF5CodeImpl.java (from rev 799, trunk/wao-business/src/main/java/fr/ifremer/wao/entity/DCFFiveCodeImpl.java) =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/DCF5CodeImpl.java (rev 0) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/DCF5CodeImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -0,0 +1,59 @@ +/* + * #%L + * Wao :: Business + * %% + * Copyright (C) 2009 - 2010 Ifremer + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.wao.entity; + +import static org.nuiton.i18n.I18n._; + +public class DCF5CodeImpl extends DCF5CodeAbstract { + + @Override + public String getFishingGearCode() { + return getFishingGearDCF().getCode(); + } + + @Override + public String getTargetSpeciesCode() { + String code = null; + if (getTargetSpeciesDCF() != null) { + code = getTargetSpeciesDCF().getCode(); + } + return code; + } + + @Override + public String getFishingGearDescription() { + return _("DCF.gear." + getFishingGearDCF()); + } + + @Override + public String getTargetSpeciesDescription() { + return _("DCF.species." + getTargetSpeciesDCF()); + } + + @Override + public String toString() { + String toString = getFishingGearCode(); + if (getTargetSpeciesDCF() != null) { + toString += "_" + getTargetSpeciesCode(); + } + return toString; + } +} Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/DCFFiveCodeImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/DCFFiveCodeImpl.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/DCFFiveCodeImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -1,46 +0,0 @@ -/* - * #%L - * Wao :: Business - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.wao.entity; - -import static org.nuiton.i18n.I18n._; - -public class DCFFiveCodeImpl extends DCFFiveCodeAbstract { - - - @Override - public String getFishingGearDCFDescription() { - return _("DCF.gear." + getFishingGearDCF()); - } - - @Override - public String getTargetSpeciesDCFDescription() { - return _("DCF.species." + getTargetSpeciesDCF()); - } - - @Override - public String toString() { - String toString = getFishingGearDCF(); - if (getTargetSpeciesDCF() != null) { - toString += "_" + getTargetSpeciesDCF(); - } - return toString; - } -} Added: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/FishingGearDCFImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/FishingGearDCFImpl.java (rev 0) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/FishingGearDCFImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -0,0 +1,17 @@ +package fr.ifremer.wao.entity; + +/** + * @author bleny + */ +public class FishingGearDCFImpl extends FishingGearDCFAbstract { + + public FishingGearDCFImpl() { + super(); + } + + public FishingGearDCFImpl(String code) { + super(); + setCode(code); + } + +} Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ProfessionImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ProfessionImpl.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ProfessionImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -44,44 +44,4 @@ private static final Logger log = LoggerFactory.getLogger(ProfessionImpl.class); private static final long serialVersionUID = 1L; - - @Override - public String getCode() { - String code = StringUtils.join(getDcf5code(), ", "); - code += getCodeWithoutDCF5(); - return code; - } - - @Override - public String getCodeWithoutDCF5() { - String code = ""; - if (!StringUtils.isEmpty(getMeshSize())) { - code += " " + getMeshSize(); - } - if (!StringUtils.isEmpty(getSize())) { - code += " " + getSize(); - } - if (!StringUtils.isEmpty(getOther())) { - code += " " + getOther(); - } - return code; - } - - @Override - public void setDcf5code(String codes, String separatorRegex) { - String[] splitCodes = codes.split(separatorRegex); - List<DCFFiveCode> dcfFives = new ArrayList<DCFFiveCode>(splitCodes.length); - for (String code : splitCodes) { - String[] codeParts = code.split("_"); - DCFFiveCode dcfFive = new DCFFiveCodeImpl(); - - dcfFive.setFishingGearDCF(codeParts[0]); - if (codeParts.length == 2) { - dcfFive.setTargetSpeciesDCF(codeParts[1]); - } - - dcfFives.add(dcfFive); - } - setDcf5code(dcfFives); - } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -25,9 +25,9 @@ package fr.ifremer.wao.entity; import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.bean.DataReliability; import fr.ifremer.wao.service.ServiceSampling; import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DurationFormatUtils; import org.nuiton.util.DateUtil; import org.nuiton.util.PeriodDates; @@ -379,4 +379,46 @@ // } // } + + + @Override + public String getProfessionDescription() { + String code = StringUtils.join(getDCF5Code(), ", "); + code += getProfessionDescriptionWithoutDCF5(); + return code; + } + + @Override + public String getProfessionDescriptionWithoutDCF5() { + String code = ""; + if (!StringUtils.isEmpty(getProfession().getMeshSize())) { + code += " " + getProfession().getMeshSize(); + } + if (!StringUtils.isEmpty(getProfession().getSize())) { + code += " " + getProfession().getSize(); + } + if (!StringUtils.isEmpty(getProfession().getOther())) { + code += " " + getProfession().getOther(); + } + return code; + } + + @Override + public void setDCF5Code(String codes, String separatorRegex) { + String[] splitCodes = codes.split(separatorRegex); + List<DCF5Code> dcfFives = new ArrayList<DCF5Code>(splitCodes.length); + for (String code : splitCodes) { + String[] codeParts = code.split("_"); + DCF5Code dcfFive = new DCF5CodeImpl(); + + dcfFive.setFishingGearDCF(new FishingGearDCFImpl(codeParts[0])); + if (codeParts.length == 2) { + dcfFive.setTargetSpeciesDCF(new TargetSpeciesDCFImpl(codeParts[1])); + } + + dcfFives.add(dcfFive); + } + setDCF5Code(dcfFives); + } + } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowLogImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowLogImpl.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowLogImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -56,9 +56,11 @@ } @Override - public void addChangeProfession(Profession oldProfession, Profession newProfession) { - if (oldProfession == null) { - addChange("Le métier de la ligne est " + newProfession.getCode()); + public void addChangeProfession(SampleRow oldSampleRow, SampleRow newSampleRow) { + Profession newProfession = newSampleRow.getProfession(); + + if (oldSampleRow == null) { + addChange("Le métier de la ligne est " + newSampleRow.getProfessionDescription()); if (newProfession.getLibelle() != null) { addChange("Le libelle du métier est " + newProfession.getLibelle()); } @@ -68,9 +70,12 @@ return; } - if (!nvl(oldProfession.getCode()).equals(nvl(newProfession.getCode()))) { - addChange("Le métier de la ligne est passé de " + oldProfession.getCode() + " à " + newProfession.getCode()); + if (!nvl(oldSampleRow.getProfessionDescription()).equals(nvl(newSampleRow.getProfessionDescription()))) { + addChange("Le métier de la ligne est passé de " + oldSampleRow.getProfessionDescription() + + " à " + newSampleRow.getProfessionDescription()); } + + Profession oldProfession = oldSampleRow.getProfession(); if (newProfession.getLibelle() != null && !nvl(oldProfession.getLibelle()).equals(nvl(newProfession.getLibelle()))) { addChange("Le libellé du métier est passé de " + oldProfession.getLibelle() + " à " + newProfession.getLibelle()); } Added: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/TargetSpeciesDCFImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/TargetSpeciesDCFImpl.java (rev 0) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/TargetSpeciesDCFImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -0,0 +1,16 @@ +package fr.ifremer.wao.entity; + +/** + * @author bleny + */ +public class TargetSpeciesDCFImpl extends TargetSpeciesDCFAbstract { + + public TargetSpeciesDCFImpl() { + super(); + } + + public TargetSpeciesDCFImpl(String code) { + super(); + setCode(code); + } +} Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ImportHelper.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ImportHelper.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ImportHelper.java 2010-11-25 15:30:03 UTC (rev 801) @@ -28,8 +28,10 @@ import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoContext; import fr.ifremer.wao.WaoException; -import fr.ifremer.wao.entity.DCFFiveCode; -import fr.ifremer.wao.entity.DCFFiveCodeImpl; +import fr.ifremer.wao.entity.DCF5Code; +import fr.ifremer.wao.entity.DCF5CodeImpl; +import fr.ifremer.wao.entity.FishingGearDCFImpl; +import fr.ifremer.wao.entity.TargetSpeciesDCFImpl; import fr.ifremer.wao.io.csv.WaoCsvHeader.ACTIVITY_CALENDAR; import fr.ifremer.wao.io.csv.WaoCsvHeader.CONTACT; import fr.ifremer.wao.io.csv.WaoCsvHeader.DatedHeader; @@ -132,17 +134,17 @@ return context.prepareSampleRowCode(code); } - public static Collection<DCFFiveCode> readDCF5Codes(CsvReader reader) throws IOException { - Collection<DCFFiveCode> result = new ArrayList<DCFFiveCode>(); + public static Collection<DCF5Code> readDCF5Codes(CsvReader reader) throws IOException { + Collection<DCF5Code> result = new ArrayList<DCF5Code>(); String codesString = read(reader, SAMPLING.METIER_CODE_DCF5); // codeString is something like "AAA_BBB CCC", let's break it String[] codes = codesString.split(" et "); for (String codeString : codes) { String[] codeParts = codeString.split("_"); - DCFFiveCode code = new DCFFiveCodeImpl(); - code.setFishingGearDCF(codeParts[0]); + DCF5Code code = new DCF5CodeImpl(); + code.setFishingGearDCF(new FishingGearDCFImpl(codeParts[0])); if (codeParts.length == 2) { - code.setTargetSpeciesDCF(codeParts[1]); + code.setTargetSpeciesDCF(new TargetSpeciesDCFImpl(codeParts[1])); } result.add(code); } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -471,7 +471,7 @@ Profession profession = row.getProfession(); // export.record(SAMPLING.METIER_CODE_DCF5, profession.getCodeDCF5()); - export.record(SAMPLING.METIER_CODE_DCF5, StringUtil.join(profession.getDcf5code(), " et ", true)); + export.record(SAMPLING.METIER_CODE_DCF5, StringUtil.join(row.getDCF5Code(), " et ", true)); export.record(SAMPLING.METIER_MAILLAGE, profession.getMeshSize()); 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-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -45,10 +45,11 @@ import fr.ifremer.wao.entity.CompanyDAO; import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ContactDAO; -import fr.ifremer.wao.entity.DCFFiveCode; -import fr.ifremer.wao.entity.DCFFiveCodeDAO; +import fr.ifremer.wao.entity.DCF5Code; +import fr.ifremer.wao.entity.DCF5CodeDAO; import fr.ifremer.wao.entity.ElligibleBoat; import fr.ifremer.wao.entity.ElligibleBoatDAO; +import fr.ifremer.wao.entity.FishingGearDCF; import fr.ifremer.wao.entity.FishingZone; import fr.ifremer.wao.entity.FishingZoneDAO; import fr.ifremer.wao.entity.Profession; @@ -63,6 +64,7 @@ import fr.ifremer.wao.entity.SampleRowLog; import fr.ifremer.wao.entity.SampleRowLogDAO; import fr.ifremer.wao.entity.SampleRowLogImpl; +import fr.ifremer.wao.entity.TargetSpeciesDCF; import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.io.ImportResults; import fr.ifremer.wao.io.ImportResultsImpl; @@ -98,7 +100,6 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -149,25 +150,43 @@ * The method, insert all new codes in database, the others are already * inserted so we reference them, so they will be used as foreign key. */ - protected Collection<DCFFiveCode> insertOrSelect(TopiaContext transaction, - Collection<DCFFiveCode> codes) throws TopiaException { - Collection<DCFFiveCode> result = new LinkedList<DCFFiveCode>(); + protected Collection<DCF5Code> insertOrSelect(TopiaContext transaction, + Collection<DCF5Code> codes) throws TopiaException, WaoBusinessException { + Collection<DCF5Code> result = new LinkedList<DCF5Code>(); - for (DCFFiveCode code : codes) { + for (DCF5Code code : codes) { + FishingGearDCF foundGearCode = WaoDAOHelper.getFishingGearDCFDAO(transaction). + findByCode(code.getFishingGearCode()); + if (foundGearCode == null) { + throw new WaoBusinessException(String.format( + "%s is not a valid fishing gear code", code.getFishingGearCode())); + } + + TargetSpeciesDCF foundSpeciesCode = null; + if (code.getTargetSpeciesCode() != null) { + foundSpeciesCode = WaoDAOHelper.getTargetSpeciesDCFDAO(transaction). + findByCode(code.getTargetSpeciesCode()); + + if (foundSpeciesCode == null) { + throw new WaoBusinessException(String.format( + "%s is not a valid target species code", code.getTargetSpeciesCode())); + } + } + // try do find code in stored entities - DCFFiveCodeDAO dao = WaoDAOHelper.getDCFFiveCodeDAO(transaction); + DCF5CodeDAO dao = WaoDAOHelper.getDCF5CodeDAO(transaction); // both fishingGear and targetSpecies code have to be equals for // DCF5 code to be considered equals. targetSpecies as to be null // if asked - Map<String, Object> properties = new HashMap<String, Object>(); - properties.put(DCFFiveCode.FISHING_GEAR_DCF, code.getFishingGearDCF()); + TopiaQuery query = dao.createQuery() + .addEquals(DCF5Code.FISHING_GEAR_DCF, foundGearCode) - // next line may result in a "IS NULL", exactly what we want - properties.put(DCFFiveCode.TARGET_SPECIES_DCF, code.getTargetSpeciesDCF()); + // next line may result in a "IS NULL", exactly what we want + .addEquals(DCF5Code.TARGET_SPECIES_DCF, foundSpeciesCode); - DCFFiveCode foundCode = dao.findByProperties(properties); + DCF5Code foundCode = dao.findByQuery(query); if (log.isDebugEnabled()) { log.debug("foundCode = " + foundCode); @@ -178,6 +197,10 @@ log.debug(code + " is not already in DB, inserting"); } + // re-use codes already in database + code.setFishingGearDCF(foundGearCode); + code.setTargetSpeciesDCF(foundSpeciesCode); + // not found, let's insert a new row in database for this code dao.create(code); // add this new row in the result @@ -262,16 +285,14 @@ rowLog.addChangePeriod(oldPeriod, newPeriod, pattern); // before saving profession - if (row.getProfession().getDcf5code() != null) { - row.getProfession().setDcf5code( - insertOrSelect(transaction, - row.getProfession().getDcf5code())); + if (row.getDCF5Code() != null) { + row.setDCF5Code(insertOrSelect(transaction, row.getDCF5Code())); } // Save Profession ProfessionDAO professionDAO = WaoDAOHelper.getProfessionDAO(transaction); context.prepareTopiaId(Profession.class, row.getProfession()); - rowLog.addChangeProfession(oldProfession, row.getProfession()); + rowLog.addChangeProfession(oldRow, row); professionDAO.update(row.getProfession()); // Save sampleMonth @@ -458,7 +479,7 @@ // builder.setFishingZoneProperty(fishingZoneProperty); // builder.applySamplingFilter(filter); - WaoQueryHelper.DCFFiveCodeProperty dcf5CodeProperty = WaoQueryHelper.newDCFFiveCodeProperty(); + WaoQueryHelper.DCF5CodeProperty dcf5CodeProperty = WaoQueryHelper.newDCF5CodeProperty(); // Add join for FishingZone TopiaQuery query = builder.applySamplingFilter(filter). @@ -468,7 +489,7 @@ fishingZoneProperty.sectorName(), fishingZoneProperty.districtCode()). addLeftJoin(sampleRowProperty.fishingZone(), fishingZoneProperty.$alias(), false). - addLeftJoin(sampleRowProperty.professionProperty().dcf5code(), dcf5CodeProperty.$alias(), false). + addLeftJoin(sampleRowProperty.dCF5Code(), dcf5CodeProperty.$alias(), false). // Order By facade, sector, districtCode, sampleRowCode addOrder(fishingZoneProperty.facadeName(), fishingZoneProperty.sectorName(), @@ -532,13 +553,13 @@ WaoQueryHelper.SampleRowProperty sampleRowProperty = builder.initializeForSampleRow(false); - WaoQueryHelper.DCFFiveCodeProperty dcf5CodeProperty = - WaoQueryHelper.newDCFFiveCodeProperty(); + WaoQueryHelper.DCF5CodeProperty dcf5CodeProperty = + WaoQueryHelper.newDCF5CodeProperty(); TopiaQuery query = builder.applySamplingFilter(filter). addDistinct(). setSelect(sampleRowProperty.$alias()). - addLeftJoin(sampleRowProperty.professionProperty().dcf5code(), + addLeftJoin(sampleRowProperty.dCF5Code(), dcf5CodeProperty.$alias(), false). addOrder(sampleRowProperty.code()); @@ -828,7 +849,7 @@ Profession profession = row.getProfession(); // export.record(SAMPLING.METIER_CODE_DCF5, profession.getCodeDCF5()); - export.record(SAMPLING.METIER_CODE_DCF5, StringUtil.join(profession.getDcf5code(), " et ", true)); + export.record(SAMPLING.METIER_CODE_DCF5, StringUtil.join(row.getDCF5Code(), " et ", true)); export.record(SAMPLING.METIER_MAILLAGE, profession.getMeshSize()); export.record(SAMPLING.METIER_TAILLE, profession.getSize()); @@ -914,8 +935,7 @@ errorArgs.set(0, currRow); errorArgs.set(1, code); - String districts = ImportHelper.read(reader, - FISHING_ZONE.PECHE_DIVISION); + String districts = ImportHelper.read(reader, FISHING_ZONE.PECHE_DIVISION); row = dao.findByCode(code); // Refuse existing SampleRow @@ -1009,9 +1029,6 @@ profession.setLibelle(libelle); profession.setSpecies(especes); - // profession.setCodeDCF5(codeDCF5); - profession.setDcf5code(insertOrSelect(transaction, ImportHelper.readDCF5Codes(reader))); - return profession; } @@ -1149,22 +1166,11 @@ @Override protected Set<String> executeGetDCFGears(TopiaContext transaction, SamplingFilter filter) throws Exception { - TopiaQuery query = WaoDAOHelper.getDCFFiveCodeDAO(transaction).createQuery(); - query.setSelect(DCFFiveCode.FISHING_GEAR_DCF); - query.addDistinct(); - List<String> dcfGears = transaction.findByQuery(query); - Set<String> result = new HashSet<String>(dcfGears); - return result; + throw new UnsupportedOperationException(); } @Override protected Set<String> executeGetDCFSpecies(TopiaContext transaction, SamplingFilter filter) throws Exception { - TopiaQuery query = WaoDAOHelper.getDCFFiveCodeDAO(transaction).createQuery(); - query.setSelect(DCFFiveCode.TARGET_SPECIES_DCF) - .addNotNull(DCFFiveCode.TARGET_SPECIES_DCF) - .addDistinct(); - List<String> dcfGears = transaction.findByQuery(query); - Set<String> result = new HashSet<String>(dcfGears); - return result; + throw new UnsupportedOperationException(); } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-11-25 15:30:03 UTC (rev 801) @@ -54,7 +54,6 @@ import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactDAO; import fr.ifremer.wao.entity.Indicator; import fr.ifremer.wao.entity.IndicatorDAO; import fr.ifremer.wao.entity.IndicatorLevel; @@ -393,9 +392,6 @@ // only if there is no unfinished sampleRow or no contact done Map<String, Double> results = new HashMap<String, Double>(); - ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); - - WaoQueryBuilder builder = context.newQueryBuilder(); ContactProperty contactProperty = builder.initializeForContact(); TopiaQuery query = builder.applySamplingFilter(filter). @@ -602,10 +598,6 @@ Map<String, ContactAverageReactivity> results = new HashMap<String, ContactAverageReactivity>(); - ContactDAO dao = WaoDAOHelper.getContactDAO(transaction); - - //TopiaQuery query = dao.createQueryDoneContactsFromDate(null, period.getFromDate()); - String contactAlias = query.getMainAlias(); String companyProperty = TopiaQuery.getProperty(contactAlias, Contact.OBSERVER, WaoUser.COMPANY); Modified: trunk/wao-business/src/main/xmi/wao.properties =================================================================== --- trunk/wao-business/src/main/xmi/wao.properties 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/main/xmi/wao.properties 2010-11-25 15:30:03 UTC (rev 801) @@ -14,7 +14,9 @@ fr.ifremer.wao.entity.SampleRow.attribute.fishingZone.tagvalue.orderBy=facadeName,sectorName,districtCode fr.ifremer.wao.entity.SampleRow.attribute.company.tagvalue.lazy=false fr.ifremer.wao.entity.SampleRow.attribute.profession.tagvalue.lazy=false -fr.ifremer.wao.entity.Profession.attribute.dcf5code.tagvalue.lazy=false +fr.ifremer.wao.entity.SampleRow.attribute.dCF5Code.tagvalue.lazy=false +fr.ifremer.wao.entity.DCF5Code.attribute.fishingGearDCF.tagvalue.lazy=false +fr.ifremer.wao.entity.DCF5Code.attribute.targetSpeciesDCF.tagvalue.lazy=false #fr.ifremer.wao.entity.SampleRow.attribute.elligibleBoat.tagvalue.lazy=false fr.ifremer.wao.entity.SampleRow.attribute.elligibleBoat.tagvalue.orderBy=companyActive #fr.ifremer.wao.entity.SampleRow.attribute.sampleRowLog.tagvalue.lazy=false Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/WaoMigrationCallBackTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/WaoMigrationCallBackTest.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/WaoMigrationCallBackTest.java 2010-11-25 15:30:03 UTC (rev 801) @@ -20,17 +20,12 @@ */ package fr.ifremer.wao; -import fr.ifremer.wao.entity.DCFFiveCode; import org.junit.Test; import org.mockito.Mockito; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; import java.util.List; -import java.util.Map; import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNull; public class WaoMigrationCallBackTest { @@ -44,23 +39,23 @@ Mockito.when(migration.splitCodeDCF5_1_6(code)).thenCallRealMethod(); // now, the split - List<DCFFiveCode> codes = migration.splitCodeDCF5_1_6(code); + List<String[]> codes = migration.splitCodeDCF5_1_6(code); // first code - assertEquals("AAA", codes.get(0).getFishingGearDCF()); - assertEquals("BBB", codes.get(0).getTargetSpeciesDCF()); + assertEquals("AAA", codes.get(0)[0]); + assertEquals("BBB", codes.get(0)[1]); // second code - assertEquals("CCC", codes.get(1).getFishingGearDCF()); - assertEquals("DDD", codes.get(1).getTargetSpeciesDCF()); + assertEquals("CCC", codes.get(1)[0]); + assertEquals("DDD", codes.get(1)[1]); // third code - assertEquals("EEE", codes.get(2).getFishingGearDCF()); - assertNull(codes.get(2).getTargetSpeciesDCF()); + assertEquals("EEE", codes.get(2)[0]); + assertEquals(1, codes.get(2).length); // last code - assertEquals("FFF", codes.get(3).getFishingGearDCF()); - assertNull(codes.get(3).getTargetSpeciesDCF()); + assertEquals("FFF", codes.get(3)[0]); + assertEquals(1, codes.get(2).length); } Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatImplTest.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatImplTest.java 2010-11-25 15:30:03 UTC (rev 801) @@ -122,7 +122,7 @@ SampleRowDAO rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); SampleRow row = rowDAO.findByCode("2010_0001"); row.getCompany(); - row.getProfession().sizeDcf5code(); + row.getProfession(); row.sizeElligibleBoat(); row.sizeSampleMonth(); transaction.closeContext(); Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceBoatImplTest.java 2010-11-25 15:30:03 UTC (rev 801) @@ -239,11 +239,11 @@ // Get two SampleRows : 2009_3 & 2010_4 SampleRowDAO rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); SampleRow row1 = rowDAO.findByCode("2009_0003"); - row1.getProfession().sizeDcf5code(); + row1.getProfession(); row1.sizeElligibleBoat(); row1.sizeSampleMonth(); SampleRow row2 = rowDAO.findByCode("2010_0004"); - row2.getProfession().sizeDcf5code(); + row2.getProfession(); row2.sizeElligibleBoat(); row2.sizeSampleMonth(); 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-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2010-11-25 15:30:03 UTC (rev 801) @@ -37,8 +37,12 @@ import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ContactDAO; import fr.ifremer.wao.entity.ContactImpl; +import fr.ifremer.wao.entity.DCF5Code; +import fr.ifremer.wao.entity.DCF5CodeImpl; import fr.ifremer.wao.entity.ElligibleBoat; import fr.ifremer.wao.entity.ElligibleBoatDAO; +import fr.ifremer.wao.entity.FishingGearDCFDAO; +import fr.ifremer.wao.entity.FishingGearDCFImpl; import fr.ifremer.wao.entity.FishingZone; import fr.ifremer.wao.entity.FishingZoneDAO; import fr.ifremer.wao.entity.Profession; @@ -49,6 +53,7 @@ import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRowDAO; import fr.ifremer.wao.entity.SampleRowLogImpl; +import fr.ifremer.wao.entity.TargetSpeciesDCFImpl; import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.io.ImportResults; import org.junit.Assert; @@ -98,6 +103,14 @@ ServiceBoatImpl serviceBoat = (ServiceBoatImpl) manager.getServiceBoat(); serviceBoat.importBoatCsv(input); + // add DRB, DRH and ALG as existing codes + FishingGearDCFDAO fishingGearDCFDAO = WaoDAOHelper.getFishingGearDCFDAO(transaction); + fishingGearDCFDAO.create(new FishingGearDCFImpl("DRB")); + fishingGearDCFDAO.create(new FishingGearDCFImpl("DRH")); + WaoDAOHelper.getTargetSpeciesDCFDAO(transaction).create(new TargetSpeciesDCFImpl("ALG")); + + transaction.commitTransaction(); + transaction.closeContext(); // CREATE @@ -134,10 +147,22 @@ row.setFishingZone(zones); row.setFishingZonesInfos("port tres loin du champ"); + // for row, add DCF5 codes DRB_ALG, DRH + Collection<DCF5Code> dcf5codes = new ArrayList<DCF5Code>(); + DCF5Code dcf5 = new DCF5CodeImpl(); + dcf5.setFishingGearDCF(new FishingGearDCFImpl("DRB")); + dcf5.setTargetSpeciesDCF(new TargetSpeciesDCFImpl("ALG")); + dcf5codes.add(dcf5); + dcf5 = new DCF5CodeImpl(); + dcf5.setFishingGearDCF(new FishingGearDCFImpl("DRH")); + dcf5codes.add(dcf5); + row.setDCF5Code(dcf5codes); + /** EXEC CREATE **/ List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174592 978419 273129"); serviceSampling.createUpdateSampleRow(row, boats, new SampleRowLogImpl()); assertNotNull(row.getTopiaId()); + assertNotNull(row.getProfession().getTopiaId()); SampleRow result = serviceSampling.getSampleRow(row.getTopiaId()); @@ -474,7 +499,7 @@ SampleRowDAO rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); SampleRow row = rowDAO.findByCode("2010_0001"); row.getProfession(); - row.getProfession().sizeDcf5code(); + row.getProfession(); row.getCompany(); row.sizeSampleMonth(); row.sizeElligibleBoat(); Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2010-11-25 15:30:03 UTC (rev 801) @@ -30,8 +30,7 @@ import fr.ifremer.wao.bean.UserRole; import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.DCFFiveCode; -import fr.ifremer.wao.entity.DCFFiveCodeImpl; +import fr.ifremer.wao.entity.DCF5Code; import fr.ifremer.wao.entity.FishingZone; import fr.ifremer.wao.entity.Profession; import fr.ifremer.wao.entity.ProfessionImpl; @@ -223,7 +222,7 @@ public String getDcf5codes() { if (dcf5codes == null) { - Collection<DCFFiveCode> codes = getSampleRow().getProfession().getDcf5code(); + Collection<DCF5Code> codes = getSampleRow().getDCF5Code(); if (CollectionUtils.isEmpty(codes)) { dcf5codes = ""; } else { @@ -634,8 +633,7 @@ "Un commentaire est obligatoire lors d'une modification de la ligne"); } - Profession profession = getSampleRow().getProfession(); - if (CollectionUtils.isEmpty(profession.getDcf5code())) { + if (CollectionUtils.isEmpty(getSampleRow().getDCF5Code())) { sampleRowForm.recordError( "Le métier doit obligatoirement avoir un Code DCF niveau 5"); } @@ -681,7 +679,7 @@ getSampleRow().setSampleMonth(getSampleMonths()); // save dcf5 codes - getSampleRow().getProfession().setDcf5code(getDcf5codes(), ", "); + getSampleRow().setDCF5Code(getDcf5codes(), ", "); serviceSampling.createUpdateSampleRow(sampleRow, boats, getSampleRowLog()); Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-11-25 15:30:03 UTC (rev 801) @@ -30,7 +30,7 @@ import fr.ifremer.wao.bean.FacadeRow; import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.bean.SamplingFilterImpl; -import fr.ifremer.wao.entity.DCFFiveCode; +import fr.ifremer.wao.entity.DCF5Code; import fr.ifremer.wao.entity.FishingZone; import fr.ifremer.wao.entity.SampleMonth; import fr.ifremer.wao.entity.SampleRow; @@ -247,61 +247,6 @@ return this; } - @Property - private boolean refreshSampleRowCodeZone; - - @Property - private int sampleRowCodeIndex; - - @Persist - @Property - private SampleRow selectedSampleRow; - - @InjectComponent - private Zone sampleRowZone; - - public void onChangeFromSelectedSampleRow(String sampleRowCode) { - if (sampleRowCode == null) { - selectedSampleRow = null; - } else { - selectedSampleRow = getSampleRowSelectModel().findObject(sampleRowCode); - if (logger.isDebugEnabled()) { - logger.debug("selectedSampleRow " + selectedSampleRow.getCode()); - } - } - } - - public Object onActionFromAddSampleRowCode() { - - if (getFilter().getSampleRows() == null) { - getFilter().setSampleRows(new ArrayList<SampleRow>()); - } - getFilter().getSampleRows().add(selectedSampleRow); - - if (logger.isDebugEnabled()) { - logger.debug("added filter on code " + selectedSampleRow.getCode()); - } - - selectedSampleRow = null; - refreshSampleRowCodeZone = true; - return sampleRowZone; - } - - public Object onActionFromRemoveSampleRowCode(int sampleRowCodeIndex) { - - logger.debug("should remove " + sampleRowCodeIndex); - - SampleRow sampleRowToRemove = getFilter().getSampleRows().get(sampleRowCodeIndex); - - logger.debug("will remove " + sampleRowToRemove.getCode()); - - boolean result = getFilter().getSampleRows().remove(sampleRowToRemove); - logger.debug("removed " + result); - - refreshSampleRowCodeZone = true; - return sampleRowZone; - } - /**************************** MAIN ACTIONS ********************************/ @Persist @@ -343,7 +288,7 @@ /* variable used in template */ @Property - private DCFFiveCode dcf5code; + private DCF5Code dcf5code; /** * Current SampleRow from loop Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ContactModelFactory.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ContactModelFactory.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ContactModelFactory.java 2010-11-25 15:30:03 UTC (rev 801) @@ -266,7 +266,7 @@ @Override public Object get(Object arg0) { Contact contact = (Contact)arg0; - return contact.getSampleRow().getProfession().getCode(); + return contact.getSampleRow().getProfessionDescription(); } @Override Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2010-11-25 15:30:03 UTC (rev 801) @@ -182,7 +182,7 @@ DateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); Profession profession = row.getProfession(); result.append("<strong>Métier : </strong>"). - append(profession.getCode()); + append(row.getProfessionDescription()); result.append(" - ").append(profession.getLibelle()); if (!StringUtils.isEmpty(profession.getSpecies())) { result.append("\n<strong>Espèces cibles : </strong>"). @@ -231,7 +231,7 @@ if (filter.getSampleRow() != null) { Profession profession = filter.getSampleRow().getProfession(); result.append(separator). - append("\nMétier ").append(profession.getCode()); + append("\nMétier ").append(filter.getSampleRow().getCode()); if (StringUtils.isNotEmpty(profession.getLibelle())) { result.append(" - ").append(profession.getLibelle()); } Modified: trunk/wao-ui/src/main/webapp/SamplingPlan.tml =================================================================== --- trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-11-24 16:18:47 UTC (rev 800) +++ trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-11-25 15:30:03 UTC (rev 801) @@ -30,19 +30,6 @@ <t:layout t:pageTitle="Plan d'Echantillonnage" t:contentId="so-sampling" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> <div class="${mainClass}"> - <!--<t:if t:test="canImportSamplingPlan()">--> - <!--<div class="so-import">--> - <!--<form t:type="form" t:id="importSamplingPlan" action="post">--> - <!--<fieldset>--> - <!--<legend>Import d'un nouveau plan d'échantillonnage</legend>--> - <!--<t:errors />--> - <!--<t:label for="samplingPlanCsvFile" /> :--> - <!--<input t:type="upload" t:id="samplingPlanCsvFile" t:validate="required" />--> - <!--<input t:type="submit" class="ico import" value="OK" title="Importer un plan d'échantillonnage (format CSV avec encodage UTF-8)" />--> - <!--</fieldset>--> - <!--</form>--> - <!--</div>--> - <!--</t:if>--> <div class="clearfix mbottom10"> <div class="clearfix"> <h1 class="fleft">Plan d'échantillonnage</h1> @@ -89,17 +76,7 @@ </t:if> </t:if> </div> - </div> - <!--form t:type="form" t:id="periodForm" action="post"> - <div> - <t:label t:for="periodBegin" /> : - <input t:type="datefield" class="width70" t:id="periodBegin" t:value="period.fromDate" t:format="MM/yyyy" t:validate="required"/> - <t:label t:for="periodEnd" /> : - <input t:type="datefield" class="width70" t:id="periodEnd" t:value="period.thruDate" t:format="MM/yyyy" t:validate="required" /> - <input t:type="submit" class="ico search" value="Search" t:title="Affichage des lignes du plan couvertes par la période sélectionnée" /> - <a t:type="actionlink" t:id="showFilters" t:zone="so-sampling-filters" class="display-form">recherche avancée</a> - </div> - </form--> + </div> <div> Pour la pédiode du <t:output value="period.fromDate" format="dateFormat" /> au <t:output value="period.thruDate" format="dateFormat" /> <a t:type="actionlink" t:id="showFilters" t:zone="so-sampling-filters" class="display-form"><img src="${asset:context:img/search.png}" /> recherche avancée</a> @@ -144,24 +121,6 @@ ${row.code} </li> </ul> - <t:zone id="so-sampling-sampleRowZone" t:id="sampleRowZone" t:update="show"> - <!--t:nuiton.subForm t:visible="refreshSampleRowCodeZone"> - <t:label t:for="selectedSampleRow" />: - <select t:type="select" t:id="selectedSampleRow" t:value="selectedSampleRow" t:model="sampleRowSelectModel" - t:mixins="ck/onEvent" t:event="change"/> - <a t:type="actionlink" t:id="addSampleRowCode" title="Ajouter un code de ligne" t:zone="so-sampling-sampleRowZone"> - <img src="${asset:context:img/add-16px.png}" /> - </a> - <ul> - <li style="display: inline;" t:type="loop" t:source="filter.sampleRows" t:value="row" t:index="sampleRowCodeIndex" t:volatile="true"> - ${row.code} - <a t:type="actionlink" t:id="removeSampleRowCode" t:context="sampleRowCodeIndex" title="Supprimer ce code de ligne" t:zone="so-sampling-sampleRowZone"> - <img src="${asset:context:img/remove-22px.png}" /> - </a> - </li> - </ul> - </t:nuiton.subForm--> - </t:zone> </div> <div> <t:label t:for="fishingGearDCF" /> : @@ -263,8 +222,8 @@ <td>${fishingZones}</td> <td>${row.fishingZonesInfos}</td> <td> - <t:loop source="row.profession.dcf5code" value="dcf5code"> - <span t:type="ck/Tooltip" t:value="${dcf5Code.fishingGearDCF} - ${dcf5Code.fishingGearDCFDescription} ; ${dcf5Code.targetSpeciesDCF} - ${dcf5Code.targetSpeciesDCFDescription}" t:effect="appear"> + <t:loop source="row.dcf5code" value="dcf5code"> + <span t:type="ck/Tooltip" t:value="${dcf5Code.fishingGearCode} - ${dcf5Code.fishingGearDescription} ; ${dcf5Code.targetSpeciesCode} - ${dcf5Code.targetSpeciesDescription}" t:effect="appear"> ${dcf5Code} </span> </t:loop> @@ -283,12 +242,12 @@ </span> </td> <td> - <t:loop source="row.profession.dcf5code" value="dcf5code"> - <span t:type="ck/Tooltip" t:value="${dcf5Code.fishingGearDCF} - ${dcf5Code.fishingGearDCFDescription} ; ${dcf5Code.targetSpeciesDCF} - ${dcf5Code.targetSpeciesDCFDescription}" t:effect="appear"> + <t:loop source="row.dcf5code" value="dcf5code"> + <span t:type="ck/Tooltip" t:value="${dcf5Code.fishingGearCode} - ${dcf5Code.fishingGearDescription} ; ${dcf5Code.targetSpeciesCode} - ${dcf5Code.targetSpeciesDescription}" t:effect="appear"> ${dcf5Code} </span> </t:loop> - ${row.profession.codeWithoutDCF5} + ${row.professionDescriptionWithoutDCF5} </td> <td class="bright"> <span t:type="ck/Tooltip" title="Infos" t:value="Espèces cibles : ${row.profession.species}" t:effect="appear">