Author: fdesbois Date: 2009-12-07 16:06:52 +0000 (Mon, 07 Dec 2009) New Revision: 100 Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ElligibleBoatsCompanyImpl.java Modified: trunk/pom.xml trunk/suiviobsmer-business/pom.xml trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceBoatMock.java trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.properties trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java trunk/suiviobsmer-business/src/test/resources/import/zonesPeche.csv trunk/suiviobsmer-ui/pom.xml trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties trunk/suiviobsmer-ui/src/main/webapp/Boats.tml Log: - Change model for ElligibleBoat - Add createUpdateBoatInfos method (Evol #1938) Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/pom.xml 2009-12-07 16:06:52 UTC (rev 100) @@ -16,7 +16,7 @@ <groupId>fr.ifremer</groupId> <artifactId>suiviobsmer</artifactId> - <version>0.0.1-SNAPSHOT</version> + <version>0.0.1-alpha-1-SNAPSHOT</version> <modules> <module>suiviobsmer-ui</module> Modified: trunk/suiviobsmer-business/pom.xml =================================================================== --- trunk/suiviobsmer-business/pom.xml 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-business/pom.xml 2009-12-07 16:06:52 UTC (rev 100) @@ -11,7 +11,7 @@ <parent> <groupId>fr.ifremer</groupId> <artifactId>suiviobsmer</artifactId> - <version>0.0.1-SNAPSHOT</version> + <version>0.0.1-alpha-1-SNAPSHOT</version> </parent> <groupId>fr.ifremer.suiviobsmer</groupId> Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ElligibleBoatsCompanyImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ElligibleBoatsCompanyImpl.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ElligibleBoatsCompanyImpl.java 2009-12-07 16:06:52 UTC (rev 100) @@ -0,0 +1,86 @@ + +package fr.ifremer.suiviobsmer.bean; + +import fr.ifremer.suiviobsmer.entity.ElligibleBoat; +import fr.ifremer.suiviobsmer.entity.ElligibleBoatImpl; +import fr.ifremer.suiviobsmer.entity.SampleRow; +import java.util.Collection; +import java.util.Iterator; +import org.apache.commons.lang.StringUtils; + +/** + * ElligibleBoatsCompanyImpl + * + * Created: 7 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ElligibleBoatsCompanyImpl extends ElligibleBoatsCompany { + + @Override + public void removeElement(String sampleRowCode) { + ElligibleBoat elligible = elligibleBoats.get(sampleRowCode); + // ElligibleBoat set by an admin + if (elligible.getCompanyActive() == null) { + elligible.setCompanyActive(Boolean.FALSE); + } else { + if (!deletedElligibleBoats.contains(elligible) && !StringUtils.isEmpty(elligible.getTopiaId())) { + deletedElligibleBoats.add(elligible); + } + elligibleBoats.remove(sampleRowCode); + } + } + + @Override + public ElligibleBoat getElement(String sampleRowCode) { + return elligibleBoats.get(sampleRowCode); + } + + @Override + public ElligibleBoat setNewElement(SampleRow row) { + ElligibleBoat elligible = null; + if (row == null) { + return null; + } + if (!elligibleBoats.containsKey(row.getCode())) { + elligible = new ElligibleBoatImpl(); + elligible.setCompanyActive(Boolean.TRUE); + elligible.setBoat(boat); + elligible.setSampleRow(row); + elligibleBoats.put(row.getCode(), elligible); + removePreviouslyDeleted(row.getCode()); + } + return elligible; + } + + protected void removePreviouslyDeleted(String sampleRowCode) { + Iterator<ElligibleBoat> it = deletedElligibleBoats.iterator(); + while (it.hasNext()) { + ElligibleBoat current = it.next(); + if (current.getSampleRow().getCode().equals(sampleRowCode)) { + it.remove(); + } + } + } + + /** + * Active only element wich is inactive. So element which is linked by admin in SamplingRowForm. + * The Boolean CompanyActive is set to null : no specific modification for company. + * @param sampleRowCode code of the element to reactivate + */ + @Override + public void activeElement(String sampleRowCode) { + ElligibleBoat elligible = getElement(sampleRowCode); + elligible.setCompanyActive(null); + } + + @Override + public Collection<ElligibleBoat> values() { + return elligibleBoats.values(); + } + +} Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java 2009-12-07 16:06:52 UTC (rev 100) @@ -67,7 +67,7 @@ public boolean hasElligibleBoat(Boat boat) { for (ElligibleBoat elligible : this.getElligibleBoat()) { String elligibleBoatTopiaId = elligible.getBoat().getTopiaId(); - if (elligibleBoatTopiaId.equals(boat.getTopiaId()) && elligible.getCompany() == null) { + if (elligibleBoatTopiaId.equals(boat.getTopiaId()) && elligible.getCompanyActive() == null) { return true; } } @@ -82,7 +82,7 @@ String elligibleBoatTopiaId = elligible.getBoat().getTopiaId(); boolean find = false; for (Boat boat : boats) { - if (elligibleBoatTopiaId.equals(boat.getTopiaId()) && elligible.getCompany() == null) { + if (elligibleBoatTopiaId.equals(boat.getTopiaId()) && elligible.getCompanyActive() == null) { find = true; break; } @@ -97,7 +97,7 @@ public String getMainElligibleBoatsAsString() { String result = ""; for (ElligibleBoat elligible : getElligibleBoat()) { - if (elligible.getCompany() == null) { + if (elligible.getCompanyActive() == null) { Boat boat = elligible.getBoat(); result += boat.getImmatriculation() + " "; } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java 2009-12-07 16:06:52 UTC (rev 100) @@ -6,6 +6,8 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.bean.BoatFilter; +import fr.ifremer.suiviobsmer.bean.ElligibleBoatsCompany; +import fr.ifremer.suiviobsmer.bean.ElligibleBoatsCompanyImpl; import fr.ifremer.suiviobsmer.entity.*; import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.services.ServiceBoat; @@ -13,12 +15,12 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.nuiton.topia.TopiaContext; import org.slf4j.Logger; @@ -147,41 +149,32 @@ /******************** CHECK ELLIGIBLE BOATS FOR EACH ROW **********/ - String companyFilteredId = companyFiltered ? filter.getCompany().getTopiaId() : null; - //List<Integer> boatsRefused = new ArrayList<Integer>(); for (SampleRow row : rows) { List<FishingZone> zones = row.getFishingZone(); // FILTER BY FISHING ZONE if (fishingZoneFiltered && !zones.contains(filter.getFishingZone())) { break; } + for (ElligibleBoat elligible : row.getElligibleBoat()) { - Company elligibleCompany = elligible.getCompany(); int immatriculation = elligible.getBoat().getImmatriculation(); - // company filtered and elligible boat set by company - if (companyFiltered && elligibleCompany != null && - companyFilteredId.equals(elligibleCompany.getTopiaId())) { - if (elligible.getActive()) { - if (log.isDebugEnabled()) { - log.debug("Add elligible boat : " + immatriculation + " - " + - elligible.getBoat().getName()); - } - results.put(immatriculation, elligible.getBoat()); - } else if (results.containsKey(immatriculation)) { - //boatsRefused.add(immatriculation); - results.remove(immatriculation); - } - } - // for everybody, no elligibleCompany set - // company may have refused this boat from an other elligibleBoat instance - if (elligibleCompany == null && elligible.getActive() /*&& - !boatsRefused.contains(immatriculation)*/) { + + // For company + boolean condition1 = companyFiltered && + BooleanUtils.isNotFalse(elligible.getCompanyActive()); + + // For admin + boolean condition2 = !companyFiltered && elligible.getGlobalActive(); + + if (condition1 || condition2) { if (log.isDebugEnabled()) { - log.debug("Add elligible boat : " + immatriculation + " - " + + log.debug("Add elligible boat : " + + immatriculation + " - " + elligible.getBoat().getName()); } results.put(immatriculation, elligible.getBoat()); } + } } @@ -201,19 +194,22 @@ /** * Get elligible boats for a company and a boat. This method is useful to get sampleRows elligibles for - * the boat. Only sampleRows not closed linked or not with the company argument will be returned. - * It is possible to have two elligibleBoats for the same sampleRow (one elligibleBoat with - * no company link and the other with a link with the company in argument), in this case, - * the method return only the one linked with the company in argument. The result give a Map - * with sampleRowCode in key and ElligibleBoat in value. The ElligibleBoat entity contains the SampleRow - * and an attribute useful to know if the link is still active. + * the boat. Only sampleRows not closed linked with the company argument will be returned. + * The result give a Map with sampleRowCode in key and ElligibleBoat in value. The ElligibleBoat entity + * contains the SampleRow and attributes useful to know if the link is active or specific for the company. * @param boatImmatriculation immatriculation of the boat * @param company the Company to filter the ElligibleBoats - * @return a Map with sampleRowCode in key and ElligibleBoat in value + * @return an ElligibleBoatsCompany wich contains the map of ElligibleBoat, the company and an empty list for + * deleted elements */ @Override - public Map<String, ElligibleBoat> getElligibleBoats(int boatImmatriculation, Company company) throws SuiviObsmerException { - Map<String, ElligibleBoat> results = new HashMap<String, ElligibleBoat>(); + public ElligibleBoatsCompany getElligibleBoats(int boatImmatriculation, Company company) + throws SuiviObsmerException { + Map<String, ElligibleBoat> map = new HashMap<String, ElligibleBoat>(); + ElligibleBoatsCompany result = new ElligibleBoatsCompanyImpl(); + result.setCompany(company); + result.setElligibleBoats(map); + result.setDeletedElligibleBoats(new ArrayList<ElligibleBoat>()); TopiaContext transaction = null; try { transaction = rootContext.beginTransaction(); @@ -221,40 +217,19 @@ BoatDAO dao = SuiviObsmerModelDAOHelper.getBoatDAO(transaction); Boat boat = dao.findByImmatriculation(boatImmatriculation); + result.setBoat(boat); for (ElligibleBoat elligible : boat.getElligibleBoat()) { SampleRow sampleRow = elligible.getSampleRow(); // SampleRow non closed only if (!sampleRow.getProgram().isFinished()) { - String companyId = elligible.getCompany() != null ? - elligible.getCompany().getTopiaId() : ""; - String sampleRowCompanyId = sampleRow.getCompany() != null ? + String companyId = sampleRow.getCompany() != null ? sampleRow.getCompany().getTopiaId() : ""; - // SampleRow not linked with any company - boolean condition1 = sampleRowCompanyId.isEmpty() && - (companyId.isEmpty() || companyId.equals(company.getTopiaId())); - - // SampleRow linked with the company argument - boolean condition2 = sampleRowCompanyId.equals(company.getTopiaId()) && - (companyId.isEmpty() || companyId.equals(company.getTopiaId())); - - if (condition1 || condition2) { - results.put(sampleRow.getCode(), elligible); - if (log.isDebugEnabled()) { - String companyName = elligible.getCompany() != null ? - elligible.getCompany().getName() : "none"; - - if (condition1) { - log.debug("Add elligibleRow linked with no company : " + - sampleRow.getCode() + " - " + companyName + " - " + elligible.getActive()); - } else if (condition2) { - log.debug("Add elligibleRow linked with " + company.getName() + " : " + - sampleRow.getCode() + " - " + companyName + " - " + elligible.getActive()); - } - } + if (companyId.equals(company.getTopiaId())) { + map.put(sampleRow.getCode(), elligible); } } } @@ -265,18 +240,39 @@ "Impossible de récupérer les lignes du plans elligibles pour" + " ce navire : " + boatImmatriculation, eee); } - return results; + return result; } - @Override - public ElligibleBoat getNewElligibleBoat(SampleRow sampleRow, Company company, Boat boat) { - ElligibleBoat elligible = new ElligibleBoatImpl(); - elligible.setActive(true); - elligible.setBoat(boat); - elligible.setSampleRow(sampleRow); - elligible.setCompany(company); - return elligible; + public void createUpdateBoatInfos(BoatInfos boatInfos, ElligibleBoatsCompany elligibleBoatsCompany) + throws SuiviObsmerException { + TopiaContext transaction = null; + try { + transaction = rootContext.beginTransaction(); + + BoatInfosDAO dao = SuiviObsmerModelDAOHelper.getBoatInfosDAO(transaction); + + SuiviObsmerUtils.prepareTopiaId(BoatInfos.class, boatInfos); + dao.update(boatInfos); + + ElligibleBoatDAO elligibleDAO = SuiviObsmerModelDAOHelper.getElligibleBoatDAO(transaction); + + for (ElligibleBoat elligible : elligibleBoatsCompany.values()) { + SuiviObsmerUtils.prepareTopiaId(ElligibleBoat.class, elligible); + elligibleDAO.update(elligible); + } + + // Delete ElligibleBoats for the company + for (ElligibleBoat elligible : elligibleBoatsCompany.getDeletedElligibleBoats()) { + elligibleDAO.delete(elligible); + } + + transaction.commitTransaction(); + transaction.closeContext(); + } catch (Exception eee) { + SuiviObsmerUtils.serviceException(transaction, + "La chaîne d'immatriculations est incorrect ! Chaque immatriculation doit posséder 6 chiffres", eee); + } } @Override Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java 2009-12-07 16:06:52 UTC (rev 100) @@ -102,7 +102,7 @@ if (!row.hasElligibleBoat(boat)) { ElligibleBoat elligibleBoat = dao.create(); elligibleBoat.setSampleRow(row); - elligibleBoat.setActive(true); + elligibleBoat.setGlobalActive(true); elligibleBoat.setBoat(boat); row.addElligibleBoat(elligibleBoat); } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceBoatMock.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceBoatMock.java 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceBoatMock.java 2009-12-07 16:06:52 UTC (rev 100) @@ -3,6 +3,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.bean.BoatFilter; +import fr.ifremer.suiviobsmer.bean.ElligibleBoatsCompany; import fr.ifremer.suiviobsmer.entity.*; import fr.ifremer.suiviobsmer.services.ServiceBoat; import java.io.InputStream; @@ -201,17 +202,17 @@ } @Override - public ElligibleBoat getNewElligibleBoat(SampleRow sampleRow, Company company, Boat boat) { + public ElligibleBoatsCompany getElligibleBoats(int boatImmatriculation, Company company) throws SuiviObsmerException { throw new UnsupportedOperationException("Not supported yet."); } @Override - public Map<String, ElligibleBoat> getElligibleBoats(int boatImmatriculation, Company company) throws SuiviObsmerException { + public Boat getBoat(String boatId) throws SuiviObsmerException { throw new UnsupportedOperationException("Not supported yet."); } @Override - public Boat getBoat(String boatId) throws SuiviObsmerException { + public void createUpdateBoatInfos(BoatInfos boatInfos, ElligibleBoatsCompany elligibleBoatsCompany) throws SuiviObsmerException { throw new UnsupportedOperationException("Not supported yet."); } Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.properties =================================================================== --- trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.properties 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.properties 2009-12-07 16:06:52 UTC (rev 100) @@ -9,12 +9,12 @@ fr.ifremer.suiviobsmer.entity.SampleRow.attribute.profession.tagvalue.lazy=false #fr.ifremer.suiviobsmer.entity.SampleRow.attribute.pogram.tagvalue.lazy=false fr.ifremer.suiviobsmer.entity.SampleRow.attribute.elligibleBoat.tagvalue.lazy=false -fr.ifremer.suiviobsmer.entity.SampleRow.attribute.elligibleBoat.tagvalue.orderBy=company +fr.ifremer.suiviobsmer.entity.SampleRow.attribute.elligibleBoat.tagvalue.orderBy=companyActive fr.ifremer.suiviobsmer.entity.FishingZone.attribute.sampleRow.tagvalue.orderBy=code fr.ifremer.suiviobsmer.entity.Boat.attribute.shipOwner.tagvalue.lazy=false -fr.ifremer.suiviobsmer.entity.Boat.attribute.elligibleBoat.tagvalue.orderBy=company +fr.ifremer.suiviobsmer.entity.Boat.attribute.elligibleBoat.tagvalue.orderBy=companyActive fr.ifremer.suiviobsmer.entity.ElligibleBoat.attribute.boat.tagvalue.lazy=false Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo =================================================================== (Binary files differ) Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java 2009-12-07 16:06:52 UTC (rev 100) @@ -1,12 +1,27 @@ package fr.ifremer.suiviobsmer.impl; +import fr.ifremer.suiviobsmer.SuiviObsmerException; +import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.SuiviObsmerRunner; +import fr.ifremer.suiviobsmer.SuiviObsmerUtils; import fr.ifremer.suiviobsmer.bean.BoatFilterImpl; import fr.ifremer.suiviobsmer.business.SuiviObsmerRunnerTest; import fr.ifremer.suiviobsmer.bean.BoatFilter; +import fr.ifremer.suiviobsmer.bean.ElligibleBoatsCompany; import fr.ifremer.suiviobsmer.entity.Boat; +import fr.ifremer.suiviobsmer.entity.BoatInfos; +import fr.ifremer.suiviobsmer.entity.Company; +import fr.ifremer.suiviobsmer.entity.CompanyDAO; +import fr.ifremer.suiviobsmer.entity.CompanyImpl; +import fr.ifremer.suiviobsmer.entity.ElligibleBoat; +import fr.ifremer.suiviobsmer.entity.SampleRow; +import fr.ifremer.suiviobsmer.entity.SampleRowDAO; +import fr.ifremer.suiviobsmer.services.ServiceReferential; +import fr.ifremer.suiviobsmer.services.ServiceSampling; import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import org.junit.After; @@ -14,6 +29,8 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.junit.Assert.*; @@ -96,6 +113,138 @@ public void testGetBoatInfos() throws Exception { } + + @Test + public void testGetElligibleBoats() throws Exception { + log.info("getElligibleBoats"); + + /** PREPARE DATA **/ + InputStream input = getClass().getResourceAsStream("/import/navires.csv"); + service.importBoatCsv(input); + + Company company = new CompanyImpl(); + company.setName("TARTANPION"); + prepareSampleRows(company); + + /** EXEC METHOD **/ + + ElligibleBoatsCompany result = service.getElligibleBoats(174592, company); + assertNotNull(result); + assertEquals(174592, result.getBoat().getImmatriculation()); + assertEquals("TARTANPION", result.getCompany().getName()); + // only row1 is getting + assertEquals(1, result.values().size()); + } + + private List<SampleRow> prepareSampleRows(Company company) + throws SuiviObsmerException, TopiaException { + ServiceReferential serviceReferential = new ServiceReferentialImpl(); + InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); + serviceReferential.importFishingZoneCsv(input); + + ServiceSampling serviceSampling = new ServiceSamplingImpl(); + input = getClass().getResourceAsStream("/import/echantillonnage.csv"); + serviceSampling.importSamplingPlanCsv(input); + + // Import doesn't set company + TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + + // Create a company + CompanyDAO companyDAO = SuiviObsmerModelDAOHelper.getCompanyDAO(transaction); + SuiviObsmerUtils.prepareTopiaId(Company.class, company); + companyDAO.update(company); + + // Get two SampleRows : 2009_3 & 2010_4 + SampleRowDAO rowDAO = SuiviObsmerModelDAOHelper.getSampleRowDAO(transaction); + SampleRow row1 = rowDAO.findByCode("2009_3"); + row1.getProgram(); + row1.getProfession(); + SampleRow row2 = rowDAO.findByCode("2010_4"); + row2.getProgram(); + row2.getProfession(); + + transaction.commitTransaction(); + + transaction.closeContext(); + + // Set company and elligibleBoats '174592 177474' for row1 + List<Boat> boats = service.getBoats("174592 177474"); + row1.setCompany(company); + serviceSampling.createUpdateSampleRow(row1, boats); + // Set company only for row2 + row2.setCompany(company); + serviceSampling.createUpdateSampleRow(row2, new ArrayList<Boat>()); + + return Arrays.asList(new SampleRow[] { row1, row2}); + } + + @Test + public void testCreateUpdateBoatInfos() throws Exception { + log.info("createUpdateBoatInfos"); + + /** PREPARE DATA **/ + InputStream input = getClass().getResourceAsStream("/import/navires.csv"); + service.importBoatCsv(input); + + List<Boat> boats = service.getBoats("174592"); + + // Two rows created : 2009_3 & 2010_4 and one Company : "TARTANPION" + Company company = new CompanyImpl(); + company.setName("TARTANPION"); + List<SampleRow> rows = prepareSampleRows(company); + + Boat boat = boats.get(0); + // Return new BoatInfos + BoatInfos boatInfos = boat.getBoatInfos(company); + + ElligibleBoatsCompany elligibleBoats = service.getElligibleBoats(174592, company); + + /** EXEC METHOD **/ + + boatInfos.setDup(2); + boatInfos.setContactFirstName("Jean-Paul"); + boatInfos.setContactLastName("Belmondo"); + + /** TEST1 **/ + // ajout d'une nouvelle ligne "2010_4" non mise en elligible auparavent + elligibleBoats.setNewElement(rows.get(1)); + // ligne deja elligible mise en inactive + elligibleBoats.removeElement("2009_3"); + + service.createUpdateBoatInfos(boatInfos, elligibleBoats); + + elligibleBoats = service.getElligibleBoats(174592, company); + + Map<String, ElligibleBoat> results = elligibleBoats.getElligibleBoats(); + assertEquals(2, results.size()); + + ElligibleBoat elligible = elligibleBoats.getElement("2009_3"); + assertNotNull(elligible.getCompanyActive()); + assertFalse(elligible.getCompanyActive()); + + elligible = elligibleBoats.getElement("2010_4"); + assertTrue(elligible.getCompanyActive()); + + /** TEST2 **/ + // Suppression ligne lié elligible pour la société + elligibleBoats.removeElement("2010_4"); + // Reactivation ligne mise en inactive juste avant + elligibleBoats.activeElement("2009_3"); + + service.createUpdateBoatInfos(boatInfos, elligibleBoats); + + elligibleBoats = service.getElligibleBoats(174592, company); + + results = elligibleBoats.getElligibleBoats(); + assertEquals(1, results.size()); + + elligible = elligibleBoats.getElement("2009_3"); + assertNull(elligible.getCompanyActive()); + assertTrue(elligible.getGlobalActive()); + + + } + /** * Test of getAllBoats method, of class ServiceBoatImpl. * @throws Exception Modified: trunk/suiviobsmer-business/src/test/resources/import/zonesPeche.csv =================================================================== --- trunk/suiviobsmer-business/src/test/resources/import/zonesPeche.csv 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-business/src/test/resources/import/zonesPeche.csv 2009-12-07 16:06:52 UTC (rev 100) @@ -1,7 +1,7 @@ "PECHE_DIVISION","PECHE_ZONE","PECHE_FACADE" "VId","Manche","Mer du Nord" "I","Mer du Nord","Mer du Nord" -"Ie","Manche Ouest","Atlantique" +"IId","Manche Ouest","Atlantique" "IIIa","Golfe de Gascogne","Atlantique" -"VII","Golfe de Gascogne","Atlantique" +"IV","Golfe de Gascogne","Atlantique" ,"Méditerranée","Méditerranée" Modified: trunk/suiviobsmer-ui/pom.xml =================================================================== --- trunk/suiviobsmer-ui/pom.xml 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-ui/pom.xml 2009-12-07 16:06:52 UTC (rev 100) @@ -11,7 +11,7 @@ <parent> <groupId>fr.ifremer</groupId> <artifactId>suiviobsmer</artifactId> - <version>0.0.1-SNAPSHOT</version> + <version>0.0.1-alpha-1-SNAPSHOT</version> </parent> <groupId>fr.ifremer.suiviobsmer</groupId> Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2009-12-07 16:06:52 UTC (rev 100) @@ -6,15 +6,14 @@ import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.entity.BoatInfos; import fr.ifremer.suiviobsmer.bean.BoatFilter; +import fr.ifremer.suiviobsmer.bean.ElligibleBoatsCompany; import fr.ifremer.suiviobsmer.entity.Company; -import fr.ifremer.suiviobsmer.entity.Contact; import fr.ifremer.suiviobsmer.entity.ElligibleBoat; import fr.ifremer.suiviobsmer.entity.FishingZone; import fr.ifremer.suiviobsmer.entity.Profession; import fr.ifremer.suiviobsmer.entity.SampleRow; import fr.ifremer.suiviobsmer.entity.User; import fr.ifremer.suiviobsmer.services.ServiceBoat; -import fr.ifremer.suiviobsmer.services.ServiceContact; import fr.ifremer.suiviobsmer.services.ServiceReferential; import fr.ifremer.suiviobsmer.services.ServiceSampling; import fr.ifremer.suiviobsmer.services.ServiceUser; @@ -26,6 +25,7 @@ import java.text.SimpleDateFormat; import java.util.List; import java.util.Map; +import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.apache.tapestry5.Block; import org.apache.tapestry5.EventContext; @@ -369,7 +369,7 @@ private BoatInfos boatInfos; @Persist - private Map<String, ElligibleBoat> elligibleSampleRows; + private ElligibleBoatsCompany elligibleSampleRows; @InjectComponent private Zone boatInfosZone; @@ -423,7 +423,7 @@ return boatInfos; } - public Map<String, ElligibleBoat> getElligibleSampleRows() throws SuiviObsmerException { + public ElligibleBoatsCompany getElligibleSampleRows() throws SuiviObsmerException { // if (elligibleSampleRows == null && boatSelectedImmatriculation != null) { // Boat selectedBoat = getBoats().get(boatSelectedImmatriculation); // if (log.isInfoEnabled()) { @@ -437,8 +437,14 @@ return BusinessUtils.getTooltipSampleRow(elligibleBoat.getSampleRow()); } + public boolean isElligibleBoatCompanyActiveFalse() { + return BooleanUtils.isFalse(elligibleBoat.getCompanyActive()); + } + public String getElligibleRowClass() { - return !elligibleBoat.getActive() ? "line-through" : ""; + boolean condition1 = elligibleBoat.getCompanyActive() == null && !elligibleBoat.getGlobalActive(); + + return condition1 || isElligibleBoatCompanyActiveFalse() ? "line-through" : ""; } public Company getCompany() throws SuiviObsmerException { @@ -485,42 +491,26 @@ void onSelectedFromAddBoatInfosSampleRow() throws SuiviObsmerException { // We stay in edition mode boatInfosEditable = true; - if (!StringUtils.isEmpty(boatInfosSampleRowCode) && !elligibleSampleRows.containsKey(boatInfosSampleRowCode)) { + if (!StringUtils.isEmpty(boatInfosSampleRowCode)) { SampleRow row = getSampleRowSelectModel().findObject(boatInfosSampleRowCode); - elligibleSampleRows.put(boatInfosSampleRowCode, - serviceBoat.getNewElligibleBoat(row, getCompany(), boatInfos.getBoat())); + elligibleSampleRows.setNewElement(row); } } void onSelectedFromRemoveBoatInfosSampleRow(String sampleRowCode) throws SuiviObsmerException { boatInfosEditable = true; - ElligibleBoat elligible = getElligibleSampleRows().get(sampleRowCode); - if (elligible.getCompany() == null) { - // Create a new ElligibleBoat inactive linked with the company of the current user - //SampleRow row = elligible.getSampleRow(); - //elligible = serviceBoat.getNewElligibleBoat(row, getCompany(), boatInfos.getBoat()); - elligible.setActive(false); - //getElligibleSampleRows().put(sampleRowCode, elligible); - } else { - // Remove the existing ElligibleBoat - getElligibleSampleRows().remove(sampleRowCode); - } + elligibleSampleRows.removeElement(sampleRowCode); } void onSelectedFromActiveBoatInfosSampleRow(String sampleRowCode) throws SuiviObsmerException { boatInfosEditable = true; - ElligibleBoat elligible = getElligibleSampleRows().get(sampleRowCode); - elligible.setActive(true); + elligibleSampleRows.activeElement(sampleRowCode); } Block onSuccessFromBoatInfosForm() throws SuiviObsmerException { if (!boatInfosEditable) { // Save data - - // Elligible rows - // for each ElligibleBoat, - // if (inactive && nocompany) create new linked with company - // if (active && company) check if not already exist with nocompany, and remove it + serviceBoat.createUpdateBoatInfos(boatInfos, elligibleSampleRows); } return boatInfosZone.getBody(); } @@ -543,7 +533,7 @@ // Get selected boat from BoatInfos boat = getBoatInfos().getBoat(); // Get sampleRow from elligibleBoat list - sampleRow = getElligibleSampleRows().get(sampleRowCode).getSampleRow(); + sampleRow = getSampleRowSelectModel().findObject(sampleRowCode); contacts.createNewContact(boat, sampleRow); return contacts; } Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java 2009-12-07 16:06:52 UTC (rev 100) @@ -1,7 +1,7 @@ package fr.ifremer.suiviobsmer.ui.pages; -import fr.ifremer.suiviobsmer.PeriodDates; + import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.entity.Company; import fr.ifremer.suiviobsmer.entity.FishingZone; @@ -23,6 +23,7 @@ import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.upload.services.UploadedFile; +import fr.ifremer.suiviobsmer.PeriodDates; import org.slf4j.Logger; /** Modified: trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties =================================================================== --- trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties 2009-12-07 16:06:52 UTC (rev 100) @@ -19,4 +19,5 @@ contactFirstName-label: Pr\u00E9nom contactLastName-label: Nom contactPhoneNumber-label: T\u00E9l\u00E9phone -contactEmail-label: E-mail \ No newline at end of file +contactEmail-label: E-mail +dup-label: Capacit\u00E9 d'accueil du navire en personnels sp\u00E9cialis\u00E9s \ No newline at end of file Modified: trunk/suiviobsmer-ui/src/main/webapp/Boats.tml =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2009-12-07 10:02:15 UTC (rev 99) +++ trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2009-12-07 16:06:52 UTC (rev 100) @@ -139,9 +139,9 @@ </fieldset> <!-- Corps - embarquement --> <fieldset id="so-boats-boat-infos-boarding"> - <legend>Informations sur les embarquements</legend> + <legend>Autres informations sur le navire</legend> <div> - <p><label>Dup : </label>${boatInfos.dup}</p> + <p><label>${message:dup-label} : </label>${boatInfos.dup}</p> <p class="sep"> </p> <p> <strong>${boatInfos.nbBoarding}</strong> embarquements @@ -184,9 +184,8 @@ <a t:type="actionlink" t:id="cancelEditBoatInfos" t:zone="so-boats-boat-infos"> <img src="${asset:context:}/img/undo-22px.png" title="Annuler les modifications"/> </a> - <!--a t:type="actionlink" t:id="saveBoatIndos" t:zone="so-boats-boat-infos"--> - <img src="${asset:context:}/img/save-22px.png" title="Enregistrer les modifications"/> - <!--/a--> + <input t:type="submit" t:id="saveBoatInfos" class="ico22px save22px" value="Save" + title="Enregistrer les modifications" /> </div> </div> <!-- Corps - contact --> @@ -204,7 +203,7 @@ </fieldset> <!-- Corps - embarquement --> <fieldset id="so-boats-boat-infos-boarding"> - <legend>Informations sur les embarquements</legend> + <legend>Autres informations sur le navire</legend> <div> <p><t:label t:for="dup"/> : <input t:type="textfield" t:id="dup" class="dup" value="boatInfos.dup" /></p> <p class="sep"> </p> @@ -222,12 +221,12 @@ ${elligibleBoat.sampleRow.code} </span> </span> - <t:if t:test="elligibleBoat.active"> - <input t:type="submitContext" t:id="removeBoatInfosSampleRow" class="ico remove" value="Remove" - t:context="elligibleBoat.sampleRow.code" title="Dissocier le navire de cette ligne du plan" /> - <p:else> - <input t:type="submitContext" t:id="activeBoatInfosSampleRow" class="ico add" value="Active" + <t:if t:test="elligibleBoatCompanyActiveFalse"> + <input t:type="submitContext" t:id="activeBoatInfosSampleRow" class="ico add" value="Active" t:context="elligibleBoat.sampleRow.code" title="Réactiver cette ligne du plan" /> + <p:else> + <input t:type="submitContext" t:id="removeBoatInfosSampleRow" class="ico remove" value="Remove" + t:context="elligibleBoat.sampleRow.code" title="Dissocier le navire de cette ligne du plan" /> </p:else> </t:if> </li>