r2086 - in trunk: . wao-persistence/src/main/java/fr/ifremer/wao/entity wao-persistence/src/main/resources wao-persistence/src/main/resources/db/migration wao-services/src/main/java/fr/ifremer/wao/services wao-services/src/main/java/fr/ifremer/wao/services/service wao-services/src/main/java/fr/ifremer/wao/services/service/administration wao-services/src/main/java/fr/ifremer/wao/services/service/csv wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations wao-services/src/main/
Author: bleny Date: 2014-06-22 20:10:23 +0200 (Sun, 22 Jun 2014) New Revision: 2086 Url: http://forge.codelutin.com/projects/wao/repository/revisions/2086 Log: fixes #4484 fixes #4488 fixes #4491 fixes #4494 add obsvente Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsList.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/IllegalAcceptationException.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingContactTerrestrialLocationException.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/Synthesis.java trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/BoatsServiceTest.java trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractSamplingPlanAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatDetailsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsFilterValuesJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CancelBoatSelectionAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CommentSampleRowAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsFilterValuesJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CreateContactAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteContactAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteSampleRowAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportBoatsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportContactsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportContactsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportSamplingPlanAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowLogAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowsFilterValuesJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SynthesisAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatElligibilityJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatInfosJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsvente/ trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/Synthesis-conversion.properties trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/BoatsAction-conversion.properties trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/ContactsAction-conversion.properties trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction-conversion.properties trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/SynthesisAction-conversion.properties trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsvente/ trunk/wao-web/src/main/webapp/WEB-INF/content/boat-details.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/boats.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/contacts.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/import-contacts-input.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/import-sampling-plan-input.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/obsvente/ trunk/wao-web/src/main/webapp/WEB-INF/content/sample-row-log.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/synthesis.jsp Removed: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsList.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSynthesis.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerBoatsServiceTest.java trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerContactsServiceTest.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatDetailsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatsFilterValuesJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CancelBoatSelectionAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CommentSampleRowAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsFilterValuesJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CreateContactAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteContactAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteSampleRowAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditSampleRowAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportBoatsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportContactsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/GetBoatContactsCountJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportContactsAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportSamplingPlanAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowLogAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowsFilterValuesJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SearchBoatJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SynthesisAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/UpdateBoatElligibilityJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/UpdateBoatInfosJsonAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/ObsMerSynthesis-conversion.properties trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/BoatsAction-conversion.properties trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/ContactsAction-conversion.properties trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/GetBoatContactsCountJsonAction-conversion.properties trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/SynthesisAction-conversion.properties trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boats.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-contact-input.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-sample-row-input.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-sampling-plan-input.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sample-row-log.jsp trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/synthesis.jsp Modified: trunk/ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationTopiaDao.java trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocations.java trunk/wao-persistence/src/main/resources/ trunk/wao-persistence/src/main/resources/db/migration/V4_0__clean_database.sql trunk/wao-services/src/main/java/fr/ifremer/wao/services/DefaultWaoServiceContext.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/WaoApplicationContext.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/WaoServiceContext.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateContactCommand.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictsParserFormatter.java trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties trunk/wao-services/src/test/java/fr/ifremer/wao/services/FakeWaoApplicationContext.java trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/CacheInvalidationTopiaEntityListener.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/DefaultWaoApplicationContext.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/WaoInterceptor.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/WaoJspActionSupport.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractDownloadCsvAction.java trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp trunk/wao-web/src/main/webapp/endpoints-js.jsp Property changes on: trunk ___________________________________________________________________ Added: svn:mergeinfo + /branches/wao-4.0-obsvente:2075-2085 Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -23,6 +23,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import org.nuiton.i18n.I18n; +import java.util.Locale; + public class TerrestrialLocationImpl extends TerrestrialLocationAbstract { @Override @@ -78,7 +80,7 @@ } else { // it's a port or an auction description.append(getName()).append(" (") .append(getCode()).append(", ") - .append(getLocationType()).append(", "); + .append(I18n.l(Locale.FRANCE, getLocationType().getI18nKey())).append(", "); // add the port name only if it's different of the name // because most of the time it's redundant if (getPortName() != null && ! getPortName().equals(getName())) { Property changes on: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java ___________________________________________________________________ Modified: svn:mergeinfo - /branches/wao-1.5.x/wao-business/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java:679-733 + /branches/wao-1.5.x/wao-business/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java:679-733 /branches/wao-4.0-obsvente/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java:2075-2085 Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationTopiaDao.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationTopiaDao.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationTopiaDao.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -21,8 +21,10 @@ * #L% */ +import fr.ifremer.wao.WaoUtils; import org.nuiton.topia.persistence.TopiaQueryBuilderAddCriteriaOrRunQueryStep; +import java.util.Collection; import java.util.Collections; import java.util.List; @@ -39,4 +41,8 @@ return forLocationTypeOrdinalEquals(locationType.ordinal()); } + public TopiaQueryBuilderAddCriteriaOrRunQueryStep<TerrestrialLocation> forLocationTypeIn(Collection<LocationType> locationTypes) { + return forLocationTypeOrdinalIn(WaoUtils.toOrdinals(locationTypes)); + } + } Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocations.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocations.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocations.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -22,7 +22,10 @@ */ import com.google.common.base.Function; +import com.google.common.collect.Ordering; +import java.util.Comparator; + public class TerrestrialLocations { public static Function<TerrestrialLocation, String> getDistrictCode() { @@ -37,6 +40,14 @@ return new GetRegionIfremerCode(); } + public static Comparator<TerrestrialLocation> nameComparator() { + return Ordering.natural().onResultOf(getName()); + } + + public static Function<TerrestrialLocation, String> getName() { + return new GetName(); + } + protected static class GetDistrictCode implements Function<TerrestrialLocation, String> { @Override @@ -60,4 +71,12 @@ return input.getRegionIfremerCode(); } } + + protected static class GetName implements Function<TerrestrialLocation, String> { + + @Override + public String apply(TerrestrialLocation input) { + return input.getName(); + } + } } Property changes on: trunk/wao-persistence/src/main/resources ___________________________________________________________________ Modified: svn:mergeinfo - /branches/wao-1.5.x/wao-business/src/main/resources:679-733 + /branches/wao-1.5.x/wao-business/src/main/resources:679-733 /branches/wao-4.0-obsvente/wao-persistence/src/main/resources:2075-2085 Modified: trunk/wao-persistence/src/main/resources/db/migration/V4_0__clean_database.sql =================================================================== --- trunk/wao-persistence/src/main/resources/db/migration/V4_0__clean_database.sql 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-persistence/src/main/resources/db/migration/V4_0__clean_database.sql 2014-06-22 18:10:23 UTC (rev 2086) @@ -36,3 +36,10 @@ update dcf5code_sampleRow set dcf5code='fr.ifremer.wao.entities.DCF5Code#1289320029000#798260963OTB' where dcf5code='fr.ifremer.wao.entities.DCF5Code#1289320029000#798260963OTBDES'; delete from dcf5code where topiaId='fr.ifremer.wao.entities.DCF5Code#1289320029000#798260963OTBDES'; + +-- Erreur de l'unicité dans le référentiel des codes DCF + +delete from boatInfos where (company, boat) in (select company, boat from boatinfos group by company, boat having count(topiaId) > 1) and topiaVersion = 0; + +alter table boatInfos add constraint company_boat_uniqueness unique (company, boat); + Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/DefaultWaoServiceContext.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/DefaultWaoServiceContext.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/DefaultWaoServiceContext.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -29,7 +29,8 @@ import fr.ifremer.wao.services.service.BoatsFilterValues; import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSynthesis; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.services.service.Synthesis; import fr.ifremer.wao.services.service.SamplingPlanCacheKey; import java.lang.reflect.Constructor; @@ -123,7 +124,7 @@ } @Override - public Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> getSamplingPlansCache() { + public Cache<SamplingPlanCacheKey, SamplingPlan> getSamplingPlansCache() { return waoApplicationContext.getSamplingPlansCache(); } @@ -133,7 +134,7 @@ } @Override - public Cache<ContactsFilter, ObsMerSynthesis> getSynthesesCache() { + public Cache<ContactsFilter, Synthesis> getSynthesesCache() { return waoApplicationContext.getSynthesesCache(); } } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -36,8 +36,8 @@ import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.entity.WaoUserImpl; import fr.ifremer.wao.entity.WaoUserTopiaDao; +import fr.ifremer.wao.services.service.ContactsService; import fr.ifremer.wao.services.service.ImportErrorException; -import fr.ifremer.wao.services.service.ObsMerContactsService; import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; import fr.ifremer.wao.services.service.administration.ReferentialService; import org.apache.commons.io.IOUtils; @@ -199,7 +199,7 @@ InputStream input = null; try { input = getClass().getResourceAsStream("/import/contacts.csv"); - serviceContext.newService(ObsMerContactsService.class).importContacts(admin(), input); + serviceContext.newService(ContactsService.class).importContacts(admin(), input); } catch (ImportErrorException e) { throw new WaoTechnicalException(e); } finally { Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/WaoApplicationContext.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/WaoApplicationContext.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/WaoApplicationContext.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -6,9 +6,9 @@ import fr.ifremer.wao.WaoTopiaPersistenceContext; import fr.ifremer.wao.services.service.BoatsFilterValues; import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSynthesis; +import fr.ifremer.wao.services.service.SamplingPlan; import fr.ifremer.wao.services.service.SamplingPlanCacheKey; +import fr.ifremer.wao.services.service.Synthesis; import java.util.Date; import java.util.Locale; @@ -35,10 +35,10 @@ void close(); - Cache<SamplingPlanCacheKey,ObsMerSamplingPlan> getSamplingPlansCache(); + Cache<SamplingPlanCacheKey,SamplingPlan> getSamplingPlansCache(); Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> getBoatsFilterValuesCache(); - Cache<ContactsFilter, ObsMerSynthesis> getSynthesesCache(); + Cache<ContactsFilter, Synthesis> getSynthesesCache(); } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/WaoServiceContext.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/WaoServiceContext.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/WaoServiceContext.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -27,9 +27,9 @@ import fr.ifremer.wao.WaoTopiaPersistenceContext; import fr.ifremer.wao.services.service.BoatsFilterValues; import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSynthesis; +import fr.ifremer.wao.services.service.SamplingPlan; import fr.ifremer.wao.services.service.SamplingPlanCacheKey; +import fr.ifremer.wao.services.service.Synthesis; import java.util.Date; import java.util.Locale; @@ -56,9 +56,9 @@ String newUuid(); - Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> getSamplingPlansCache(); + Cache<SamplingPlanCacheKey, SamplingPlan> getSamplingPlansCache(); Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> getBoatsFilterValuesCache(); - Cache<ContactsFilter,ObsMerSynthesis> getSynthesesCache(); + Cache<ContactsFilter,Synthesis> getSynthesesCache(); } Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsList.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsList.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsList.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsList.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,58 @@ +package fr.ifremer.wao.services.service; + +/* + * #%L + * Wao :: Services + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import fr.ifremer.wao.entity.Boat; +import org.nuiton.util.pagination.PaginationResult; + +import java.io.Serializable; + +/** + * Created on 4/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class BoatsList implements Serializable { + + private static final long serialVersionUID = 1L; + + protected PaginationResult<Boat> boats; + + protected BoatsFilterValues filterValues; + + public PaginationResult<Boat> getBoats() { + return boats; + } + + public void setBoats(PaginationResult<Boat> boats) { + this.boats = boats; + } + + public BoatsFilterValues getFilterValues() { + return filterValues; + } + + public void setFilterValues(BoatsFilterValues filterValues) { + this.filterValues = filterValues; + } +} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatsService.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,291 @@ +package fr.ifremer.wao.services.service; + +/* + * #%L + * Wao :: Services + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Charsets; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.cache.Cache; +import com.google.common.collect.ImmutableSet; +import fr.ifremer.wao.BoatsFilter; +import fr.ifremer.wao.ContactsFilter; +import fr.ifremer.wao.WaoTechnicalException; +import fr.ifremer.wao.entity.Boat; +import fr.ifremer.wao.entity.BoatInfos; +import fr.ifremer.wao.entity.BoatInfosImpl; +import fr.ifremer.wao.entity.BoatInfosTopiaDao; +import fr.ifremer.wao.entity.BoatTopiaDao; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.ContactState; +import fr.ifremer.wao.entity.ContactTopiaDao; +import fr.ifremer.wao.entity.ElligibleBoat; +import fr.ifremer.wao.entity.ElligibleBoatTopiaDao; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.service.csv.BoatImportExportModel; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.csv.Export; +import org.nuiton.csv.ExportModel; +import org.nuiton.util.pagination.PaginationParameter; +import org.nuiton.util.pagination.PaginationResult; + +import java.io.InputStream; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.List; + +/** + * Created on 4/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class BoatsService extends WaoServiceSupport { + + /** Logger. */ + private static final Log log = LogFactory.getLog(BoatsService.class); + + public BoatsFilterValues getBoatsFilterValues(AuthenticatedWaoUser authenticatedWaoUser, BoatsFilter filter) { + + Optional<String> optionalCompanyId = Optional.absent(); + if (authenticatedWaoUser.isCoordinatorOrObserver()) { + optionalCompanyId = Optional.of(authenticatedWaoUser.getCompany().getTopiaId()); + } + + BoatsFilterValuesCacheKey boatsFilterValuesCacheKey = + new BoatsFilterValuesCacheKey( + serviceContext.getLocale(), + authenticatedWaoUser.getObsProgram(), + optionalCompanyId); + + Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> cache = + serviceContext.getBoatsFilterValuesCache(); + + BoatsFilterValues boatsFilterValues = cache.getIfPresent(boatsFilterValuesCacheKey); + + if (boatsFilterValues == null) { + + BoatTopiaDao dao = getBoatDao(); + + List<Boat> boats = dao.findAll(filter); + + boatsFilterValues = new BoatsFilterValues(serviceContext.getLocale(), authenticatedWaoUser.getObsProgram(), optionalCompanyId); + + for (Boat boat : boats) { + boatsFilterValues.addBoat(boat); + } + + cache.put(boatsFilterValuesCacheKey, boatsFilterValues); + + } + + return boatsFilterValues; + } + + public BoatsList getBoatsList(AuthenticatedWaoUser authenticatedWaoUser, + BoatsFilter filter, + PaginationParameter pager) { + + BoatTopiaDao dao = getBoatDao(); + + PaginationResult<Boat> boats = dao.find(filter, pager); + + BoatsFilterValues boatsFilterValues = getBoatsFilterValues(authenticatedWaoUser, filter); + + BoatsList boatsList = new BoatsList(); + boatsList.setBoats(boats); + boatsList.setFilterValues(boatsFilterValues); + return boatsList; + } + + public PaginationParameter newBoatsPaginationParameter(int pageNumber, int pageSize) { + PaginationParameter result = PaginationParameter.of(pageNumber, pageSize, Boat.PROPERTY_NAME, false); + return result; + } + + public BoatsFilter newBoatsFilter(AuthenticatedWaoUser authenticatedWaoUser) { + + BoatsFilter boatsFilter = new BoatsFilter(); + + if (authenticatedWaoUser.isProfessional()) { + // Pour le profesionnel, on restreint d'office à la liste des bateaux qu'il peut voir + Collection<String> canReadBoatsTopiaIds = authenticatedWaoUser.getWaoUser().getCanReadBoatsTopiaIds(); + if (CollectionUtils.isEmpty(canReadBoatsTopiaIds)) { + if (log.isWarnEnabled()) { + log.warn("user " + authenticatedWaoUser.getWaoUser() + " is professional but can't read any boat"); + } + } else { + boatsFilter.setBoatIds(new HashSet<>(canReadBoatsTopiaIds)); + } + } + + return boatsFilter; + + } + + public InputStream exportBoats(BoatsFilter filter) { + + BoatTopiaDao dao = getBoatDao(); + + List<Boat> sampleRows = dao.findAll(filter); + + ExportModel<Boat> exportModel = + new BoatImportExportModel(getLocale()); + + Export<Boat> export = Export.newExport(exportModel, sampleRows); + + try { + + String csvContent = export.toString(Charsets.UTF_8); + + InputStream csvInputStream = IOUtils.toInputStream(csvContent, Charsets.UTF_8); + + return csvInputStream; + + } catch (Exception e) { + throw new WaoTechnicalException(e); + } + } + + public BoatDetails getBoatDetails(ObsProgram obsProgram, String boatId, String companyId) { + + BoatInfos boatInfos = getBoatInfos(boatId, companyId); + + Contact mostRecentContact = getContactDao().findMostRecentContactOrNull(obsProgram, boatId, companyId); + + ContactsFilter filter = new ContactsFilter(); + filter.getSampleRowFilter().setObsProgram(obsProgram); + filter.getBoatFilter().setBoatIds(ImmutableSet.of(boatId)); + filter.getSampleRowFilter().setCompanyIds(ImmutableSet.of(companyId)); + long contactsCount = getContactDao().forFilter(filter, false).count(); + + Date now = serviceContext.getNow(); + + BoatDetails boatDetails = new BoatDetails(now, obsProgram, boatInfos, mostRecentContact, contactsCount); + + return boatDetails; + + } + + public BoatInfos getBoatInfos(String boatId, String companyId) { + + BoatInfosTopiaDao dao = getBoatInfosDao(); + + Optional<BoatInfos> optionalBoatInfos = + dao.newQueryBuilder() + .addTopiaIdEquals(BoatInfos.PROPERTY_BOAT, boatId) + .addTopiaIdEquals(BoatInfos.PROPERTY_COMPANY, companyId) + .tryFindUnique(); + + BoatInfos boatInfos; + if (optionalBoatInfos.isPresent()) { + boatInfos = optionalBoatInfos.get(); + } else { + Boat boat = getBoatDao().findByTopiaId(boatId); + Company company = getCompanyDao().findByTopiaId(companyId); + boatInfos = new BoatInfosImpl(); + boatInfos.setBoat(boat); + boatInfos.setCompany(company); + } + + return boatInfos; + + } + + public void saveBoatInfos(BoatInfos boatInfos) { + + BoatInfosTopiaDao dao = getBoatInfosDao(); + + if (boatInfos.isPersisted()) { + dao.update(boatInfos); + } else { + dao.create(boatInfos); + } + + commit(); + + } + + public BoatContactsCounts getBoatContactsCounts(AuthenticatedWaoUser authenticatedWaoUser, String boatId, String companyId, Date since) { + + ContactsFilter filter = new ContactsFilter(); + + filter.getSampleRowFilter().setObsProgram(authenticatedWaoUser.getObsProgram()); + filter.setPeriodFrom(since); + filter.getBoatFilter().setBoatIds(ImmutableSet.of(boatId)); + filter.setFilterOnObservationBeginDate(false); + + ContactTopiaDao dao = getContactDao(); + + long contactsCount = dao.forFilter(filter, false).count(); + + filter.getSampleRowFilter().setCompanyIds(ImmutableSet.of(companyId)); + long contactsCompanyCount = dao.forFilter(filter, false).count(); + + filter.setContactStates(ImmutableSet.of(ContactState.OBSERVATION_DONE)); + long observationsCompanyCount = dao.forFilter(filter, false).count(); + + filter.getSampleRowFilter().setCompanyIds(null); + long observationsCount = dao.forFilter(filter, false).count(); + + Preconditions.checkState(contactsCompanyCount <= contactsCount); + Preconditions.checkState(observationsCount <= contactsCount); + + Preconditions.checkState(observationsCompanyCount <= contactsCompanyCount); + Preconditions.checkState(observationsCompanyCount <= observationsCount); + + return new BoatContactsCounts(contactsCount, observationsCount, contactsCompanyCount, observationsCompanyCount); + + } + + public Collection<Boat> getBoats(BoatsFilter boatsFilter, int pageSize) { + + PaginationParameter pager = newBoatsPaginationParameter(0, pageSize); + + PaginationResult<Boat> boats = getBoatDao().find(boatsFilter, pager); + + return boats.getElements(); + + } + + public void changeBoatElligibility(AuthenticatedWaoUser authenticatedWaoUser, String boatId, String sampleRowId, boolean active) { + + ElligibleBoatTopiaDao dao = getElligibleBoatDao(); + + ElligibleBoat elligibleBoat = dao.forBoatIdAndSampleRowId(boatId, sampleRowId).findUnique(); + + if (authenticatedWaoUser.isAdmin()) { + elligibleBoat.setGlobalActive(active); + } else if (authenticatedWaoUser.isCoordinatorOrObserver()) { + elligibleBoat.setCompanyActive(active); + } else { + throw new IllegalStateException(authenticatedWaoUser.getWaoUser().toString()); + } + + commit(); + } +} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,1041 @@ +package fr.ifremer.wao.services.service; + +/* + * #%L + * Wao :: Services + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Charsets; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableSet; +import fr.ifremer.wao.ContactsFilter; +import fr.ifremer.wao.WaoTechnicalException; +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.Boat; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.ContactImpl; +import fr.ifremer.wao.entity.ContactState; +import fr.ifremer.wao.entity.ContactStateMotif; +import fr.ifremer.wao.entity.ContactTopiaDao; +import fr.ifremer.wao.entity.DataReliability; +import fr.ifremer.wao.entity.ElligibleBoat; +import fr.ifremer.wao.entity.ElligibleBoatTopiaDao; +import fr.ifremer.wao.entity.LocationType; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.ObservedDataControl; +import fr.ifremer.wao.entity.SampleMonth; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.TerrestrialLocation; +import fr.ifremer.wao.entity.WaoUser; +import fr.ifremer.wao.entity.WaoUserTopiaDao; +import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.service.csv.ContactImportExportModel; +import fr.ifremer.wao.services.service.mail.AddBoatToUserAllegroWalletEmail; +import fr.ifremer.wao.services.service.mail.EmailService; +import fr.ifremer.wao.services.service.mail.MammalsObservationEmail; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.csv.AbstractImportErrorInfo; +import org.nuiton.csv.Export; +import org.nuiton.csv.ExportModel; +import org.nuiton.csv.Import2; +import org.nuiton.csv.ImportConf; +import org.nuiton.csv.ImportModel; +import org.nuiton.csv.ImportRow; +import org.nuiton.i18n.I18n; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.DateUtil; +import org.nuiton.util.StringUtil; +import org.nuiton.util.beans.Binder; +import org.nuiton.util.beans.BinderFactory; +import org.nuiton.util.pagination.PaginationParameter; +import org.nuiton.util.pagination.PaginationResult; + +import java.io.InputStream; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import static org.nuiton.i18n.I18n.l; + +public class ContactsService extends WaoServiceSupport { + + private static final Log log = LogFactory.getLog(ContactsService.class); + + public ContactsFilter newContactFilter(AuthenticatedWaoUser authenticatedWaoUser) { + + ContactsFilter newContactsFilter = new ContactsFilter(); + + newContactsFilter.getSampleRowFilter().setObsProgram(authenticatedWaoUser.getObsProgram()); + + // DO NOT REMOVE THIS + if (authenticatedWaoUser.isCoordinatorOrObserver()) { + String authenticatedWaoUserCompanyTopiaId = authenticatedWaoUser.getWaoUser().getCompany().getTopiaId(); + newContactsFilter.getSampleRowFilter().setCompanyIds(ImmutableSet.of(authenticatedWaoUserCompanyTopiaId)); + } + + Calendar periodFromCalendar = Calendar.getInstance(); + periodFromCalendar.setTime(serviceContext.getNow()); + + // in the firsts months of a new year go from now to 6 months before + // in the rest of the year, just start at the beginning of the current year + if (periodFromCalendar.get(Calendar.MONTH) < 3) { + periodFromCalendar.add(Calendar.MONTH, -6); + } else { + periodFromCalendar.set(Calendar.DAY_OF_YEAR, 1); + } + + Date periodFrom = periodFromCalendar.getTime(); + Date periodTo = DateUtils.addYears(periodFromCalendar.getTime(), 1); + + newContactsFilter.setPeriodFrom(periodFrom); + newContactsFilter.setPeriodTo(periodTo); + + if (authenticatedWaoUser.isProfessional()) { + // Pour le profesionnel, on restreint d'office à la liste des contacts portant sur les bateaux qu'il peut voir + Collection<String> canReadBoatsTopiaIds = authenticatedWaoUser.getWaoUser().getCanReadBoatsTopiaIds(); + if (CollectionUtils.isEmpty(canReadBoatsTopiaIds)) { + if (log.isWarnEnabled()) { + log.warn("user " + authenticatedWaoUser.getWaoUser() + " is professional but can't read any boat"); + } + } else { + newContactsFilter.getBoatFilter().setBoatIds(new HashSet<>(canReadBoatsTopiaIds)); + } + } + + return newContactsFilter; + + } + + public ContactsFilterValues getContactsFilterValues(AuthenticatedWaoUser authenticatedWaoUser, ContactsFilter filter) { + + ContactTopiaDao dao = getContactDao(); + List<Contact> contacts = dao.forFilter(filter, false).findAll(); + + Optional<String> optionalCompanyId = Optional.absent(); + if (authenticatedWaoUser.isCoordinatorOrObserver()) { + optionalCompanyId = Optional.of(authenticatedWaoUser.getCompany().getTopiaId()); + } + ContactsFilterValues contactsFilterValues = new ContactsFilterValues(serviceContext.getLocale(), authenticatedWaoUser.getObsProgram(), optionalCompanyId); + + for (Contact contact : contacts) { + contactsFilterValues.addContact(contact); + } + + return contactsFilterValues; + } + + public ObsMerContactsList getContactsList(AuthenticatedWaoUser authenticatedWaoUser, + ContactsFilter filter, + PaginationParameter queryPager) { + + ContactTopiaDao dao = getContactDao(); + + // Need to copy to add sort attributes + PaginationParameter.PaginationParameterBuilder builder = PaginationParameter.builder(queryPager.getPageNumber(), queryPager.getPageSize()); + if (filter.isSortedByBoardingDate()) { + builder.addOrder(Contact.PROPERTY_OBSERVATION_BEGIN_DATE, true); + } else { + builder.addOrder(Contact.PROPERTY_CREATION_DATE, true); + } + PaginationParameter pager = builder.build(); + + PaginationResult<Contact> contacts = dao.forFilter(filter, false).findPage(pager); + + ContactsFilterValues filterValues = getContactsFilterValues(authenticatedWaoUser, filter); + + ObsMerContactsList contactsList = new ObsMerContactsList(); + contactsList.setContacts(contacts); + contactsList.setFilterValues(filterValues); + return contactsList; + } + + public PaginationParameter newContactsPaginationParameter(int pageNumber, int pageSize) { + PaginationParameter result = PaginationParameter.of(pageNumber, pageSize); + return result; + } + + public UpdateContactCommand newUpdateContactCommand(AuthenticatedWaoUser authenticatedWaoUser, Optional<String> optionalContactId) { + + //FIXME Should we apply some security rules (can create, update, import) ? + //Preconditions.checkState(authenticatedWaoUser.isAuthorizedToCreateSampleRow()); + + UpdateContactCommand updateContactCommand = new UpdateContactCommand(); + + updateContactCommand.setAdmin(authenticatedWaoUser.isAdmin()); + + Contact contact; + + if (optionalContactId.isPresent()) { + + String contactId = optionalContactId.get(); + + contact = getContact(contactId); + + updateContactCommand.setContact(contact); + + updateContactCommand.setCreation(false); + + String mainObserverId = contact.getMainObserver().getTopiaId(); + updateContactCommand.setMainObserverId(mainObserverId); + Set<String> secondaryObserversTopiaIds = contact.getSecondaryObserversTopiaIds(); + updateContactCommand.setSecondaryObserverIds(secondaryObserversTopiaIds); + + if (contact.getTerrestrialLocation() != null) { + String terrestrialLocationId = contact.getTerrestrialLocation().getTopiaId(); + updateContactCommand.setTerrestrialLocationId(terrestrialLocationId); + } + + } else { + + contact = new ContactImpl(); + + contact.setObsProgram(authenticatedWaoUser.getObsProgram()); + + contact.setCreationDate(getNow()); + + updateContactCommand.setContact(contact); + + updateContactCommand.setCreation(true); + } + + return updateContactCommand; + } + + public Contact getContact(String contactId) { + return getContactDao().forTopiaIdEquals(contactId).findUnique(); + } + + public InputStream exportContacts(ContactsFilter filter) { + ContactTopiaDao dao = getContactDao(); + + List<Contact> contacts = dao.forFilter(filter, true).findAll(); + + ExportModel<Contact> exportModel = ContactImportExportModel.forExport(getLocale(), + filter.getSampleRowFilter().getObsProgram()); + + Export<Contact> export = Export.newExport(exportModel, contacts); + + try { + + String csvContent = export.toString(Charsets.UTF_8); + + InputStream csvInputStream = IOUtils.toInputStream(csvContent, Charsets.UTF_8); + + return csvInputStream; + + } catch (Exception e) { + throw new WaoTechnicalException(e); + } + } + + public void importContacts(AuthenticatedWaoUser authenticatedWaoUser, + InputStream csv) throws ImportErrorException { + + ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); + + List<SampleRow> sampleRows = + getSampleRowDao().forObsProgramOrdinalEquals(obsProgram.ordinal()).findAll(); + List<WaoUser> waoUsers = getWaoUserDao().findAll(); + List<Boat> boats = getBoatDao().findAll(); + List<ContactStateMotif> motives = getContactStateMotifDao().findAll(); + List<TerrestrialLocation> terrestrialLocations = + getTerrestrialLocationDao().forLocationTypeIn(ImmutableSet.of(LocationType.AUCTION, LocationType.PORT)).findAll(); + + Locale l = getLocale(); + ImportModel<Contact> contactImportModel = + ContactImportExportModel.forImport(l, + obsProgram, + waoUsers, + sampleRows, + boats, + motives, + terrestrialLocations); + + ImportConf importConf = new ImportConf(); + importConf.setStrictMode(true); + + Import2<Contact> contactImport = Import2.newImport(importConf, contactImportModel, csv); + + for (ImportRow<Contact> contactRow : contactImport) { + + if (!contactRow.isValid()) { + // throw first error + Set<AbstractImportErrorInfo<Contact>> errors = contactRow.getErrors(); + AbstractImportErrorInfo<Contact> errorInfo = errors.iterator().next(); + throw new ImportErrorException(errorInfo.getCause()); + } + long lineNumber = contactRow.getLineNumber(); + + Contact contact = contactRow.getBean(); + + String contactId = contact.getTopiaId(); + + if (StringUtils.isEmpty(contactId)) { + contactId = null; + } + + Optional<String> optionalContactId = Optional.fromNullable(contactId); + UpdateContactCommand updateContactCommand = newUpdateContactCommand(authenticatedWaoUser, + optionalContactId); + + if (updateContactCommand.isCreation()) { + + updateContactCommand.setContact(contact); + + // Prevent that someone who is not admin change data that only admin + // must be able to modify + if ( ! authenticatedWaoUser.isAdmin()) { + contact.setCommentAdmin(null); + contact.setValidationProgram(null); + contact.setDataReliability(DataReliability.UNKNOWN); + } + + } else { + + Contact contactToUpdate = updateContactCommand.getContact(); + + // TODO brendan 20/06/14 create to binders + Binder<Contact, Contact> binder = BinderFactory.newBinder(Contact.class); + binder.copyExcluding(contact, contactToUpdate, TopiaEntity.PROPERTY_TOPIA_ID, TopiaEntity.PROPERTY_TOPIA_VERSION, + TopiaEntity.PROPERTY_TOPIA_CREATE_DATE, Contact.PROPERTY_SAMPLE_ROW); + + // Prevent that someone who is not admin change data that only admin + // must be able to modify + if ( ! authenticatedWaoUser.isAdmin()) { + contactToUpdate.setCommentAdmin(contact.getCommentAdmin()); + contactToUpdate.setValidationProgram(contact.getValidationProgram()); + contactToUpdate.setDataReliability(contact.getDataReliability()); + } + + } + + try { + validate(authenticatedWaoUser, updateContactCommand, false); + } catch (ContactNotUpdatableException e) { + String message = l(l, "wao.import.contact.failure.not.updatable", lineNumber); + throw new ImportErrorException(message); + } catch (UnwantedContactContactStateMotifException e) { + String message = l(l, "wao.import.contact.failure.unwantedContactStateMotif", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactNbObservantsException e) { + String state = WaoUtils.l(l, e.getContact().getContactState()); + String message = l(l, "wao.import.contact.failure.missingObserver", lineNumber, state); + throw new ImportErrorException(message); + } catch (MissingContactObservationEndDateException e) { + String state = WaoUtils.l(l, e.getContact().getContactState()); + String message = l(l, "wao.import.contact.failure.missingObservationEndDate", lineNumber, state); + throw new ImportErrorException(message); + } catch (ContactDataInputDateBeforeObservationEndDateException e) { + String message = l(l, "wao.import.contact.failure.dataInputDateBeforeObservationEndDate", lineNumber); + throw new ImportErrorException(message); + } catch (InvalidContactObservationBeginDateException e) { + String message = l(l, "wao.import.contact.failure.invalidObservationBeginDate", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactRestitutionException e) { + String message = l(l, "wao.import.contact.failure.missingRestitution", lineNumber); + throw new ImportErrorException(message); + } catch (ContactDataInputDateAfterTodayException e) { + String message = l(l, "wao.import.contact.failure.dataInputDateAfterToday", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactCommentException e) { + String state = WaoUtils.l(l, e.getContact().getContactState()); + String message = l(l, "wao.import.contact.failure.missingComment", state, lineNumber); + throw new ImportErrorException(message); + } catch (MismatchContactMainObserverCompanyException e) { + String companyName = e.getCompany().getName(); + String observerLogin = e.getObserver().getLogin(); + String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, companyName); + throw new ImportErrorException(message); + } catch (ContactRestitutionDateBeforeDataInputDateException e) { + String message = l(l, "wao.import.contact.failure.transmissionDateBeforeDataInputDate", lineNumber); + throw new ImportErrorException(message); + } catch (ContactObservationEndDateBeforeBeginDateException e) { + String message = l(l, "wao.import.contact.failure.observationEndDateBeforeBeginDate", lineNumber); + throw new ImportErrorException(message); + } catch (DuplicatedContactMainObserverInSecondaryObserversException e) { + String message = l(l, "wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactDataReliabilityException e) { + String message = l(l, "wao.import.contact.failure.missingDataReliability", lineNumber); + throw new ImportErrorException(message); + } catch (MismatchContactSecondaryObserverCompanyException e) { + String companyName = e.getCompany().getName(); + String observerLogin = e.getObserver().getLogin(); + String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, companyName); + throw new ImportErrorException(message); + } catch (MissingContactObservedDataControlException e) { + String message = l(l, "wao.import.contact.failure.missingObservedDataControl", lineNumber); + throw new ImportErrorException(message); + } catch (ContactWithObservedDataControlToCorrectionAskedException e) { + String message = l(l, "wao.import.contact.failure.observedDataControlToCorrectionAsked", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactStateMotifException e) { + String message = l(l, "wao.import.contact.failure.missingContactStateMotif", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactDataInputDateException e) { + String message = l(l, "wao.import.contact.failure.missingDataInputDate", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactMainObserverException e) { + String message = l(l, "wao.import.contact.failure.missingMainObserver", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactCommentAdminException e) { + String dataReliability = WaoUtils.l(l, e.getContact().getDataReliability()); + String message = l(l, "wao.import.contact.failure.missingCommentAdmin", lineNumber, dataReliability); + throw new ImportErrorException(message); + } catch (ContactObservationEndDateAfterTodayException e) { + String message = l(l, "wao.import.contact.failure.observationEndDateAfterToday", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactObservationBeginDateException e) { + String state = WaoUtils.l(l, e.getContact().getContactState()); + String message = l(l, "wao.import.contact.failure.missingObservationBeginDate", lineNumber, state); + throw new ImportErrorException(message); + } catch (MissingContactMammalsInfoException e) { + String message = l(l, "wao.import.contact.failure.missingContactMammalsInfo", lineNumber); + throw new ImportErrorException(message); + } catch (MissingContactTerrestrialLocationException e) { + String message = l(l, "wao.import.contact.failure.missingTerrestrialLocation", lineNumber); + throw new ImportErrorException(message); + } catch (IllegalAcceptationException e) { + String message = l(l, "wao.import.contact.failure.illegalAcceptation", lineNumber); + throw new ImportErrorException(message); + } + + save0(updateContactCommand); + } + + commit(); + } + + public void preValidate(UpdateContactCommand updateContactCommand) { + + String mainObserverId = updateContactCommand.getMainObserverId(); + + WaoUser mainObserver = getWaoUserDao().forTopiaIdEquals(mainObserverId).findUnique(); + updateContactCommand.getContact().setMainObserver(mainObserver); + + List<WaoUser> secondaryObservers = getWaoUserDao().forTopiaIdIn(updateContactCommand.getSecondaryObserverIds()).findAll(); + updateContactCommand.getContact().setSecondaryObservers(new HashSet<>(secondaryObservers)); + + String terrestrialLocationId = updateContactCommand.getTerrestrialLocationId(); + if (StringUtils.isBlank(terrestrialLocationId)) { + updateContactCommand.getContact().setTerrestrialLocation(null); + } else { + TerrestrialLocation terrestrialLocation = getTerrestrialLocationDao().forTopiaIdEquals(terrestrialLocationId).findUnique(); + updateContactCommand.getContact().setTerrestrialLocation(terrestrialLocation); + } + + } + + public void validate(AuthenticatedWaoUser authenticatedWaoUser, + UpdateContactCommand updateContactCommand, + boolean needUpdate) throws + ContactNotUpdatableException, + MissingContactMainObserverException, + MismatchContactMainObserverCompanyException, + DuplicatedContactMainObserverInSecondaryObserversException, + MismatchContactSecondaryObserverCompanyException, + InvalidContactObservationBeginDateException, + ContactObservationEndDateBeforeBeginDateException, + ContactObservationEndDateAfterTodayException, + ContactDataInputDateBeforeObservationEndDateException, + ContactDataInputDateAfterTodayException, + MissingContactCommentException, + MissingContactObservationBeginDateException, + MissingContactObservationEndDateException, + MissingContactNbObservantsException, + MissingContactStateMotifException, + UnwantedContactContactStateMotifException, + MissingContactObservedDataControlException, + MissingContactMammalsInfoException, + ContactWithObservedDataControlToCorrectionAskedException, + MissingContactRestitutionException, + MissingContactDataInputDateException, + ContactRestitutionDateBeforeDataInputDateException, + MissingContactDataReliabilityException, + MissingContactCommentAdminException, MissingContactTerrestrialLocationException, IllegalAcceptationException { + + if (needUpdate) { + Preconditions.checkState(!updateContactCommand.isCreation()); + } + + //FIXME Do some security checks about authenticatedWaoUser + + // Check if contact can be updated + boolean canUpdateContact = updateContactCommand.canUpdateContact(authenticatedWaoUser); + if (!canUpdateContact) { + throw new ContactNotUpdatableException(); + } + + // Check if a validation controls are required + boolean mustValidateContact = updateContactCommand.mustValidateContact(); + + if (mustValidateContact) { + + // Pass validation controls + Contact contact = updateContactCommand.getContact(); + + Company company = contact.getSampleRow().getCompany(); + + WaoUser mainObserver = contact.getMainObserver(); + + { + //--- + // mainObserver + //--- + + if (mainObserver == null) { + throw new MissingContactMainObserverException(contact); + } + + boolean observerWorksForCompanyInSampleRow = mainObserver.getCompany().equals(company); + if (!observerWorksForCompanyInSampleRow) { + throw new MismatchContactMainObserverCompanyException(contact, mainObserver, company); + } + } + + if (contact.isSecondaryObserversNotEmpty()) { + + //--- + // secondaryObservers + //--- + + if (contact.getSecondaryObservers().contains(mainObserver)) { + throw new DuplicatedContactMainObserverInSecondaryObserversException(contact); + } + + for (WaoUser observer : contact.getSecondaryObservers()) { + boolean observerWorksForCompanyInSampleRow = observer.getCompany().equals(company); + if (!observerWorksForCompanyInSampleRow) { + throw new MismatchContactSecondaryObserverCompanyException(contact, observer, company); + } + } + } + + Date observationBeginDate = contact.getObservationBeginDate(); + Date observationEndDate = contact.getObservationEndDate(); + Date dataInputDate = contact.getDataInputDate(); + + SampleRow sampleRow = contact.getSampleRow(); + + if (observationBeginDate != null) { + + //--- + // observationBeginDate + //--- + + SampleMonth month = sampleRow.getSampleMonth(observationBeginDate); + boolean operationBeginDateIsValid = month != null; + + if (!operationBeginDateIsValid) { + throw new InvalidContactObservationBeginDateException(contact); + } + } + + Date currentDate = serviceContext.getNow(); + + if (observationEndDate != null) { + + //--- + // observationEndDate + //--- + + if (observationBeginDate != null + && observationEndDate.before(observationBeginDate)) { + throw new ContactObservationEndDateBeforeBeginDateException(contact); + } + + if (observationEndDate.after(currentDate)) { + throw new ContactObservationEndDateAfterTodayException(contact, currentDate); + } + + } + + if (dataInputDate != null) { + + //--- + // dataInputDate + //--- + + if (observationEndDate != null) { + + // Here, we check that the date input date is after the end of the + // observation. Since the first is a day (at 00:00) and the second + // is date-time, there may be a bug if the data input day is the same + // as the end of observation + boolean dataInputDateAfterObservationEndDate = + observationEndDate.after(DateUtil.setMaxTimeOfDay(dataInputDate)); + + if (dataInputDateAfterObservationEndDate) { + throw new ContactDataInputDateBeforeObservationEndDateException(contact); + } + } + + if (dataInputDate.after(currentDate)) { + throw new ContactDataInputDateAfterTodayException(contact, currentDate); + } + } + + //--- + // contactState + //--- + + ContactState contactState = contact.getContactState(); + + boolean contactMustHaveAMotif = false; + switch (contactState) { + case OBSERVATION_CANCELLED: + + // Non abouti + + if (StringUtils.isBlank(contact.getComment())) { + throw new MissingContactCommentException(contact); + } + break; + case OBSERVATION_DONE: + + // Observation réalisée + + if (observationBeginDate == null) { + throw new MissingContactObservationBeginDateException(contact); + } + if (observationEndDate == null) { + throw new MissingContactObservationEndDateException(contact); + } + if (contact.getNbObservants() == 0) { + throw new MissingContactNbObservantsException(contact); + } + if (contact.getObsProgram().isObsVente() && contact.getTerrestrialLocation() == null) { + throw new MissingContactTerrestrialLocationException(contact); + } + break; + + case CONTACT_REFUSED: + contactMustHaveAMotif = true; + break; + case CONTACT_DEFINITELY_REFUSED: + contactMustHaveAMotif = true; + break; + + } + + //--- + // contactStateMotif + //--- + + if (contactMustHaveAMotif && contact.getContactStateMotif() == null) { + throw new MissingContactStateMotifException(contact); + } + + if (!contactMustHaveAMotif && contact.getContactStateMotif() != null) { + throw new UnwantedContactContactStateMotifException(contact); + } + + if (contact.isMammalsCapture() && StringUtils.isBlank(contact.getMammalsInfo())) { + throw new MissingContactMammalsInfoException(contact); + } + + if (BooleanUtils.isTrue(contact.getValidationCompany())) { + + //--- + // validationCompany + //--- + + if (ContactState.OBSERVATION_DONE == contactState) { + if (contact.getObsProgram().isObsMer() && contact.getObservedDataControl() == null) { + throw new MissingContactObservedDataControlException(contact); + } else if (ObservedDataControl.CORRECTION_ASKED.equals(contact.getObservedDataControl())) { + throw new ContactWithObservedDataControlToCorrectionAskedException(contact); + } + } + + // Pour valider un contact société, il faut que le contact aie une date de transmission + Date restitution = contact.getRestitution(); + if (ObservedDataControl.ACCEPTED.equals(contact.getObservedDataControl()) && restitution == null) { + throw new MissingContactRestitutionException(contact); + } + if (dataInputDate == null && restitution != null) { + throw new MissingContactDataInputDateException(contact); + } + if (dataInputDate != null && restitution != null && restitution.before(dataInputDate)) { + throw new ContactRestitutionDateBeforeDataInputDateException(contact); + } + } + + DataReliability dataReliability = contact.getDataReliability(); + + if (dataReliability != null && dataReliability.isCommentRequired() && StringUtils.isBlank(contact.getCommentAdmin())) { + throw new MissingContactCommentAdminException(contact); + } + + if (contact.getValidationProgram() != null && contact.getValidationCompany() == null) { + + throw new IllegalAcceptationException(contact); + } + + if (BooleanUtils.isTrue(contact.getValidationProgram())) { + + //--- + // validationProgram + //--- + + // it's an admin validation, data-reliability field must be filled + + if (dataReliability == null || DataReliability.UNKNOWN == dataReliability) { + throw new MissingContactDataReliabilityException(contact); + } + } + } + } + + public void save(UpdateContactCommand updateContactCommand, + boolean needUpdate) throws ContactNotUpdatableException { + + if (needUpdate) { + Preconditions.checkState(!updateContactCommand.isCreation()); + } + + save0(updateContactCommand); + + commit(); + + updateAllegroWalletIfNecessary(updateContactCommand); + + notifyMammalsObservationIfNecessary(updateContactCommand); + + } + + protected void notifyMammalsObservationIfNecessary(UpdateContactCommand updateContactCommand) { + + if (updateContactCommand.isMammalsInfosChanged()) { + + Contact contact = updateContactCommand.getContact(); + + MammalsObservationEmail email = getEmailService().newMammalsObservationEmail(); + email.setContact(contact); + + // now trying to find to what user we need to send the mail + WaoUserTopiaDao userDao = getWaoUserDao(); + // users contains all the user we need to notify for the capture + List<WaoUser> waoUsers = userDao.forMammalsNotificationsEquals(true).addEquals(WaoUser.PROPERTY_ACTIVE, true).findAll(); + + for (WaoUser waoUser : waoUsers) { + if (StringUtil.isEmail(waoUser.getLogin())) { + email.addBcc(waoUser); + } else { + if (log.isWarnEnabled()) { + log.warn("will not send mammals capture notification to user " + waoUser + ". login is not an email"); + } + } + } + + getEmailService().send(email); + + } + + } + + public void delete(String contactId) throws IllegalDeletionException { + + Contact contact = getContact(contactId); + + // Execute delete + ContactTopiaDao dao = getContactDao(); + + Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> allUsages = dao.findAllUsages(contact); + + if (!allUsages.isEmpty()) { + throw new IllegalDeletionException(allUsages); + } + + SamplingPlanService samplingPlanService = newService(SamplingPlanService.class); + + samplingPlanService.recomputeSampleRowEstimatedAndRealTides(contact.getSampleRow()); + + dao.delete(contact); + + commit(); + } + + protected void save0(UpdateContactCommand updateContactCommand) { + + // Get contact to validate (must exist) + Contact contact = updateContactCommand.getContact(); + + ContactTopiaDao dao = getContactDao(); + + SamplingPlanService samplingPlanService = newService(SamplingPlanService.class); + + if (updateContactCommand.isCreation()) { + + //Update the elligible boat depends on contact creation. The + //{@code contact} reference can only be created for a sampleRow and a + //boat if both are linked with an elligibleBoat. So this method is + //used to create the link if needed during contacts import. This + //elligibleBoat is needed for the contact owned by a company, so + //the companyActive property of ElligibleBoat will be set to TRUE. No + //admin has decided to explicitly create this link. + + ElligibleBoatTopiaDao elligibleDAO = getElligibleBoatDao(); + ElligibleBoat elligible = elligibleDAO.findUniqueOrNull(contact); + + if (elligible == null) { + // Create new elligible boat not active in a global way + elligible = elligibleDAO.create(contact); + } + elligible.setCompanyActive(Boolean.TRUE); + + if (contact.getCreationDate() == null) { + contact.setCreationDate(serviceContext.getNow()); + } + + samplingPlanService.recomputeSampleRowEstimatedAndRealTides(contact.getSampleRow()); + + dao.create(contact); + + } else { + + samplingPlanService.recomputeSampleRowEstimatedAndRealTides(contact.getSampleRow()); + + dao.update(contact); + } + + } + + protected void updateAllegroWalletIfNecessary(UpdateContactCommand updateContactCommand) { + + Contact contact = updateContactCommand.getContact(); + ContactState contactState = contact.getContactState(); + ObsProgram obsProgram = contact.getObsProgram(); + + boolean addBoatToObserversAllegroWallet = false; + + if (obsProgram == ObsProgram.OBSMER) { + addBoatToObserversAllegroWallet = contactState == ContactState.OBSERVATION_DONE + || contactState == ContactState.OBSERVATION_EXPECTED; + } else if (obsProgram == ObsProgram.OBSVENTE) { + addBoatToObserversAllegroWallet = ContactState.OBSERVATION_DONE == contactState; + } + + if (addBoatToObserversAllegroWallet) { + + Boat boat = contact.getBoat(); + + String info; + + if (contactState == ContactState.OBSERVATION_EXPECTED) { + info = I18n.l( + serviceContext.getLocale(), + "wao.email.addBoatToUserAllegroWallet.contactExpected", + WaoUtils.formatDate(serviceContext.getLocale(), contact.getObservationBeginDate())); + } else if (contactState == ContactState.OBSERVATION_DONE) { + info = I18n.l( + serviceContext.getLocale(), + "wao.email.addBoatToUserAllegroWallet.contactDone", + WaoUtils.formatDateTime(serviceContext.getLocale(), contact.getObservationBeginDate()), + WaoUtils.formatDateTime(serviceContext.getLocale(), contact.getObservationEndDate())); + } else { + throw new IllegalStateException(contactState + " should not lead to a mail sent"); + } + + // in obsvente, only the main observer + Collection<WaoUser> observers; + if (ObsProgram.OBSVENTE.equals(obsProgram)) { + observers = ImmutableSet.of(contact.getMainObserver()); + } else if (ObsProgram.OBSMER.equals(obsProgram)) { + observers = contact.getAllObservers(); + } else { + throw new IllegalStateException(); + } + + EmailService emailService = getEmailService(); + + WaoUserTopiaDao waoUserDao = getWaoUserDao(); + + for (WaoUser observer : observers) { + + boolean boatAlreadyInWallet = observer.containsAllegroWallet(boat); + + if (boatAlreadyInWallet) { + + if (log.isInfoEnabled()) { + log.info("user " + observer + " already has " + boat + " in his allegroWallet"); + } + + } else { + + if (log.isInfoEnabled()) { + log.info("user " + observer + " miss " + boat + " in his allegro wallet, adding"); + } + + String observerLogin = observer.getLogin(); + String emailToUpdateAllegroWallets = getApplicationConfig().getEmailToUpdateAllegroWallets(); + + AddBoatToUserAllegroWalletEmail email = + emailService.newAddBoatToUserAllegroWalletEmail(); + + email.setBoat(boat); + email.setObserver(observer); + email.setInfo(info); + email.setObsProgram(contact.getObsProgram()); + + if ( ! StringUtil.isEmail(observerLogin)) { + if (log.isInfoEnabled()) { + log.info("user login is not a email, won't send anything: " + observerLogin + " email=" + email); + } + } else if ( ! observer.isActive()) { + if (log.isInfoEnabled()) { + log.info("observer is no longer active, won't send " + email); + } + } else if (StringUtils.isBlank(emailToUpdateAllegroWallets)) { + if (log.isInfoEnabled()) { + log.info("no email to update allegro wallets provided in configuration, won't send " + email); + } + } else if ( ! StringUtil.isEmail(emailToUpdateAllegroWallets)) { + if (log.isWarnEnabled()) { + log.warn("email to update allegro wallets provided in configuration is not valid, won't send " + emailToUpdateAllegroWallets); + } + } else { + + email.addBcc(observer); + + email.addTo(emailToUpdateAllegroWallets); + + emailService.send(email); + + observer.addAllegroWallet(boat); + waoUserDao.update(observer); + commit(); + + } + } + } + } + } + + public Contact createContact(AuthenticatedWaoUser authenticatedWaoUser, String sampleRowId, String boatId) { + + if (log.isInfoEnabled()) { + log.info(authenticatedWaoUser.getWaoUser() + " is creating a contact for " + sampleRowId + " and " + boatId); + } + + UpdateContactCommand updateContactCommand = newUpdateContactCommand(authenticatedWaoUser, Optional.<String>absent()); + + Boat boat = getBoatDao().findByTopiaId(boatId); + Preconditions.checkState(boat.isActive(), "boat must be active"); + + SampleRow sampleRow = getSampleRowDao().findByTopiaId(sampleRowId); + ObsProgram obsProgram = sampleRow.getObsProgram(); + + WaoUser observer = authenticatedWaoUser.getWaoUser(); + Contact mostRecentContactOrNull = getContactDao().findMostRecentContactOrNull(obsProgram, boatId, observer.getCompany().getTopiaId()); + Preconditions.checkState( + mostRecentContactOrNull == null || mostRecentContactOrNull.getContactState().isFinalState(), + "contact already exists"); + + Date now = serviceContext.getNow(); + + Contact newContact = updateContactCommand.getContact(); + newContact.setDataReliability(DataReliability.UNKNOWN); + newContact.setBoat(boat); + newContact.setMainObserver(observer); + newContact.setSampleRow(sampleRow); + newContact.setCreationDate(now); + + // initial contact state depends on the program + if (obsProgram == ObsProgram.OBSMER) { + newContact.setContactState(ContactState.CONTACT_START); + } else if (obsProgram == ObsProgram.OBSVENTE) { + newContact.setContactState(ContactState.OBSERVATION_EXPECTED); + } + + // we can suppose a new contact default values are the one + // expected in the sampling plan + + if (newContact.getObsProgram() == ObsProgram.OBSVENTE) { + // we hope in this contact, user used expected sampling strategy + newContact.setSamplingStrategy(sampleRow.getSamplingStrategy()); + } + + // In the case of ObsVente, we may have a user who wants to create + // multiple contact for a same day. Here we try, to ease the input + // of data by trying to pre-fill some field using data given + // in a previous entered contact + + if (newContact.getObsProgram() == ObsProgram.OBSVENTE) { + // try to pre-fill some field for user-experience + + // let's try to find a recent similar contact + Map<String, Object> properties = new HashMap<>(); + properties.put(Contact.PROPERTY_OBS_PROGRAM_ORDINAL, newContact.getObsProgram().ordinal()); + properties.put(Contact.PROPERTY_SAMPLE_ROW, sampleRow); + properties.put(Contact.PROPERTY_MAIN_OBSERVER, observer); + + List<Contact> candidates = getContactDao().forProperties(properties).findAll(); + + Contact similarContact = null; // to be found among candidates + for (Contact candidate : candidates) { + if (DateUtil.getDifferenceInDays(candidate.getCreationDate(), now) <= 1) { + similarContact = candidate; + } + } + + if (log.isDebugEnabled()) { + String logMessage; + if (similarContact == null) { + logMessage = "no similar contact found"; + } else { + logMessage = "similar contact found to pre-fill values of contact : " + + similarContact.getTopiaId() + " boat = " + similarContact.getBoat().getName(); + } + log.debug(logMessage); + } + + if (similarContact != null) { + newContact.setObservationBeginDate(similarContact.getObservationBeginDate()); + newContact.setObservationEndDate(similarContact.getObservationEndDate()); + newContact.setTerrestrialLocation(similarContact.getTerrestrialLocation()); + newContact.clearSecondaryObservers(); + newContact.addAllSecondaryObservers(similarContact.getSecondaryObservers()); + newContact.setDataInputDate(similarContact.getDataInputDate()); + } + } + + save0(updateContactCommand); + + commit(); + + return newContact; + + } + +} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/IllegalAcceptationException.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/IllegalAcceptationException.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/IllegalAcceptationException.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/IllegalAcceptationException.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,10 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.entity.Contact; + +public class IllegalAcceptationException extends WaoContactValidationException { + + public IllegalAcceptationException(Contact contact) { + super(contact); + } +} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingContactTerrestrialLocationException.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingContactTerrestrialLocationException.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingContactTerrestrialLocationException.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingContactTerrestrialLocationException.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,10 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.entity.Contact; + +public class MissingContactTerrestrialLocationException extends WaoContactValidationException { + + public MissingContactTerrestrialLocationException(Contact contact) { + super(contact); + } +} Deleted: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsList.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsList.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsList.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,60 +0,0 @@ -package fr.ifremer.wao.services.service; - -/* - * #%L - * Wao :: Services - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import fr.ifremer.wao.entity.Boat; - -import java.io.Serializable; -import java.util.List; - -import org.nuiton.util.pagination.PaginationResult; - -/** - * Created on 4/1/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class ObsMerBoatsList implements Serializable { - - private static final long serialVersionUID = 1L; - - protected PaginationResult<Boat> boats; - - protected BoatsFilterValues filterValues; - - public PaginationResult<Boat> getBoats() { - return boats; - } - - public void setBoats(PaginationResult<Boat> boats) { - this.boats = boats; - } - - public BoatsFilterValues getFilterValues() { - return filterValues; - } - - public void setFilterValues(BoatsFilterValues filterValues) { - this.filterValues = filterValues; - } -} Deleted: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,291 +0,0 @@ -package fr.ifremer.wao.services.service; - -/* - * #%L - * Wao :: Services - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Charsets; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.cache.Cache; -import com.google.common.collect.ImmutableSet; -import fr.ifremer.wao.BoatsFilter; -import fr.ifremer.wao.ContactsFilter; -import fr.ifremer.wao.WaoTechnicalException; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.BoatInfos; -import fr.ifremer.wao.entity.BoatInfosImpl; -import fr.ifremer.wao.entity.BoatInfosTopiaDao; -import fr.ifremer.wao.entity.BoatTopiaDao; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactState; -import fr.ifremer.wao.entity.ContactTopiaDao; -import fr.ifremer.wao.entity.ElligibleBoat; -import fr.ifremer.wao.entity.ElligibleBoatTopiaDao; -import fr.ifremer.wao.entity.ObsProgram; -import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.services.service.csv.BoatImportExportModel; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Export; -import org.nuiton.csv.ExportModel; -import org.nuiton.util.pagination.PaginationParameter; -import org.nuiton.util.pagination.PaginationResult; - -import java.io.InputStream; -import java.util.Collection; -import java.util.Date; -import java.util.HashSet; -import java.util.List; - -/** - * Created on 4/1/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class ObsMerBoatsService extends WaoServiceSupport { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ObsMerBoatsService.class); - - public BoatsFilterValues getBoatsFilterValues(AuthenticatedWaoUser authenticatedWaoUser, BoatsFilter filter) { - - Optional<String> optionalCompanyId = Optional.absent(); - if (authenticatedWaoUser.isCoordinatorOrObserver()) { - optionalCompanyId = Optional.of(authenticatedWaoUser.getCompany().getTopiaId()); - } - - BoatsFilterValuesCacheKey boatsFilterValuesCacheKey = - new BoatsFilterValuesCacheKey( - serviceContext.getLocale(), - authenticatedWaoUser.getObsProgram(), - optionalCompanyId); - - Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> cache = - serviceContext.getBoatsFilterValuesCache(); - - BoatsFilterValues boatsFilterValues = cache.getIfPresent(boatsFilterValuesCacheKey); - - if (boatsFilterValues == null) { - - BoatTopiaDao dao = getBoatDao(); - - List<Boat> boats = dao.findAll(filter); - - boatsFilterValues = new BoatsFilterValues(serviceContext.getLocale(), authenticatedWaoUser.getObsProgram(), optionalCompanyId); - - for (Boat boat : boats) { - boatsFilterValues.addBoat(boat); - } - - cache.put(boatsFilterValuesCacheKey, boatsFilterValues); - - } - - return boatsFilterValues; - } - - public ObsMerBoatsList getBoatsList(AuthenticatedWaoUser authenticatedWaoUser, - BoatsFilter filter, - PaginationParameter pager) { - - BoatTopiaDao dao = getBoatDao(); - - PaginationResult<Boat> boats = dao.find(filter, pager); - - BoatsFilterValues boatsFilterValues = getBoatsFilterValues(authenticatedWaoUser, filter); - - ObsMerBoatsList obsMerBoatsList = new ObsMerBoatsList(); - obsMerBoatsList.setBoats(boats); - obsMerBoatsList.setFilterValues(boatsFilterValues); - return obsMerBoatsList; - } - - public PaginationParameter newBoatsPaginationParameter(int pageNumber, int pageSize) { - PaginationParameter result = PaginationParameter.of(pageNumber, pageSize, Boat.PROPERTY_NAME, false); - return result; - } - - public BoatsFilter newBoatsFilter(AuthenticatedWaoUser authenticatedWaoUser) { - - BoatsFilter boatsFilter = new BoatsFilter(); - - if (authenticatedWaoUser.isProfessional()) { - // Pour le profesionnel, on restreint d'office à la liste des bateaux qu'il peut voir - Collection<String> canReadBoatsTopiaIds = authenticatedWaoUser.getWaoUser().getCanReadBoatsTopiaIds(); - if (CollectionUtils.isEmpty(canReadBoatsTopiaIds)) { - if (log.isWarnEnabled()) { - log.warn("user " + authenticatedWaoUser.getWaoUser() + " is professional but can't read any boat"); - } - } else { - boatsFilter.setBoatIds(new HashSet<>(canReadBoatsTopiaIds)); - } - } - - return boatsFilter; - - } - - public InputStream exportBoats(BoatsFilter filter) { - - BoatTopiaDao dao = getBoatDao(); - - List<Boat> sampleRows = dao.findAll(filter); - - ExportModel<Boat> exportModel = - new BoatImportExportModel(getLocale()); - - Export<Boat> export = Export.newExport(exportModel, sampleRows); - - try { - - String csvContent = export.toString(Charsets.UTF_8); - - InputStream csvInputStream = IOUtils.toInputStream(csvContent, Charsets.UTF_8); - - return csvInputStream; - - } catch (Exception e) { - throw new WaoTechnicalException(e); - } - } - - public BoatDetails getBoatDetails(ObsProgram obsProgram, String boatId, String companyId) { - - BoatInfos boatInfos = getBoatInfos(boatId, companyId); - - Contact mostRecentContact = getContactDao().findMostRecentContactOrNull(obsProgram, boatId, companyId); - - ContactsFilter filter = new ContactsFilter(); - filter.getSampleRowFilter().setObsProgram(obsProgram); - filter.getBoatFilter().setBoatIds(ImmutableSet.of(boatId)); - filter.getSampleRowFilter().setCompanyIds(ImmutableSet.of(companyId)); - long contactsCount = getContactDao().forFilter(filter, false).count(); - - Date now = serviceContext.getNow(); - - BoatDetails boatDetails = new BoatDetails(now, obsProgram, boatInfos, mostRecentContact, contactsCount); - - return boatDetails; - - } - - public BoatInfos getBoatInfos(String boatId, String companyId) { - - BoatInfosTopiaDao dao = getBoatInfosDao(); - - Optional<BoatInfos> optionalBoatInfos = - dao.newQueryBuilder() - .addTopiaIdEquals(BoatInfos.PROPERTY_BOAT, boatId) - .addTopiaIdEquals(BoatInfos.PROPERTY_COMPANY, companyId) - .tryFindUnique(); - - BoatInfos boatInfos; - if (optionalBoatInfos.isPresent()) { - boatInfos = optionalBoatInfos.get(); - } else { - Boat boat = getBoatDao().findByTopiaId(boatId); - Company company = getCompanyDao().findByTopiaId(companyId); - boatInfos = new BoatInfosImpl(); - boatInfos.setBoat(boat); - boatInfos.setCompany(company); - } - - return boatInfos; - - } - - public void saveBoatInfos(BoatInfos boatInfos) { - - BoatInfosTopiaDao dao = getBoatInfosDao(); - - if (boatInfos.isPersisted()) { - dao.update(boatInfos); - } else { - dao.create(boatInfos); - } - - commit(); - - } - - public BoatContactsCounts getBoatContactsCounts(AuthenticatedWaoUser authenticatedWaoUser, String boatId, String companyId, Date since) { - - ContactsFilter filter = new ContactsFilter(); - - filter.getSampleRowFilter().setObsProgram(authenticatedWaoUser.getObsProgram()); - filter.setPeriodFrom(since); - filter.getBoatFilter().setBoatIds(ImmutableSet.of(boatId)); - filter.setFilterOnObservationBeginDate(false); - - ContactTopiaDao dao = getContactDao(); - - long contactsCount = dao.forFilter(filter, false).count(); - - filter.getSampleRowFilter().setCompanyIds(ImmutableSet.of(companyId)); - long contactsCompanyCount = dao.forFilter(filter, false).count(); - - filter.setContactStates(ImmutableSet.of(ContactState.OBSERVATION_DONE)); - long observationsCompanyCount = dao.forFilter(filter, false).count(); - - filter.getSampleRowFilter().setCompanyIds(null); - long observationsCount = dao.forFilter(filter, false).count(); - - Preconditions.checkState(contactsCompanyCount <= contactsCount); - Preconditions.checkState(observationsCount <= contactsCount); - - Preconditions.checkState(observationsCompanyCount <= contactsCompanyCount); - Preconditions.checkState(observationsCompanyCount <= observationsCount); - - return new BoatContactsCounts(contactsCount, observationsCount, contactsCompanyCount, observationsCompanyCount); - - } - - public Collection<Boat> getBoats(BoatsFilter boatsFilter, int pageSize) { - - PaginationParameter pager = newBoatsPaginationParameter(0, pageSize); - - PaginationResult<Boat> boats = getBoatDao().find(boatsFilter, pager); - - return boats.getElements(); - - } - - public void changeBoatElligibility(AuthenticatedWaoUser authenticatedWaoUser, String boatId, String sampleRowId, boolean active) { - - ElligibleBoatTopiaDao dao = getElligibleBoatDao(); - - ElligibleBoat elligibleBoat = dao.forBoatIdAndSampleRowId(boatId, sampleRowId).findUnique(); - - if (authenticatedWaoUser.isAdmin()) { - elligibleBoat.setGlobalActive(active); - } else if (authenticatedWaoUser.isCoordinatorOrObserver()) { - elligibleBoat.setCompanyActive(active); - } else { - throw new IllegalStateException(authenticatedWaoUser.getWaoUser().toString()); - } - - commit(); - } -} Deleted: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,1024 +0,0 @@ -package fr.ifremer.wao.services.service; - -/* - * #%L - * Wao :: Services - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Charsets; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableSet; -import fr.ifremer.wao.ContactsFilter; -import fr.ifremer.wao.WaoTechnicalException; -import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactImpl; -import fr.ifremer.wao.entity.ContactState; -import fr.ifremer.wao.entity.ContactStateMotif; -import fr.ifremer.wao.entity.ContactTopiaDao; -import fr.ifremer.wao.entity.DataReliability; -import fr.ifremer.wao.entity.ElligibleBoat; -import fr.ifremer.wao.entity.ElligibleBoatTopiaDao; -import fr.ifremer.wao.entity.ObsProgram; -import fr.ifremer.wao.entity.ObservedDataControl; -import fr.ifremer.wao.entity.SampleMonth; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.entity.WaoUserTopiaDao; -import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.services.service.csv.ObsMerContactImportExportModel; -import fr.ifremer.wao.services.service.mail.AddBoatToUserAllegroWalletEmail; -import fr.ifremer.wao.services.service.mail.EmailService; -import fr.ifremer.wao.services.service.mail.MammalsObservationEmail; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.AbstractImportErrorInfo; -import org.nuiton.csv.Export; -import org.nuiton.csv.ExportModel; -import org.nuiton.csv.Import2; -import org.nuiton.csv.ImportConf; -import org.nuiton.csv.ImportModel; -import org.nuiton.csv.ImportRow; -import org.nuiton.i18n.I18n; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.util.DateUtil; -import org.nuiton.util.StringUtil; -import org.nuiton.util.beans.Binder; -import org.nuiton.util.beans.BinderFactory; -import org.nuiton.util.pagination.PaginationParameter; -import org.nuiton.util.pagination.PaginationResult; - -import java.io.InputStream; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -import static org.nuiton.i18n.I18n.l; - -public class ObsMerContactsService extends WaoServiceSupport { - - private static final Log log = LogFactory.getLog(ObsMerContactsService.class); - - public ContactsFilterValues getContactsFilterValues(AuthenticatedWaoUser authenticatedWaoUser, ContactsFilter filter) { - - ContactTopiaDao dao = getContactDao(); - List<Contact> contacts = dao.forFilter(filter, false).findAll(); - - Optional<String> optionalCompanyId = Optional.absent(); - if (authenticatedWaoUser.isCoordinatorOrObserver()) { - optionalCompanyId = Optional.of(authenticatedWaoUser.getCompany().getTopiaId()); - } - ContactsFilterValues contactsFilterValues = new ContactsFilterValues(serviceContext.getLocale(), authenticatedWaoUser.getObsProgram(), optionalCompanyId); - - for (Contact contact : contacts) { - contactsFilterValues.addContact(contact); - } - - return contactsFilterValues; - } - - public ObsMerContactsList getContactsList(AuthenticatedWaoUser authenticatedWaoUser, - ContactsFilter filter, - PaginationParameter queryPager) { - - ContactTopiaDao dao = getContactDao(); - - // Need to copy to add sort attributes - PaginationParameter.PaginationParameterBuilder builder = PaginationParameter.builder(queryPager.getPageNumber(), queryPager.getPageSize()); - if (filter.isSortedByBoardingDate()) { - builder.addOrder(Contact.PROPERTY_OBSERVATION_BEGIN_DATE, true); - } else { - builder.addOrder(Contact.PROPERTY_CREATION_DATE, true); - } - PaginationParameter pager = builder.build(); - - PaginationResult<Contact> contacts = dao.forFilter(filter, false).findPage(pager); - - ContactsFilterValues filterValues = getContactsFilterValues(authenticatedWaoUser, filter); - - ObsMerContactsList contactsList = new ObsMerContactsList(); - contactsList.setContacts(contacts); - contactsList.setFilterValues(filterValues); - return contactsList; - } - - public PaginationParameter newContactsPaginationParameter(int pageNumber, int pageSize) { - PaginationParameter result = PaginationParameter.of(pageNumber, pageSize); - return result; - } - - public ContactsFilter newContactFilter(AuthenticatedWaoUser authenticatedWaoUser) { - - ContactsFilter newContactsFilter = new ContactsFilter(); - - newContactsFilter.getSampleRowFilter().setObsProgram(authenticatedWaoUser.getObsProgram()); - - // DO NOT REMOVE THIS - if (authenticatedWaoUser.isCoordinatorOrObserver()) { - String authenticatedWaoUserCompanyTopiaId = authenticatedWaoUser.getWaoUser().getCompany().getTopiaId(); - newContactsFilter.getSampleRowFilter().setCompanyIds(ImmutableSet.of(authenticatedWaoUserCompanyTopiaId)); - } - - Calendar periodFromCalendar = Calendar.getInstance(); - periodFromCalendar.setTime(serviceContext.getNow()); - - // in the firsts months of a new year go from now to 6 months before - // in the rest of the year, just start at the beginning of the current year - if (periodFromCalendar.get(Calendar.MONTH) < 3) { - periodFromCalendar.add(Calendar.MONTH, -6); - } else { - periodFromCalendar.set(Calendar.DAY_OF_YEAR, 1); - } - - Date periodFrom = periodFromCalendar.getTime(); - Date periodTo = DateUtils.addYears(periodFromCalendar.getTime(), 1); - - newContactsFilter.setPeriodFrom(periodFrom); - newContactsFilter.setPeriodTo(periodTo); - - if (authenticatedWaoUser.isProfessional()) { - // Pour le profesionnel, on restreint d'office à la liste des contacts portant sur les bateaux qu'il peut voir - Collection<String> canReadBoatsTopiaIds = authenticatedWaoUser.getWaoUser().getCanReadBoatsTopiaIds(); - if (CollectionUtils.isEmpty(canReadBoatsTopiaIds)) { - if (log.isWarnEnabled()) { - log.warn("user " + authenticatedWaoUser.getWaoUser() + " is professional but can't read any boat"); - } - } else { - newContactsFilter.getBoatFilter().setBoatIds(new HashSet<>(canReadBoatsTopiaIds)); - } - } - - return newContactsFilter; - - } - - public UpdateContactCommand newUpdateContactCommand(AuthenticatedWaoUser authenticatedWaoUser, Optional<String> optionalContactId) { - - //FIXME Should we apply some security rules (can create, update, import) ? - //Preconditions.checkState(authenticatedWaoUser.isAuthorizedToCreateSampleRow()); - - UpdateContactCommand updateContactCommand = new UpdateContactCommand(); - - updateContactCommand.setAdmin(authenticatedWaoUser.isAdmin()); - - Contact contact; - - if (optionalContactId.isPresent()) { - - String contactId = optionalContactId.get(); - - contact = getContact(contactId); - - updateContactCommand.setContact(contact); - - updateContactCommand.setCreation(false); - - String mainObserverId = contact.getMainObserver().getTopiaId(); - updateContactCommand.setMainObserverId(mainObserverId); - Set<String> secondaryObserversTopiaIds = contact.getSecondaryObserversTopiaIds(); - updateContactCommand.setSecondaryObserverIds(secondaryObserversTopiaIds); - - } else { - - contact = new ContactImpl(); - - contact.setObsProgram(authenticatedWaoUser.getObsProgram()); - - updateContactCommand.setContact(contact); - - updateContactCommand.setCreation(true); - } - - return updateContactCommand; - } - - public Contact getContact(String contactId) { - return getContactDao().forTopiaIdEquals(contactId).findUnique(); - } - - public InputStream exportContacts(ContactsFilter filter) { - ContactTopiaDao dao = getContactDao(); - - List<Contact> contacts = dao.forFilter(filter, true).findAll(); - - ExportModel<Contact> exportModel = ObsMerContactImportExportModel.forExport(getLocale(), - filter.getSampleRowFilter().getObsProgram()); - - Export<Contact> export = Export.newExport(exportModel, contacts); - - try { - - String csvContent = export.toString(Charsets.UTF_8); - - InputStream csvInputStream = IOUtils.toInputStream(csvContent, Charsets.UTF_8); - - return csvInputStream; - - } catch (Exception e) { - throw new WaoTechnicalException(e); - } - } - - public void importContacts(AuthenticatedWaoUser authenticatedWaoUser, - InputStream csv) throws ImportErrorException { - - ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); - - List<SampleRow> sampleRows = - getSampleRowDao().forObsProgramOrdinalEquals(obsProgram.ordinal()).findAll(); - List<WaoUser> waoUsers = getWaoUserDao().findAll(); - List<Boat> boats = getBoatDao().findAll(); - List<ContactStateMotif> motives = getContactStateMotifDao().findAll(); - - Locale l = getLocale(); - ImportModel<Contact> contactImportModel = - ObsMerContactImportExportModel.forImport(l, - obsProgram, - waoUsers, - sampleRows, - boats, - motives); - - ImportConf importConf = new ImportConf(); - importConf.setStrictMode(true); - - Import2<Contact> contactImport = Import2.newImport(importConf, contactImportModel, csv); - - for (ImportRow<Contact> contactRow : contactImport) { - - if (!contactRow.isValid()) { - // throw first error - Set<AbstractImportErrorInfo<Contact>> errors = contactRow.getErrors(); - AbstractImportErrorInfo<Contact> errorInfo = errors.iterator().next(); - throw new ImportErrorException(errorInfo.getCause()); - } - long lineNumber = contactRow.getLineNumber(); - - Contact contact = contactRow.getBean(); - - String contactId = contact.getTopiaId(); - - if (StringUtils.isEmpty(contactId)) { - contactId = null; - } - - Optional<String> optionalContactId = Optional.fromNullable(contactId); - UpdateContactCommand updateContactCommand = newUpdateContactCommand(authenticatedWaoUser, - optionalContactId); - - if (updateContactCommand.isCreation()) { - - updateContactCommand.setContact(contact); - - // Prevent that someone who is not admin change data that only admin - // must be able to modify - if ( ! authenticatedWaoUser.isAdmin()) { - contact.setCommentAdmin(null); - contact.setValidationProgram(null); - contact.setDataReliability(DataReliability.UNKNOWN); - } - - } else { - - Contact contactToUpdate = updateContactCommand.getContact(); - Binder<Contact, Contact> binder = BinderFactory.newBinder(Contact.class); - binder.copy(contact, contactToUpdate, - Contact.PROPERTY_CREATION_DATE, - Contact.PROPERTY_MAIN_OBSERVER, - Contact.PROPERTY_SECONDARY_OBSERVERS, - "contactState", - Contact.PROPERTY_OBSERVATION_BEGIN_DATE, - Contact.PROPERTY_OBSERVATION_END_DATE, - Contact.PROPERTY_DATA_INPUT_DATE, - Contact.PROPERTY_COMMENT, - Contact.PROPERTY_COMMENT_COORDINATOR, - Contact.PROPERTY_COMMENT_ADMIN, - Contact.PROPERTY_BOAT, - Contact.PROPERTY_VALIDATION_COMPANY, - Contact.PROPERTY_VALIDATION_PROGRAM, - Contact.PROPERTY_SAMPLE_ROW, - Contact.PROPERTY_MAMMALS_OBSERVATION, - Contact.PROPERTY_MAMMALS_CAPTURE, - Contact.PROPERTY_MAMMALS_INFO, - Contact.PROPERTY_CONTACT_STATE_MOTIF, - Contact.PROPERTY_RESTITUTION, - Contact.PROPERTY_OBSERVED_DATA_CONTROL); - - // Prevent that someone who is not admin change data that only admin - // must be able to modify - if ( ! authenticatedWaoUser.isAdmin()) { - contactToUpdate.setCommentAdmin(contact.getCommentAdmin()); - contactToUpdate.setValidationProgram(contact.getValidationProgram()); - contactToUpdate.setDataReliability(contact.getDataReliability()); - } - - } - - try { - validate(authenticatedWaoUser, updateContactCommand, false); - } catch (ContactNotUpdatableException e) { - String message = l(l, "wao.import.contact.failure.not.updatable", lineNumber); - throw new ImportErrorException(message); - } catch (UnwantedContactContactStateMotifException e) { - String message = l(l, "wao.import.contact.failure.unwantedContactStateMotif", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactNbObservantsException e) { - String state = WaoUtils.l(l, e.getContact().getContactState()); - String message = l(l, "wao.import.contact.failure.missingObserver", lineNumber, state); - throw new ImportErrorException(message); - } catch (MissingContactObservationEndDateException e) { - String state = WaoUtils.l(l, e.getContact().getContactState()); - String message = l(l, "wao.import.contact.failure.missingObservationEndDate", lineNumber, state); - throw new ImportErrorException(message); - } catch (ContactDataInputDateBeforeObservationEndDateException e) { - String message = l(l, "wao.import.contact.failure.dataInputDateBeforeObservationEndDate", lineNumber); - throw new ImportErrorException(message); - } catch (InvalidContactObservationBeginDateException e) { - String message = l(l, "wao.import.contact.failure.invalidObservationBeginDate", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactRestitutionException e) { - String message = l(l, "wao.import.contact.failure.missingRestitution", lineNumber); - throw new ImportErrorException(message); - } catch (ContactDataInputDateAfterTodayException e) { - String message = l(l, "wao.import.contact.failure.dataInputDateAfterToday", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactCommentException e) { - String state = WaoUtils.l(l, e.getContact().getContactState()); - String message = l(l, "wao.import.contact.failure.missingComment", state, lineNumber); - throw new ImportErrorException(message); - } catch (MismatchContactMainObserverCompanyException e) { - String companyName = e.getCompany().getName(); - String observerLogin = e.getObserver().getLogin(); - String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, companyName); - throw new ImportErrorException(message); - } catch (ContactRestitutionDateBeforeDataInputDateException e) { - String message = l(l, "wao.import.contact.failure.transmissionDateBeforeDataInputDate", lineNumber); - throw new ImportErrorException(message); - } catch (ContactObservationEndDateBeforeBeginDateException e) { - String message = l(l, "wao.import.contact.failure.observationEndDateBeforeBeginDate", lineNumber); - throw new ImportErrorException(message); - } catch (DuplicatedContactMainObserverInSecondaryObserversException e) { - String message = l(l, "wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactDataReliabilityException e) { - String message = l(l, "wao.import.contact.failure.missingDataReliability", lineNumber); - throw new ImportErrorException(message); - } catch (MismatchContactSecondaryObserverCompanyException e) { - String companyName = e.getCompany().getName(); - String observerLogin = e.getObserver().getLogin(); - String message = l(l, "wao.import.contact.failure.mismatchCompanyForObserver", lineNumber, observerLogin, companyName); - throw new ImportErrorException(message); - } catch (MissingContactObservedDataControlException e) { - String message = l(l, "wao.import.contact.failure.missingObservedDataControl", lineNumber); - throw new ImportErrorException(message); - } catch (ContactWithObservedDataControlToCorrectionAskedException e) { - String message = l(l, "wao.import.contact.failure.observedDataControlToCorrectionAsked", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactStateMotifException e) { - String message = l(l, "wao.import.contact.failure.missingContactStateMotif", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactDataInputDateException e) { - String message = l(l, "wao.import.contact.failure.missingDataInputDate", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactMainObserverException e) { - String message = l(l, "wao.import.contact.failure.missingMainObserver", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactCommentAdminException e) { - String dataReliability = WaoUtils.l(l, e.getContact().getDataReliability()); - String message = l(l, "wao.import.contact.failure.missingCommentAdmin", lineNumber, dataReliability); - throw new ImportErrorException(message); - } catch (ContactObservationEndDateAfterTodayException e) { - String message = l(l, "wao.import.contact.failure.observationEndDateAfterToday", lineNumber); - throw new ImportErrorException(message); - } catch (MissingContactObservationBeginDateException e) { - String state = WaoUtils.l(l, e.getContact().getContactState()); - String message = l(l, "wao.import.contact.failure.missingObservationBeginDate", lineNumber, state); - throw new ImportErrorException(message); - } catch (MissingContactMammalsInfoException e) { - String message = l(l, "wao.import.contact.failure.missingContactMammalsInfo", lineNumber); - throw new ImportErrorException(message); - } - - save0(updateContactCommand); - } - - commit(); - } - - public void preValidate(UpdateContactCommand updateContactCommand) { - - String mainObserverId = updateContactCommand.getMainObserverId(); - - WaoUser mainObserver = getWaoUserDao().forTopiaIdEquals(mainObserverId).findUnique(); - updateContactCommand.getContact().setMainObserver(mainObserver); - - List<WaoUser> secondaryObservers = getWaoUserDao().forTopiaIdIn(updateContactCommand.getSecondaryObserverIds()).findAll(); - updateContactCommand.getContact().setSecondaryObservers(new HashSet<>(secondaryObservers)); - - } - - public void validate(AuthenticatedWaoUser authenticatedWaoUser, - UpdateContactCommand updateContactCommand, - boolean needUpdate) throws - ContactNotUpdatableException, - MissingContactMainObserverException, - MismatchContactMainObserverCompanyException, - DuplicatedContactMainObserverInSecondaryObserversException, - MismatchContactSecondaryObserverCompanyException, - InvalidContactObservationBeginDateException, - ContactObservationEndDateBeforeBeginDateException, - ContactObservationEndDateAfterTodayException, - ContactDataInputDateBeforeObservationEndDateException, - ContactDataInputDateAfterTodayException, - MissingContactCommentException, - MissingContactObservationBeginDateException, - MissingContactObservationEndDateException, - MissingContactNbObservantsException, - MissingContactStateMotifException, - UnwantedContactContactStateMotifException, - MissingContactObservedDataControlException, - MissingContactMammalsInfoException, - ContactWithObservedDataControlToCorrectionAskedException, - MissingContactRestitutionException, - MissingContactDataInputDateException, - ContactRestitutionDateBeforeDataInputDateException, - MissingContactDataReliabilityException, - MissingContactCommentAdminException { - - if (needUpdate) { - Preconditions.checkState(!updateContactCommand.isCreation()); - } - - //FIXME Do some security checks about authenticatedWaoUser - - // Check if contact can be updated - boolean canUpdateContact = updateContactCommand.canUpdateContact(authenticatedWaoUser); - if (!canUpdateContact) { - throw new ContactNotUpdatableException(); - } - - // Check if a validation controls are required - boolean mustValidateContact = updateContactCommand.mustValidateContact(); - - if (mustValidateContact) { - - // Pass validation controls - Contact contact = updateContactCommand.getContact(); - - Company company = contact.getSampleRow().getCompany(); - - WaoUser mainObserver = contact.getMainObserver(); - - { - //--- - // mainObserver - //--- - - if (mainObserver == null) { - throw new MissingContactMainObserverException(contact); - } - - boolean observerWorksForCompanyInSampleRow = mainObserver.getCompany().equals(company); - if (!observerWorksForCompanyInSampleRow) { - throw new MismatchContactMainObserverCompanyException(contact, mainObserver, company); - } - } - - if (contact.isSecondaryObserversNotEmpty()) { - - //--- - // secondaryObservers - //--- - - if (contact.getSecondaryObservers().contains(mainObserver)) { - throw new DuplicatedContactMainObserverInSecondaryObserversException(contact); - } - - for (WaoUser observer : contact.getSecondaryObservers()) { - boolean observerWorksForCompanyInSampleRow = observer.getCompany().equals(company); - if (!observerWorksForCompanyInSampleRow) { - throw new MismatchContactSecondaryObserverCompanyException(contact, observer, company); - } - } - } - - Date observationBeginDate = contact.getObservationBeginDate(); - Date observationEndDate = contact.getObservationEndDate(); - Date dataInputDate = contact.getDataInputDate(); - - SampleRow sampleRow = contact.getSampleRow(); - - if (observationBeginDate != null) { - - //--- - // observationBeginDate - //--- - - SampleMonth month = sampleRow.getSampleMonth(observationBeginDate); - boolean operationBeginDateIsValid = month != null; - - if (!operationBeginDateIsValid) { - throw new InvalidContactObservationBeginDateException(contact); - } - } - - Date currentDate = serviceContext.getNow(); - - if (observationEndDate != null) { - - //--- - // observationEndDate - //--- - - if (observationBeginDate != null - && observationEndDate.before(observationBeginDate)) { - throw new ContactObservationEndDateBeforeBeginDateException(contact); - } - - if (observationEndDate.after(currentDate)) { - throw new ContactObservationEndDateAfterTodayException(contact, currentDate); - } - - } - - if (dataInputDate != null) { - - //--- - // dataInputDate - //--- - - if (observationEndDate != null) { - - // Here, we check that the date input date is after the end of the - // observation. Since the first is a day (at 00:00) and the second - // is date-time, there may be a bug if the data input day is the same - // as the end of observation - boolean dataInputDateAfterObservationEndDate = - observationEndDate.after(DateUtil.setMaxTimeOfDay(dataInputDate)); - - if (dataInputDateAfterObservationEndDate) { - throw new ContactDataInputDateBeforeObservationEndDateException(contact); - } - } - - if (dataInputDate.after(currentDate)) { - throw new ContactDataInputDateAfterTodayException(contact, currentDate); - } - } - - //--- - // contactState - //--- - - ContactState contactState = contact.getContactState(); - - boolean contactMustHaveAMotif = false; - switch (contactState) { - case OBSERVATION_CANCELLED: - - // Non abouti - - if (StringUtils.isBlank(contact.getComment())) { - throw new MissingContactCommentException(contact); - } - break; - case OBSERVATION_DONE: - - // Observation réalisée - - if (observationBeginDate == null) { - throw new MissingContactObservationBeginDateException(contact); - } - if (observationEndDate == null) { - throw new MissingContactObservationEndDateException(contact); - } - if (contact.getNbObservants() == 0) { - throw new MissingContactNbObservantsException(contact); - } - break; - - case CONTACT_REFUSED: - contactMustHaveAMotif = true; - break; - case CONTACT_DEFINITELY_REFUSED: - contactMustHaveAMotif = true; - break; - - } - - //--- - // contactStateMotif - //--- - - if (contactMustHaveAMotif && contact.getContactStateMotif() == null) { - throw new MissingContactStateMotifException(contact); - } - - if (!contactMustHaveAMotif && contact.getContactStateMotif() != null) { - throw new UnwantedContactContactStateMotifException(contact); - } - - if (contact.isMammalsCapture() && StringUtils.isBlank(contact.getMammalsInfo())) { - throw new MissingContactMammalsInfoException(contact); - } - - if (BooleanUtils.isTrue(contact.getValidationCompany())) { - - //--- - // validationCompany - //--- - - if (ContactState.OBSERVATION_DONE == contactState) { - if (contact.getObservedDataControl() == null) { - throw new MissingContactObservedDataControlException(contact); - } else if (contact.getObservedDataControl().equals(ObservedDataControl.CORRECTION_ASKED)) { - throw new ContactWithObservedDataControlToCorrectionAskedException(contact); - } - } - - // Pour valider un contact société, il faut que le contact aie une date de transmission - Date restitution = contact.getRestitution(); - if (ObservedDataControl.ACCEPTED == contact.getObservedDataControl() && restitution == null) { - throw new MissingContactRestitutionException(contact); - } - if (dataInputDate == null && restitution != null) { - throw new MissingContactDataInputDateException(contact); - } - if (dataInputDate != null && restitution != null && restitution.before(dataInputDate)) { - throw new ContactRestitutionDateBeforeDataInputDateException(contact); - } - } - - DataReliability dataReliability = contact.getDataReliability(); - - if (dataReliability != null && dataReliability.isCommentRequired() && StringUtils.isBlank(contact.getCommentAdmin())) { - throw new MissingContactCommentAdminException(contact); - } - - if (BooleanUtils.isTrue(contact.getValidationProgram())) { - - //--- - // validationProgram - //--- - - // it's an admin validation, data-reliability field must be filled - - if (dataReliability == null || DataReliability.UNKNOWN == dataReliability) { - throw new MissingContactDataReliabilityException(contact); - } - } - } - } - - public void save(UpdateContactCommand updateContactCommand, - boolean needUpdate) throws ContactNotUpdatableException { - - if (needUpdate) { - Preconditions.checkState(!updateContactCommand.isCreation()); - } - - save0(updateContactCommand); - - commit(); - - updateAllegroWalletIfNecessary(updateContactCommand); - - notifyMammalsObservationIfNecessary(updateContactCommand); - - } - - protected void notifyMammalsObservationIfNecessary(UpdateContactCommand updateContactCommand) { - - if (updateContactCommand.isMammalsInfosChanged()) { - - Contact contact = updateContactCommand.getContact(); - - MammalsObservationEmail email = getEmailService().newMammalsObservationEmail(); - email.setContact(contact); - - // now trying to find to what user we need to send the mail - WaoUserTopiaDao userDao = getWaoUserDao(); - // users contains all the user we need to notify for the capture - List<WaoUser> waoUsers = userDao.forMammalsNotificationsEquals(true).addEquals(WaoUser.PROPERTY_ACTIVE, true).findAll(); - - for (WaoUser waoUser : waoUsers) { - if (StringUtil.isEmail(waoUser.getLogin())) { - email.addBcc(waoUser); - } else { - if (log.isWarnEnabled()) { - log.warn("will not send mammals capture notification to user " + waoUser + ". login is not an email"); - } - } - } - - getEmailService().send(email); - - } - - } - - public void delete(String contactId) throws IllegalDeletionException { - - Contact contact = getContact(contactId); - - // Execute delete - ContactTopiaDao dao = getContactDao(); - - Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> allUsages = dao.findAllUsages(contact); - - if (!allUsages.isEmpty()) { - throw new IllegalDeletionException(allUsages); - } - - ObsMerSamplingPlanService samplingPlanService = newService(ObsMerSamplingPlanService.class); - - samplingPlanService.recomputeSampleRowEstimatedAndRealTides(contact.getSampleRow()); - - dao.delete(contact); - - commit(); - } - - protected void save0(UpdateContactCommand updateContactCommand) { - - // Get contact to validate (must exist) - Contact contact = updateContactCommand.getContact(); - - ContactTopiaDao dao = getContactDao(); - - ObsMerSamplingPlanService samplingPlanService = newService(ObsMerSamplingPlanService.class); - - if (updateContactCommand.isCreation()) { - - //Update the elligible boat depends on contact creation. The - //{@code contact} reference can only be created for a sampleRow and a - //boat if both are linked with an elligibleBoat. So this method is - //used to create the link if needed during contacts import. This - //elligibleBoat is needed for the contact owned by a company, so - //the companyActive property of ElligibleBoat will be set to TRUE. No - //admin has decided to explicitly create this link. - - ElligibleBoatTopiaDao elligibleDAO = getElligibleBoatDao(); - ElligibleBoat elligible = elligibleDAO.findUniqueOrNull(contact); - - if (elligible == null) { - // Create new elligible boat not active in a global way - elligible = elligibleDAO.create(contact); - } - elligible.setCompanyActive(Boolean.TRUE); - - if (contact.getCreationDate() == null) { - contact.setCreationDate(serviceContext.getNow()); - } - - samplingPlanService.recomputeSampleRowEstimatedAndRealTides(contact.getSampleRow()); - - dao.create(contact); - - } else { - - samplingPlanService.recomputeSampleRowEstimatedAndRealTides(contact.getSampleRow()); - - dao.update(contact); - } - - } - - protected void updateAllegroWalletIfNecessary(UpdateContactCommand updateContactCommand) { - - Contact contact = updateContactCommand.getContact(); - ContactState contactState = contact.getContactState(); - ObsProgram obsProgram = contact.getObsProgram(); - - boolean addBoatToObserversAllegroWallet = false; - - if (obsProgram == ObsProgram.OBSMER) { - addBoatToObserversAllegroWallet = contactState == ContactState.OBSERVATION_DONE - || contactState == ContactState.OBSERVATION_EXPECTED; - } else if (obsProgram == ObsProgram.OBSVENTE) { - addBoatToObserversAllegroWallet = ContactState.OBSERVATION_DONE == contactState; - } - - if (addBoatToObserversAllegroWallet) { - - Boat boat = contact.getBoat(); - - String info; - - if (contactState == ContactState.OBSERVATION_EXPECTED) { - info = I18n.l( - serviceContext.getLocale(), - "wao.email.addBoatToUserAllegroWallet.contactExpected", - WaoUtils.formatDate(serviceContext.getLocale(), contact.getObservationBeginDate())); - } else if (contactState == ContactState.OBSERVATION_DONE) { - info = I18n.l( - serviceContext.getLocale(), - "wao.email.addBoatToUserAllegroWallet.contactDone", - WaoUtils.formatDateTime(serviceContext.getLocale(), contact.getObservationBeginDate()), - WaoUtils.formatDateTime(serviceContext.getLocale(), contact.getObservationEndDate())); - } else { - throw new IllegalStateException(contactState + " should not lead to a mail sent"); - } - - // in obsvente, only the main observer - Collection<WaoUser> observers; - if (ObsProgram.OBSVENTE.equals(obsProgram)) { - observers = ImmutableSet.of(contact.getMainObserver()); - } else if (ObsProgram.OBSMER.equals(obsProgram)) { - observers = contact.getAllObservers(); - } else { - throw new IllegalStateException(); - } - - EmailService emailService = getEmailService(); - - WaoUserTopiaDao waoUserDao = getWaoUserDao(); - - for (WaoUser observer : observers) { - - boolean boatAlreadyInWallet = observer.containsAllegroWallet(boat); - - if (boatAlreadyInWallet) { - - if (log.isInfoEnabled()) { - log.info("user " + observer + " already has " + boat + " in his allegroWallet"); - } - - } else { - - if (log.isInfoEnabled()) { - log.info("user " + observer + " miss " + boat + " in his allegro wallet, adding"); - } - - String observerLogin = observer.getLogin(); - String emailToUpdateAllegroWallets = getApplicationConfig().getEmailToUpdateAllegroWallets(); - - AddBoatToUserAllegroWalletEmail email = - emailService.newAddBoatToUserAllegroWalletEmail(); - - email.setBoat(boat); - email.setObserver(observer); - email.setInfo(info); - email.setObsProgram(contact.getObsProgram()); - - if ( ! StringUtil.isEmail(observerLogin)) { - if (log.isInfoEnabled()) { - log.info("user login is not a email, won't send anything: " + observerLogin + " email=" + email); - } - } else if ( ! observer.isActive()) { - if (log.isInfoEnabled()) { - log.info("observer is no longer active, won't send " + email); - } - } else if (StringUtils.isBlank(emailToUpdateAllegroWallets)) { - if (log.isInfoEnabled()) { - log.info("no email to update allegro wallets provided in configuration, won't send " + email); - } - } else if ( ! StringUtil.isEmail(emailToUpdateAllegroWallets)) { - if (log.isWarnEnabled()) { - log.warn("email to update allegro wallets provided in configuration is not valid, won't send " + emailToUpdateAllegroWallets); - } - } else { - - email.addBcc(observer); - - email.addTo(emailToUpdateAllegroWallets); - - emailService.send(email); - - observer.addAllegroWallet(boat); - waoUserDao.update(observer); - commit(); - - } - } - } - } - } - - public Contact createContact(AuthenticatedWaoUser authenticatedWaoUser, String sampleRowId, String boatId) { - - if (log.isInfoEnabled()) { - log.info(authenticatedWaoUser.getWaoUser() + " is creating a contact for " + sampleRowId + " and " + boatId); - } - - UpdateContactCommand updateContactCommand = newUpdateContactCommand(authenticatedWaoUser, Optional.<String>absent()); - - Boat boat = getBoatDao().findByTopiaId(boatId); - Preconditions.checkState(boat.isActive(), "boat must be active"); - - SampleRow sampleRow = getSampleRowDao().findByTopiaId(sampleRowId); - ObsProgram obsProgram = sampleRow.getObsProgram(); - - WaoUser observer = authenticatedWaoUser.getWaoUser(); - Contact mostRecentContactOrNull = getContactDao().findMostRecentContactOrNull(obsProgram, boatId, observer.getCompany().getTopiaId()); - Preconditions.checkState( - mostRecentContactOrNull == null || mostRecentContactOrNull.getContactState().isFinalState(), - "contact already exists"); - - Date now = serviceContext.getNow(); - - Contact newContact = updateContactCommand.getContact(); - newContact.setDataReliability(DataReliability.UNKNOWN); - newContact.setBoat(boat); - newContact.setMainObserver(observer); - newContact.setSampleRow(sampleRow); - newContact.setCreationDate(now); - - // initial contact state depends on the program - if (obsProgram == ObsProgram.OBSMER) { - newContact.setContactState(ContactState.CONTACT_START); - } else if (obsProgram == ObsProgram.OBSVENTE) { - newContact.setContactState(ContactState.OBSERVATION_EXPECTED); - } - - // we can suppose a new contact default values are the one - // expected in the sampling plan - - if (newContact.getObsProgram() == ObsProgram.OBSVENTE) { - // we hope in this contact, user used expected sampling strategy - newContact.setSamplingStrategy(sampleRow.getSamplingStrategy()); - } - - // In the case of ObsVente, we may have a user who wants to create - // multiple contact for a same day. Here we try, to ease the input - // of data by trying to pre-fill some field using data given - // in a previous entered contact - - if (newContact.getObsProgram() == ObsProgram.OBSVENTE) { - // try to pre-fill some field for user-experience - - // let's try to find a recent similar contact - Map<String, Object> properties = new HashMap<>(); - properties.put(Contact.PROPERTY_OBS_PROGRAM_ORDINAL, newContact.getObsProgram().ordinal()); - properties.put(Contact.PROPERTY_SAMPLE_ROW, sampleRow); - properties.put(Contact.PROPERTY_MAIN_OBSERVER, observer); - - List<Contact> candidates = getContactDao().forProperties(properties).findAll(); - - Contact similarContact = null; // to be found among candidates - for (Contact candidate : candidates) { - if (DateUtil.getDifferenceInDays(candidate.getCreationDate(), now) <= 1) { - similarContact = candidate; - } - } - - if (log.isDebugEnabled()) { - String logMessage; - if (similarContact == null) { - logMessage = "no similar contact found"; - } else { - logMessage = "similar contact found to pre-fill values of contact : " - + similarContact.getTopiaId() + " boat = " + similarContact.getBoat().getName(); - } - log.debug(logMessage); - } - - if (similarContact != null) { - newContact.setObservationBeginDate(similarContact.getObservationBeginDate()); - newContact.setObservationEndDate(similarContact.getObservationEndDate()); - newContact.setTerrestrialLocation(similarContact.getTerrestrialLocation()); - newContact.clearSecondaryObservers(); - newContact.addAllSecondaryObservers(similarContact.getSecondaryObservers()); - newContact.setDataInputDate(similarContact.getDataInputDate()); - } - } - - save0(updateContactCommand); - - commit(); - - return newContact; - - } - -} Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -21,49 +21,20 @@ * #L% */ -import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.DCF5Code; -import fr.ifremer.wao.entity.FishingZone; -import fr.ifremer.wao.entity.SampleMonth; import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.SampleRowLog; -import fr.ifremer.wao.entity.TerrestrialLocation; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.nuiton.util.DateUtil; -import java.io.Serializable; -import java.text.NumberFormat; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -public class ObsMerSamplingPlan implements Iterable<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart>, Serializable { +public class ObsMerSamplingPlan extends SamplingPlan { private static final long serialVersionUID = 1L; /** - * All facades of the sampling plan. - */ - protected Collection<ObsMerSamplingPlanFacadePart> facades; - - /** - * Total tides over the plan by month. - */ - protected Map<Date, ObsMerSamplingPlanStatistics> totalsPerMonth; - - /** - * High total over the hole plan. - */ - protected ObsMerSamplingPlanStatistics highTotals; - - /** * Total of observation times in days expected. * <p/> * <strong>Note:</strong> can be null. @@ -84,54 +55,21 @@ */ protected Long observationTimesInDaysTotalEstimated; - /** - * List of month used by sample rows. - */ - protected List<Date> months; - - /** - * Universe of filter values. - */ - protected SampleRowsFilterValues filterValues; - - /** - * Ids of all the sample rows included in this sampling plan. - */ - protected Set<String> sampleRowIds; - public ObsMerSamplingPlan(List<Date> months, - Collection<ObsMerSamplingPlanFacadePart> facadeParts, - Map<Date, ObsMerSamplingPlanStatistics> totalsPerMonth, - ObsMerSamplingPlanStatistics highTotals, + Collection<SamplingPlanFacadePart> facadeParts, + Map<Date, SamplingPlanStatistics> totalsPerMonth, + SamplingPlanStatistics highTotals, Double observationTimesInDaysTotalExpected, Long observationTimesInDaysTotalReal, Long observationTimesInDaysTotalEstimated, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { - this.months = months; - this.facades = facadeParts; - this.totalsPerMonth = totalsPerMonth; - this.highTotals = highTotals; + super(months, facadeParts, totalsPerMonth, highTotals, filterValues, sampleRowIds); this.observationTimesInDaysTotalExpected = observationTimesInDaysTotalExpected; this.observationTimesInDaysTotalReal = observationTimesInDaysTotalReal; this.observationTimesInDaysTotalEstimated = observationTimesInDaysTotalEstimated; - this.filterValues = filterValues; - this.sampleRowIds = sampleRowIds; } - public Set<String> getSampleRowIds() { - return sampleRowIds; - } - - @Override - public Iterator<ObsMerSamplingPlanFacadePart> iterator() { - return facades.iterator(); - } - - public List<Date> getMonths() { - return months; - } - public Double getObservationTimesInDaysTotalExpected() { return observationTimesInDaysTotalExpected; } @@ -144,140 +82,17 @@ return observationTimesInDaysTotalEstimated; } - public Integer getTotalExpected(Date month) { - Integer result = totalsPerMonth.get(month).getNbTidesExpected(); - return result; - } - - public Integer getTotalReal(Date month) { - Integer result = totalsPerMonth.get(month).getNbTidesReal(); - return result; - } - - public Integer getTotalEstimated(Date month) { - Integer result = totalsPerMonth.get(month).getNbTidesEstimated(); - return result; - } - - public String getTotalRealRatio(Date month) { - String result = totalsPerMonth.get(month).getRealRatio("-"); - return result; - } - - public String getTotalEstimatedRatio(Date month) { - String result = totalsPerMonth.get(month).getEstimatedRatio("-"); - return result; - } - - public Integer getHighTotalExpected() { - return highTotals.getNbTidesExpected(); - } - - public Integer getHighTotalReal() { - return highTotals.getNbTidesReal(); - } - - public Integer getHighTotalEstimated() { - return highTotals.getNbTidesEstimated(); - } - - public String getHighTotalRealRatio() { - String ratio = highTotals.getRealRatio(""); - return ratio; - } - - public String getHighTotalEstimatedRatio() { - String ratio = highTotals.getEstimatedRatio(""); - return ratio; - } - - public SampleRowsFilterValues getFilterValues() { - return filterValues; - } - /** - * All sectors part for a given facade. - * <p/> * Created on 3/24/14. * * @author Tony Chemit <chemit@codelutin.com> * @since 4.0 */ - public static class ObsMerSamplingPlanFacadePart implements Iterable<ObsMerSamplingPlanSectorPart>, Serializable { + public static class ObsMerSamplingPlanSampleRowPart extends SamplingPlanSampleRowPart { private static final long serialVersionUID = 1L; - protected String facade; - /** - * All sector parts for this facade. - */ - protected Collection<ObsMerSamplingPlanSectorPart> sectors; - - public ObsMerSamplingPlanFacadePart(String facade, - Collection<ObsMerSamplingPlanSectorPart> sectors) { - this.facade = facade; - this.sectors = sectors; - } - - public String getFacade() { - return facade; - } - - @Override - public Iterator<ObsMerSamplingPlanSectorPart> iterator() { - return sectors.iterator(); - } - } - - /** - * Contains sample rows of a same sectors. - */ - public static class ObsMerSamplingPlanSectorPart implements Iterable<ObsMerSamplingPlanSampleRowPart>, Serializable { - - private static final long serialVersionUID = 1L; - - protected String sectors; - - protected Collection<ObsMerSamplingPlanSampleRowPart> sampleRows; - - public ObsMerSamplingPlanSectorPart(String sectors, - Collection<ObsMerSamplingPlanSampleRowPart> sampleRows) { - this.sectors = sectors; - this.sampleRows = sampleRows; - } - - public String getSectors() { - return sectors; - } - - @Override - public Iterator<ObsMerSamplingPlanSampleRowPart> iterator() { - return sampleRows.iterator(); - } - } - - /** - * Created on 3/24/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ - public static class ObsMerSamplingPlanSampleRowPart implements Serializable { - - private static final long serialVersionUID = 1L; - - /** - * Nb tides by month. - */ - protected Map<Date, ObsMerSamplingPlanStatistics> nbTidesPerMonth; - - /** - * Total of tides. - */ - protected ObsMerSamplingPlanStatistics totalTides; - - /** * Expected Times of observation days. * <p/> * <strong>Note:</strong> can be null. @@ -302,107 +117,23 @@ protected Integer observationTimesInDaysRealPercentage; - protected String fishingZones; - protected int nbObservants; protected double averageTideTime; - protected String code; - - protected String fishingZonesInfos; - - protected String comment; - - protected String programName; - - protected Date periodBegin; - - protected Date periodEnd; - - protected String terrestrialLocationInfos; - - protected Date expectedDate; - - protected String groupName; - protected Double appliedCoverageRate; - protected int averageObservationsCount; - - protected String professionMeshSize; - - protected String professionSize; - - protected String professionOther; - - protected String professionLibelle; - - protected String professionSpecies; - - protected String companyName; - - protected String samplingStrategy; - - protected String professionDescriptionWithoutDCF5; - - protected Map<String, String> dcf5CodesAndDescriptions; - - protected Map<String, String> terrestrialLocationNamesAndDescriptions; - - protected String sampleRowId; - - /** - * Date of the latest sample log. - */ - protected Date latestSampleLogCreateDate; - - /** - * First sample month date. - */ - protected Date firstSampleMonthDate; - - /** - * Last sample month date. - */ - protected Date lastSampleMonthDate; - - /** - * Last sample month end of month. - */ - protected Date lastSampleMonthEndOfMonth; - - protected boolean elligibleBoatsProvided; - public ObsMerSamplingPlanSampleRowPart(Locale locale, - Map<Date, ObsMerSamplingPlanStatistics> nbTidesPerMonth, + Map<Date, SamplingPlanStatistics> nbTidesPerMonth, SampleRow sampleRow, Double observationTimesInDaysExpected, Long observationTimesInDaysReal, Long observationTimesInDaysEstimated) { + super(locale, nbTidesPerMonth, sampleRow); this.observationTimesInDaysExpected = observationTimesInDaysExpected; this.observationTimesInDaysReal = observationTimesInDaysReal; this.observationTimesInDaysEstimated = observationTimesInDaysEstimated; - this.nbTidesPerMonth = nbTidesPerMonth; - // compute total tides - int totalTidesExpected = 0; - int totalTidesEstimated = 0; - int totalTidesReal = 0; - for (ObsMerSamplingPlanStatistics obsMerSamplingPlanStatistics : nbTidesPerMonth.values()) { - Integer totalExpected = obsMerSamplingPlanStatistics.getNbTidesExpected(); - if (totalExpected != null) { - totalTidesExpected += totalExpected; - } - Integer totalEstimated = obsMerSamplingPlanStatistics.getNbTidesEstimated(); - if (totalEstimated != null) { - totalTidesEstimated += totalEstimated; - } - Integer totalReal = obsMerSamplingPlanStatistics.getNbTidesReal(); - if (totalReal != null) { - totalTidesReal += totalReal; - } - } if (observationTimesInDaysExpected != null && observationTimesInDaysExpected > 0) { if (observationTimesInDaysEstimated != null) { @@ -412,220 +143,14 @@ observationTimesInDaysRealPercentage = (int) Math.round((observationTimesInDaysReal / observationTimesInDaysExpected) * 100); } } - totalTides = new ObsMerSamplingPlanStatistics(totalTidesExpected, totalTidesReal, totalTidesEstimated); - fishingZones = ""; - for (FishingZone zone : sampleRow.getFishingZone()) { - fishingZones += zone.getDistrictCode() + ", "; - } - fishingZones = fishingZones.substring(0, fishingZones.length() - 2); nbObservants = sampleRow.getNbObservants(); averageTideTime = sampleRow.getAverageTideTime(); - fishingZonesInfos = sampleRow.getFishingZonesInfos(); - comment = sampleRow.getComment(); - programName = sampleRow.getProgramName(); - periodBegin = sampleRow.getPeriodBegin(); - periodEnd = sampleRow.getPeriodEnd(); - terrestrialLocationInfos = sampleRow.getTerrestrialLocationInfos(); - expectedDate = sampleRow.getExpectedDate(); - groupName = sampleRow.getGroupName(); + appliedCoverageRate = sampleRow.getAppliedCoverageRate(); - averageObservationsCount = sampleRow.getAverageObservationsCount(); - companyName = sampleRow.getCompany().getName(); - code = sampleRow.getCode(); - professionMeshSize = sampleRow.getProfession().getMeshSize(); - professionSize = sampleRow.getProfession().getSize(); - professionOther = sampleRow.getProfession().getOther(); - professionLibelle = sampleRow.getProfession().getLibelle(); - professionSpecies = sampleRow.getProfession().getSpecies(); - dcf5CodesAndDescriptions = new LinkedHashMap<>(); - for (DCF5Code dcf5Code : sampleRow.getdCF5Code()) { - String key = dcf5Code.getCode(); - String description = dcf5Code.getFishingGearCode() + " - " + WaoUtils.l(locale, dcf5Code.getFishingGearDCF()); - if (dcf5Code.getTargetSpeciesCode() != null) { - description += " ; " + dcf5Code.getTargetSpeciesCode() + " - " + WaoUtils.l(locale, dcf5Code.getTargetSpeciesDCF()); - } - dcf5CodesAndDescriptions.put(key, description); - } - terrestrialLocationNamesAndDescriptions = new LinkedHashMap<>(); - if (CollectionUtils.isNotEmpty(sampleRow.getTerrestrialLocations())) { - for (TerrestrialLocation terrestrialLocation : sampleRow.getTerrestrialLocations()) { - String key = terrestrialLocation.getDistrictName(); - String description = terrestrialLocation.getDescription(); - terrestrialLocationNamesAndDescriptions.put(key, description); - } - } - professionDescriptionWithoutDCF5 = sampleRow.getProfessionDescriptionWithoutDCF5(); - //FIXME Is this ok? - samplingStrategy = WaoUtils.l(locale,sampleRow.getSamplingStrategy()); - sampleRowId = sampleRow.getTopiaId(); - // consider a recently created sample row as recently updated - latestSampleLogCreateDate = sampleRow.getTopiaCreateDate(); - // compute lastSampleLogCreateDate - if (sampleRow.isSampleRowLogNotEmpty()) { - for (SampleRowLog sampleRowLog : sampleRow.getSampleRowLog()) { - if (sampleRowLog.getCreateDate().after(latestSampleLogCreateDate)) { - latestSampleLogCreateDate = sampleRowLog.getCreateDate(); - } - } - } - - // compute sampleRowPeriod - // TODO brendan 15/04/14 use treeset - List<SampleMonth> sampleMonth = new ArrayList<>(sampleRow.getSampleMonth()); - firstSampleMonthDate = sampleMonth.get(0).getPeriodDate(); - lastSampleMonthDate = sampleMonth.get(sampleMonth.size() - 1).getPeriodDate(); - - lastSampleMonthEndOfMonth = WaoUtils.getEndOfMonth(lastSampleMonthDate); - elligibleBoatsProvided = sampleRow.isElligibleBoatNotEmpty(); } - public String getSamplingStrategy() { - return samplingStrategy; - } - - public String getSampleRowId() { - return sampleRowId; - } - - public Date getFirstSampleMonthDate() { - return firstSampleMonthDate; - } - - public Date getLastSampleMonthDate() { - return lastSampleMonthDate; - } - - public int getNbObservants() { - return nbObservants; - } - - public double getAverageTideTime() { - return averageTideTime; - } - - public String getCode() { - return code; - } - - public String getFishingZonesInfos() { - return fishingZonesInfos; - } - - public String getTerrestrialLocationInfos() { - return terrestrialLocationInfos; - } - - public String getProfessionSize() { - return professionSize; - } - - public Map<String, String> getDcf5CodesAndDescriptions() { - return dcf5CodesAndDescriptions; - } - - public Map<String, String> getTerrestrialLocationNamesAndDescriptions() { - return terrestrialLocationNamesAndDescriptions; - } - - public String getComment() { - return comment; - } - - public String getProgramName() { - return programName; - } - - public Date getPeriodBegin() { - return periodBegin; - } - - public Date getPeriodEnd() { - return periodEnd; - } - - public Date getExpectedDate() { - return expectedDate; - } - - public String getGroupName() { - return groupName; - } - - public Double getAppliedCoverageRate() { - return appliedCoverageRate; - } - - public int getAverageObservationsCount() { - return averageObservationsCount; - } - - public String getProfessionMeshSize() { - return professionMeshSize; - } - - public String getProfessionOther() { - return professionOther; - } - - public String getProfessionLibelle() { - return professionLibelle; - } - - public String getProfessionSpecies() { - return professionSpecies; - } - - public String getCompanyName() { - return companyName; - } - - public int getTotalTidesExpected() { - return totalTides.getNbTidesExpected(); - } - - public int getTotalTidesReal() { - return totalTides.getNbTidesReal(); - } - - public int getTotalTidesEstimated() { - return totalTides.getNbTidesEstimated(); - } - - public String getProfessionDescriptionWithoutDCF5() { - return professionDescriptionWithoutDCF5; - } - - public Integer getNbTidesExpected(Date month) { - Integer result = nbTidesPerMonth.get(month).getNbTidesExpected(); - return result; - } - - public Integer getNbTidesReal(Date month) { - Integer result = nbTidesPerMonth.get(month).getNbTidesReal(); - return result; - } - - public Integer getNbTidesEstimated(Date month) { - Integer result = nbTidesPerMonth.get(month).getNbTidesEstimated(); - return result; - } - - public String getTotalRealPercentage() { - String result = totalTides.getRealRatio("-"); - return result; - } - - public String getTotalEstimatedPercentage() { - String result = totalTides.getEstimatedRatio("-"); - return result; - } - - public String getFishingZones() { - return fishingZones; - } - public Double getObservationTimesInDaysExpected() { return observationTimesInDaysExpected; } @@ -646,86 +171,16 @@ return observationTimesInDaysEstimatedPercentage; } - public boolean isElligibleBoatsProvided() { - return elligibleBoatsProvided; + public Double getAppliedCoverageRate() { + return appliedCoverageRate; } - public boolean isRecentlyUpdated() { - boolean isRecentlyUpdated = latestSampleLogCreateDate != null - && DateUtil.getDifferenceInDays(latestSampleLogCreateDate, new Date()) <= 2 * 7; - return isRecentlyUpdated; + public int getNbObservants() { + return nbObservants; } - public boolean isNewContactCreatable() { - boolean isNewContactCreatable = new Date().before(lastSampleMonthEndOfMonth); - return isNewContactCreatable; + public double getAverageTideTime() { + return averageTideTime; } } - - public static class ObsMerSamplingPlanStatistics implements Serializable { - - private static final long serialVersionUID = 1L; - - /** - * Number of expected tides. - */ - protected Integer nbTidesExpected; - - /** - * Number of real tides. - */ - protected Integer nbTidesReal; - - /** - * Number of estimated tides. - */ - protected Integer nbTidesEstimated; - - public ObsMerSamplingPlanStatistics(Integer nbTidesExpected, - Integer nbTidesReal, - Integer nbTidesEstimated) { - this.nbTidesExpected = nbTidesExpected; - this.nbTidesReal = nbTidesReal; - this.nbTidesEstimated = nbTidesEstimated; - } - - public Integer getNbTidesExpected() { - return nbTidesExpected; - } - - public Integer getNbTidesReal() { - return nbTidesReal; - } - - public Integer getNbTidesEstimated() { - return nbTidesEstimated; - } - - public String getRealRatio(String defaultValue) { - String ratio = defaultValue; - if (nbTidesExpected != null && nbTidesExpected > 0 && - nbTidesReal != null && nbTidesReal > 0) { - double percent = ((double) nbTidesReal / nbTidesExpected); - ratio = NumberFormat.getPercentInstance().format(percent); - } - return ratio; - } - - public String getEstimatedRatio(String defaultValue) { - String ratio = defaultValue; - if (nbTidesExpected != null && nbTidesExpected > 0 && - nbTidesEstimated != null && nbTidesEstimated > 0) { - double percent = ((double) nbTidesEstimated / nbTidesExpected); - ratio = NumberFormat.getPercentInstance().format(percent); - } - return ratio; - } - - @Override - public String toString() { - String toString = ToStringBuilder.reflectionToString(this); - return toString; - } - - } } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -124,21 +124,21 @@ /** * To compute by month the total of expected tides. * - * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#nbTidesExpected + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesExpected */ protected Map<Date, MutableInt> totalExpectedForMonths; /** * To compute by month the total of expected tides. * - * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#nbTidesEstimated + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesEstimated */ protected Map<Date, MutableInt> totalEstimatedForMonths; /** * To compute by month the total of real tides. * - * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#nbTidesReal + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesReal */ protected Map<Date, MutableInt> totalRealForMonths; @@ -182,7 +182,7 @@ SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); // compute nb tides per month - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> nbTidesPerMonth = computeNbTidesPerMonth(sampleRow); + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> nbTidesPerMonth = computeNbTidesPerMonth(sampleRow); // add sample row sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), @@ -207,34 +207,34 @@ public ObsMerSamplingPlan toPlan() { // Get facade parts - Collection<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart> facadeParts = new ArrayList<>(); + Collection<SamplingPlan.SamplingPlanFacadePart> facadeParts = new ArrayList<>(); for (FacadeContext facadeContext : facadeMap.values()) { - ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart facadePart = facadeContext.toBean(); + SamplingPlan.SamplingPlanFacadePart facadePart = facadeContext.toBean(); facadeParts.add(facadePart); } // Sort them - Collection<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart> sortedFacades = Ordering.natural().onResultOf(new Function<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart, String>() { - public String apply(ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart input) { + Collection<SamplingPlan.SamplingPlanFacadePart> sortedFacades = Ordering.natural().onResultOf(new Function<SamplingPlan.SamplingPlanFacadePart, String>() { + public String apply(SamplingPlan.SamplingPlanFacadePart input) { return input.getFacade(); } }).immutableSortedCopy(facadeParts); // Get statistics - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> statisticsMap = new TreeMap<>(); + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> statisticsMap = new TreeMap<>(); for (Date month : months) { MutableInt totalExpected = totalExpectedForMonths.get(month); MutableInt totalReal = totalRealForMonths.get(month); MutableInt totalEstimated = totalEstimatedForMonths.get(month); - ObsMerSamplingPlan.ObsMerSamplingPlanStatistics planStatistics = - new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics(totalExpected == null ? null : totalExpected.toInteger(), + ObsMerSamplingPlan.SamplingPlanStatistics planStatistics = + new ObsMerSamplingPlan.SamplingPlanStatistics(totalExpected == null ? null : totalExpected.toInteger(), totalReal == null ? null : totalReal.toInteger(), totalEstimated == null ? null : totalEstimated.toInteger()); statisticsMap.put(month, planStatistics); } - ObsMerSamplingPlan.ObsMerSamplingPlanStatistics highTotals = new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics(highTotalExpected, highTotalReal, highTotalEstimated); + ObsMerSamplingPlan.SamplingPlanStatistics highTotals = new ObsMerSamplingPlan.SamplingPlanStatistics(highTotalExpected, highTotalReal, highTotalEstimated); ObsMerSamplingPlan result = new ObsMerSamplingPlan(months, sortedFacades, @@ -248,8 +248,8 @@ return result; } - protected Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> computeNbTidesPerMonth(SampleRow sampleRow) { - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> result = new TreeMap<>(); + protected Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> computeNbTidesPerMonth(SampleRow sampleRow) { + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> result = new TreeMap<>(); for (Date month : months) { Integer expectedTidesValue = SampleRows.getExpectedTidesValue(sampleRow, month); if (expectedTidesValue != null) { @@ -279,7 +279,7 @@ mutableInt.add(estimatedTidesValue); highTotalEstimated += estimatedTidesValue; } - result.put(month, new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics(expectedTidesValue, + result.put(month, new ObsMerSamplingPlan.SamplingPlanStatistics(expectedTidesValue, realTidesValue, estimatedTidesValue)); @@ -309,22 +309,22 @@ return sectorPart; } - protected ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart toBean() { + protected SamplingPlan.SamplingPlanFacadePart toBean() { // get sector parts - Collection<ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart> sectorParts = new ArrayList<>(); + Collection<SamplingPlan.SamplingPlanSectorPart> sectorParts = new ArrayList<>(); for (SectorContext sectorContext : sectorMap.values()) { - ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart sectorPart = sectorContext.toBean(); + SamplingPlan.SamplingPlanSectorPart sectorPart = sectorContext.toBean(); sectorParts.add(sectorPart); } // sort them - Collection<ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart> sortedSectors = Ordering.natural().onResultOf(new Function<ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart, String>() { - public String apply(ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart input) { + Collection<SamplingPlan.SamplingPlanSectorPart> sortedSectors = Ordering.natural().onResultOf(new Function<SamplingPlan.SamplingPlanSectorPart, String>() { + public String apply(SamplingPlan.SamplingPlanSectorPart input) { return input.getSectors(); } }).immutableSortedCopy(sectorParts); - ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart result = - new ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart(facade, sortedSectors); + SamplingPlan.SamplingPlanFacadePart result = + new SamplingPlan.SamplingPlanFacadePart(facade, sortedSectors); return result; } } @@ -340,9 +340,9 @@ this.rows = new ArrayList<>(); } - protected ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart addSampleRow(Locale locale, + protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow(Locale locale, SampleRow row, - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> nbTidesPerMonth, + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> nbTidesPerMonth, Double observationTimesInDaysExpected, Long observationTimesInDaysReal, Long observationTimesInDaysEstimated) { @@ -359,15 +359,15 @@ return rowPart; } - protected ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart toBean() { + protected SamplingPlan.SamplingPlanSectorPart toBean() { Collection<ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart> sortedRows = Ordering.natural().onResultOf(new Function<ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart, String>() { public String apply(ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart input) { return input.getCode(); } }).immutableSortedCopy(rows); - ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart result = - new ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart(sectors, sortedRows); + SamplingPlan.SamplingPlanSectorPart result = + new SamplingPlan.SamplingPlanSectorPart(sectors, sortedRows); return result; } } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -21,376 +21,33 @@ * #L% */ -import com.google.common.base.Charsets; import com.google.common.base.Optional; -import com.google.common.base.Preconditions; import com.google.common.cache.Cache; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; import com.google.common.collect.Range; import com.google.common.collect.Sets; import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.WaoTechnicalException; import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.Boats; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.CompanyTopiaDao; import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ContactState; -import fr.ifremer.wao.entity.DCF5Code; -import fr.ifremer.wao.entity.ElligibleBoat; -import fr.ifremer.wao.entity.ElligibleBoatImpl; -import fr.ifremer.wao.entity.ElligibleBoatTopiaDao; -import fr.ifremer.wao.entity.FishingZone; -import fr.ifremer.wao.entity.FishingZoneTopiaDao; -import fr.ifremer.wao.entity.LocationType; -import fr.ifremer.wao.entity.ObsProgram; -import fr.ifremer.wao.entity.Profession; -import fr.ifremer.wao.entity.ProfessionImpl; -import fr.ifremer.wao.entity.ProfessionTopiaDao; import fr.ifremer.wao.entity.SampleMonth; -import fr.ifremer.wao.entity.SampleMonthImpl; -import fr.ifremer.wao.entity.SampleMonthTopiaDao; import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.SampleRowImpl; -import fr.ifremer.wao.entity.SampleRowLog; -import fr.ifremer.wao.entity.SampleRowLogImpl; -import fr.ifremer.wao.entity.SampleRowLogTopiaDao; import fr.ifremer.wao.entity.SampleRowTopiaDao; -import fr.ifremer.wao.entity.SamplingStrategy; -import fr.ifremer.wao.entity.TerrestrialLocation; -import fr.ifremer.wao.entity.TerrestrialLocationTopiaDao; import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.services.service.administration.ReferentialService; -import fr.ifremer.wao.services.service.administration.UnknownBoatImmatriculationsException; -import fr.ifremer.wao.services.service.csv.ObsMerObsVenteSamplingPlanImportExportModel; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Export; -import org.nuiton.csv.ExportModel; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportModel; -import org.nuiton.csv.ImportRuntimeException; -import org.nuiton.topia.persistence.TopiaEntities; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.util.DateUtil; -import java.io.InputStream; -import java.text.ParseException; -import java.util.Calendar; import java.util.Collection; import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Set; -public class ObsMerSamplingPlanService extends WaoServiceSupport { +public class ObsMerSamplingPlanService extends SamplingPlanService { private static final Log log = LogFactory.getLog(ObsMerSamplingPlanService.class); - public UpdateSampleRowCommand newUpdateSampleRowCommand(AuthenticatedWaoUser authenticatedWaoUser, Optional<String> optionalSampleRowId) { - - Preconditions.checkState(authenticatedWaoUser.isAuthorizedToCreateSampleRow()); - - UpdateSampleRowCommand updateSampleRowCommand = new UpdateSampleRowCommand(); - - if (optionalSampleRowId.isPresent()) { - - String sampleRowId = optionalSampleRowId.get(); - - SampleRowTopiaDao sampleRowDao = getSampleRowDao(); - - SampleRow sampleRowMemento = sampleRowDao.findByTopiaId(sampleRowId); - sampleRowDao.detach(sampleRowMemento); - updateSampleRowCommand.setSampleRowMemento(sampleRowMemento); - - SampleRow sampleRow = sampleRowDao.findByTopiaId(sampleRowId); - updateSampleRowCommand.setSampleRow(sampleRow); - - updateSampleRowCommand.setCreation(false); - - SampleRowLogImpl newSampleRowLog = new SampleRowLogImpl(); - newSampleRowLog.setAuthor(authenticatedWaoUser.getWaoUser()); - newSampleRowLog.setFromAdmin(authenticatedWaoUser.isAdmin()); - updateSampleRowCommand.setSampleRowLog(newSampleRowLog); - sampleRow.addSampleRowLog(newSampleRowLog); - - Set<Boat> elligibleBoats = new HashSet<>(); - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - boolean boatIsElligibleForUser = - authenticatedWaoUser.isAdmin() && elligibleBoat.isGlobalActive() || - authenticatedWaoUser.isCoordinator() && BooleanUtils.isTrue(elligibleBoat.getCompanyActive()); - if (boatIsElligibleForUser) { - elligibleBoats.add(elligibleBoat.getBoat()); - } - } - String elligibleBoatImmatriculations = Boats.toImmatriculations(elligibleBoats); - updateSampleRowCommand.setElligibleBoatImmatriculations(elligibleBoatImmatriculations); - - } else { - - SampleRow newSampleRow = new SampleRowImpl(); - - newSampleRow.setObsProgram(ObsProgram.OBSMER); - newSampleRow.setProfession(new ProfessionImpl()); - newSampleRow.setFishingZone(new HashSet<FishingZone>()); - newSampleRow.setSampleMonth(new HashSet<SampleMonth>()); - newSampleRow.setSamplingStrategy(SamplingStrategy.SIMULTANEOUS_ALL_SPECIES); - - String newSampleRowCode = getNewSampleRowCode(ObsProgram.OBSMER); - newSampleRow.setCode(newSampleRowCode); - - updateSampleRowCommand.setSampleRow(newSampleRow); - - updateSampleRowCommand.setCreation(true); - - } - - ImmutableMap<String, FishingZone> allFishingZones = - Maps.uniqueIndex( - getReferentialService().getAllFishingZones(), - TopiaEntities.getTopiaIdFunction() - ); - updateSampleRowCommand.setAllFishingZones(allFishingZones); - - ImmutableMap<String, Company> allCompanies = - Maps.uniqueIndex( - getCompaniesService().getAllCompanies(), - TopiaEntities.getTopiaIdFunction() - ); - updateSampleRowCommand.setAllCompanies(allCompanies); - - ImmutableMap<String, DCF5Code> allDcf5Codes = - Maps.uniqueIndex( - getReferentialService().getAllDcf5Codes(), - TopiaEntities.getTopiaIdFunction() - ); - updateSampleRowCommand.setAllDcf5Codes(allDcf5Codes); - - return updateSampleRowCommand; - - } - - /** - * On va rechercher en base pour générer un code qui n'existe pas déjà. - */ - protected String getNewSampleRowCode(ObsProgram obsProgram) { - - // On pré-définit un code pour la nouvelle ligne. - // au moment de la création d'une nouvelle ligne, on a aucune info donc - // on suppose que c'est pour l'année en cours - - Calendar begin = new GregorianCalendar(); - begin.setTime(getNow()); - int year = begin.get(Calendar.YEAR); - - String newSampleRowCodePrefix = year + "_" + obsProgram.getShortCode(); - - SampleRowTopiaDao dao = getSampleRowDao(); - - Optional<String> optionalMaxSampleRowCode = dao.findMaxSampleRowCode(newSampleRowCodePrefix); - int maxSampleRowCodeSequence; - if (optionalMaxSampleRowCode.isPresent()) { - String maxSampleRowCode = optionalMaxSampleRowCode.get(); - if (log.isDebugEnabled()) { - log.debug("max code found : " + maxSampleRowCode); - } - String sequenceStr = StringUtils.removeStart(maxSampleRowCode, newSampleRowCodePrefix); - maxSampleRowCodeSequence = Integer.parseInt(sequenceStr); - } else { - maxSampleRowCodeSequence = 0; - } - - maxSampleRowCodeSequence += 1; - - String newSampleRowCodeSuffix = StringUtils.leftPad(String.valueOf(maxSampleRowCodeSequence), 4, "0"); - - String newSampleRowCode = newSampleRowCodePrefix + newSampleRowCodeSuffix; - - if (log.isInfoEnabled()) { - log.info("new sample row code for " + obsProgram + " is " + newSampleRowCode); - } - - return newSampleRowCode; - - } - - public void preValidate(AuthenticatedWaoUser authenticatedWaoUser, UpdateSampleRowCommand updateSampleRowCommand) - throws UnknownBoatImmatriculationsException, SampleRowCodeMustBeUniqueException { - - SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); - - SampleRowTopiaDao dao = getSampleRowDao(); - List<SampleRow> existingSampleRowsForTheSameCode = dao.forCodeEquals(sampleRow.getCode()).findAll(); - if (existingSampleRowsForTheSameCode.size() > 1) { - throw new SampleRowCodeMustBeUniqueException(); - } else if (existingSampleRowsForTheSameCode.size() == 1 && !Iterables.getOnlyElement(existingSampleRowsForTheSameCode).equals(sampleRow)) { - throw new SampleRowCodeMustBeUniqueException(); - } - - String elligibleBoatImmatriculations = updateSampleRowCommand.getElligibleBoatImmatriculations(); - - List<Boat> elligibleBoats = getReferentialService().getBoatsFromImmatriculations(elligibleBoatImmatriculations); - ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); - - for (Boat boat : elligibleBoats) { - ElligibleBoat elligibleBoat = sampleRow.getElligibleBoatByBoat(boat); - if (elligibleBoat == null) { - elligibleBoat = new ElligibleBoatImpl(); - elligibleBoat.setSampleRow(sampleRow); - elligibleBoat.setBoat(boat); - elligibleBoatDao.create(elligibleBoat); - } - if (authenticatedWaoUser.isAdmin()) { - elligibleBoat.setGlobalActive(true); - } else if (authenticatedWaoUser.isCoordinator()) { - elligibleBoat.setCompanyActive(true); - } - elligibleBoatDao.update(elligibleBoat); - } - - if (sampleRow.isElligibleBoatNotEmpty()) { - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - Boat boat = elligibleBoat.getBoat(); - boolean isNoLongerActive = !elligibleBoats.contains(boat); - if (isNoLongerActive) { - if (authenticatedWaoUser.isAdmin()) { - elligibleBoat.setGlobalActive(false); - } else if (authenticatedWaoUser.isCoordinator()) { - elligibleBoat.setCompanyActive(null); - } - } - } - } - - SampleMonthTopiaDao sampleMonthDao = getSampleMonthDao(); - - Set<SampleMonth> sampleMonthsToRemove = new HashSet<>(sampleRow.getSampleMonth()); - Map<String, Integer> expectedObservationsByMonths = updateSampleRowCommand.getExpectedObservationsByMonths(); - for (Map.Entry<String, Integer> entry : expectedObservationsByMonths.entrySet()) { - Date month; - try { - month = updateSampleRowCommand.monthFormat.parse(entry.getKey()); - } catch (ParseException e) { - throw new IllegalArgumentException(expectedObservationsByMonths.toString(), e); - } - SampleMonth sampleMonth = sampleRow.getSampleMonth(month); - Integer expectedObservations = entry.getValue(); - if (expectedObservations == null) { - if (sampleMonth != null) { - // rien à faire, il va être supprimé - } - } else { - if (sampleMonth == null) { - sampleMonth = new SampleMonthImpl(); - sampleMonth.setPeriodDate(month); - sampleRow.addSampleMonth(sampleMonth); - sampleMonthDao.create(sampleMonth); - if (log.isTraceEnabled()) { - log.trace("created sample month " + sampleMonth); - } - } else { - sampleMonthsToRemove.remove(sampleMonth); - if (log.isTraceEnabled()) { - log.trace("will keep " + sampleMonth); - } - } - sampleMonth.setExpectedTidesValue(expectedObservations); - sampleMonthDao.update(sampleMonth); - } - } - - for (SampleMonth sampleMonth : sampleMonthsToRemove) { - if (log.isTraceEnabled()) { - log.trace("will remove " + sampleMonth); - } - sampleRow.removeSampleMonth(sampleMonth); - sampleMonthDao.delete(sampleMonth); - } - - } - - public void save(UpdateSampleRowCommand updateSampleRowCommand) { - - SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); - - if (!updateSampleRowCommand.isCreation()) { - SampleRowLog sampleRowLog = updateSampleRowCommand.getSampleRowLog(); - getSampleRowLogDao().create(sampleRowLog); - sampleRowLog.setLogText(updateSampleRowCommand.getSampleRowMemento(), sampleRow); - } - - ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); - if (sampleRow.isElligibleBoatNotEmpty()) { - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - if (elligibleBoat.isPersisted()) { - elligibleBoatDao.update(elligibleBoat); - } else { - elligibleBoatDao.create(elligibleBoat); - } - } - } - - ProfessionTopiaDao professionDao = getProfessionDao(); - Profession profession = sampleRow.getProfession(); - if (profession.isPersisted()) { - professionDao.update(profession); - } else { - professionDao.create(profession); - } - - SampleRowTopiaDao dao = getSampleRowDao(); - if (sampleRow.isPersisted()) { - dao.update(sampleRow); - } else { - dao.create(sampleRow); - } - commit(); - - } - - public SampleRow getSampleRow(String sampleRowId) { - - SampleRow sampleRow = getSampleRowDao().findByTopiaId(sampleRowId); - - return sampleRow; - - } - - public void commentSampleRow(AuthenticatedWaoUser authenticatedWaoUser, String sampleRowId, String comment) { - - SampleRow sampleRow = getSampleRow(sampleRowId); - - SampleRowLog sampleRowLog = new SampleRowLogImpl(); - sampleRowLog.setFromAdmin(authenticatedWaoUser.isAdmin()); - sampleRowLog.setComment(comment); - sampleRowLog.setAuthor(authenticatedWaoUser.getWaoUser()); - - sampleRow.addSampleRowLog(sampleRowLog); - - commit(); - - } - - public List<SampleRow> getSamplingPlanRows(SampleRowsFilter sampleRowsFilter) { - - SampleRowTopiaDao dao = getSampleRowDao(); - - return dao.findAll(sampleRowsFilter); - - } - public ObsMerSamplingPlan getSamplingPlan( AuthenticatedWaoUser authenticatedWaoUser, SampleRowsFilter sampleRowsFilter) { @@ -406,10 +63,10 @@ optionalCompanyId, sampleRowsFilter); - Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> samplingPlansCache = + Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache = serviceContext.getSamplingPlansCache(); - ObsMerSamplingPlan result = samplingPlansCache.getIfPresent(samplingPlanCacheKey); + ObsMerSamplingPlan result = (ObsMerSamplingPlan) samplingPlansCache.getIfPresent(samplingPlanCacheKey); if (result == null) { @@ -459,156 +116,6 @@ } - public SampleRowsFilter newSampleRowsFilter(AuthenticatedWaoUser authenticatedWaoUser) { - - // all users can see only rows for the program they are logged for - SampleRowsFilter newFilter = new SampleRowsFilter(); - newFilter.setObsProgram(authenticatedWaoUser.getObsProgram()); - - // We don't want to see all rows but the ones important for today - Date fromDate = serviceContext.getNow(); - Date toDate = fromDate; - - // Dans ObsMer et ObsVente, le plan est mensualisé - fromDate = DateUtils.truncate(fromDate, Calendar.MONTH); - - // la période initiale doit toujours aller d'avril à mars (contractuel). - // on prend la période dans laquelle on se trouve actuellement - - // si on est avant le premier avril de l'année courante - boolean beforePeriodChangeInCurrentYear = DateUtil.getMonth(fromDate) < 3; - - if (beforePeriodChangeInCurrentYear) { - // on prend la période qui a commencé l'année dernière et qui finit - // cette année - fromDate = DateUtils.setMonths(fromDate, 3); - fromDate = DateUtils.addYears(fromDate, -1); - } else { - // on prend la période qui commence cette année et se termine - // l'année prochaine - fromDate = DateUtils.setMonths(fromDate, 3); - } - - // on a fromDate sur le premier avril de la bonne année, on va - // jusqu'au mois de mars suivant - toDate = DateUtils.addMonths(fromDate, 11); - - newFilter.setPeriodFrom(fromDate); - newFilter.setPeriodTo(toDate); - - // Very very important to do that at beginning - // Evo #2227 : Guest user has no default company filter - if (authenticatedWaoUser.isCoordinatorOrObserver()) { - newFilter.setCompanyIds(Sets.newHashSet(authenticatedWaoUser.getCompany().getTopiaId())); - } - - return newFilter; - - } - - public void importSamplingPlan(AuthenticatedWaoUser authenticatedWaoUser, InputStream csv) throws ImportErrorException { - - ImportModel<SampleRow> samplingPlanImportModel = - newSamplingPlanImportModel(authenticatedWaoUser); - - Import<SampleRow> samplingPlanImport = - Import.newImport(samplingPlanImportModel, csv); - - SampleRowTopiaDao dao = getSampleRowDao(); - - try { - - for (SampleRow sampleRow : samplingPlanImport) { - - if (StringUtils.isBlank(sampleRow.getCode())) { - - String newSampleRowCode = getNewSampleRowCode(ObsProgram.OBSMER); - - sampleRow.setCode(newSampleRowCode); - - } else { - - // TODO brendan 18/03/14 - - } - - getProfessionDao().create(sampleRow.getProfession()); - - dao.create(sampleRow); - - } - - } catch (ImportRuntimeException e) { - throw new ImportErrorException(e); - } - - commit(); - - } - - protected ImportModel<SampleRow> newSamplingPlanImportModel(AuthenticatedWaoUser authenticatedWaoUser) { - - ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); - - CompanyTopiaDao companyDao = getCompanyDao(); - List<Company> activeCompanies = companyDao.forActiveEquals(true).findAll(); - - TerrestrialLocationTopiaDao terrestrialLocationDao = getTerrestrialLocationDao(); - List<TerrestrialLocation> terrestrialDistricts = - terrestrialLocationDao.forLocationTypeEquals(LocationType.DISTRICT).findAll(); - - FishingZoneTopiaDao fishingZoneDao = getFishingZoneDao(); - List<FishingZone> fishingZones = fishingZoneDao.findAll(); - - ReferentialService referentialService = getReferentialService(); - - ImportModel<SampleRow> samplingPlanImportModel = - new ObsMerObsVenteSamplingPlanImportExportModel(getLocale(), - obsProgram, - activeCompanies, - fishingZones, - terrestrialDistricts, - referentialService); - - return samplingPlanImportModel; - - } - - public InputStream exportSamplingPlan(SampleRowsFilter filter) { - - Preconditions.checkArgument(filter.getPeriodFrom() != null); - Preconditions.checkArgument(filter.getPeriodTo() != null); - - // ignore pagination when exporting - filter.setOrderByArguments(ImmutableSet.of(SampleRow.PROPERTY_CODE)); - - SampleRowTopiaDao dao = getSampleRowDao(); - - List<SampleRow> sampleRows = dao.findAll(filter); - - ExportModel<SampleRow> exportModel = - new ObsMerObsVenteSamplingPlanImportExportModel( - getLocale(), - filter.getPeriodFrom(), - filter.getPeriodTo(), - ObsProgram.OBSMER); - - Export<SampleRow> export = Export.newExport(exportModel, sampleRows); - - try { - - String csvContent = export.toString(Charsets.UTF_8); - - InputStream csvInputStream = IOUtils.toInputStream(csvContent, Charsets.UTF_8); - - return csvInputStream; - - } catch (Exception e) { - throw new WaoTechnicalException(e); - } - - } - /** * Récupérer l'effort d'observation en nombre de jours plannifié poru * le sample row donné pendant la période donnée. @@ -618,9 +125,9 @@ * @param sampleRow la ligne à filtrer * @return l'effort plannifié calculé */ - public double getObservationTimesInDayExpected(Date periodFrom, - Date periodTo, - SampleRow sampleRow) { + protected double getObservationTimesInDayExpected(Date periodFrom, + Date periodTo, + SampleRow sampleRow) { Range<Date> period = Range.closed(periodFrom, periodTo); @@ -652,7 +159,7 @@ * @param periodTo la date jusqu'à laquelle on compte les contacts * @return la paire (effort réalisé - effort estimé) calculée */ - public Pair<Long, Long> getSampleRowObservationTimesInDayRealAndEstimated(String sampleRowId, Date periodFrom, Date periodTo) { + protected Pair<Long, Long> getSampleRowObservationTimesInDayRealAndEstimated(String sampleRowId, Date periodFrom, Date periodTo) { // D'abord, on a besoin de récupérer toutes les observations réalisées // pour cette ligne du plan @@ -702,113 +209,4 @@ return Pair.of(real, estimated); } - public void deleteSampleRow(String sampleRowId) throws IllegalDeletionException { - - SampleRowTopiaDao dao = getSampleRowDao(); - - SampleRow sampleRow = dao.findByTopiaId(sampleRowId); - - SampleMonthTopiaDao sampleMonthDao = getSampleMonthDao(); - for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { - sampleMonthDao.delete(sampleMonth); - } - sampleRow.clearSampleMonth(); - - SampleRowLogTopiaDao sampleRowLogDao = getSampleRowLogDao(); - for (SampleRowLog sampleRowLog : sampleRow.getSampleRowLog()) { - sampleRowLogDao.delete(sampleRowLog); - } - sampleRow.clearSampleRowLog(); - - ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - elligibleBoatDao.delete(elligibleBoat); - } - sampleRow.clearElligibleBoat(); - - sampleRow.clearFishingZone(); - - if (sampleRow.getProfession() != null) { - ProfessionTopiaDao professionDao = getProfessionDao(); - professionDao.delete(sampleRow.getProfession()); - sampleRow.setProfession(null); - } - - Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> allUsages = dao.findAllUsages(sampleRow); - - if (allUsages.isEmpty()) { - dao.delete(sampleRow); - } else { - throw new IllegalDeletionException(allUsages); - } - - commit(); - - } - - public void recomputeSampleRowEstimatedAndRealTides(SampleRow sampleRow) { - - //---- - // Reset des tides de la ligne - //---- - - for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { - sampleMonth.setEstimatedTidesValue(0); - sampleMonth.setRealTidesValue(0); - } - - //---- - // Recuperation de tous les contacts de la ligne - //---- - - ContactsFilter contactFilter = new ContactsFilter(); - - contactFilter.setFilterOnObservationBeginDate(true); - contactFilter.getSampleRowFilter().setSampleRowIds(Sets.newHashSet(sampleRow.getTopiaId())); - - contactFilter.setContactStates(ImmutableSet.of(ContactState.OBSERVATION_DONE)); - // on exclue les contacts qui sont invalidés par le programme - contactFilter.setProgramAcceptations(Sets.newHashSet(true, null)); - // on exclue les contacts invalidés par la société - contactFilter.setCompanyAcceptations(Sets.newHashSet(true, null)); - - Collection<Contact> contacts = getContactDao().forFilter(contactFilter, false).findAll(); - - //---- - // Recalcul des tides - //---- - - for (Contact contact : contacts) { - - Date observationBeginDate = contact.getObservationBeginDate(); - - SampleMonth month = sampleRow.getSampleMonth(observationBeginDate); - - month.setEstimatedTidesValue(month.getEstimatedTidesValue() + 1); - - if (BooleanUtils.isTrue(contact.getValidationCompany())) { - month.setRealTidesValue(month.getRealTidesValue() + 1); - } - - } - - } - - public List<SampleRow> getUnfinishedSampleRows(AuthenticatedWaoUser authenticatedWaoUser, String companyId) { - - SampleRowsFilter sampleRowsFilter = newSampleRowsFilter(authenticatedWaoUser); - - sampleRowsFilter.setCompanyIds(ImmutableSet.of(companyId)); - - Date now = getNow(); - sampleRowsFilter.setPeriodFrom(now); - // sampleRowsFilter.setPeriodTo(DateUtils.addYears(now, 1)); - - sampleRowsFilter.setOrderByArguments(ImmutableSet.of(SampleRow.PROPERTY_CODE)); - - List<SampleRow> unfinishedSampleRows = getSamplingPlanRows(sampleRowsFilter); - - return unfinishedSampleRows; - - } } Deleted: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSynthesis.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSynthesis.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSynthesis.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,133 +0,0 @@ -package fr.ifremer.wao.services.service; - -import fr.ifremer.wao.entity.Boat; -import org.jfree.chart.JFreeChart; - -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -public class ObsMerSynthesis { - - protected JFreeChart expectedVsActualObservationsByMonthsChart; - - protected JFreeChart boardingBoatsChart; - - protected int maxBoardingValue; - - protected Boat maxBoardingBoat; - - protected int boardingsCount; - - protected int invalidBoardingsCount; - - protected int validBoardingsCount; - - protected Map<String, CompanySynthesis> companySyntheses = new HashMap<>(); - - protected Set<String> sampleRowIds; - - public Map<String, CompanySynthesis> getCompanySyntheses() { - return companySyntheses; - } - - public JFreeChart getExpectedVsActualObservationsByMonthsChart() { - return expectedVsActualObservationsByMonthsChart; - } - - public void setExpectedVsActualObservationsByMonthsChart(JFreeChart expectedVsActualObservationsByMonthsChart) { - this.expectedVsActualObservationsByMonthsChart = expectedVsActualObservationsByMonthsChart; - } - - public JFreeChart getBoardingBoatsChart() { - return boardingBoatsChart; - } - - public void setBoardingBoatsChart(JFreeChart boardingBoatsChart) { - this.boardingBoatsChart = boardingBoatsChart; - } - - public int getMaxBoardingValue() { - return maxBoardingValue; - } - - public void setMaxBoardingValue(int maxBoardingValue) { - this.maxBoardingValue = maxBoardingValue; - } - - public Boat getMaxBoardingBoat() { - return maxBoardingBoat; - } - - public void setMaxBoardingBoat(Boat maxBoardingBoat) { - this.maxBoardingBoat = maxBoardingBoat; - } - - public int getBoardingsCount() { - return boardingsCount; - } - - public void setBoardingsCount(int boardingsCount) { - this.boardingsCount = boardingsCount; - } - - public int getInvalidBoardingsCount() { - return invalidBoardingsCount; - } - - public void setInvalidBoardingsCount(int invalidBoardingsCount) { - this.invalidBoardingsCount = invalidBoardingsCount; - } - - public int getValidBoardingsCount() { - return validBoardingsCount; - } - - public void setValidBoardingsCount(int validBoardingsCount) { - this.validBoardingsCount = validBoardingsCount; - } - - public Map<String, Double> getComplianceBoardingIndicator() { - Map<String, Double> complianceBoardingIndicator = new TreeMap(); - for (CompanySynthesis companySynthesis : companySyntheses.values()) { - complianceBoardingIndicator.put( - companySynthesis.getCompanyName(), - companySynthesis.getComplianceBoardingIndicator()); - } - return complianceBoardingIndicator; - } - - public void setSampleRowIds(Set<String> sampleRowIds) { - this.sampleRowIds = sampleRowIds; - } - - public Set<String> getSampleRowIds() { - return sampleRowIds; - } - - public CompanySynthesis getCompanySynthesis(String companyId) { - CompanySynthesis companySynthesis = companySyntheses.get(companyId); - if (companySynthesis == null) { - companySynthesis = new CompanySynthesis(); - companySynthesis.setCompanyId(companyId); - companySyntheses.put(companyId, companySynthesis); - } - return companySynthesis; - } - - public Set<CompanySynthesis> getCompanySynthesesOrderedByName() { - Map<String, CompanySynthesis> companySynthesesOrderedByName = new TreeMap(); - for (CompanySynthesis companySynthesis : companySyntheses.values()) { - companySynthesesOrderedByName.put( - companySynthesis.getCompanyName(), - companySynthesis); - } - return new LinkedHashSet<>(companySynthesesOrderedByName.values()); - } - - public boolean isEmpty() { - return companySyntheses.isEmpty(); - } -} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,77 @@ +package fr.ifremer.wao.services.service; + +/* + * #%L + * Wao :: Services + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.TerrestrialLocation; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.Collection; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +public class ObsVenteSamplingPlan extends SamplingPlan implements Iterable<SamplingPlan.SamplingPlanFacadePart> { + + public ObsVenteSamplingPlan(List<Date> months, Collection<SamplingPlanFacadePart> facadeParts, Map<Date, SamplingPlanStatistics> totalsPerMonth, SamplingPlanStatistics highTotals, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { + super(months, facadeParts, totalsPerMonth, highTotals, filterValues, sampleRowIds); + } + + public static class ObsVenteSamplingPlanSampleRowPart extends SamplingPlanSampleRowPart { + + protected Map<String, String> terrestrialLocationNamesAndDescriptions; + + protected String terrestrialLocationInfos; + + protected int averageObservationsCount; + + public ObsVenteSamplingPlanSampleRowPart(Locale locale, Map<Date, SamplingPlanStatistics> nbTidesPerMonth, SampleRow sampleRow) { + super(locale, nbTidesPerMonth, sampleRow); + terrestrialLocationInfos = sampleRow.getTerrestrialLocationInfos(); + terrestrialLocationNamesAndDescriptions = new LinkedHashMap<>(); + if (CollectionUtils.isNotEmpty(sampleRow.getTerrestrialLocations())) { + for (TerrestrialLocation terrestrialLocation : sampleRow.getTerrestrialLocations()) { + String key = terrestrialLocation.getDistrictName(); + String description = terrestrialLocation.getDescription(); + terrestrialLocationNamesAndDescriptions.put(key, description); + } + } + averageObservationsCount = sampleRow.getAverageObservationsCount(); + } + + public String getTerrestrialLocationInfos() { + return terrestrialLocationInfos; + } + + public Map<String, String> getTerrestrialLocationNamesAndDescriptions() { + return terrestrialLocationNamesAndDescriptions; + } + + public int getAverageObservationsCount() { + return averageObservationsCount; + } + } + +} \ No newline at end of file Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,322 @@ +package fr.ifremer.wao.services.service; + +/* + * #%L + * Wao :: Services + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Function; +import com.google.common.base.Optional; +import com.google.common.collect.Ordering; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRows; +import org.apache.commons.lang3.mutable.MutableInt; +import org.nuiton.util.PeriodDates; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + * @since 4.0 + */ +public class ObsVenteSamplingPlanBuilder { + + /** + * Incoming filter used. + */ + protected SampleRowsFilter sampleRowsFilter; + + /** + * Bean to hold all values that user can select to fill {@link fr.ifremer.wao.SampleRowsFilter}. + */ + protected SampleRowsFilterValues sampleRowsFilterValues; + + /** + * Ids of all the sample rows included in this sampling plan. + */ + protected Set<String> sampleRowIds; + + /** + * List of month computed from the filter. + */ + protected List<Date> months; + + /** + * Dictionnary of facades indexed by their facade name. + */ + protected Map<String, FacadeContext> facadeMap; + + /** + * To compute the high total expected. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan#highTotals + */ + protected int highTotalExpected; + + /** + * To compute the high total real. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan#highTotals + */ + protected int highTotalReal; + + /** + * To compute the high total estimated. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan#highTotals + */ + protected int highTotalEstimated; + + /** + * To compute by month the total of expected tides. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesExpected + */ + protected Map<Date, MutableInt> totalExpectedForMonths; + + /** + * To compute by month the total of expected tides. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesEstimated + */ + protected Map<Date, MutableInt> totalEstimatedForMonths; + + /** + * To compute by month the total of real tides. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesReal + */ + protected Map<Date, MutableInt> totalRealForMonths; + + public ObsVenteSamplingPlanBuilder(Locale locale, + Optional<String> optionalCompanyId, + SampleRowsFilter sampleRowsFilter) { + this.sampleRowsFilter = sampleRowsFilter; + this.sampleRowsFilterValues = new SampleRowsFilterValues(locale, ObsProgram.OBSVENTE, optionalCompanyId); + this.sampleRowIds = new HashSet<>(); + this.facadeMap = new TreeMap<>(); + this.totalExpectedForMonths = new TreeMap<>(); + this.totalRealForMonths = new TreeMap<>(); + this.totalEstimatedForMonths = new TreeMap<>(); + + PeriodDates periodDates = new PeriodDates(sampleRowsFilter.getPeriodFrom(), + sampleRowsFilter.getPeriodTo()); + this.months = periodDates.getMonths(); + } + + public ObsVenteSamplingPlanBuilder addSampleRow(SampleRow sampleRow) { + + String facade = sampleRow.getFacade(); + FacadeContext facadeContext = facadeMap.get(facade); + + if (facadeContext == null) { + + // register a new facade + facadeContext = new FacadeContext(facade); + facadeMap.put(facade, facadeContext); + } + + String sectors = sampleRow.getSectors(); + + // get sector context + SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); + + // compute nb tides per month + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> nbTidesPerMonth = computeNbTidesPerMonth(sampleRow); + + // add sample row + sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), + sampleRow, + nbTidesPerMonth); + + sampleRowsFilterValues.addSampleRow(sampleRow); + + sampleRowIds.add(sampleRow.getTopiaId()); + + return this; + } + + public ObsVenteSamplingPlan toPlan() { + + // Get facade parts + Collection<SamplingPlan.SamplingPlanFacadePart> facadeParts = new ArrayList<>(); + for (FacadeContext facadeContext : facadeMap.values()) { + SamplingPlan.SamplingPlanFacadePart facadePart = facadeContext.toBean(); + facadeParts.add(facadePart); + } + + // Sort them + Collection<SamplingPlan.SamplingPlanFacadePart> sortedFacades = Ordering.natural().onResultOf(new Function<SamplingPlan.SamplingPlanFacadePart, String>() { + public String apply(SamplingPlan.SamplingPlanFacadePart input) { + return input.getFacade(); + } + }).immutableSortedCopy(facadeParts); + + // Get statistics + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> statisticsMap = new TreeMap<>(); + for (Date month : months) { + + MutableInt totalExpected = totalExpectedForMonths.get(month); + MutableInt totalReal = totalRealForMonths.get(month); + MutableInt totalEstimated = totalEstimatedForMonths.get(month); + ObsMerSamplingPlan.SamplingPlanStatistics planStatistics = + new ObsMerSamplingPlan.SamplingPlanStatistics(totalExpected == null ? null : totalExpected.toInteger(), + totalReal == null ? null : totalReal.toInteger(), + totalEstimated == null ? null : totalEstimated.toInteger()); + statisticsMap.put(month, planStatistics); + } + + ObsMerSamplingPlan.SamplingPlanStatistics highTotals = new ObsMerSamplingPlan.SamplingPlanStatistics(highTotalExpected, highTotalReal, highTotalEstimated); + + ObsVenteSamplingPlan result = new ObsVenteSamplingPlan(months, + sortedFacades, + statisticsMap, + highTotals, + sampleRowsFilterValues, + sampleRowIds); + return result; + } + + protected Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> computeNbTidesPerMonth(SampleRow sampleRow) { + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> result = new TreeMap<>(); + for (Date month : months) { + Integer expectedTidesValue = SampleRows.getExpectedTidesValue(sampleRow, month); + if (expectedTidesValue != null) { + MutableInt mutableInt = totalExpectedForMonths.get(month); + if (mutableInt == null) { + totalExpectedForMonths.put(month, mutableInt = new MutableInt()); + } + mutableInt.add(expectedTidesValue); + highTotalExpected += expectedTidesValue; + } + Integer realTidesValue = SampleRows.getRealTidesValue(sampleRow, month); + if (realTidesValue != null) { + MutableInt mutableInt = totalRealForMonths.get(month); + if (mutableInt == null) { + totalRealForMonths.put(month, mutableInt = new MutableInt()); + } + mutableInt.add(realTidesValue); + highTotalReal += realTidesValue; + } + + Integer estimatedTidesValue = SampleRows.getEstimatedTidesValue(sampleRow, month); + if (estimatedTidesValue != null) { + MutableInt mutableInt = totalEstimatedForMonths.get(month); + if (mutableInt == null) { + totalEstimatedForMonths.put(month, mutableInt = new MutableInt()); + } + mutableInt.add(estimatedTidesValue); + highTotalEstimated += estimatedTidesValue; + } + result.put(month, new ObsMerSamplingPlan.SamplingPlanStatistics(expectedTidesValue, + realTidesValue, + estimatedTidesValue)); + + } + return result; + } + + protected static class FacadeContext { + + protected String facade; + + protected Map<String, SectorContext> sectorMap; + + protected FacadeContext(String facade) { + this.facade = facade; + this.sectorMap = new TreeMap<>(); + } + + protected SectorContext getOrAddSectorContext(String sectors) { + SectorContext sectorPart = sectorMap.get(sectors); + if (sectorPart == null) { + + // register a new sector + sectorPart = new SectorContext(sectors); + sectorMap.put(sectors, sectorPart); + } + return sectorPart; + } + + protected SamplingPlan.SamplingPlanFacadePart toBean() { + + // get sector parts + Collection<SamplingPlan.SamplingPlanSectorPart> sectorParts = new ArrayList<>(); + for (SectorContext sectorContext : sectorMap.values()) { + SamplingPlan.SamplingPlanSectorPart sectorPart = sectorContext.toBean(); + sectorParts.add(sectorPart); + } + // sort them + Collection<SamplingPlan.SamplingPlanSectorPart> sortedSectors = Ordering.natural().onResultOf(new Function<SamplingPlan.SamplingPlanSectorPart, String>() { + public String apply(SamplingPlan.SamplingPlanSectorPart input) { + return input.getSectors(); + } + }).immutableSortedCopy(sectorParts); + SamplingPlan.SamplingPlanFacadePart result = + new SamplingPlan.SamplingPlanFacadePart(facade, sortedSectors); + return result; + } + } + + protected static class SectorContext { + + protected String sectors; + + protected Collection<ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart> rows; + + protected SectorContext(String sectors) { + this.sectors = sectors; + this.rows = new ArrayList<>(); + } + + protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow(Locale locale, + SampleRow row, + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> nbTidesPerMonth) { + + ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart rowPart = + new ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart(locale, + nbTidesPerMonth, + row); + rows.add(rowPart); + + return rowPart; + } + + protected SamplingPlan.SamplingPlanSectorPart toBean() { + + Collection<ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart> sortedRows = Ordering.natural().onResultOf(new Function<ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart, String>() { + public String apply(ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart input) { + return input.getCode(); + } + }).immutableSortedCopy(rows); + SamplingPlan.SamplingPlanSectorPart result = + new SamplingPlan.SamplingPlanSectorPart(sectors, sortedRows); + return result; + } + } +} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,63 @@ +package fr.ifremer.wao.services.service; + +import com.google.common.base.Optional; +import com.google.common.cache.Cache; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowTopiaDao; +import fr.ifremer.wao.services.AuthenticatedWaoUser; + +import java.util.List; + +public class ObsVenteSamplingPlanService extends SamplingPlanService { + + public ObsVenteSamplingPlan getSamplingPlan( + AuthenticatedWaoUser authenticatedWaoUser, + SampleRowsFilter sampleRowsFilter) { + + Optional<String> optionalCompanyId = Optional.absent(); + if (authenticatedWaoUser.isCoordinatorOrObserver()) { + optionalCompanyId = Optional.of(authenticatedWaoUser.getCompany().getTopiaId()); + } + + SamplingPlanCacheKey samplingPlanCacheKey = + new SamplingPlanCacheKey( + serviceContext.getLocale(), + optionalCompanyId, + sampleRowsFilter); + + Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache = + serviceContext.getSamplingPlansCache(); + + ObsVenteSamplingPlan result = (ObsVenteSamplingPlan) samplingPlansCache.getIfPresent(samplingPlanCacheKey); + + if (result == null) { + + SampleRowTopiaDao dao = getSampleRowDao(); + + // recuperation des lignes du plan + List<SampleRow> sampleRows = dao.findAll(sampleRowsFilter); + + // creation du plan d'echantillonnage + ObsVenteSamplingPlanBuilder builder = new ObsVenteSamplingPlanBuilder( + serviceContext.getLocale(), + optionalCompanyId, + sampleRowsFilter); + + for (SampleRow sampleRow : sampleRows) { + + // ajout de la ligne au build de plan + builder.addSampleRow(sampleRow); + + } + result = builder.toPlan(); + + samplingPlansCache.put(samplingPlanCacheKey, result); + + } + + return result; + + } + +} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,542 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.DCF5Code; +import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.SampleMonth; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowLog; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.nuiton.util.DateUtil; + +import java.io.Serializable; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlanFacadePart>, Serializable { + + /** + * List of month used by sample rows. + */ + protected List<Date> months; + + /** + * All facades of the sampling plan. + */ + protected Collection<SamplingPlanFacadePart> facades; + + /** + * Total tides over the plan by month. + */ + protected Map<Date, SamplingPlanStatistics> totalsPerMonth; + + /** + * High total over the hole plan. + */ + protected SamplingPlanStatistics highTotals; + + /** + * Universe of filter values. + */ + protected SampleRowsFilterValues filterValues; + + /** + * Ids of all the sample rows included in this sampling plan. + */ + protected Set<String> sampleRowIds; + + public SamplingPlan(List<Date> months, + Collection<SamplingPlanFacadePart> facadeParts, + Map<Date, SamplingPlanStatistics> totalsPerMonth, + SamplingPlanStatistics highTotals, + SampleRowsFilterValues filterValues, + Set<String> sampleRowIds) { + this.months = months; + this.facades = facadeParts; + this.totalsPerMonth = totalsPerMonth; + this.highTotals = highTotals; + this.filterValues = filterValues; + this.sampleRowIds = sampleRowIds; + } + + public static class SamplingPlanStatistics implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * Number of expected tides. + */ + protected Integer nbTidesExpected; + + /** + * Number of real tides. + */ + protected Integer nbTidesReal; + + /** + * Number of estimated tides. + */ + protected Integer nbTidesEstimated; + + public SamplingPlanStatistics(Integer nbTidesExpected, + Integer nbTidesReal, + Integer nbTidesEstimated) { + this.nbTidesExpected = nbTidesExpected; + this.nbTidesReal = nbTidesReal; + this.nbTidesEstimated = nbTidesEstimated; + } + + public Integer getNbTidesExpected() { + return nbTidesExpected; + } + + public Integer getNbTidesReal() { + return nbTidesReal; + } + + public Integer getNbTidesEstimated() { + return nbTidesEstimated; + } + + public String getRealRatio(String defaultValue) { + String ratio = defaultValue; + if (nbTidesExpected != null && nbTidesExpected > 0 && + nbTidesReal != null && nbTidesReal > 0) { + double percent = ((double) nbTidesReal / nbTidesExpected); + ratio = NumberFormat.getPercentInstance().format(percent); + } + return ratio; + } + + public String getEstimatedRatio(String defaultValue) { + String ratio = defaultValue; + if (nbTidesExpected != null && nbTidesExpected > 0 && + nbTidesEstimated != null && nbTidesEstimated > 0) { + double percent = ((double) nbTidesEstimated / nbTidesExpected); + ratio = NumberFormat.getPercentInstance().format(percent); + } + return ratio; + } + + @Override + public String toString() { + String toString = ToStringBuilder.reflectionToString(this); + return toString; + } + + } + + public SampleRowsFilterValues getFilterValues() { + return filterValues; + } + + /** + * All sectors part for a given facade. + * <p/> + * Created on 3/24/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ + public static class SamplingPlanFacadePart implements Iterable<SamplingPlanSectorPart>, Serializable { + + private static final long serialVersionUID = 1L; + + protected String facade; + + /** + * All sector parts for this facade. + */ + protected Collection<SamplingPlanSectorPart> sectors; + + public SamplingPlanFacadePart(String facade, + Collection<SamplingPlanSectorPart> sectors) { + this.facade = facade; + this.sectors = sectors; + } + + public String getFacade() { + return facade; + } + + @Override + public Iterator<SamplingPlanSectorPart> iterator() { + return sectors.iterator(); + } + } + + /** + * Contains sample rows of a same sectors. + */ + public static class SamplingPlanSectorPart<T extends SamplingPlanSampleRowPart> implements Iterable<T>, Serializable { + + private static final long serialVersionUID = 1L; + + protected String sectors; + + protected Collection<T> sampleRows; + + public SamplingPlanSectorPart(String sectors, + Collection<T> sampleRows) { + this.sectors = sectors; + this.sampleRows = sampleRows; + } + + public String getSectors() { + return sectors; + } + + @Override + public Iterator<T> iterator() { + return sampleRows.iterator(); + } + } + + public Integer getTotalExpected(Date month) { + Integer result = totalsPerMonth.get(month).getNbTidesExpected(); + return result; + } + + public Integer getTotalReal(Date month) { + Integer result = totalsPerMonth.get(month).getNbTidesReal(); + return result; + } + + public Integer getTotalEstimated(Date month) { + Integer result = totalsPerMonth.get(month).getNbTidesEstimated(); + return result; + } + + public String getTotalRealRatio(Date month) { + String result = totalsPerMonth.get(month).getRealRatio("-"); + return result; + } + + public String getTotalEstimatedRatio(Date month) { + String result = totalsPerMonth.get(month).getEstimatedRatio("-"); + return result; + } + + public Integer getHighTotalExpected() { + return highTotals.getNbTidesExpected(); + } + + public Integer getHighTotalReal() { + return highTotals.getNbTidesReal(); + } + + public Integer getHighTotalEstimated() { + return highTotals.getNbTidesEstimated(); + } + + public String getHighTotalRealRatio() { + String ratio = highTotals.getRealRatio(""); + return ratio; + } + + public String getHighTotalEstimatedRatio() { + String ratio = highTotals.getEstimatedRatio(""); + return ratio; + } + + public Set<String> getSampleRowIds() { + return sampleRowIds; + } + + @Override + public Iterator<SamplingPlanFacadePart> iterator() { + return facades.iterator(); + } + + public List<Date> getMonths() { + return months; + } + + + /** + * Created on 3/24/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ + public abstract static class SamplingPlanSampleRowPart implements Serializable { + + /** + * Nb tides by month. + */ + protected Map<Date, SamplingPlanStatistics> nbTidesPerMonth; + + /** + * Total of tides. + */ + protected SamplingPlanStatistics totalTides; + + protected String fishingZones; + + protected String code; + + protected String fishingZonesInfos; + + protected String comment; + + protected String programName; + + protected Date periodBegin; + + protected Date periodEnd; + + protected String professionMeshSize; + + protected String professionSize; + + protected String professionOther; + + protected String professionLibelle; + + protected String professionSpecies; + + protected String companyName; + + protected String samplingStrategy; + + protected String professionDescriptionWithoutDCF5; + + protected Map<String, String> dcf5CodesAndDescriptions; + + protected String sampleRowId; + + /** + * Date of the latest sample log. + */ + protected Date latestSampleLogCreateDate; + + /** + * First sample month date. + */ + protected Date firstSampleMonthDate; + + /** + * Last sample month date. + */ + protected Date lastSampleMonthDate; + + /** + * Last sample month end of month. + */ + protected Date lastSampleMonthEndOfMonth; + + protected boolean elligibleBoatsProvided; + + public SamplingPlanSampleRowPart(Locale locale, + Map<Date, SamplingPlanStatistics> nbTidesPerMonth, + SampleRow sampleRow) { + this.nbTidesPerMonth = nbTidesPerMonth; + // compute total tides + int totalTidesExpected = 0; + int totalTidesEstimated = 0; + int totalTidesReal = 0; + for (SamplingPlanStatistics samplingPlanStatistics : nbTidesPerMonth.values()) { + Integer totalExpected = samplingPlanStatistics.getNbTidesExpected(); + if (totalExpected != null) { + totalTidesExpected += totalExpected; + } + Integer totalEstimated = samplingPlanStatistics.getNbTidesEstimated(); + if (totalEstimated != null) { + totalTidesEstimated += totalEstimated; + } + Integer totalReal = samplingPlanStatistics.getNbTidesReal(); + if (totalReal != null) { + totalTidesReal += totalReal; + } + } + totalTides = new SamplingPlanStatistics(totalTidesExpected, totalTidesReal, totalTidesEstimated); + fishingZones = ""; + for (FishingZone zone : sampleRow.getFishingZone()) { + fishingZones += zone.getDistrictCode() + ", "; + } + fishingZones = fishingZones.substring(0, fishingZones.length() - 2); + fishingZonesInfos = sampleRow.getFishingZonesInfos(); + comment = sampleRow.getComment(); + programName = sampleRow.getProgramName(); + periodBegin = sampleRow.getPeriodBegin(); + periodEnd = sampleRow.getPeriodEnd(); + companyName = sampleRow.getCompany().getName(); + code = sampleRow.getCode(); + professionMeshSize = sampleRow.getProfession().getMeshSize(); + professionSize = sampleRow.getProfession().getSize(); + professionOther = sampleRow.getProfession().getOther(); + professionLibelle = sampleRow.getProfession().getLibelle(); + professionSpecies = sampleRow.getProfession().getSpecies(); + dcf5CodesAndDescriptions = new LinkedHashMap<>(); + for (DCF5Code dcf5Code : sampleRow.getdCF5Code()) { + String key = dcf5Code.getCode(); + String description = dcf5Code.getFishingGearCode() + " - " + WaoUtils.l(locale, dcf5Code.getFishingGearDCF()); + if (dcf5Code.getTargetSpeciesCode() != null) { + description += " ; " + dcf5Code.getTargetSpeciesCode() + " - " + WaoUtils.l(locale, dcf5Code.getTargetSpeciesDCF()); + } + dcf5CodesAndDescriptions.put(key, description); + } + + professionDescriptionWithoutDCF5 = sampleRow.getProfessionDescriptionWithoutDCF5(); + samplingStrategy = WaoUtils.l(locale, sampleRow.getSamplingStrategy()); + sampleRowId = sampleRow.getTopiaId(); + + // consider a recently created sample row as recently updated + latestSampleLogCreateDate = sampleRow.getTopiaCreateDate(); + // compute lastSampleLogCreateDate + if (sampleRow.isSampleRowLogNotEmpty()) { + for (SampleRowLog sampleRowLog : sampleRow.getSampleRowLog()) { + if (sampleRowLog.getCreateDate().after(latestSampleLogCreateDate)) { + latestSampleLogCreateDate = sampleRowLog.getCreateDate(); + } + } + } + + // compute sampleRowPeriod + // TODO brendan 15/04/14 use treeset + List<SampleMonth> sampleMonth = new ArrayList<>(sampleRow.getSampleMonth()); + firstSampleMonthDate = sampleMonth.get(0).getPeriodDate(); + lastSampleMonthDate = sampleMonth.get(sampleMonth.size() - 1).getPeriodDate(); + + lastSampleMonthEndOfMonth = WaoUtils.getEndOfMonth(lastSampleMonthDate); + elligibleBoatsProvided = sampleRow.isElligibleBoatNotEmpty(); + } + + public String getSamplingStrategy() { + return samplingStrategy; + } + + public String getSampleRowId() { + return sampleRowId; + } + + public Date getFirstSampleMonthDate() { + return firstSampleMonthDate; + } + + public Date getLastSampleMonthDate() { + return lastSampleMonthDate; + } + + public String getCode() { + return code; + } + + public String getFishingZonesInfos() { + return fishingZonesInfos; + } + + public String getProfessionSize() { + return professionSize; + } + + public Map<String, String> getDcf5CodesAndDescriptions() { + return dcf5CodesAndDescriptions; + } + + public String getComment() { + return comment; + } + + public String getProgramName() { + return programName; + } + + public Date getPeriodBegin() { + return periodBegin; + } + + public Date getPeriodEnd() { + return periodEnd; + } + + public String getProfessionMeshSize() { + return professionMeshSize; + } + + public String getProfessionOther() { + return professionOther; + } + + public String getProfessionLibelle() { + return professionLibelle; + } + + public String getProfessionSpecies() { + return professionSpecies; + } + + public String getCompanyName() { + return companyName; + } + + public int getTotalTidesExpected() { + return totalTides.getNbTidesExpected(); + } + + public int getTotalTidesReal() { + return totalTides.getNbTidesReal(); + } + + public int getTotalTidesEstimated() { + return totalTides.getNbTidesEstimated(); + } + + public String getProfessionDescriptionWithoutDCF5() { + return professionDescriptionWithoutDCF5; + } + + public Integer getNbTidesExpected(Date month) { + Integer result = nbTidesPerMonth.get(month).getNbTidesExpected(); + return result; + } + + public Integer getNbTidesReal(Date month) { + Integer result = nbTidesPerMonth.get(month).getNbTidesReal(); + return result; + } + + public Integer getNbTidesEstimated(Date month) { + Integer result = nbTidesPerMonth.get(month).getNbTidesEstimated(); + return result; + } + + public String getTotalRealPercentage() { + String result = totalTides.getRealRatio("-"); + return result; + } + + public String getTotalEstimatedPercentage() { + String result = totalTides.getEstimatedRatio("-"); + return result; + } + + public String getFishingZones() { + return fishingZones; + } + + public boolean isElligibleBoatsProvided() { + return elligibleBoatsProvided; + } + + public boolean isRecentlyUpdated() { + boolean isRecentlyUpdated = latestSampleLogCreateDate != null + && DateUtil.getDifferenceInDays(latestSampleLogCreateDate, new Date()) <= 2 * 7; + return isRecentlyUpdated; + } + + public boolean isNewContactCreatable() { + boolean isNewContactCreatable = new Date().before(lastSampleMonthEndOfMonth); + return isNewContactCreatable; + } + } + +} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,623 @@ +package fr.ifremer.wao.services.service; + +import com.google.common.base.Charsets; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import fr.ifremer.wao.ContactsFilter; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.WaoTechnicalException; +import fr.ifremer.wao.entity.Boat; +import fr.ifremer.wao.entity.Boats; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.CompanyTopiaDao; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.ContactState; +import fr.ifremer.wao.entity.DCF5Code; +import fr.ifremer.wao.entity.ElligibleBoat; +import fr.ifremer.wao.entity.ElligibleBoatImpl; +import fr.ifremer.wao.entity.ElligibleBoatTopiaDao; +import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.FishingZoneTopiaDao; +import fr.ifremer.wao.entity.LocationType; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.Profession; +import fr.ifremer.wao.entity.ProfessionImpl; +import fr.ifremer.wao.entity.ProfessionTopiaDao; +import fr.ifremer.wao.entity.SampleMonth; +import fr.ifremer.wao.entity.SampleMonthImpl; +import fr.ifremer.wao.entity.SampleMonthTopiaDao; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowImpl; +import fr.ifremer.wao.entity.SampleRowLog; +import fr.ifremer.wao.entity.SampleRowLogImpl; +import fr.ifremer.wao.entity.SampleRowLogTopiaDao; +import fr.ifremer.wao.entity.SampleRowTopiaDao; +import fr.ifremer.wao.entity.SamplingStrategy; +import fr.ifremer.wao.entity.TerrestrialLocation; +import fr.ifremer.wao.entity.TerrestrialLocationTopiaDao; +import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.service.administration.ReferentialService; +import fr.ifremer.wao.services.service.administration.UnknownBoatImmatriculationsException; +import fr.ifremer.wao.services.service.csv.ObsMerObsVenteSamplingPlanImportExportModel; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.csv.Export; +import org.nuiton.csv.ExportModel; +import org.nuiton.csv.Import; +import org.nuiton.csv.ImportModel; +import org.nuiton.csv.ImportRuntimeException; +import org.nuiton.topia.persistence.TopiaEntities; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.DateUtil; + +import java.io.InputStream; +import java.text.ParseException; +import java.util.Calendar; +import java.util.Collection; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class SamplingPlanService extends WaoServiceSupport { + + private static final Log log = LogFactory.getLog(SamplingPlanService.class); + + public SampleRow getSampleRow(String sampleRowId) { + + SampleRow sampleRow = getSampleRowDao().findByTopiaId(sampleRowId); + + return sampleRow; + + } + + /** + * On va rechercher en base pour générer un code qui n'existe pas déjà. + */ + protected String getNewSampleRowCode(ObsProgram obsProgram) { + + // On pré-définit un code pour la nouvelle ligne. + // au moment de la création d'une nouvelle ligne, on a aucune info donc + // on suppose que c'est pour l'année en cours + + Calendar begin = new GregorianCalendar(); + begin.setTime(getNow()); + int year = begin.get(Calendar.YEAR); + + String newSampleRowCodePrefix = year + "_" + obsProgram.getShortCode(); + + SampleRowTopiaDao dao = getSampleRowDao(); + + Optional<String> optionalMaxSampleRowCode = dao.findMaxSampleRowCode(newSampleRowCodePrefix); + int maxSampleRowCodeSequence; + if (optionalMaxSampleRowCode.isPresent()) { + String maxSampleRowCode = optionalMaxSampleRowCode.get(); + if (log.isDebugEnabled()) { + log.debug("max code found : " + maxSampleRowCode); + } + String sequenceStr = StringUtils.removeStart(maxSampleRowCode, newSampleRowCodePrefix); + maxSampleRowCodeSequence = Integer.parseInt(sequenceStr); + } else { + maxSampleRowCodeSequence = 0; + } + + maxSampleRowCodeSequence += 1; + + String newSampleRowCodeSuffix = StringUtils.leftPad(String.valueOf(maxSampleRowCodeSequence), 4, "0"); + + String newSampleRowCode = newSampleRowCodePrefix + newSampleRowCodeSuffix; + + if (log.isInfoEnabled()) { + log.info("new sample row code for " + obsProgram + " is " + newSampleRowCode); + } + + return newSampleRowCode; + + } + + public SampleRowsFilter newSampleRowsFilter(AuthenticatedWaoUser authenticatedWaoUser) { + + // all users can see only rows for the program they are logged for + SampleRowsFilter newFilter = new SampleRowsFilter(); + newFilter.setObsProgram(authenticatedWaoUser.getObsProgram()); + + // We don't want to see all rows but the ones important for today + Date fromDate = serviceContext.getNow(); + Date toDate = fromDate; + + // Dans ObsMer et ObsVente, le plan est mensualisé + fromDate = DateUtils.truncate(fromDate, Calendar.MONTH); + + // la période initiale doit toujours aller d'avril à mars (contractuel). + // on prend la période dans laquelle on se trouve actuellement + + // si on est avant le premier avril de l'année courante + boolean beforePeriodChangeInCurrentYear = DateUtil.getMonth(fromDate) < 3; + + if (beforePeriodChangeInCurrentYear) { + // on prend la période qui a commencé l'année dernière et qui finit + // cette année + fromDate = DateUtils.setMonths(fromDate, 3); + fromDate = DateUtils.addYears(fromDate, -1); + } else { + // on prend la période qui commence cette année et se termine + // l'année prochaine + fromDate = DateUtils.setMonths(fromDate, 3); + } + + // on a fromDate sur le premier avril de la bonne année, on va + // jusqu'au mois de mars suivant + toDate = DateUtils.addMonths(fromDate, 11); + + newFilter.setPeriodFrom(fromDate); + newFilter.setPeriodTo(toDate); + + // Very very important to do that at beginning + // Evo #2227 : Guest user has no default company filter + if (authenticatedWaoUser.isCoordinatorOrObserver()) { + newFilter.setCompanyIds(Sets.newHashSet(authenticatedWaoUser.getCompany().getTopiaId())); + } + + return newFilter; + + } + + public List<SampleRow> getUnfinishedSampleRows(AuthenticatedWaoUser authenticatedWaoUser, String companyId) { + + SampleRowsFilter sampleRowsFilter = newSampleRowsFilter(authenticatedWaoUser); + + sampleRowsFilter.setCompanyIds(ImmutableSet.of(companyId)); + + Date now = getNow(); + sampleRowsFilter.setPeriodFrom(now); + // sampleRowsFilter.setPeriodTo(DateUtils.addYears(now, 1)); + + sampleRowsFilter.setOrderByArguments(ImmutableSet.of(SampleRow.PROPERTY_CODE)); + + SampleRowTopiaDao dao = getSampleRowDao(); + + List<SampleRow> unfinishedSampleRows = dao.findAll(sampleRowsFilter); + + return unfinishedSampleRows; + + } + + public void commentSampleRow(AuthenticatedWaoUser authenticatedWaoUser, String sampleRowId, String comment) { + + SampleRow sampleRow = getSampleRow(sampleRowId); + + SampleRowLog sampleRowLog = new SampleRowLogImpl(); + sampleRowLog.setFromAdmin(authenticatedWaoUser.isAdmin()); + sampleRowLog.setComment(comment); + sampleRowLog.setAuthor(authenticatedWaoUser.getWaoUser()); + + sampleRow.addSampleRowLog(sampleRowLog); + + commit(); + + } + + public void deleteSampleRow(String sampleRowId) throws IllegalDeletionException { + + SampleRowTopiaDao dao = getSampleRowDao(); + + SampleRow sampleRow = dao.findByTopiaId(sampleRowId); + + SampleMonthTopiaDao sampleMonthDao = getSampleMonthDao(); + for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { + sampleMonthDao.delete(sampleMonth); + } + sampleRow.clearSampleMonth(); + + SampleRowLogTopiaDao sampleRowLogDao = getSampleRowLogDao(); + for (SampleRowLog sampleRowLog : sampleRow.getSampleRowLog()) { + sampleRowLogDao.delete(sampleRowLog); + } + sampleRow.clearSampleRowLog(); + + ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + elligibleBoatDao.delete(elligibleBoat); + } + sampleRow.clearElligibleBoat(); + + sampleRow.clearFishingZone(); + + if (sampleRow.getProfession() != null) { + ProfessionTopiaDao professionDao = getProfessionDao(); + professionDao.delete(sampleRow.getProfession()); + sampleRow.setProfession(null); + } + + Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> allUsages = dao.findAllUsages(sampleRow); + + if (allUsages.isEmpty()) { + dao.delete(sampleRow); + } else { + throw new IllegalDeletionException(allUsages); + } + + commit(); + + } + + public UpdateSampleRowCommand newUpdateSampleRowCommand(AuthenticatedWaoUser authenticatedWaoUser, Optional<String> optionalSampleRowId) { + + Preconditions.checkState(authenticatedWaoUser.isAuthorizedToCreateSampleRow()); + + UpdateSampleRowCommand updateSampleRowCommand = new UpdateSampleRowCommand(); + + if (optionalSampleRowId.isPresent()) { + + String sampleRowId = optionalSampleRowId.get(); + + SampleRowTopiaDao sampleRowDao = getSampleRowDao(); + + SampleRow sampleRowMemento = sampleRowDao.findByTopiaId(sampleRowId); + sampleRowDao.detach(sampleRowMemento); + updateSampleRowCommand.setSampleRowMemento(sampleRowMemento); + + SampleRow sampleRow = sampleRowDao.findByTopiaId(sampleRowId); + updateSampleRowCommand.setSampleRow(sampleRow); + + updateSampleRowCommand.setCreation(false); + + SampleRowLogImpl newSampleRowLog = new SampleRowLogImpl(); + newSampleRowLog.setAuthor(authenticatedWaoUser.getWaoUser()); + newSampleRowLog.setFromAdmin(authenticatedWaoUser.isAdmin()); + updateSampleRowCommand.setSampleRowLog(newSampleRowLog); + sampleRow.addSampleRowLog(newSampleRowLog); + + Set<Boat> elligibleBoats = new HashSet<>(); + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + boolean boatIsElligibleForUser = + authenticatedWaoUser.isAdmin() && elligibleBoat.isGlobalActive() || + authenticatedWaoUser.isCoordinator() && BooleanUtils.isTrue(elligibleBoat.getCompanyActive()); + if (boatIsElligibleForUser) { + elligibleBoats.add(elligibleBoat.getBoat()); + } + } + String elligibleBoatImmatriculations = Boats.toImmatriculations(elligibleBoats); + updateSampleRowCommand.setElligibleBoatImmatriculations(elligibleBoatImmatriculations); + + } else { + + SampleRow newSampleRow = new SampleRowImpl(); + + newSampleRow.setObsProgram(ObsProgram.OBSMER); + newSampleRow.setProfession(new ProfessionImpl()); + newSampleRow.setFishingZone(new HashSet<FishingZone>()); + newSampleRow.setSampleMonth(new HashSet<SampleMonth>()); + + ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); + if (obsProgram.isObsMer()) { + newSampleRow.setSamplingStrategy(SamplingStrategy.SIMULTANEOUS_ALL_SPECIES); + } + + String newSampleRowCode = getNewSampleRowCode(obsProgram); + newSampleRow.setCode(newSampleRowCode); + + updateSampleRowCommand.setSampleRow(newSampleRow); + + updateSampleRowCommand.setCreation(true); + + } + + ImmutableMap<String, FishingZone> allFishingZones = + Maps.uniqueIndex( + getReferentialService().getAllFishingZones(), + TopiaEntities.getTopiaIdFunction() + ); + updateSampleRowCommand.setAllFishingZones(allFishingZones); + + ImmutableMap<String, Company> allCompanies = + Maps.uniqueIndex( + getCompaniesService().getAllCompanies(), + TopiaEntities.getTopiaIdFunction() + ); + updateSampleRowCommand.setAllCompanies(allCompanies); + + ImmutableMap<String, DCF5Code> allDcf5Codes = + Maps.uniqueIndex( + getReferentialService().getAllDcf5Codes(), + TopiaEntities.getTopiaIdFunction() + ); + updateSampleRowCommand.setAllDcf5Codes(allDcf5Codes); + + return updateSampleRowCommand; + + } + + public void preValidate(AuthenticatedWaoUser authenticatedWaoUser, UpdateSampleRowCommand updateSampleRowCommand) + throws UnknownBoatImmatriculationsException, SampleRowCodeMustBeUniqueException { + + SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); + + SampleRowTopiaDao dao = getSampleRowDao(); + List<SampleRow> existingSampleRowsForTheSameCode = dao.forCodeEquals(sampleRow.getCode()).findAll(); + if (existingSampleRowsForTheSameCode.size() > 1) { + throw new SampleRowCodeMustBeUniqueException(); + } else if (existingSampleRowsForTheSameCode.size() == 1 && !Iterables.getOnlyElement(existingSampleRowsForTheSameCode).equals(sampleRow)) { + throw new SampleRowCodeMustBeUniqueException(); + } + + String elligibleBoatImmatriculations = updateSampleRowCommand.getElligibleBoatImmatriculations(); + + List<Boat> elligibleBoats = getReferentialService().getBoatsFromImmatriculations(elligibleBoatImmatriculations); + ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); + + for (Boat boat : elligibleBoats) { + ElligibleBoat elligibleBoat = sampleRow.getElligibleBoatByBoat(boat); + if (elligibleBoat == null) { + elligibleBoat = new ElligibleBoatImpl(); + elligibleBoat.setSampleRow(sampleRow); + elligibleBoat.setBoat(boat); + elligibleBoatDao.create(elligibleBoat); + } + if (authenticatedWaoUser.isAdmin()) { + elligibleBoat.setGlobalActive(true); + } else if (authenticatedWaoUser.isCoordinator()) { + elligibleBoat.setCompanyActive(true); + } + elligibleBoatDao.update(elligibleBoat); + } + + if (sampleRow.isElligibleBoatNotEmpty()) { + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + Boat boat = elligibleBoat.getBoat(); + boolean isNoLongerActive = !elligibleBoats.contains(boat); + if (isNoLongerActive) { + if (authenticatedWaoUser.isAdmin()) { + elligibleBoat.setGlobalActive(false); + } else if (authenticatedWaoUser.isCoordinator()) { + elligibleBoat.setCompanyActive(null); + } + } + } + } + + SampleMonthTopiaDao sampleMonthDao = getSampleMonthDao(); + + Set<SampleMonth> sampleMonthsToRemove = new HashSet<>(sampleRow.getSampleMonth()); + Map<String, Integer> expectedObservationsByMonths = updateSampleRowCommand.getExpectedObservationsByMonths(); + for (Map.Entry<String, Integer> entry : expectedObservationsByMonths.entrySet()) { + Date month; + try { + month = updateSampleRowCommand.monthFormat.parse(entry.getKey()); + } catch (ParseException e) { + throw new IllegalArgumentException(expectedObservationsByMonths.toString(), e); + } + SampleMonth sampleMonth = sampleRow.getSampleMonth(month); + Integer expectedObservations = entry.getValue(); + if (expectedObservations == null) { + if (sampleMonth != null) { + // rien à faire, il va être supprimé + } + } else { + if (sampleMonth == null) { + sampleMonth = new SampleMonthImpl(); + sampleMonth.setPeriodDate(month); + sampleRow.addSampleMonth(sampleMonth); + sampleMonthDao.create(sampleMonth); + if (log.isTraceEnabled()) { + log.trace("created sample month " + sampleMonth); + } + } else { + sampleMonthsToRemove.remove(sampleMonth); + if (log.isTraceEnabled()) { + log.trace("will keep " + sampleMonth); + } + } + sampleMonth.setExpectedTidesValue(expectedObservations); + sampleMonthDao.update(sampleMonth); + } + } + + for (SampleMonth sampleMonth : sampleMonthsToRemove) { + if (log.isTraceEnabled()) { + log.trace("will remove " + sampleMonth); + } + sampleRow.removeSampleMonth(sampleMonth); + sampleMonthDao.delete(sampleMonth); + } + + } + + public void save(UpdateSampleRowCommand updateSampleRowCommand) { + + SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); + + if (!updateSampleRowCommand.isCreation()) { + SampleRowLog sampleRowLog = updateSampleRowCommand.getSampleRowLog(); + getSampleRowLogDao().create(sampleRowLog); + sampleRowLog.setLogText(updateSampleRowCommand.getSampleRowMemento(), sampleRow); + } + + ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); + if (sampleRow.isElligibleBoatNotEmpty()) { + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + if (elligibleBoat.isPersisted()) { + elligibleBoatDao.update(elligibleBoat); + } else { + elligibleBoatDao.create(elligibleBoat); + } + } + } + + ProfessionTopiaDao professionDao = getProfessionDao(); + Profession profession = sampleRow.getProfession(); + if (profession.isPersisted()) { + professionDao.update(profession); + } else { + professionDao.create(profession); + } + + SampleRowTopiaDao dao = getSampleRowDao(); + if (sampleRow.isPersisted()) { + dao.update(sampleRow); + } else { + dao.create(sampleRow); + } + commit(); + + } + + public InputStream exportSamplingPlan(SampleRowsFilter filter) { + + Preconditions.checkArgument(filter.getPeriodFrom() != null); + Preconditions.checkArgument(filter.getPeriodTo() != null); + + // ignore pagination when exporting + filter.setOrderByArguments(ImmutableSet.of(SampleRow.PROPERTY_CODE)); + + SampleRowTopiaDao dao = getSampleRowDao(); + + List<SampleRow> sampleRows = dao.findAll(filter); + + ExportModel<SampleRow> exportModel = + new ObsMerObsVenteSamplingPlanImportExportModel( + getLocale(), + filter.getPeriodFrom(), + filter.getPeriodTo(), + filter.getObsProgram()); + + Export<SampleRow> export = Export.newExport(exportModel, sampleRows); + + try { + + String csvContent = export.toString(Charsets.UTF_8); + + InputStream csvInputStream = IOUtils.toInputStream(csvContent, Charsets.UTF_8); + + return csvInputStream; + + } catch (Exception e) { + throw new WaoTechnicalException(e); + } + + } + + public void importSamplingPlan(AuthenticatedWaoUser authenticatedWaoUser, InputStream csv) throws ImportErrorException { + + ImportModel<SampleRow> samplingPlanImportModel = + newSamplingPlanImportModel(authenticatedWaoUser); + + Import<SampleRow> samplingPlanImport = + Import.newImport(samplingPlanImportModel, csv); + + SampleRowTopiaDao dao = getSampleRowDao(); + + try { + + for (SampleRow sampleRow : samplingPlanImport) { + + if (StringUtils.isBlank(sampleRow.getCode())) { + + String newSampleRowCode = getNewSampleRowCode(ObsProgram.OBSMER); + + sampleRow.setCode(newSampleRowCode); + + } + + getProfessionDao().create(sampleRow.getProfession()); + + dao.create(sampleRow); + + } + + } catch (ImportRuntimeException e) { + throw new ImportErrorException(e); + } + + commit(); + + } + + protected ImportModel<SampleRow> newSamplingPlanImportModel(AuthenticatedWaoUser authenticatedWaoUser) { + + ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); + + CompanyTopiaDao companyDao = getCompanyDao(); + List<Company> activeCompanies = companyDao.forActiveEquals(true).findAll(); + + TerrestrialLocationTopiaDao terrestrialLocationDao = getTerrestrialLocationDao(); + List<TerrestrialLocation> terrestrialDistricts = + terrestrialLocationDao.forLocationTypeEquals(LocationType.DISTRICT).findAll(); + + FishingZoneTopiaDao fishingZoneDao = getFishingZoneDao(); + List<FishingZone> fishingZones = fishingZoneDao.findAll(); + + ReferentialService referentialService = getReferentialService(); + + ImportModel<SampleRow> samplingPlanImportModel = + new ObsMerObsVenteSamplingPlanImportExportModel(getLocale(), + obsProgram, + activeCompanies, + fishingZones, + terrestrialDistricts, + referentialService); + + return samplingPlanImportModel; + + } + + public void recomputeSampleRowEstimatedAndRealTides(SampleRow sampleRow) { + + //---- + // Reset des tides de la ligne + //---- + + for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { + sampleMonth.setEstimatedTidesValue(0); + sampleMonth.setRealTidesValue(0); + } + + //---- + // Recuperation de tous les contacts de la ligne + //---- + + ContactsFilter contactFilter = new ContactsFilter(); + + contactFilter.setFilterOnObservationBeginDate(true); + contactFilter.getSampleRowFilter().setSampleRowIds(Sets.newHashSet(sampleRow.getTopiaId())); + + contactFilter.setContactStates(ImmutableSet.of(ContactState.OBSERVATION_DONE)); + // on exclue les contacts qui sont invalidés par le programme + contactFilter.setProgramAcceptations(Sets.newHashSet(true, null)); + // on exclue les contacts invalidés par la société + contactFilter.setCompanyAcceptations(Sets.newHashSet(true, null)); + + Collection<Contact> contacts = getContactDao().forFilter(contactFilter, false).findAll(); + + //---- + // Recalcul des tides + //---- + + for (Contact contact : contacts) { + + Date observationBeginDate = contact.getObservationBeginDate(); + + SampleMonth month = sampleRow.getSampleMonth(observationBeginDate); + + month.setEstimatedTidesValue(month.getEstimatedTidesValue() + 1); + + if (BooleanUtils.isTrue(contact.getValidationCompany())) { + month.setRealTidesValue(month.getRealTidesValue() + 1); + } + + } + + } + +} Copied: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/Synthesis.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/Synthesis.java) =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/Synthesis.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/Synthesis.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,133 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.entity.Boat; +import org.jfree.chart.JFreeChart; + +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +public class Synthesis { + + protected JFreeChart expectedVsActualObservationsByMonthsChart; + + protected JFreeChart boardingBoatsChart; + + protected int maxBoardingValue; + + protected Boat maxBoardingBoat; + + protected int boardingsCount; + + protected int invalidBoardingsCount; + + protected int validBoardingsCount; + + protected Map<String, CompanySynthesis> companySyntheses = new HashMap<>(); + + protected Set<String> sampleRowIds; + + public Map<String, CompanySynthesis> getCompanySyntheses() { + return companySyntheses; + } + + public JFreeChart getExpectedVsActualObservationsByMonthsChart() { + return expectedVsActualObservationsByMonthsChart; + } + + public void setExpectedVsActualObservationsByMonthsChart(JFreeChart expectedVsActualObservationsByMonthsChart) { + this.expectedVsActualObservationsByMonthsChart = expectedVsActualObservationsByMonthsChart; + } + + public JFreeChart getBoardingBoatsChart() { + return boardingBoatsChart; + } + + public void setBoardingBoatsChart(JFreeChart boardingBoatsChart) { + this.boardingBoatsChart = boardingBoatsChart; + } + + public int getMaxBoardingValue() { + return maxBoardingValue; + } + + public void setMaxBoardingValue(int maxBoardingValue) { + this.maxBoardingValue = maxBoardingValue; + } + + public Boat getMaxBoardingBoat() { + return maxBoardingBoat; + } + + public void setMaxBoardingBoat(Boat maxBoardingBoat) { + this.maxBoardingBoat = maxBoardingBoat; + } + + public int getBoardingsCount() { + return boardingsCount; + } + + public void setBoardingsCount(int boardingsCount) { + this.boardingsCount = boardingsCount; + } + + public int getInvalidBoardingsCount() { + return invalidBoardingsCount; + } + + public void setInvalidBoardingsCount(int invalidBoardingsCount) { + this.invalidBoardingsCount = invalidBoardingsCount; + } + + public int getValidBoardingsCount() { + return validBoardingsCount; + } + + public void setValidBoardingsCount(int validBoardingsCount) { + this.validBoardingsCount = validBoardingsCount; + } + + public Map<String, Double> getComplianceBoardingIndicator() { + Map<String, Double> complianceBoardingIndicator = new TreeMap(); + for (CompanySynthesis companySynthesis : companySyntheses.values()) { + complianceBoardingIndicator.put( + companySynthesis.getCompanyName(), + companySynthesis.getComplianceBoardingIndicator()); + } + return complianceBoardingIndicator; + } + + public void setSampleRowIds(Set<String> sampleRowIds) { + this.sampleRowIds = sampleRowIds; + } + + public Set<String> getSampleRowIds() { + return sampleRowIds; + } + + public CompanySynthesis getCompanySynthesis(String companyId) { + CompanySynthesis companySynthesis = companySyntheses.get(companyId); + if (companySynthesis == null) { + companySynthesis = new CompanySynthesis(); + companySynthesis.setCompanyId(companyId); + companySyntheses.put(companyId, companySynthesis); + } + return companySynthesis; + } + + public Set<CompanySynthesis> getCompanySynthesesOrderedByName() { + Map<String, CompanySynthesis> companySynthesesOrderedByName = new TreeMap(); + for (CompanySynthesis companySynthesis : companySyntheses.values()) { + companySynthesesOrderedByName.put( + companySynthesis.getCompanyName(), + companySynthesis); + } + return new LinkedHashSet<>(companySynthesesOrderedByName.values()); + } + + public boolean isEmpty() { + return companySyntheses.isEmpty(); + } +} Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/SynthesisService.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -46,55 +46,55 @@ public ContactsFilter newFilter(AuthenticatedWaoUser authenticatedWaoUser) { - ObsMerContactsService obsMerContactsService = newService(ObsMerContactsService.class); + ContactsService contactsService = newService(ContactsService.class); - ContactsFilter newFilter = obsMerContactsService.newContactFilter(authenticatedWaoUser); + ContactsFilter newFilter = contactsService.newContactFilter(authenticatedWaoUser); return newFilter; } - public ObsMerSynthesis getObsMerSynthesis(ContactsFilter filter) { + public Synthesis getObsMerSynthesis(ContactsFilter filter) { - Cache<ContactsFilter, ObsMerSynthesis> cache = serviceContext.getSynthesesCache(); + Cache<ContactsFilter, Synthesis> cache = serviceContext.getSynthesesCache(); - ObsMerSynthesis obsMerSynthesis = cache.getIfPresent(filter); + Synthesis synthesis = cache.getIfPresent(filter); - if (obsMerSynthesis == null) { + if (synthesis == null) { - obsMerSynthesis = new ObsMerSynthesis(); + synthesis = new Synthesis(); List<String> sampleRowsIds = getContactDao().getSampleRowsIds(filter); - obsMerSynthesis.setSampleRowIds(new HashSet<>(sampleRowsIds)); + synthesis.setSampleRowIds(new HashSet<>(sampleRowsIds)); - setExpectedVsActualObservationsByMonthsBarChartData(obsMerSynthesis, filter); + setExpectedVsActualObservationsByMonthsBarChartData(synthesis, filter); - setBoardingBoatsData(obsMerSynthesis, filter); + setBoardingBoatsData(synthesis, filter); - setComplianceBoardingIndicator(obsMerSynthesis, filter); + setComplianceBoardingIndicator(synthesis, filter); - setContactStatesStatistics(obsMerSynthesis, filter); + setContactStatesStatistics(synthesis, filter); - setDataInputDateReactivity(obsMerSynthesis, filter); + setDataInputDateReactivity(synthesis, filter); - setDataReliability(obsMerSynthesis, filter); + setDataReliability(synthesis, filter); - for (CompanySynthesis companySynthesis : obsMerSynthesis.getCompanySyntheses().values()) { + for (CompanySynthesis companySynthesis : synthesis.getCompanySyntheses().values()) { String companyId = companySynthesis.getCompanyId(); Company company = getCompanyDao().findByTopiaId(companyId); companySynthesis.setCompanyName(company.getName()); } - cache.put(filter, obsMerSynthesis); + cache.put(filter, synthesis); } - return obsMerSynthesis; + return synthesis; } - protected void setDataReliability(ObsMerSynthesis obsMerSynthesis, ContactsFilter filter) { + protected void setDataReliability(Synthesis synthesis, ContactsFilter filter) { ContactTopiaDao dao = getContactDao(); @@ -102,13 +102,13 @@ for (Map.Entry<String, Long> entry : reliableObservationsCount.entrySet()) { String companyId = entry.getKey(); - CompanySynthesis companySynthesis = obsMerSynthesis.getCompanySynthesis(companyId); + CompanySynthesis companySynthesis = synthesis.getCompanySynthesis(companyId); companySynthesis.setReliableObservationsCount(reliableObservationsCount.get(companyId)); } } - protected void setDataInputDateReactivity(ObsMerSynthesis obsMerSynthesis, ContactsFilter filter) { + protected void setDataInputDateReactivity(Synthesis synthesis, ContactsFilter filter) { ContactTopiaDao dao = getContactDao(); @@ -119,7 +119,7 @@ contactsDoneObservationBeginDateAndDateInputDate.asMap().entrySet()) { String companyId = entry.getKey(); - CompanySynthesis companySynthesis = obsMerSynthesis.getCompanySynthesis(companyId); + CompanySynthesis companySynthesis = synthesis.getCompanySynthesis(companyId); Collection<Pair<Date, Date>> dates = entry.getValue(); @@ -138,7 +138,7 @@ } - protected void setContactStatesStatistics(ObsMerSynthesis obsMerSynthesis, ContactsFilter filter) { + protected void setContactStatesStatistics(Synthesis synthesis, ContactsFilter filter) { ContactTopiaDao dao = getContactDao(); @@ -148,21 +148,21 @@ for (Map.Entry<String, Map<ContactState, Long>> entry : contactStatesStatistics.entrySet()) { String companyId = entry.getKey(); - CompanySynthesis companySynthesis = obsMerSynthesis.getCompanySynthesis(companyId); + CompanySynthesis companySynthesis = synthesis.getCompanySynthesis(companyId); companySynthesis.setContactsStatesStatistics(entry.getValue()); companySynthesis.setContactsCount(contactsCountsByCompany.get(companyId)); } } - protected void setComplianceBoardingIndicator(ObsMerSynthesis obsMerSynthesis, ContactsFilter filter) { + protected void setComplianceBoardingIndicator(Synthesis synthesis, ContactsFilter filter) { ContactTopiaDao dao = getContactDao(); Map<String, Double> complianceBoardingIndicator = dao.getComplianceBoardingIndicator(filter); for (Map.Entry<String, Double> entry : complianceBoardingIndicator.entrySet()) { - CompanySynthesis companySynthesis = obsMerSynthesis.getCompanySynthesis(entry.getKey()); + CompanySynthesis companySynthesis = synthesis.getCompanySynthesis(entry.getKey()); companySynthesis.setComplianceBoardingIndicator(entry.getValue()); } @@ -172,7 +172,7 @@ * Un graphique avec, pour chaque mois, deux barres qui représentent l'effort demandé * vs l'effort réalisé. */ - protected void setExpectedVsActualObservationsByMonthsBarChartData(ObsMerSynthesis obsMerSynthesis, ContactsFilter filter) { + protected void setExpectedVsActualObservationsByMonthsBarChartData(Synthesis synthesis, ContactsFilter filter) { Locale locale = serviceContext.getLocale(); @@ -227,7 +227,7 @@ JFreeChart expectedVsActualObservationsByMonthsChart = new JFreeChart(I18n.l(locale, SynthesisId.GRAPH_SAMPLING.getI18nKey()), JFreeChart.DEFAULT_TITLE_FONT, plot, true); - obsMerSynthesis.setExpectedVsActualObservationsByMonthsChart(expectedVsActualObservationsByMonthsChart); + synthesis.setExpectedVsActualObservationsByMonthsChart(expectedVsActualObservationsByMonthsChart); } @@ -242,7 +242,7 @@ * and for invalid boardings from 1 to {@code MAX_BOARDINGS}, the boat with * the max boarding and its value. */ - protected void setBoardingBoatsData(ObsMerSynthesis obsMerSynthesis, ContactsFilter filter) { + protected void setBoardingBoatsData(Synthesis synthesis, ContactsFilter filter) { Locale locale = serviceContext.getLocale(); @@ -319,11 +319,11 @@ } } - obsMerSynthesis.setMaxBoardingValue(maxBoardingCount); - obsMerSynthesis.setMaxBoardingBoat(maxBoardingBoat); - obsMerSynthesis.setBoardingsCount(boardingTotal); - obsMerSynthesis.setInvalidBoardingsCount(invalidBoardingTotal); - obsMerSynthesis.setValidBoardingsCount(boardingTotal - invalidBoardingTotal); + synthesis.setMaxBoardingValue(maxBoardingCount); + synthesis.setMaxBoardingBoat(maxBoardingBoat); + synthesis.setBoardingsCount(boardingTotal); + synthesis.setInvalidBoardingsCount(invalidBoardingTotal); + synthesis.setValidBoardingsCount(boardingTotal - invalidBoardingTotal); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); @@ -350,7 +350,7 @@ JFreeChart boardingBoatsChart = new JFreeChart(I18n.l(locale, SynthesisId.GRAPH_BOARDING.getI18nKey()), JFreeChart.DEFAULT_TITLE_FONT, plot, true); - obsMerSynthesis.setBoardingBoatsChart(boardingBoatsChart); + synthesis.setBoardingBoatsChart(boardingBoatsChart); } } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateContactCommand.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateContactCommand.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateContactCommand.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -57,6 +57,8 @@ protected Set<String> secondaryObserverIds = new HashSet<>(); + private String terrestrialLocationId; + public boolean isCreation() { return creation; } @@ -180,4 +182,12 @@ public void setSecondaryObserverIds(Set<String> secondaryObserverIds) { this.secondaryObserverIds = secondaryObserverIds; } + + public String getTerrestrialLocationId() { + return terrestrialLocationId; + } + + public void setTerrestrialLocationId(String terrestrialLocationId) { + this.terrestrialLocationId = terrestrialLocationId; + } } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -96,6 +96,7 @@ import java.io.InputStream; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -1130,4 +1131,21 @@ return dcf5Codes; } + + public List<TerrestrialLocation> getTerrestrialLocationInDistricts(Collection<TerrestrialLocation> terrestrialDistricts) { + + Set districtCodes = new HashSet(); + for (TerrestrialLocation terrestrialDistrict : terrestrialDistricts) { + Preconditions.checkArgument(terrestrialDistrict.isDistrict()); + districtCodes.add(terrestrialDistrict.getDistrictCode()); + } + + TerrestrialLocationTopiaDao dao = getTerrestrialLocationDao(); + + List<TerrestrialLocation> locationsInDistricts = dao.forLocationTypeIn(ImmutableSet.of(LocationType.PORT, LocationType.AUCTION)).addIn(TerrestrialLocation.PROPERTY_DISTRICT_CODE, districtCodes).findAll(); + + return locationsInDistricts; + + } + } Property changes on: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java ___________________________________________________________________ Modified: svn:mergeinfo - /branches/wao-1.5.x/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java:679-733 + /branches/wao-1.5.x/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java:679-733 /branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java:2075-2085 Property changes on: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv ___________________________________________________________________ Modified: svn:mergeinfo - /branches/wao-1.5.x/wao-business/src/main/java/fr/ifremer/wao/io/csv2/models:679-733 + /branches/wao-1.5.x/wao-business/src/main/java/fr/ifremer/wao/io/csv2/models:679-733 /branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/csv:2075-2085 Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -23,6 +23,8 @@ */ package fr.ifremer.wao.services.service.csv; +import com.google.common.base.Preconditions; +import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.entity.Boat; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.Contact; @@ -31,9 +33,7 @@ import fr.ifremer.wao.entity.ContactStateMotif; import fr.ifremer.wao.entity.DataReliability; import fr.ifremer.wao.entity.LocationType; -import fr.ifremer.wao.entity.ObsDebCode; import fr.ifremer.wao.entity.ObsProgram; -import fr.ifremer.wao.entity.ObservationType; import fr.ifremer.wao.entity.ObservedDataControl; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.TerrestrialLocation; @@ -43,7 +43,6 @@ import fr.ifremer.wao.services.service.csv.operations.ContactStateMotivesParserFormatter; import fr.ifremer.wao.services.service.csv.operations.I18nAbleParserFormatter; import fr.ifremer.wao.services.service.csv.operations.LocationTypeParserFormatter; -import fr.ifremer.wao.services.service.csv.operations.ObsDebCodeParserFormatter; import fr.ifremer.wao.services.service.csv.operations.SampleRowParserFormatter; import fr.ifremer.wao.services.service.csv.operations.UserParserFormatter; import fr.ifremer.wao.services.service.csv.operations.UsersParserFormatter; @@ -69,100 +68,55 @@ public class ContactImportExportModel implements ImportExportModel<Contact> { - /** will get terrestrial location depending on location code and pushed location type */ - static class TerrestrialLocationParserFormatter implements ValueParserFormatter<TerrestrialLocation> { - - protected Map<LocationType, Map<String, TerrestrialLocation>> indexedLocations; - - protected List<TerrestrialLocation> terrestrialLocations; - - protected ValueGetter<Contact, LocationType> locationTypeGetter; - - TerrestrialLocationParserFormatter(List<TerrestrialLocation> terrestrialLocations, - ValueGetter<Contact, LocationType> locationTypeGetter) { - this.terrestrialLocations = terrestrialLocations; - this.locationTypeGetter = locationTypeGetter; - } - - @Override - public String format(TerrestrialLocation terrestrialLocation) { - String code = ""; - if (terrestrialLocation != null) { - code = terrestrialLocation.getCode(); - } - return code; - } - - @Override - public TerrestrialLocation parse(String code) throws ParseException { - if (indexedLocations == null) { - indexedLocations = new HashMap<>(); - for (TerrestrialLocation terrestrialLocation : terrestrialLocations) { - LocationType locationType = terrestrialLocation.getLocationType(); - Map<String, TerrestrialLocation> locationsForType = indexedLocations.get(locationType); - if (locationsForType == null) { - locationsForType = new HashMap<>(); - } - locationsForType.put(terrestrialLocation.getCode(), terrestrialLocation); - indexedLocations.put(locationType, locationsForType); - } - } - TerrestrialLocation terrestrialLocation = null; - if (StringUtils.isNotBlank(code)) { - LocationType locationType; - try { - locationType = locationTypeGetter.get(null); - } catch (Exception e) { - throw new RuntimeException(e); - } - if (locationType == null) { - throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.locationTypeMissing")); - } - terrestrialLocation = indexedLocations.get(locationType).get(code); - if (terrestrialLocation == null) { - throw new IllegalArgumentException(I18n.t("wao.import.contact.failure.wrongTerrestrialLocation", - locationType.toString(), code)); - } - } - return terrestrialLocation; - } - } - protected final Locale locale; protected ObsProgram obsProgram; protected List<WaoUser> waoUsers; - protected List<TerrestrialLocation> terrestrialLocations; - protected List<SampleRow> sampleRows; protected List<Boat> boats; - protected List<ObsDebCode> obsDebCodes; - protected List<ContactStateMotif> motives; - /** for export */ - public ContactImportExportModel(Locale locale, ObsProgram obsProgram) { - this.locale = locale; - this.obsProgram = obsProgram; + private List<TerrestrialLocation> terrestrialLocations; + + public static ContactImportExportModel forExport(Locale locale, + ObsProgram obsProgram) { + return new ContactImportExportModel(locale, obsProgram, null, null, null, null, null); } - /** for import */ - public ContactImportExportModel(Locale locale, ObsProgram obsProgram, List<WaoUser> waoUsers, - List<TerrestrialLocation> terrestrialLocations, - List<SampleRow> sampleRows, List<Boat> boats, - List<ObsDebCode> obsDebCodes, List<ContactStateMotif> motives) { + public static ContactImportExportModel forImport(Locale locale, + ObsProgram obsProgram, + List<WaoUser> waoUsers, + List<SampleRow> sampleRows, + List<Boat> boats, + List<ContactStateMotif> motives, + List<TerrestrialLocation> terrestrialLocations) { + + Preconditions.checkState(waoUsers != null, "To import must have waoUsers"); + Preconditions.checkState(boats != null, "To import must have boats"); + Preconditions.checkState(sampleRows != null, "To import must have sampleRows"); + Preconditions.checkState(motives != null, "To import must have motives"); + Preconditions.checkState(terrestrialLocations != null, "To import must have motives"); + return new ContactImportExportModel(locale, obsProgram, waoUsers, sampleRows, boats, motives, terrestrialLocations); + } + + protected ContactImportExportModel(Locale locale, + ObsProgram obsProgram, + List<WaoUser> waoUsers, + List<SampleRow> sampleRows, + List<Boat> boats, + List<ContactStateMotif> motives, + List<TerrestrialLocation> terrestrialLocations) { this.locale = locale; this.obsProgram = obsProgram; this.waoUsers = waoUsers; - this.terrestrialLocations = terrestrialLocations; this.sampleRows = sampleRows; this.boats = boats; - this.obsDebCodes = obsDebCodes; this.motives = motives; + this.terrestrialLocations = terrestrialLocations; } @Override @@ -188,6 +142,7 @@ modelBuilder.newColumnForImportExport("CONTACT_DATE_CREATION", Contact.PROPERTY_CREATION_DATE, Common.DAY_TIME); modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEUR_PRINCIPAL", Contact.PROPERTY_MAIN_OBSERVER, new UserParserFormatter(locale, waoUsers)); modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEURS_SECONDAIRES", Contact.PROPERTY_SECONDARY_OBSERVERS, new UsersParserFormatter(locale, waoUsers)); + modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_NOMS"); modelBuilder.newColumnForExport( "CONTACT_OBSERVATEURS_NOMS", @@ -235,9 +190,9 @@ modelBuilder.newColumnForImportExport("PLAN_CODE", Contact.PROPERTY_SAMPLE_ROW, new SampleRowParserFormatter(locale, sampleRows)); - if (obsProgram == ObsProgram.OBSMER) { + if (obsProgram.isObsMer()) { modelBuilder.newColumnForImportExport("CONTACT_QUALITE_DONNEE", "dataReliability", - new I18nAbleParserFormatter<>(locale, DataReliability.values())); + new I18nAbleParserFormatter<>(locale, DataReliability.values())); modelBuilder.newColumnForImportExport("CONTACT_OBSERVATION_MAMMIFERE", Contact.PROPERTY_MAMMALS_OBSERVATION, Common.BOOLEAN); modelBuilder.newColumnForImportExport("CONTACT_CAPTURE_ACCIDENTELLE", Contact.PROPERTY_MAMMALS_CAPTURE, Common.BOOLEAN); modelBuilder.newIgnoredColumn("CONTACT_CAPTURE_ACCIDENTELLE_DETAILS"); @@ -245,6 +200,7 @@ modelBuilder.newColumnForImportExport("CONTACT_ETAT_MOTIF_CODE", Contact.PROPERTY_CONTACT_STATE_MOTIF, new ContactStateMotivesParserFormatter(locale, motives)); modelBuilder.newIgnoredColumn("CONTACT_ETAT_MOTIF_NOM"); modelBuilder.newColumnForExport("CONTACT_ETAT_MOTIF_NOM", new ValueGetter<Contact, String>() { + @Override public String get(Contact contact) throws Exception { String name = ""; @@ -262,7 +218,11 @@ I18nAbleParserFormatter<ObservedDataControl> valueParserFormatter = new I18nAbleParserFormatter<>(locale, observedDataControlsValues); valueParserFormatter.setAcceptNullValues(true); modelBuilder.newColumnForImportExport("CONTACT_DONNEES_ALLEGRO_VALIDEES", Contact.PROPERTY_OBSERVED_DATA_CONTROL, valueParserFormatter); - } else { + } + + if (obsProgram.isObsVente()) { + modelBuilder.newColumnForImportExport("CONTACT_ECHANTILLONNAGE_COMPLET", Contact.PROPERTY_COMPLETE_SAMPLING, Common.BOOLEAN); + // FIXME 20110606 bleny contact.getTerrestrialLocation() may be null, export will fail // terrestrial location for both ObsVente and ObsDeb @@ -285,12 +245,11 @@ return locationType; } }, - locationTypeParserFormatter - ); + locationTypeParserFormatter); modelBuilder.newColumnForImportExport( "CONTACT_LIEU_CODE", Contact.PROPERTY_TERRESTRIAL_LOCATION, - new TerrestrialLocationParserFormatter(terrestrialLocations, locationTypeGetter)); + new TerrestrialLocationParserFormatter(locale, terrestrialLocations, locationTypeGetter)); modelBuilder.newIgnoredColumn("CONTACT_LIEU_DESCRIPTION"); modelBuilder.newColumnForExport("CONTACT_LIEU_DESCRIPTION", new ValueGetter<Contact, String>() { @@ -304,18 +263,9 @@ return description; } }); - } - if (obsProgram == ObsProgram.OBSVENTE) { - modelBuilder.newColumnForImportExport("CONTACT_ECHANTILLONNAGE_COMPLET", Contact.PROPERTY_COMPLETE_SAMPLING, Common.BOOLEAN); } - if (obsProgram == ObsProgram.OBSDEB) { - modelBuilder.newColumnForImportExport("CONTACT_DATE_DEBARQUEMENT", Contact.PROPERTY_LANDING_DATE, Common.DAY_TIME); - modelBuilder.newColumnForImportExport("CONTACT_TYPE_OBSERVATION", "observationType", new I18nAbleParserFormatter<>(locale, ObservationType.values())); - modelBuilder.newColumnForImportExport("CONTACT_METIER", Contact.PROPERTY_OBS_DEB_CODE, new ObsDebCodeParserFormatter(locale, obsDebCodes)); - } - return modelBuilder; } @@ -327,6 +277,68 @@ @Override public Iterable<ImportableColumn<Contact, Object>> getColumnsForImport() { return (Iterable) getModel().getColumnsForImport(); + } /** will get terrestrial location depending on location code and pushed location type */ + + protected static class TerrestrialLocationParserFormatter implements ValueParserFormatter<TerrestrialLocation> { + + protected Locale locale; + + protected Map<LocationType, Map<String, TerrestrialLocation>> indexedLocations; + + protected List<TerrestrialLocation> terrestrialLocations; + + protected ValueGetter<Contact, LocationType> locationTypeGetter; + + TerrestrialLocationParserFormatter(Locale locale, + List<TerrestrialLocation> terrestrialLocations, + ValueGetter<Contact, LocationType> locationTypeGetter) { + this.locale = locale; + this.terrestrialLocations = terrestrialLocations; + this.locationTypeGetter = locationTypeGetter; + } + + @Override + public String format(TerrestrialLocation terrestrialLocation) { + String code = ""; + if (terrestrialLocation != null) { + code = terrestrialLocation.getCode(); + } + return code; + } + + @Override + public TerrestrialLocation parse(String code) throws ParseException { + if (indexedLocations == null) { + indexedLocations = new HashMap<>(); + for (TerrestrialLocation terrestrialLocation : terrestrialLocations) { + LocationType locationType = terrestrialLocation.getLocationType(); + Map<String, TerrestrialLocation> locationsForType = indexedLocations.get(locationType); + if (locationsForType == null) { + locationsForType = new HashMap<>(); + } + locationsForType.put(terrestrialLocation.getCode(), terrestrialLocation); + indexedLocations.put(locationType, locationsForType); + } + } + TerrestrialLocation terrestrialLocation = null; + if (StringUtils.isNotBlank(code)) { + LocationType locationType; + try { + locationType = locationTypeGetter.get(null); + } catch (Exception e) { + throw new RuntimeException(e); + } + if (locationType == null) { + throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.locationTypeMissing")); + } + terrestrialLocation = indexedLocations.get(locationType).get(code); + if (terrestrialLocation == null) { + throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.wrongTerrestrialLocation", + WaoUtils.l(locale, locationType), code)); + } + } + return terrestrialLocation; + } } } Deleted: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerContactImportExportModel.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,217 +0,0 @@ -/* - * #%L - * Wao :: Business - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2011 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.services.service.csv; - -import com.google.common.base.Preconditions; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactImpl; -import fr.ifremer.wao.entity.ContactState; -import fr.ifremer.wao.entity.ContactStateMotif; -import fr.ifremer.wao.entity.DataReliability; -import fr.ifremer.wao.entity.ObsProgram; -import fr.ifremer.wao.entity.ObservedDataControl; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.services.service.csv.operations.BoatParserFormatter; -import fr.ifremer.wao.services.service.csv.operations.CompanyParserFormatter; -import fr.ifremer.wao.services.service.csv.operations.ContactStateMotivesParserFormatter; -import fr.ifremer.wao.services.service.csv.operations.I18nAbleParserFormatter; -import fr.ifremer.wao.services.service.csv.operations.SampleRowParserFormatter; -import fr.ifremer.wao.services.service.csv.operations.UserParserFormatter; -import fr.ifremer.wao.services.service.csv.operations.UsersParserFormatter; -import org.apache.commons.lang3.StringUtils; -import org.nuiton.csv.Common; -import org.nuiton.csv.ExportableColumn; -import org.nuiton.csv.ImportExportModel; -import org.nuiton.csv.ImportableColumn; -import org.nuiton.csv.ModelBuilder; -import org.nuiton.csv.ValueFormatter; -import org.nuiton.csv.ValueGetter; - -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; - -public class ObsMerContactImportExportModel implements ImportExportModel<Contact> { - - protected final Locale locale; - - protected ObsProgram obsProgram; - - protected List<WaoUser> waoUsers; - - protected List<SampleRow> sampleRows; - - protected List<Boat> boats; - - protected List<ContactStateMotif> motives; - - public static ObsMerContactImportExportModel forExport(Locale locale, - ObsProgram obsProgram) { - return new ObsMerContactImportExportModel(locale, obsProgram, null, null, null, null); - } - - public static ObsMerContactImportExportModel forImport(Locale locale, - ObsProgram obsProgram, - List<WaoUser> waoUsers, - List<SampleRow> sampleRows, - List<Boat> boats, - List<ContactStateMotif> motives) { - - Preconditions.checkState(waoUsers != null, "To import must have waoUsers"); - Preconditions.checkState(boats != null, "To import must have boats"); - Preconditions.checkState(sampleRows != null, "To import must have sampleRows"); - Preconditions.checkState(motives != null, "To import must have motives"); - return new ObsMerContactImportExportModel(locale, obsProgram, waoUsers, sampleRows, boats, motives); - } - - protected ObsMerContactImportExportModel(Locale locale, - ObsProgram obsProgram, - List<WaoUser> waoUsers, - List<SampleRow> sampleRows, - List<Boat> boats, - List<ContactStateMotif> motives) { - this.locale = locale; - this.obsProgram = obsProgram; - this.waoUsers = waoUsers; - this.sampleRows = sampleRows; - this.boats = boats; - this.motives = motives; - } - - @Override - public char getSeparator() { - return ';'; - } - - @Override - public void pushCsvHeaderNames(List<String> headerNames) { - // nothing to do - } - - @Override - public Contact newEmptyInstance() { - Contact newContact = new ContactImpl(); - newContact.setObsProgram(obsProgram); - return newContact; - } - - protected ModelBuilder<Contact> getModel() { - ModelBuilder<Contact> modelBuilder = new ModelBuilder<>(); - modelBuilder.newColumnForImportExport("CONTACT_ID", Contact.PROPERTY_TOPIA_ID); - modelBuilder.newColumnForImportExport("CONTACT_DATE_CREATION", Contact.PROPERTY_CREATION_DATE, Common.DAY_TIME); - modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEUR_PRINCIPAL", Contact.PROPERTY_MAIN_OBSERVER, new UserParserFormatter(locale, waoUsers)); - modelBuilder.newColumnForImportExport("CONTACT_OBSERVATEURS_SECONDAIRES", Contact.PROPERTY_SECONDARY_OBSERVERS, new UsersParserFormatter(locale, waoUsers)); - - modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_NOMS"); - modelBuilder.newColumnForExport( - "CONTACT_OBSERVATEURS_NOMS", - "allObservers", - new ValueFormatter<List<WaoUser>>() { - @Override - public String format(List<WaoUser> value) { - List<String> fullNames = new LinkedList<>(); - for (WaoUser waoUser : value) { - fullNames.add(waoUser.getFullName()); - } - return StringUtils.join(fullNames, ", "); - } - } - ); - modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_SOCIETE"); - modelBuilder.newColumnForExport( - "CONTACT_OBSERVATEURS_SOCIETE", - new ValueGetter<Contact, Company>() { - @Override - public Company get(Contact contact) { - return contact.getMainObserver().getCompany(); - } - }, - new CompanyParserFormatter(locale, null) - ); - modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new I18nAbleParserFormatter<>(locale, ContactState.getAllowedStates(obsProgram))); - modelBuilder.newColumnForImportExport("CONTACT_DEBUT_OBSERVATION", Contact.PROPERTY_OBSERVATION_BEGIN_DATE, Common.DAY_TIME); - modelBuilder.newColumnForImportExport("CONTACT_FIN_OBSERVATION", Contact.PROPERTY_OBSERVATION_END_DATE, Common.DAY_TIME); - modelBuilder.newColumnForImportExport("CONTACT_SAISIE_DONNEES", Contact.PROPERTY_DATA_INPUT_DATE, Common.DAY); - modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_OBSERVATEUR", Contact.PROPERTY_COMMENT); - modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_COORDINATEUR", Contact.PROPERTY_COMMENT_COORDINATOR); - modelBuilder.newColumnForImportExport("CONTACT_COMMENTAIRE_PROGRAMME", Contact.PROPERTY_COMMENT_ADMIN); - - modelBuilder.newColumnForImportExport("NAVIRE_IMMATRICULATION", Contact.PROPERTY_BOAT, new BoatParserFormatter(boats, locale)); - modelBuilder.newIgnoredColumn("NAVIRE_NOM"); - modelBuilder.newColumnForExport("NAVIRE_NOM", new ValueGetter<Contact, String>() { - @Override - public String get(Contact contact) throws Exception { - return contact.getBoat().getName(); - } - }); - modelBuilder.newColumnForImportExport("CONTACT_VALIDATION_SOCIETE", Contact.PROPERTY_VALIDATION_COMPANY, Common.BOOLEAN); - modelBuilder.newColumnForImportExport("CONTACT_VALIDATION_PROGRAMME", Contact.PROPERTY_VALIDATION_PROGRAM, Common.BOOLEAN); - - modelBuilder.newColumnForImportExport("PLAN_CODE", Contact.PROPERTY_SAMPLE_ROW, new SampleRowParserFormatter(locale, sampleRows)); - - modelBuilder.newColumnForImportExport("CONTACT_QUALITE_DONNEE", "dataReliability", - new I18nAbleParserFormatter<>(locale, DataReliability.values())); - modelBuilder.newColumnForImportExport("CONTACT_OBSERVATION_MAMMIFERE", Contact.PROPERTY_MAMMALS_OBSERVATION, Common.BOOLEAN); - modelBuilder.newColumnForImportExport("CONTACT_CAPTURE_ACCIDENTELLE", Contact.PROPERTY_MAMMALS_CAPTURE, Common.BOOLEAN); - modelBuilder.newIgnoredColumn("CONTACT_CAPTURE_ACCIDENTELLE_DETAILS"); - modelBuilder.newColumnForExport("CONTACT_CAPTURE_ACCIDENTELLE_DETAILS", Contact.PROPERTY_MAMMALS_INFO); - modelBuilder.newColumnForImportExport("CONTACT_ETAT_MOTIF_CODE", Contact.PROPERTY_CONTACT_STATE_MOTIF, new ContactStateMotivesParserFormatter(locale, motives)); - modelBuilder.newIgnoredColumn("CONTACT_ETAT_MOTIF_NOM"); - modelBuilder.newColumnForExport("CONTACT_ETAT_MOTIF_NOM", new ValueGetter<Contact, String>() { - @Override - public String get(Contact contact) throws Exception { - String name = ""; - if (contact.getContactStateMotif() != null) { - name = contact.getContactStateMotif().getName(); - } - return name; - } - }); - modelBuilder.newColumnForImportExport("CONTACT_TRANSMISSION_RESTITUTION", Contact.PROPERTY_RESTITUTION, Common.DAY); - - List<ObservedDataControl> observedDataControlsValues = new LinkedList<>(); - Collections.addAll(observedDataControlsValues, ObservedDataControl.values()); - observedDataControlsValues.add(null); - I18nAbleParserFormatter<ObservedDataControl> valueParserFormatter = new I18nAbleParserFormatter<>(locale, observedDataControlsValues); - valueParserFormatter.setAcceptNullValues(true); - modelBuilder.newColumnForImportExport("CONTACT_DONNEES_ALLEGRO_VALIDEES", Contact.PROPERTY_OBSERVED_DATA_CONTROL, valueParserFormatter); - - return modelBuilder; - } - - @Override - public Iterable<ExportableColumn<Contact, Object>> getColumnsForExport() { - return (Iterable) getModel().getColumnsForExport(); - } - - @Override - public Iterable<ImportableColumn<Contact, Object>> getColumnsForImport() { - return (Iterable) getModel().getColumnsForImport(); - } - -} Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -35,11 +35,15 @@ import fr.ifremer.wao.entity.SampleMonthImpl; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRowImpl; +import fr.ifremer.wao.entity.SamplingStrategy; import fr.ifremer.wao.entity.TerrestrialLocation; import fr.ifremer.wao.services.service.administration.ReferentialService; import fr.ifremer.wao.services.service.csv.operations.CompanyParserFormatter; import fr.ifremer.wao.services.service.csv.operations.DCF5CodesParserFormatter; +import fr.ifremer.wao.services.service.csv.operations.DistrictNamesFormatter; +import fr.ifremer.wao.services.service.csv.operations.DistrictsParserFormatter; import fr.ifremer.wao.services.service.csv.operations.FishingZonesParserFormatter; +import fr.ifremer.wao.services.service.csv.operations.I18nAbleParserFormatter; import fr.ifremer.wao.services.service.csv.operations.SampleRowCodeParserFormatter; import org.nuiton.csv.Common; import org.nuiton.csv.ExportableColumn; @@ -224,14 +228,12 @@ } if (obsProgram == ObsProgram.OBSVENTE) { - throw new UnsupportedOperationException(); - // FIXME brendan 24/03/14 on ne peut plus utiliser ToStringParserFormatter -// modelBuilder.newColumnForImportExport("PLAN_STRATEGIE", "samplingStrategy", new Common.ToStringParserFormatter<>(SamplingStrategy.values())); -// modelBuilder.newColumnForImportExport("PLAN_LIEU_CODE", SampleRow.PROPERTY_TERRESTRIAL_LOCATIONS, new DistrictsParserFormatter(terrestrialDistricts)); -// modelBuilder.newColumnForExport("PLAN_LIEU_NOM", SampleRow.PROPERTY_TERRESTRIAL_LOCATIONS, new DistrictNamesFormatter()); -// modelBuilder.newIgnoredColumn("PLAN_LIEU_NOM"); -// modelBuilder.newColumnForImportExport("PLAN_LIEU_COMMENT", SampleRow.PROPERTY_TERRESTRIAL_LOCATION_INFOS); -// modelBuilder.newColumnForImportExport("PLAN_NOMBRE_OBSERVATIONS", SampleRow.PROPERTY_AVERAGE_OBSERVATIONS_COUNT, Common.PRIMITIVE_INTEGER); + modelBuilder.newColumnForImportExport("PLAN_STRATEGIE", "samplingStrategy", new I18nAbleParserFormatter<>(locale, SamplingStrategy.values())); + modelBuilder.newColumnForImportExport("PLAN_LIEU_CODE", SampleRow.PROPERTY_TERRESTRIAL_LOCATIONS, new DistrictsParserFormatter(locale, terrestrialDistricts)); + modelBuilder.newColumnForExport("PLAN_LIEU_NOM", SampleRow.PROPERTY_TERRESTRIAL_LOCATIONS, new DistrictNamesFormatter()); + modelBuilder.newIgnoredColumn("PLAN_LIEU_NOM"); + modelBuilder.newColumnForImportExport("PLAN_LIEU_COMMENT", SampleRow.PROPERTY_TERRESTRIAL_LOCATION_INFOS); + modelBuilder.newColumnForImportExport("PLAN_NOMBRE_OBSERVATIONS", SampleRow.PROPERTY_AVERAGE_OBSERVATIONS_COUNT, Common.PRIMITIVE_INTEGER); } if (log.isDebugEnabled()) { Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictsParserFormatter.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictsParserFormatter.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/DistrictsParserFormatter.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -40,18 +40,13 @@ protected final Locale locale; + protected List<TerrestrialLocation> districts; + protected Map<String, TerrestrialLocation> indexedDistricts; public DistrictsParserFormatter(Locale locale, List<TerrestrialLocation> districts) { this.locale = locale; - indexedDistricts = new HashMap<>(); - for (TerrestrialLocation district : districts) { - if ( ! district.isDistrict()) { - throw new IllegalArgumentException(); - } - indexedDistricts.put(district.getDistrictCode(), district); - } - // XXX brendan 28/02/14 on utilise pas Maps.uniqueIndex car la clé peut être null (quartier maritime « Hors France ») + this.districts = districts; } @Override @@ -68,6 +63,16 @@ @Override public Collection<TerrestrialLocation> parse(String value) throws ParseException { + if (indexedDistricts == null) { + indexedDistricts = new HashMap<>(); + for (TerrestrialLocation district : districts) { + // XXX brendan 28/02/14 on utilise pas Maps.uniqueIndex car la clé peut être null (quartier maritime « Hors France ») + if (!district.isDistrict()) { + throw new IllegalArgumentException(); + } + indexedDistricts.put(district.getDistrictCode(), district); + } + } if (StringUtils.isBlank(value)) { throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.districtMissing")); } Modified: trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties =================================================================== --- trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -34,12 +34,13 @@ wao.import.boat.failure.invalid.locationCode=The code '%s' is not a valid location code wao.import.boat.failure.missing.port=The port is required wao.import.contact.failure.boatMissing=You need to precise the plate number of the boat associated to the contact -wao.import.contact.failure.dataInputDateAfterObservationEndDate=La date de saisie des données doit être postérieure à la date de fin d'observation -wao.import.contact.failure.dataInputDateAfterToday= -wao.import.contact.failure.dataInputDateBeforeObservationEndDate= -wao.import.contact.failure.dataInputDateBeforeToday=La date de saisie des données doit être antérieur à la date du jour +wao.import.contact.failure.dataInputDateAfterObservationEndDate=Data input date must be after observation end date +wao.import.contact.failure.dataInputDateAfterToday=The data input date must not be in the future +wao.import.contact.failure.dataInputDateBeforeObservationEndDate=The data input date cannot be before observation end date +wao.import.contact.failure.dataInputDateBeforeToday=Data input date must be before today wao.import.contact.failure.districtMissing=You need to precise the boat district wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers=Main observer can not be also a secondary observer +wao.import.contact.failure.illegalAcceptation=Contact must be accepted by company before being accepted by program wao.import.contact.failure.invalidObservationBeginDate=La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne wao.import.contact.failure.locationTypeMissing=The type of the location must be filled wao.import.contact.failure.mismatchCompanyForObserver=L'observateur %s n'est pas membre de la société %s @@ -52,11 +53,12 @@ wao.import.contact.failure.missingHoursOfBeginEndObservation=You must provide accurate time for the beginning and the end of observation wao.import.contact.failure.missingMainObserver=Il faut au moins un observateur référant wao.import.contact.failure.missingObservationArea=Il faut préciser un lieu d'observation -wao.import.contact.failure.missingObservationBeginDate=La date de début de marée est obligatoire pour l'état '%s' -wao.import.contact.failure.missingObservationEndDate=La date de fin d'observation est obligatoire pour l'état '%s' +wao.import.contact.failure.missingObservationBeginDate=Observation begin date must be provided for state '%s' +wao.import.contact.failure.missingObservationEndDate=Observation end date must be provided for state '%s' wao.import.contact.failure.missingObservedDataControl=You must provide a value for observed data control -wao.import.contact.failure.missingObserver=Il ne peut y avoir aucun observateur pour l'état '%s' +wao.import.contact.failure.missingObserver=There can't be no observer for state '%s' wao.import.contact.failure.missingRestitution=You must provide the restitution forward date +wao.import.contact.failure.missingTerrestrialLocation=You must provide the terrestrial location wao.import.contact.failure.not.updatable=Insufficient credentials to update contact wao.import.contact.failure.observationEndDateAfterToday=La date de fin de la marée ne peut pas être postérieure à la date du jour wao.import.contact.failure.observationEndDateBeforeBeginDate=La date de fin d'observation ne peut pas être antérieure à celle du début @@ -91,6 +93,6 @@ wao.synthesis.planned=Planned wao.ui.chart.numberBoats=Number of boats wao.ui.chart.numberOfBoatsWithBoardings=Number of boats with x boardings -wao.ui.samplingPlan.Actual= +wao.ui.samplingPlan.Actual=Actual wao.validation.sampleRow.conflictOnObserver=Observer %s cannot be associated to the line %s because he has to observer, on the same day, for row %s wao.validation.sampleRow.observerNotInCompany=Observer %s doesn't work for company %s Modified: trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties =================================================================== --- trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -37,6 +37,7 @@ wao.import.contact.failure.dataInputDateBeforeObservationEndDate=La date de saisie des données doit être postérieure à la date de fin d'observation wao.import.contact.failure.districtMissing=Il faut préciser le code d'un quartier maritime wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers=L'utilisateur référant ne doit pas se trouver aussi parmi les observateurs secondaires +wao.import.contact.failure.illegalAcceptation=Le contact doit être accepté par la société avant d'être accepté par le programme wao.import.contact.failure.invalidObservationBeginDate=Ligne %s \: La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne wao.import.contact.failure.locationTypeMissing=Le type du lieu doit être renseigné wao.import.contact.failure.mismatchCompanyForObserver=Ligne %s \: L'observateur %s n'est pas membre de la société %s @@ -54,6 +55,7 @@ wao.import.contact.failure.missingObservedDataControl=Ligne %s \: Il faut préciser une valeur pour le contrôle des données observées wao.import.contact.failure.missingObserver=Ligne %s \: Il ne peut y avoir aucun observateur pour l'état '%s' wao.import.contact.failure.missingRestitution=Ligne %s \: Il faut préciser une date de transmission de la restitution de la donnée avant de valider +wao.import.contact.failure.missingTerrestrialLocation=Ligne %s \: Il faut préciser le lieu terrestre wao.import.contact.failure.not.updatable=Ligne %s \: Vous n'avez pas les droits suffisants pour modifier le contact wao.import.contact.failure.observationEndDateAfterToday=Ligne %s \: La date de fin de la marée doit être antérieure à la date du jour wao.import.contact.failure.observationEndDateBeforeBeginDate=Ligne %s \: La date de fin d'observation doit être postérieure à celle du début @@ -88,6 +90,6 @@ wao.synthesis.planned=Planifié wao.ui.chart.numberBoats=Nombre de navires wao.ui.chart.numberOfBoatsWithBoardings=Nombres de navires avec x embarquements -wao.ui.samplingPlan.Actual= +wao.ui.samplingPlan.Actual=Réalisé wao.validation.sampleRow.conflictOnObserver=L'observateur %s ne peut être associé à la ligne %s car il doit observer, le même jour, pour la ligne %s wao.validation.sampleRow.observerNotInCompany=L'observateur %s ne fait pas parti de la société %s Modified: trunk/wao-services/src/test/java/fr/ifremer/wao/services/FakeWaoApplicationContext.java =================================================================== --- trunk/wao-services/src/test/java/fr/ifremer/wao/services/FakeWaoApplicationContext.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/FakeWaoApplicationContext.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -11,9 +11,9 @@ import fr.ifremer.wao.services.service.BoatsFilterValues; import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; import fr.ifremer.wao.services.service.InitWaoService; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSynthesis; +import fr.ifremer.wao.services.service.SamplingPlan; import fr.ifremer.wao.services.service.SamplingPlanCacheKey; +import fr.ifremer.wao.services.service.Synthesis; import org.apache.commons.lang3.SystemUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -48,11 +48,11 @@ protected Date date = DateUtil.createDate(1, 11, 2009); - protected Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> samplingPlansCache; + protected Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache; protected Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> boatsFilterValuesCache; - protected Cache<ContactsFilter, ObsMerSynthesis> synthesisCache; + protected Cache<ContactsFilter, Synthesis> synthesisCache; public FakeWaoApplicationContext(String context, boolean initWithReferential) { this.context = context; @@ -162,6 +162,7 @@ hibernateH2Config.put(Environment.DIALECT, org.hibernate.dialect.H2Dialect.class.getName()); hibernateH2Config.put(Environment.USER, "sa"); hibernateH2Config.put(Environment.PASS, ""); + hibernateH2Config.remove("topia.service.migration"); File databaseFile = getDatabaseFile(context); @@ -245,7 +246,7 @@ } @Override - public Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> getSamplingPlansCache() { + public Cache<SamplingPlanCacheKey, SamplingPlan> getSamplingPlansCache() { if (samplingPlansCache == null) { samplingPlansCache = CacheBuilder.newBuilder().build(); } @@ -261,7 +262,7 @@ } @Override - public Cache<ContactsFilter, ObsMerSynthesis> getSynthesesCache() { + public Cache<ContactsFilter, Synthesis> getSynthesesCache() { if (synthesisCache == null) { synthesisCache = CacheBuilder.newBuilder().build(); } Copied: trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/BoatsServiceTest.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/test/java/fr/ifremer/wao/services/service/BoatsServiceTest.java) =================================================================== --- trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/BoatsServiceTest.java (rev 0) +++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/BoatsServiceTest.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,73 @@ +package fr.ifremer.wao.services.service; + +/* + * #%L + * Wao :: Services + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import fr.ifremer.wao.BoatsFilter; +import fr.ifremer.wao.services.AbstractWaoServiceTest; +import fr.ifremer.wao.services.ObsMerFixtures; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.util.pagination.PaginationParameter; + +/** + * Created on 4/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class BoatsServiceTest extends AbstractWaoServiceTest { + + protected BoatsService service; + + protected ObsMerFixtures fixtures; + + @Before + public void setUp() { + service = newService(BoatsService.class); + fixtures = new ObsMerFixtures(newServiceContext()); + } + + protected boolean isDatabaseWithReferential() { + return true; + } + + @Test + public void testGetBoatsFilterValues() { + + BoatsFilter filter = service.newBoatsFilter(fixtures.admin()); + + BoatsFilterValues boatsFilterValues = service.getBoatsFilterValues(fixtures.admin(), filter); + + } + + @Test + public void testGetBoatsList() { + + BoatsFilter filter = service.newBoatsFilter(fixtures.admin()); + + PaginationParameter pager = service.newBoatsPaginationParameter(0, 50); + + BoatsList boatsList = service.getBoatsList(fixtures.admin(), filter, pager); + + } + +} \ No newline at end of file Copied: trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java (from rev 2085, branches/wao-4.0-obsvente/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java) =================================================================== --- trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java (rev 0) +++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,101 @@ +package fr.ifremer.wao.services.service; + +/* + * #%L + * Wao :: Services + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import fr.ifremer.wao.ContactsFilter; +import fr.ifremer.wao.services.AbstractWaoServiceTest; +import fr.ifremer.wao.services.ObsMerFixtures; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.nuiton.util.DateUtil; +import org.nuiton.util.pagination.PaginationParameter; + +import java.io.InputStream; + +public class ContactsServiceTest extends AbstractWaoServiceTest { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ContactsServiceTest.class); + + protected ContactsService service; + + protected ObsMerFixtures fixtures; + + @Before + public void setUp() { + service = newService(ContactsService.class); + fixtures = new ObsMerFixtures(newServiceContext()); + } + + protected boolean isDatabaseWithReferential() { + return true; + } + + @Test + public void testGetContactsFilterValues() { + + ContactsFilter filter = service.newContactFilter(fixtures.admin()); + + ContactsFilterValues filterValues = service.getContactsFilterValues(fixtures.admin(), filter); + } + + @Test + public void testGetContactsList() { + + ContactsFilter filter = service.newContactFilter(fixtures.admin()); + + PaginationParameter pager = service.newContactsPaginationParameter(0, 50); + + ObsMerContactsList contactsList = service.getContactsList(fixtures.admin(), filter, pager); + } + + @Test + public void testImportContacts() { + fixtures.samplingPlan(); + fixtures.jmichmuche(); + fixtures.navires(); + + // today must be after the observation end date + applicationContext.setDate(DateUtil.createDate(1, 2, 2011)); + + InputStream input = null; + try { + + Assert.assertEquals(0, service.getContactDao().count()); + input = getClass().getResourceAsStream("/import/contacts.csv"); + service.importContacts(fixtures.admin(), input); + Assert.assertEquals(2, service.getContactDao().count()); + } catch (ImportErrorException e) { + if (log.isDebugEnabled()) { + log.debug("unexpected exception raised", e); + } + Assert.fail("exception should not be raised"); + } finally { + IOUtils.closeQuietly(input); + } + } + +} Deleted: trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerBoatsServiceTest.java =================================================================== --- trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerBoatsServiceTest.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerBoatsServiceTest.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,74 +0,0 @@ -package fr.ifremer.wao.services.service; - -/* - * #%L - * Wao :: Services - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import fr.ifremer.wao.BoatsFilter; -import fr.ifremer.wao.services.AbstractWaoServiceTest; -import fr.ifremer.wao.services.ObsMerFixtures; -import org.junit.Before; -import org.junit.Test; -import org.nuiton.topia.persistence.pager.TopiaPagerBean; -import org.nuiton.util.pagination.PaginationParameter; - -/** - * Created on 4/1/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class ObsMerBoatsServiceTest extends AbstractWaoServiceTest { - - protected ObsMerBoatsService service; - - protected ObsMerFixtures fixtures; - - @Before - public void setUp() { - service = newService(ObsMerBoatsService.class); - fixtures = new ObsMerFixtures(newServiceContext()); - } - - protected boolean isDatabaseWithReferential() { - return true; - } - - @Test - public void testGetBoatsFilterValues() { - - BoatsFilter filter = service.newBoatsFilter(fixtures.admin()); - - BoatsFilterValues boatsFilterValues = service.getBoatsFilterValues(fixtures.admin(), filter); - - } - - @Test - public void testGetBoatsList() { - - BoatsFilter filter = service.newBoatsFilter(fixtures.admin()); - - PaginationParameter pager = service.newBoatsPaginationParameter(0, 50); - - ObsMerBoatsList boatsList = service.getBoatsList(fixtures.admin(), filter, pager); - - } - -} \ No newline at end of file Deleted: trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerContactsServiceTest.java =================================================================== --- trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerContactsServiceTest.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerContactsServiceTest.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,101 +0,0 @@ -package fr.ifremer.wao.services.service; - -/* - * #%L - * Wao :: Services - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import fr.ifremer.wao.ContactsFilter; -import fr.ifremer.wao.services.AbstractWaoServiceTest; -import fr.ifremer.wao.services.ObsMerFixtures; -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.nuiton.util.DateUtil; -import org.nuiton.util.pagination.PaginationParameter; - -import java.io.InputStream; - -public class ObsMerContactsServiceTest extends AbstractWaoServiceTest { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ObsMerContactsServiceTest.class); - - protected ObsMerContactsService service; - - protected ObsMerFixtures fixtures; - - @Before - public void setUp() { - service = newService(ObsMerContactsService.class); - fixtures = new ObsMerFixtures(newServiceContext()); - } - - protected boolean isDatabaseWithReferential() { - return true; - } - - @Test - public void testGetContactsFilterValues() { - - ContactsFilter filter = service.newContactFilter(fixtures.admin()); - - ContactsFilterValues filterValues = service.getContactsFilterValues(fixtures.admin(), filter); - } - - @Test - public void testGetContactsList() { - - ContactsFilter filter = service.newContactFilter(fixtures.admin()); - - PaginationParameter pager = service.newContactsPaginationParameter(0, 50); - - ObsMerContactsList contactsList = service.getContactsList(fixtures.admin(), filter, pager); - } - - @Test - public void testImportContacts() { - fixtures.samplingPlan(); - fixtures.jmichmuche(); - fixtures.navires(); - - // today must be after the observation end date - applicationContext.setDate(DateUtil.createDate(1, 2, 2011)); - - InputStream input = null; - try { - - Assert.assertEquals(0, service.getContactDao().count()); - input = getClass().getResourceAsStream("/import/contacts.csv"); - service.importContacts(fixtures.admin(), input); - Assert.assertEquals(2, service.getContactDao().count()); - } catch (ImportErrorException e) { - if (log.isDebugEnabled()) { - log.debug("unexpected exception raised", e); - } - Assert.fail("exception should not be raised"); - } finally { - IOUtils.closeQuietly(input); - } - } - -} Modified: trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java =================================================================== --- trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -42,9 +42,7 @@ import java.util.HashMap; import java.util.Map; -import static fr.ifremer.wao.services.service.ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart; import static fr.ifremer.wao.services.service.ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart; -import static fr.ifremer.wao.services.service.ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart; public class ObsMerSamplingPlanServiceTest extends AbstractWaoServiceTest { @@ -113,8 +111,8 @@ protected void assertSamplePlanRowsNumber(int expectedRowsSize, ObsMerSamplingPlan samplingPlan) { int actualRowsSize = 0; - for (ObsMerSamplingPlanFacadePart facade : samplingPlan) { - for (ObsMerSamplingPlanSectorPart sectors : facade) { + for (SamplingPlan.SamplingPlanFacadePart facade : samplingPlan) { + for (SamplingPlan.SamplingPlanSectorPart<ObsMerSamplingPlanSampleRowPart> sectors : facade) { for (ObsMerSamplingPlanSampleRowPart row : sectors) { actualRowsSize++; @@ -171,10 +169,10 @@ SampleRow sampleRow = serviceContext.getPersistenceContext().getSampleRowDao().forCodeEquals("2010_M0011").findUnique(); - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> oldStats = new HashMap<>(); + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> oldStats = new HashMap<>(); for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { - ObsMerSamplingPlan.ObsMerSamplingPlanStatistics stats = new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics( + ObsMerSamplingPlan.SamplingPlanStatistics stats = new ObsMerSamplingPlan.SamplingPlanStatistics( sampleMonth.getExpectedTidesValue(), sampleMonth.getRealTidesValue(), sampleMonth.getEstimatedTidesValue() @@ -185,7 +183,7 @@ for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { - ObsMerSamplingPlan.ObsMerSamplingPlanStatistics oldMonth = oldStats.get(sampleMonth.getPeriodDate()); + ObsMerSamplingPlan.SamplingPlanStatistics oldMonth = oldStats.get(sampleMonth.getPeriodDate()); int expectedTidesValue = sampleMonth.getExpectedTidesValue(); int realTidesValue = sampleMonth.getRealTidesValue(); int estimatedTidesValue = sampleMonth.getEstimatedTidesValue(); Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/CacheInvalidationTopiaEntityListener.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/CacheInvalidationTopiaEntityListener.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/CacheInvalidationTopiaEntityListener.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -8,9 +8,9 @@ import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.services.service.BoatsFilterValues; import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSynthesis; +import fr.ifremer.wao.services.service.SamplingPlan; import fr.ifremer.wao.services.service.SamplingPlanCacheKey; +import fr.ifremer.wao.services.service.Synthesis; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -32,11 +32,11 @@ private static final Log log = LogFactory.getLog(CacheInvalidationTopiaEntityListener.class); - protected Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> samplingPlansCache; + protected Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache; protected Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> boatsFilterValuesCache; - protected Cache<ContactsFilter, ObsMerSynthesis> synthesesCache; + protected Cache<ContactsFilter, Synthesis> synthesesCache; protected Set<String> dirtySampleRowIds = new HashSet<>(); @@ -51,9 +51,9 @@ protected boolean invalidateAllContacts = false; public CacheInvalidationTopiaEntityListener( - Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> samplingPlansCache, + Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache, Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> boatsFilterValuesCache, - Cache<ContactsFilter, ObsMerSynthesis> synthesesCache) { + Cache<ContactsFilter, Synthesis> synthesesCache) { this.samplingPlansCache = samplingPlansCache; this.boatsFilterValuesCache = boatsFilterValuesCache; this.synthesesCache = synthesesCache; @@ -123,14 +123,14 @@ synthesesCache.invalidateAll(); } else { Set<SamplingPlanCacheKey> samplingPlansCacheKeysToInvalidate = new HashSet<>(); - for (Map.Entry<SamplingPlanCacheKey, ObsMerSamplingPlan> entry : samplingPlansCache.asMap().entrySet()) { + for (Map.Entry<SamplingPlanCacheKey, SamplingPlan> entry : samplingPlansCache.asMap().entrySet()) { if (CollectionUtils.containsAny(entry.getValue().getSampleRowIds(), dirtySampleRowIds)) { samplingPlansCacheKeysToInvalidate.add(entry.getKey()); } } samplingPlansCache.invalidateAll(samplingPlansCacheKeysToInvalidate); Set<ContactsFilter> synthesesCacheKeysToInvalidate = new HashSet<>(); - for (Map.Entry<ContactsFilter, ObsMerSynthesis> entry : synthesesCache.asMap().entrySet()) { + for (Map.Entry<ContactsFilter, Synthesis> entry : synthesesCache.asMap().entrySet()) { if (CollectionUtils.containsAny(entry.getValue().getSampleRowIds(), dirtySampleRowIds)) { synthesesCacheKeysToInvalidate.add(entry.getKey()); } Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/DefaultWaoApplicationContext.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/DefaultWaoApplicationContext.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/DefaultWaoApplicationContext.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -36,7 +36,8 @@ import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; import fr.ifremer.wao.services.service.InitWaoService; import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSynthesis; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.services.service.Synthesis; import fr.ifremer.wao.services.service.SamplingPlanCacheKey; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -67,11 +68,11 @@ protected Random random; - protected Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> samplingPlansCache; + protected Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache; protected Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> boatsFilterValuesCache; - protected Cache<ContactsFilter, ObsMerSynthesis> synthesesCache; + protected Cache<ContactsFilter, Synthesis> synthesesCache; @Override public WaoApplicationConfig getApplicationConfig() { @@ -116,7 +117,7 @@ } @Override - public Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> getSamplingPlansCache() { + public Cache<SamplingPlanCacheKey, SamplingPlan> getSamplingPlansCache() { if (samplingPlansCache == null) { samplingPlansCache = newCacheBuilder(100).expireAfterAccess(30, TimeUnit.DAYS).build(); } @@ -132,7 +133,7 @@ } @Override - public Cache<ContactsFilter, ObsMerSynthesis> getSynthesesCache() { + public Cache<ContactsFilter, Synthesis> getSynthesesCache() { if (synthesesCache == null) { synthesesCache = newCacheBuilder(100).expireAfterAccess(30, TimeUnit.DAYS).build(); } Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/WaoInterceptor.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/WaoInterceptor.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/WaoInterceptor.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -88,7 +88,7 @@ admin.getCompany().getTopiaId(); UserProfile userProfile = new UserProfileImpl(); userProfile.setUserRole(UserRole.ADMIN); - userProfile.setObsProgram(ObsProgram.OBSMER); + userProfile.setObsProgram(ObsProgram.OBSVENTE); userProfile.setCanWrite(true); AuthenticatedWaoUser authenticatedWaoUser = new AuthenticatedWaoUser(admin, userProfile); waoSession.setAuthenticatedWaoUser(authenticatedWaoUser); Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/WaoJspActionSupport.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/WaoJspActionSupport.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/WaoJspActionSupport.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -24,7 +24,7 @@ import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.entity.ObsProgram; import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.web.action.obsmer.SamplingPlanAction; +import fr.ifremer.wao.web.action.AbstractSamplingPlanAction; import org.apache.commons.lang3.time.DateUtils; import org.nuiton.util.pagination.PaginationResult; @@ -70,7 +70,7 @@ public String getText(String aTextName, String defaultValue) { String text = super.getText(aTextName, defaultValue); if ("invalid.fieldvalue.filter.periodFrom".equals(aTextName)) { - if (this instanceof SamplingPlanAction) { + if (this instanceof AbstractSamplingPlanAction) { text = getText("wao.ui.invalidMonthFormat"); } else { text = getText("wao.ui.invalidDateFormat"); Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractDownloadCsvAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractDownloadCsvAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractDownloadCsvAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -40,7 +40,7 @@ private static final long serialVersionUID = 1L; - protected SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-dd-MM_HH-mm"); + protected SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm"); public abstract String getFileName(); Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractSamplingPlanAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractSamplingPlanAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractSamplingPlanAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractSamplingPlanAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,131 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Objects; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.services.service.SampleRowsFilterValues; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.commons.lang3.time.DateUtils; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public abstract class AbstractSamplingPlanAction extends WaoJspActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService samplingPlanService; + + public void setSamplingPlanService(SamplingPlanService samplingPlanService) { + this.samplingPlanService = samplingPlanService; + } + + protected SampleRowsFilter filter; + + protected SamplingPlan samplingPlan; + + public SampleRowsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + @Override + public void prepare() { + + if (filter == null) { + filter = samplingPlanService.newSampleRowsFilter(getAuthenticatedWaoUser()); + } + + } + + @Override + public String execute() { + + filter = Objects.firstNonNull(session.getSampleRowsFilter(), filter); + + return applyFilter(); + + } + + public String resetFilter() { + + filter = samplingPlanService.newSampleRowsFilter(getAuthenticatedWaoUser()); + + return applyFilter(); + + } + + public String applyFilter() { + + getSession().setSampleRowsFilter(filter); + + samplingPlan = samplingPlan(); + + return SUCCESS; + + } + + protected abstract SamplingPlan samplingPlan(); + + public SamplingPlan getSamplingPlan() { + return samplingPlan; + } + + public String getSampleRowToHighlightId() { + return getSession().getSampleRowToHighlightId(); + } + + public SampleRowsFilterValues getFilterValues() { + SampleRowsFilterValues filterValues = getSamplingPlan().getFilterValues(); + return filterValues; + } + + public boolean isFullView() { + boolean fullView = getAuthenticatedWaoUser().isAdmin() || getAuthenticatedWaoUser().isProfessional(); + return fullView; + } + + protected SimpleDateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); + + public boolean isCurrentMonth(Date month) { + + String currentStr = dateFormat.format(getNow()); + String monthStr = dateFormat.format(month); + return currentStr.equals(monthStr); + } + + public String getFilterPeriodFromPlaceholder() { + String placeholder = formatMonth(DateUtils.addMonths(getNow(), 1)); + return placeholder; + } + + public String getFilterPeriodToPlaceholder() { + String placeholder = formatMonth(DateUtils.addYears(getNow(), 1)); + return placeholder; + } +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatDetailsAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatDetailsAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatDetailsAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatDetailsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,98 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.services.service.BoatDetails; +import fr.ifremer.wao.services.service.BoatsService; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.web.WaoJspActionSupport; + +import java.util.List; + +public class BoatDetailsAction extends WaoJspActionSupport { + + private static final long serialVersionUID = 1L; + + protected transient BoatsService service; + + protected transient SamplingPlanService samplingPlanService; + + protected String companyId; + + protected String boatId; + + protected BoatDetails boatDetails; + + protected SampleRow startBoatSelectionForSampleRow; + + private List<SampleRow> sampleRowsToSetElligible; + + public void setService(BoatsService service) { + this.service = service; + } + + public void setSamplingPlanService(SamplingPlanService samplingPlanService) { + this.samplingPlanService = samplingPlanService; + } + + public void setCompanyId(String companyId) { + this.companyId = companyId; + } + + public void setBoatId(String boatId) { + this.boatId = boatId; + } + + @Override + public String execute() { + + Preconditions.checkState(getAuthenticatedWaoUser().isAuthorizedToViewBoatDetails(companyId)); + + boatDetails = service.getBoatDetails(getObsProgram(), boatId, companyId); + + String startBoatSelectionForSampleRowId = session.getStartBoatSelectionForSampleRowId(); + + if (startBoatSelectionForSampleRowId != null) { + startBoatSelectionForSampleRow = samplingPlanService.getSampleRow(startBoatSelectionForSampleRowId); + } + + // TODO brendan 14/04/14 really useful ? + sampleRowsToSetElligible = samplingPlanService.getUnfinishedSampleRows(getAuthenticatedWaoUser(), companyId); + + return SUCCESS; + + } + + public BoatDetails getBoatDetails() { + return boatDetails; + } + + public SampleRow getStartBoatSelectionForSampleRow() { + return startBoatSelectionForSampleRow; + } + + public List<SampleRow> getSampleRowsToSetElligible() { + return sampleRowsToSetElligible; + } +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,192 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Objects; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.BoatsFilter; +import fr.ifremer.wao.entity.Boat; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.services.service.BoatsFilterValues; +import fr.ifremer.wao.services.service.BoatsList; +import fr.ifremer.wao.services.service.BoatsService; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.services.service.administration.CompaniesService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.util.pagination.PaginationParameter; +import org.nuiton.util.pagination.PaginationResult; + +import java.util.List; + +/** + * Created on 4/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class BoatsAction extends WaoJspActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + private static final Log log = LogFactory.getLog(BoatsAction.class); + + protected transient BoatsService service; + + protected transient CompaniesService companiesService; + + protected transient SamplingPlanService samplingPlanService; + + protected int pageNumber; // 1-based page number + + protected long firstRangePage; + + protected long lastRangePage; + + /** + * Boats filter. + */ + protected BoatsFilter filter; + + /** + * List of boats according to the input pager and filter. + */ + protected BoatsList boatList; + + protected String startBoatSelectionForSampleRowId; + + protected SampleRow startBoatSelectionForSampleRow; + + public void setService(BoatsService service) { + this.service = service; + } + + public BoatsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + public List<Boat> getBoats() { + return boatList.getBoats().getElements(); + } + + public BoatsFilterValues getFilterValues() { + return boatList.getFilterValues(); + } + + public PaginationResult<Boat> getPagination() { + return boatList.getBoats(); + } + + public void setStartBoatSelectionForSampleRowId(String startBoatSelectionForSampleRowId) { + this.startBoatSelectionForSampleRowId = startBoatSelectionForSampleRowId; + } + + public void setSamplingPlanService(SamplingPlanService samplingPlanService) { + this.samplingPlanService = samplingPlanService; + } + + public void setCompaniesService(CompaniesService companiesService) { + this.companiesService = companiesService; + } + + public void setPageNumber(int pageNumber) { + this.pageNumber = pageNumber; + } + + @Override + public void prepare() { + + if (filter == null) { + filter = service.newBoatsFilter(getAuthenticatedWaoUser()); + } + + if (StringUtils.isNotBlank(startBoatSelectionForSampleRowId)) { + + session.setStartBoatSelectionForSampleRowId(startBoatSelectionForSampleRowId); + + if (log.isInfoEnabled()) { + log.info("user " + getAuthenticatedWaoUser().getWaoUser() + " is starting to select a boat for sample row " + startBoatSelectionForSampleRow); + } + + } + + if (session.getStartBoatSelectionForSampleRowId() != null) { + + startBoatSelectionForSampleRow = samplingPlanService.getSampleRow(session.getStartBoatSelectionForSampleRowId()); + + } + + } + + @Override + public String execute() { + + filter = Objects.firstNonNull(session.getBoatsFilter(), filter); + + return applyFilter(); + + } + + public String resetFilter() { + + filter = service.newBoatsFilter(getAuthenticatedWaoUser()); + + return applyFilter(); + + } + + public String applyFilter() { + + getSession().setBoatsFilter(filter); + + PaginationParameter pager = service.newBoatsPaginationParameter(pageNumber, 25); + boatList = service.getBoatsList(getAuthenticatedWaoUser(), filter, pager); + + firstRangePage = getPaginationFirstPage(boatList.getBoats(), 10); + lastRangePage = getPaginationLastPage(boatList.getBoats(), 10, firstRangePage); + + return SUCCESS; + + } + + public SampleRow getStartBoatSelectionForSampleRow() { + return startBoatSelectionForSampleRow; + } + + public List<Company> getAllCompanies() { + return companiesService.getAllCompanies(); + } + + public long getFirstRangePage() { + return firstRangePage; + } + + public long getLastRangePage() { + return lastRangePage; + } +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsFilterValuesJsonAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsFilterValuesJsonAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsFilterValuesJsonAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/BoatsFilterValuesJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,90 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.BoatsFilter; +import fr.ifremer.wao.services.service.BoatsFilterValues; +import fr.ifremer.wao.services.service.BoatsService; +import fr.ifremer.wao.web.WaoJsonActionSupport; +import org.apache.commons.lang3.StringUtils; + +/** + * Created on 4/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class BoatsFilterValuesJsonAction extends WaoJsonActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient BoatsService service; + + protected BoatsFilter filter; + + protected BoatsFilterValues filterValues; + + protected String filterValuesField; + + public void setService(BoatsService service) { + this.service = service; + } + + public void setFilterValuesField(String filterValuesField) { + this.filterValuesField = filterValuesField; + } + + public BoatsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + @Override + public void prepare() { + + filter = service.newBoatsFilter(session.getAuthenticatedWaoUser()); + } + + @Override + public String execute() { + + filterValues = service.getBoatsFilterValues(session.getAuthenticatedWaoUser(), filter); + + if (StringUtils.isNotBlank(filterValuesField)) { + + // le client ne demande qu'un seul champ, on peut éviter de retourner l'objet complet + + filterValues = filterValues.getCopyWithSingleProperty(filterValuesField); + + } + + return SUCCESS; + } + + public BoatsFilterValues getFilterValues() { + return filterValues; + } + +} \ No newline at end of file Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CancelBoatSelectionAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/CancelBoatSelectionAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CancelBoatSelectionAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CancelBoatSelectionAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,22 @@ +package fr.ifremer.wao.web.action; + +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + + +@Results({ + @Result(name="success", type="redirectAction", params = { "actionName", "boats" }) +}) +public class CancelBoatSelectionAction extends WaoJspActionSupport { + + @Override + public String execute() { + + session.setStartBoatSelectionForSampleRowId(null); + + return SUCCESS; + + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CommentSampleRowAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/CommentSampleRowAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CommentSampleRowAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CommentSampleRowAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,74 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.commons.lang3.StringUtils; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +@Results({ + @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) +}) +public class CommentSampleRowAction extends WaoJspActionSupport { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService service; + + protected String sampleRowId; + + protected String comment; + + public void setService(ObsMerSamplingPlanService service) { + this.service = service; + } + + public void setSampleRowId(String sampleRowId) { + this.sampleRowId = sampleRowId; + } + + public void setComment(String comment) { + this.comment = comment; + } + + @Override + public String execute() { + + Preconditions.checkState(getAuthenticatedWaoUser().isAuthorizedToCommentSampleRow()); + + if (StringUtils.isNotBlank(comment)) { + + service.commentSampleRow(getAuthenticatedWaoUser(), sampleRowId, comment); + + session.addMessage(t("wao.ui.form.addComment.success")); + + } + + return SUCCESS; + + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,249 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Objects; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.ContactsFilter; +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.ContactState; +import fr.ifremer.wao.entity.DCF5Code; +import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.services.service.ContactsFilterValues; +import fr.ifremer.wao.services.service.ContactsService; +import fr.ifremer.wao.services.service.ObsMerContactsList; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.commons.lang3.time.DateUtils; +import org.nuiton.util.pagination.PaginationParameter; +import org.nuiton.util.pagination.PaginationResult; + +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Created on 4/3/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class ContactsAction extends WaoJspActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient ContactsService service; + + protected int pageNumber; + + protected long firstRangePage; + + protected long lastRangePage; + + /** + * Contacts filter. + */ + protected ContactsFilter filter; + + /** + * List of contacts according to the input pager and filter. + */ + protected ObsMerContactsList contactsList; + + public void setService(ContactsService service) { + this.service = service; + } + + public void setPageNumber(int pageNumber) { + this.pageNumber = pageNumber; + } + + public long getFirstRangePage() { + return firstRangePage; + } + + public long getLastRangePage() { + return lastRangePage; + } + + public ContactsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + public List<Contact> getContacts() { + return contactsList.getContacts().getElements(); + } + + public ContactsFilterValues getFilterValues() { + return contactsList.getFilterValues(); + } + + public PaginationResult<Contact> getPagination() { + return contactsList.getContacts(); + } + + @Override + public void prepare() { + + if (filter == null) { + filter = service.newContactFilter(getAuthenticatedWaoUser()); + } + + } + + @Override + public String execute() { + + filter = Objects.firstNonNull(session.getContactsFilter(), filter); + + return applyFilter(); + + } + + public String resetFilter() { + + filter = service.newContactFilter(getAuthenticatedWaoUser()); + + return applyFilter(); + + } + + public String applyFilter() { + + getSession().setContactsFilter(filter); + + PaginationParameter pager = service.newContactsPaginationParameter(pageNumber, 25); + contactsList = service.getContactsList(getAuthenticatedWaoUser(), filter, pager); + + firstRangePage = getPaginationFirstPage(contactsList.getContacts(), 10); + lastRangePage = getPaginationLastPage(contactsList.getContacts(), 10, firstRangePage); + + return SUCCESS; + + } + + protected Date now = new Date(); + + public String getFilterPeriodFromPlaceholder() { + String placeholder = formatDate(DateUtils.addMonths(now, 1)); + return placeholder; + } + + public String getFilterPeriodToPlaceholder() { + String placeholder = formatDate(DateUtils.addYears(now, 1)); + return placeholder; + } + + public boolean isFullView() { + boolean fullView = getAuthenticatedWaoUser().isAdmin() || getAuthenticatedWaoUser().isProfessional(); + return fullView; + } + + public String getMammalsInfo(Contact contact) { + return escapeForToolTip(contact.getMammalsInfo()); + } + + public boolean isBoardingDone(Contact contact) { + return ContactState.OBSERVATION_DONE == contact.getContactState(); + } + + public String getDivision(SampleRow sampleRow) { + String result = ""; + for (FishingZone zone : sampleRow.getFishingZone()) { + result += zone.getDistrictCode() + " "; + } + return result; + } + + /** + * Devrait résoudre un problème que pose le composant ck/tooltip. + * <p/> + * Voir ANO#606 + */ + public static String escapeForToolTip(String str) { + String result = str.replaceAll("\r\n", "\n"); + result = result.replaceAll("\n", "<br />"); + result = result.replaceAll("'", "’"); + result = result.replaceAll("\"", """); + result = result.replaceAll("%", "%"); + return result; + } + + public String getContactToHighlightId() { + return session.getContactToHighlightId(); + } + + public Map<String, String> getDcf5CodesAndDescriptions(SampleRow sampleRow) { + Map<String, String> dcf5CodesAndDescriptions = new LinkedHashMap<>(); + for (DCF5Code dcf5Code : sampleRow.getdCF5Code()) { + String key = dcf5Code.getCode(); + String description = dcf5Code.getFishingGearCode() + " - " + WaoUtils.l(getLocale(), dcf5Code.getFishingGearDCF()); + if (dcf5Code.getTargetSpeciesCode() != null) { + description += " ; " + dcf5Code.getTargetSpeciesCode() + " - " + WaoUtils.l(getLocale(), dcf5Code.getTargetSpeciesDCF()); + } + dcf5CodesAndDescriptions.put(key, description); + } + return dcf5CodesAndDescriptions; + } + + public boolean isAcceptable(Contact contact) { + boolean acceptable; + if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { + acceptable = contact.isAcceptableByCompany(); + } else if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { + acceptable = contact.isAcceptableByProgram(); + } else { + throw new IllegalStateException(); + } + return acceptable; + } + + public boolean isRefusable(Contact contact) { + boolean refuseable; + if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { + refuseable = contact.isRefusableByCompany(); + } else if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { + refuseable = contact.isRefusableByProgram(); + } else { + throw new IllegalStateException(); + } + return refuseable; + } + + public boolean isUnacceptable(Contact contact) { + boolean unacceptable; + if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { + unacceptable = contact.isUnacceptableByCompany(); + } else if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { + unacceptable = contact.isUnacceptableByProgram(); + } else { + throw new IllegalStateException(); + } + return unacceptable; + } + +} \ No newline at end of file Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsFilterValuesJsonAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsFilterValuesJsonAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsFilterValuesJsonAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ContactsFilterValuesJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,76 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.ContactsFilter; +import fr.ifremer.wao.services.service.ContactsFilterValues; +import fr.ifremer.wao.services.service.ContactsService; +import fr.ifremer.wao.web.WaoJsonActionSupport; + +/** + * Created on 4/3/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class ContactsFilterValuesJsonAction extends WaoJsonActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient ContactsService service; + + protected ContactsFilter filter; + + protected ContactsFilterValues filterValues; + + public void setService(ContactsService service) { + this.service = service; + } + + public ContactsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + public ContactsFilterValues getFilterValues() { + return filterValues; + } + + @Override + public void prepare() { + + filter = service.newContactFilter(session.getAuthenticatedWaoUser()); + } + + @Override + public String execute() { + + filterValues = service.getContactsFilterValues(session.getAuthenticatedWaoUser(), filter); + + return SUCCESS; + + } + +} \ No newline at end of file Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CreateContactAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/CreateContactAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CreateContactAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/CreateContactAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,45 @@ +package fr.ifremer.wao.web.action; + +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.services.service.ContactsService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +@Results({ + @Result(name="success", type="redirectAction", params = { "actionName", "contacts" }) +}) +public class CreateContactAction extends WaoJspActionSupport { + + protected ContactsService service; + + protected String boatId; + + protected String sampleRowId; + + public void setService(ContactsService service) { + this.service = service; + } + + public void setBoatId(String boatId) { + this.boatId = boatId; + } + + public void setSampleRowId(String sampleRowId) { + this.sampleRowId = sampleRowId; + } + + @Override + public String execute() { + + Contact contact = service.createContact(getAuthenticatedWaoUser(), sampleRowId, boatId); + + session.setStartBoatSelectionForSampleRowId(null); + + session.setContactToHighlightId(contact.getTopiaId()); + + return SUCCESS; + + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteContactAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteContactAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteContactAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteContactAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,84 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.services.service.ContactsService; +import fr.ifremer.wao.services.service.IllegalDeletionException; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +/** + * Created on 4/3/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +@Results({ + @Result(name = "error", type = "redirectAction", params = {"actionName", "edit-contact!input", "contactId", "%{contactId}"}), + @Result(name = "success", type = "redirectAction", params = {"actionName", "contacts"}) + }) +public class DeleteContactAction extends WaoJspActionSupport { + + private static final long serialVersionUID = 1L; + + protected String contactId; + + protected transient ContactsService service; + + public void setService(ContactsService service) { + this.service = service; + } + + public void setContactId(String contactId) { + this.contactId = contactId; + } + + public String getContactId() { + return contactId; + } + + @Override + public String execute() { + + Contact contact = service.getContact(contactId); + String contactCode = contact.getMainObserver().getFullName(); + + String result; + try { + service.delete(contactId); + + session.addMessage(t("wao.ui.action.deleteContact.success", contactCode)); + + result = SUCCESS; + + } catch (IllegalDeletionException e) { + + session.addErrorMessages(t("wao.ui.action.deleteContact.failure", contactCode)); + session.addErrorMessages(e.getExplanation(getLocale())); + + result = ERROR; + } + return result; + } +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteSampleRowAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteSampleRowAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteSampleRowAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteSampleRowAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,77 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import fr.ifremer.wao.services.service.IllegalDeletionException; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +@Results({ + @Result(name="error", type="redirectAction", params = { "actionName", "edit-sample-row!input", "sampleRowId", "%{sampleRowId}" }), + @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) +}) +public class DeleteSampleRowAction extends WaoJspActionSupport { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService service; + + protected String sampleRowId; + + public void setService(SamplingPlanService service) { + this.service = service; + } + + public void setSampleRowId(String sampleRowId) { + this.sampleRowId = sampleRowId; + } + + @Override + public String execute() { + + String sampleRowCode = service.getSampleRow(sampleRowId).getCode(); + + try { + + service.deleteSampleRow(sampleRowId); + + session.addMessage(t("wao.ui.action.deleteSampleRow.success", sampleRowCode)); + + return SUCCESS; + + } catch (IllegalDeletionException e) { + + session.addErrorMessages(t("wao.ui.action.deleteSampleRow.failure", sampleRowCode)); + session.addErrorMessages(e.getExplanation(getLocale())); + + return ERROR; + + } + + } + + public String getSampleRowId() { + return sampleRowId; + } +} \ No newline at end of file Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,358 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Optional; +import com.google.common.base.Strings; +import com.google.common.collect.Sets; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.ContactState; +import fr.ifremer.wao.entity.ContactStateMotif; +import fr.ifremer.wao.entity.DataReliability; +import fr.ifremer.wao.entity.ObservedDataControl; +import fr.ifremer.wao.entity.SamplingStrategy; +import fr.ifremer.wao.entity.TerrestrialLocation; +import fr.ifremer.wao.entity.TerrestrialLocations; +import fr.ifremer.wao.entity.WaoUser; +import fr.ifremer.wao.entity.WaoUsers; +import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.service.ContactDataInputDateAfterTodayException; +import fr.ifremer.wao.services.service.ContactDataInputDateBeforeObservationEndDateException; +import fr.ifremer.wao.services.service.ContactNotUpdatableException; +import fr.ifremer.wao.services.service.ContactObservationEndDateAfterTodayException; +import fr.ifremer.wao.services.service.ContactObservationEndDateBeforeBeginDateException; +import fr.ifremer.wao.services.service.ContactRestitutionDateBeforeDataInputDateException; +import fr.ifremer.wao.services.service.ContactWithObservedDataControlToCorrectionAskedException; +import fr.ifremer.wao.services.service.ContactsService; +import fr.ifremer.wao.services.service.DuplicatedContactMainObserverInSecondaryObserversException; +import fr.ifremer.wao.services.service.IllegalAcceptationException; +import fr.ifremer.wao.services.service.InvalidContactObservationBeginDateException; +import fr.ifremer.wao.services.service.MismatchContactMainObserverCompanyException; +import fr.ifremer.wao.services.service.MismatchContactSecondaryObserverCompanyException; +import fr.ifremer.wao.services.service.MissingContactCommentAdminException; +import fr.ifremer.wao.services.service.MissingContactCommentException; +import fr.ifremer.wao.services.service.MissingContactDataInputDateException; +import fr.ifremer.wao.services.service.MissingContactDataReliabilityException; +import fr.ifremer.wao.services.service.MissingContactMainObserverException; +import fr.ifremer.wao.services.service.MissingContactMammalsInfoException; +import fr.ifremer.wao.services.service.MissingContactNbObservantsException; +import fr.ifremer.wao.services.service.MissingContactObservationBeginDateException; +import fr.ifremer.wao.services.service.MissingContactObservationEndDateException; +import fr.ifremer.wao.services.service.MissingContactObservedDataControlException; +import fr.ifremer.wao.services.service.MissingContactRestitutionException; +import fr.ifremer.wao.services.service.MissingContactStateMotifException; +import fr.ifremer.wao.services.service.MissingContactTerrestrialLocationException; +import fr.ifremer.wao.services.service.UnwantedContactContactStateMotifException; +import fr.ifremer.wao.services.service.UpdateContactCommand; +import fr.ifremer.wao.services.service.administration.ReferentialService; +import fr.ifremer.wao.services.service.administration.WaoUsersService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +import java.util.Date; +import java.util.EnumMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +/** + * Created on 4/6/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +@Results({@Result(name = "success", type = "redirectAction", params = {"actionName", "contacts"})}) +public class EditContactAction extends WaoJspActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + /** + * Id of contact to edit. + */ + protected Optional<String> optionalContactId = Optional.absent(); + + protected Map<String, String> observers; + + protected Map<String, String> terrestrialLocations; + + protected Map<ContactState, String> contactStates; + + protected Map<String, String> contactStateMotives; + + protected Map<ObservedDataControl, String> observedDataControls; + + protected Map<DataReliability, String> dataReliabilities; + + protected Map<SamplingStrategy, String> samplingStrategies; + + protected transient ContactsService service; + + protected transient WaoUsersService waoUsersService; + + protected transient ReferentialService referentialService; + + protected UpdateContactCommand updateContactCommand; + + public void setService(ContactsService service) { + this.service = service; + } + + public void setWaoUsersService(WaoUsersService waoUsersService) { + this.waoUsersService = waoUsersService; + } + + public void setReferentialService(ReferentialService referentialService) { + this.referentialService = referentialService; + } + + public void setContactId(String contactId) { + this.optionalContactId = Optional.fromNullable(Strings.emptyToNull(contactId)); + } + + public String getContactId() { + return optionalContactId.orNull(); + } + + public UpdateContactCommand getUpdateContactCommand() { + if (updateContactCommand == null) { + prepare(); + } + return updateContactCommand; + } + + public Map<String, String> getObservers() { + if (observers == null) { + prepare(); + } + return observers; + } + + public Map<ContactState, String> getContactStates() { + if (contactStates == null) { + prepare(); + } + return contactStates; + } + + public Map<String, String> getContactStateMotives() { + if (contactStateMotives == null) { + prepare(); + } + return contactStateMotives; + } + + public Map<ObservedDataControl, String> getObservedDataControls() { + if (observedDataControls == null) { + prepare(); + } + return observedDataControls; + } + + public Map<DataReliability, String> getDataReliabilities() { + if (dataReliabilities == null) { + prepare(); + } + return dataReliabilities; + } + + public Map<String, String> getTerrestrialLocations() { + if (terrestrialLocations == null) { + prepare(); + } + return terrestrialLocations; + } + + public Map<SamplingStrategy, String> getSamplingStrategies() { + if (samplingStrategies == null) { + prepare(); + } + return samplingStrategies; + } + + public String getDateTimePlaceholder() { + return formatDateTime(new Date()); + } + + public String getDatePlaceholder() { + return formatDate(new Date()); + } + + @Override + public void prepare() { + + updateContactCommand = service.newUpdateContactCommand(getAuthenticatedWaoUser(), optionalContactId); + + List<WaoUser> waoUsers = waoUsersService.getActiveWaoUsers(Optional.of(updateContactCommand.getContact().getSampleRow().getCompany().getTopiaId())); + Set<WaoUser> sortedWaoUsers = Sets.newTreeSet(WaoUsers.fullNameComparator()); + sortedWaoUsers.addAll(waoUsers); + observers = new LinkedHashMap<>(); + for (WaoUser waoUser : sortedWaoUsers) { + observers.put(waoUser.getTopiaId(), waoUser.getFullName()); + } + contactStates = new EnumMap<>(ContactState.class); + for (ContactState contactState : ContactState.getAllowedStates(getAuthenticatedWaoUser().getObsProgram())) { + contactStates.put(contactState, WaoUtils.l(getLocale(), contactState)); + } + + contactStateMotives = new TreeMap<>(); + for (ContactStateMotif contactStateMotif : referentialService.getAllContactStateMotifs(null)) { + contactStateMotives.put(contactStateMotif.getTopiaId(), contactStateMotif.getName()); + } + + observedDataControls = new EnumMap<>(ObservedDataControl.class); + for (ObservedDataControl observedDataControl : ObservedDataControl.values()) { + observedDataControls.put(observedDataControl, WaoUtils.l(getLocale(), observedDataControl)); + } + + dataReliabilities = new EnumMap<>(DataReliability.class); + for (DataReliability dataReliability : DataReliability.values()) { + dataReliabilities.put(dataReliability, WaoUtils.l(getLocale(), dataReliability)); + } + + samplingStrategies = new EnumMap<>(SamplingStrategy.class); + for (SamplingStrategy samplingStrategy : SamplingStrategy.values()) { + samplingStrategies.put(samplingStrategy, WaoUtils.l(getLocale(), samplingStrategy)); + } + + terrestrialLocations = new LinkedHashMap<>(); + List<TerrestrialLocation> terrestrialLocationInDistricts = referentialService.getTerrestrialLocationInDistricts(updateContactCommand.getContact().getSampleRow().getTerrestrialLocations()); + Set<TerrestrialLocation> sortedTerrestrialLocations = new TreeSet<>(TerrestrialLocations.nameComparator()); + sortedTerrestrialLocations.addAll(terrestrialLocationInDistricts); + for (TerrestrialLocation terrestrialLocation : sortedTerrestrialLocations) { + terrestrialLocations.put(terrestrialLocation.getTopiaId(), terrestrialLocation.getDescription()); + } + } + + @Override + public void validate() { + + service.preValidate(updateContactCommand); + + AuthenticatedWaoUser authenticatedWaoUser = session.getAuthenticatedWaoUser(); + + try { + service.validate(authenticatedWaoUser, updateContactCommand, true); + } catch (ContactNotUpdatableException e) { + session.addErrorMessages(t("wao.ui.contacts.validation.failure.not.updatable")); + + } catch (UnwantedContactContactStateMotifException e) { + addFieldError("updateContactCommand.contact.contactStateMotif", t("wao.ui.form.Contact.error.unwantedContactStateMotif")); + + } catch (MissingContactNbObservantsException e) { + String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); + addFieldError("updateContactCommand.contact.nbObservants", t("wao.ui.form.Contact.error.missingObserver", state)); + + } catch (MissingContactObservationEndDateException e) { + String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); + addFieldError("updateContactCommand.contact.observationEndDate", t("wao.ui.form.Contact.error.missingObservationEndDate", state)); + + } catch (ContactDataInputDateBeforeObservationEndDateException e) { + addFieldError("updateContactCommand.contact.dataInputDate", t("wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate")); + + } catch (InvalidContactObservationBeginDateException e) { + addFieldError("updateContactCommand.contact.observationBeginDate", t("wao.ui.form.Contact.error.invalidObservationBeginDate")); + + } catch (MissingContactRestitutionException e) { + addFieldError("updateContactCommand.contact.restitution", t("wao.ui.form.Contact.error.missingRestitution")); + + } catch (ContactDataInputDateAfterTodayException e) { + addFieldError("updateContactCommand.contact.dataInputDate", t("wao.ui.form.Contact.error.dataInputDateAfterToday")); + + } catch (MissingContactCommentException e) { + String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); + addFieldError("updateContactCommand.contact.comment", t("wao.ui.form.Contact.error.missingComment", state)); + + } catch (MismatchContactMainObserverCompanyException e) { + String companyName = e.getCompany().getName(); + String observerLogin = e.getObserver().getLogin(); + addFieldError("updateContactCommand.contact.mainObserver", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName)); + + } catch (ContactRestitutionDateBeforeDataInputDateException e) { + addFieldError("updateContactCommand.contact.restitution", t("wao.ui.form.Contact.error.transmissionDateBeforeDataInputDate")); + + } catch (ContactObservationEndDateBeforeBeginDateException e) { + addFieldError("updateContactCommand.contact.observationEndDate", t("wao.ui.form.Contact.error.observationEndDateBeforeBeginDate")); + + } catch (DuplicatedContactMainObserverInSecondaryObserversException e) { + addFieldError("updateContactCommand.contact.secondaryObservers", t("wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers")); + + } catch (MissingContactDataReliabilityException e) { + addFieldError("updateContactCommand.contact.dataReliability", t("wao.ui.form.Contact.error.missingDataReliability")); + + } catch (MismatchContactSecondaryObserverCompanyException e) { + String companyName = e.getCompany().getName(); + String observerLogin = e.getObserver().getLogin(); + addFieldError("updateContactCommand.contact.secondaryObservers", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName)); + + } catch (MissingContactObservedDataControlException e) { + addFieldError("updateContactCommand.contact.observedDataControl", t("wao.ui.form.Contact.error.missingObservedDataControl")); + + } catch (ContactWithObservedDataControlToCorrectionAskedException e) { + addFieldError("updateContactCommand.contact.observedDataControl", t("wao.ui.form.Contact.error.observedDataControlToCorrectionAsked")); + + } catch (MissingContactStateMotifException e) { + addFieldError("updateContactCommand.contact.contactStateMotif", t("wao.ui.form.Contact.error.missingContactStateMotif")); + + } catch (MissingContactDataInputDateException e) { + addFieldError("updateContactCommand.contact.dataInputDate", t("wao.ui.form.Contact.error.missingDataInputDate")); + + } catch (MissingContactMainObserverException e) { + addFieldError("updateContactCommand.contact.mainObserver", t("wao.ui.form.Contact.error.missingMainObserver")); + + } catch (MissingContactCommentAdminException e) { + String dataReliability = WaoUtils.l(getLocale(), e.getContact().getDataReliability()); + addFieldError("updateContactCommand.contact.commentAdmin", t("wao.ui.form.Contact.error.missingCommentAdmin", dataReliability)); + + } catch (ContactObservationEndDateAfterTodayException e) { + addFieldError("updateContactCommand.contact.observationEndDate", t("wao.ui.form.Contact.error.observationEndDateAfterToday")); + + } catch (MissingContactObservationBeginDateException e) { + String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); + addFieldError("updateContactCommand.contact.observationBeginDate", t("wao.ui.form.Contact.error.missingObservationBeginDate", state)); + + } catch (MissingContactMammalsInfoException e) { + addFieldError("updateContactCommand.contact.mammalsInfo", t("wao.ui.form.Contact.error.missingMammalsInfo")); + + } catch (MissingContactTerrestrialLocationException e) { + throw new UnsupportedOperationException(); + } catch (IllegalAcceptationException e) { + throw new IllegalStateException("should never occur", e); + } + } + + @Override + public String execute() throws Exception { + + service.save(updateContactCommand, false); + + session.addMessage(t("wao.ui.form.updateContactCommand.success")); + + session.setContactToHighlightId(updateContactCommand.getContact().getTopiaId()); + return SUCCESS; + } + +} \ No newline at end of file Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,158 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Joiner; +import com.google.common.base.Optional; +import com.google.common.base.Strings; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; +import fr.ifremer.wao.services.service.SampleRowCodeMustBeUniqueException; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.services.service.UpdateSampleRowCommand; +import fr.ifremer.wao.services.service.administration.UnknownBoatImmatriculationsException; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +import java.util.Map; + +@Results({ + @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) +}) +public class EditSampleRowAction extends WaoJspActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + private static final Log log = LogFactory.getLog(EditSampleRowAction.class); + + protected transient SamplingPlanService service; + + protected Optional<String> optionalSampleRowId = Optional.absent(); + + protected UpdateSampleRowCommand updateSampleRowCommand; + + public void setService(ObsMerSamplingPlanService service) { + this.service = service; + } + + public String getSampleRowId() { + return optionalSampleRowId.orNull(); + } + + public void setSampleRowId(String sampleRowId) { + this.optionalSampleRowId = Optional.fromNullable(Strings.emptyToNull(sampleRowId)); + } + + @Override + public void prepare() { + + updateSampleRowCommand = service.newUpdateSampleRowCommand(getAuthenticatedWaoUser(), optionalSampleRowId); + + } + + @Override + public void validate() { + + SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); + + try { + + service.preValidate(getAuthenticatedWaoUser(), updateSampleRowCommand); + + if (CollectionUtils.isEmpty(sampleRow.getdCF5Code())) { + addFieldError("updateSampleRowCommand.dcf5Codes", t("wao.ui.form.SampleRow.error.missingDcf5Codes")); + } + + } catch (UnknownBoatImmatriculationsException e) { + addFieldError("updateSampleRowCommand.elligibleBoatImmatriculations", t("wao.ui.unknownBoatImmatriculations", Joiner.on(", ").join(e.getImmatriculations()))); + } catch (SampleRowCodeMustBeUniqueException e) { + addFieldError("updateSampleRowCommand.code", t("wao.ui.form.SampleRow.error.codeMustBeUnique")); + } + + if (updateSampleRowCommand.isCreation()) { + if ( ! WaoUtils.getSampleRowCodePattern(sampleRow.getObsProgram()).matcher(sampleRow.getCode()).matches()) { + addFieldError("updateSampleRowCommand.code", t("wao.import.sampleRow.failure.wrongSampleRowCodeFormat", sampleRow.getCode())); + } + } else { + if (StringUtils.isBlank(updateSampleRowCommand.getSampleRowLog().getComment())) { + addFieldError("updateSampleRowCommand.sampleRowLog.comment", t("wao.ui.form.SampleRow.error.missingLogComment")); + } + } + + if (StringUtils.isBlank(sampleRow.getProgramName())) { + addFieldError("updateSampleRowCommand.sampleRow.programName", t("wao.ui.form.SampleRow.error.missingProgramName")); + } + + if (sampleRow.getPeriodBegin() == null) { + addFieldError("updateSampleRowCommand.sampleRow.periodBegin", t("wao.ui.form.SampleRow.error.missingPeriodBegin")); + } + + if (sampleRow.getPeriodEnd() == null) { + addFieldError("updateSampleRowCommand.sampleRow.periodEnd", t("wao.ui.form.SampleRow.error.missingPeriodEnd")); + } + + if (CollectionUtils.isEmpty(sampleRow.getFishingZone())) { + addFieldError("updateSampleRowCommand.fishingZones", t("wao.ui.form.SampleRow.error.missingFishingZones")); + } + + if (sampleRow.getSamplingStrategy().isSpecificStock() && StringUtils.isEmpty(sampleRow.getProfession().getSpecies())) { + addFieldError("updateSampleRowCommand.sampleRow.samplingStrategy", t("wao.ui.form.SampleRow.error.missingProfessionSpecies")); + } + + } + + @Override + public String execute() { + + service.save(updateSampleRowCommand); + + session.addMessage(t("wao.ui.form.updateSampleRowCommand.success", updateSampleRowCommand.getSampleRow().getCode())); + + session.setSampleRowToHighlightId(updateSampleRowCommand.getSampleRow().getTopiaId()); + + return SUCCESS; + + } + + public UpdateSampleRowCommand getUpdateSampleRowCommand() { + if (updateSampleRowCommand == null) { + prepare(); + } + return updateSampleRowCommand; + } + + public Map<String, Integer> getExpectedObservationsByMonths() { + return getUpdateSampleRowCommand().getExpectedObservationsByMonths(); + } + + public void setExpectedObservationsByMonths(Map<String, Integer> expectedObservationsByMonths) { + getUpdateSampleRowCommand().setExpectedObservationsByMonths(expectedObservationsByMonths); + } + +} \ No newline at end of file Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportBoatsAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportBoatsAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportBoatsAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportBoatsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,77 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.BoatsFilter; +import fr.ifremer.wao.services.service.BoatsService; + +import java.io.InputStream; +import java.util.Date; + +/** + * Created on 4/1/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class ExportBoatsAction extends AbstractDownloadCsvAction implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient BoatsService service; + + protected BoatsFilter filter; + + public void setService(BoatsService service) { + this.service = service; + } + + public BoatsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + @Override + public void prepare() { + + filter = service.newBoatsFilter(getAuthenticatedWaoUser()); + + } + + @Override + public String getFileName() { + + return "boats_" + getObsProgram().name() + "_" + dateFormat.format(new Date()) + ".csv"; + + } + + @Override + public InputStream getInputStream() { + + return service.exportBoats(filter); + + } + +} \ No newline at end of file Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportContactsAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportContactsAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportContactsAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportContactsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,74 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.ContactsFilter; +import fr.ifremer.wao.services.service.ContactsService; + +import java.io.InputStream; +import java.util.Date; + +/** + * Created on 4/3/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class ExportContactsAction extends AbstractDownloadCsvAction implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient ContactsService service; + + protected ContactsFilter filter; + + public void setService(ContactsService service) { + this.service = service; + } + + public ContactsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + @Override + public void prepare() { + + filter = service.newContactFilter(getAuthenticatedWaoUser()); + } + + @Override + public String getFileName() { + + return "contacts_" + getObsProgram().name() + "_" + dateFormat.format(new Date()) + ".csv"; + } + + @Override + public InputStream getInputStream() { + + return service.exportContacts(filter); + } + +} \ No newline at end of file Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,71 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.services.service.SamplingPlanService; + +import java.io.InputStream; +import java.util.Date; + +public class ExportSamplingPlanAction extends AbstractDownloadCsvAction implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService service; + + protected SampleRowsFilter filter; + + public void setService(SamplingPlanService service) { + this.service = service; + } + + public SampleRowsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + @Override + public void prepare() { + + filter = service.newSampleRowsFilter(getAuthenticatedWaoUser()); + + } + + @Override + public String getFileName() { + + return "plan_" + getObsProgram().name() + "_" + dateFormat.format(new Date()) + ".csv"; + + } + + @Override + public InputStream getInputStream() { + + return service.exportSamplingPlan(filter); + + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,50 @@ +package fr.ifremer.wao.web.action; + +import fr.ifremer.wao.services.service.BoatContactsCounts; +import fr.ifremer.wao.services.service.BoatsService; +import fr.ifremer.wao.web.WaoJsonActionSupport; + +import java.util.Date; + +public class GetBoatContactsCountJsonAction extends WaoJsonActionSupport { + + protected Date since; + + protected BoatsService service; + + protected String boatId; + + protected String companyId; + + protected BoatContactsCounts boatContactsCounts; + + public void setSince(Date since) { + this.since = since; + } + + public void setService(BoatsService service) { + this.service = service; + } + + public void setBoatId(String boatId) { + this.boatId = boatId; + } + + public void setCompanyId(String companyId) { + this.companyId = companyId; + } + + @Override + public String execute() { + + boatContactsCounts = service.getBoatContactsCounts(session.getAuthenticatedWaoUser(), boatId, companyId, since); + + return SUCCESS; + + } + + public BoatContactsCounts getBoatContactsCounts() { + return boatContactsCounts; + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportContactsAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportContactsAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportContactsAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportContactsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,61 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import fr.ifremer.wao.services.service.ContactsService; +import fr.ifremer.wao.services.service.ImportErrorException; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +import java.io.InputStream; + +/** + * Created on 4/3/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +@Results({ + @Result(name = "error", type = "redirectAction", params = {"actionName", "import-contacts!input"}), + @Result(name = "success", type = "redirectAction", params = {"actionName", "contacts"}) + }) +public class ImportContactsAction extends AbstractImportCsvAction { + + private static final long serialVersionUID = 1L; + + protected transient ContactsService contactsService; + + public void setContactsService(ContactsService contactsService) { + this.contactsService = contactsService; + } + + @Override + protected void importCsv(InputStream csvInputStream) throws ImportErrorException { + contactsService.importContacts(getAuthenticatedWaoUser(), csvInputStream); + } + + @Override + protected String getSuccessMessage() { + return t("wao.ui.import.contacts.success"); + } + +} \ No newline at end of file Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportSamplingPlanAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportSamplingPlanAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportSamplingPlanAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportSamplingPlanAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,55 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import fr.ifremer.wao.services.service.ImportErrorException; +import fr.ifremer.wao.services.service.SamplingPlanService; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +import java.io.InputStream; + +@Results({ + @Result(name="error", type="redirectAction", params = { "actionName", "import-sampling-plan!input" }) , + @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) +}) +public class ImportSamplingPlanAction extends AbstractImportCsvAction { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService samplingPlanService; + + public void setService(SamplingPlanService samplingPlanService) { + this.samplingPlanService = samplingPlanService; + } + + @Override + protected void importCsv(InputStream csvInputStream) throws ImportErrorException { + samplingPlanService.importSamplingPlan(getAuthenticatedWaoUser(), csvInputStream); + } + + @Override + protected String getSuccessMessage() { + return t("wao.ui.import.samplingPlan.success"); + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowLogAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowLogAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowLogAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowLogAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,62 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.web.WaoJspActionSupport; + +public class SampleRowLogAction extends WaoJspActionSupport { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService service; + + protected String sampleRowId; + + protected SampleRow sampleRow; + + public void setService(SamplingPlanService service) { + this.service = service; + } + + public void setSampleRowId(String sampleRowId) { + this.sampleRowId = sampleRowId; + } + + @Override + public String execute() { + + sampleRow = service.getSampleRow(sampleRowId); + + return SUCCESS; + } + + public SampleRow getSampleRow() { + return sampleRow; + } + + public String getSampleRowId() { + return sampleRowId; + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowsFilterValuesJsonAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowsFilterValuesJsonAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowsFilterValuesJsonAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowsFilterValuesJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,105 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; +import fr.ifremer.wao.services.service.ObsVenteSamplingPlanService; +import fr.ifremer.wao.services.service.SampleRowsFilterValues; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.web.WaoJsonActionSupport; +import org.apache.commons.lang3.StringUtils; + +public class SampleRowsFilterValuesJsonAction extends WaoJsonActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient ObsMerSamplingPlanService obsMerSamplingPlanService; + + protected transient ObsVenteSamplingPlanService obsVenteSamplingPlanService; + + protected SampleRowsFilter filter; + + protected SampleRowsFilterValues filterValues; + + protected String filterValuesField; + + public void setObsMerSamplingPlanService(ObsMerSamplingPlanService obsMerSamplingPlanService) { + this.obsMerSamplingPlanService = obsMerSamplingPlanService; + } + + public void setObsVenteSamplingPlanService(ObsVenteSamplingPlanService obsVenteSamplingPlanService) { + this.obsVenteSamplingPlanService = obsVenteSamplingPlanService; + } + + public SampleRowsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + public void setFilterValuesField(String filterValuesField) { + this.filterValuesField = filterValuesField; + } + + @Override + public void prepare() { + + filter = obsMerSamplingPlanService.newSampleRowsFilter(session.getAuthenticatedWaoUser()); + + } + + @Override + public String execute() { + + SamplingPlan samplingPlan; + if (filter.getObsProgram().isObsMer()) { + samplingPlan = obsMerSamplingPlanService.getSamplingPlan(session.getAuthenticatedWaoUser(), filter); + } else if (filter.getObsProgram().isObsVente()) { + samplingPlan = obsVenteSamplingPlanService.getSamplingPlan(session.getAuthenticatedWaoUser(), filter); + } else { + throw new UnsupportedOperationException(); + } + filterValues = samplingPlan.getFilterValues(); + + if (StringUtils.isNotBlank(filterValuesField)) { + + // le client ne demande qu'un seul champ, on peut éviter de retourner l'objet complet + + filterValues = filterValues.getCopyWithSingleProperty(filterValuesField); + + } + + return SUCCESS; + } + + public String getFilterValuesField() { + return filterValuesField; + } + + public SampleRowsFilterValues getFilterValues() { + return filterValues; + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SynthesisAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SynthesisAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SynthesisAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/SynthesisAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,67 @@ +package fr.ifremer.wao.web.action; + +import com.google.common.base.Objects; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.ContactsFilter; +import fr.ifremer.wao.services.service.Synthesis; +import fr.ifremer.wao.services.service.SynthesisService; +import fr.ifremer.wao.web.WaoJspActionSupport; + +public class SynthesisAction extends WaoJspActionSupport implements Preparable { + + protected ContactsFilter filter; + + protected SynthesisService service; + + protected Synthesis synthesis; + + public void setService(SynthesisService service) { + this.service = service; + } + + public ContactsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + @Override + public void prepare() { + + if (filter == null) { + filter = service.newFilter(getAuthenticatedWaoUser()); + } + + } + + @Override + public String execute() { + + filter = Objects.firstNonNull(session.getSynthesisFilter(), filter); + + return applyFilter(); + + } + + public String resetFilter() { + + filter = service.newFilter(getAuthenticatedWaoUser()); + + return applyFilter(); + + } + + public String applyFilter() { + + getSession().setSynthesisFilter(filter); + + synthesis = service.getObsMerSynthesis(filter); + + return SUCCESS; + } + + public Synthesis getSynthesis() { + return synthesis; + } +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatElligibilityJsonAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatElligibilityJsonAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatElligibilityJsonAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatElligibilityJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,39 @@ +package fr.ifremer.wao.web.action; + +import fr.ifremer.wao.services.service.BoatsService; +import fr.ifremer.wao.web.WaoJsonActionSupport; + +public class UpdateBoatElligibilityJsonAction extends WaoJsonActionSupport { + + protected BoatsService service; + + protected String boatId; + + protected String sampleRowId; + + protected boolean active; + + public void setService(BoatsService service) { + this.service = service; + } + + public void setActive(boolean active) { + this.active = active; + } + + public void setBoatId(String boatId) { + this.boatId = boatId; + } + + public void setSampleRowId(String sampleRowId) { + this.sampleRowId = sampleRowId; + } + + @Override + public String execute() { + + service.changeBoatElligibility(session.getAuthenticatedWaoUser(), boatId, sampleRowId, active); + + return SUCCESS; + } +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatInfosJsonAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatInfosJsonAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatInfosJsonAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/UpdateBoatInfosJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,59 @@ +package fr.ifremer.wao.web.action; + +import com.google.common.base.Preconditions; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.entity.BoatInfos; +import fr.ifremer.wao.services.service.BoatsService; +import fr.ifremer.wao.web.WaoJsonActionSupport; + +public class UpdateBoatInfosJsonAction extends WaoJsonActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient BoatsService service; + + protected String companyId; + + protected String boatId; + + protected BoatInfos boatInfos; + + public void setService(BoatsService service) { + this.service = service; + } + + public void setCompanyId(String companyId) { + this.companyId = companyId; + } + + public void setBoatId(String boatId) { + this.boatId = boatId; + } + + @Override + public void prepare() { + + Preconditions.checkState(session.getAuthenticatedWaoUser().isAuthorizedToViewBoatDetails(companyId)); + + boatInfos = service.getBoatInfos(boatId, companyId); + + } + + public BoatInfos getBoatInfos() { + return boatInfos; + } + + public void setBoatInfos(BoatInfos boatInfos) { + this.boatInfos = boatInfos; + } + + @Override + public String execute() { + + service.saveBoatInfos(boatInfos); + + return SUCCESS; + + } + +} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,310 @@ +package fr.ifremer.wao.web.action; + +/* + * #%L + * Wao :: Web + * %% + * Copyright (C) 2009 - 2014 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% + */ + +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.WaoTechnicalException; +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.service.ContactDataInputDateBeforeObservationEndDateException; +import fr.ifremer.wao.services.service.ContactDataInputDateAfterTodayException; +import fr.ifremer.wao.services.service.ContactNotUpdatableException; +import fr.ifremer.wao.services.service.ContactObservationEndDateAfterTodayException; +import fr.ifremer.wao.services.service.ContactObservationEndDateBeforeBeginDateException; +import fr.ifremer.wao.services.service.ContactRestitutionDateBeforeDataInputDateException; +import fr.ifremer.wao.services.service.ContactWithObservedDataControlToCorrectionAskedException; +import fr.ifremer.wao.services.service.ContactsService; +import fr.ifremer.wao.services.service.DuplicatedContactMainObserverInSecondaryObserversException; +import fr.ifremer.wao.services.service.IllegalAcceptationException; +import fr.ifremer.wao.services.service.InvalidContactObservationBeginDateException; +import fr.ifremer.wao.services.service.MismatchContactMainObserverCompanyException; +import fr.ifremer.wao.services.service.MismatchContactSecondaryObserverCompanyException; +import fr.ifremer.wao.services.service.MissingContactCommentAdminException; +import fr.ifremer.wao.services.service.MissingContactCommentException; +import fr.ifremer.wao.services.service.MissingContactDataInputDateException; +import fr.ifremer.wao.services.service.MissingContactDataReliabilityException; +import fr.ifremer.wao.services.service.MissingContactMainObserverException; +import fr.ifremer.wao.services.service.MissingContactMammalsInfoException; +import fr.ifremer.wao.services.service.MissingContactNbObservantsException; +import fr.ifremer.wao.services.service.MissingContactObservationBeginDateException; +import fr.ifremer.wao.services.service.MissingContactObservationEndDateException; +import fr.ifremer.wao.services.service.MissingContactObservedDataControlException; +import fr.ifremer.wao.services.service.MissingContactRestitutionException; +import fr.ifremer.wao.services.service.MissingContactStateMotifException; +import fr.ifremer.wao.services.service.MissingContactTerrestrialLocationException; +import fr.ifremer.wao.services.service.UnwantedContactContactStateMotifException; +import fr.ifremer.wao.services.service.UpdateContactCommand; +import fr.ifremer.wao.web.WaoJsonActionSupport; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Created on 4/3/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class ValidateContactJsonAction extends WaoJsonActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + /** Logger. */ + private static final Log log = LogFactory.getLog(ValidateContactJsonAction.class); + + /** + * Id of contact to treat. + */ + protected String contactId; + + /** + * New validation state. + */ + protected Boolean validationState; + + /** + * Success message + */ + protected String successMessage; + + /** + * Error message if validation, or any was wrong while update. + */ + protected String errorMessage; + + protected transient ContactsService service; + + protected UpdateContactCommand updateContactCommand; + + public void setService(ContactsService service) { + this.service = service; + } + + public void setContactId(String contactId) { + this.contactId = contactId; + } + + public void setValidationState(Boolean validationState) { + this.validationState = validationState; + } + + public String getContactId() { + return contactId; + } + + public Boolean getValidationState() { + return validationState; + } + + public String getSuccessMessage() { + return successMessage; + } + + public String getErrorMessage() { + return errorMessage; + } + + public boolean isSuccessful() { + return errorMessage == null; + } + + @Override + public void prepare() { + + Preconditions.checkState(StringUtils.isNotEmpty(contactId)); + + AuthenticatedWaoUser authenticatedWaoUser = session.getAuthenticatedWaoUser(); + + updateContactCommand = service.newUpdateContactCommand( + session.getAuthenticatedWaoUser(), + Optional.of(contactId)); + + if (authenticatedWaoUser.isAdmin()) { + updateContactCommand.setValidationProgram(validationState); + } else { + updateContactCommand.setValidationCompany(validationState); + } + } + + @Override + public String execute() { + + AuthenticatedWaoUser authenticatedWaoUser = session.getAuthenticatedWaoUser(); + + try { + service.validate(authenticatedWaoUser, updateContactCommand, true); + } catch (ContactNotUpdatableException e) { + session.addErrorMessages(t("wao.ui.contacts.validation.failure.not.updatable")); + + } catch (UnwantedContactContactStateMotifException e) { + errorMessage = t("wao.ui.form.Contact.error.unwantedContactStateMotif"); + + } catch (MissingContactNbObservantsException e) { + String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); + errorMessage = t("wao.ui.form.Contact.error.missingObserver", state); + + } catch (MissingContactObservationEndDateException e) { + String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); + errorMessage = t("wao.ui.form.Contact.error.missingObservationEndDate", state); + + } catch (ContactDataInputDateBeforeObservationEndDateException e) { + errorMessage = t("wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate"); + + } catch (InvalidContactObservationBeginDateException e) { + errorMessage = t("wao.ui.form.Contact.error.invalidObservationBeginDate"); + + } catch (MissingContactRestitutionException e) { + errorMessage = t("wao.ui.form.Contact.error.missingRestitution"); + + } catch (ContactDataInputDateAfterTodayException e) { + errorMessage = t("wao.ui.form.Contact.error.dataInputDateAfterToday"); + + } catch (MissingContactCommentException e) { + String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); + errorMessage = t("wao.ui.form.Contact.error.missingComment", state); + + } catch (MismatchContactMainObserverCompanyException e) { + String companyName = e.getCompany().getName(); + String observerLogin = e.getObserver().getLogin(); + errorMessage = t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName); + + } catch (ContactRestitutionDateBeforeDataInputDateException e) { + errorMessage = t("wao.ui.form.Contact.error.transmissionDateBeforeDataInputDate"); + + } catch (ContactObservationEndDateBeforeBeginDateException e) { + errorMessage = t("wao.ui.form.Contact.error.observationEndDateBeforeBeginDate"); + + } catch (DuplicatedContactMainObserverInSecondaryObserversException e) { + errorMessage = t("wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers"); + + } catch (MissingContactDataReliabilityException e) { + errorMessage = t("wao.ui.form.Contact.error.missingDataReliability"); + + } catch (MismatchContactSecondaryObserverCompanyException e) { + String companyName = e.getCompany().getName(); + String observerLogin = e.getObserver().getLogin(); + errorMessage = t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName); + + } catch (MissingContactObservedDataControlException e) { + errorMessage = t("wao.ui.form.Contact.error.missingObservedDataControl"); + + } catch (ContactWithObservedDataControlToCorrectionAskedException e) { + errorMessage = t("wao.ui.form.Contact.error.observedDataControlToCorrectionAsked"); + + } catch (MissingContactStateMotifException e) { + errorMessage = t("wao.ui.form.Contact.error.missingContactStateMotif"); + + } catch (MissingContactDataInputDateException e) { + errorMessage = t("wao.ui.form.Contact.error.missingDataInputDate"); + + } catch (MissingContactMainObserverException e) { + errorMessage = t("wao.ui.form.Contact.error.missingMainObserver"); + + } catch (MissingContactCommentAdminException e) { + String dataReliability = WaoUtils.l(getLocale(), e.getContact().getDataReliability()); + errorMessage = t("wao.ui.form.Contact.error.missingCommentAdmin", dataReliability); + + } catch (ContactObservationEndDateAfterTodayException e) { + errorMessage = t("wao.ui.form.Contact.error.observationEndDateAfterToday"); + + } catch (MissingContactObservationBeginDateException e) { + String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); + errorMessage = t("wao.ui.form.Contact.error.missingObservationBeginDate", state); + + } catch (MissingContactTerrestrialLocationException e) { + errorMessage = t("wao.ui.form.Contact.error.missingContactTerrestrialLocation"); + + } catch (MissingContactMammalsInfoException e) { + errorMessage = t("wao.ui.form.Contact.error.missingContactMammalsInfo"); + + } catch (IllegalAcceptationException e) { + errorMessage = t("wao.ui.form.Contact.error.illegalAcceptationException"); + + } + + if (isSuccessful()) { + + try { + service.save(updateContactCommand, true); + } catch (ContactNotUpdatableException e) { + throw new WaoTechnicalException("should never occur", e); + } + if (validationState == null) { + successMessage = t("wao.ui.contacts.validation.to.unvalidate.state.success"); + } else if (validationState) { + successMessage = t("wao.ui.contacts.validation.to.accept.state.success"); + } else { + successMessage = t("wao.ui.contacts.validation.to.reject.state.success"); + } + } + + return SUCCESS; + } + + public boolean isAcceptable(Contact contact) { + boolean acceptable; + if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { + acceptable = contact.isAcceptableByCompany(); + } else if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { + acceptable = contact.isAcceptableByProgram(); + } else { + throw new IllegalStateException(); + } + return acceptable; + } + + public boolean isRefusable(Contact contact) { + boolean refuseable; + if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { + refuseable = contact.isRefusableByCompany(); + } else if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { + refuseable = contact.isRefusableByProgram(); + } else { + throw new IllegalStateException(); + } + return refuseable; + } + + public boolean isUnacceptable(Contact contact) { + boolean unacceptable; + if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { + unacceptable = contact.isUnacceptableByCompany(); + } else if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { + unacceptable = contact.isUnacceptableByProgram(); + } else { + throw new IllegalStateException(); + } + return unacceptable; + } + + public Boolean getValidationProgram() { + return updateContactCommand.getContact().getValidationProgram(); + } + + public Boolean getValidationCompany() { + return updateContactCommand.getContact().getValidationCompany(); + } + +} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatDetailsAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatDetailsAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatDetailsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,98 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Preconditions; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.services.service.BoatDetails; -import fr.ifremer.wao.services.service.ObsMerBoatsService; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.WaoJspActionSupport; - -import java.util.List; - -public class BoatDetailsAction extends WaoJspActionSupport { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerBoatsService service; - - protected transient ObsMerSamplingPlanService obsMerSamplingPlanService; - - protected String companyId; - - protected String boatId; - - protected BoatDetails boatDetails; - - protected SampleRow startBoatSelectionForSampleRow; - - private List<SampleRow> sampleRowsToSetElligible; - - public void setService(ObsMerBoatsService service) { - this.service = service; - } - - public void setObsMerSamplingPlanService(ObsMerSamplingPlanService obsMerSamplingPlanService) { - this.obsMerSamplingPlanService = obsMerSamplingPlanService; - } - - public void setCompanyId(String companyId) { - this.companyId = companyId; - } - - public void setBoatId(String boatId) { - this.boatId = boatId; - } - - @Override - public String execute() { - - Preconditions.checkState(getAuthenticatedWaoUser().isAuthorizedToViewBoatDetails(companyId)); - - boatDetails = service.getBoatDetails(getObsProgram(), boatId, companyId); - - String startBoatSelectionForSampleRowId = session.getStartBoatSelectionForSampleRowId(); - - if (startBoatSelectionForSampleRowId != null) { - startBoatSelectionForSampleRow = obsMerSamplingPlanService.getSampleRow(startBoatSelectionForSampleRowId); - } - - // TODO brendan 14/04/14 really useful ? - sampleRowsToSetElligible = obsMerSamplingPlanService.getUnfinishedSampleRows(getAuthenticatedWaoUser(), companyId); - - return SUCCESS; - - } - - public BoatDetails getBoatDetails() { - return boatDetails; - } - - public SampleRow getStartBoatSelectionForSampleRow() { - return startBoatSelectionForSampleRow; - } - - public List<SampleRow> getSampleRowsToSetElligible() { - return sampleRowsToSetElligible; - } -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatsAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatsAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,192 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Objects; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.BoatsFilter; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.services.service.BoatsFilterValues; -import fr.ifremer.wao.services.service.ObsMerBoatsList; -import fr.ifremer.wao.services.service.ObsMerBoatsService; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.services.service.administration.CompaniesService; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.util.pagination.PaginationParameter; -import org.nuiton.util.pagination.PaginationResult; - -import java.util.List; - -/** - * Created on 4/1/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class BoatsAction extends WaoJspActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - private static final Log log = LogFactory.getLog(BoatsAction.class); - - protected transient ObsMerBoatsService service; - - protected transient CompaniesService companiesService; - - protected transient ObsMerSamplingPlanService obsMerSamplingPlanService; - - protected int pageNumber; // 1-based page number - - protected long firstRangePage; - - protected long lastRangePage; - - /** - * Boats filter. - */ - protected BoatsFilter filter; - - /** - * List of boats according to the input pager and filter. - */ - protected ObsMerBoatsList boatList; - - protected String startBoatSelectionForSampleRowId; - - protected SampleRow startBoatSelectionForSampleRow; - - public void setService(ObsMerBoatsService service) { - this.service = service; - } - - public BoatsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - public List<Boat> getBoats() { - return boatList.getBoats().getElements(); - } - - public BoatsFilterValues getFilterValues() { - return boatList.getFilterValues(); - } - - public PaginationResult<Boat> getPagination() { - return boatList.getBoats(); - } - - public void setStartBoatSelectionForSampleRowId(String startBoatSelectionForSampleRowId) { - this.startBoatSelectionForSampleRowId = startBoatSelectionForSampleRowId; - } - - public void setObsMerSamplingPlanService(ObsMerSamplingPlanService obsMerSamplingPlanService) { - this.obsMerSamplingPlanService = obsMerSamplingPlanService; - } - - public void setCompaniesService(CompaniesService companiesService) { - this.companiesService = companiesService; - } - - public void setPageNumber(int pageNumber) { - this.pageNumber = pageNumber; - } - - @Override - public void prepare() { - - if (filter == null) { - filter = service.newBoatsFilter(getAuthenticatedWaoUser()); - } - - if (StringUtils.isNotBlank(startBoatSelectionForSampleRowId)) { - - session.setStartBoatSelectionForSampleRowId(startBoatSelectionForSampleRowId); - - if (log.isInfoEnabled()) { - log.info("user " + getAuthenticatedWaoUser().getWaoUser() + " is starting to select a boat for sample row " + startBoatSelectionForSampleRow); - } - - } - - if (session.getStartBoatSelectionForSampleRowId() != null) { - - startBoatSelectionForSampleRow = obsMerSamplingPlanService.getSampleRow(session.getStartBoatSelectionForSampleRowId()); - - } - - } - - @Override - public String execute() { - - filter = Objects.firstNonNull(session.getBoatsFilter(), filter); - - return applyFilter(); - - } - - public String resetFilter() { - - filter = service.newBoatsFilter(getAuthenticatedWaoUser()); - - return applyFilter(); - - } - - public String applyFilter() { - - getSession().setBoatsFilter(filter); - - PaginationParameter pager = service.newBoatsPaginationParameter(pageNumber, 25); - boatList = service.getBoatsList(getAuthenticatedWaoUser(), filter, pager); - - firstRangePage = getPaginationFirstPage(boatList.getBoats(), 10); - lastRangePage = getPaginationLastPage(boatList.getBoats(), 10, firstRangePage); - - return SUCCESS; - - } - - public SampleRow getStartBoatSelectionForSampleRow() { - return startBoatSelectionForSampleRow; - } - - public List<Company> getAllCompanies() { - return companiesService.getAllCompanies(); - } - - public long getFirstRangePage() { - return firstRangePage; - } - - public long getLastRangePage() { - return lastRangePage; - } -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatsFilterValuesJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatsFilterValuesJsonAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/BoatsFilterValuesJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,90 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.BoatsFilter; -import fr.ifremer.wao.services.service.BoatsFilterValues; -import fr.ifremer.wao.services.service.ObsMerBoatsService; -import fr.ifremer.wao.web.WaoJsonActionSupport; -import org.apache.commons.lang3.StringUtils; - -/** - * Created on 4/1/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class BoatsFilterValuesJsonAction extends WaoJsonActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerBoatsService service; - - protected BoatsFilter filter; - - protected BoatsFilterValues filterValues; - - protected String filterValuesField; - - public void setService(ObsMerBoatsService service) { - this.service = service; - } - - public void setFilterValuesField(String filterValuesField) { - this.filterValuesField = filterValuesField; - } - - public BoatsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - @Override - public void prepare() { - - filter = service.newBoatsFilter(session.getAuthenticatedWaoUser()); - } - - @Override - public String execute() { - - filterValues = service.getBoatsFilterValues(session.getAuthenticatedWaoUser(), filter); - - if (StringUtils.isNotBlank(filterValuesField)) { - - // le client ne demande qu'un seul champ, on peut éviter de retourner l'objet complet - - filterValues = filterValues.getCopyWithSingleProperty(filterValuesField); - - } - - return SUCCESS; - } - - public BoatsFilterValues getFilterValues() { - return filterValues; - } - -} \ No newline at end of file Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CancelBoatSelectionAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CancelBoatSelectionAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CancelBoatSelectionAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,22 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - - -@Results({ - @Result(name="success", type="redirectAction", params = { "actionName", "boats" }) -}) -public class CancelBoatSelectionAction extends WaoJspActionSupport { - - @Override - public String execute() { - - session.setStartBoatSelectionForSampleRowId(null); - - return SUCCESS; - - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CommentSampleRowAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CommentSampleRowAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CommentSampleRowAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,73 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Preconditions; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.commons.lang3.StringUtils; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -@Results({ - @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) -}) -public class CommentSampleRowAction extends WaoJspActionSupport { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected String sampleRowId; - - protected String comment; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public void setSampleRowId(String sampleRowId) { - this.sampleRowId = sampleRowId; - } - - public void setComment(String comment) { - this.comment = comment; - } - - @Override - public String execute() { - - Preconditions.checkState(getAuthenticatedWaoUser().isAuthorizedToCommentSampleRow()); - - if (StringUtils.isNotBlank(comment)) { - - service.commentSampleRow(getAuthenticatedWaoUser(), sampleRowId, comment); - - session.addMessage(t("wao.ui.form.addComment.success")); - - } - - return SUCCESS; - - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,249 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Objects; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.ContactsFilter; -import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.ContactState; -import fr.ifremer.wao.entity.DCF5Code; -import fr.ifremer.wao.entity.FishingZone; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.services.service.ContactsFilterValues; -import fr.ifremer.wao.services.service.ObsMerContactsList; -import fr.ifremer.wao.services.service.ObsMerContactsService; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.commons.lang3.time.DateUtils; -import org.nuiton.util.pagination.PaginationParameter; -import org.nuiton.util.pagination.PaginationResult; - -import java.util.Date; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * Created on 4/3/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class ContactsAction extends WaoJspActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerContactsService service; - - protected int pageNumber; - - protected long firstRangePage; - - protected long lastRangePage; - - /** - * Contacts filter. - */ - protected ContactsFilter filter; - - /** - * List of contacts according to the input pager and filter. - */ - protected ObsMerContactsList contactsList; - - public void setService(ObsMerContactsService service) { - this.service = service; - } - - public void setPageNumber(int pageNumber) { - this.pageNumber = pageNumber; - } - - public long getFirstRangePage() { - return firstRangePage; - } - - public long getLastRangePage() { - return lastRangePage; - } - - public ContactsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - public List<Contact> getContacts() { - return contactsList.getContacts().getElements(); - } - - public ContactsFilterValues getFilterValues() { - return contactsList.getFilterValues(); - } - - public PaginationResult<Contact> getPagination() { - return contactsList.getContacts(); - } - - @Override - public void prepare() { - - if (filter == null) { - filter = service.newContactFilter(getAuthenticatedWaoUser()); - } - - } - - @Override - public String execute() { - - filter = Objects.firstNonNull(session.getContactsFilter(), filter); - - return applyFilter(); - - } - - public String resetFilter() { - - filter = service.newContactFilter(getAuthenticatedWaoUser()); - - return applyFilter(); - - } - - public String applyFilter() { - - getSession().setContactsFilter(filter); - - PaginationParameter pager = service.newContactsPaginationParameter(pageNumber, 25); - contactsList = service.getContactsList(getAuthenticatedWaoUser(), filter, pager); - - firstRangePage = getPaginationFirstPage(contactsList.getContacts(), 10); - lastRangePage = getPaginationLastPage(contactsList.getContacts(), 10, firstRangePage); - - return SUCCESS; - - } - - protected Date now = new Date(); - - public String getFilterPeriodFromPlaceholder() { - String placeholder = formatDateTime(DateUtils.addMonths(now, 1)); - return placeholder; - } - - public String getFilterPeriodToPlaceholder() { - String placeholder = formatDateTime(DateUtils.addYears(now, 1)); - return placeholder; - } - - public boolean isFullView() { - boolean fullView = getAuthenticatedWaoUser().isAdmin() || getAuthenticatedWaoUser().isProfessional(); - return fullView; - } - - public String getMammalsInfo(Contact contact) { - return escapeForToolTip(contact.getMammalsInfo()); - } - - public boolean isBoardingDone(Contact contact) { - return ContactState.OBSERVATION_DONE == contact.getContactState(); - } - - public String getDivision(SampleRow sampleRow) { - String result = ""; - for (FishingZone zone : sampleRow.getFishingZone()) { - result += zone.getDistrictCode() + " "; - } - return result; - } - - /** - * Devrait résoudre un problème que pose le composant ck/tooltip. - * <p/> - * Voir ANO#606 - */ - public static String escapeForToolTip(String str) { - String result = str.replaceAll("\r\n", "\n"); - result = result.replaceAll("\n", "<br />"); - result = result.replaceAll("'", "’"); - result = result.replaceAll("\"", """); - result = result.replaceAll("%", "%"); - return result; - } - - public String getContactToHighlightId() { - return session.getContactToHighlightId(); - } - - public Map<String, String> getDcf5CodesAndDescriptions(SampleRow sampleRow) { - Map<String, String> dcf5CodesAndDescriptions = new LinkedHashMap<>(); - for (DCF5Code dcf5Code : sampleRow.getdCF5Code()) { - String key = dcf5Code.getCode(); - String description = dcf5Code.getFishingGearCode() + " - " + WaoUtils.l(getLocale(), dcf5Code.getFishingGearDCF()); - if (dcf5Code.getTargetSpeciesCode() != null) { - description += " ; " + dcf5Code.getTargetSpeciesCode() + " - " + WaoUtils.l(getLocale(), dcf5Code.getTargetSpeciesDCF()); - } - dcf5CodesAndDescriptions.put(key, description); - } - return dcf5CodesAndDescriptions; - } - - public boolean isAcceptable(Contact contact) { - boolean acceptable; - if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { - acceptable = contact.isAcceptableByCompany(); - } else if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { - acceptable = contact.isAcceptableByProgram(); - } else { - throw new IllegalStateException(); - } - return acceptable; - } - - public boolean isRefusable(Contact contact) { - boolean refuseable; - if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { - refuseable = contact.isRefusableByCompany(); - } else if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { - refuseable = contact.isRefusableByProgram(); - } else { - throw new IllegalStateException(); - } - return refuseable; - } - - public boolean isUnacceptable(Contact contact) { - boolean unacceptable; - if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { - unacceptable = contact.isUnacceptableByCompany(); - } else if (getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { - unacceptable = contact.isUnacceptableByProgram(); - } else { - throw new IllegalStateException(); - } - return unacceptable; - } - -} \ No newline at end of file Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsFilterValuesJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsFilterValuesJsonAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ContactsFilterValuesJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,77 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.ContactsFilter; -import fr.ifremer.wao.services.service.ContactsFilterValues; -import fr.ifremer.wao.services.service.ObsMerContactsService; -import fr.ifremer.wao.web.WaoJsonActionSupport; - -/** - * Created on 4/3/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class ContactsFilterValuesJsonAction extends WaoJsonActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerContactsService service; - - protected ContactsFilter filter; - - protected ContactsFilterValues filterValues; - - public void setService(ObsMerContactsService service) { - this.service = service; - } - - - public ContactsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - public ContactsFilterValues getFilterValues() { - return filterValues; - } - - @Override - public void prepare() { - - filter = service.newContactFilter(session.getAuthenticatedWaoUser()); - } - - @Override - public String execute() { - - filterValues = service.getContactsFilterValues(session.getAuthenticatedWaoUser(), filter); - - return SUCCESS; - - } - -} \ No newline at end of file Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CreateContactAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CreateContactAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CreateContactAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,45 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.services.service.ObsMerContactsService; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -@Results({ - @Result(name="success", type="redirectAction", params = { "actionName", "contacts" }) -}) -public class CreateContactAction extends WaoJspActionSupport { - - protected ObsMerContactsService service; - - protected String boatId; - - protected String sampleRowId; - - public void setService(ObsMerContactsService service) { - this.service = service; - } - - public void setBoatId(String boatId) { - this.boatId = boatId; - } - - public void setSampleRowId(String sampleRowId) { - this.sampleRowId = sampleRowId; - } - - @Override - public String execute() { - - Contact contact = service.createContact(getAuthenticatedWaoUser(), sampleRowId, boatId); - - session.setStartBoatSelectionForSampleRowId(null); - - session.setContactToHighlightId(contact.getTopiaId()); - - return SUCCESS; - - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteContactAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteContactAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteContactAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,84 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.services.service.IllegalDeletionException; -import fr.ifremer.wao.services.service.ObsMerContactsService; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -/** - * Created on 4/3/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -@Results({ - @Result(name = "error", type = "redirectAction", params = {"actionName", "edit-contact!input", "contactId", "%{contactId}"}), - @Result(name = "success", type = "redirectAction", params = {"actionName", "contacts"}) - }) -public class DeleteContactAction extends WaoJspActionSupport { - - private static final long serialVersionUID = 1L; - - protected String contactId; - - protected transient ObsMerContactsService service; - - public void setService(ObsMerContactsService service) { - this.service = service; - } - - public void setContactId(String contactId) { - this.contactId = contactId; - } - - public String getContactId() { - return contactId; - } - - @Override - public String execute() { - - Contact contact = service.getContact(contactId); - String contactCode = contact.getMainObserver().getFullName(); - - String result; - try { - service.delete(contactId); - - session.addMessage(t("wao.ui.action.deleteContact.success", contactCode)); - - result = SUCCESS; - - } catch (IllegalDeletionException e) { - - session.addErrorMessages(t("wao.ui.action.deleteContact.failure", contactCode)); - session.addErrorMessages(e.getExplanation(getLocale())); - - result = ERROR; - } - return result; - } -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteSampleRowAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteSampleRowAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteSampleRowAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,77 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import fr.ifremer.wao.services.service.IllegalDeletionException; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -@Results({ - @Result(name="error", type="redirectAction", params = { "actionName", "edit-sample-row!input", "sampleRowId", "%{sampleRowId}" }), - @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) -}) -public class DeleteSampleRowAction extends WaoJspActionSupport { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected String sampleRowId; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public void setSampleRowId(String sampleRowId) { - this.sampleRowId = sampleRowId; - } - - @Override - public String execute() { - - String sampleRowCode = service.getSampleRow(sampleRowId).getCode(); - - try { - - service.deleteSampleRow(sampleRowId); - - session.addMessage(t("wao.ui.action.deleteSampleRow.success", sampleRowCode)); - - return SUCCESS; - - } catch (IllegalDeletionException e) { - - session.addErrorMessages(t("wao.ui.action.deleteSampleRow.failure", sampleRowCode)); - session.addErrorMessages(e.getExplanation(getLocale())); - - return ERROR; - - } - - } - - public String getSampleRowId() { - return sampleRowId; - } -} \ No newline at end of file Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,317 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Optional; -import com.google.common.base.Strings; -import com.google.common.collect.Sets; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.ContactState; -import fr.ifremer.wao.entity.ContactStateMotif; -import fr.ifremer.wao.entity.DataReliability; -import fr.ifremer.wao.entity.ObservedDataControl; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.entity.WaoUsers; -import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.services.service.ContactDataInputDateAfterTodayException; -import fr.ifremer.wao.services.service.ContactDataInputDateBeforeObservationEndDateException; -import fr.ifremer.wao.services.service.ContactNotUpdatableException; -import fr.ifremer.wao.services.service.ContactObservationEndDateAfterTodayException; -import fr.ifremer.wao.services.service.ContactObservationEndDateBeforeBeginDateException; -import fr.ifremer.wao.services.service.ContactRestitutionDateBeforeDataInputDateException; -import fr.ifremer.wao.services.service.ContactWithObservedDataControlToCorrectionAskedException; -import fr.ifremer.wao.services.service.DuplicatedContactMainObserverInSecondaryObserversException; -import fr.ifremer.wao.services.service.InvalidContactObservationBeginDateException; -import fr.ifremer.wao.services.service.MismatchContactMainObserverCompanyException; -import fr.ifremer.wao.services.service.MismatchContactSecondaryObserverCompanyException; -import fr.ifremer.wao.services.service.MissingContactCommentAdminException; -import fr.ifremer.wao.services.service.MissingContactCommentException; -import fr.ifremer.wao.services.service.MissingContactDataInputDateException; -import fr.ifremer.wao.services.service.MissingContactDataReliabilityException; -import fr.ifremer.wao.services.service.MissingContactMainObserverException; -import fr.ifremer.wao.services.service.MissingContactMammalsInfoException; -import fr.ifremer.wao.services.service.MissingContactNbObservantsException; -import fr.ifremer.wao.services.service.MissingContactObservationBeginDateException; -import fr.ifremer.wao.services.service.MissingContactObservationEndDateException; -import fr.ifremer.wao.services.service.MissingContactObservedDataControlException; -import fr.ifremer.wao.services.service.MissingContactRestitutionException; -import fr.ifremer.wao.services.service.MissingContactStateMotifException; -import fr.ifremer.wao.services.service.ObsMerContactsService; -import fr.ifremer.wao.services.service.UnwantedContactContactStateMotifException; -import fr.ifremer.wao.services.service.UpdateContactCommand; -import fr.ifremer.wao.services.service.administration.ReferentialService; -import fr.ifremer.wao.services.service.administration.WaoUsersService; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -import java.util.Date; -import java.util.EnumMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - -/** - * Created on 4/6/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -@Results({@Result(name = "success", type = "redirectAction", params = {"actionName", "contacts"})}) -public class EditContactAction extends WaoJspActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - /** - * Id of contact to edit. - */ - protected Optional<String> optionalContactId = Optional.absent(); - - protected Map<String, String> observers; - - protected Map<ContactState, String> contactStates; - - protected Map<String, String> contactStateMotives; - - protected Map<ObservedDataControl, String> observedDataControls; - - protected Map<DataReliability, String> dataReliabilities; - - protected transient ObsMerContactsService service; - - protected transient WaoUsersService waoUsersService; - - protected transient ReferentialService referentialService; - - protected UpdateContactCommand updateContactCommand; - - public void setService(ObsMerContactsService service) { - this.service = service; - } - - public void setWaoUsersService(WaoUsersService waoUsersService) { - this.waoUsersService = waoUsersService; - } - - public void setReferentialService(ReferentialService referentialService) { - this.referentialService = referentialService; - } - - public void setContactId(String contactId) { - this.optionalContactId = Optional.fromNullable(Strings.emptyToNull(contactId)); - } - - public String getContactId() { - return optionalContactId.orNull(); - } - - public UpdateContactCommand getUpdateContactCommand() { - if (updateContactCommand == null) { - prepare(); - } - return updateContactCommand; - } - - public Map<String, String> getObservers() { - if (observers == null) { - prepare(); - } - return observers; - } - - public Map<ContactState, String> getContactStates() { - if (contactStates == null) { - prepare(); - } - return contactStates; - } - - public Map<String, String> getContactStateMotives() { - if (contactStateMotives == null) { - prepare(); - } - return contactStateMotives; - } - - public Map<ObservedDataControl, String> getObservedDataControls() { - if (observedDataControls == null) { - prepare(); - } - return observedDataControls; - } - - public Map<DataReliability, String> getDataReliabilities() { - if (dataReliabilities == null) { - prepare(); - } - return dataReliabilities; - } - - public String getDateTimePlaceholder() { - return formatDateTime(new Date()); - } - - public String getDatePlaceholder() { - return formatDate(new Date()); - } - - @Override - public void prepare() { - - updateContactCommand = service.newUpdateContactCommand(getAuthenticatedWaoUser(), optionalContactId); - - List<WaoUser> waoUsers = waoUsersService.getActiveWaoUsers(Optional.of(updateContactCommand.getContact().getSampleRow().getCompany().getTopiaId())); - Set<WaoUser> sortedWaoUsers = Sets.newTreeSet(WaoUsers.fullNameComparator()); - sortedWaoUsers.addAll(waoUsers); - observers = new LinkedHashMap<>(); - for (WaoUser waoUser : sortedWaoUsers) { - observers.put(waoUser.getTopiaId(), waoUser.getFullName()); - } - contactStates = new EnumMap<>(ContactState.class); - for (ContactState contactState : ContactState.getAllowedStates(getAuthenticatedWaoUser().getObsProgram())) { - contactStates.put(contactState, WaoUtils.l(getLocale(), contactState)); - } - - contactStateMotives = new TreeMap<>(); - for (ContactStateMotif contactStateMotif : referentialService.getAllContactStateMotifs(null)) { - contactStateMotives.put(contactStateMotif.getTopiaId(), contactStateMotif.getName()); - } - - observedDataControls = new EnumMap<>(ObservedDataControl.class); - for (ObservedDataControl observedDataControl : ObservedDataControl.values()) { - observedDataControls.put(observedDataControl, WaoUtils.l(getLocale(), observedDataControl)); - } - - dataReliabilities = new EnumMap<>(DataReliability.class); - for (DataReliability dataReliability : DataReliability.values()) { - dataReliabilities.put(dataReliability, WaoUtils.l(getLocale(), dataReliability)); - } - } - - @Override - public void validate() { - - service.preValidate(updateContactCommand); - - AuthenticatedWaoUser authenticatedWaoUser = session.getAuthenticatedWaoUser(); - - try { - service.validate(authenticatedWaoUser, updateContactCommand, true); - } catch (ContactNotUpdatableException e) { - session.addErrorMessages(t("wao.ui.contacts.validation.failure.not.updatable")); - - } catch (UnwantedContactContactStateMotifException e) { - addFieldError("updateContactCommand.contact.contactStateMotif", t("wao.ui.form.Contact.error.unwantedContactStateMotif")); - - } catch (MissingContactNbObservantsException e) { - String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - addFieldError("updateContactCommand.contact.nbObservants", t("wao.ui.form.Contact.error.missingObserver", state)); - - } catch (MissingContactObservationEndDateException e) { - String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - addFieldError("updateContactCommand.contact.observationEndDate", t("wao.ui.form.Contact.error.missingObservationEndDate", state)); - - } catch (ContactDataInputDateBeforeObservationEndDateException e) { - addFieldError("updateContactCommand.contact.dataInputDate", t("wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate")); - - } catch (InvalidContactObservationBeginDateException e) { - addFieldError("updateContactCommand.contact.observationBeginDate", t("wao.ui.form.Contact.error.invalidObservationBeginDate")); - - } catch (MissingContactRestitutionException e) { - addFieldError("updateContactCommand.contact.restitution", t("wao.ui.form.Contact.error.missingRestitution")); - - } catch (ContactDataInputDateAfterTodayException e) { - addFieldError("updateContactCommand.contact.dataInputDate", t("wao.ui.form.Contact.error.dataInputDateAfterToday")); - - } catch (MissingContactCommentException e) { - String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - addFieldError("updateContactCommand.contact.comment", t("wao.ui.form.Contact.error.missingComment", state)); - - } catch (MismatchContactMainObserverCompanyException e) { - String companyName = e.getCompany().getName(); - String observerLogin = e.getObserver().getLogin(); - addFieldError("updateContactCommand.contact.mainObserver", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName)); - - } catch (ContactRestitutionDateBeforeDataInputDateException e) { - addFieldError("updateContactCommand.contact.restitution", t("wao.ui.form.Contact.error.transmissionDateBeforeDataInputDate")); - - } catch (ContactObservationEndDateBeforeBeginDateException e) { - addFieldError("updateContactCommand.contact.observationEndDate", t("wao.ui.form.Contact.error.observationEndDateBeforeBeginDate")); - - } catch (DuplicatedContactMainObserverInSecondaryObserversException e) { - addFieldError("updateContactCommand.contact.secondaryObservers", t("wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers")); - - } catch (MissingContactDataReliabilityException e) { - addFieldError("updateContactCommand.contact.dataReliability", t("wao.ui.form.Contact.error.missingDataReliability")); - - } catch (MismatchContactSecondaryObserverCompanyException e) { - String companyName = e.getCompany().getName(); - String observerLogin = e.getObserver().getLogin(); - addFieldError("updateContactCommand.contact.secondaryObservers", t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName)); - - } catch (MissingContactObservedDataControlException e) { - addFieldError("updateContactCommand.contact.observedDataControl", t("wao.ui.form.Contact.error.missingObservedDataControl")); - - } catch (ContactWithObservedDataControlToCorrectionAskedException e) { - addFieldError("updateContactCommand.contact.observedDataControl", t("wao.ui.form.Contact.error.observedDataControlToCorrectionAsked")); - - } catch (MissingContactStateMotifException e) { - addFieldError("updateContactCommand.contact.contactStateMotif", t("wao.ui.form.Contact.error.missingContactStateMotif")); - - } catch (MissingContactDataInputDateException e) { - addFieldError("updateContactCommand.contact.dataInputDate", t("wao.ui.form.Contact.error.missingDataInputDate")); - - } catch (MissingContactMainObserverException e) { - addFieldError("updateContactCommand.contact.mainObserver", t("wao.ui.form.Contact.error.missingMainObserver")); - - } catch (MissingContactCommentAdminException e) { - String dataReliability = WaoUtils.l(getLocale(), e.getContact().getDataReliability()); - addFieldError("updateContactCommand.contact.commentAdmin", t("wao.ui.form.Contact.error.missingCommentAdmin", dataReliability)); - - } catch (ContactObservationEndDateAfterTodayException e) { - addFieldError("updateContactCommand.contact.observationEndDate", t("wao.ui.form.Contact.error.observationEndDateAfterToday")); - - } catch (MissingContactObservationBeginDateException e) { - String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - addFieldError("updateContactCommand.contact.observationBeginDate", t("wao.ui.form.Contact.error.missingObservationBeginDate", state)); - - } catch (MissingContactMammalsInfoException e) { - addFieldError("updateContactCommand.contact.mammalsInfo", t("wao.ui.form.Contact.error.missingMammalsInfo")); - - } - } - - @Override - public String execute() throws Exception { - - service.save(updateContactCommand, false); - - session.addMessage(t("wao.ui.form.updateContactCommand.success")); - - session.setContactToHighlightId(updateContactCommand.getContact().getTopiaId()); - return SUCCESS; - } - -} \ No newline at end of file Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditSampleRowAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditSampleRowAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditSampleRowAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,157 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Joiner; -import com.google.common.base.Optional; -import com.google.common.base.Strings; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.services.service.SampleRowCodeMustBeUniqueException; -import fr.ifremer.wao.services.service.UpdateSampleRowCommand; -import fr.ifremer.wao.services.service.administration.UnknownBoatImmatriculationsException; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -import java.util.Map; - -@Results({ - @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) -}) -public class EditSampleRowAction extends WaoJspActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - private static final Log log = LogFactory.getLog(EditSampleRowAction.class); - - protected transient ObsMerSamplingPlanService service; - - protected Optional<String> optionalSampleRowId = Optional.absent(); - - protected UpdateSampleRowCommand updateSampleRowCommand; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public String getSampleRowId() { - return optionalSampleRowId.orNull(); - } - - public void setSampleRowId(String sampleRowId) { - this.optionalSampleRowId = Optional.fromNullable(Strings.emptyToNull(sampleRowId)); - } - - @Override - public void prepare() { - - updateSampleRowCommand = service.newUpdateSampleRowCommand(getAuthenticatedWaoUser(), optionalSampleRowId); - - } - - @Override - public void validate() { - - SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); - - try { - - service.preValidate(getAuthenticatedWaoUser(), updateSampleRowCommand); - - if (CollectionUtils.isEmpty(sampleRow.getdCF5Code())) { - addFieldError("updateSampleRowCommand.dcf5Codes", t("wao.ui.form.SampleRow.error.missingDcf5Codes")); - } - - } catch (UnknownBoatImmatriculationsException e) { - addFieldError("updateSampleRowCommand.elligibleBoatImmatriculations", t("wao.ui.unknownBoatImmatriculations", Joiner.on(", ").join(e.getImmatriculations()))); - } catch (SampleRowCodeMustBeUniqueException e) { - addFieldError("updateSampleRowCommand.code", t("wao.ui.form.SampleRow.error.codeMustBeUnique")); - } - - if (updateSampleRowCommand.isCreation()) { - if ( ! WaoUtils.getSampleRowCodePattern(sampleRow.getObsProgram()).matcher(sampleRow.getCode()).matches()) { - addFieldError("updateSampleRowCommand.code", t("wao.import.sampleRow.failure.wrongSampleRowCodeFormat", sampleRow.getCode())); - } - } else { - if (StringUtils.isBlank(updateSampleRowCommand.getSampleRowLog().getComment())) { - addFieldError("updateSampleRowCommand.sampleRowLog.comment", t("wao.ui.form.SampleRow.error.missingLogComment")); - } - } - - if (StringUtils.isBlank(sampleRow.getProgramName())) { - addFieldError("updateSampleRowCommand.sampleRow.programName", t("wao.ui.form.SampleRow.error.missingProgramName")); - } - - if (sampleRow.getPeriodBegin() == null) { - addFieldError("updateSampleRowCommand.sampleRow.periodBegin", t("wao.ui.form.SampleRow.error.missingPeriodBegin")); - } - - if (sampleRow.getPeriodEnd() == null) { - addFieldError("updateSampleRowCommand.sampleRow.periodEnd", t("wao.ui.form.SampleRow.error.missingPeriodEnd")); - } - - if (CollectionUtils.isEmpty(sampleRow.getFishingZone())) { - addFieldError("updateSampleRowCommand.fishingZones", t("wao.ui.form.SampleRow.error.missingFishingZones")); - } - - if (sampleRow.getSamplingStrategy().isSpecificStock() && StringUtils.isEmpty(sampleRow.getProfession().getSpecies())) { - addFieldError("updateSampleRowCommand.sampleRow.samplingStrategy", t("wao.ui.form.SampleRow.error.missingProfessionSpecies")); - } - - } - - @Override - public String execute() { - - service.save(updateSampleRowCommand); - - session.addMessage(t("wao.ui.form.updateSampleRowCommand.success", updateSampleRowCommand.getSampleRow().getCode())); - - session.setSampleRowToHighlightId(updateSampleRowCommand.getSampleRow().getTopiaId()); - - return SUCCESS; - - } - - public UpdateSampleRowCommand getUpdateSampleRowCommand() { - if (updateSampleRowCommand == null) { - prepare(); - } - return updateSampleRowCommand; - } - - public Map<String, Integer> getExpectedObservationsByMonths() { - return getUpdateSampleRowCommand().getExpectedObservationsByMonths(); - } - - public void setExpectedObservationsByMonths(Map<String, Integer> expectedObservationsByMonths) { - getUpdateSampleRowCommand().setExpectedObservationsByMonths(expectedObservationsByMonths); - } - -} \ No newline at end of file Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportBoatsAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportBoatsAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportBoatsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,78 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.BoatsFilter; -import fr.ifremer.wao.services.service.ObsMerBoatsService; -import fr.ifremer.wao.web.action.AbstractDownloadCsvAction; - -import java.io.InputStream; -import java.util.Date; - -/** - * Created on 4/1/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class ExportBoatsAction extends AbstractDownloadCsvAction implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerBoatsService service; - - protected BoatsFilter filter; - - public void setService(ObsMerBoatsService service) { - this.service = service; - } - - public BoatsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - @Override - public void prepare() { - - filter = service.newBoatsFilter(getAuthenticatedWaoUser()); - - } - - @Override - public String getFileName() { - - return "boats_" + getObsProgram().name() + "_" + dateFormat.format(new Date()) + ".csv"; - - } - - @Override - public InputStream getInputStream() { - - return service.exportBoats(filter); - - } - -} \ No newline at end of file Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportContactsAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportContactsAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportContactsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,75 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.ContactsFilter; -import fr.ifremer.wao.services.service.ObsMerContactsService; -import fr.ifremer.wao.web.action.AbstractDownloadCsvAction; - -import java.io.InputStream; -import java.util.Date; - -/** - * Created on 4/3/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class ExportContactsAction extends AbstractDownloadCsvAction implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerContactsService service; - - protected ContactsFilter filter; - - public void setService(ObsMerContactsService service) { - this.service = service; - } - - public ContactsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - @Override - public void prepare() { - - filter = service.newContactFilter(getAuthenticatedWaoUser()); - } - - @Override - public String getFileName() { - - return "contacts_" + getObsProgram().name() + "_" + dateFormat.format(new Date()) + ".csv"; - } - - @Override - public InputStream getInputStream() { - - return service.exportContacts(filter); - } - -} \ No newline at end of file Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,72 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.action.AbstractDownloadCsvAction; - -import java.io.InputStream; -import java.util.Date; - -public class ExportSamplingPlanAction extends AbstractDownloadCsvAction implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected SampleRowsFilter filter; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public SampleRowsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - @Override - public void prepare() { - - filter = service.newSampleRowsFilter(getAuthenticatedWaoUser()); - - } - - @Override - public String getFileName() { - - return "plan_" + getObsProgram().name() + "_" + dateFormat.format(new Date()) + ".csv"; - - } - - @Override - public InputStream getInputStream() { - - return service.exportSamplingPlan(filter); - - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/GetBoatContactsCountJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/GetBoatContactsCountJsonAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/GetBoatContactsCountJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,50 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -import fr.ifremer.wao.services.service.BoatContactsCounts; -import fr.ifremer.wao.services.service.ObsMerBoatsService; -import fr.ifremer.wao.web.WaoJsonActionSupport; - -import java.util.Date; - -public class GetBoatContactsCountJsonAction extends WaoJsonActionSupport { - - protected Date since; - - protected ObsMerBoatsService service; - - protected String boatId; - - protected String companyId; - - protected BoatContactsCounts boatContactsCounts; - - public void setSince(Date since) { - this.since = since; - } - - public void setService(ObsMerBoatsService service) { - this.service = service; - } - - public void setBoatId(String boatId) { - this.boatId = boatId; - } - - public void setCompanyId(String companyId) { - this.companyId = companyId; - } - - @Override - public String execute() { - - boatContactsCounts = service.getBoatContactsCounts(session.getAuthenticatedWaoUser(), boatId, companyId, since); - - return SUCCESS; - - } - - public BoatContactsCounts getBoatContactsCounts() { - return boatContactsCounts; - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportContactsAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportContactsAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportContactsAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,62 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import fr.ifremer.wao.services.service.ImportErrorException; -import fr.ifremer.wao.services.service.ObsMerContactsService; -import fr.ifremer.wao.web.action.AbstractImportCsvAction; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -import java.io.InputStream; - -/** - * Created on 4/3/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -@Results({ - @Result(name = "error", type = "redirectAction", params = {"actionName", "import-contacts!input"}), - @Result(name = "success", type = "redirectAction", params = {"actionName", "contacts"}) - }) -public class ImportContactsAction extends AbstractImportCsvAction { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerContactsService contactsService; - - public void setService(ObsMerContactsService contactsService) { - this.contactsService = contactsService; - } - - @Override - protected void importCsv(InputStream csvInputStream) throws ImportErrorException { - contactsService.importContacts(getAuthenticatedWaoUser(), csvInputStream); - } - - @Override - protected String getSuccessMessage() { - return t("wao.ui.import.contacts.success"); - } - -} \ No newline at end of file Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportSamplingPlanAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportSamplingPlanAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportSamplingPlanAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,56 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import fr.ifremer.wao.services.service.ImportErrorException; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.action.AbstractImportCsvAction; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -import java.io.InputStream; - -@Results({ - @Result(name="error", type="redirectAction", params = { "actionName", "import-sampling-plan!input" }) , - @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) -}) -public class ImportSamplingPlanAction extends AbstractImportCsvAction { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService samplingPlanService; - - public void setService(ObsMerSamplingPlanService samplingPlanService) { - this.samplingPlanService = samplingPlanService; - } - - @Override - protected void importCsv(InputStream csvInputStream) throws ImportErrorException { - samplingPlanService.importSamplingPlan(getAuthenticatedWaoUser(), csvInputStream); - } - - @Override - protected String getSuccessMessage() { - return t("wao.ui.import.samplingPlan.success"); - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowLogAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowLogAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowLogAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,62 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.WaoJspActionSupport; - -public class SampleRowLogAction extends WaoJspActionSupport { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected String sampleRowId; - - protected SampleRow sampleRow; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public void setSampleRowId(String sampleRowId) { - this.sampleRowId = sampleRowId; - } - - @Override - public String execute() { - - sampleRow = service.getSampleRow(sampleRowId); - - return SUCCESS; - } - - public SampleRow getSampleRow() { - return sampleRow; - } - - public String getSampleRowId() { - return sampleRowId; - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowsFilterValuesJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowsFilterValuesJsonAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowsFilterValuesJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,92 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.services.service.SampleRowsFilterValues; -import fr.ifremer.wao.web.WaoJsonActionSupport; -import org.apache.commons.lang3.StringUtils; - -public class SampleRowsFilterValuesJsonAction extends WaoJsonActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected SampleRowsFilter filter; - - protected SampleRowsFilterValues filterValues; - - protected String filterValuesField; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public SampleRowsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - public void setFilterValuesField(String filterValuesField) { - this.filterValuesField = filterValuesField; - } - - @Override - public void prepare() { - - filter = service.newSampleRowsFilter(session.getAuthenticatedWaoUser()); - - } - - @Override - public String execute() { - - ObsMerSamplingPlan samplingPlan = service.getSamplingPlan(session.getAuthenticatedWaoUser(), filter); - - filterValues = samplingPlan.getFilterValues(); - - if (StringUtils.isNotBlank(filterValuesField)) { - - // le client ne demande qu'un seul champ, on peut éviter de retourner l'objet complet - - filterValues = filterValues.getCopyWithSingleProperty(filterValuesField); - - } - - return SUCCESS; - } - - public String getFilterValuesField() { - return filterValuesField; - } - - public SampleRowsFilterValues getFilterValues() { - return filterValues; - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,129 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Objects; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.services.service.SampleRowsFilterValues; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.commons.lang3.time.DateUtils; - -import java.text.SimpleDateFormat; -import java.util.Date; - -public class SamplingPlanAction extends WaoJspActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected SampleRowsFilter filter; - - protected ObsMerSamplingPlan samplingPlan; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public SampleRowsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - @Override - public void prepare() { - - if (filter == null) { - filter = service.newSampleRowsFilter(getAuthenticatedWaoUser()); - } - - } - - @Override - public String execute() { - - filter = Objects.firstNonNull(session.getSampleRowsFilter(), filter); - - return applyFilter(); - - } - - public String resetFilter() { - - filter = service.newSampleRowsFilter(getAuthenticatedWaoUser()); - - return applyFilter(); - - } - - public String applyFilter() { - - getSession().setSampleRowsFilter(filter); - - samplingPlan = service.getSamplingPlan(getAuthenticatedWaoUser(), filter); - - return SUCCESS; - - } - - public ObsMerSamplingPlan getSamplingPlan() { - return samplingPlan; - } - - public String getSampleRowToHighlightId() { - return getSession().getSampleRowToHighlightId(); - } - - public SampleRowsFilterValues getFilterValues() { - SampleRowsFilterValues filterValues = getSamplingPlan().getFilterValues(); - return filterValues; - } - - public boolean isFullView() { - boolean fullView = getAuthenticatedWaoUser().isAdmin() || getAuthenticatedWaoUser().isProfessional(); - return fullView; - } - - protected SimpleDateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); - - public boolean isCurrentMonth(Date month) { - - String currentStr = dateFormat.format(getNow()); - String monthStr = dateFormat.format(month); - return currentStr.equals(monthStr); - } - - public String getFilterPeriodFromPlaceholder() { - String placeholder = formatMonth(DateUtils.addMonths(getNow(), 1)); - return placeholder; - } - - public String getFilterPeriodToPlaceholder() { - String placeholder = formatMonth(DateUtils.addYears(getNow(), 1)); - return placeholder; - } -} Copied: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java) =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java (rev 0) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,21 @@ +package fr.ifremer.wao.web.action.obsmer; + +import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.web.action.AbstractSamplingPlanAction; + +public class SamplingPlanAction extends AbstractSamplingPlanAction { + + protected transient ObsMerSamplingPlanService service; + + public void setService(ObsMerSamplingPlanService service) { + this.service = service; + } + + @Override + protected SamplingPlan samplingPlan() { + + return service.getSamplingPlan(getAuthenticatedWaoUser(), filter); + + } +} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SearchBoatJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SearchBoatJsonAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SearchBoatJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,71 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.BoatsFilter; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.services.service.FilterOption; -import fr.ifremer.wao.services.service.ObsMerBoatsService; -import fr.ifremer.wao.web.WaoJsonActionSupport; - -import java.util.Collection; - -public class SearchBoatJsonAction extends WaoJsonActionSupport implements Preparable { - - protected static final Function<Boat, FilterOption> BOAT_TO_FILTER_OPTION_FUNCTION = new Function<Boat, FilterOption>() { - - @Override - public FilterOption apply(Boat boat) { - String value = boat.getTopiaId(); - String label = boat.getImmatriculation() + " " + boat.getName(); - return FilterOption.forValueAndLabel(value, label); - } - }; - - protected ObsMerBoatsService service; - - protected BoatsFilter filter; - - protected int pageSize; - - protected Collection<FilterOption> boatFilterOptions; - - public void setService(ObsMerBoatsService service) { - this.service = service; - } - - public void setPageSize(int pageSize) { - this.pageSize = pageSize; - } - - public BoatsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - @Override - public void prepare() { - - filter = service.newBoatsFilter(session.getAuthenticatedWaoUser()); - - } - - @Override - public String execute() { - - Collection<Boat> boats = service.getBoats(filter, pageSize); - - boatFilterOptions = Collections2.transform(boats, BOAT_TO_FILTER_OPTION_FUNCTION); - - return SUCCESS; - - } - - public Collection<FilterOption> getBoatFilterOptions() { - return boatFilterOptions; - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SynthesisAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SynthesisAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SynthesisAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,67 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -import com.google.common.base.Objects; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.ContactsFilter; -import fr.ifremer.wao.services.service.ObsMerSynthesis; -import fr.ifremer.wao.services.service.SynthesisService; -import fr.ifremer.wao.web.WaoJspActionSupport; - -public class SynthesisAction extends WaoJspActionSupport implements Preparable { - - protected ContactsFilter filter; - - protected SynthesisService service; - - protected ObsMerSynthesis synthesis; - - public void setService(SynthesisService service) { - this.service = service; - } - - public ContactsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - @Override - public void prepare() { - - if (filter == null) { - filter = service.newFilter(getAuthenticatedWaoUser()); - } - - } - - @Override - public String execute() { - - filter = Objects.firstNonNull(session.getSynthesisFilter(), filter); - - return applyFilter(); - - } - - public String resetFilter() { - - filter = service.newFilter(getAuthenticatedWaoUser()); - - return applyFilter(); - - } - - public String applyFilter() { - - getSession().setSynthesisFilter(filter); - - synthesis = service.getObsMerSynthesis(filter); - - return SUCCESS; - } - - public ObsMerSynthesis getSynthesis() { - return synthesis; - } -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/UpdateBoatElligibilityJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/UpdateBoatElligibilityJsonAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/UpdateBoatElligibilityJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,39 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -import fr.ifremer.wao.services.service.ObsMerBoatsService; -import fr.ifremer.wao.web.WaoJsonActionSupport; - -public class UpdateBoatElligibilityJsonAction extends WaoJsonActionSupport { - - protected ObsMerBoatsService service; - - protected String boatId; - - protected String sampleRowId; - - protected boolean active; - - public void setService(ObsMerBoatsService service) { - this.service = service; - } - - public void setActive(boolean active) { - this.active = active; - } - - public void setBoatId(String boatId) { - this.boatId = boatId; - } - - public void setSampleRowId(String sampleRowId) { - this.sampleRowId = sampleRowId; - } - - @Override - public String execute() { - - service.changeBoatElligibility(session.getAuthenticatedWaoUser(), boatId, sampleRowId, active); - - return SUCCESS; - } -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/UpdateBoatInfosJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/UpdateBoatInfosJsonAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/UpdateBoatInfosJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,59 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -import com.google.common.base.Preconditions; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.entity.BoatInfos; -import fr.ifremer.wao.services.service.ObsMerBoatsService; -import fr.ifremer.wao.web.WaoJsonActionSupport; - -public class UpdateBoatInfosJsonAction extends WaoJsonActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerBoatsService service; - - protected String companyId; - - protected String boatId; - - protected BoatInfos boatInfos; - - public void setService(ObsMerBoatsService service) { - this.service = service; - } - - public void setCompanyId(String companyId) { - this.companyId = companyId; - } - - public void setBoatId(String boatId) { - this.boatId = boatId; - } - - @Override - public void prepare() { - - Preconditions.checkState(session.getAuthenticatedWaoUser().isAuthorizedToViewBoatDetails(companyId)); - - boatInfos = service.getBoatInfos(boatId, companyId); - - } - - public BoatInfos getBoatInfos() { - return boatInfos; - } - - public void setBoatInfos(BoatInfos boatInfos) { - this.boatInfos = boatInfos; - } - - @Override - public String execute() { - - service.saveBoatInfos(boatInfos); - - return SUCCESS; - - } - -} Deleted: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,303 +0,0 @@ -package fr.ifremer.wao.web.action.obsmer; - -/* - * #%L - * Wao :: Web - * %% - * Copyright (C) 2009 - 2014 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% - */ - -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.WaoTechnicalException; -import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.services.service.ContactDataInputDateBeforeObservationEndDateException; -import fr.ifremer.wao.services.service.ContactDataInputDateAfterTodayException; -import fr.ifremer.wao.services.service.ContactNotUpdatableException; -import fr.ifremer.wao.services.service.ContactObservationEndDateAfterTodayException; -import fr.ifremer.wao.services.service.ContactObservationEndDateBeforeBeginDateException; -import fr.ifremer.wao.services.service.ContactRestitutionDateBeforeDataInputDateException; -import fr.ifremer.wao.services.service.ContactWithObservedDataControlToCorrectionAskedException; -import fr.ifremer.wao.services.service.DuplicatedContactMainObserverInSecondaryObserversException; -import fr.ifremer.wao.services.service.InvalidContactObservationBeginDateException; -import fr.ifremer.wao.services.service.MismatchContactMainObserverCompanyException; -import fr.ifremer.wao.services.service.MismatchContactSecondaryObserverCompanyException; -import fr.ifremer.wao.services.service.MissingContactCommentAdminException; -import fr.ifremer.wao.services.service.MissingContactCommentException; -import fr.ifremer.wao.services.service.MissingContactDataInputDateException; -import fr.ifremer.wao.services.service.MissingContactDataReliabilityException; -import fr.ifremer.wao.services.service.MissingContactMainObserverException; -import fr.ifremer.wao.services.service.MissingContactNbObservantsException; -import fr.ifremer.wao.services.service.MissingContactObservationBeginDateException; -import fr.ifremer.wao.services.service.MissingContactObservationEndDateException; -import fr.ifremer.wao.services.service.MissingContactObservedDataControlException; -import fr.ifremer.wao.services.service.MissingContactRestitutionException; -import fr.ifremer.wao.services.service.MissingContactStateMotifException; -import fr.ifremer.wao.services.service.UnwantedContactContactStateMotifException; -import fr.ifremer.wao.services.service.ObsMerContactsService; -import fr.ifremer.wao.services.service.UpdateContactCommand; -import fr.ifremer.wao.web.WaoJsonActionSupport; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Created on 4/3/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 4.0 - */ -public class ValidateContactJsonAction extends WaoJsonActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - /** Logger. */ - private static final Log log = LogFactory.getLog(ValidateContactJsonAction.class); - - /** - * Id of contact to treat. - */ - protected String contactId; - - /** - * New validation state. - */ - protected Boolean validationState; - - /** - * Success message - */ - protected String successMessage; - - /** - * Error message if validation, or any was wrong while update. - */ - protected String errorMessage; - - protected transient ObsMerContactsService service; - - protected UpdateContactCommand updateContactCommand; - - public void setService(ObsMerContactsService service) { - this.service = service; - } - - public void setContactId(String contactId) { - this.contactId = contactId; - } - - public void setValidationState(Boolean validationState) { - this.validationState = validationState; - } - - public String getContactId() { - return contactId; - } - - public Boolean getValidationState() { - return validationState; - } - - public String getSuccessMessage() { - return successMessage; - } - - public String getErrorMessage() { - return errorMessage; - } - - public boolean isSuccessful() { - return errorMessage == null; - } - - @Override - public void prepare() { - - Preconditions.checkState(StringUtils.isNotEmpty(contactId)); - - AuthenticatedWaoUser authenticatedWaoUser = session.getAuthenticatedWaoUser(); - - updateContactCommand = service.newUpdateContactCommand( - session.getAuthenticatedWaoUser(), - Optional.of(contactId)); - - if (authenticatedWaoUser.isAdmin()) { - updateContactCommand.setValidationProgram(validationState); - } else { - updateContactCommand.setValidationCompany(validationState); - } - } - - @Override - public String execute() { - - AuthenticatedWaoUser authenticatedWaoUser = session.getAuthenticatedWaoUser(); - - try { - service.validate(authenticatedWaoUser, updateContactCommand, true); - } catch (ContactNotUpdatableException e) { - session.addErrorMessages(t("wao.ui.contacts.validation.failure.not.updatable")); - - } catch (UnwantedContactContactStateMotifException e) { - errorMessage = t("wao.ui.form.Contact.error.unwantedContactStateMotif"); - - } catch (MissingContactNbObservantsException e) { - String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - errorMessage = t("wao.ui.form.Contact.error.missingObserver", state); - - } catch (MissingContactObservationEndDateException e) { - String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - errorMessage = t("wao.ui.form.Contact.error.missingObservationEndDate", state); - - } catch (ContactDataInputDateBeforeObservationEndDateException e) { - errorMessage = t("wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate"); - - } catch (InvalidContactObservationBeginDateException e) { - errorMessage = t("wao.ui.form.Contact.error.invalidObservationBeginDate"); - - } catch (MissingContactRestitutionException e) { - errorMessage = t("wao.ui.form.Contact.error.missingRestitution"); - - } catch (ContactDataInputDateAfterTodayException e) { - errorMessage = t("wao.ui.form.Contact.error.dataInputDateAfterToday"); - - } catch (MissingContactCommentException e) { - String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - errorMessage = t("wao.ui.form.Contact.error.missingComment", state); - - } catch (MismatchContactMainObserverCompanyException e) { - String companyName = e.getCompany().getName(); - String observerLogin = e.getObserver().getLogin(); - errorMessage = t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName); - - } catch (ContactRestitutionDateBeforeDataInputDateException e) { - errorMessage = t("wao.ui.form.Contact.error.transmissionDateBeforeDataInputDate"); - - } catch (ContactObservationEndDateBeforeBeginDateException e) { - errorMessage = t("wao.ui.form.Contact.error.observationEndDateBeforeBeginDate"); - - } catch (DuplicatedContactMainObserverInSecondaryObserversException e) { - errorMessage = t("wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers"); - - } catch (MissingContactDataReliabilityException e) { - errorMessage = t("wao.ui.form.Contact.error.missingDataReliability"); - - } catch (MismatchContactSecondaryObserverCompanyException e) { - String companyName = e.getCompany().getName(); - String observerLogin = e.getObserver().getLogin(); - errorMessage = t("wao.ui.form.Contact.error.mismatchCompanyForObserver", observerLogin, companyName); - - } catch (MissingContactObservedDataControlException e) { - errorMessage = t("wao.ui.form.Contact.error.missingObservedDataControl"); - - } catch (ContactWithObservedDataControlToCorrectionAskedException e) { - errorMessage = t("wao.ui.form.Contact.error.observedDataControlToCorrectionAsked"); - - } catch (MissingContactStateMotifException e) { - errorMessage = t("wao.ui.form.Contact.error.missingContactStateMotif"); - - } catch (MissingContactDataInputDateException e) { - errorMessage = t("wao.ui.form.Contact.error.missingDataInputDate"); - - } catch (MissingContactMainObserverException e) { - errorMessage = t("wao.ui.form.Contact.error.missingMainObserver"); - - } catch (MissingContactCommentAdminException e) { - String dataReliability = WaoUtils.l(getLocale(), e.getContact().getDataReliability()); - errorMessage = t("wao.ui.form.Contact.error.missingCommentAdmin", dataReliability); - - } catch (ContactObservationEndDateAfterTodayException e) { - errorMessage = t("wao.ui.form.Contact.error.observationEndDateAfterToday"); - - } catch (MissingContactObservationBeginDateException e) { - String state = WaoUtils.l(getLocale(), e.getContact().getContactState()); - errorMessage = t("wao.ui.form.Contact.error.missingObservationBeginDate", state); - - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error(e); - } - errorMessage = t("wao.ui.contacts.validation.failure", e.getMessage()); - } - - if (isSuccessful()) { - - try { - service.save(updateContactCommand, true); - } catch (ContactNotUpdatableException e) { - throw new WaoTechnicalException("should never occur", e); - } - if (validationState == null) { - successMessage = t("wao.ui.contacts.validation.to.unvalidate.state.success"); - } else if (validationState) { - successMessage = t("wao.ui.contacts.validation.to.accept.state.success"); - } else { - successMessage = t("wao.ui.contacts.validation.to.reject.state.success"); - } - } - - return SUCCESS; - } - - public boolean isAcceptable(Contact contact) { - boolean acceptable; - if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { - acceptable = contact.isAcceptableByCompany(); - } else if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { - acceptable = contact.isAcceptableByProgram(); - } else { - throw new IllegalStateException(); - } - return acceptable; - } - - public boolean isRefusable(Contact contact) { - boolean refuseable; - if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { - refuseable = contact.isRefusableByCompany(); - } else if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { - refuseable = contact.isRefusableByProgram(); - } else { - throw new IllegalStateException(); - } - return refuseable; - } - - public boolean isUnacceptable(Contact contact) { - boolean unacceptable; - if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationCompany()) { - unacceptable = contact.isUnacceptableByCompany(); - } else if (session.getAuthenticatedWaoUser().isAuthorizedToChangeValidationProgram()) { - unacceptable = contact.isUnacceptableByProgram(); - } else { - throw new IllegalStateException(); - } - return unacceptable; - } - - public Boolean getValidationProgram() { - return updateContactCommand.getContact().getValidationProgram(); - } - - public Boolean getValidationCompany() { - return updateContactCommand.getContact().getValidationCompany(); - } - -} Deleted: trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/ObsMerSynthesis-conversion.properties =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/ObsMerSynthesis-conversion.properties 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/ObsMerSynthesis-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,2 +0,0 @@ -expectedVsActualObservationsByMonthsChart=fr.ifremer.wao.web.converter.JFreeChartToImgTagConverter -boardingBoatsChart=fr.ifremer.wao.web.converter.JFreeChartToImgTagConverter Copied: trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/Synthesis-conversion.properties (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/services/service/Synthesis-conversion.properties) =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/Synthesis-conversion.properties (rev 0) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/Synthesis-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,2 @@ +expectedVsActualObservationsByMonthsChart=fr.ifremer.wao.web.converter.JFreeChartToImgTagConverter +boardingBoatsChart=fr.ifremer.wao.web.converter.JFreeChartToImgTagConverter Copied: trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/BoatsAction-conversion.properties (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/web/action/BoatsAction-conversion.properties) =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/BoatsAction-conversion.properties (rev 0) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/BoatsAction-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1 @@ +filter=org.nuiton.web.struts2.converters.JsonConverter Copied: trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/ContactsAction-conversion.properties (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/web/action/ContactsAction-conversion.properties) =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/ContactsAction-conversion.properties (rev 0) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/ContactsAction-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1 @@ +filter=org.nuiton.web.struts2.converters.JsonConverter Copied: trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction-conversion.properties (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction-conversion.properties) =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction-conversion.properties (rev 0) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/GetBoatContactsCountJsonAction-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1 @@ +since=fr.ifremer.wao.web.converter.DateConverter Copied: trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/SynthesisAction-conversion.properties (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/web/action/SynthesisAction-conversion.properties) =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/SynthesisAction-conversion.properties (rev 0) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/SynthesisAction-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1 @@ +filter=org.nuiton.web.struts2.converters.JsonConverter Deleted: trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/BoatsAction-conversion.properties =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/BoatsAction-conversion.properties 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/BoatsAction-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -1 +0,0 @@ -filter=org.nuiton.web.struts2.converters.JsonConverter Deleted: trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/ContactsAction-conversion.properties =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/ContactsAction-conversion.properties 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/ContactsAction-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -1 +0,0 @@ -filter=org.nuiton.web.struts2.converters.JsonConverter Deleted: trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/GetBoatContactsCountJsonAction-conversion.properties =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/GetBoatContactsCountJsonAction-conversion.properties 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/GetBoatContactsCountJsonAction-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -1 +0,0 @@ -since=fr.ifremer.wao.web.converter.DateConverter Deleted: trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/SynthesisAction-conversion.properties =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/SynthesisAction-conversion.properties 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsmer/SynthesisAction-conversion.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -1 +0,0 @@ -filter=org.nuiton.web.struts2.converters.JsonConverter Modified: trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties =================================================================== --- trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -167,6 +167,7 @@ wao.ui.field.Boat.boatLength=Length wao.ui.field.Boat.buildYear=Build year wao.ui.field.Boat.district=Boat district +wao.ui.field.Boat.district.long=Boat district for boat wao.ui.field.Boat.districtCode=District oode wao.ui.field.Boat.fleet=Fleet wao.ui.field.Boat.immatriculation=Registration number @@ -226,6 +227,7 @@ wao.ui.field.FishingZone.facadeName=Facade wao.ui.field.FishingZone.sectorName=Sector wao.ui.field.SampleRow.appliedCoverageRate=Applied coverage rate +wao.ui.field.SampleRow.averageObservationsCount=Observations wao.ui.field.SampleRow.averageTideTime=Average tide time wao.ui.field.SampleRow.boat=Boat wao.ui.field.SampleRow.code=Line code @@ -286,11 +288,14 @@ wao.ui.form.Contact.error.dataInputDateAfterToday=The data input date cannot be after tomorrow wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate=The data input date cannot be before observation end date wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers=The main observer cannot also be a secondary observer +wao.ui.form.Contact.error.illegalAcceptationException=Contact must be validated by company before being validated by program wao.ui.form.Contact.error.invalidObservationBeginDate=The observation begin date must be a date in a month with an expected effort in the sampling plan wao.ui.form.Contact.error.mismatchCompanyForObserver=Observers must belong to the company attached to the sample row wao.ui.form.Contact.error.missingComment=The comment is mandatory wao.ui.form.Contact.error.missingCommentAdmin=The admin comment is mandatory +wao.ui.form.Contact.error.missingContactMammalsInfo=You must provide information about captured mammals wao.ui.form.Contact.error.missingContactStateMotif=The contact state motif must be provided +wao.ui.form.Contact.error.missingContactTerrestrialLocation=You must provide a terrestrial location wao.ui.form.Contact.error.missingDataInputDate=The data input date must be provided wao.ui.form.Contact.error.missingDataReliability=The data reliability must be provided wao.ui.form.Contact.error.missingMainObserver=The main observer must be provided @@ -552,6 +557,7 @@ wao.ui.tip.youMustChooseBoat=You must choose a boat in the list wao.ui.unavailableOperation=Unavailable operation wao.ui.unit.days=day(s) +wao.ui.unit.observations=observations wao.ui.unit.observers=observer(s) wao.ui.unknownBoatImmatriculations=Unknown boats\: %s wao.ui.userList=Users list Property changes on: trunk/wao-web/src/main/resources/i18n/wao-web_en_GB.properties ___________________________________________________________________ Modified: svn:mergeinfo - /branches/wao-1.5.x/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties:679-733 + /branches/wao-1.5.x/wao-ui/src/main/resources/i18n/wao-ui_en_GB.properties:679-733 /branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_en_GB.properties:2075-2085 Modified: trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties =================================================================== --- trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-06-22 18:10:23 UTC (rev 2086) @@ -167,6 +167,7 @@ wao.ui.field.Boat.boatLength=Longueur wao.ui.field.Boat.buildYear=Année de construction wao.ui.field.Boat.district=Quartier maritime +wao.ui.field.Boat.district.long=Quartier maritime du navire wao.ui.field.Boat.districtCode=Code quartier wao.ui.field.Boat.fleet=Flotille wao.ui.field.Boat.immatriculation=Immatriculation @@ -226,6 +227,7 @@ wao.ui.field.FishingZone.facadeName=Façade wao.ui.field.FishingZone.sectorName=Zone wao.ui.field.SampleRow.appliedCoverageRate=Taux de couverture appliqué +wao.ui.field.SampleRow.averageObservationsCount=Nombre d'observations wao.ui.field.SampleRow.averageTideTime=Durée moyenne d'une marée wao.ui.field.SampleRow.boat=Navire wao.ui.field.SampleRow.code=Code ligne @@ -286,11 +288,14 @@ wao.ui.form.Contact.error.dataInputDateAfterToday=La date de saisie des données doit être antérieure à la date du jour wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate=La date de saisie des données doit être postérieure à la date de fin d'observation wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers=L'utilisateur référant ne doit pas se trouver aussi parmi les observateurs secondaires +wao.ui.form.Contact.error.illegalAcceptationException=Le contact doit être accepté par la société avant d'être accepté ou refusé par le programme wao.ui.form.Contact.error.invalidObservationBeginDate=La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne wao.ui.form.Contact.error.mismatchCompanyForObserver=L'observateur %s n'est pas membre de la société %s wao.ui.form.Contact.error.missingComment=Il faut préciser un commentaire pour l'état '%s' wao.ui.form.Contact.error.missingCommentAdmin=Il faut préciser dans le commentaire administrateur pourquoi la donnée est '%s' +wao.ui.form.Contact.error.missingContactMammalsInfo=Il faut préciser les informations concernants les captures accidentelles wao.ui.form.Contact.error.missingContactStateMotif=Il faut préciser un motif de refus +wao.ui.form.Contact.error.missingContactTerrestrialLocation=Il faut préciser le lieu terrestre wao.ui.form.Contact.error.missingDataInputDate=Il faut préciser une date de saisie des données en plus de la date de transmission de la restitution wao.ui.form.Contact.error.missingDataReliability=Il faut préciser la qualité de la donnée avant de valider wao.ui.form.Contact.error.missingMainObserver=Il faut au moins un observateur référant @@ -552,6 +557,7 @@ wao.ui.tip.youMustChooseBoat=Vous devez sélectionner un navire dans la liste en cliquant sur son immatriculation pour afficher les détails ici. wao.ui.unavailableOperation=Opération non-disponible wao.ui.unit.days=jour(s) +wao.ui.unit.observations=observations wao.ui.unit.observers=observateur(s) wao.ui.unknownBoatImmatriculations=Les navires ayant pour immatriculations %s sont inconnus du référentiel wao.ui.userList=Liste des utilisateurs Property changes on: trunk/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties ___________________________________________________________________ Modified: svn:mergeinfo - /branches/wao-1.5.x/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties:679-733 + /branches/wao-1.5.x/wao-ui/src/main/resources/i18n/wao-ui_fr_FR.properties:679-733 /branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties:2075-2085 Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/boat-details.jsp (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/boat-details.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/boat-details.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/boat-details.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,402 @@ +<%-- + #%L + Wao :: Web + %% + Copyright (C) 2009 - 2014 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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> +<%@taglib uri="/struts-tags" prefix="s" %> + +<script> + $(document).ready(function () { + + // le formulaire concernant l'interlocuteur + + var $boatInfosForm = $('#boat-infos-form'); + var $saveBoatInfosButton = $('#save-boat-infos'); + var $unlockBoatInfosFormButton = $('#unlock-boat-infos-form'); + + $saveBoatInfosButton.click(function () { + $boatInfosForm.find('input, textarea').attr('readonly', 'readonly'); + $saveBoatInfosButton.attr('disabled', 'disabled'); + $unlockBoatInfosFormButton.removeAttr('disabled'); + var data = WAO.toData($boatInfosForm); + var successCallback = function () { + WAO.notifications.success('<s:text name="wao.ui.form.BoatInfos.success"/>'); + } + WAO.post(WAO.UPDATE_BOAT_INFOS_JSON_URL, data, successCallback); + }); + + $unlockBoatInfosFormButton.click(function () { + $boatInfosForm.find('input[readonly], button, textarea').removeAttr('readonly').removeAttr('disabled'); + $unlockBoatInfosFormButton.attr('disabled', 'disabled'); + }); + + + // le calcul des sollicitations + + var $boatContactsCountForm = $('#boat-contacts-count-form'); + var $boatContactsCountsTable = $('#boat-contacts-counts-table'); + + $boatContactsCountsTable.hide(); + + var getBoatContactsCount = function () { + var data = WAO.toData($boatContactsCountForm); + var since = data.since; + var successCallback = function (data) { + var tr = '<tr>' + + ' <td>' + + since + + ' </td>' + + ' <td>' + + data.boatContactsCounts.contactsCompanyCount + + ' (' + data.boatContactsCounts.observationsCompanyCount + ')' + + ' </td>' + + ' <td>' + + data.boatContactsCounts.contactsCount + + ' (' + data.boatContactsCounts.observationsCount + ')' + + ' </td>' + + '</tr>'; + $boatContactsCountsTable.find('tbody').append(tr); + $boatContactsCountsTable.show(); + }; + WAO.get(WAO.GET_BOAT_CONTACTS_COUNT_JSON_URL, data, successCallback); + } + + $('#get-boat-contacts-count').click(getBoatContactsCount); + $boatContactsCountForm.enterKey(getBoatContactsCount); + + // création d'un contact depuis une ligne éligible + + var $createContactFromBoatButton = $('#createContactFromBoatButton'); + var $sampleRowIdInput = $('input[name="sampleRowId"]'); + var expiredSampleRowIds = <s:property value="boatDetails.expiredSampleRowIds" escapeHtml="false"/> + $sampleRowIdInput.change(function () { + $createContactFromBoatButton.removeAttr('disabled'); + }); + $createContactFromBoatButton.click(function (e) { + var selectedSampleRowIsExpired = $.inArray($('input[name="sampleRowId"]:checked').val(), expiredSampleRowIds); + var confirmMessage = "<s:text name="wao.ui.contacts.createFromBoat.warn"/>"; + if (selectedSampleRowIsExpired && ! confirm(confirmMessage)) { + e.preventDefault(); + } + }); + + // suppresssion d'une éligibilité + $('.remove-boat-eligibility').click(function (e) { + e.preventDefault(); + if (confirm("<s:text name="wao.ui.removeBoatEligibility.confirm"/>")) { + var url = $(this).attr('href'); + var $toRemove = $(this).parents('.elligible-sample-row') + var successCallback = function (data) { + $toRemove.remove(); + }; + WAO.post(url, {}, successCallback); + } + }); + + }); +</script> + +<h2> + <s:text name="wao.ui.boatinfo.contacts"> + <s:param value="boatDetails.boatInfos.boat.name"/> + </s:text> +</h2> + +<h3> + <s:text name="wao.ui.boats.contacts.existing"/> +</h3> + +<s:if test="boatDetails.contactsCount > 0"> + + <h4> + <s:text name="wao.ui.contact.lastContact"/> + </h4> + + <table class="table"> + <tbody> + <tr> + <th> + <s:text name="wao.ui.field.Contact.creationDate"/> + </th> + <td> + <s:property value="boatDetails.mostRecentContact.creationDate"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Contact.mainObserver"/> + </th> + <td> + <s:property value="boatDetails.mostRecentContact.mainObserver.fullName"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Contact.contactState"/> + </th> + <td> + <s:property value="%{getText(boatDetails.mostRecentContact.contactState)}"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Contact.sampleRow"/> + </th> + <td> + <s:property value="boatDetails.mostRecentContact.sampleRow.code"/> + </td> + </tr> + </tbody> + </table> + + <s:url action="contacts" id="viewAssociatedContactsForBoatUrl"> + <s:param name="filter.boatFilter.registrationCode" value="boatDetails.boatInfos.boat.immatriculation"/> + <s:param name="filter.sampleRowFilter.companyIds" value="boatDetails.boatInfos.company.topiaId"/> + <s:param name="filter.periodFrom"/> + <s:param name="filter.periodTo"/> + </s:url> + <s:a href="%{viewAssociatedContactsForBoatUrl}"> + <s:text name="wao.ui.action.viewAssociatedContactsForBoat"> + <s:param value="boatDetails.contactsCount"/> + </s:text> + </s:a> + +</s:if> +<s:else> + <s:text name="wao.ui.boats.contacts.none"/> +</s:else> + +<h3> + <s:text name="wao.ui.contact.creation"/> +</h3> + +<s:if test="boatDetails.boatInfos.boat.active"> + <s:if test="startBoatSelectionForSampleRow == null"> + <s:if test="boatDetails.elligibleForSampleRows.empty"> + <s:text name="wao.ui.tip.boatDetails.elligibleForSampleRowsEmpty" /> + </s:if> + <s:else> + <s:text name="wao.ui.boats.associatedLine"/> + <s:if test="boatDetails.newContactCreatable && authenticatedWaoUser.authorizedToCreateContact"> + <s:form action="create-contact"> + + <s:hidden name="boatId" value="%{boatDetails.boatInfos.boat.topiaId}"/> + + <div class="control-group"> + <div class="controls"> + <s:iterator value="boatDetails.elligibleForSampleRows" status="status"> + <div class="elligible-sample-row"> + <s:set name="radioId">radio-<s:property value="#status.index"/></s:set> + <input type="radio" name="sampleRowId" id="<s:property value="#radioId"/>" value="<s:property value="topiaId"/>"/> + <%-- + <label for="<s:property value="%{#radioId}"/>" class="radio"> + <s:property value="code"/> + </label> + --%> + <s:property value="code"/> + <s:url action="update-boat-elligibility-json" id="updateBoatElligibilityUrl"> + <s:param name="boatId" value="boatDetails.boatInfos.boat.topiaId"/> + <s:param name="sampleRowId" value="topiaId"/> + <s:param name="active" value="false"/> + </s:url> + <s:a href="%{updateBoatElligibilityUrl}" cssClass="btn btn-link remove-boat-eligibility"> + <i class="icon-remove"></i> + </s:a> + </div> + </s:iterator> + </div> + </div> + + + <s:submit id="createContactFromBoatButton" type="button" cssClass="btn btn-success" disabled="true"> + <i class="icon-plus"></i> + <s:text name="wao.ui.contacts.createFromBoat"/> + </s:submit> + </s:form> + </s:if> + <s:else> + <ul> + <s:iterator value="boatDetails.elligibleForSampleRows"> + <li class="elligible-sample-row"> + <s:property value="code"/> + <s:url action="update-boat-elligibility-json" id="updateBoatElligibilityUrl"> + <s:param name="boatId" value="boatDetails.boatInfos.boat.topiaId"/> + <s:param name="sampleRowId" value="topiaId"/> + <s:param name="active" value="false"/> + </s:url> + <s:a href="%{updateBoatElligibilityUrl}" cssClass="btn btn-link remove-boat-eligibility"> + <i class="icon-remove"></i> + </s:a> + </li> + </s:iterator> + </ul> + </s:else> + </s:else> + <s:if test="authenticatedWaoUser.authorizedToCreateContact"> + <div class="alert alert-info"> + <s:text name="wao.ui.tip.useBoatSelectionForSampleRow"/> + </div> + </s:if> + </s:if> + <s:else> + <s:if test="boatDetails.newContactCreatable"> + <s:if test="boatDetails.newContactCreatable && authenticatedWaoUser.authorizedToCreateContact"> + <s:url action="create-contact" id="createContactUrl"> + <s:param name="boatId" value="boatDetails.boatInfos.boat.topiaId"/> + <s:param name="sampleRowId" value="startBoatSelectionForSampleRow.topiaId"/> + </s:url> + <s:a href="%{createContactUrl}" cssClass="btn btn-success"> + <i class="icon-plus"></i> + <s:text name="wao.ui.contacts.createFromBoatAndSelectedSampleRow"> + <s:param value="startBoatSelectionForSampleRow.code"/> + <s:param value="startBoatSelectionForSampleRow.professionDescription"/> + </s:text> + </s:a> + </s:if> + </s:if> + <s:else> + <div class="alert"> + <s:text name="wao.ui.tip.contactAlreadyExists"/> + </div> + </s:else> + </s:else> + +</s:if> +<s:else> + <div class="alert"> + <s:text name="wao.ui.tip.inactiveBoat"/> + </div> +</s:else> + +<h3> + <s:text name="wao.ui.boatDetails.boatContactsCounts.title"/> +</h3> + +<table id="boat-contacts-counts-table" class="table no-border-top"> + <thead> + <tr> + <td> + <s:text name="wao.ui.boatDetails.boatContactsCounts.since"/> + </td> + <td> + <s:text name="wao.ui.boatDetails.boatContactsCounts.contactsCompanyCount"/> + </td> + <td> + <s:text name="wao.ui.boatDetails.boatContactsCounts.contactsCount"/> + </td> + </thead> + <tbody> + </tbody> +</table> + +<s:form id="boat-contacts-count-form"> + + <s:hidden name="boatId" value="%{boatDetails.boatInfos.boat.topiaId}" /> + <s:hidden name="companyId" value="%{boatDetails.boatInfos.company.topiaId}" /> + + <div class="input-prepend input-append"> + + <span class="add-on"> + <s:text name="wao.ui.boatDetails.boatContactsCounts.since"/> + </span> + + <input name="since" type="text" value="<s:property value="%{oneYearAgoDatePlaceHolder}"/>"/> + + <button type="button" id="get-boat-contacts-count" class="btn"> + <i class="icon-plus"></i> <s:text name="wao.ui.boatDetails.boatContactsCounts.compute" /> + </button> + </div> +</s:form> + +<h2> + <s:text name="wao.ui.boatinfo.title"> + <s:param value="boatDetails.boatInfos.boat.name"/> + </s:text> +</h2> + +<h3> + <s:text name="wao.ui.boats.info"/> +</h3> + +<table class="table"> + <tbody> + <tr> + <th class="no-border-top"> + <s:text name="wao.ui.field.Boat.shipOwner"/> + </th> + <td class="no-border-top"> + <s:url action="boats" id="shipOwnerBoatsUrl"> + <s:param name="filter.shipOwnerIds" value="boatDetails.boatInfos.boat.shipOwner.topiaId"/> + </s:url> + <s:set name="shipOwnerBoatsTitle"> + <s:text name="wao.ui.action.viewShipOwnerBoats"/> + </s:set> + <s:a href="%{shipOwnerBoatsUrl}" title="%{shipOwnerBoatsTitle}"> + <s:property value="boatDetails.boatInfos.boat.shipOwner.firstName"/> + <s:property value="boatDetails.boatInfos.boat.shipOwner.lastName"/> + </s:a> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Boat.boatGroup"/> + </th> + <td> + <s:if test="boatDetails.boatInfos.boat.boatGroup == null"> + <s:text name="wao.ui.misc.N/A"/> + </s:if> + <s:else> + <s:property value="boatDetails.boatInfos.boat.boatGroup.description"/> + </s:else> + </td> + </tr> + </tbody> +</table> + +<h3> + <s:text name="wao.ui.boats.interlocutor"/> +</h3> + +<s:form id="boat-infos-form" cssClass="form-horizontal"> + + <s:hidden name="boatId" value="%{boatDetails.boatInfos.boat.topiaId}" /> + <s:hidden name="companyId" value="%{boatDetails.boatInfos.company.topiaId}" /> + + <s:textfield name="boatInfos.contactFirstName" value="%{boatDetails.boatInfos.contactFirstName}" label="%{getText('wao.ui.field.BoatInfos.contactFirstName')}" readonly="true" cssClass="input-large" /> + <s:textfield name="boatInfos.contactLastName" value="%{boatDetails.boatInfos.contactLastName}" label="%{getText('wao.ui.field.BoatInfos.contactLastName')}" readonly="true" cssClass="input-large" /> + <s:textfield type="email" name="boatInfos.contactEmail" value="%{boatDetails.boatInfos.contactEmail}" label="%{getText('wao.ui.field.BoatInfos.contactEmail')}" readonly="true" cssClass="input-large" /> + <s:textfield type="tel" name="boatInfos.contactPhoneNumber" value="%{boatDetails.boatInfos.contactPhoneNumber}" label="%{getText('wao.ui.field.BoatInfos.contactPhoneNumber')}" readonly="true" cssClass="input-large" /> + <s:textfield type="number" name="boatInfos.dup" value="%{boatDetails.boatInfos.dup}" label="%{getText('wao.ui.field.BoatInfos.dup')}" readonly="true" cssClass="input-small" /> + <s:textfield name="boatInfos.contactAddress1" value="%{boatDetails.boatInfos.contactAddress1}" label="%{getText('wao.ui.field.BoatInfos.contactAddress1')}" readonly="true" cssClass="input-xxlarge" /> + <s:textfield name="boatInfos.contactAddress2" value="%{boatDetails.boatInfos.contactAddress2}" label="%{getText('wao.ui.field.BoatInfos.contactAddress2')}" readonly="true" cssClass="input-xxlarge" /> + <s:textfield name="boatInfos.contactPostalCode" value="%{boatDetails.boatInfos.contactPostalCode}" label="%{getText('wao.ui.field.BoatInfos.contactPostalCode')}" readonly="true" cssClass="input-small" /> + <s:textfield name="boatInfos.contactCity" value="%{boatDetails.boatInfos.contactCity}" label="%{getText('wao.ui.field.BoatInfos.contactCity')}" readonly="true" cssClass="input-large" /> + <s:textarea name="boatInfos.comment" value="%{boatDetails.boatInfos.comment}" label="%{getText('wao.ui.field.BoatInfos.comment')}" readonly="true" cssClass="input-xxlarge" /> + + <div class="form-actions"> + <button type="button" id="unlock-boat-infos-form" class="btn"> + <i class="icon-edit"></i> <s:text name="wao.ui.action.edit" /> + </button> + + <button type="button" id="save-boat-infos" class="btn" disabled="disabled"> + <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> + </button> + </div> + +</s:form> \ No newline at end of file Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/boats.jsp (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/boats.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/boats.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/boats.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,308 @@ +<%-- + #%L + Wao :: Web + %% + Copyright (C) 2009 - 2014 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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + +<head> + <title> + <s:text name="wao.ui.page.Boats.title"/> + </title> + + <script> + + $(document).ready(function () { + + var boatFilterMappings = [ + + <s:if test="authenticatedWaoUser.authorizedToFilterOnBoats"> + { + filterName: 'boatIds', + filterLabel: "<s:text name="wao.ui.entity.Boat"/>", + filterValuesField: 'boats', + minimumInputLength: 3 + }, + </s:if> + { + filterName: 'elligibleForSampleRowsFilter.fishingZoneFacadeNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.facadeName"/>", + filterValuesField: 'elligibleForSampleRowsFilterValues.fishingZoneFacadeNames' + }, + { + filterName: 'elligibleForSampleRowsFilter.fishingZoneSectorNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.sectorName"/>", + filterValuesField: 'elligibleForSampleRowsFilterValues.fishingZoneSectorNames' + }, + { + filterName: 'elligibleForSampleRowsFilter.sampleRowCodes', + filterLabel: "<s:text name="wao.ui.field.SampleRow.code"/>", + filterValuesField: 'elligibleForSampleRowsFilterValues.sampleRowCodes' + }, + { + filterName: 'districtIds', + filterLabel: "<s:text name="wao.ui.field.Boat.district"/>", + filterValuesField: 'districts' + }, + { + filterName: 'shipOwnerIds', + filterLabel: "<s:text name="wao.ui.field.Boat.shipOwner"/>", + filterValuesField: 'shipOwners', + minimumInputLength: 3 + }, + { + filterName: 'portOfRegistryIds', + filterLabel: "<s:text name="wao.ui.field.Boat.portOfRegistry"/>", + filterValuesField: 'portsOfRegistry' + } + ]; + + filter = <s:property value="filter" escapeHtml="false"/>; + + boatsFilterController2 = new FilterController2(boatFilterMappings, filter, WAO.BOATS_FILTER_VALUES_JSON_URL, $('#boats-filters-form fieldset.extra-filters')); + boatsFilterController2.init(); + +// var $boatsFiltersForm = $('#boats-filters-form'); +// var boatsFilterController = new FilterController(WAO.BOATS_FILTER_VALUES_JSON_URL, $boatsFiltersForm); +// boatsFilterController.init(); + + var $boatDetails = $('#boat-details'); + var $companyId = $('#companyId'); + + var showBoatDetails = function (boatId) { + var companyId = $companyId.val(); + var successCallback = function (data) { + $boatDetails.html(data); + $('tr.boat-row').removeClass('highlight'); + $('tr[data-boat-id="' + boatId + '"]').addClass('highlight'); + $boatDetails.effect('highlight', 'slow'); + }; + var data = { + fragment: true, + boatId: boatId, + companyId: companyId + }; + WAO.get(WAO.BOAT_DETAILS_URL, data, successCallback); + } + $('a.boat-details-action').click(function (e) { + e.preventDefault(); + var boatId = $(this).parents('tr.boat-row').attr('data-boat-id'); + showBoatDetails(boatId); + }); + $companyId.change(function () { + var boatId = $('tr.boat-row.highlight').attr('data-boat-id'); + if (boatId) { + showBoatDetails(boatId); + } + }); + + }); + + </script> + +</head> + +<content tag="mainClass">large</content> +<content tag="boatsMenuItemClass">active</content> + +<s:if test="startBoatSelectionForSampleRow != null"> + <div class="alert alert-info"> + <s:text name="wao.ui.tip.boatSelectionForSampleRowStarted"> + <s:param value="startBoatSelectionForSampleRow.code"/> + <s:param value="startBoatSelectionForSampleRow.professionDescription"/> + </s:text> + <s:url action="cancel-boat-selection" id="cancelBoatSelectionUrl"/> + <s:a href="%{cancelBoatSelectionUrl}" cssClass="btn btn-link"> + <s:text name="wao.ui.action.cancel"/> + </s:a> + </div> +</s:if> + +<div id="boats-filters-list-details-layout"> + + <div> + <s:form method="GET" id="boats-filters-form" cssClass="filters-form"> + + <fieldset class="extra-filters"> + + </fieldset> + + <div class="form-actions"> + + <s:submit type="button" action="boats!applyFilter" cssClass="btn btn-primary"> + <i class="icon-filter"></i> <s:text name="wao.ui.action.filter"/> + </s:submit> + + <s:submit type="button" action="boats!resetFilter" cssClass="btn"> + <i class="icon-trash"></i> <s:text name="wao.ui.action.reset"/> + </s:submit> + + <s:submit action="export-boats" type="button" cssClass="btn"> + <i class="icon-download"></i> <s:text name="wao.ui.action.csvExport"/> + </s:submit> + + </div> + + </s:form> + + </div> + + <div> + <div class="arrow-right"></div> + <h2> + <s:text name="wao.ui.boats.title"> + <s:param value="%{pagination.count}"/> + </s:text> + </h2> + + <s:if test="authenticatedWaoUser.authorizedToViewBoatDetailsForAllCompanies"> + <s:select id="companyId" + name="companyId" + label="Vous devez sélectionner la société pour laquelle vous souhaitez consulter les informations" + list="allCompanies" + listKey="%{topiaId}" + listValue="%{name}" + value="%{authenticatedWaoUser.waoUser.company.topiaId}" + cssClass="input-xxlarge" /> + </s:if> + <s:else> + <s:hidden id="companyId" name="companyId" value="%{authenticatedWaoUser.waoUser.company.topiaId}"/> + </s:else> + + <table id="boats-list" class="table-condensed table-striped table-hover"> + <thead> + <tr> + <th> + <s:text name="wao.ui.boats.registrationCode"/> + </th> + <th> + <s:text name="wao.ui.boats.boatName"/> + </th> + <th> + <s:text name="wao.ui.boats.boatLength"/> (cm) + </th> + <th> + <s:text name="wao.ui.boats.buildYear"/> + </th> + <th> + <s:text name="wao.ui.boats.district"/> + </th> + <th> + <span data-original-title="<s:text name="wao.ui.boats.portOfRegistry.description"/>" data-toggle="tooltip" data-placement="bottom"> + <s:text name="wao.ui.boats.portOfRegistry"/> + </span> + </th> + </tr> + </thead> + <tbody> + <s:iterator value="boats" var="boat"> + <tr data-boat-id="<s:property value="topiaId"/>" class="boat-row"> + <td> + <s:if test="authenticatedWaoUser.authorizedToViewBoatDetails"> + <s:url action="boat-details" id="boatDetailsUrl"> + <s:param name="companyId" value="authenticatedWaoUser.waoUser.company.topiaId" /> + <s:param name="boatId" value="topiaId" /> + </s:url> + <s:a href="%{boatDetailsUrl}" cssClass="boat-details-action"> + <s:property value="%{'' + immatriculation}"/> + </s:a> + </s:if> + <s:else> + <s:property value="%{'' + immatriculation}"/> + </s:else> + </td> + <td<s:if test="!active"> class="inactive"</s:if>> + <s:property value="name"/> + </td> + <td><s:property value="boatLength"/></td> + <td><s:property value="%{'' + buildYear}"/></td> + <td><s:property value="district.districtCode"/></td> + <td> + <s:if test="portOfRegistry != null"> + <span data-original-title="<s:property value="portOfRegistry.description"/>" data-toggle="tooltip" data-placement="bottom"> + <s:property value="portOfRegistry.portCode"/> + </span> + </s:if> + </td> + </tr> + </s:iterator> + </todby> + </table> + + <%-- Pagination --%> + <div class="pagination"> + <ul> + <s:url var="fullUrl" includeParams="get"/> + <s:set var="paginationUrl" value="%{getPaginationUrl(#fullUrl)}"/> + <s:if test="firstRangePage > 2"> + <li> + <a href="${paginationUrl}0">1</a> + </li> + <li> + <a href="${paginationUrl}1">2</a> + </li> + <li> + <span>...</span> + </li> + </s:if> + + <s:iterator var="currentPage" begin="firstRangePage" end="lastRangePage"> + <li class="<s:if test="#currentPage - 1 == pagination.currentPage.pageNumber">active</s:if>"> + <a href="${paginationUrl}${currentPage - 1}"> + <s:property/> + </a> + </li> + </s:iterator> + + <s:if test="lastRangePage < pagination.pageCount - 1"> + <li> + <span>...</span> + </li> + <li> + <a href="${paginationUrl}${pagination.pageCount - 2}"> + <s:property value="pagination.pageCount - 1"/> + </a> + </li> + <li> + <a href="${paginationUrl}${pagination.pageCount - 1}"> + <s:property value="pagination.pageCount"/> + </a> + </li> + </s:if> + </ul> + </div> + </div> + + <s:if test="authenticatedWaoUser.authorizedToViewBoatDetails"> + + <div> + <div class="arrow-right"></div> + <div id="boat-details"> + <div class="alert alert-info"> + <s:text name="wao.ui.tip.youMustChooseBoat" /> + </div> + </div> + </div> + </s:if> + +</div> + +</html> Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/contacts.jsp (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/contacts.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/contacts.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/contacts.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,630 @@ +<%-- + #%L + Wao :: Web + %% + Copyright (C) 2009 - 2014 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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + +<head> + <title> + <s:text name="wao.ui.page.Contacts.title"/> + </title> + + <script> + + $(document).ready(function () { + + var contactsFilterMappings = [ + <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + { + filterName: 'sampleRowFilter.companyIds', + filterLabel: "<s:text name="wao.ui.entity.Company"/>", + filterValuesField: 'sampleRowsFilterValues.companies', + }, + </s:if> + { + filterName: 'sampleRowFilter.sampleRowCodes', + filterLabel: "<s:text name="wao.ui.field.SampleRow.code"/>", + filterValuesField: 'sampleRowsFilterValues.sampleRowCodes', + }, + { + filterName: 'sampleRowFilter.programNames', + filterLabel: "<s:text name="wao.ui.field.SampleRow.programName"/>", + filterValuesField: 'sampleRowsFilterValues.programNames', + }, + { + filterName: 'sampleRowFilter.fishingZoneFacadeNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.facadeName"/>", + filterValuesField: 'sampleRowsFilterValues.fishingZoneFacadeNames', + }, + { + filterName: 'sampleRowFilter.fishingZoneSectorNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.sectorName"/>", + filterValuesField: 'sampleRowsFilterValues.fishingZoneSectorNames', + }, + <s:if test="obsVente"> + { + filterName: 'terrestrialLocationIds', + filterLabel: "<s:text name="wao.ui.field.Contact.terrestrialLocation"/>", + filterValuesField: 'terrestrialLocations' + }, + </s:if> + { + filterName: 'sampleRowFilter.fishingGearDcfIds', + filterLabel: "<s:text name="wao.ui.entity.fishingGearDCF"/>", + filterValuesField: 'sampleRowsFilterValues.fishingGearDcfs', + }, + { + filterName: 'sampleRowFilter.targetSpeciesDcfIds', + filterLabel: "<s:text name="wao.ui.entity.targetSpeciesDCF"/>", + filterValuesField: 'sampleRowsFilterValues.targetSpeciesDcfs', + }, + <s:if test="authenticatedWaoUser.authorizedToFilterOnBoats"> + { + filterName: 'boatFilter.boatIds', + filterLabel: "<s:text name="wao.ui.entity.Boat"/>", + filterValuesField: 'boatsFilterValues.boats', + minimumInputLength: 3 + }, + </s:if> + { + filterName: 'boatFilter.districtIds', + filterLabel: "<s:text name="wao.ui.field.Boat.district"/>", + filterValuesField: 'boatsFilterValues.districts' + }, + { + filterName: 'observerIds', + filterLabel: "<s:text name="wao.ui.misc.observer"/>", + filterValuesField: 'observers' + }, + { + filterName: 'contactStates', + filterLabel: "<s:text name="wao.ui.field.Contact.contactState"/>", + filterValuesField: 'contactStates' + }, + { + filterName: 'companyAcceptations', + filterLabel: "<s:text name="wao.ui.field.Contact.validationCompany"/>", + filterValuesField: 'companyAcceptations' + }, + { + filterName: 'programAcceptations', + filterLabel: "<s:text name="wao.ui.field.Contact.validationProgram"/>", + filterValuesField: 'programAcceptations' + }, + <s:if test="obsMer"> + { + filterName: 'observedDataControls', + filterLabel: "<s:text name="wao.ui.field.Contact.observedDataControl"/>", + filterValuesField: 'observedDataControls' + }, + </s:if> + <s:if test="obsVente"> + { + filterName: 'sampleRowFilter.terrestrialDistrictIds', + filterLabel: "<s:text name="wao.ui.field.SampleRow.terrestrialLocation"/>", + filterValuesField: 'sampleRowsFilterValues.terrestrialDistricts' + }, + { + filterName: 'sampleRowFilter.samplingStrategies', + filterLabel: "<s:text name="wao.ui.field.SampleRow.samplingStrategy"/>", + filterValuesField: 'sampleRowsFilterValues.samplingStrategies' + }, + { + filterName: 'actualSamplingStrategies', + filterLabel: "<s:text name="wao.ui.field.Contact.samplingStrategy"/>", + filterValuesField: 'actualSamplingStrategies' + }, + { + filterName: 'completeSamplings', + filterLabel: "<s:text name="wao.ui.field.Contact.completeSampling"/>", + filterValuesField: 'completeSamplings' + }, + </s:if> + { + filterName: 'dataReliabilities', + filterLabel: "<s:text name="wao.ui.field.Contact.dataReliability"/>", + filterValuesField: 'dataReliabilities' + } + ]; + + filter = <s:property value="filter" escapeHtml="false"/>; + + contactsFilterController2 = new FilterController2(contactsFilterMappings, filter, WAO.CONTACTS_FILTER_VALUES_JSON_URL, $('#contacts-filters-form fieldset.extra-filters')); + contactsFilterController2.init(); + + $('#switch-compact-full-view').click(function () { + $('#switch-compact-full-view').toggleClass('full-view').toggleClass('compact-view'); + $('table.contacts-list').toggleClass('full-view').toggleClass('compact-view'); + }); + + $('.validation-action').click(function(e) { + e.preventDefault(); + var $action = $(this); + var url = $action.attr('href'); + var successCallback = function (data) { + var successful = data['successful']; + if (successful) { + var success = data['successMessage']; + WAO.notifications.success(success); + var $tr = $('#contacts-list').find('tr[data-contactId="' + data.contactId + '"]'); + $tr.removeClass('accepted-by-company refused-by-company accepted-by-program refused-by-program'); + if (data.validationCompany) { + $tr.addClass('accepted-by-company'); + } else if (data.validationCompany === false) { + $tr.addClass('refused-by-company'); + } + if (data.validationProgram) { + $tr.addClass('accepted-by-program'); + } else if (data.validationProgram === false) { + $tr.addClass('refused-by-program'); + } + } else { + var error = data['errorMessage']; + WAO.notifications.error(error); + } + }; + WAO.post(url, {}, successCallback); + }); + + // Do not expose any struts internal input fields + $('input[type="hidden"][id^="__"]').prop('disabled', true); + }); + + </script> + +</head> + +<content tag="mainClass">large</content> +<content tag="contactsMenuItemClass">active</content> + +<s:form method="GET" id="contacts-filters-form" cssClass="filters-form"> + + <fieldset> + + <s:textfield name="filter.periodFrom" + label="%{getText('wao.ui.form.periodFrom')}" + placeholder="%{getFilterPeriodFromPlaceholder()}" + cssClass="input-small"/> + + <s:textfield name="filter.periodTo" + label="%{getText('wao.ui.form.period.to')}" + placeholder="%{getFilterPeriodToPlaceholder()}" + cssClass="input-small"/> + + <div title="<s:text name="wao.ui.form.filterOnObservationBeginDate.tooltip"/>"> + <s:checkbox name="filter.filterOnObservationBeginDate" + label="%{getText('wao.ui.form.filterOnObservationBeginDate')}"/> + </div> + + </fieldset> + + <fieldset class="extra-filters"> + + </fieldset> + + <fieldset> + + <s:checkbox name="filter.mammalsObservationOnly" + label="%{getText('wao.ui.misc.observations')}"/> + + <s:checkbox name="filter.mammalsCaptureOnly" + label="%{getText('wao.ui.field.Contact.mammalsCapture')}"/> + + <s:checkbox name="filter.commentDefinedOnly" + label="%{getText('wao.ui.field.Contact.comment')}"/> + + <s:checkbox name="filter.commentCompanyDefinedOnly" + label="%{getText('wao.ui.field.Contact.commentCompany')}"/> + + <s:checkbox name="filter.commentAdminDefinedOnly" + label="%{getText('wao.ui.field.Contact.commentAdmin')}"/> + + </fieldset> + + <fieldset> + + <s:checkbox name="filter.sortedByBoardingDate" + label="%{getText('wao.ui.form.sortByTideBegin')}"/> + + </fieldset> + + <div class="form-actions"> + + <s:submit type="button" action="contacts!applyFilter" cssClass="btn btn-primary"> + <i class="icon-filter"></i> <s:text name="wao.ui.action.filter"/> + </s:submit> + + <s:submit type="button" action="contacts!resetFilter" cssClass="btn"> + <i class="icon-trash"></i> <s:text name="wao.ui.action.reset"/> + </s:submit> + + <s:if test="authenticatedWaoUser.authorizedToExportContacts"> + <s:submit action="export-contacts" type="button" cssClass="btn"> + <i class="icon-download"></i> <s:text name="wao.ui.action.csvExport"/> + </s:submit> + </s:if> + + </div> + +</s:form> + +<h3> + <s:text name="wao.ui.contacts.title"> + <s:param value="%{pagination.count}"/> + </s:text> +</h3> + +<s:set name="pagination"> + <%-- Pagination --%> + <div class="pagination"> + <ul> + <s:url var="fullUrl" includeParams="get"/> + <s:set var="paginationUrl" value="%{getPaginationUrl(#fullUrl)}"/> + <s:if test="firstRangePage > 2"> + <li> + <a href="${paginationUrl}0">1</a> + </li> + <li> + <a href="${paginationUrl}1">2</a> + </li> + <li> + <span>...</span> + </li> + </s:if> + + <s:iterator var="currentPage" begin="firstRangePage" end="lastRangePage"> + <li class="<s:if test="#currentPage - 1 == pagination.currentPage.pageNumber">active</s:if>"> + <a href="${paginationUrl}${currentPage - 1}"> + <s:property/> + </a> + </li> + </s:iterator> + + <s:if test="lastRangePage < pagination.pageCount - 1"> + <li> + <span>...</span> + </li> + <li> + <a href="${paginationUrl}${pagination.pageCount - 2}"> + <s:property value="pagination.pageCount - 1"/> + </a> + </li> + <li> + <a href="${paginationUrl}${pagination.pageCount - 1}"> + <s:property value="pagination.pageCount"/> + </a> + </li> + </s:if> + </ul> + </div> +</s:set> + +<s:set var="fullView" value="%{fullView}"/> + +<div class="sticky-buttons"> + <button type="button" id="switch-compact-full-view" class="btn <s:if test="fullView">full-view</s:if><s:else>compact-view</s:else>"> + <span class="only-in-compact-view"> + <i class="fa fa-expand"></i><span class="only-on-hover"> <s:text name="wao.ui.action.switchToFullView" /></span> + </span> + <span class="only-in-full-view"> + <i class="fa fa-compress"></i><span class="only-on-hover"> <s:text name="wao.ui.action.switchToCompactView" /></span> + </span> + </button> +</div> + + +<s:property value="#pagination" escapeHtml="false"/> + +<table id="contacts-list" class="contacts-list large-table table-striped <s:if test="fullView">full-view</s:if><s:else>compact-view</s:else>"> + <thead> + <tr> + <th><s:text name="wao.ui.field.Contact.creationDate"/></th> + <th><s:text name="wao.ui.contacts.boatName"/></th> + <th><s:text name="wao.ui.field.Contact.sampleRow"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.programName"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.professionCode"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.contacts.Profession.libelle"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.contacts.Profession.species"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.contacts.FishingZone.facadeName"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.contacts.FishingZone.sectorName"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.contacts.division"/></th> + <s:if test="obsVente"> + <th><s:text name="wao.ui.field.Contact.terrestrialLocation"/></th> + <th><s:text name="wao.ui.field.SampleRow.samplingStrategy"/></th> + </s:if> + <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.company"/></th> + <th><s:text name="wao.ui.contacts.observers"/></th> + <th><s:text name="wao.ui.field.Contact.contactState"/> (<s:text name="wao.ui.field.Contact.contactStateMotif"/>)</th> + <th class="date-time"><s:text name="wao.ui.field.Contact.beginDate"/></th> + <th class="date-time"><s:text name="wao.ui.field.Contact.endDate"/></th> + <s:if test="obsMer"> + <th class="date-time"><s:text name="wao.ui.field.Contact.observationTimeInDays"/></th> + </s:if> + <th class="date"><s:text name="wao.ui.field.Contact.dataInputDate"/></th> + <s:if test="obsMer"> + <th><s:text name="wao.ui.field.Contact.observedDataControl"/></th> + <th class="date"><s:text name="wao.ui.field.Contact.restitution"/></th> + <th><s:text name="wao.ui.contacts.observations"/></th> + </s:if> + <s:if test="obsVente"> + <th><s:text name="wao.ui.field.Contact.samplingStrategy"/></th> + <th><s:text name="wao.ui.field.Contact.completeSampling"/></th> + </s:if> + <s:if test="authenticatedWaoUser.authorizedToViewContactsComments"> + <th><s:text name="wao.ui.field.Contact.comment"/></th> + <th><s:text name="wao.ui.field.Contact.commentCompany"/></th> + <th><s:text name="wao.ui.field.Contact.commentAdmin"/></th> + </s:if> + <s:if test="obsMer"> + <th><s:text name="wao.ui.field.Contact.dataReliability"/></th> + </s:if> + <th><s:text name="wao.ui.contacts.validation"/></th> + <th><s:text name="wao.ui.actions"/></th> + </tr> + </thead> + <tbody> + + <s:iterator value="contacts" var="contact"> + <s:set name="trCssClasses">contact-row<s:if test="topiaId.equals(contactToHighlightId)"> highlight</s:if><s:if test="validationCompany==null"></s:if><s:elseif test="validationCompany"> accepted-by-company</s:elseif><s:else> refused-by-company</s:else><s:if test="validationProgram==null"></s:if><s:elseif test="validationProgram"> accepted-by-program</s:elseif><s:else> refused-by-program</s:else></s:set> + <tr class="<s:property value="#trCssClasses"/>" data-contactId="<s:property value="topiaId"/>"> + <td> + <s:property value="creationDate"/> + </td> + <td> + <s:set name="boatTooltip"> + <s:text name="wao.ui.boats.registrationCode"/> <s:property value="%{'' + boat.immatriculation}" escapeHtml="false"/> + <s:text name="wao.ui.boats.boatLength"/> <s:property value="boat.boatLength" escapeHtml="false"/> cm + <s:text name="wao.ui.boats.buildYear"/> <s:property value="%{'' + boat.buildYear}" escapeHtml="false"/> + <s:text name="wao.ui.boats.district"/> <s:property value="boat.district.districtName" escapeHtml="false"/> (<s:property value="boat.district.districtCode" escapeHtml="false"/>) + </s:set> + <span data-original-title="<s:property value="#boatTooltip"/>" data-toggle="tooltip" data-placement="right"> + <s:property value="boat.name"/> + </span> + </td> + <td class="only-in-compact-view"> + <s:set name="sampleRowTooltip"> + <s:text name="wao.ui.field.SampleRow.programName"/> <s:property value="sampleRow.programName" escapeHtml="false"/> + <s:text name="wao.ui.field.SampleRow.professionCode"/> <s:property value="sampleRow.professionDescription" escapeHtml="false"/> + <s:text name="wao.ui.contacts.Profession.libelle"/> <s:property value="sampleRow.profession.libelle" escapeHtml="false"/> + <s:text name="wao.ui.contacts.Profession.species"/> <s:property value="sampleRow.profession.species" escapeHtml="false"/> + <s:text name="wao.ui.contacts.FishingZone.facadeName"/> <s:property value="sampleRow.facade" escapeHtml="false"/> + <s:text name="wao.ui.contacts.FishingZone.sectorName"/> <s:property value="sampleRow.sectors" escapeHtml="false"/> + <s:text name="wao.ui.contacts.division"/> <s:property value="%{getDivision(sampleRow)}" escapeHtml="false"/> + </s:set> + <span data-original-title="<s:property value="#sampleRowTooltip"/>" data-toggle="tooltip" data-placement="right"> + <s:property value="sampleRow.code"/> + </span> + </td> + <td class="only-in-full-view"> + <s:property value="sampleRow.code"/> + </td> + <td class="only-in-full-view"> + <s:property value="sampleRow.programName"/> + </td> + <td class="only-in-full-view"> + <s:iterator value="getDcf5CodesAndDescriptions(sampleRow)"> + <abbr title="<s:property value="value"/>"><s:property value="key"/></abbr> + </s:iterator> + <s:property value="sampleRow.professionDescriptionWithoutDCF5" /> + </td> + <td class="only-in-full-view"> + <s:property value="sampleRow.profession.libelle"/> + </td> + <td class="only-in-full-view"> + <s:property value="sampleRow.profession.species"/> + </td> + <td class="only-in-full-view"> + <s:property value="sampleRow.facade"/> + </td> + <td class="only-in-full-view"> + <s:property value="sampleRow.sectors"/> + </td> + <td class="only-in-full-view"> + <s:property value="%{getDivision(sampleRow)}"/> + </td> + <s:if test="obsVente"> + <td> + <s:property value="terrestrialLocation.description"/> + </td> + <td> + <s:if test="sampleRow.samplingStrategy != null"> + <s:text name="%{sampleRow.samplingStrategy.i18nKey}"/> + </s:if> + </td> + </s:if> + <td class="only-in-full-view"> + <s:property value="sampleRow.company.name"/> + </td> + <td> + <ul> + <s:iterator value="allObservers"> + <li><s:property value="fullName"/></li> + </s:iterator> + </ul> + </td> + <td> + <s:text name="%{contactState.i18nKey}"/> + <s:if test="contactStateMotif != null"> + <s:property value="contactStateMotif.name"/> + </s:if> + </td> + <td class="date-time"> + <s:if test="observationBeginDate != null"> + <s:property value="observationBeginDate"/> + </s:if> + </td> + <td class="date-time"> + <s:if test="observationEndDate != null"> + <s:property value="observationEndDate"/> + </s:if> + </td> + <s:if test="obsMer"> + <td> + <s:if test="observationTimeInDays != null"> + <s:property value="observationTimeInDays"/> + </s:if> + </td> + </s:if> + <td class="date"> + <s:if test="dataInputDate != null"> + <s:property value="dataInputDate"/> + </s:if> + </td> + <s:if test="obsMer"> + <td> + <s:if test="observedDataControl != null"> + <s:text name="%{observedDataControl.i18nKey}"/> + </s:if> + </td> + <td class="date"> + <s:if test="restitution != null"> + <s:property value="restitution"/> + </s:if> + </td> + <td class="align-center"> + <s:if test="mammalsObservation"> + <i class="fa fa-eye" + title="<s:text name="wao.ui.field.Contact.mammalsObservation"/>"></i> + </s:if> + <s:if test="mammalsCapture"> + <img src="<s:url value="/img/hook-22px.png"/>" + alt="<s:text name="wao.ui.field.Contact.mammalsCapture"/>" + title="<s:property value="mammalsInfo" escapeHtml="false"/>"/> + </s:if> + </td> + </s:if> + <s:if test="obsVente"> + <td> + <s:if test="samplingStrategy != null"> + <s:text name="%{samplingStrategy.i18nKey}"/> + </s:if> + </td> + <td> + <s:if test="completeSampling == null"> + </s:if> + <s:elseif test="completeSampling"> + <s:text name="wao.ui.misc.yes"/> + </s:elseif> + <s:else> + <s:text name="wao.ui.misc.no"/> + </s:else> + </td> + </s:if> + <s:if test="authenticatedWaoUser.authorizedToViewContactsComments"> + <td class="align-center"> + <s:if test=" ! comment.empty"> + <i title="<s:property value="comment" escapeHtml="false"/>" class="fa fa-comment"></i> + </s:if> + </td> + <td class="align-center"> + <s:if test=" ! commentCoordinator.empty"> + <i title="<s:property value="commentCoordinator" escapeHtml="false"/>" class="fa fa-comment"></i> + </s:if> + </td> + <td class="align-center"> + <s:if test=" ! commentAdmin.empty"> + <i title="<s:property value="commentAdmin" escapeHtml="false"/>" class="fa fa-comment"></i> + </s:if> + </td> + </s:if> + <s:if test="obsMer"> + <td> + <s:if test="isBoardingDone(#contact)"> + <s:if test="validationCompany"> + <s:text name="%{dataReliability.i18nKey}"/> + </s:if> + </s:if> + </td> + </s:if> + <td> + <span class="fa-stack fa-lg" title="<s:text name="wao.ui.misc.validated"/>"> + <i class="fa fa-square-o fa-stack-2x"></i> + <i class="fa fa-check fa-stack-1x only-if-accepted-by-company"></i> + <i class="fa fa-times fa-stack-1x only-if-refused-by-company"></i> + </span> + <span class="fa-stack fa-lg" title="<s:text name="wao.ui.misc.validated"/>"> + <i class="fa fa-square-o fa-stack-2x"></i> + <i class="fa fa-check fa-stack-1x only-if-accepted-by-program"></i> + <i class="fa fa-times fa-stack-1x only-if-refused-by-program"></i> + </span> + </td> + <td class="actions"> + <div class="dropdown"> + <a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> + <s:text name="wao.ui.actions"/> + <b class="caret"></b> + </a> + <ul class="dropdown-menu"> + <li> + <s:if test="authenticatedWaoUser.admin"> + <s:set name="focusAnchor">adminFocus</s:set> + </s:if> + <s:else> + <s:set name="focusAnchor">coordinatorOrObserverFocus</s:set> + </s:else> + <s:url action="edit-contact!input" id="editContactUrl" anchor='%{focusAnchor}'> + <s:param name="contactId" value="topiaId"/> + </s:url> + <s:a href="%{editContactUrl}"> + <i class="icon-edit"></i> <s:text name="wao.ui.action.editOrDeleteContact"/> + </s:a> + </li> + <s:if test="authenticatedWaoUser.authorizedToChangeContactValidation"> + <li> + <s:url action="validate-contact-json" id="acceptContactUrl" escapeAmp="false"> + <s:param name="contactId" value="topiaId"/> + <s:param name="validationState">true</s:param> + </s:url> + <s:set name="disabled"><s:if test="%{ ! isAcceptable(#contact)}">disabled</s:if></s:set> + <s:a cssClass="validation-action" href="%{acceptContactUrl}"> + <s:text name="wao.ui.action.acceptContact"/> + </s:a> + </li> + <li> + <s:url action="validate-contact-json" id="refuseContactUrl" escapeAmp="false"> + <s:param name="contactId" value="topiaId"/> + <s:param name="validationState">false</s:param> + </s:url> + <s:a cssClass="validation-action" href="%{refuseContactUrl}"> + <s:text name="wao.ui.action.refuseContact"/> + </s:a> + </li> + <li> + <s:url action="validate-contact-json" id="unvalidateContactUrl"> + <s:param name="contactId" value="topiaId"/> + </s:url> + <s:a cssClass="validation-action" href="%{unvalidateContactUrl}"> + <s:text name="wao.ui.action.unvalidateContact"/> + </s:a> + </li> + </s:if> + </ul> + </div> + </td> + </tr> + </s:iterator> + </todby> +</table> + +<s:property value="#pagination" escapeHtml="false"/> + +</html> Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,366 @@ +<%-- + #%L + Wao :: Web + %% + Copyright (C) 2009 - 2014 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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> +<head> + <title> + <s:if test="updateContactCommand.creation"> + <s:text name="wao.ui.contact.creation"/> + </s:if> + <s:else> + <s:text name="wao.ui.contact.edition"/> + </s:else> + </title> + <script> + + $(document).ready(function () { + + <s:if test="contact.obsProgram.obsMer"> + var $mammalsCaptureCheckbox = $('#mammalsCaptureCheckbox'); + var $mammalsInfo = $('#mammalsInfo'); + + var showHideMammalsInfo = function () { + if ($mammalsCaptureCheckbox.prop('checked')) { + $mammalsInfo.show(); + } else { + $mammalsInfo.hide(); + } + }; + + $mammalsCaptureCheckbox.change(showHideMammalsInfo); + showHideMammalsInfo(); + + var $contactStateMotif = $('#contactStateMotif'); + var $contactStateSelect = $('select[name="updateContactCommand.contact.contactState"]'); + + var showHideContactStateMotif = function () { + var contactState = $contactStateSelect.val(); + if (contactState === 'CONTACT_REFUSED' || contactState === 'CONTACT_DEFINITELY_REFUSED') { + $contactStateMotif.show(); + } else { + $contactStateMotif.hide(); + } + }; + + $contactStateSelect.change(showHideContactStateMotif); + showHideContactStateMotif(); + + </s:if> + + $('#delete-contact-link').click(function (e) { + if ( ! confirm("<s:text name="wao.ui.action.deleteContact.confirm"/>")) { + e.preventDefault(); + } + }) + + }); + + </script> + <content tag="mainClass">form</content> +</head> + + <div class="form-wrapper"> + <h1> + <s:if test="updateContactCommand.creation"> + <s:text name="wao.ui.contact.creation"/> + </s:if> + <s:else> + <s:text name="wao.ui.contact.edition"/> + </s:else> + </h1> + + <aside class="well"> + + <h2><s:text name="wao.ui.misc.information"/></h2> + + <s:text name="wao.ui.form.Contact.contactCreatedOn"> + <s:param value="%{formatDate(updateContactCommand.contact.creationDate)}"/> + </s:text> + + <h3><s:text name="wao.ui.field.Contact.boat"/></h3> + + <table class="table"> + <tbody> + <tr> + <th> + <s:text name="wao.ui.field.Boat.name"/> + </th> + <td> + <s:property value="updateContactCommand.contact.boat.name"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Boat.immatriculation"/> + </th> + <td> + <s:property value="updateContactCommand.contact.boat.immatriculation"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Boat.districtCode"/> + </th> + <td> + <s:property value="updateContactCommand.contact.boat.districtCode"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Boat.boatLength"/> + </th> + <td> + <s:property value="%{'' + updateContactCommand.contact.boat.boatLength}"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.Boat.buildYear"/> + </th> + <td> + <s:property value="%{'' + updateContactCommand.contact.boat.buildYear}"/> + </td> + </tr> + </tbody> + </table> + + <h3><s:text name="wao.ui.field.Contact.sampleRow"/></h3> + + <table class="table"> + <tbody> + <tr> + <th> + <s:text name="wao.ui.field.SampleRow.profession"/> + </th> + <td> + <s:property value="updateContactCommand.contact.sampleRow.professionDescription"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.SampleRow.programName"/> + </th> + <td> + <s:property value="updateContactCommand.contact.sampleRow.programName"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.SampleRow.periodBegin"/> + </th> + <td> + <s:property value="%{formatMonth(updateContactCommand.contact.sampleRow.periodBegin)}"/> + </td> + </tr> + <tr> + <th> + <s:text name="wao.ui.field.SampleRow.periodEnd"/> + </th> + <td> + <s:property value="%{formatMonth(updateContactCommand.contact.sampleRow.periodEnd)}"/> + </td> + </tr> + </tbody> + </table> + + </aside> + + <s:form> + + <s:set name="editObservationReport" + value="%{authenticatedWaoUser.isAuthorizedToEditObservationReport(updateContactCommand.contact)}"/> + + <s:hidden name="contactId" value="%{contactId}"/> + + <fieldset> + <legend><s:text name="wao.ui.misc.observers"/></legend> + + <s:select name="updateContactCommand.mainObserverId" + value="%{updateContactCommand.mainObserverId}" + label="%{getText('wao.ui.field.Contact.mainObserver')}" + list="observers" + emptyOption="true" + disabled="%{!#editObservationReport}" + cssClass="input-large" + /> + + <s:select name="updateContactCommand.secondaryObserverIds" + value="%{updateContactCommand.secondaryObserverIds}" + label="%{getText('wao.ui.field.Contact.secondaryObservers')}" + list="observers" + multiple="true" + disabled="%{!#editObservationReport}" + cssClass="input-xlarge" + /> + + </fieldset> + + <%--Do not remove the id (use by contacts page)--%> + <fieldset id="coordinatorOrObserverFocus"> + <legend><s:text name="wao.ui.misc.observationReport"/></legend> + + <s:textfield name="updateContactCommand.contact.observationBeginDate" + label="%{getText('wao.ui.field.Contact.beginDate')}" + placeholder="%{getDateTimePlaceholder()}" + disabled="%{!#editObservationReport}"/> + + <s:textfield name="updateContactCommand.contact.observationEndDate" + label="%{getText('wao.ui.field.Contact.endDate')}" + placeholder="%{getDateTimePlaceholder()}" + disabled="%{!#editObservationReport}"/> + + <s:select name="updateContactCommand.contact.contactState" + label="%{getText('wao.ui.field.Contact.contactState')}" + requiredLabel="true" + list="contactStates" + disabled="%{!#editObservationReport}"/> + + <s:if test="updateContactCommand.contact.obsProgram.obsVente"> + + <s:select name="updateContactCommand.terrestrialLocationId" + value="%{updateContactCommand.terrestrialLocationId}" + label="%{getText('wao.ui.field.Contact.terrestrialLocation')}" + list="terrestrialLocations" + emptyOption="true" + disabled="%{!#editObservationReport}" + cssClass="input-xxlarge" + /> + + <s:select name="updateContactCommand.contact.samplingStrategy" + label="%{getText('wao.ui.field.Contact.samplingStrategy')}" + list="samplingStrategies" + emptyOption="true" + disabled="%{!#editObservationReport}"/> + + <s:checkbox name="updateContactCommand.contact.completeSampling" + label="%{getText('wao.ui.field.Contact.completeSampling')}" + disabled="%{!#editObservationReport}"/> + + </s:if> + + <s:if test="updateContactCommand.contact.obsProgram.obsMer"> + + <div id="contactStateMotif"> + <s:select name="updateContactCommand.contact.contactStateMotif" + value="%{updateContactCommand.contact.contactState.topiaId}" + label="%{getText('wao.ui.field.Contact.contactStateMotif')}" + list="contactStateMotives" + emptyOption="true" + disabled="%{!#editObservationReport}"/> + </div> + + <s:checkbox name="updateContactCommand.contact.mammalsObservation" + label="%{getText('wao.ui.field.Contact.mammalsObservation')}" + disabled="%{!#editObservationReport}"/> + + <s:checkbox name="updateContactCommand.contact.mammalsCapture" + id="mammalsCaptureCheckbox" + label="%{getText('wao.ui.field.Contact.mammalsCapture')}" + disabled="%{!#editObservationReport}"/> + + <div id="mammalsInfo"> + <s:textarea name="updateContactCommand.contact.mammalsInfo" + label="%{getText('wao.ui.field.Contact.mammalsInfo')}" + disabled="%{!#editObservationReport}"/> + <div class="alert"> + <s:text name="wao.ui.page.ContactForm.mammalsInfo.disclaimer"/> + </div> + </div> + + </s:if> + + <s:textfield name="updateContactCommand.contact.dataInputDate" + label="%{getText('wao.ui.field.Contact.dataInputDate')}" + placeholder="%{getDatePlaceholder()}" + disabled="%{!#editObservationReport}"/> + + <s:if test="updateContactCommand.contact.obsProgram.obsMer"> + + <s:select name="updateContactCommand.contact.observedDataControl" + label="%{getText('wao.ui.field.Contact.observedDataControl')}" + list="observedDataControls" + emptyOption="true" + disabled="%{!#editObservationReport || !authenticatedWaoUser.coordinator}"/> + + <s:textfield name="updateContactCommand.contact.restitution" + label="%{getText('wao.ui.field.Contact.restitution')}" + placeholder="%{getDatePlaceholder()}" + disabled="%{!#editObservationReport}"/> + + </s:if> + + <s:textarea name="updateContactCommand.contact.comment" + label="%{getText('wao.ui.field.Contact.comment')}" + placeholder="%{getText('wao.ui.misc.noComment')}" + disabled="%{!#editObservationReport || !authenticatedWaoUser.observer}"/> + + <s:textarea name="updateContactCommand.contact.commentCoordinator" + label="%{getText('wao.ui.field.Contact.commentCoordinator')}" + placeholder="%{getText('wao.ui.misc.noComment')}" + disabled="%{!#editObservationReport || !authenticatedWaoUser.coordinator}"/> + + </fieldset> + + <%--Do not remove the id (use by contacts page)--%> + <fieldset id="adminFocus"> + <legend><s:text name="wao.ui.form.programEvaluation"/></legend> + + <s:if test="authenticatedWaoUser.authorizedToDisplayContactDataReliability"> + <s:select name="updateContactCommand.contact.dataReliability" + label="%{getText('wao.ui.field.Contact.dataReliability')}" + list="dataReliabilities" + emptyOption="true" + disabled="%{!authenticatedWaoUser.isAuthorizedToEditContactDataReliability(updateContactCommand.contact)}"/> + </s:if> + + <s:textarea name="updateContactCommand.contact.commentAdmin" + label="%{getText('wao.ui.field.Contact.commentAdmin')}" + placeholder="%{getText('wao.ui.misc.noComment')}" + disabled="%{!authenticatedWaoUser.admin}"/> + </fieldset> + + <div class="form-actions"> + <s:url action="contacts" id="contactsUrl"/> + <s:a href="%{contactsUrl}" cssClass="btn"> + <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.cancel"/> + </s:a> + <s:if test="authenticatedWaoUser.isAuthorizedToEditContact(updateContactCommand.contact)"> + <s:submit type="button" cssClass="btn"> + <i class="icon-hdd"></i> <s:text name="wao.ui.action.save"/> + </s:submit> + </s:if> + + <s:if test=" ! updateContactCommand.creation && authenticatedWaoUser.isAuthorizedToDeleteContact(updateContactCommand.contact)"> + <s:url action="delete-contact" id="deleteContactUrl"> + <s:param name="contactId" value="contactId"/> + </s:url> + <s:a href="%{deleteContactUrl}" cssClass="btn pull-right" id="delete-contact-link"> + <i class="icon-trash"></i> <s:text name="wao.ui.action.deleteContact"/> + </s:a> + </s:if> + </div> + + </s:form> + </div> +</html> + Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,281 @@ +<%-- + #%L + Wao :: Web + %% + Copyright (C) 2009 - 2014 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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + <head> + <title> + <s:if test="updateSampleRowCommand.creation"> + <s:text name="wao.ui.sampleRow.creation" /> + </s:if> + <s:else> + <s:property value="t('wao.ui.sampleRow.edition', updateSampleRowCommand.sampleRow.code)" /> + </s:else> + </title> + <script> + + $(document).ready(function() { + + var expectedObservationsByMonths = <s:property value="updateSampleRowCommand.expectedObservationsByMonths" escapeHtml="false" />; + + var $expectedObservationsByMonthsTable = $('#expectedObservationsByMonthsTable'); + var $expectedObservationsByMonthsTableHead = $expectedObservationsByMonthsTable.find('thead'); + var $expectedObservationsByMonthsTableBody = $expectedObservationsByMonthsTable.find('tbody'); + var $periodBeginInput = $('input[name="updateSampleRowCommand.sampleRow.periodBegin"]'); + var $periodEndInput = $('input[name="updateSampleRowCommand.sampleRow.periodEnd"]'); + + var updateExpectedObservationsByMonthsTable = function() { + $expectedObservationsByMonthsTableHead.empty(); + $expectedObservationsByMonthsTableBody.empty(); + var periodBegin = moment($periodBeginInput.val(), 'MM/YYYY'); + var periodEnd = moment($periodEndInput.val(), 'MM/YYYY'); + if (periodBegin.isValid() && periodEnd.isValid()) { + if (periodBegin > periodEnd) { + $periodEndInput.val($periodBeginInput.val()); + periodEnd = moment($periodEndInput.val(), 'MM/YYYY'); + } + var months = []; + do { + months.push(periodBegin.format('YYYYMM')); + periodBegin.add('months', 1); + } while (periodBegin <= periodEnd); + $expectedObservationsByMonthsTableHead.append('<tr></tr>'); + $expectedObservationsByMonthsTableBody.append('<tr></tr>'); + $(months).each(function (index, month) { + var newInput = ' <td>' + + ' ' + moment(month, 'YYYYMM').format('MM/YYYY') + + ' </td>'; + $expectedObservationsByMonthsTableHead.find('tr').append(newInput); + }); + $(months).each(function (index, month) { + var value = ""; + if (expectedObservationsByMonths[month]) { + value = expectedObservationsByMonths[month]; + } + var newInput = ' <td>' + + ' <input type="number" name="expectedObservationsByMonths[\'' + month + '\']" value="' + value + '" class="input-small" />' + + ' </td>'; + $expectedObservationsByMonthsTableBody.find('tr').append(newInput); + }); + } + } + + updateExpectedObservationsByMonthsTable(); + + $periodBeginInput.change(updateExpectedObservationsByMonthsTable); + $periodEndInput.change(updateExpectedObservationsByMonthsTable); + + }); + + </script> + + <content tag="mainClass">form</content> + </head> + + + <s:if test="updateSampleRowCommand.observationAlreadyStarted"> + <div class="alert"> + <s:text name="wao.ui.form.SampleRow.warn.observationAlreadyStarted" /> + </div> + </s:if> + + <s:form> + + <h1> + <s:if test="updateSampleRowCommand.creation"> + <s:text name="wao.ui.sampleRow.creation" /> + </s:if> + <s:else> + <s:property value="t('wao.ui.sampleRow.edition', updateSampleRowCommand.sampleRow.code)" /> + </s:else> + </h1> + + <s:hidden name="sampleRowId" value="%{sampleRowId}" /> + + <fieldset> + + <legend><s:text name="wao.ui.field.SampleRow.profession" /></legend> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.libelle" + label="%{getText('wao.ui.field.SampleRow.libelle')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-xxlarge" /> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.size" + label="%{getText('wao.ui.field.SampleRow.size')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + inputAppend="m" + cssClass="input-small" /> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.meshSize" + label="%{getText('wao.ui.field.SampleRow.meshSize')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + inputAppend="mm" + cssClass="input-small" /> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.species" + label="%{getText('wao.ui.field.SampleRow.species')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-xxlarge" /> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.other" + label="%{getText('wao.ui.field.SampleRow.other')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-xxlarge" /> + + <s:select name="updateSampleRowCommand.dcf5CodesIds" + label="%{getText('wao.ui.field.SampleRow.dcf5Codes')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + list="updateSampleRowCommand.allDcf5Codes" + listValue="%{value.code}" + cssClass="input-xxlarge select2" + multiple="true" + /> + + </fieldset> + + <fieldset> + + <legend><s:text name="wao.ui.field.SampleRow.fishingZones" /></legend> + + <s:select name="updateSampleRowCommand.fishingZoneIds" + label="%{getText('wao.ui.field.SampleRow.fishingZones')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + list="updateSampleRowCommand.allFishingZones" + listValue="%{value.code}" + multiple="true" + cssClass="input-xxlarge" + /> + + <s:textfield name="updateSampleRowCommand.sampleRow.fishingZonesInfos" label="%{getText('wao.ui.field.SampleRow.fishingZonesInfos')}" cssClass="input-xxlarge" /> + + </fieldset> + + <fieldset> + + <legend><s:text name="wao.ui.form.SampleRow.program" /></legend> + + <s:textfield name="updateSampleRowCommand.sampleRow.programName" + label="%{getText('wao.ui.field.SampleRow.programName')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" /> + <s:textfield name="updateSampleRowCommand.sampleRow.periodBegin" + label="%{getText('wao.ui.field.SampleRow.periodBegin')}" + placeholder="04/2014" + cssClass="input-small" /> + <s:textfield name="updateSampleRowCommand.sampleRow.periodEnd" + label="%{getText('wao.ui.field.SampleRow.periodEnd')}" + placeholder="03/2015" + cssClass="input-small" /> + + + <div class="control-group"> + <label class="control-label"><s:text name="wao.ui.samplingPlan.effort" /></label> + <div class="controls"> + <table id="expectedObservationsByMonthsTable"> + <thead> + </thead> + <tbody> + </tbody> + </table> + </div> + </div> + + + </fieldset> + + <fieldset> + + <legend><s:text name="wao.ui.form.SampleRow.others" /></legend> + + <s:if test="updateSampleRowCommand.creation"> + <s:textfield name="updateSampleRowCommand.code" + label="%{getText('wao.ui.field.SampleRow.code')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-small" /> + </s:if> + + <s:select name="updateSampleRowCommand.companyId" + label="%{getText('wao.ui.field.SampleRow.company')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + list="updateSampleRowCommand.allCompanies" + listValue="%{value.name}" + cssClass="input-xxlarge" + /> + + <s:if test="updateSampleRowCommand.sampleRow.obsProgram.obsMer"> + + <s:textfield type="number" name="updateSampleRowCommand.sampleRow.nbObservants" label="%{getText('wao.ui.field.SampleRow.nbObservants')}" inputAppend="%{getText('wao.ui.unit.observers')}" cssClass="input-small"/> + + <%-- XXX brendan 19/05/14 ne pas mettre type="number" car avec le formatter qui mets la valeur avec ',' on a pas la valeur quand on modifie une ligne --%> + <s:textfield name="updateSampleRowCommand.sampleRow.averageTideTime" label="%{getText('wao.ui.field.SampleRow.averageTideTime')}" inputAppend="%{getText('wao.ui.unit.days')}" cssClass="input-small"/> + <s:textfield name="updateSampleRowCommand.sampleRow.appliedCoverageRate" label="%{getText('wao.ui.field.SampleRow.appliedCoverageRate')}" inputAppend="%" cssClass="input-small"/> + + </s:if> + + <s:if test="updateSampleRowCommand.sampleRow.obsProgram.obsVente"> + + <s:textfield type="number" name="updateSampleRowCommand.sampleRow.averageObservationsCount" label="%{getText('wao.ui.field.SampleRow.averageObservationsCount')}" inputAppend="%{getText('wao.ui.unit.observations')}" cssClass="input-small"/> + + </s:if> + + <s:textarea name="updateSampleRowCommand.elligibleBoatImmatriculations" label="%{getText('wao.ui.field.SampleRow.elligibleBoat')}" /> + + <s:textarea name="updateSampleRowCommand.sampleRow.comment" label="%{getText('wao.ui.field.SampleRow.comment')}" /> + + </fieldset> + + <s:if test=" ! updateSampleRowCommand.creation"> + + <fieldset> + + <legend><s:text name="wao.ui.form.editComment" /></legend> + + <s:text name="wao.ui.form.editionAuthor" /> <s:property value="updateSampleRowCommand.sampleRowLog.author.fullName" /> + + <s:textarea name="updateSampleRowCommand.sampleRowLog.comment" label="%{getText('wao.ui.form.editComment')}" requiredLabel="true" /> + + </fieldset> + + </s:if> + + <div class="form-actions"> + <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> + <s:a href="%{samplingPlanUrl}" cssClass="btn"> + <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.cancel" /> + </s:a> + <s:submit type="button" cssClass="btn"> + <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> + </s:submit> + <s:if test=" ! updateSampleRowCommand.creation"> + <s:url action="delete-sample-row" id="deleteSampleRowUrl"> + <s:param name="sampleRowId" value="sampleRowId" /> + </s:url> + <s:a href="%{deleteSampleRowUrl}" cssClass="btn pull-right"> + <i class="icon-trash"></i> <s:text name="wao.ui.action.deleteSampleRow" /> + </s:a> + </s:if> + </div> + + </s:form> + +</html> + Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/import-contacts-input.jsp (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-contacts-input.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/import-contacts-input.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/import-contacts-input.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,55 @@ +<%-- + #%L + Wao :: Web + %% + Copyright (C) 2009 - 2014 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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + +<head> + <title><s:text name="wao.ui.import.contacts" /></title> + <content tag="mainClass">form</content> +</head> + +<s:form action="import-contacts" method="POST" enctype="multipart/form-data"> + + <h1><s:text name="wao.ui.import.contacts" /></h1> + + <div class="alert alert-info"> + <s:text name="wao.ui.import.disclaimer" /> + </div> + + <fieldset> + <legend> + <s:text name="wao.ui.import.contacts" /> + </legend> + + <s:file name="csvFile" /> + + <div class="form-actions"> + <s:submit type="button" cssClass="btn"> + <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/> + </s:submit> + </div> + </fieldset> + +</s:form> + +</html> \ No newline at end of file Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/import-sampling-plan-input.jsp (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-sampling-plan-input.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/import-sampling-plan-input.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/import-sampling-plan-input.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,55 @@ +<%-- + #%L + Wao :: Web + %% + Copyright (C) 2009 - 2014 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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + + <head> + <title><s:text name="wao.ui.import.samplingPlan" /></title> + <content tag="mainClass">form</content> + </head> + + <s:form action="import-sampling-plan" method="POST" enctype="multipart/form-data"> + + <h1><s:text name="wao.ui.import.samplingPlan" /></h1> + + <div class="alert alert-info"> + <s:text name="wao.ui.import.disclaimer" /> + </div> + + <fieldset> + <legend> + <s:text name="wao.ui.import.samplingPlan" /> + </legend> + + <s:file name="csvFile" /> + + <div class="form-actions"> + <s:submit type="button" cssClass="btn"> + <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/> + </s:submit> + </div> + </fieldset> + + </s:form> + +</html> Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,402 +0,0 @@ -<%-- - #%L - Wao :: Web - %% - Copyright (C) 2009 - 2014 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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> -<%@taglib uri="/struts-tags" prefix="s" %> - -<script> - $(document).ready(function () { - - // le formulaire concernant l'interlocuteur - - var $boatInfosForm = $('#boat-infos-form'); - var $saveBoatInfosButton = $('#save-boat-infos'); - var $unlockBoatInfosFormButton = $('#unlock-boat-infos-form'); - - $saveBoatInfosButton.click(function () { - $boatInfosForm.find('input, textarea').attr('readonly', 'readonly'); - $saveBoatInfosButton.attr('disabled', 'disabled'); - $unlockBoatInfosFormButton.removeAttr('disabled'); - var data = WAO.toData($boatInfosForm); - var successCallback = function () { - WAO.notifications.success('<s:text name="wao.ui.form.BoatInfos.success"/>'); - } - WAO.post(WAO.OBSMER_UPDATE_BOAT_INFOS_JSON_URL, data, successCallback); - }); - - $unlockBoatInfosFormButton.click(function () { - $boatInfosForm.find('input[readonly], button, textarea').removeAttr('readonly').removeAttr('disabled'); - $unlockBoatInfosFormButton.attr('disabled', 'disabled'); - }); - - - // le calcul des sollicitations - - var $boatContactsCountForm = $('#boat-contacts-count-form'); - var $boatContactsCountsTable = $('#boat-contacts-counts-table'); - - $boatContactsCountsTable.hide(); - - var getBoatContactsCount = function () { - var data = WAO.toData($boatContactsCountForm); - var since = data.since; - var successCallback = function (data) { - var tr = '<tr>' - + ' <td>' - + since - + ' </td>' - + ' <td>' - + data.boatContactsCounts.contactsCompanyCount - + ' (' + data.boatContactsCounts.observationsCompanyCount + ')' - + ' </td>' - + ' <td>' - + data.boatContactsCounts.contactsCount - + ' (' + data.boatContactsCounts.observationsCount + ')' - + ' </td>' - + '</tr>'; - $boatContactsCountsTable.find('tbody').append(tr); - $boatContactsCountsTable.show(); - }; - WAO.get(WAO.OBSMER_GET_BOAT_CONTACTS_COUNT_JSON_URL, data, successCallback); - } - - $('#get-boat-contacts-count').click(getBoatContactsCount); - $boatContactsCountForm.enterKey(getBoatContactsCount); - - // création d'un contact depuis une ligne éligible - - var $createContactFromBoatButton = $('#createContactFromBoatButton'); - var $sampleRowIdInput = $('input[name="sampleRowId"]'); - var expiredSampleRowIds = <s:property value="boatDetails.expiredSampleRowIds" escapeHtml="false"/> - $sampleRowIdInput.change(function () { - $createContactFromBoatButton.removeAttr('disabled'); - }); - $createContactFromBoatButton.click(function (e) { - var selectedSampleRowIsExpired = $.inArray($('input[name="sampleRowId"]:checked').val(), expiredSampleRowIds); - var confirmMessage = "<s:text name="wao.ui.contacts.createFromBoat.warn"/>"; - if (selectedSampleRowIsExpired && ! confirm(confirmMessage)) { - e.preventDefault(); - } - }); - - // suppresssion d'une éligibilité - $('.remove-boat-eligibility').click(function (e) { - e.preventDefault(); - if (confirm("<s:text name="wao.ui.removeBoatEligibility.confirm"/>")) { - var url = $(this).attr('href'); - var $toRemove = $(this).parents('.elligible-sample-row') - var successCallback = function (data) { - $toRemove.remove(); - }; - WAO.post(url, {}, successCallback); - } - }); - - }); -</script> - -<h2> - <s:text name="wao.ui.boatinfo.contacts"> - <s:param value="boatDetails.boatInfos.boat.name"/> - </s:text> -</h2> - -<h3> - <s:text name="wao.ui.boats.contacts.existing"/> -</h3> - -<s:if test="boatDetails.contactsCount > 0"> - - <h4> - <s:text name="wao.ui.contact.lastContact"/> - </h4> - - <table class="table"> - <tbody> - <tr> - <th> - <s:text name="wao.ui.field.Contact.creationDate"/> - </th> - <td> - <s:property value="boatDetails.mostRecentContact.creationDate"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Contact.mainObserver"/> - </th> - <td> - <s:property value="boatDetails.mostRecentContact.mainObserver.fullName"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Contact.contactState"/> - </th> - <td> - <s:property value="%{getText(boatDetails.mostRecentContact.contactState)}"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Contact.sampleRow"/> - </th> - <td> - <s:property value="boatDetails.mostRecentContact.sampleRow.code"/> - </td> - </tr> - </tbody> - </table> - - <s:url action="contacts" id="viewAssociatedContactsForBoatUrl"> - <s:param name="filter.boatFilter.registrationCode" value="boatDetails.boatInfos.boat.immatriculation"/> - <s:param name="filter.sampleRowFilter.companyIds" value="boatDetails.boatInfos.company.topiaId"/> - <s:param name="filter.periodFrom"/> - <s:param name="filter.periodTo"/> - </s:url> - <s:a href="%{viewAssociatedContactsForBoatUrl}"> - <s:text name="wao.ui.action.viewAssociatedContactsForBoat"> - <s:param value="boatDetails.contactsCount"/> - </s:text> - </s:a> - -</s:if> -<s:else> - <s:text name="wao.ui.boats.contacts.none"/> -</s:else> - -<h3> - <s:text name="wao.ui.contact.creation"/> -</h3> - -<s:if test="boatDetails.boatInfos.boat.active"> - <s:if test="startBoatSelectionForSampleRow == null"> - <s:if test="boatDetails.elligibleForSampleRows.empty"> - <s:text name="wao.ui.tip.boatDetails.elligibleForSampleRowsEmpty" /> - </s:if> - <s:else> - <s:text name="wao.ui.boats.associatedLine"/> - <s:if test="boatDetails.newContactCreatable && authenticatedWaoUser.authorizedToCreateContact"> - <s:form action="create-contact"> - - <s:hidden name="boatId" value="%{boatDetails.boatInfos.boat.topiaId}"/> - - <div class="control-group"> - <div class="controls"> - <s:iterator value="boatDetails.elligibleForSampleRows" status="status"> - <div class="elligible-sample-row"> - <s:set name="radioId">radio-<s:property value="#status.index"/></s:set> - <input type="radio" name="sampleRowId" id="<s:property value="#radioId"/>" value="<s:property value="topiaId"/>"/> - <%-- - <label for="<s:property value="%{#radioId}"/>" class="radio"> - <s:property value="code"/> - </label> - --%> - <s:property value="code"/> - <s:url action="update-boat-elligibility-json" id="updateBoatElligibilityUrl"> - <s:param name="boatId" value="boatDetails.boatInfos.boat.topiaId"/> - <s:param name="sampleRowId" value="topiaId"/> - <s:param name="active" value="false"/> - </s:url> - <s:a href="%{updateBoatElligibilityUrl}" cssClass="btn btn-link remove-boat-eligibility"> - <i class="icon-remove"></i> - </s:a> - </div> - </s:iterator> - </div> - </div> - - - <s:submit id="createContactFromBoatButton" type="button" cssClass="btn btn-success" disabled="true"> - <i class="icon-plus"></i> - <s:text name="wao.ui.contacts.createFromBoat"/> - </s:submit> - </s:form> - </s:if> - <s:else> - <ul> - <s:iterator value="boatDetails.elligibleForSampleRows"> - <li class="elligible-sample-row"> - <s:property value="code"/> - <s:url action="update-boat-elligibility-json" id="updateBoatElligibilityUrl"> - <s:param name="boatId" value="boatDetails.boatInfos.boat.topiaId"/> - <s:param name="sampleRowId" value="topiaId"/> - <s:param name="active" value="false"/> - </s:url> - <s:a href="%{updateBoatElligibilityUrl}" cssClass="btn btn-link remove-boat-eligibility"> - <i class="icon-remove"></i> - </s:a> - </li> - </s:iterator> - </ul> - </s:else> - </s:else> - <s:if test="authenticatedWaoUser.authorizedToCreateContact"> - <div class="alert alert-info"> - <s:text name="wao.ui.tip.useBoatSelectionForSampleRow"/> - </div> - </s:if> - </s:if> - <s:else> - <s:if test="boatDetails.newContactCreatable"> - <s:if test="boatDetails.newContactCreatable && authenticatedWaoUser.authorizedToCreateContact"> - <s:url action="create-contact" id="createContactUrl"> - <s:param name="boatId" value="boatDetails.boatInfos.boat.topiaId"/> - <s:param name="sampleRowId" value="startBoatSelectionForSampleRow.topiaId"/> - </s:url> - <s:a href="%{createContactUrl}" cssClass="btn btn-success"> - <i class="icon-plus"></i> - <s:text name="wao.ui.contacts.createFromBoatAndSelectedSampleRow"> - <s:param value="startBoatSelectionForSampleRow.code"/> - <s:param value="startBoatSelectionForSampleRow.professionDescription"/> - </s:text> - </s:a> - </s:if> - </s:if> - <s:else> - <div class="alert"> - <s:text name="wao.ui.tip.contactAlreadyExists"/> - </div> - </s:else> - </s:else> - -</s:if> -<s:else> - <div class="alert"> - <s:text name="wao.ui.tip.inactiveBoat"/> - </div> -</s:else> - -<h3> - <s:text name="wao.ui.boatDetails.boatContactsCounts.title"/> -</h3> - -<table id="boat-contacts-counts-table" class="table no-border-top"> - <thead> - <tr> - <td> - <s:text name="wao.ui.boatDetails.boatContactsCounts.since"/> - </td> - <td> - <s:text name="wao.ui.boatDetails.boatContactsCounts.contactsCompanyCount"/> - </td> - <td> - <s:text name="wao.ui.boatDetails.boatContactsCounts.contactsCount"/> - </td> - </thead> - <tbody> - </tbody> -</table> - -<s:form id="boat-contacts-count-form"> - - <s:hidden name="boatId" value="%{boatDetails.boatInfos.boat.topiaId}" /> - <s:hidden name="companyId" value="%{boatDetails.boatInfos.company.topiaId}" /> - - <div class="input-prepend input-append"> - - <span class="add-on"> - <s:text name="wao.ui.boatDetails.boatContactsCounts.since"/> - </span> - - <input name="since" type="text" value="<s:property value="%{oneYearAgoDatePlaceHolder}"/>"/> - - <button type="button" id="get-boat-contacts-count" class="btn"> - <i class="icon-plus"></i> <s:text name="wao.ui.boatDetails.boatContactsCounts.compute" /> - </button> - </div> -</s:form> - -<h2> - <s:text name="wao.ui.boatinfo.title"> - <s:param value="boatDetails.boatInfos.boat.name"/> - </s:text> -</h2> - -<h3> - <s:text name="wao.ui.boats.info"/> -</h3> - -<table class="table"> - <tbody> - <tr> - <th class="no-border-top"> - <s:text name="wao.ui.field.Boat.shipOwner"/> - </th> - <td class="no-border-top"> - <s:url action="boats" id="shipOwnerBoatsUrl"> - <s:param name="filter.shipOwnerIds" value="boatDetails.boatInfos.boat.shipOwner.topiaId"/> - </s:url> - <s:set name="shipOwnerBoatsTitle"> - <s:text name="wao.ui.action.viewShipOwnerBoats"/> - </s:set> - <s:a href="%{shipOwnerBoatsUrl}" title="%{shipOwnerBoatsTitle}"> - <s:property value="boatDetails.boatInfos.boat.shipOwner.firstName"/> - <s:property value="boatDetails.boatInfos.boat.shipOwner.lastName"/> - </s:a> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Boat.boatGroup"/> - </th> - <td> - <s:if test="boatDetails.boatInfos.boat.boatGroup == null"> - <s:text name="wao.ui.misc.N/A"/> - </s:if> - <s:else> - <s:property value="boatDetails.boatInfos.boat.boatGroup.description"/> - </s:else> - </td> - </tr> - </tbody> -</table> - -<h3> - <s:text name="wao.ui.boats.interlocutor"/> -</h3> - -<s:form id="boat-infos-form" cssClass="form-horizontal"> - - <s:hidden name="boatId" value="%{boatDetails.boatInfos.boat.topiaId}" /> - <s:hidden name="companyId" value="%{boatDetails.boatInfos.company.topiaId}" /> - - <s:textfield name="boatInfos.contactFirstName" value="%{boatDetails.boatInfos.contactFirstName}" label="%{getText('wao.ui.field.BoatInfos.contactFirstName')}" readonly="true" cssClass="input-large" /> - <s:textfield name="boatInfos.contactLastName" value="%{boatDetails.boatInfos.contactLastName}" label="%{getText('wao.ui.field.BoatInfos.contactLastName')}" readonly="true" cssClass="input-large" /> - <s:textfield type="email" name="boatInfos.contactEmail" value="%{boatDetails.boatInfos.contactEmail}" label="%{getText('wao.ui.field.BoatInfos.contactEmail')}" readonly="true" cssClass="input-large" /> - <s:textfield type="tel" name="boatInfos.contactPhoneNumber" value="%{boatDetails.boatInfos.contactPhoneNumber}" label="%{getText('wao.ui.field.BoatInfos.contactPhoneNumber')}" readonly="true" cssClass="input-large" /> - <s:textfield type="number" name="boatInfos.dup" value="%{boatDetails.boatInfos.dup}" label="%{getText('wao.ui.field.BoatInfos.dup')}" readonly="true" cssClass="input-small" /> - <s:textfield name="boatInfos.contactAddress1" value="%{boatDetails.boatInfos.contactAddress1}" label="%{getText('wao.ui.field.BoatInfos.contactAddress1')}" readonly="true" cssClass="input-xxlarge" /> - <s:textfield name="boatInfos.contactAddress2" value="%{boatDetails.boatInfos.contactAddress2}" label="%{getText('wao.ui.field.BoatInfos.contactAddress2')}" readonly="true" cssClass="input-xxlarge" /> - <s:textfield name="boatInfos.contactPostalCode" value="%{boatDetails.boatInfos.contactPostalCode}" label="%{getText('wao.ui.field.BoatInfos.contactPostalCode')}" readonly="true" cssClass="input-small" /> - <s:textfield name="boatInfos.contactCity" value="%{boatDetails.boatInfos.contactCity}" label="%{getText('wao.ui.field.BoatInfos.contactCity')}" readonly="true" cssClass="input-large" /> - <s:textarea name="boatInfos.comment" value="%{boatDetails.boatInfos.comment}" label="%{getText('wao.ui.field.BoatInfos.comment')}" readonly="true" cssClass="input-xxlarge" /> - - <div class="form-actions"> - <button type="button" id="unlock-boat-infos-form" class="btn"> - <i class="icon-edit"></i> <s:text name="wao.ui.action.edit" /> - </button> - - <button type="button" id="save-boat-infos" class="btn" disabled="disabled"> - <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> - </button> - </div> - -</s:form> \ No newline at end of file Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boats.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boats.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boats.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,308 +0,0 @@ -<%-- - #%L - Wao :: Web - %% - Copyright (C) 2009 - 2014 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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - -<head> - <title> - <s:text name="wao.ui.page.Boats.title"/> - </title> - - <script> - - $(document).ready(function () { - - var boatFilterMappings = [ - - <s:if test="authenticatedWaoUser.authorizedToFilterOnBoats"> - { - filterName: 'boatIds', - filterLabel: "<s:text name="wao.ui.entity.Boat"/>", - filterValuesField: 'boats', - minimumInputLength: 3 - }, - </s:if> - { - filterName: 'elligibleForSampleRowsFilter.fishingZoneFacadeNames', - filterLabel: "<s:text name="wao.ui.field.FishingZone.facadeName"/>", - filterValuesField: 'elligibleForSampleRowsFilterValues.fishingZoneFacadeNames' - }, - { - filterName: 'elligibleForSampleRowsFilter.fishingZoneSectorNames', - filterLabel: "<s:text name="wao.ui.field.FishingZone.sectorName"/>", - filterValuesField: 'elligibleForSampleRowsFilterValues.fishingZoneSectorNames' - }, - { - filterName: 'elligibleForSampleRowsFilter.sampleRowCodes', - filterLabel: "<s:text name="wao.ui.field.SampleRow.code"/>", - filterValuesField: 'elligibleForSampleRowsFilterValues.sampleRowCodes' - }, - { - filterName: 'districtIds', - filterLabel: "<s:text name="wao.ui.field.Boat.district"/>", - filterValuesField: 'districts' - }, - { - filterName: 'shipOwnerIds', - filterLabel: "<s:text name="wao.ui.field.Boat.shipOwner"/>", - filterValuesField: 'shipOwners', - minimumInputLength: 3 - }, - { - filterName: 'portOfRegistryIds', - filterLabel: "<s:text name="wao.ui.field.Boat.portOfRegistry"/>", - filterValuesField: 'portsOfRegistry' - } - ]; - - filter = <s:property value="filter" escapeHtml="false"/>; - - boatsFilterController2 = new FilterController2(boatFilterMappings, filter, WAO.OBSMER_BOATS_FILTER_VALUES_JSON_URL, $('#boats-filters-form fieldset.extra-filters')); - boatsFilterController2.init(); - -// var $boatsFiltersForm = $('#boats-filters-form'); -// var boatsFilterController = new FilterController(WAO.OBSMER_BOATS_FILTER_VALUES_JSON_URL, $boatsFiltersForm); -// boatsFilterController.init(); - - var $boatDetails = $('#boat-details'); - var $companyId = $('#companyId'); - - var showBoatDetails = function (boatId) { - var companyId = $companyId.val(); - var successCallback = function (data) { - $boatDetails.html(data); - $('tr.boat-row').removeClass('highlight'); - $('tr[data-boat-id="' + boatId + '"]').addClass('highlight'); - $boatDetails.effect('highlight', 'slow'); - }; - var data = { - fragment: true, - boatId: boatId, - companyId: companyId - }; - WAO.get(WAO.OBSMER_BOAT_DETAILS_URL, data, successCallback); - } - $('a.boat-details-action').click(function (e) { - e.preventDefault(); - var boatId = $(this).parents('tr.boat-row').attr('data-boat-id'); - showBoatDetails(boatId); - }); - $companyId.change(function () { - var boatId = $('tr.boat-row.highlight').attr('data-boat-id'); - if (boatId) { - showBoatDetails(boatId); - } - }); - - }); - - </script> - -</head> - -<content tag="mainClass">large</content> -<content tag="boatsMenuItemClass">active</content> - -<s:if test="startBoatSelectionForSampleRow != null"> - <div class="alert alert-info"> - <s:text name="wao.ui.tip.boatSelectionForSampleRowStarted"> - <s:param value="startBoatSelectionForSampleRow.code"/> - <s:param value="startBoatSelectionForSampleRow.professionDescription"/> - </s:text> - <s:url action="cancel-boat-selection" id="cancelBoatSelectionUrl"/> - <s:a href="%{cancelBoatSelectionUrl}" cssClass="btn btn-link"> - <s:text name="wao.ui.action.cancel"/> - </s:a> - </div> -</s:if> - -<div id="boats-filters-list-details-layout"> - - <div> - <s:form method="GET" id="boats-filters-form" cssClass="filters-form"> - - <fieldset class="extra-filters"> - - </fieldset> - - <div class="form-actions"> - - <s:submit type="button" action="boats!applyFilter" cssClass="btn btn-primary"> - <i class="icon-filter"></i> <s:text name="wao.ui.action.filter"/> - </s:submit> - - <s:submit type="button" action="boats!resetFilter" cssClass="btn"> - <i class="icon-trash"></i> <s:text name="wao.ui.action.reset"/> - </s:submit> - - <s:submit action="export-boats" type="button" cssClass="btn"> - <i class="icon-download"></i> <s:text name="wao.ui.action.csvExport"/> - </s:submit> - - </div> - - </s:form> - - </div> - - <div> - <div class="arrow-right"></div> - <h2> - <s:text name="wao.ui.boats.title"> - <s:param value="%{pagination.count}"/> - </s:text> - </h2> - - <s:if test="authenticatedWaoUser.authorizedToViewBoatDetailsForAllCompanies"> - <s:select id="companyId" - name="companyId" - label="Vous devez sélectionner la société pour laquelle vous souhaitez consulter les informations" - list="allCompanies" - listKey="%{topiaId}" - listValue="%{name}" - value="%{authenticatedWaoUser.waoUser.company.topiaId}" - cssClass="input-xxlarge" /> - </s:if> - <s:else> - <s:hidden id="companyId" name="companyId" value="%{authenticatedWaoUser.waoUser.company.topiaId}"/> - </s:else> - - <table id="boats-list" class="table-condensed table-striped table-hover"> - <thead> - <tr> - <th> - <s:text name="wao.ui.boats.registrationCode"/> - </th> - <th> - <s:text name="wao.ui.boats.boatName"/> - </th> - <th> - <s:text name="wao.ui.boats.boatLength"/> (cm) - </th> - <th> - <s:text name="wao.ui.boats.buildYear"/> - </th> - <th> - <s:text name="wao.ui.boats.district"/> - </th> - <th> - <span data-original-title="<s:text name="wao.ui.boats.portOfRegistry.description"/>" data-toggle="tooltip" data-placement="bottom"> - <s:text name="wao.ui.boats.portOfRegistry"/> - </span> - </th> - </tr> - </thead> - <tbody> - <s:iterator value="boats" var="boat"> - <tr data-boat-id="<s:property value="topiaId"/>" class="boat-row"> - <td> - <s:if test="authenticatedWaoUser.authorizedToViewBoatDetails"> - <s:url action="boat-details" id="boatDetailsUrl"> - <s:param name="companyId" value="authenticatedWaoUser.waoUser.company.topiaId" /> - <s:param name="boatId" value="topiaId" /> - </s:url> - <s:a href="%{boatDetailsUrl}" cssClass="boat-details-action"> - <s:property value="%{'' + immatriculation}"/> - </s:a> - </s:if> - <s:else> - <s:property value="%{'' + immatriculation}"/> - </s:else> - </td> - <td<s:if test="!active"> class="inactive"</s:if>> - <s:property value="name"/> - </td> - <td><s:property value="boatLength"/></td> - <td><s:property value="%{'' + buildYear}"/></td> - <td><s:property value="district.districtCode"/></td> - <td> - <s:if test="portOfRegistry != null"> - <span data-original-title="<s:property value="portOfRegistry.description"/>" data-toggle="tooltip" data-placement="bottom"> - <s:property value="portOfRegistry.portCode"/> - </span> - </s:if> - </td> - </tr> - </s:iterator> - </todby> - </table> - - <%-- Pagination --%> - <div class="pagination"> - <ul> - <s:url var="fullUrl" includeParams="get"/> - <s:set var="paginationUrl" value="%{getPaginationUrl(#fullUrl)}"/> - <s:if test="firstRangePage > 2"> - <li> - <a href="${paginationUrl}0">1</a> - </li> - <li> - <a href="${paginationUrl}1">2</a> - </li> - <li> - <span>...</span> - </li> - </s:if> - - <s:iterator var="currentPage" begin="firstRangePage" end="lastRangePage"> - <li class="<s:if test="#currentPage - 1 == pagination.currentPage.pageNumber">active</s:if>"> - <a href="${paginationUrl}${currentPage - 1}"> - <s:property/> - </a> - </li> - </s:iterator> - - <s:if test="lastRangePage < pagination.pageCount - 1"> - <li> - <span>...</span> - </li> - <li> - <a href="${paginationUrl}${pagination.pageCount - 2}"> - <s:property value="pagination.pageCount - 1"/> - </a> - </li> - <li> - <a href="${paginationUrl}${pagination.pageCount - 1}"> - <s:property value="pagination.pageCount"/> - </a> - </li> - </s:if> - </ul> - </div> - </div> - - <s:if test="authenticatedWaoUser.authorizedToViewBoatDetails"> - - <div> - <div class="arrow-right"></div> - <div id="boat-details"> - <div class="alert alert-info"> - <s:text name="wao.ui.tip.youMustChooseBoat" /> - </div> - </div> - </div> - </s:if> - -</div> - -</html> Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/contacts.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,552 +0,0 @@ -<%-- - #%L - Wao :: Web - %% - Copyright (C) 2009 - 2014 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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - -<head> - <title> - <s:text name="wao.ui.page.Contacts.title"/> - </title> - - <script> - - $(document).ready(function () { - - var contactsFilterMappings = [ - <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> - { - filterName: 'sampleRowFilter.companyIds', - filterLabel: "<s:text name="wao.ui.entity.Company"/>", - filterValuesField: 'sampleRowsFilterValues.companies', - }, - </s:if> - { - filterName: 'sampleRowFilter.sampleRowCodes', - filterLabel: "<s:text name="wao.ui.field.SampleRow.code"/>", - filterValuesField: 'sampleRowsFilterValues.sampleRowCodes', - }, - { - filterName: 'sampleRowFilter.programNames', - filterLabel: "<s:text name="wao.ui.field.SampleRow.programName"/>", - filterValuesField: 'sampleRowsFilterValues.programNames', - }, - { - filterName: 'sampleRowFilter.fishingZoneFacadeNames', - filterLabel: "<s:text name="wao.ui.field.FishingZone.facadeName"/>", - filterValuesField: 'sampleRowsFilterValues.fishingZoneFacadeNames', - }, - { - filterName: 'sampleRowFilter.fishingZoneSectorNames', - filterLabel: "<s:text name="wao.ui.field.FishingZone.sectorName"/>", - filterValuesField: 'sampleRowsFilterValues.fishingZoneSectorNames', - }, - { - filterName: 'sampleRowFilter.fishingGearDcfIds', - filterLabel: "<s:text name="wao.ui.entity.fishingGearDCF"/>", - filterValuesField: 'sampleRowsFilterValues.fishingGearDcfs', - }, - { - filterName: 'sampleRowFilter.targetSpeciesDcfIds', - filterLabel: "<s:text name="wao.ui.entity.targetSpeciesDCF"/>", - filterValuesField: 'sampleRowsFilterValues.targetSpeciesDcfs', - }, - <s:if test="authenticatedWaoUser.authorizedToFilterOnBoats"> - { - filterName: 'boatFilter.boatIds', - filterLabel: "<s:text name="wao.ui.entity.Boat"/>", - filterValuesField: 'boatsFilterValues.boats', - minimumInputLength: 3 - }, - </s:if> - { - filterName: 'boatFilter.districtIds', - filterLabel: "<s:text name="wao.ui.field.Boat.district"/>", - filterValuesField: 'boatsFilterValues.districts' - }, - { - filterName: 'observerIds', - filterLabel: "<s:text name="wao.ui.misc.observer"/>", - filterValuesField: 'observers' - }, - { - filterName: 'contactStates', - filterLabel: "<s:text name="wao.ui.field.Contact.contactState"/>", - filterValuesField: 'contactStates' - }, - { - filterName: 'companyAcceptations', - filterLabel: "<s:text name="wao.ui.field.Contact.validationCompany"/>", - filterValuesField: 'companyAcceptations' - }, - { - filterName: 'programAcceptations', - filterLabel: "<s:text name="wao.ui.field.Contact.validationProgram"/>", - filterValuesField: 'programAcceptations' - }, - { - filterName: 'observedDataControls', - filterLabel: "<s:text name="wao.ui.field.Contact.observedDataControl"/>", - filterValuesField: 'observedDataControls' - }, - { - filterName: 'dataReliabilities', - filterLabel: "<s:text name="wao.ui.field.Contact.dataReliability"/>", - filterValuesField: 'dataReliabilities' - } - ]; - - filter = <s:property value="filter" escapeHtml="false"/>; - - contactsFilterController2 = new FilterController2(contactsFilterMappings, filter, WAO.OBSMER_CONTACTS_FILTER_VALUES_JSON_URL, $('#contacts-filters-form fieldset.extra-filters')); - contactsFilterController2.init(); - - $('#switch-compact-full-view').click(function () { - $('#switch-compact-full-view').toggleClass('full-view').toggleClass('compact-view'); - $('table.contacts-list').toggleClass('full-view').toggleClass('compact-view'); - }); - - $('.validation-action').click(function(e) { - e.preventDefault(); - var $action = $(this); - var url = $action.attr('href'); - var successCallback = function (data) { - var successful = data['successful']; - if (successful) { - var success = data['successMessage']; - WAO.notifications.success(success); - var $tr = $('#contacts-list').find('tr[data-contactId="' + data.contactId + '"]'); - $tr.removeClass('accepted-by-company refused-by-company accepted-by-program refused-by-program'); - if (data.validationCompany) { - $tr.addClass('accepted-by-company'); - } else if (data.validationCompany === false) { - $tr.addClass('refused-by-company'); - } - if (data.validationProgram) { - $tr.addClass('accepted-by-program'); - } else if (data.validationProgram === false) { - $tr.addClass('refused-by-program'); - } - } else { - var error = data['errorMessage']; - WAO.notifications.error(error); - } - }; - WAO.post(url, {}, successCallback); - }); - - // Do not expose any struts internal input fields - $('input[type="hidden"][id^="__"]').prop('disabled', true); - }); - - </script> - -</head> - -<content tag="mainClass">large</content> -<content tag="contactsMenuItemClass">active</content> - -<s:form method="GET" id="contacts-filters-form" cssClass="filters-form"> - - <fieldset> - - <s:textfield name="filter.periodFrom" - label="%{getText('wao.ui.form.periodFrom')}" - placeholder="%{getFilterPeriodFromPlaceholder()}" - cssClass="input-small"/> - - <s:textfield name="filter.periodTo" - label="%{getText('wao.ui.form.period.to')}" - placeholder="%{getFilterPeriodToPlaceholder()}" - cssClass="input-small"/> - - <div title="<s:text name="wao.ui.form.filterOnObservationBeginDate.tooltip"/>"> - <s:checkbox name="filter.filterOnObservationBeginDate" - label="%{getText('wao.ui.form.filterOnObservationBeginDate')}"/> - </div> - - </fieldset> - - <fieldset class="extra-filters"> - - </fieldset> - - <fieldset> - - <s:checkbox name="filter.mammalsObservationOnly" - label="%{getText('wao.ui.misc.observations')}"/> - - <s:checkbox name="filter.mammalsCaptureOnly" - label="%{getText('wao.ui.field.Contact.mammalsCapture')}"/> - - <s:checkbox name="filter.commentDefinedOnly" - label="%{getText('wao.ui.field.Contact.comment')}"/> - - <s:checkbox name="filter.commentCompanyDefinedOnly" - label="%{getText('wao.ui.field.Contact.commentCompany')}"/> - - <s:checkbox name="filter.commentAdminDefinedOnly" - label="%{getText('wao.ui.field.Contact.commentAdmin')}"/> - - </fieldset> - - <fieldset> - - <s:checkbox name="filter.sortedByBoardingDate" - label="%{getText('wao.ui.form.sortByTideBegin')}"/> - - </fieldset> - - <div class="form-actions"> - - <s:submit type="button" action="contacts!applyFilter" cssClass="btn btn-primary"> - <i class="icon-filter"></i> <s:text name="wao.ui.action.filter"/> - </s:submit> - - <s:submit type="button" action="contacts!resetFilter" cssClass="btn"> - <i class="icon-trash"></i> <s:text name="wao.ui.action.reset"/> - </s:submit> - - <s:if test="authenticatedWaoUser.authorizedToExportContacts"> - <s:submit action="export-contacts" type="button" cssClass="btn"> - <i class="icon-download"></i> <s:text name="wao.ui.action.csvExport"/> - </s:submit> - </s:if> - - </div> - -</s:form> - -<h3> - <s:text name="wao.ui.contacts.title"> - <s:param value="%{pagination.count}"/> - </s:text> -</h3> - -<s:set name="pagination"> - <%-- Pagination --%> - <div class="pagination"> - <ul> - <s:url var="fullUrl" includeParams="get"/> - <s:set var="paginationUrl" value="%{getPaginationUrl(#fullUrl)}"/> - <s:if test="firstRangePage > 2"> - <li> - <a href="${paginationUrl}0">1</a> - </li> - <li> - <a href="${paginationUrl}1">2</a> - </li> - <li> - <span>...</span> - </li> - </s:if> - - <s:iterator var="currentPage" begin="firstRangePage" end="lastRangePage"> - <li class="<s:if test="#currentPage - 1 == pagination.currentPage.pageNumber">active</s:if>"> - <a href="${paginationUrl}${currentPage - 1}"> - <s:property/> - </a> - </li> - </s:iterator> - - <s:if test="lastRangePage < pagination.pageCount - 1"> - <li> - <span>...</span> - </li> - <li> - <a href="${paginationUrl}${pagination.pageCount - 2}"> - <s:property value="pagination.pageCount - 1"/> - </a> - </li> - <li> - <a href="${paginationUrl}${pagination.pageCount - 1}"> - <s:property value="pagination.pageCount"/> - </a> - </li> - </s:if> - </ul> - </div> -</s:set> - -<s:set var="fullView" value="%{fullView}"/> - -<div class="sticky-buttons"> - <button type="button" id="switch-compact-full-view" class="btn <s:if test="fullView">full-view</s:if><s:else>compact-view</s:else>"> - <span class="only-in-compact-view"> - <i class="fa fa-expand"></i><span class="only-on-hover"> <s:text name="wao.ui.action.switchToFullView" /></span> - </span> - <span class="only-in-full-view"> - <i class="fa fa-compress"></i><span class="only-on-hover"> <s:text name="wao.ui.action.switchToCompactView" /></span> - </span> - </button> -</div> - - -<s:property value="#pagination" escapeHtml="false"/> - -<table id="contacts-list" class="contacts-list large-table table-striped <s:if test="fullView">full-view</s:if><s:else>compact-view</s:else>"> - <thead> - <tr> - <th><s:text name="wao.ui.field.Contact.creationDate"/></th> - <th><s:text name="wao.ui.contacts.boatName"/></th> - <th><s:text name="wao.ui.field.Contact.sampleRow"/></th> - <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.programName"/></th> - <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.professionCode"/></th> - <th class="only-in-full-view"><s:text name="wao.ui.contacts.Profession.libelle"/></th> - <th class="only-in-full-view"><s:text name="wao.ui.contacts.Profession.species"/></th> - <th class="only-in-full-view"><s:text name="wao.ui.contacts.FishingZone.facadeName"/></th> - <th class="only-in-full-view"><s:text name="wao.ui.contacts.FishingZone.sectorName"/></th> - <th class="only-in-full-view"><s:text name="wao.ui.contacts.division"/></th> - <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.company"/></th> - <th><s:text name="wao.ui.contacts.observers"/></th> - <th><s:text name="wao.ui.field.Contact.contactState"/> (<s:text name="wao.ui.field.Contact.contactStateMotif"/>)</th> - <th class="date-time"><s:text name="wao.ui.field.Contact.beginDate"/></th> - <th class="date-time"><s:text name="wao.ui.field.Contact.endDate"/></th> - <th class="date-time"><s:text name="wao.ui.field.Contact.observationTimeInDays"/></th> - <th class="date"><s:text name="wao.ui.field.Contact.dataInputDate"/></th> - <th><s:text name="wao.ui.field.Contact.observedDataControl"/></th> - <th class="date"><s:text name="wao.ui.field.Contact.restitution"/></th> - <th><s:text name="wao.ui.contacts.observations"/></th> - <s:if test="authenticatedWaoUser.authorizedToViewContactsComments"> - <th><s:text name="wao.ui.field.Contact.comment"/></th> - <th><s:text name="wao.ui.field.Contact.commentCompany"/></th> - <th><s:text name="wao.ui.field.Contact.commentAdmin"/></th> - </s:if> - <th><s:text name="wao.ui.field.Contact.dataReliability"/></th> - <th><s:text name="wao.ui.contacts.validation"/></th> - <th><s:text name="wao.ui.actions"/></th> - </tr> - </thead> - <tbody> - - <s:iterator value="contacts" var="contact"> - <s:set name="trCssClasses">contact-row<s:if test="topiaId.equals(contactToHighlightId)"> highlight</s:if><s:if test="validationCompany==null"></s:if><s:elseif test="validationCompany"> accepted-by-company</s:elseif><s:else> refused-by-company</s:else><s:if test="validationProgram==null"></s:if><s:elseif test="validationProgram"> accepted-by-program</s:elseif><s:else> refused-by-program</s:else></s:set> - <tr class="<s:property value="#trCssClasses"/>" data-contactId="<s:property value="topiaId"/>"> - <td> - <s:property value="creationDate"/> - </td> - <td> - <s:set name="boatTooltip"> - <s:text name="wao.ui.boats.registrationCode"/> <s:property value="%{'' + boat.immatriculation}" escapeHtml="false"/> - <s:text name="wao.ui.boats.boatLength"/> <s:property value="boat.boatLength" escapeHtml="false"/> cm - <s:text name="wao.ui.boats.buildYear"/> <s:property value="%{'' + boat.buildYear}" escapeHtml="false"/> - <s:text name="wao.ui.boats.district"/> <s:property value="boat.district.districtName" escapeHtml="false"/> (<s:property value="boat.district.districtCode" escapeHtml="false"/>) - </s:set> - <span data-original-title="<s:property value="#boatTooltip"/>" data-toggle="tooltip" data-placement="right"> - <s:property value="boat.name"/> - </span> - </td> - <td class="only-in-compact-view"> - <s:set name="sampleRowTooltip"> - <s:text name="wao.ui.field.SampleRow.programName"/> <s:property value="sampleRow.programName" escapeHtml="false"/> - <s:text name="wao.ui.field.SampleRow.professionCode"/> <s:property value="sampleRow.professionDescription" escapeHtml="false"/> - <s:text name="wao.ui.contacts.Profession.libelle"/> <s:property value="sampleRow.profession.libelle" escapeHtml="false"/> - <s:text name="wao.ui.contacts.Profession.species"/> <s:property value="sampleRow.profession.species" escapeHtml="false"/> - <s:text name="wao.ui.contacts.FishingZone.facadeName"/> <s:property value="sampleRow.facade" escapeHtml="false"/> - <s:text name="wao.ui.contacts.FishingZone.sectorName"/> <s:property value="sampleRow.sectors" escapeHtml="false"/> - <s:text name="wao.ui.contacts.division"/> <s:property value="%{getDivision(sampleRow)}" escapeHtml="false"/> - </s:set> - <span data-original-title="<s:property value="#sampleRowTooltip"/>" data-toggle="tooltip" data-placement="right"> - <s:property value="sampleRow.code"/> - </span> - </td> - <td class="only-in-full-view"> - <s:property value="sampleRow.code"/> - </td> - <td class="only-in-full-view"> - <s:property value="sampleRow.programName"/> - </td> - <td class="only-in-full-view"> - <s:iterator value="getDcf5CodesAndDescriptions(sampleRow)"> - <abbr title="<s:property value="value"/>"><s:property value="key"/></abbr> - </s:iterator> - <s:property value="sampleRow.professionDescriptionWithoutDCF5" /> - </td> - <td class="only-in-full-view"> - <s:property value="sampleRow.profession.libelle"/> - </td> - <td class="only-in-full-view"> - <s:property value="sampleRow.profession.species"/> - </td> - <td class="only-in-full-view"> - <s:property value="sampleRow.facade"/> - </td> - <td class="only-in-full-view"> - <s:property value="sampleRow.sectors"/> - </td> - <td class="only-in-full-view"> - <s:property value="%{getDivision(sampleRow)}"/> - </td> - <td class="only-in-full-view"> - <s:property value="sampleRow.company.name"/> - </td> - <td> - <ul> - <s:iterator value="allObservers"> - <li><s:property value="fullName"/></li> - </s:iterator> - </ul> - </td> - <td> - <s:text name="%{contactState.i18nKey}"/> - <s:if test="contactStateMotif != null"> - <s:property value="contactStateMotif.name"/> - </s:if> - </td> - <td class="date-time"> - <s:if test="observationBeginDate != null"> - <s:property value="observationBeginDate"/> - </s:if> - </td> - <td class="date-time"> - <s:if test="observationEndDate != null"> - <s:property value="observationEndDate"/> - </s:if> - </td> - <td> - <s:if test="observationTimeInDays != null"> - <s:property value="observationTimeInDays"/> - </s:if> - </td> - <td class="date"> - <s:if test="dataInputDate != null"> - <s:property value="dataInputDate"/> - </s:if> - </td> - <td> - <s:if test="observedDataControl != null"> - <s:text name="%{observedDataControl.i18nKey}"/> - </s:if> - </td> - <td class="date"> - <s:if test="restitution != null"> - <s:property value="restitution"/> - </s:if> - </td> - <td class="align-center"> - <s:if test="mammalsObservation"> - <i class="fa fa-eye" - title="<s:text name="wao.ui.field.Contact.mammalsObservation"/>"></i> - </s:if> - <s:if test="mammalsCapture"> - <img src="<s:url value="/img/hook-22px.png"/>" - alt="<s:text name="wao.ui.field.Contact.mammalsCapture"/>" - title="<s:property value="mammalsInfo" escapeHtml="false"/>"/> - </s:if> - </td> - <s:if test="authenticatedWaoUser.authorizedToViewContactsComments"> - <td class="align-center"> - <s:if test=" ! comment.empty"> - <i title="<s:property value="comment" escapeHtml="false"/>" class="fa fa-comment"></i> - </s:if> - </td> - <td class="align-center"> - <s:if test=" ! commentCoordinator.empty"> - <i title="<s:property value="commentCoordinator" escapeHtml="false"/>" class="fa fa-comment"></i> - </s:if> - </td> - <td class="align-center"> - <s:if test=" ! commentAdmin.empty"> - <i title="<s:property value="commentAdmin" escapeHtml="false"/>" class="fa fa-comment"></i> - </s:if> - </td> - </s:if> - <td> - <s:if test="isBoardingDone(#contact)"> - <s:if test="validationCompany"> - <s:text name="%{dataReliability.i18nKey}"/> - </s:if> - </s:if> - </td> - <td> - <span class="fa-stack fa-lg" title="<s:text name="wao.ui.misc.validated"/>"> - <i class="fa fa-square-o fa-stack-2x"></i> - <i class="fa fa-check fa-stack-1x only-if-accepted-by-company"></i> - <i class="fa fa-times fa-stack-1x only-if-refused-by-company"></i> - </span> - <span class="fa-stack fa-lg" title="<s:text name="wao.ui.misc.validated"/>"> - <i class="fa fa-square-o fa-stack-2x"></i> - <i class="fa fa-check fa-stack-1x only-if-accepted-by-program"></i> - <i class="fa fa-times fa-stack-1x only-if-refused-by-program"></i> - </span> - </td> - <td class="actions"> - <div class="dropdown"> - <a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> - <s:text name="wao.ui.actions"/> - <b class="caret"></b> - </a> - <ul class="dropdown-menu"> - <li> - <s:if test="authenticatedWaoUser.admin"> - <s:set name="focusAnchor">adminFocus</s:set> - </s:if> - <s:else> - <s:set name="focusAnchor">coordinatorOrObserverFocus</s:set> - </s:else> - <s:url action="edit-contact!input" id="editContactUrl" anchor='%{focusAnchor}'> - <s:param name="contactId" value="topiaId"/> - </s:url> - <s:a href="%{editContactUrl}"> - <i class="icon-edit"></i> <s:text name="wao.ui.action.editOrDeleteContact"/> - </s:a> - </li> - <s:if test="authenticatedWaoUser.authorizedToChangeContactValidation"> - <li> - <s:url action="validate-contact-json" id="acceptContactUrl" escapeAmp="false"> - <s:param name="contactId" value="topiaId"/> - <s:param name="validationState">true</s:param> - </s:url> - <s:set name="disabled"><s:if test="%{ ! isAcceptable(#contact)}">disabled</s:if></s:set> - <s:a cssClass="validation-action" href="%{acceptContactUrl}"> - <s:text name="wao.ui.action.acceptContact"/> - </s:a> - </li> - <li> - <s:url action="validate-contact-json" id="refuseContactUrl" escapeAmp="false"> - <s:param name="contactId" value="topiaId"/> - <s:param name="validationState">false</s:param> - </s:url> - <s:a cssClass="validation-action" href="%{refuseContactUrl}"> - <s:text name="wao.ui.action.refuseContact"/> - </s:a> - </li> - <li> - <s:url action="validate-contact-json" id="unvalidateContactUrl"> - <s:param name="contactId" value="topiaId"/> - </s:url> - <s:a cssClass="validation-action" href="%{unvalidateContactUrl}"> - <s:text name="wao.ui.action.unvalidateContact"/> - </s:a> - </li> - </s:if> - </ul> - </div> - </td> - </tr> - </s:iterator> - </todby> -</table> - -<s:property value="#pagination" escapeHtml="false"/> - -</html> Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-contact-input.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-contact-input.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-contact-input.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,332 +0,0 @@ -<%-- - #%L - Wao :: Web - %% - Copyright (C) 2009 - 2014 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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> -<head> - <title> - <s:if test="updateContactCommand.creation"> - <s:text name="wao.ui.contact.creation"/> - </s:if> - <s:else> - <s:text name="wao.ui.contact.edition"/> - </s:else> - </title> - <script> - - $(document).ready(function () { - - var $mammalsCaptureCheckbox = $('#mammalsCaptureCheckbox'); - var $mammalsInfo = $('#mammalsInfo'); - - var showHideMammalsInfo = function () { - if ($mammalsCaptureCheckbox.prop('checked')) { - $mammalsInfo.show(); - } else { - $mammalsInfo.hide(); - } - }; - - $mammalsCaptureCheckbox.change(showHideMammalsInfo); - showHideMammalsInfo(); - - var $contactStateMotif = $('#contactStateMotif'); - var $contactStateSelect = $('select[name="updateContactCommand.contact.contactState"]'); - - var showHideContactStateMotif = function () { - var contactState = $contactStateSelect.val(); - if (contactState === 'CONTACT_REFUSED' || contactState === 'CONTACT_DEFINITELY_REFUSED') { - $contactStateMotif.show(); - } else { - $contactStateMotif.hide(); - } - }; - - $contactStateSelect.change(showHideContactStateMotif); - showHideContactStateMotif(); - - $('#delete-contact-link').click(function (e) { - if ( ! confirm("<s:text name="wao.ui.action.deleteContact.confirm"/>")) { - e.preventDefault(); - } - }) - - }); - - </script> - <content tag="mainClass">form</content> -</head> - - <div class="form-wrapper"> - <h1> - <s:if test="updateContactCommand.creation"> - <s:text name="wao.ui.contact.creation"/> - </s:if> - <s:else> - <s:text name="wao.ui.contact.edition"/> - </s:else> - </h1> - - <aside class="well"> - - <h2><s:text name="wao.ui.misc.information"/></h2> - - <s:text name="wao.ui.form.Contact.contactCreatedOn"> - <s:param value="%{formatDate(updateContactCommand.contact.creationDate)}"/> - </s:text> - - <h3><s:text name="wao.ui.field.Contact.boat"/></h3> - - <table class="table"> - <tbody> - <tr> - <th> - <s:text name="wao.ui.field.Boat.name"/> - </th> - <td> - <s:property value="updateContactCommand.contact.boat.name"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Boat.immatriculation"/> - </th> - <td> - <s:property value="updateContactCommand.contact.boat.immatriculation"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Boat.districtCode"/> - </th> - <td> - <s:property value="updateContactCommand.contact.boat.districtCode"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Boat.boatLength"/> - </th> - <td> - <s:property value="%{'' + updateContactCommand.contact.boat.boatLength}"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.Boat.buildYear"/> - </th> - <td> - <s:property value="%{'' + updateContactCommand.contact.boat.buildYear}"/> - </td> - </tr> - </tbody> - </table> - - <h3><s:text name="wao.ui.field.Contact.sampleRow"/></h3> - - <table class="table"> - <tbody> - <tr> - <th> - <s:text name="wao.ui.field.SampleRow.profession"/> - </th> - <td> - <s:property value="updateContactCommand.contact.sampleRow.professionDescription"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.SampleRow.programName"/> - </th> - <td> - <s:property value="updateContactCommand.contact.sampleRow.programName"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.SampleRow.periodBegin"/> - </th> - <td> - <s:property value="%{formatMonth(updateContactCommand.contact.sampleRow.periodBegin)}"/> - </td> - </tr> - <tr> - <th> - <s:text name="wao.ui.field.SampleRow.periodEnd"/> - </th> - <td> - <s:property value="%{formatMonth(updateContactCommand.contact.sampleRow.periodEnd)}"/> - </td> - </tr> - </tbody> - </table> - - </aside> - - <s:form> - - <s:set name="editObservationReport" - value="%{authenticatedWaoUser.isAuthorizedToEditObservationReport(updateContactCommand.contact)}"/> - - <s:hidden name="contactId" value="%{contactId}"/> - - <fieldset> - <legend><s:text name="wao.ui.misc.observers"/></legend> - - <s:select name="updateContactCommand.mainObserverId" - value="%{updateContactCommand.mainObserverId}" - label="%{getText('wao.ui.field.Contact.mainObserver')}" - list="observers" - emptyOption="true" - disabled="%{!#editObservationReport}" - cssClass="input-large" - /> - - <s:select name="updateContactCommand.secondaryObserverIds" - value="%{updateContactCommand.secondaryObserverIds}" - label="%{getText('wao.ui.field.Contact.secondaryObservers')}" - list="observers" - multiple="true" - disabled="%{!#editObservationReport}" - cssClass="input-xlarge" - /> - - </fieldset> - - <%--Do not remove the id (use by contacts page)--%> - <fieldset id="coordinatorOrObserverFocus"> - <legend><s:text name="wao.ui.misc.observationReport"/></legend> - - <s:textfield name="updateContactCommand.contact.observationBeginDate" - label="%{getText('wao.ui.field.Contact.beginDate')}" - placeholder="%{getDateTimePlaceholder()}" - disabled="%{!#editObservationReport}"/> - - <s:textfield name="updateContactCommand.contact.observationEndDate" - label="%{getText('wao.ui.field.Contact.endDate')}" - placeholder="%{getDateTimePlaceholder()}" - disabled="%{!#editObservationReport}"/> - - <s:select name="updateContactCommand.contact.contactState" - label="%{getText('wao.ui.field.Contact.contactState')}" - requiredLabel="true" - list="contactStates" - disabled="%{!#editObservationReport}"/> - - <div id="contactStateMotif"> - <s:select name="updateContactCommand.contact.contactStateMotif" - value="%{updateContactCommand.contact.contactState.topiaId}" - label="%{getText('wao.ui.field.Contact.contactStateMotif')}" - list="contactStateMotives" - emptyOption="true" - disabled="%{!#editObservationReport}"/> - </div> - - <s:checkbox name="updateContactCommand.contact.mammalsObservation" - label="%{getText('wao.ui.field.Contact.mammalsObservation')}" - disabled="%{!#editObservationReport}"/> - - <s:checkbox name="updateContactCommand.contact.mammalsCapture" - id="mammalsCaptureCheckbox" - label="%{getText('wao.ui.field.Contact.mammalsCapture')}" - disabled="%{!#editObservationReport}"/> - - <div id="mammalsInfo"> - <s:textarea name="updateContactCommand.contact.mammalsInfo" - label="%{getText('wao.ui.field.Contact.mammalsInfo')}" - disabled="%{!#editObservationReport}"/> - <div class="alert"> - <s:text name="wao.ui.page.ContactForm.mammalsInfo.disclaimer"/> - </div> - </div> - - <s:textfield name="updateContactCommand.contact.dataInputDate" - label="%{getText('wao.ui.field.Contact.dataInputDate')}" - placeholder="%{getDatePlaceholder()}" - disabled="%{!#editObservationReport}"/> - - <s:select name="updateContactCommand.contact.observedDataControl" - label="%{getText('wao.ui.field.Contact.observedDataControl')}" - list="observedDataControls" - emptyOption="true" - disabled="%{!#editObservationReport || !authenticatedWaoUser.coordinator}"/> - - <s:textfield name="updateContactCommand.contact.restitution" - label="%{getText('wao.ui.field.Contact.restitution')}" - placeholder="%{getDatePlaceholder()}" - disabled="%{!#editObservationReport}"/> - - <s:textarea name="updateContactCommand.contact.comment" - label="%{getText('wao.ui.field.Contact.comment')}" - placeholder="%{getText('wao.ui.misc.noComment')}" - disabled="%{!#editObservationReport || !authenticatedWaoUser.observer}"/> - - <s:textarea name="updateContactCommand.contact.commentCoordinator" - label="%{getText('wao.ui.field.Contact.commentCoordinator')}" - placeholder="%{getText('wao.ui.misc.noComment')}" - disabled="%{!#editObservationReport || !authenticatedWaoUser.coordinator}"/> - - </fieldset> - - <%--Do not remove the id (use by contacts page)--%> - <fieldset id="adminFocus"> - <legend><s:text name="wao.ui.form.programEvaluation"/></legend> - - <s:if test="authenticatedWaoUser.authorizedToDisplayContactDataReliability"> - <s:select name="updateContactCommand.contact.dataReliability" - label="%{getText('wao.ui.field.Contact.dataReliability')}" - list="dataReliabilities" - emptyOption="true" - disabled="%{!authenticatedWaoUser.isAuthorizedToEditContactDataReliability(updateContactCommand.contact)}"/> - </s:if> - - <s:textarea name="updateContactCommand.contact.commentAdmin" - label="%{getText('wao.ui.field.Contact.commentAdmin')}" - placeholder="%{getText('wao.ui.misc.noComment')}" - disabled="%{!authenticatedWaoUser.admin}"/> - </fieldset> - - <div class="form-actions"> - <s:url action="contacts" id="contactsUrl"/> - <s:a href="%{contactsUrl}" cssClass="btn"> - <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.cancel"/> - </s:a> - <s:if test="authenticatedWaoUser.isAuthorizedToEditContact(updateContactCommand.contact)"> - <s:submit type="button" cssClass="btn"> - <i class="icon-hdd"></i> <s:text name="wao.ui.action.save"/> - </s:submit> - </s:if> - - <s:if test=" ! updateContactCommand.creation && authenticatedWaoUser.isAuthorizedToDeleteContact(updateContactCommand.contact)"> - <s:url action="delete-contact" id="deleteContactUrl"> - <s:param name="contactId" value="contactId"/> - </s:url> - <s:a href="%{deleteContactUrl}" cssClass="btn pull-right" id="delete-contact-link"> - <i class="icon-trash"></i> <s:text name="wao.ui.action.deleteContact"/> - </s:a> - </s:if> - </div> - - </s:form> - </div> -</html> - Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-sample-row-input.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-sample-row-input.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-sample-row-input.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,271 +0,0 @@ -<%-- - #%L - Wao :: Web - %% - Copyright (C) 2009 - 2014 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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - <head> - <title> - <s:if test="updateSampleRowCommand.creation"> - <s:text name="wao.ui.sampleRow.creation" /> - </s:if> - <s:else> - <s:property value="t('wao.ui.sampleRow.edition', updateSampleRowCommand.sampleRow.code)" /> - </s:else> - </title> - <script> - - $(document).ready(function() { - - var expectedObservationsByMonths = <s:property value="updateSampleRowCommand.expectedObservationsByMonths" escapeHtml="false" />; - - var $expectedObservationsByMonthsTable = $('#expectedObservationsByMonthsTable'); - var $expectedObservationsByMonthsTableHead = $expectedObservationsByMonthsTable.find('thead'); - var $expectedObservationsByMonthsTableBody = $expectedObservationsByMonthsTable.find('tbody'); - var $periodBeginInput = $('input[name="updateSampleRowCommand.sampleRow.periodBegin"]'); - var $periodEndInput = $('input[name="updateSampleRowCommand.sampleRow.periodEnd"]'); - - var updateExpectedObservationsByMonthsTable = function() { - $expectedObservationsByMonthsTableHead.empty(); - $expectedObservationsByMonthsTableBody.empty(); - var periodBegin = moment($periodBeginInput.val(), 'MM/YYYY'); - var periodEnd = moment($periodEndInput.val(), 'MM/YYYY'); - if (periodBegin.isValid() && periodEnd.isValid()) { - if (periodBegin > periodEnd) { - $periodEndInput.val($periodBeginInput.val()); - periodEnd = moment($periodEndInput.val(), 'MM/YYYY'); - } - var months = []; - do { - months.push(periodBegin.format('YYYYMM')); - periodBegin.add('months', 1); - } while (periodBegin <= periodEnd); - $expectedObservationsByMonthsTableHead.append('<tr></tr>'); - $expectedObservationsByMonthsTableBody.append('<tr></tr>'); - $(months).each(function (index, month) { - var newInput = ' <td>' - + ' ' + moment(month, 'YYYYMM').format('MM/YYYY') - + ' </td>'; - $expectedObservationsByMonthsTableHead.find('tr').append(newInput); - }); - $(months).each(function (index, month) { - var value = ""; - if (expectedObservationsByMonths[month]) { - value = expectedObservationsByMonths[month]; - } - var newInput = ' <td>' - + ' <input type="number" name="expectedObservationsByMonths[\'' + month + '\']" value="' + value + '" class="input-small" />' - + ' </td>'; - $expectedObservationsByMonthsTableBody.find('tr').append(newInput); - }); - } - } - - updateExpectedObservationsByMonthsTable(); - - $periodBeginInput.change(updateExpectedObservationsByMonthsTable); - $periodEndInput.change(updateExpectedObservationsByMonthsTable); - - }); - - </script> - - <content tag="mainClass">form</content> - </head> - - - <s:if test="updateSampleRowCommand.observationAlreadyStarted"> - <div class="alert"> - <s:text name="wao.ui.form.SampleRow.warn.observationAlreadyStarted" /> - </div> - </s:if> - - <s:form> - - <h1> - <s:if test="updateSampleRowCommand.creation"> - <s:text name="wao.ui.sampleRow.creation" /> - </s:if> - <s:else> - <s:property value="t('wao.ui.sampleRow.edition', updateSampleRowCommand.sampleRow.code)" /> - </s:else> - </h1> - - <s:hidden name="sampleRowId" value="%{sampleRowId}" /> - - <fieldset> - - <legend><s:text name="wao.ui.field.SampleRow.profession" /></legend> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.libelle" - label="%{getText('wao.ui.field.SampleRow.libelle')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-xxlarge" /> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.size" - label="%{getText('wao.ui.field.SampleRow.size')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - inputAppend="m" - cssClass="input-small" /> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.meshSize" - label="%{getText('wao.ui.field.SampleRow.meshSize')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - inputAppend="mm" - cssClass="input-small" /> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.species" - label="%{getText('wao.ui.field.SampleRow.species')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-xxlarge" /> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.other" - label="%{getText('wao.ui.field.SampleRow.other')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-xxlarge" /> - - <s:select name="updateSampleRowCommand.dcf5CodesIds" - label="%{getText('wao.ui.field.SampleRow.dcf5Codes')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - list="updateSampleRowCommand.allDcf5Codes" - listValue="%{value.code}" - cssClass="input-xxlarge select2" - multiple="true" - /> - - </fieldset> - - <fieldset> - - <legend><s:text name="wao.ui.field.SampleRow.fishingZones" /></legend> - - <s:select name="updateSampleRowCommand.fishingZoneIds" - label="%{getText('wao.ui.field.SampleRow.fishingZones')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - list="updateSampleRowCommand.allFishingZones" - listValue="%{value.code}" - multiple="true" - cssClass="input-xxlarge" - /> - - <s:textfield name="updateSampleRowCommand.sampleRow.fishingZonesInfos" label="%{getText('wao.ui.field.SampleRow.fishingZonesInfos')}" cssClass="input-xxlarge" /> - - </fieldset> - - <fieldset> - - <legend><s:text name="wao.ui.form.SampleRow.program" /></legend> - - <s:textfield name="updateSampleRowCommand.sampleRow.programName" - label="%{getText('wao.ui.field.SampleRow.programName')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" /> - <s:textfield name="updateSampleRowCommand.sampleRow.periodBegin" - label="%{getText('wao.ui.field.SampleRow.periodBegin')}" - placeholder="04/2014" - cssClass="input-small" /> - <s:textfield name="updateSampleRowCommand.sampleRow.periodEnd" - label="%{getText('wao.ui.field.SampleRow.periodEnd')}" - placeholder="03/2015" - cssClass="input-small" /> - - - <div class="control-group"> - <label class="control-label"><s:text name="wao.ui.samplingPlan.effort" /></label> - <div class="controls"> - <table id="expectedObservationsByMonthsTable"> - <thead> - </thead> - <tbody> - </tbody> - </table> - </div> - </div> - - - </fieldset> - - <fieldset> - - <legend><s:text name="wao.ui.form.SampleRow.others" /></legend> - - <s:if test="updateSampleRowCommand.creation"> - <s:textfield name="updateSampleRowCommand.code" - label="%{getText('wao.ui.field.SampleRow.code')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-small" /> - </s:if> - - <s:select name="updateSampleRowCommand.companyId" - label="%{getText('wao.ui.field.SampleRow.company')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - list="updateSampleRowCommand.allCompanies" - listValue="%{value.name}" - cssClass="input-xxlarge" - /> - - <s:textfield type="number" name="updateSampleRowCommand.sampleRow.nbObservants" label="%{getText('wao.ui.field.SampleRow.nbObservants')}" inputAppend="%{getText('wao.ui.unit.observers')}" cssClass="input-small"/> - - <%-- XXX brendan 19/05/14 ne pas mettre type="number" car avec le formatter qui mets la valeur avec ',' on a pas la valeur quand on modifie une ligne --%> - <s:textfield name="updateSampleRowCommand.sampleRow.averageTideTime" label="%{getText('wao.ui.field.SampleRow.averageTideTime')}" inputAppend="%{getText('wao.ui.unit.days')}" cssClass="input-small"/> - <s:textfield name="updateSampleRowCommand.sampleRow.appliedCoverageRate" label="%{getText('wao.ui.field.SampleRow.appliedCoverageRate')}" inputAppend="%" cssClass="input-small"/> - - <s:textarea name="updateSampleRowCommand.elligibleBoatImmatriculations" label="%{getText('wao.ui.field.SampleRow.elligibleBoat')}" /> - - <s:textarea name="updateSampleRowCommand.sampleRow.comment" label="%{getText('wao.ui.field.SampleRow.comment')}" /> - - </fieldset> - - <s:if test=" ! updateSampleRowCommand.creation"> - - <fieldset> - - <legend><s:text name="wao.ui.form.editComment" /></legend> - - <s:text name="wao.ui.form.editionAuthor" /> <s:property value="updateSampleRowCommand.sampleRowLog.author.fullName" /> - - <s:textarea name="updateSampleRowCommand.sampleRowLog.comment" label="%{getText('wao.ui.form.editComment')}" requiredLabel="true" /> - - </fieldset> - - </s:if> - - <div class="form-actions"> - <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> - <s:a href="%{samplingPlanUrl}" cssClass="btn"> - <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.cancel" /> - </s:a> - <s:submit type="button" cssClass="btn"> - <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> - </s:submit> - <s:if test=" ! updateSampleRowCommand.creation"> - <s:url action="delete-sample-row" id="deleteSampleRowUrl"> - <s:param name="sampleRowId" value="sampleRowId" /> - </s:url> - <s:a href="%{deleteSampleRowUrl}" cssClass="btn pull-right"> - <i class="icon-trash"></i> <s:text name="wao.ui.action.deleteSampleRow" /> - </s:a> - </s:if> - </div> - - </s:form> - -</html> - Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,55 +0,0 @@ -<%-- - #%L - Wao :: Web - %% - Copyright (C) 2009 - 2014 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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - -<head> - <title><s:text name="wao.ui.import.contacts" /></title> - <content tag="mainClass">form</content> -</head> - -<s:form action="import-contacts" method="POST" enctype="multipart/form-data"> - - <h1><s:text name="wao.ui.import.contacts" /></h1> - - <div class="alert alert-info"> - <s:text name="wao.ui.import.disclaimer" /> - </div> - - <fieldset> - <legend> - <s:text name="wao.ui.import.contacts" /> - </legend> - - <s:file name="csvFile" /> - - <div class="form-actions"> - <s:submit type="button" cssClass="btn"> - <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/> - </s:submit> - </div> - </fieldset> - -</s:form> - -</html> \ No newline at end of file Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-sampling-plan-input.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-sampling-plan-input.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-sampling-plan-input.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,55 +0,0 @@ -<%-- - #%L - Wao :: Web - %% - Copyright (C) 2009 - 2014 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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - - <head> - <title><s:text name="wao.ui.import.samplingPlan" /></title> - <content tag="mainClass">form</content> - </head> - - <s:form action="import-sampling-plan" method="POST" enctype="multipart/form-data"> - - <h1><s:text name="wao.ui.import.samplingPlan" /></h1> - - <div class="alert alert-info"> - <s:text name="wao.ui.import.disclaimer" /> - </div> - - <fieldset> - <legend> - <s:text name="wao.ui.import.samplingPlan" /> - </legend> - - <s:file name="csvFile" /> - - <div class="form-actions"> - <s:submit type="button" cssClass="btn"> - <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/> - </s:submit> - </div> - </fieldset> - - </s:form> - -</html> Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sample-row-log.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sample-row-log.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sample-row-log.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,98 +0,0 @@ -<%-- - #%L - Wao :: Web - %% - Copyright (C) 2009 - 2014 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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - - <head> - <title> - <s:property value="%{t('wao.ui.sampleRowLog.title', sampleRow.code)}" /> - </title> - </head> - - <h1> - <s:property value="%{t('wao.ui.sampleRowLog.title', sampleRow.code)}" /> - </h1> - - <s:iterator value="sampleRow.sampleRowLog" var="sampleRowLogEntry"> - - <article> - <h2> - <s:if test="fromAdmin"> - <s:text name="wao.ui.misc.changeOn" /> - </s:if> - <s:else> - <s:text name="wao.ui.misc.commentAddedOn" /> - </s:else> - <s:property value="topiaCreateDate" /> - <s:text name="wao.ui.misc.by" /> - <s:property value="author.fullName" /> - </h2> - - <s:property value="logText" /> - - <s:property value="comment" /> - - </article> - - </s:iterator> - - <s:if test="authenticatedWaoUser.authorizedToCommentSampleRow"> - - <s:form action="comment-sample-row"> - - <fieldset> - <legend><s:text name="wao.ui.form.addComment" /></legend> - - <s:hidden name="sampleRowId" value="%{sampleRowId}" /> - - <s:textarea name="comment" label="%{getText('wao.ui.misc.comment')}" /> - - <div class="form-actions"> - <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> - <s:a href="%{samplingPlanUrl}" cssClass="btn"> - <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.goBackToSamplingPlan" /> - </s:a> - - <s:submit type="button" cssClass="btn"> - <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> - </s:submit> - </div> - - </fieldset> - - </s:form> - - </s:if> - - <s:else> - - <div class="form-actions"> - <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> - <s:a href="%{samplingPlanUrl}" cssClass="btn"> - <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.goBackToSamplingPlan" /> - </s:a> - </div> - - </s:else> - -</html> Modified: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -32,7 +32,7 @@ $(document).ready(function () { - // var sampleRowsFilterController = new FilterController(WAO.OBSMER_SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form')); + // var sampleRowsFilterController = new FilterController(WAO.SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form')); // sampleRowsFilterController.init(); var sampleRowsFilterMappings = [ @@ -77,7 +77,7 @@ filter = <s:property value="filter" escapeHtml="false"/>; - sampleRowsFilterController2 = new FilterController2(sampleRowsFilterMappings, filter, WAO.OBSMER_SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form fieldset.extra-filters')); + sampleRowsFilterController2 = new FilterController2(sampleRowsFilterMappings, filter, WAO.SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form fieldset.extra-filters')); sampleRowsFilterController2.init(); $('#switch-estimated-real').click(function () { Deleted: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/synthesis.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/synthesis.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/synthesis.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -1,361 +0,0 @@ -<%-- - #%L - Wao :: Web - %% - Copyright (C) 2009 - 2014 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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib uri="/struts-tags" prefix="s" %> - -<content tag="synthesisMenuItemClass">active</content> - -<html> - - <head> - <title> - <s:text name="wao.ui.page.Synthesis.title"/> - </title> - - <script type="text/javascript"> - - $(document).ready(function() { - - var contactsFilterMappings = [ - <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> - { - filterName: 'sampleRowFilter.companyIds', - filterLabel: "<s:text name="wao.ui.entity.Company"/>", - filterValuesField: 'sampleRowsFilterValues.companies', - }, - </s:if> - { - filterName: 'sampleRowFilter.sampleRowCodes', - filterLabel: "<s:text name="wao.ui.field.SampleRow.code"/>", - filterValuesField: 'sampleRowsFilterValues.sampleRowCodes', - }, - { - filterName: 'sampleRowFilter.programNames', - filterLabel: "<s:text name="wao.ui.field.SampleRow.programName"/>", - filterValuesField: 'sampleRowsFilterValues.programNames', - }, - { - filterName: 'sampleRowFilter.fishingZoneFacadeNames', - filterLabel: "<s:text name="wao.ui.field.FishingZone.facadeName"/>", - filterValuesField: 'sampleRowsFilterValues.fishingZoneFacadeNames', - }, - { - filterName: 'sampleRowFilter.fishingZoneSectorNames', - filterLabel: "<s:text name="wao.ui.field.FishingZone.sectorName"/>", - filterValuesField: 'sampleRowsFilterValues.fishingZoneSectorNames', - }, - { - filterName: 'sampleRowFilter.fishingGearDcfIds', - filterLabel: "<s:text name="wao.ui.entity.fishingGearDCF"/>", - filterValuesField: 'sampleRowsFilterValues.fishingGearDcfs', - }, - { - filterName: 'sampleRowFilter.targetSpeciesDcfIds', - filterLabel: "<s:text name="wao.ui.entity.targetSpeciesDCF"/>", - filterValuesField: 'sampleRowsFilterValues.targetSpeciesDcfs', - }, - <s:if test="authenticatedWaoUser.authorizedToFilterOnBoats"> - { - filterName: 'boatFilter.boatIds', - filterLabel: "<s:text name="wao.ui.entity.Boat"/>", - filterValuesField: 'boatsFilterValues.boats', - minimumInputLength: 3 - }, - </s:if> - { - filterName: 'boatFilter.districtIds', - filterLabel: "<s:text name="wao.ui.field.Boat.district"/>", - filterValuesField: 'boatsFilterValues.districts' - }, - { - filterName: 'observerIds', - filterLabel: "<s:text name="wao.ui.misc.observer"/>", - filterValuesField: 'observers' - } - ]; - - filter = <s:property value="filter" escapeHtml="false"/>; - - contactsFilterController2 = new FilterController2(contactsFilterMappings, filter, WAO.OBSMER_CONTACTS_FILTER_VALUES_JSON_URL, $('#synthesis-filters-form fieldset.extra-filters')); - contactsFilterController2.init(); - - }); - - </script> - </head> - - <content tag="mainClass">large syntheses</content> - - <s:form method="GET" id="synthesis-filters-form" cssClass="filters-form"> - - <fieldset> - - <s:textfield name="filter.periodFrom" - label="%{getText('wao.ui.form.periodFrom')}" - placeholder="%{getFilterPeriodFromPlaceholder()}" - cssClass="input-small"/> - - <s:textfield name="filter.periodTo" - label="%{getText('wao.ui.form.period.to')}" - placeholder="%{getFilterPeriodToPlaceholder()}" - cssClass="input-small"/> - - <div title="<s:text name="wao.ui.form.filterOnObservationBeginDate.tooltip"/>"> - <s:checkbox name="filter.filterOnObservationBeginDate" - label="%{getText('wao.ui.form.filterOnObservationBeginDate')}"/> - </div> - - </fieldset> - - <fieldset class="extra-filters"> - - </fieldset> - - <fieldset> - - <s:checkbox name="filter.mammalsObservationOnly" - label="%{getText('wao.ui.misc.observations')}"/> - - <s:checkbox name="filter.mammalsCaptureOnly" - label="%{getText('wao.ui.field.Contact.mammalsCapture')}"/> - - <s:checkbox name="filter.commentDefinedOnly" - label="%{getText('wao.ui.field.Contact.comment')}"/> - - <s:checkbox name="filter.commentCompanyDefinedOnly" - label="%{getText('wao.ui.field.Contact.commentCompany')}"/> - - <s:checkbox name="filter.commentAdminDefinedOnly" - label="%{getText('wao.ui.field.Contact.commentAdmin')}"/> - - <s:checkbox name="filter.realVsEstimated" - label="%{getText('wao.ui.form.realTides.description')}"/> - - </fieldset> - - <div class="form-actions"> - - <s:submit type="button" action="synthesis!applyFilter" cssClass="btn btn-primary"> - <i class="icon-filter"></i> <s:text name="wao.ui.action.filter"/> - </s:submit> - - <s:submit type="button" action="synthesis!resetFilter" cssClass="btn"> - <i class="icon-trash"></i> <s:text name="wao.ui.action.reset"/> - </s:submit> - - </div> - - </s:form> - - <s:if test="synthesis.empty"> - <s:text name="wao.ui.synthesis.empty"/> - </s:if> - <s:else> - - <article> - <h2> - <s:text name="SynthesisId.GRAPH_SAMPLING"/> - </h2> - - <s:property value="synthesis.expectedVsActualObservationsByMonthsChart" escapeHtml="false"/> - </article> - - <article> - <h2> - <s:text name="SynthesisId.GRAPH_BOARDING"/> - </h2> - - <s:property value="synthesis.boardingBoatsChart" escapeHtml="false"/> - - <p> - <s:text name="wao.ui.synthesis.boarding.description"/> - </p> - - <p> - <s:text name="wao.ui.synthesis.boarding.mostUsedBoat"> - <s:param value="%{synthesis.maxBoardingValue}"/> - <s:param value="%{synthesis.maxBoardingBoat.name}"/> - <s:param value="%{synthesis.maxBoardingBoat.immatriculation}"/> - </s:text> - </p> - - <p> - <s:text name="wao.ui.synthesis.boarding.boardingCount"> - <s:param value="%{synthesis.invalidBoardingsCount}"/> - <s:param value="%{synthesis.boardingsCount}"/> - <%-- - <s:param value="%{synthesis.validBoardingsCount}"/> - --%> - </s:text> - </p> - - </article> - - <article> - <h2> - <s:text name="SynthesisId.IND_COMPLIANCE_BOARDING"/> - </h2> - - <table class="table"> - <thead> - <tr> - <th> - <s:text name="wao.ui.entity.Company"/> - </th> - <th> - <s:text name="wao.ui.synthesis.complianceBoarding.description"/> - </th> - </tr> - </thead> - <tbody> - <s:iterator value="synthesis.companySynthesesOrderedByName"> - <tr> - <td> - <s:property value="companyName"/> - </td> - <td> - <s:property value="complianceBoardingIndicator * 100"/> % - </td> - </tr> - </s:iterator> - </tbody> - </table> - - </article> - - <article> - <h2> - <s:text name="SynthesisId.IND_CONTACT_STATE"/> - </h2> - - <table class="table"> - <thead> - <tr> - <th> - <s:text name="wao.ui.entity.Company"/> - </th> - <s:iterator value="synthesis.companySynthesesOrderedByName.iterator.next().contactsStatesStatistics.keySet()" var="contactState"> - <th> - <s:text name="%{#contactState.i18nKey}"/> - </th> - </s:iterator> - <th> - <s:text name="wao.ui.misc.total"/> - </th> - </tr> - </thead> - <tbody> - <s:iterator value="synthesis.companySynthesesOrderedByName"> - <tr> - <td> - <s:property value="companyName"/> - </td> - <s:iterator value="contactsStatesStatistics"> - <td> - <s:property value="value"/> - <s:set name="percentage" value="%{value.doubleValue() / contactsCount * 100}" /> - (<s:property value="#percentage"/> %) - </td> - </s:iterator> - <td> - <s:property value="contactsCount"/> - </td> - </tr> - </s:iterator> - </tbody> - </table> - - </article> - - <article> - <h2> - <s:text name="SynthesisId.IND_ALLEGRO_REACTIVITY"/> - </h2> - - <table class="table"> - <thead> - <tr> - <th> - <s:text name="wao.ui.entity.Company"/> - </th> - <th> - <s:text name="wao.ui.synthesis.allegroReactivity.title"/> - </th> - </tr> - </thead> - <tbody> - <s:iterator value="synthesis.companySynthesesOrderedByName"> - <tr> - <td> - <s:property value="companyName"/> - </td> - <td<s:if test="dataInputDateReactivityHigh"> class="lower-than-expected"</s:if>> - <s:property value="dataInputDateReactivity"/> - <s:text name="wao.ui.unit.days"/> - </td> - </tr> - </s:iterator> - </tbody> - </table> - - <p> - <s:text name="wao.ui.synthesis.allegroReactivity.description"/> - </p> - - </article> - - <article> - - <h2> - <s:text name="SynthesisId.IND_DATA_RELIABILITY"/> - </h2> - - <table class="table"> - <thead> - <tr> - <th> - <s:text name="wao.ui.entity.Company"/> - </th> - <th> - <s:text name="wao.ui.synthesis.dataReliability.description"/> - </th> - </tr> - </thead> - <tbody> - <s:iterator value="synthesis.companySynthesesOrderedByName"> - <tr> - <td> - <s:property value="companyName"/> - </td> - <td> - <s:property value="dataReliabilityRatio * 100"/> % - </td> - </tr> - </s:iterator> - </tbody> - </table> - - </article> - - </s:else> - - -</html> Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/sample-row-log.jsp (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/sample-row-log.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/sample-row-log.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/sample-row-log.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,98 @@ +<%-- + #%L + Wao :: Web + %% + Copyright (C) 2009 - 2014 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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + + <head> + <title> + <s:property value="%{t('wao.ui.sampleRowLog.title', sampleRow.code)}" /> + </title> + </head> + + <h1> + <s:property value="%{t('wao.ui.sampleRowLog.title', sampleRow.code)}" /> + </h1> + + <s:iterator value="sampleRow.sampleRowLog" var="sampleRowLogEntry"> + + <article> + <h2> + <s:if test="fromAdmin"> + <s:text name="wao.ui.misc.changeOn" /> + </s:if> + <s:else> + <s:text name="wao.ui.misc.commentAddedOn" /> + </s:else> + <s:property value="topiaCreateDate" /> + <s:text name="wao.ui.misc.by" /> + <s:property value="author.fullName" /> + </h2> + + <s:property value="logText" /> + + <s:property value="comment" /> + + </article> + + </s:iterator> + + <s:if test="authenticatedWaoUser.authorizedToCommentSampleRow"> + + <s:form action="comment-sample-row"> + + <fieldset> + <legend><s:text name="wao.ui.form.addComment" /></legend> + + <s:hidden name="sampleRowId" value="%{sampleRowId}" /> + + <s:textarea name="comment" label="%{getText('wao.ui.misc.comment')}" /> + + <div class="form-actions"> + <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> + <s:a href="%{samplingPlanUrl}" cssClass="btn"> + <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.goBackToSamplingPlan" /> + </s:a> + + <s:submit type="button" cssClass="btn"> + <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> + </s:submit> + </div> + + </fieldset> + + </s:form> + + </s:if> + + <s:else> + + <div class="form-actions"> + <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> + <s:a href="%{samplingPlanUrl}" cssClass="btn"> + <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.goBackToSamplingPlan" /> + </s:a> + </div> + + </s:else> + +</html> Copied: trunk/wao-web/src/main/webapp/WEB-INF/content/synthesis.jsp (from rev 2085, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/synthesis.jsp) =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/synthesis.jsp (rev 0) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/synthesis.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -0,0 +1,393 @@ +<%-- + #%L + Wao :: Web + %% + Copyright (C) 2009 - 2014 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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<content tag="synthesisMenuItemClass">active</content> + +<html> + + <head> + <title> + <s:text name="wao.ui.page.Synthesis.title"/> + </title> + + <script type="text/javascript"> + + $(document).ready(function() { + + var contactsFilterMappings = [ + <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + { + filterName: 'sampleRowFilter.companyIds', + filterLabel: "<s:text name="wao.ui.entity.Company"/>", + filterValuesField: 'sampleRowsFilterValues.companies', + }, + </s:if> + { + filterName: 'sampleRowFilter.sampleRowCodes', + filterLabel: "<s:text name="wao.ui.field.SampleRow.code"/>", + filterValuesField: 'sampleRowsFilterValues.sampleRowCodes', + }, + { + filterName: 'sampleRowFilter.programNames', + filterLabel: "<s:text name="wao.ui.field.SampleRow.programName"/>", + filterValuesField: 'sampleRowsFilterValues.programNames', + }, + { + filterName: 'sampleRowFilter.fishingZoneFacadeNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.facadeName"/>", + filterValuesField: 'sampleRowsFilterValues.fishingZoneFacadeNames', + }, + { + filterName: 'sampleRowFilter.fishingZoneSectorNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.sectorName"/>", + filterValuesField: 'sampleRowsFilterValues.fishingZoneSectorNames', + }, + { + filterName: 'sampleRowFilter.fishingGearDcfIds', + filterLabel: "<s:text name="wao.ui.entity.fishingGearDCF"/>", + filterValuesField: 'sampleRowsFilterValues.fishingGearDcfs', + }, + { + filterName: 'sampleRowFilter.targetSpeciesDcfIds', + filterLabel: "<s:text name="wao.ui.entity.targetSpeciesDCF"/>", + filterValuesField: 'sampleRowsFilterValues.targetSpeciesDcfs', + }, + <s:if test="obsVente"> + { + filterName: 'sampleRowFilter.terrestrialDistrictIds', + filterLabel: "<s:text name="wao.ui.field.SampleRow.terrestrialLocation"/>", + filterValuesField: 'sampleRowsFilterValues.terrestrialDistricts' + }, + </s:if> + <s:if test="authenticatedWaoUser.authorizedToFilterOnBoats"> + { + filterName: 'boatFilter.boatIds', + filterLabel: "<s:text name="wao.ui.entity.Boat"/>", + filterValuesField: 'boatsFilterValues.boats', + minimumInputLength: 3 + }, + </s:if> + { + filterName: 'boatFilter.districtIds', + filterLabel: "<s:text name="wao.ui.field.Boat.district.long"/>", + filterValuesField: 'boatsFilterValues.districts' + }, + <s:if test="obsVente"> + { + filterName: 'sampleRowFilter.samplingStrategies', + filterLabel: "<s:text name="wao.ui.field.SampleRow.samplingStrategy"/>", + filterValuesField: 'sampleRowsFilterValues.samplingStrategies' + }, + { + filterName: 'actualSamplingStrategies', + filterLabel: "<s:text name="wao.ui.field.Contact.samplingStrategy"/>", + filterValuesField: 'actualSamplingStrategies' + }, + { + filterName: 'completeSamplings', + filterLabel: "<s:text name="wao.ui.field.Contact.completeSampling"/>", + filterValuesField: 'completeSamplings' + }, + </s:if> + { + filterName: 'observerIds', + filterLabel: "<s:text name="wao.ui.misc.observer"/>", + filterValuesField: 'observers' + } + ]; + + filter = <s:property value="filter" escapeHtml="false"/>; + + contactsFilterController2 = new FilterController2(contactsFilterMappings, filter, WAO.CONTACTS_FILTER_VALUES_JSON_URL, $('#synthesis-filters-form fieldset.extra-filters')); + contactsFilterController2.init(); + + }); + + </script> + </head> + + <content tag="mainClass">large syntheses</content> + + <s:form method="GET" id="synthesis-filters-form" cssClass="filters-form"> + + <fieldset> + + <s:textfield name="filter.periodFrom" + label="%{getText('wao.ui.form.periodFrom')}" + placeholder="%{getFilterPeriodFromPlaceholder()}" + cssClass="input-small"/> + + <s:textfield name="filter.periodTo" + label="%{getText('wao.ui.form.period.to')}" + placeholder="%{getFilterPeriodToPlaceholder()}" + cssClass="input-small"/> + + <div title="<s:text name="wao.ui.form.filterOnObservationBeginDate.tooltip"/>"> + <s:checkbox name="filter.filterOnObservationBeginDate" + label="%{getText('wao.ui.form.filterOnObservationBeginDate')}"/> + </div> + + </fieldset> + + <fieldset class="extra-filters"> + + </fieldset> + + <fieldset> + + <s:checkbox name="filter.mammalsObservationOnly" + label="%{getText('wao.ui.misc.observations')}"/> + + <s:checkbox name="filter.mammalsCaptureOnly" + label="%{getText('wao.ui.field.Contact.mammalsCapture')}"/> + + <s:checkbox name="filter.commentDefinedOnly" + label="%{getText('wao.ui.field.Contact.comment')}"/> + + <s:checkbox name="filter.commentCompanyDefinedOnly" + label="%{getText('wao.ui.field.Contact.commentCompany')}"/> + + <s:checkbox name="filter.commentAdminDefinedOnly" + label="%{getText('wao.ui.field.Contact.commentAdmin')}"/> + + <s:checkbox name="filter.realVsEstimated" + label="%{getText('wao.ui.form.realTides.description')}"/> + + </fieldset> + + <div class="form-actions"> + + <s:submit type="button" action="synthesis!applyFilter" cssClass="btn btn-primary"> + <i class="icon-filter"></i> <s:text name="wao.ui.action.filter"/> + </s:submit> + + <s:submit type="button" action="synthesis!resetFilter" cssClass="btn"> + <i class="icon-trash"></i> <s:text name="wao.ui.action.reset"/> + </s:submit> + + </div> + + </s:form> + + <s:if test="synthesis.empty"> + <s:text name="wao.ui.synthesis.empty"/> + </s:if> + <s:else> + + <article> + <h2> + <s:text name="SynthesisId.GRAPH_SAMPLING"/> + </h2> + + <s:property value="synthesis.expectedVsActualObservationsByMonthsChart" escapeHtml="false"/> + </article> + + <article> + <h2> + <s:text name="SynthesisId.GRAPH_BOARDING"/> + </h2> + + <s:property value="synthesis.boardingBoatsChart" escapeHtml="false"/> + + <p> + <s:text name="wao.ui.synthesis.boarding.description"/> + </p> + + <p> + <s:text name="wao.ui.synthesis.boarding.mostUsedBoat"> + <s:param value="%{synthesis.maxBoardingValue}"/> + <s:param value="%{synthesis.maxBoardingBoat.name}"/> + <s:param value="%{synthesis.maxBoardingBoat.immatriculation}"/> + </s:text> + </p> + + <p> + <s:text name="wao.ui.synthesis.boarding.boardingCount"> + <s:param value="%{synthesis.invalidBoardingsCount}"/> + <s:param value="%{synthesis.boardingsCount}"/> + <%-- + <s:param value="%{synthesis.validBoardingsCount}"/> + --%> + </s:text> + </p> + + </article> + + <s:if test="obsMer"> + + <article> + <h2> + <s:text name="SynthesisId.IND_COMPLIANCE_BOARDING"/> + </h2> + + <table class="table"> + <thead> + <tr> + <th> + <s:text name="wao.ui.entity.Company"/> + </th> + <th> + <s:text name="wao.ui.synthesis.complianceBoarding.description"/> + </th> + </tr> + </thead> + <tbody> + <s:iterator value="synthesis.companySynthesesOrderedByName"> + <tr> + <td> + <s:property value="companyName"/> + </td> + <td> + <s:property value="complianceBoardingIndicator * 100"/> % + </td> + </tr> + </s:iterator> + </tbody> + </table> + + </article> + + </s:if> + + <article> + <h2> + <s:text name="SynthesisId.IND_CONTACT_STATE"/> + </h2> + + <table class="table"> + <thead> + <tr> + <th> + <s:text name="wao.ui.entity.Company"/> + </th> + <s:iterator value="synthesis.companySynthesesOrderedByName.iterator.next().contactsStatesStatistics.keySet()" var="contactState"> + <th> + <s:text name="%{#contactState.i18nKey}"/> + </th> + </s:iterator> + <th> + <s:text name="wao.ui.misc.total"/> + </th> + </tr> + </thead> + <tbody> + <s:iterator value="synthesis.companySynthesesOrderedByName"> + <tr> + <td> + <s:property value="companyName"/> + </td> + <s:iterator value="contactsStatesStatistics"> + <td> + <s:property value="value"/> + <s:set name="percentage" value="%{value.doubleValue() / contactsCount * 100}" /> + (<s:property value="#percentage"/> %) + </td> + </s:iterator> + <td> + <s:property value="contactsCount"/> + </td> + </tr> + </s:iterator> + </tbody> + </table> + + </article> + + <article> + <h2> + <s:text name="SynthesisId.IND_ALLEGRO_REACTIVITY"/> + </h2> + + <table class="table"> + <thead> + <tr> + <th> + <s:text name="wao.ui.entity.Company"/> + </th> + <th> + <s:text name="wao.ui.synthesis.allegroReactivity.title"/> + </th> + </tr> + </thead> + <tbody> + <s:iterator value="synthesis.companySynthesesOrderedByName"> + <tr> + <td> + <s:property value="companyName"/> + </td> + <td<s:if test="dataInputDateReactivityHigh"> class="lower-than-expected"</s:if>> + <s:property value="dataInputDateReactivity"/> + <s:text name="wao.ui.unit.days"/> + </td> + </tr> + </s:iterator> + </tbody> + </table> + + <p> + <s:text name="wao.ui.synthesis.allegroReactivity.description"/> + </p> + + </article> + + <s:if test="obsMer"> + + <article> + + <h2> + <s:text name="SynthesisId.IND_DATA_RELIABILITY"/> + </h2> + + <table class="table"> + <thead> + <tr> + <th> + <s:text name="wao.ui.entity.Company"/> + </th> + <th> + <s:text name="wao.ui.synthesis.dataReliability.description"/> + </th> + </tr> + </thead> + <tbody> + <s:iterator value="synthesis.companySynthesesOrderedByName"> + <tr> + <td> + <s:property value="companyName"/> + </td> + <td> + <s:property value="dataReliabilityRatio * 100"/> % + </td> + </tr> + </s:iterator> + </tbody> + </table> + + </article> + + </s:if> + + </s:else> + + +</html> Modified: trunk/wao-web/src/main/webapp/endpoints-js.jsp =================================================================== --- trunk/wao-web/src/main/webapp/endpoints-js.jsp 2014-06-21 14:04:10 UTC (rev 2085) +++ trunk/wao-web/src/main/webapp/endpoints-js.jsp 2014-06-22 18:10:23 UTC (rev 2086) @@ -27,17 +27,17 @@ $(document).ready(function () { // json - WAO.OBSMER_SAMPLE_ROWS_FILTER_VALUES_JSON_URL = '<s:url namespace="/obsmer" action="sample-rows-filter-values-json"/>'; + WAO.SAMPLE_ROWS_FILTER_VALUES_JSON_URL = '<s:url namespace="/" action="sample-rows-filter-values-json"/>'; - WAO.OBSMER_UPDATE_BOAT_INFOS_JSON_URL = '<s:url namespace="/obsmer" action="update-boat-infos-json"/>'; - WAO.OBSMER_BOATS_FILTER_VALUES_JSON_URL = '<s:url namespace="/obsmer" action="boats-filter-values-json"/>'; - WAO.OBSMER_GET_BOAT_CONTACTS_COUNT_JSON_URL = '<s:url namespace="/obsmer" action="get-boat-contacts-count-json"/>'; - WAO.OBSMER_SEARCH_BOAT_JSON_URL = '<s:url namespace="/obsmer" action="search-boat-json"/>'; + WAO.UPDATE_BOAT_INFOS_JSON_URL = '<s:url namespace="/" action="update-boat-infos-json"/>'; + WAO.BOATS_FILTER_VALUES_JSON_URL = '<s:url namespace="/" action="boats-filter-values-json"/>'; + WAO.GET_BOAT_CONTACTS_COUNT_JSON_URL = '<s:url namespace="/" action="get-boat-contacts-count-json"/>'; + WAO.SEARCH_BOAT_JSON_URL = '<s:url namespace="/" action="search-boat-json"/>'; - WAO.OBSMER_CONTACTS_FILTER_VALUES_JSON_URL = '<s:url namespace="/obsmer" action="contacts-filter-values-json"/>'; + WAO.CONTACTS_FILTER_VALUES_JSON_URL = '<s:url namespace="/obsmer" action="contacts-filter-values-json"/>'; // fragments - WAO.OBSMER_BOAT_DETAILS_URL = '<s:url namespace="/obsmer" action="boat-details"/>'; + WAO.BOAT_DETAILS_URL = '<s:url namespace="/" action="boat-details"/>'; });
participants (1)
-
bleny@users.forge.codelutin.com