[Suiviobsmer-commits] r473 - in trunk: . wao-business wao-business/src/main/java/fr/ifremer/wao/entity wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/xmi wao-business/src/test/java/fr/ifremer/wao wao-business/src/test/java/fr/ifremer/wao/service wao-ui
Author: fdesbois Date: 2010-04-29 21:50:44 +0000 (Thu, 29 Apr 2010) New Revision: 473 Log: - Ano #2282 : Change count (problem with distinct) + improve elligibleBoat save (one instance for each sampleRow/boat couple) - Improve elligibleBoat logs in sampleRow update - Add abstract test class Added: trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java Modified: trunk/changelog.txt trunk/pom.xml trunk/wao-business/pom.xml 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/service/ServiceBoatImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java trunk/wao-ui/pom.xml Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2010-04-29 05:32:50 UTC (rev 472) +++ trunk/changelog.txt 2010-04-29 21:50:44 UTC (rev 473) @@ -3,6 +3,19 @@ Historique des versions +1.2.1 +----- + +Anomalies ++++++++++ + +- [fdesbois] Ano #2282 : Doublon sur les navires éligibles pour une ligne. + +Mise à jour librairies +++++++++++++++++++++++ + +- **mavenpom4labs** 2.1 -> 2.1.3 [http://maven-site.nuiton.org/mavenpom/mavenpom4labs] + 1.2 ---- @@ -30,8 +43,8 @@ - [fdesbois] Ano #2245 : Erreur création ligne du plan : le chargement des colonnes des mois en fonction de la période ne fonctionne pas. -Dépendances -+++++++++++ +Mise à jour librairies +++++++++++++++++++++++ - **mavenpom4labs** 2.0.7 -> 2.1 [http://maven-site.nuiton.org/mavenpom/mavenpom4labs] - **Nuiton-utils** 1.2.1 -> 1.2.2 [http://maven-site.nuiton.org/nuiton-utils] Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2010-04-29 05:32:50 UTC (rev 472) +++ trunk/pom.xml 2010-04-29 21:50:44 UTC (rev 473) @@ -15,7 +15,7 @@ <groupId>fr.ifremer</groupId> <artifactId>wao</artifactId> - <version>1.3-SNAPSHOT</version> + <version>1.2.1-SNAPSHOT</version> <modules> <module>wao-ui</module> Modified: trunk/wao-business/pom.xml =================================================================== --- trunk/wao-business/pom.xml 2010-04-29 05:32:50 UTC (rev 472) +++ trunk/wao-business/pom.xml 2010-04-29 21:50:44 UTC (rev 473) @@ -10,7 +10,7 @@ <parent> <groupId>fr.ifremer</groupId> <artifactId>wao</artifactId> - <version>1.3-SNAPSHOT</version> + <version>1.2.1-SNAPSHOT</version> </parent> <groupId>fr.ifremer.wao</groupId> 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-04-29 05:32:50 UTC (rev 472) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2010-04-29 21:50:44 UTC (rev 473) @@ -191,32 +191,36 @@ } /** - * Check if the sampleRow has an ElligibleBoat corresponding to the boat in argument. - * The test return true only if it's a global ElligbleBoat set by an admin and not by a user (companyActive). - * @param boat Boat to test - * @return true if the ElligibleBoat is find, false otherwise + * Retrieve the elligibleBoat corresponding to the {@code boat}. + * + * @param boat Boat referenced by the ElligibleBoat + * @return the existing ElligibleBoat or null otherwise */ @Override - public boolean hasElligibleBoat(Boat boat) { - for (ElligibleBoat elligible : this.getElligibleBoat()) { - String elligibleBoatTopiaId = elligible.getBoat().getTopiaId(); - if (elligibleBoatTopiaId.equals(boat.getTopiaId()) && elligible.getCompanyActive() == null) { - return true; + public ElligibleBoat getElligibleBoatByBoat(Boat boat) { + for (ElligibleBoat elligible : getElligibleBoat()) { + if (elligible.getBoat().equals(boat)) { + return elligible; } } - return false; + return null; } /** - * Check from the list of ElligibleBoat linked with the SampleRow if the boats in argument corresponding. - * The argument means new boats to linked with SampleRow, so an ElligibleBoat not contains in this list is removed. + * Check from the list of ElligibleBoat linked with the SampleRow if the + * boats in argument corresponding. The argument means new boats to + * linked with SampleRow, so an ElligibleBoat not contains in this list + * is removed. * - * @param boats a List of Boats to check with ElligibleBoats linked with the SampleRow. - * @see fr.ifremer.wao.impl.ServiceSamplingImpl#createUpdateSampleRow(fr.ifremer.wao.entity.SampleRow, java.util.List) + * @param boats a List of Boats to check with ElligibleBoats linked with + * the SampleRow. + * @return the list of boat immatriculations that are removed (used for log) + * @see fr.ifremer.wao.service.ServiceSampling#createUpdateSampleRow(SampleRow, List) */ @Override - public void removeNoLongerElligibleBoats(List<Boat> boats) { + public List<Integer> removeNoLongerElligibleBoats(List<Boat> boats) { Iterator<ElligibleBoat> it = getElligibleBoat().iterator(); + List<Integer> updatedImmatriculations = new ArrayList<Integer>(); while (it.hasNext()) { ElligibleBoat elligible = it.next(); String elligibleBoatTopiaId = elligible.getBoat().getTopiaId(); @@ -234,8 +238,11 @@ } else { elligible.setGlobalActive(false); } + updatedImmatriculations.add( + elligible.getBoat().getImmatriculation()); } } + return updatedImmatriculations; } /** @@ -248,7 +255,7 @@ public String getMainElligibleBoatsAsString() { String result = ""; for (ElligibleBoat elligible : getElligibleBoat()) { - if (elligible.getCompanyActive() == null) { + if (elligible.getGlobalActive()) { Boat boat = elligible.getBoat(); result += boat.getImmatriculation() + " "; } 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-04-29 05:32:50 UTC (rev 472) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowLogImpl.java 2010-04-29 21:50:44 UTC (rev 473) @@ -27,8 +27,10 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.List; import org.apache.commons.lang.StringUtils; import org.nuiton.util.PeriodDates; +import org.nuiton.util.StringUtil; /** * SampleRowLogImpl @@ -138,5 +140,20 @@ } } + + @Override + public void addNewBoats(List<Integer> newBoats) { + if (!newBoats.isEmpty()) { + addChange("Les navires suivant deviennent éligibles : " + newBoats); + } + } + + @Override + public void addRemoveBoats(List<Integer> removedBoats) { + if (!removedBoats.isEmpty()) { + addChange("Les navires suivant ne sont plus éligibles : " + + removedBoats); + } + } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-04-29 05:32:50 UTC (rev 472) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-04-29 21:50:44 UTC (rev 473) @@ -129,7 +129,9 @@ query = createQueryForBoatFilter(query, filter); - return query.executeCount(); + // Ano #560 in ToPIA, distinct will be manage in executeCount() for 2.4 + //return query.executeCount(); + return query.executeToInteger("COUNT(DISTINCT B)"); } protected TopiaQuery createQueryForBoatFilter(TopiaQuery query, @@ -151,7 +153,7 @@ // Test only valid ElligibleBoat for that company query.add("E." + ElligibleBoat.COMPANY_ACTIVE + " = :booleanTrue " + - "OR (E." + ElligibleBoat.COMPANY_ACTIVE + + "OR (E." + ElligibleBoat.COMPANY_ACTIVE + " IS NULL AND E." + ElligibleBoat.GLOBAL_ACTIVE + " = :booleanTrue)"); query.addParam("booleanTrue", Boolean.TRUE); 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-04-29 05:32:50 UTC (rev 472) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-04-29 21:50:44 UTC (rev 473) @@ -47,6 +47,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Array; import java.text.DateFormat; import java.text.NumberFormat; import java.text.ParseException; @@ -211,25 +212,17 @@ monthDAO.update(month); } - // Remove no longer elligibleBoats - row.removeNoLongerElligibleBoats(boats); - // Save new elligibleBoats - ElligibleBoatDAO dao = WaoDAOHelper.getElligibleBoatDAO(transaction); - for (Boat boat : boats) { - if (!row.hasElligibleBoat(boat)) { - ElligibleBoat elligibleBoat = dao.create(); - elligibleBoat.setSampleRow(row); - elligibleBoat.setGlobalActive(true); - elligibleBoat.setBoat(boat); - row.addElligibleBoat(elligibleBoat); - } - } + List<List<Integer>> immatriculations = + updateElligibleBoats(transaction, row, boats); - // ChangeLog boats - String oldBoats = oldRow != null ? oldRow.getMainElligibleBoatsAsString() : ""; - rowLog.addChangeBoats(oldBoats, row.getMainElligibleBoatsAsString()); + // ChangeLog boats (index=0 for removed, index=1 for new) + rowLog.addRemoveBoats(immatriculations.get(0)); + rowLog.addNewBoats(immatriculations.get(1)); +// String oldBoats = oldRow != null ? oldRow.getMainElligibleBoatsAsString() : ""; +// rowLog.addNewBoats(immatriculations.get(1)); + // Remove no longer linked FishingZone List<FishingZone> newZones = row.getFishingZone(); for (FishingZone oldZone : oldZones) { @@ -268,6 +261,58 @@ } } + /** + * Update elligibleBoats for admin. The {@code boats} list correspond to + * the needed elligibleBoats for the {@code row}. The old elligibeBoats + * (no link with company) will be deleted if not contained in the + * {@code boats} list. New elligibleBoats will be created for new referenced + * {@code boats} and existing elligibleBoats linked with company will be + * updated (globalActive set to true). + * + * @param transaction to retrieve correct dao + * @param row which reference the existing ElligibleBoats + * @param boats used to check the existing ElligibleBoats + * @return two Lists : index = 0 for removedImmatriculations and index = 1 + * for updateImmatriculations + * @throws TopiaException + */ + protected List<List<Integer>> updateElligibleBoats(TopiaContext transaction, + SampleRow row, List<Boat> boats) throws TopiaException { + + List<List<Integer>> results = new ArrayList<List<Integer>>(); + + // Remove no longer elligibleBoats + List<Integer> removedImmatriculations = + row.removeNoLongerElligibleBoats(boats); + + // index = 0 + results.add(removedImmatriculations); + + // Save new elligibleBoats + ElligibleBoatDAO dao = WaoDAOHelper.getElligibleBoatDAO(transaction); + List<Integer> updatedImmatriculations = new ArrayList<Integer>(); + // index = 1 + results.add(updatedImmatriculations); + + for (Boat boat : boats) { + ElligibleBoat elligibleBoat = row.getElligibleBoatByBoat(boat); + // Create new ElligibleBoat + if (elligibleBoat == null) { + elligibleBoat = dao.create(); + elligibleBoat.setBoat(boat); + row.addElligibleBoat(elligibleBoat); + updatedImmatriculations.add(boat.getImmatriculation()); + } + // Update globalActive to true if needed + if (!elligibleBoat.getGlobalActive()) { + elligibleBoat.setGlobalActive(true); + updatedImmatriculations.add(boat.getImmatriculation()); + } + } + + return results; + } + @Override public FacadeRow executeGetSampleRowsOrderedByFishingZone( TopiaContext transaction, Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Added: trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java (rev 0) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java 2010-04-29 21:50:44 UTC (rev 473) @@ -0,0 +1,283 @@ + +package fr.ifremer.wao; + +import fr.ifremer.wao.entity.Boat; +import fr.ifremer.wao.entity.BoatDAO; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.CompanyDAO; +import fr.ifremer.wao.entity.ElligibleBoat; +import fr.ifremer.wao.entity.ElligibleBoatDAO; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowDAO; +import fr.ifremer.wao.service.ServiceSamplingImpl; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; + +/** + * AbstractServiceTest + * + * Created: 29 avr. 2010 + * + * @author fdesbois + */ +public abstract class AbstractServiceTest { + + protected static TestManager manager; + + protected ServiceSamplingImpl serviceSampling; + + protected static final String BOAT_DEFAULT_NAME = "SPRINGFIELD"; + protected static final int BOAT_DEFAULT_IMMATRICULATION = 123456; + protected static final String SAMPLE_ROW_DEFAULT_CODE = "2010_0001"; + protected static final String COMPANY_DEFAULT_NAME = "TARTANPION"; + + @BeforeClass + public static void setUpClass() throws Exception { + manager = new TestManager(); + } + + @Before + public void setUp() throws Exception { + manager.start(); + serviceSampling = manager.getServiceSampling(); + } + + @After + public void tearDown() throws Exception { + manager.stop(); + } + + /** + * Create a company : <br /> + * <ul> + * <li>name : TARTANPION</li> + * </ul> + * + * @return the new Company + * @throws TopiaException + */ + protected Company createDefaultCompany() throws TopiaException { + return createCompany(COMPANY_DEFAULT_NAME); + } + + /** + * Create a company : <br /> + * <ul> + * <li>name : defined with {@code name} argument</li> + * </ul> + * + * @param name + * @return the new Company + * @throws TopiaException + */ + protected Company createCompany(String name) throws TopiaException { + Company company = null; + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + CompanyDAO dao = WaoDAOHelper.getCompanyDAO(transaction); + + company = dao.create(); + company.setName(name); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + return company; + } + + /** + * Create a default sampleRow : <br /> + * <ul> + * <li>code : 2010_0001</li> + * <li>company : TARTANPION</li> + * </ul> + * + * @return the new SampleRow + * @throws TopiaException + */ + protected SampleRow createDefaultSampleRow() throws TopiaException { + return createSampleRow(SAMPLE_ROW_DEFAULT_CODE, findDefaultCompany()); + } + + /** + * Create a default sampleRow : <br /> + * <ul> + * <li>code : defined with {@code code} argument</li> + * <li>company : defined with {@code company} argument</li> + * </ul> + * + * @param code + * @param company + * @return the new SampleRow + * @throws TopiaException + */ + protected SampleRow createSampleRow(String code, Company company) + throws TopiaException { + SampleRow row = null; + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + SampleRowDAO dao = + WaoDAOHelper.getSampleRowDAO(transaction); + + row = dao.create(); + row.setCode(code); + row.setCompany(company); + + transaction.commitTransaction(); + } finally { + transaction.closeContext(); + } + + return row; + } + + /** + * Create a default boat : <br /> + * <ul> + * <li>immatriculation : 123456</li> + * <li>name : SPRINGFIELD</li> + * <li>active : true</li> + * </ul> + * + * @return the new Boat + * @throws TopiaException + */ + protected Boat createDefaultBoat() throws TopiaException { + return createBoat(123456, "SPRINGFIELD"); + } + + /** + * Create a boat : <br /> + * <ul> + * <li>immatriculation : defined with {@code immatriculation} argument</li> + * <li>name : defined with {@code name} argument</li> + * <li>active : true</li> + * </ul> + * + * @param immatriculation + * @param name + * @return the new Boat + * @throws TopiaException + */ + protected Boat createBoat(int immatriculation, String name) + throws TopiaException { + Boat boat = null; + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); + + // CREATE + boat = dao.create(); + boat.setImmatriculation(immatriculation); + boat.setName(name); + boat.setActive(true); + + transaction.commitTransaction(); + + } finally { + transaction.closeContext(); + } + return boat; + } + + /** + * Create an elligibleBoat : <br /> + * <ul> + * <li>sampleRow : defined with {@code row} argument</li> + * <li>boat : defined with {@code boat} argument</li> + * <li>companyActive : true if {@code company} is true, null otherwise</li> + * <li>globalActive : true if {@code company} is false, false otherwise</li> + * </ul> + * + * @param row to set for ElligibleBoat + * @param boat to set for ElligibleBoat + * @param company true for companyActive, false for globalActive + * @return the new ElligibleBoat + * @throws TopiaException + */ + protected ElligibleBoat createElligibleBoat(SampleRow row, Boat boat, + boolean company) throws TopiaException { + + ElligibleBoat elligibleBoat = null; + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + ElligibleBoatDAO dao = + WaoDAOHelper.getElligibleBoatDAO(transaction); + + // CREATE + elligibleBoat = dao.create(); + elligibleBoat.setBoat(boat); + elligibleBoat.setSampleRow(row); + if (company) { + elligibleBoat.setCompanyActive(true); + } else { + elligibleBoat.setGlobalActive(true); + } + transaction.commitTransaction(); + + } finally { + transaction.closeContext(); + } + return elligibleBoat; + } + + protected Company findDefaultCompany() throws TopiaException { + Company findCompany = findCompanyByName(BOAT_DEFAULT_NAME); + if (findCompany == null) { + findCompany = createDefaultCompany(); + } + return findCompany; + } + + protected Company findCompanyByName(String name) throws TopiaException { + Company company = null; + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + CompanyDAO dao = WaoDAOHelper.getCompanyDAO(transaction); + + company = dao.findByName(name); + } finally { + transaction.closeContext(); + } + return company; + } + + protected SampleRow findDefaultSampleRow(String... properties) + throws TopiaException { + SampleRow findRow = findSampleRowByCode( + SAMPLE_ROW_DEFAULT_CODE, properties); + + if (findRow == null) { + findRow = createDefaultSampleRow(); + } + return findRow; + } + + protected SampleRow findSampleRowByCode(String code, String... properties) + throws TopiaException { + SampleRow row = null; + TopiaContext transaction = manager.getContext().beginTransaction(); + try { + SampleRowDAO dao = + WaoDAOHelper.getSampleRowDAO(transaction); + + row = dao.findByCode(code); + if (row != null) { + // Load properties + for (String property : properties) { + if (property.equals(SampleRow.ELLIGIBLE_BOAT)) { + row.sizeElligibleBoat(); + } + } + } + } finally { + transaction.closeContext(); + } + return row; + } +} Property changes on: trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-04-29 05:32:50 UTC (rev 472) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-04-29 21:50:44 UTC (rev 473) @@ -136,7 +136,7 @@ return instance; } - public ServiceSampling getServiceSampling() { + public ServiceSamplingImpl getServiceSampling() { ServiceSamplingImpl instance = new ServiceSamplingImpl(); instance.setContext(getContext()); return instance; 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-04-29 05:32:50 UTC (rev 472) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2010-04-29 21:50:44 UTC (rev 473) @@ -25,13 +25,13 @@ package fr.ifremer.wao.service; +import fr.ifremer.wao.AbstractServiceTest; import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoDAOHelper; import fr.ifremer.wao.WaoException; import fr.ifremer.wao.bean.ImportResults; import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.bean.SamplingFilterImpl; -import fr.ifremer.wao.TestManager; import fr.ifremer.wao.bean.FacadeRow; import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Company; @@ -55,11 +55,7 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.List; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; @@ -76,37 +72,11 @@ * * @author fdesbois <fdesbois at codelutin.com> */ -public class ServiceSamplingImplTest { +public class ServiceSamplingImplTest extends AbstractServiceTest { - private static TestManager manager; + private static final Logger log = + LoggerFactory.getLogger(ServiceSamplingImplTest.class); - private static final Logger log = LoggerFactory.getLogger(ServiceSamplingImplTest.class); - - private ServiceSampling service; - - public ServiceSamplingImplTest() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - manager = new TestManager(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Before - public void setUp() throws Exception { - manager.start(); - service = manager.getServiceSampling(); - } - - @After - public void tearDown() throws Exception { - manager.stop(); - } - @Test public void testCreateUpdateSampleRow() throws Exception { log.info("createUpdateSampleRow"); @@ -145,7 +115,7 @@ months.add(month); } - SampleRow row = service.getNewSampleRow(); + SampleRow row = serviceSampling.getNewSampleRow(); row.setCode("2010_03"); row.setNbObservants(3); row.setAverageTideTime(2.5); @@ -159,31 +129,67 @@ /** EXEC CREATE **/ List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174592 978419 273129"); - service.createUpdateSampleRow(row, boats, new SampleRowLogImpl()); + serviceSampling.createUpdateSampleRow(row, boats, new SampleRowLogImpl()); assertNotNull(row.getTopiaId()); assertNotNull(row.getProfession().getTopiaId()); - SampleRow result = service.getSampleRow(row.getTopiaId()); + SampleRow result = serviceSampling.getSampleRow(row.getTopiaId()); assertEquals(3, result.getFishingZone().size()); assertEquals(3, result.getElligibleBoat().size()); // TEST FOR DELETE ELLIGIBLE BOAT boats.remove(2); - service.createUpdateSampleRow(result, boats, new SampleRowLogImpl()); + serviceSampling.createUpdateSampleRow(result, boats, new SampleRowLogImpl()); - result = service.getSampleRow(row.getTopiaId()); + result = serviceSampling.getSampleRow(row.getTopiaId()); assertEquals(2, result.getElligibleBoat().size()); // TEST FOR REMOVE FISHING ZONE //FishingZone zone = result.getFishingZone().get(0); result.getFishingZone().remove(0); - service.createUpdateSampleRow(result, boats, new SampleRowLogImpl()); + serviceSampling.createUpdateSampleRow(result, boats, new SampleRowLogImpl()); - result = service.getSampleRow(row.getTopiaId()); + result = serviceSampling.getSampleRow(row.getTopiaId()); assertEquals(2, result.getFishingZone().size()); } + @Test + public void testUpdateElligibleBoats() throws TopiaException { + log.info("testUpdateElligibleBoats"); + + /** PREPARE DATA **/ + SampleRow row = createDefaultSampleRow(); + Boat boat = createDefaultBoat(); + + // Create an elligibleBoat active for company + ElligibleBoat elligible = createElligibleBoat(row, boat, true); + // Retrieve the sampleRow (updated with elligible) + row = findDefaultSampleRow(SampleRow.ELLIGIBLE_BOAT); + + /** EXEC METHOD **/ + List<Boat> boats = new ArrayList<Boat>(); + boats.add(boat); + + TopiaContext transaction = serviceSampling.beginTransaction(); + // Will update the existing ElligibleBoat and set globalActive to true + List<List<Integer>> results = + serviceSampling.updateElligibleBoats(transaction, row, boats); + + /** CHECKING RESULTS **/ + Assert.assertEquals(2, results.size()); + // Index=1 for updatedImmatriculations, 1 is updated + Assert.assertEquals(1, results.get(1).size()); + // Index=0 for removedImmatriculations, 0 is removed + Assert.assertEquals(0, results.get(0).size()); + + Assert.assertEquals(1, row.sizeElligibleBoat()); + ElligibleBoat updatedElligible = + row.getElligibleBoatByTopiaId(elligible.getTopiaId()); + + Assert.assertTrue(updatedElligible.getGlobalActive()); + } + /** * Test of getSampleRowsOrderedByFishingZone method, of class ServiceSamplingImpl. */ @@ -257,7 +263,7 @@ SamplingFilter filter = new SamplingFilterImpl(); filter.setPeriod(new PeriodDates(begin, end)); // RESULT : [2010_0002, 2010_0004, 2010_0001, 2010_0003] - FacadeRow facade = service.getSampleRowsOrderedByFishingZone(filter, null); + FacadeRow facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter, null); List<SampleRow> rows = facade.getValues(); assertEquals(4, rows.size()); SampleRow resultRow0 = rows.get(0); @@ -287,7 +293,7 @@ end = new GregorianCalendar(2020, 11, 31, 0, 0, 0); filter.setPeriod(new PeriodDates(begin, end)); // RESULT : [2010_0002, 2010_0004, 2010_0001] - facade = service.getSampleRowsOrderedByFishingZone(filter, null); + facade = serviceSampling.getSampleRowsOrderedByFishingZone(filter, null); rows = facade.getValues(); assertEquals(3, rows.size()); resultRow0 = rows.get(0); @@ -350,7 +356,7 @@ transaction.closeContext(); InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - service.importSamplingPlanCsv(input); + serviceSampling.importSamplingPlanCsv(input); /** EXEC METHOD **/ SamplingFilter filter = new SamplingFilterImpl(); @@ -358,14 +364,14 @@ // admin.setAdmin(true); // filter.setCompany() filter.setNbMonthFinishedFromToday(0); - List<SampleRow> results = service.getSampleRowsByFilter(filter); + List<SampleRow> results = serviceSampling.getSampleRowsByFilter(filter); // total in file : 11, 1 refused, 1 finished assertEquals(9, results.size()); // User user = new UserImpl(); // user.setCompany(company); filter.setCompany(company); - results = service.getSampleRowsByFilter(filter); + results = serviceSampling.getSampleRowsByFilter(filter); assertEquals(1, results.size()); } @@ -406,7 +412,7 @@ transaction.closeContext(); /** EXEC METHOD **/ - Profession newProfession = service.getNewProfession(profession); + Profession newProfession = serviceSampling.getNewProfession(profession); Assert.assertNotSame(profession, newProfession); Assert.assertEquals("OBR", newProfession.getCodeDCF5()); Assert.assertEquals("Fileyage en barre", newProfession.getLibelle()); @@ -435,7 +441,7 @@ InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - service.importSamplingPlanCsv(input); + serviceSampling.importSamplingPlanCsv(input); SampleRowDAO rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); SampleRow row = rowDAO.findByCode("2010_0001"); @@ -450,10 +456,10 @@ serviceBoat.importBoatCsv(input); List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174592 978419 273129"); - service.createUpdateSampleRow(row, boats, new SampleRowLogImpl()); + serviceSampling.createUpdateSampleRow(row, boats, new SampleRowLogImpl()); /** EXEC METHOD **/ - service.deleteSampleRow(row); + serviceSampling.deleteSampleRow(row); transaction = manager.getContext().beginTransaction(); rowDAO = WaoDAOHelper.getSampleRowDAO(transaction); row = rowDAO.findByCode("2010_0001"); @@ -486,7 +492,7 @@ /** EXEC METHOD **/ InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - ImportResults result = service.importSamplingPlanCsv(input); + ImportResults result = serviceSampling.importSamplingPlanCsv(input); // total imported assertEquals(12, result.getNbRowsImported()); @@ -549,10 +555,10 @@ transaction.closeContext(); InputStream input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - service.importSamplingPlanCsv(input); + serviceSampling.importSamplingPlanCsv(input); /** EXEC METHOD **/ - List<String> programs = service.getPrograms(null); + List<String> programs = serviceSampling.getPrograms(null); assertEquals(4, programs.size()); } @@ -584,7 +590,7 @@ Calendar begin = new GregorianCalendar(2009, 11, 1); - String result = service.getNewSampleRowCode(begin.getTime()); + String result = serviceSampling.getNewSampleRowCode(begin.getTime()); Assert.assertEquals("2009_0007", result); // Test regex for replacment in importSamplingPlanCsv Modified: trunk/wao-ui/pom.xml =================================================================== --- trunk/wao-ui/pom.xml 2010-04-29 05:32:50 UTC (rev 472) +++ trunk/wao-ui/pom.xml 2010-04-29 21:50:44 UTC (rev 473) @@ -10,7 +10,7 @@ <parent> <groupId>fr.ifremer</groupId> <artifactId>wao</artifactId> - <version>1.3-SNAPSHOT</version> + <version>1.2.1-SNAPSHOT</version> </parent> <groupId>fr.ifremer.wao</groupId> @@ -203,9 +203,9 @@ </build> </profile> </profiles> - <repositories> +<!-- <repositories> - <!-- Repository for fckeditor component needed for News page --> + Repository for fckeditor component needed for News page <repository> <id>m2-release-repository.orientimport.kenai.com</id> <name>Orient Import Oy Maven Release Repository</name> @@ -219,7 +219,7 @@ <url>http://tapestry.formos.com/maven-repository</url> </repository> - </repositories> + </repositories>--> <scm> <url>http://labs.libre-entreprise.org/scm/viewvc.php/trunk/wao-ui/?root=suiviobsmer</url>
participants (1)
-
fdesbois@users.labs.libre-entreprise.org