[Suiviobsmer-commits] r1235 - in trunk/wao-business/src: main/java/fr/ifremer/wao/io/csv2 main/java/fr/ifremer/wao/service main/resources/i18n main/xmi test/java/fr/ifremer/wao/service
Author: bleny Date: 2011-04-22 12:35:30 +0000 (Fri, 22 Apr 2011) New Revision: 1235 Log: add synthesis for hours of osbservation Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv2/Column.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties trunk/wao-business/src/main/resources/i18n/wao-business_fr_FR.properties trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-business/src/test/java/fr/ifremer/wao/service/ObsDebTest.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv2/Column.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv2/Column.java 2011-04-22 12:33:57 UTC (rev 1234) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv2/Column.java 2011-04-22 12:35:30 UTC (rev 1235) @@ -38,13 +38,16 @@ protected ValueSetter<E, T> valueSetter; + /** Column for import */ public Column(String headerName, ValueParser<T> valueParser, ValueSetter<E, T> valueSetter, boolean ignored) { this.headerName = headerName; this.valueParser = valueParser; this.valueSetter = valueSetter; this.ignored = ignored; + this.mandatory = ! ignored; } + /** Column for export, ignored at import */ public Column(String headerName, ValueGetter<E, T> valueGetter, ValueFormatter<T> valueFormatter) { this.headerName = headerName; this.valueGetter = valueGetter; @@ -52,6 +55,7 @@ this.ignored = true; } + /** Column for both import and export */ public Column(String headerName, ValueGetterSetter<E, T> valueGetterSetter, ValueParserFormatter<T> valueParserFormatter) { this.headerName = headerName; this.valueGetter = valueGetterSetter; @@ -106,7 +110,7 @@ public void setValue(E object, T value) throws Exception { if ( ! isIgnored()) { if (valueSetter == null) { - throw new UnsupportedOperationException("no setter provided"); + throw new UnsupportedOperationException("no setter provided for " + this); } else { valueSetter.set(object, value); } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2011-04-22 12:33:57 UTC (rev 1234) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2011-04-22 12:35:30 UTC (rev 1235) @@ -519,7 +519,7 @@ @Override protected void executeImportInitialContactStateMotifs(TopiaContext transaction) throws Exception { ContactStateMotifDAO contactStateMotifDAO = WaoDAOHelper.getContactStateMotifDAO(transaction); - int count = contactStateMotifDAO.count(); + long count = contactStateMotifDAO.count(); if (count == 0) { List<ContactStateMotif> motifs = new LinkedList<ContactStateMotif>(); 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 2011-04-22 12:33:57 UTC (rev 1234) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2011-04-22 12:35:30 UTC (rev 1235) @@ -55,6 +55,7 @@ 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.ContactStateMotif; import fr.ifremer.wao.entity.Indicator; import fr.ifremer.wao.entity.IndicatorDAO; @@ -64,6 +65,8 @@ import fr.ifremer.wao.entity.IndicatorLogImpl; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.WaoUser; +import org.apache.commons.collections.OrderedMap; +import org.apache.commons.collections.map.HashedMap; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; @@ -1244,5 +1247,51 @@ // return results; } + + @Override + protected Map<String, Map<String, Integer>> executeGetObservationHours(TopiaContext transaction, SamplingFilter samplingFilter) throws Exception { + WaoQueryBuilder builder = context.newQueryBuilder(); + builder.initializeForContact(); + TopiaQuery query = builder.applySamplingFilter(samplingFilter); + ContactDAO contactDAO = WaoDAOHelper.getContactDAO(transaction); + List<Contact> contacts = contactDAO.findAllByQuery(query); + if (log.isDebugEnabled()) { + log.debug(contacts.size() + " found for observation hours synthesis"); + } + SimpleDateFormat yearFormat = new SimpleDateFormat("yyyy"); + SimpleDateFormat hourFormat = new SimpleDateFormat("HH:00"); + Map<String, Map<String, Integer>> result = new TreeMap<String, Map<String, Integer>>(); + + for (Contact contact : contacts) { + String year = yearFormat.format(contact.getObservationBeginDate()); + String hour = hourFormat.format(contact.getObservationBeginDate()); + + Map<String, Integer> yearToObservationCount = result.get(hour); + if (yearToObservationCount == null) { + yearToObservationCount = new TreeMap<String, Integer>(); + result.put(hour, yearToObservationCount); + } + Integer count = yearToObservationCount.get(year); + if (count == null) { + count = 0; + } + count += 1; + yearToObservationCount.put(year, count); + } + + if (log.isDebugEnabled()) { + log.debug("observation hours synthesis returns "); + for (Map.Entry<String, Map<String, Integer>> entry : result.entrySet()) { + String hour = entry.getKey(); + for (Map.Entry<String, Integer> yearToObservationCount : entry.getValue().entrySet()) { + String year = yearToObservationCount.getKey(); + Integer count = yearToObservationCount.getValue(); + log.debug(hour + " " + year + " " + count); + } + } + } + + return result; + } } Modified: trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties 2011-04-22 12:33:57 UTC (rev 1234) +++ trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties 2011-04-22 12:35:30 UTC (rev 1235) @@ -232,6 +232,7 @@ wao.error.serviceSynthesis.getGlobalSynthesisParameters=Unable to get data about global synthesis parameters wao.error.serviceSynthesis.getGlobalSynthesisResult= wao.error.serviceSynthesis.getNonComplianceBoardingIndicator= +wao.error.serviceSynthesis.getObservationHours= wao.error.serviceSynthesis.updateGlobalSynthesisParameters=Unable to update global synthesis parameters wao.error.serviceUser.addTokensToAllProfiles= wao.error.serviceUser.connect= Modified: trunk/wao-business/src/main/resources/i18n/wao-business_fr_FR.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business_fr_FR.properties 2011-04-22 12:33:57 UTC (rev 1234) +++ trunk/wao-business/src/main/resources/i18n/wao-business_fr_FR.properties 2011-04-22 12:35:30 UTC (rev 1235) @@ -232,6 +232,7 @@ wao.error.serviceSynthesis.getGlobalSynthesisParameters=Impossible de r\u00E9cup\u00E9rer les donn\u00E9es concernant les indicateurs pour la synth\u00E8se globale wao.error.serviceSynthesis.getGlobalSynthesisResult= wao.error.serviceSynthesis.getNonComplianceBoardingIndicator=Impossible de r\u00E9cup\u00E9rer l'indicateur de non respect du nombre d'observateurs embarqu\u00E9s +wao.error.serviceSynthesis.getObservationHours= wao.error.serviceSynthesis.updateGlobalSynthesisParameters=Impossible de mettre \u00E0 jour les param\u00E8tres de la synth\u00E8se globale wao.error.serviceUser.addTokensToAllProfiles= wao.error.serviceUser.connect=Une erreur est survenue lors de la demande de connexion Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ObsDebTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ObsDebTest.java 2011-04-22 12:33:57 UTC (rev 1234) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ObsDebTest.java 2011-04-22 12:35:30 UTC (rev 1235) @@ -41,6 +41,7 @@ import org.apache.commons.lang.StringUtils; import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.nuiton.util.DateUtil; import org.nuiton.util.PeriodDates; @@ -50,6 +51,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; +import java.util.Map; /** * @@ -64,8 +66,9 @@ protected ServiceReferential serviceReferential; protected ServiceBoat serviceBoat; protected ServiceSampling serviceSampling; + private ServiceSynthesis serviceSynthesis; + protected ServiceContact serviceContact; - protected ObsDebFixtures fixtures; @Before @@ -75,6 +78,7 @@ serviceBoat = manager.getServiceBoat(); serviceSampling = manager.getServiceSampling(); serviceContact = manager.getServiceContact(); + serviceSynthesis = manager.getServiceSynthesis(); } @Before @@ -389,7 +393,10 @@ Assert.assertNotNull("service must have pre filled field", contact.getTerrestrialLocation()); } - /** Check that coordinator is able to export the contacts created in {@link #observerCanCreateContact()} */ + /** Check that coordinator is able to export the contacts created in {@link #observerCanCreateContact()} + * @throws WaoBusinessException + * @throws IOException + */ @Test public void coordinatorCanExportContacts() throws IOException, WaoBusinessException { // first, create two contacts @@ -410,4 +417,15 @@ int actualLineNumber = StringUtils.countMatches(csv, "\n"); Assert.assertEquals(expectedLineNumber, actualLineNumber); } + + /** Check that coordinator is able to export the contacts created in {@link #observerCanCreateContact()} */ + @Test + public void coordinatorCanGetSynthesisResults() throws WaoBusinessException, IOException { + observerCanCreateContact(); + + SamplingFilter samplingFilter = serviceSampling.newSamplingFilter(fixtures.joshAsCoordinator()); + Map<String, Map<String, Integer>> observationHours = serviceSynthesis.getObservationHours(samplingFilter); + + Assert.assertEquals(2, observationHours.get("09:00").get("2010").intValue()); + } }
participants (1)
-
bleny@users.labs.libre-entreprise.org