branch feature/2263 created (now f4a83c2)
This is an automated email from the git hooks/post-receive script. New change to branch feature/2263 in repository wao. See http://git.codelutin.com/wao.git at f4a83c2 Import du plan d'échantillonnage scléro This branch includes the following new commits: new 6bf8157 Ouverture de l'accès au programme Scléro pour le compte 'admin', correction du formulaire d'administration des utilisateurs pour ne pas pouvoir utiliser la notion d'invité et de professionnel new fd59834 Modification du modèle de la ligne du plan, introduction du service et de la vue pour le plan scléro, migration new 2c6e908 Dans l'écran de gestion des référentiels, on n'affiche que ce qui est pertinent pour scléro new 675f001 Suppression d'un fichier obsdeb new f4a83c2 Import du plan d'échantillonnage scléro The 5 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit f4a83c25404158e2e637ef5c7e34e85a70319154 Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Dec 18 11:36:37 2014 +0100 Import du plan d'échantillonnage scléro commit 675f00192651555d766d6237e3268c0b57b01305 Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Dec 18 10:27:01 2014 +0100 Suppression d'un fichier obsdeb commit 2c6e908c8db51c57862224a7a2ec9b69fd233573 Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Dec 18 09:59:41 2014 +0100 Dans l'écran de gestion des référentiels, on n'affiche que ce qui est pertinent pour scléro commit fd59834846ebbb3791bedd46b9a6884483e60643 Author: Brendan Le Ny <bleny@codelutin.com> Date: Mon Dec 15 15:49:36 2014 +0100 Modification du modèle de la ligne du plan, introduction du service et de la vue pour le plan scléro, migration commit 6bf81571ac6d97cd7abdd5161eec6fcceb9ba17f Author: Brendan Le Ny <bleny@codelutin.com> Date: Mon Dec 15 10:45:50 2014 +0100 Ouverture de l'accès au programme Scléro pour le compte 'admin', correction du formulaire d'administration des utilisateurs pour ne pas pouvoir utiliser la notion d'invité et de professionnel -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2263 in repository wao. See http://git.codelutin.com/wao.git commit 6bf81571ac6d97cd7abdd5161eec6fcceb9ba17f Author: Brendan Le Ny <bleny@codelutin.com> Date: Mon Dec 15 10:45:50 2014 +0100 Ouverture de l'accès au programme Scléro pour le compte 'admin', correction du formulaire d'administration des utilisateurs pour ne pas pouvoir utiliser la notion d'invité et de professionnel --- .../db/migration/V5_0__sclerochronology.sql | 13 ++++++ wao-persistence/src/main/xmi/wao-model.properties | 2 +- .../administration/UpdateWaoUserCommand.java | 9 ++++ .../content/administration/edit-wao-user.jsp | 4 +- .../src/main/webapp/WEB-INF/decorators/layout.jsp | 50 ++++++++++++---------- 5 files changed, 52 insertions(+), 26 deletions(-) diff --git a/wao-persistence/src/main/resources/db/migration/V5_0__sclerochronology.sql b/wao-persistence/src/main/resources/db/migration/V5_0__sclerochronology.sql new file mode 100644 index 0000000..ee61e50 --- /dev/null +++ b/wao-persistence/src/main/resources/db/migration/V5_0__sclerochronology.sql @@ -0,0 +1,13 @@ + + +-- Ouverture de l'accès au programme sclérochronologie du compte admin +insert into UserProfile values ( + 'fr.ifremer.wao.entities.UserProfile#129111142543000#933200987654321550', + 1, + now(), + (select topiaId from WaoUser where login = 'admin'), + 'SCLEROCHRONOLOGY', + 'ADMIN', + true, + uuid_in(md5(random()::text || now()::text)::cstring) +); diff --git a/wao-persistence/src/main/xmi/wao-model.properties b/wao-persistence/src/main/xmi/wao-model.properties index 86db9ad..b807930 100644 --- a/wao-persistence/src/main/xmi/wao-model.properties +++ b/wao-persistence/src/main/xmi/wao-model.properties @@ -21,7 +21,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # #L% ### -model.tagValue.version=4.3 +model.tagValue.version=5.0 model.tagValue.useEnumerationName=true # orderBy tagValues diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/UpdateWaoUserCommand.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/UpdateWaoUserCommand.java index d40c5dd..ef67ec0 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/UpdateWaoUserCommand.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/UpdateWaoUserCommand.java @@ -257,4 +257,13 @@ public class UpdateWaoUserCommand implements Serializable{ public void setObsProgram(ObsProgram obsProgram) { this.obsProgram = obsProgram; } + + public boolean isGuestRoleAvailable() { + return ! obsProgram.isSclerochronology(); + } + + public boolean isProfessionalRoleAvailable() { + return ! obsProgram.isSclerochronology(); + } + } diff --git a/wao-web/src/main/webapp/WEB-INF/content/administration/edit-wao-user.jsp b/wao-web/src/main/webapp/WEB-INF/content/administration/edit-wao-user.jsp index 66e6cac..9466a5f 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/administration/edit-wao-user.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/administration/edit-wao-user.jsp @@ -149,11 +149,11 @@ <s:checkbox name="updateWaoUserCommand.observer" label="%{getText('wao.ui.form.updateWaoUserCommand.observer')}" /> <s:checkbox name="updateWaoUserCommand.observerReadOnly" label="%{getText('wao.ui.form.updateWaoUserCommand.observerReadOnly')}" /> </s:if> - <s:if test="authenticatedWaoUser.authorizedToSetGuest"> + <s:if test="authenticatedWaoUser.authorizedToSetGuest && updateWaoUserCommand.guestRoleAvailable"> <s:checkbox name="updateWaoUserCommand.guest" label="%{getText('wao.ui.form.updateWaoUserCommand.guest')}" /> <s:checkbox name="updateWaoUserCommand.guestReadOnly" label="%{getText('wao.ui.form.updateWaoUserCommand.guestReadOnly')}" /> </s:if> - <s:if test="authenticatedWaoUser.authorizedToSetProfessional"> + <s:if test="authenticatedWaoUser.authorizedToSetProfessional && updateWaoUserCommand.professionalRoleAvailable"> <s:checkbox name="updateWaoUserCommand.professional" label="%{getText('wao.ui.form.updateWaoUserCommand.professional')}" /> <s:checkbox name="updateWaoUserCommand.professionalReadOnly" label="%{getText('wao.ui.form.updateWaoUserCommand.professionalReadOnly')}" /> <div id="defineCanReadBoats"> diff --git a/wao-web/src/main/webapp/WEB-INF/decorators/layout.jsp b/wao-web/src/main/webapp/WEB-INF/decorators/layout.jsp index 3f9cf39..7f9a39f 100644 --- a/wao-web/src/main/webapp/WEB-INF/decorators/layout.jsp +++ b/wao-web/src/main/webapp/WEB-INF/decorators/layout.jsp @@ -115,8 +115,6 @@ <div class="navbar"> <div class="navbar-inner"> <a class="brand" href="#"><span>WAO</span> <s:text name="%{obsProgram.getI18nKey()}"/></a> - - <%--<a class="brand" href="#">Wao <s:property value="%{getText(#obsProgram.getI18nKey())}" /></a>--%> <ul class="nav"> <li class="<decorator:getProperty property="page.newsMenuItemClass"/>"> <s:url namespace="/%{obsProgram.name().toLowerCase()}" action="news" id="newsUrl" /> @@ -130,29 +128,35 @@ <i class="fa fa-calendar"></i> <s:text name="wao.ui.page.SamplingPlan.title" /> </s:a> </li> - <s:if test="authenticatedWaoUser.authorizedToViewBoats"> - <li class="<decorator:getProperty property="page.boatsMenuItemClass"/>"> - <s:url namespace="/%{obsProgram.name().toLowerCase()}" action="boats" id="boatsUrl" /> - <s:a href="%{boatsUrl}"> - <i class="fa fa-anchor"></i> <s:text name="wao.ui.page.Boats.title" /> - </s:a> - </li> + <s:if test=" ! sclerochronology"> + <s:if test="authenticatedWaoUser.authorizedToViewBoats"> + <li class="<decorator:getProperty property="page.boatsMenuItemClass"/>"> + <s:url namespace="/%{obsProgram.name().toLowerCase()}" action="boats" id="boatsUrl" /> + <s:a href="%{boatsUrl}"> + <i class="fa fa-anchor"></i> <s:text name="wao.ui.page.Boats.title" /> + </s:a> + </li> + </s:if> </s:if> - <s:if test="authenticatedWaoUser.authorizedToViewContacts"> - <li class="<decorator:getProperty property="page.contactsMenuItemClass"/>"> - <s:url namespace="/%{obsProgram.name().toLowerCase()}" action="contacts" id="contactsUrl" /> - <s:a href="%{contactsUrl}"> - <i class="fa fa-stack-exchange"></i> <s:text name="wao.ui.page.Contacts.title" /> - </s:a> - </li> + <s:if test=" ! sclerochronology"> + <s:if test="authenticatedWaoUser.authorizedToViewContacts"> + <li class="<decorator:getProperty property="page.contactsMenuItemClass"/>"> + <s:url namespace="/%{obsProgram.name().toLowerCase()}" action="contacts" id="contactsUrl" /> + <s:a href="%{contactsUrl}"> + <i class="fa fa-stack-exchange"></i> <s:text name="wao.ui.page.Contacts.title" /> + </s:a> + </li> + </s:if> </s:if> - <s:if test="authenticatedWaoUser.authorizedToViewSynthesis"> - <li class="<decorator:getProperty property="page.synthesisMenuItemClass"/>"> - <s:url namespace="/%{obsProgram.name().toLowerCase()}" action="synthesis" id="synthesisUrl" /> - <s:a href="%{synthesisUrl}"> - <i class="fa fa-bar-chart-o"></i> <s:text name="wao.ui.page.Synthesis.title" /> - </s:a> - </li> + <s:if test=" ! sclerochronology"> + <s:if test="authenticatedWaoUser.authorizedToViewSynthesis"> + <li class="<decorator:getProperty property="page.synthesisMenuItemClass"/>"> + <s:url namespace="/%{obsProgram.name().toLowerCase()}" action="synthesis" id="synthesisUrl" /> + <s:a href="%{synthesisUrl}"> + <i class="fa fa-bar-chart-o"></i> <s:text name="wao.ui.page.Synthesis.title" /> + </s:a> + </li> + </s:if> </s:if> </ul> <ul class="nav pull-right"> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2263 in repository wao. See http://git.codelutin.com/wao.git commit fd59834846ebbb3791bedd46b9a6884483e60643 Author: Brendan Le Ny <bleny@codelutin.com> Date: Mon Dec 15 15:49:36 2014 +0100 Modification du modèle de la ligne du plan, introduction du service et de la vue pour le plan scléro, migration --- .../wao/entity/IndividualMeasurementStrategy.java | 39 ++ .../entity/SclerochronologySamplingContext.java | 38 ++ .../db/migration/V5_0__sclerochronology.sql | 5 + .../i18n/wao-persistence_en_GB.properties | 6 + .../i18n/wao-persistence_fr_FR.properties | 6 + wao-persistence/src/main/xmi/wao-model.zargo | Bin 61366 -> 61993 bytes .../service/SclerochronologySamplingPlan.java | 107 +++++ .../SclerochronologySamplingPlanBuilder.java | 326 +++++++++++++++ .../SclerochronologySamplingPlanService.java | 89 ++++ .../sclerochronology/SamplingPlanAction.java | 43 ++ .../SamplingPlanAction-conversion.properties | 1 + .../main/resources/i18n/wao-web_en_GB.properties | 4 + .../main/resources/i18n/wao-web_fr_FR.properties | 4 + .../content/sclerochronology/sampling-plan.jsp | 449 +++++++++++++++++++++ 14 files changed, 1117 insertions(+) diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/IndividualMeasurementStrategy.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/IndividualMeasurementStrategy.java new file mode 100644 index 0000000..0f69565 --- /dev/null +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/IndividualMeasurementStrategy.java @@ -0,0 +1,39 @@ +package fr.ifremer.wao.entity; + +import static org.nuiton.i18n.I18n.n; + +/** + * Dans la sclérochronologie, représente les caractéristiques qu'il est demander de mesurer + * lors de l'échantillonnage d'un individu. + * + * @since 5.0 + */ +public enum IndividualMeasurementStrategy implements I18nAble { + + /** + * Taille, poids » et « » + */ + SIZE_WEIGHT(n("IndividualMeasurementStrategy.SIZE_WEIGHT")), + + /** + * Taille, poids, sexe + */ + SIZE_WEIGHT_SEX(n("IndividualMeasurementStrategy.SIZE_WEIGHT_SEX")), + + /** + * Taille, poids, sexe, maturité, âge + */ + SIZE_WEIGHT_SEX_MATURITY_AGE(n("IndividualMeasurementStrategy.SIZE_WEIGHT_SEX_MATURITY_AGE")); + + protected String i18nKey; + + IndividualMeasurementStrategy(String i18nKey) { + this.i18nKey = i18nKey; + } + + @Override + public String getI18nKey() { + return i18nKey; + } + +} diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/SclerochronologySamplingContext.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/SclerochronologySamplingContext.java new file mode 100644 index 0000000..68648a3 --- /dev/null +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/SclerochronologySamplingContext.java @@ -0,0 +1,38 @@ +package fr.ifremer.wao.entity; + + +import static org.nuiton.i18n.I18n.n; + +/** + * Contexte dans lequel l'échantillonnage pour la sclérochronologie a été effectué. + * + * @since 5.0 + */ +public enum SclerochronologySamplingContext implements I18nAble { + + /** + * Campagne scientifique + */ + SCIENTIFIC_CAMPAIGN(n("SclerochronologySamplingContext.SCIENTIFIC_CAMPAIGN")), + + /** + * Échantillonnage en mer + */ + FISHING_TRIP(n("SclerochronologySamplingContext.FISHING_TRIP")), + + /** + * Échantillonnage à terre + */ + TERRESTRIAL_SAMPLING(n("SclerochronologySamplingContext.TERRESTRIAL_SAMPLING")); + + protected String i18nKey; + + SclerochronologySamplingContext(String i18nKey) { + this.i18nKey = i18nKey; + } + + @Override + public String getI18nKey() { + return i18nKey; + } +} diff --git a/wao-persistence/src/main/resources/db/migration/V5_0__sclerochronology.sql b/wao-persistence/src/main/resources/db/migration/V5_0__sclerochronology.sql index ee61e50..fe74d39 100644 --- a/wao-persistence/src/main/resources/db/migration/V5_0__sclerochronology.sql +++ b/wao-persistence/src/main/resources/db/migration/V5_0__sclerochronology.sql @@ -11,3 +11,8 @@ insert into UserProfile values ( true, uuid_in(md5(random()::text || now()::text)::cstring) ); + +alter table SampleRow add column species character varying(255) references Species(topiaId); +alter table SampleRow add column sclerochronologySamplingContext character varying(255); +alter table SampleRow add column individualMeasurementStrategy character varying(255); +alter table SampleRow add column sclerochronologySamplingContextInfo text; diff --git a/wao-persistence/src/main/resources/i18n/wao-persistence_en_GB.properties b/wao-persistence/src/main/resources/i18n/wao-persistence_en_GB.properties index 4334ea7..e4f6dfb 100644 --- a/wao-persistence/src/main/resources/i18n/wao-persistence_en_GB.properties +++ b/wao-persistence/src/main/resources/i18n/wao-persistence_en_GB.properties @@ -21,6 +21,9 @@ GlobalIndicatorValue.GOOD=Level 1 bonus GlobalIndicatorValue.NEUTRAL=Conform GlobalIndicatorValue.VERY_BAD=Level 2 penalty GlobalIndicatorValue.VERY_GOOD=Level 2 bonus +IndividualMeasurementStrategy.SIZE_WEIGHT=Size, weight +IndividualMeasurementStrategy.SIZE_WEIGHT_SEX=Size, weight, sex +IndividualMeasurementStrategy.SIZE_WEIGHT_SEX_MATURITY_AGE=Size, weight, sex, maturity, age LocationType.AUCTION=Auction LocationType.DISTRICT=District LocationType.PORT=Port @@ -37,6 +40,9 @@ SamplingStrategy.SIMULTANEOUS_ALL_SPECIES=Simultaneous \: All commercial species SamplingStrategy.SIMULTANEOUS_G1_G2_SPECIES=Simultaneous \: G1+G2 species SamplingStrategy.SIMULTANEOUS_G1_SPECIES=Simultaneous \: G1 species SamplingStrategy.SPECIFIC_STOCK=Specific stock +SclerochronologySamplingContext.FISHING_TRIP=Fishing trip +SclerochronologySamplingContext.SCIENTIFIC_CAMPAIGN=Scientific campaign +SclerochronologySamplingContext.TERRESTRIAL_SAMPLING=Terrestrial sampling StrategyValues.CONTACTS_STATES=Contact states by boat district StrategyValues.CONTACTS_STATES_MOTIFS=Refusal motives StrategyValues.CONTACTS_STATES_SEABOARDS=Contact states by seaboard diff --git a/wao-persistence/src/main/resources/i18n/wao-persistence_fr_FR.properties b/wao-persistence/src/main/resources/i18n/wao-persistence_fr_FR.properties index cf72839..972c780 100644 --- a/wao-persistence/src/main/resources/i18n/wao-persistence_fr_FR.properties +++ b/wao-persistence/src/main/resources/i18n/wao-persistence_fr_FR.properties @@ -21,6 +21,9 @@ GlobalIndicatorValue.GOOD=Bonus de niveau 1 GlobalIndicatorValue.NEUTRAL=Conforme au cahier des charges GlobalIndicatorValue.VERY_BAD=Pénalité de niveau 2 GlobalIndicatorValue.VERY_GOOD=Bonus de niveau 2 +IndividualMeasurementStrategy.SIZE_WEIGHT=Poids, taille +IndividualMeasurementStrategy.SIZE_WEIGHT_SEX=Poids, taille, sexe +IndividualMeasurementStrategy.SIZE_WEIGHT_SEX_MATURITY_AGE=Poids, taille, sexe, maturité, âge LocationType.AUCTION=Criée LocationType.DISTRICT=Quartier maritime LocationType.PORT=Port @@ -37,6 +40,9 @@ SamplingStrategy.SIMULTANEOUS_ALL_SPECIES=Simultané \: Toutes espèces commerci SamplingStrategy.SIMULTANEOUS_G1_G2_SPECIES=Simultané \: espèces G1+G2 SamplingStrategy.SIMULTANEOUS_G1_SPECIES=Simultané \: espèces G1 SamplingStrategy.SPECIFIC_STOCK=Stock spécifique +SclerochronologySamplingContext.FISHING_TRIP=Échantillonnage en mer +SclerochronologySamplingContext.SCIENTIFIC_CAMPAIGN=Campagne scientifique +SclerochronologySamplingContext.TERRESTRIAL_SAMPLING=Échantillonnage à terre StrategyValues.CONTACTS_STATES=États des contacts selon le quartier maritime StrategyValues.CONTACTS_STATES_MOTIFS=Motifs de refus StrategyValues.CONTACTS_STATES_SEABOARDS=États des contacts selon la façade maritime diff --git a/wao-persistence/src/main/xmi/wao-model.zargo b/wao-persistence/src/main/xmi/wao-model.zargo index 5f27d3a..5535ef4 100644 Binary files a/wao-persistence/src/main/xmi/wao-model.zargo and b/wao-persistence/src/main/xmi/wao-model.zargo differ diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java new file mode 100644 index 0000000..d23fefd --- /dev/null +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlan.java @@ -0,0 +1,107 @@ +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.WaoUtils; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.SampleRow; + +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +public class SclerochronologySamplingPlan extends SamplingPlan implements Iterable<SamplingPlan.SamplingPlanFacadePart> { + + public SclerochronologySamplingPlan(List<Date> months, Collection<SamplingPlanFacadePart> facadeParts, Map<Date, Effort> totalEffortInObservationsPerMonths, Effort highTotalEffortInObservations, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { + super(months, facadeParts, totalEffortInObservationsPerMonths, highTotalEffortInObservations, filterValues, sampleRowIds); + } + + public static class SclerochronologySamplingPlanSampleRowPart extends SamplingPlanSampleRowPart { + + protected String samplingContext; + + protected String samplingContextInfo; + + protected String individualMeasurementStrategy; + + protected String species; + + public SclerochronologySamplingPlanSampleRowPart(Locale locale, Map<Date, Effort> effortInObservationsPerMonths, SampleRow sampleRow, long sampleRowContactCounts) { + super(locale, effortInObservationsPerMonths, sampleRow, sampleRowContactCounts); + species = sampleRow.getSpecies().getVernacularName(); + samplingContext = WaoUtils.l(locale, sampleRow.getSclerochronologySamplingContext()); + samplingContextInfo = sampleRow.getSclerochronologySamplingContextInfo(); + individualMeasurementStrategy = WaoUtils.l(locale, sampleRow.getIndividualMeasurementStrategy()); + } + + public String getSamplingContextInfo() { + return samplingContextInfo; + } + + public String getIndividualMeasurementStrategy() { + return individualMeasurementStrategy; + } + + public String getSpecies() { + return species; + } + + public String getSamplingContext() { + return samplingContext; + } + + @Override + public Map<String, String> getDcf5CodesAndDescriptions() { + throw new UnsupportedOperationException("not in " + ObsProgram.SCLEROCHRONOLOGY); + } + + @Override + public String getProfessionMeshSize() { + throw new UnsupportedOperationException("not in " + ObsProgram.SCLEROCHRONOLOGY); + } + + @Override + public String getProfessionSize() { + throw new UnsupportedOperationException("not in " + ObsProgram.SCLEROCHRONOLOGY); + } + + @Override + public String getProfessionOther() { + throw new UnsupportedOperationException("not in " + ObsProgram.SCLEROCHRONOLOGY); + } + + @Override + public String getProfessionLibelle() { + throw new UnsupportedOperationException("not in " + ObsProgram.SCLEROCHRONOLOGY); + } + + @Override + public String getProfessionSpecies() { + throw new UnsupportedOperationException("not in " + ObsProgram.SCLEROCHRONOLOGY); + } + + } + +} \ No newline at end of file diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java new file mode 100644 index 0000000..aed9964 --- /dev/null +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanBuilder.java @@ -0,0 +1,326 @@ +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 5.0 + */ +public class SclerochronologySamplingPlanBuilder { + + /** + * 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.SclerochronologySamplingPlan#highTotalEffortInObservations + */ + protected int highTotalExpected; + + /** + * To compute the high total real. + * + * @see fr.ifremer.wao.services.service.SclerochronologySamplingPlan#highTotalEffortInObservations + */ + protected int highTotalReal; + + /** + * To compute the high total estimated. + * + * @see fr.ifremer.wao.services.service.SclerochronologySamplingPlan#highTotalEffortInObservations + */ + protected int highTotalEstimated; + + /** + * To compute by month the total of expected tides. + * + * @see fr.ifremer.wao.services.service.SamplingPlan.Effort#expected + */ + protected Map<Date, MutableInt> totalExpectedForMonths; + + /** + * To compute by month the total of expected tides. + * + * @see fr.ifremer.wao.services.service.SamplingPlan.Effort#estimated + */ + protected Map<Date, MutableInt> totalEstimatedForMonths; + + /** + * To compute by month the total of real tides. + * + * @see fr.ifremer.wao.services.service.SamplingPlan.Effort#real + */ + protected Map<Date, MutableInt> totalRealForMonths; + + public SclerochronologySamplingPlanBuilder(Locale locale, + Optional<String> optionalCompanyId, + SampleRowsFilter sampleRowsFilter) { + this.sampleRowsFilter = sampleRowsFilter; + this.sampleRowsFilterValues = new SampleRowsFilterValues(locale, ObsProgram.SCLEROCHRONOLOGY, 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 SclerochronologySamplingPlanBuilder addSampleRow(SampleRow sampleRow, long sampleRowContactCounts) { + + 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, SamplingPlan.Effort> effortInObservationsPerMonths = getEffortInObservationsPerMonths(sampleRow); + + // add sample row + sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), + sampleRow, + effortInObservationsPerMonths, + sampleRowContactCounts); + + sampleRowsFilterValues.addSampleRow(sampleRow); + + sampleRowIds.add(sampleRow.getTopiaId()); + + return this; + } + + public SclerochronologySamplingPlan 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, SamplingPlan.Effort> statisticsMap = new TreeMap<>(); + for (Date month : months) { + + MutableInt totalExpected = totalExpectedForMonths.get(month); + MutableInt totalReal = totalRealForMonths.get(month); + MutableInt totalEstimated = totalEstimatedForMonths.get(month); + SamplingPlan.Effort planStatistics = + new SamplingPlan.Effort(totalExpected == null ? null : totalExpected.toInteger(), + totalReal == null ? null : totalReal.toInteger(), + totalEstimated == null ? null : totalEstimated.toInteger()); + statisticsMap.put(month, planStatistics); + } + + SamplingPlan.Effort highTotals = new SamplingPlan.Effort(highTotalExpected, highTotalReal, highTotalEstimated); + + SclerochronologySamplingPlan result = new SclerochronologySamplingPlan(months, + sortedFacades, + statisticsMap, + highTotals, + sampleRowsFilterValues, + sampleRowIds); + return result; + } + + protected Map<Date, SamplingPlan.Effort> getEffortInObservationsPerMonths(SampleRow sampleRow) { + Map<Date, SamplingPlan.Effort> 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 SamplingPlan.Effort(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<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart> rows; + + protected SectorContext(String sectors) { + this.sectors = sectors; + this.rows = new ArrayList<>(); + } + + protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow(Locale locale, + SampleRow row, + Map<Date, SamplingPlan.Effort> effortInObservationsPerMonths, + long sampleRowContactCounts) { + + SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart rowPart = + new SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart( + locale, + effortInObservationsPerMonths, + row, + sampleRowContactCounts); + rows.add(rowPart); + + return rowPart; + } + + protected SamplingPlan.SamplingPlanSectorPart toBean() { + + Collection<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart> sortedRows = Ordering.natural().onResultOf(new Function<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart, String>() { + public String apply(SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart input) { + return input.getCode(); + } + }).immutableSortedCopy(rows); + SamplingPlan.SamplingPlanSectorPart result = + new SamplingPlan.SamplingPlanSectorPart(sectors, sortedRows); + return result; + } + } +} diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java new file mode 100644 index 0000000..f0cd05f --- /dev/null +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java @@ -0,0 +1,89 @@ +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.Optional; +import com.google.common.cache.Cache; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.entity.ContactTopiaDao; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowTopiaDao; +import fr.ifremer.wao.services.AuthenticatedWaoUser; + +import java.util.List; + +public class SclerochronologySamplingPlanService extends SamplingPlanService { + + public SclerochronologySamplingPlan 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(); + + SclerochronologySamplingPlan result = (SclerochronologySamplingPlan) samplingPlansCache.getIfPresent(samplingPlanCacheKey); + + if (result == null) { + + SampleRowTopiaDao dao = getSampleRowDao(); + ContactTopiaDao contactDao = getContactDao(); + + // recuperation des lignes du plan + List<SampleRow> sampleRows = dao.findAll(sampleRowsFilter); + + // creation du plan d'echantillonnage + SclerochronologySamplingPlanBuilder builder = new SclerochronologySamplingPlanBuilder( + serviceContext.getLocale(), + optionalCompanyId, + sampleRowsFilter); + + for (SampleRow sampleRow : sampleRows) { + + long sampleRowContactCounts = contactDao.forSampleRowEquals(sampleRow).count(); + + // ajout de la ligne au build de plan + builder.addSampleRow(sampleRow, sampleRowContactCounts); + + } + + result = builder.toPlan(); + + samplingPlansCache.put(samplingPlanCacheKey.clone(), result); + + } + + return result; + + } + +} diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/sclerochronology/SamplingPlanAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/sclerochronology/SamplingPlanAction.java new file mode 100644 index 0000000..fe9f68a --- /dev/null +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/sclerochronology/SamplingPlanAction.java @@ -0,0 +1,43 @@ +package fr.ifremer.wao.web.action.sclerochronology; + +/* + * #%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.SclerochronologySamplingPlan; +import fr.ifremer.wao.services.service.SclerochronologySamplingPlanService; +import fr.ifremer.wao.web.action.AbstractSamplingPlanAction; + +public class SamplingPlanAction extends AbstractSamplingPlanAction { + + protected SclerochronologySamplingPlanService service; + + public void setService(SclerochronologySamplingPlanService service) { + this.service = service; + } + + @Override + protected SclerochronologySamplingPlan samplingPlan() { + + return service.getSamplingPlan(getAuthenticatedWaoUser(), filter); + + } + +} diff --git a/wao-web/src/main/resources/fr/ifremer/wao/web/action/sclerochronology/SamplingPlanAction-conversion.properties b/wao-web/src/main/resources/fr/ifremer/wao/web/action/sclerochronology/SamplingPlanAction-conversion.properties new file mode 100644 index 0000000..977bee2 --- /dev/null +++ b/wao-web/src/main/resources/fr/ifremer/wao/web/action/sclerochronology/SamplingPlanAction-conversion.properties @@ -0,0 +1 @@ +filter=org.nuiton.web.struts2.converters.JsonConverter diff --git a/wao-web/src/main/resources/i18n/wao-web_en_GB.properties b/wao-web/src/main/resources/i18n/wao-web_en_GB.properties index da6df47..e540698 100644 --- a/wao-web/src/main/resources/i18n/wao-web_en_GB.properties +++ b/wao-web/src/main/resources/i18n/wao-web_en_GB.properties @@ -253,6 +253,7 @@ wao.ui.field.SampleRow.elligibleBoat=Eligible boats wao.ui.field.SampleRow.expectedDate=Date wao.ui.field.SampleRow.fishingZones=Fishing zone(s) wao.ui.field.SampleRow.fishingZonesInfos=Fishing zone(s) details +wao.ui.field.SampleRow.individualMeasurementStrategy=Individual measurement strategy wao.ui.field.SampleRow.libelle=Labels wao.ui.field.SampleRow.meshSize=Mesh size wao.ui.field.SampleRow.nbObservants=Number of observers @@ -266,7 +267,10 @@ wao.ui.field.SampleRow.profession=Profession wao.ui.field.SampleRow.professionCode=Profession code wao.ui.field.SampleRow.programName=Program wao.ui.field.SampleRow.regionIfremer=Region +wao.ui.field.SampleRow.samplingContext= wao.ui.field.SampleRow.samplingStrategy=Sampling strategy +wao.ui.field.SampleRow.sclerochronologySamplingContext=Context +wao.ui.field.SampleRow.sclerochronologySamplingContextInfo=Context (details) wao.ui.field.SampleRow.size=Boat size wao.ui.field.SampleRow.species=Species wao.ui.field.SampleRow.terrestrialLocation=Maritime district diff --git a/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties b/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties index 5f60f26..0726cc6 100644 --- a/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties +++ b/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties @@ -254,6 +254,7 @@ wao.ui.field.SampleRow.elligibleBoat=Navires éligibles wao.ui.field.SampleRow.expectedDate=Date wao.ui.field.SampleRow.fishingZones=Zone(s) de pêche wao.ui.field.SampleRow.fishingZonesInfos=Autres informations +wao.ui.field.SampleRow.individualMeasurementStrategy=Paramètres à mesurer wao.ui.field.SampleRow.libelle=Libellé wao.ui.field.SampleRow.meshSize=Maillage wao.ui.field.SampleRow.nbObservants=Nombre d'observateurs @@ -267,7 +268,10 @@ wao.ui.field.SampleRow.profession=Métier wao.ui.field.SampleRow.professionCode=Code métier wao.ui.field.SampleRow.programName=Programme wao.ui.field.SampleRow.regionIfremer=Région +wao.ui.field.SampleRow.samplingContext= wao.ui.field.SampleRow.samplingStrategy=Stratégie d'échantillonnage +wao.ui.field.SampleRow.sclerochronologySamplingContext=Contexte +wao.ui.field.SampleRow.sclerochronologySamplingContextInfo=Contexte (complément) wao.ui.field.SampleRow.size=Taille du navire wao.ui.field.SampleRow.species=Espèces cibles wao.ui.field.SampleRow.terrestrialLocation=Quartier maritime diff --git a/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp new file mode 100644 index 0000000..30dd0c5 --- /dev/null +++ b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp @@ -0,0 +1,449 @@ +<%-- + #%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.SamplingPlan.title" /> + </title> + + <script> + + $(document).ready(function () { + + // var sampleRowsFilterController = new FilterController(WAO.SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form')); + // sampleRowsFilterController.init(); + + var sampleRowsFilterMappings = [ + <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + { + filterName: 'companyIds', + filterLabel: "<s:text name="wao.ui.entity.Company"/>", + filterValuesField: 'companies', + }, + </s:if> + { + filterName: 'programNames', + filterLabel: "<s:text name="wao.ui.field.SampleRow.programName"/>", + filterValuesField: 'programNames', + }, + { + filterName: 'sampleRowCodes', + filterLabel: "<s:text name="wao.ui.field.SampleRow.code"/>", + filterValuesField: 'sampleRowCodes', + }, + { + filterName: 'fishingZoneFacadeNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.facadeName"/>", + filterValuesField: 'fishingZoneFacadeNames', + }, + { + filterName: 'fishingZoneSectorNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.sectorName"/>", + filterValuesField: 'fishingZoneSectorNames', + }, + { + filterName: 'samplingContext', + filterLabel: "<s:text name="wao.ui.field.SampleRow.sclerochronologySamplingContext"/>", + filterValuesField: 'samplingContexts', + }, + { + filterName: 'individualMeasurementStrategy', + filterLabel: "<s:text name="wao.ui.field.SampleRow.individualMeasurementStrategy"/>", + filterValuesField: 'individualMeasurementStrategies', + }, + { + filterName: 'species', + filterLabel: "<s:text name="wao.ui.field.SampleRow.species"/>", + filterValuesField: 'species' + } + ]; + + filter = <s:property value="filter" escapeHtml="false"/>; + + 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 () { + $('#switch-estimated-real').toggleClass('show-estimated').toggleClass('show-real'); + $('table.sampling-plan').toggleClass('show-estimated').toggleClass('show-real'); + $('.estimated-differ-from-real').effect( "highlight", "slow" ) + }); + + var $views = $('#switch-compact-full-view, table.sampling-plan'); + $views.toggleCompactFullView(WAO.getCookie().samplingPlanFullView); + + $('#switch-compact-full-view').click(function () { + WAO.getCookie().samplingPlanFullView = ! WAO.getCookie().samplingPlanFullView; + $views.toggleCompactFullView(WAO.getCookie().samplingPlanFullView); + }); + + }); + + </script> + + </head> + + <content tag="mainClass">large</content> + <content tag="samplingPlanMenuItemClass">active</content> + + <s:if test="authenticatedWaoUser.authorizedToEditSamplingPlan"> + <content tag="administrationMenuOtherOptions"> + <li> + <s:url action="edit-sample-row!input" id="createSampleRow"/> + <s:a href="%{createSampleRow}"> + <i class="icon-plus"></i> <s:text name="wao.ui.action.createSampleRow"/> + </s:a> + </li> + </content> + </s:if> + + <s:form method="GET" id="sampling-plan-filters-form" cssClass="filters-form"> + + <fieldset class="filters-group"> + + <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" /> + + </fieldset> + + <fieldset class="extra-filters"> + + </fieldset> + + <div class="form-actions"> + + <s:submit type="button" action="sampling-plan!applyFilter" cssClass="btn btn-primary"> + <i class="icon-filter"></i> <s:text name="wao.ui.action.filter" /> + </s:submit> + + <s:submit type="button" action="sampling-plan!resetFilter" cssClass="btn"> + <i class="icon-trash"></i> <s:text name="wao.ui.action.reset"/> + </s:submit> + + <s:if test="authenticatedWaoUser.authorizedToExportSamplingPlan"> + <s:submit action="export-sampling-plan" type="button" cssClass="btn"> + <i class="icon-download"></i> <s:text name="wao.ui.action.csvExport" /> + </s:submit> + </s:if> + + </div> + + </s:form> + + <div class="sticky-buttons"> + <button type="button" id="switch-compact-full-view" class="btn"> + <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> + + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <button type="button" id="switch-estimated-real" class="btn show-estimated"> + <span class="estimated"> + <i class="fa fa-adjust"></i><span class="only-on-hover"> <s:text name="wao.ui.action.viewReal" /></span> + </span> + <span class="real"> + <i class="fa fa-adjust"></i><span class="only-on-hover"> <s:text name="wao.ui.action.viewEstimated" /></span> + </span> + </button> + </s:if> + </div> + +<s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + <s:set var="nbColumnsForProfessionInFullView" value="10" /> +</s:if> +<s:else> + <s:set var="nbColumnsForProfessionInFullView" value="9" /> +</s:else> +<s:set var="nbColumnsForProfessionInCompactView" value="6" /> +<s:set var="nbColumnsForMonths" value="%{samplingPlan.months.size() + 1}" /> +<s:set var="nbColumnsForOther" value="2" /> +<s:set var="nbColumnsTotalInFullView" value="%{#nbColumnsForProfessionInFullView + #nbColumnsForMonths + #nbColumnsForOther}" /> +<s:set var="nbColumnsTotalInCompactView" value="%{#nbColumnsForProfessionInCompactView + #nbColumnsForMonths + #nbColumnsForOther}" /> + + <table id="sampling-plan" class="large-table sampling-plan show-estimated"> + <thead> + <tr> + <th colspan="<s:property value="#nbColumnsForProfessionInFullView" />" class="only-in-full-view"> + <s:text name="wao.ui.samplingPlan.sampledProfessions" /> + </th> + <th colspan="<s:property value="#nbColumnsForProfessionInCompactView" />" class="only-in-compact-view"> + <s:text name="wao.ui.samplingPlan.sampledProfessions" /> + </th> + <th colspan="${nbColumnsForMonths}"> + <s:text name="wao.ui.samplingPlan.effort" /> + + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + [ + <span class="estimated"> + (<s:text name="wao.ui.samplingPlan.actual" /> + <s:text name="wao.ui.samplingPlan.estimated" />) + </span> + <span class="real"> + <s:text name="wao.ui.samplingPlan.actual" /> + </span> + / + <s:text name="wao.ui.samplingPlan.expected" /> + ] + </s:if> + </th> + <th colspan="${nbColumnsForOther}"><s:text name="wao.ui.misc.others" /></th> + </tr> + <tr> + <!-- Profession columns --> + <th><s:text name="wao.ui.field.SampleRow.code"/></th> + <th><s:text name="wao.ui.samplingPlan.program"/></th> + <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + <th class="only-in-full-view"> + <s:text name="wao.ui.entity.Organisation"/> + </th> + </s:if> + <th><s:text name="wao.ui.entity.FishingZone"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.samplingPlan.fishingZoneInfo"/></th> + <th><s:text name="wao.ui.field.SampleRow.sclerochronologySamplingContext"/></th> + <th><s:text name="wao.ui.field.SampleRow.sclerochronologySamplingContextInfo"/></th> + <th><s:text name="wao.ui.field.SampleRow.individualMeasurementStrategy"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.periodBegin"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.periodEnd"/></th> + + <!-- Months columns --> + <s:iterator value="samplingPlan.months" var="month"> + <th class="effort <s:if test="isCurrentMonth(#month)"> now</s:if>"> + <span class="month"><s:property value="%{formatDateMonth(#month)}"/></span> + <span class="year"><s:property value="%{formatDateYear(#month)}"/></span> + </th> + </s:iterator> + <th><s:text name="wao.ui.misc.total"/></th> + <!-- Other columns --> + <th><s:text name="wao.ui.misc.comment"/></th> + <th><s:text name="wao.ui.samplingPlan.actions"/></th> + </tr> + </thead> + <tbody> + +<%--Iterate on Facades--%> +<s:iterator value="samplingPlan" var="samplingPlanFacade"> + <tr class="facade-row"> + <th colspan="${nbColumnsTotalInFullView}" class="facade only-in-full-view"> + <s:property value="%{#samplingPlanFacade.facade}"/> + </th> + <th colspan="${nbColumnsTotalInCompactView}" class="facade only-in-compact-view"> + <s:property value="%{#samplingPlanFacade.facade}"/> + </th> + </tr> +<%--Iterate on Sectors --%> +<s:iterator value="samplingPlanFacade" var="samplingPlanSector"> + <tr class="sector-row"> + <th colspan="${nbColumnsTotalInFullView}" class="sector only-in-full-view"> + <s:property value="%{#samplingPlanSector.sectors}"/> + </th> + </tr> + <tr class="sector-row"> + <th colspan="${nbColumnsTotalInCompactView}" class="sector only-in-compact-view"> + <s:property value="%{#samplingPlanSector.sectors}"/> + </th> + </tr> +<%--Iterate on SampleRows --%> +<s:iterator value="samplingPlanSector" var="samplingPlanRow"> + <tr class="sample-row-row<s:if test="sampleRowId.equals(sampleRowToHighlightId)"> highlight</s:if>"> + <th> + <s:property value="code" /> + <s:if test="recentlyUpdated"> + <span class="label label-important"> + <s:text name="wao.ui.misc.recentUpdate" /> + </span> + </s:if> + </th> + <td><s:property value="programName" /></td> + <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + <td class="only-in-full-view"> + <s:property value="companyName" /> + </td> + </s:if> + <td class="only-in-full-view"><s:property value="fishingZones" /></td> + <td class="only-in-compact-view"> + <s:if test="fishingZonesInfos == null"> + <s:property value="fishingZones"/> + </s:if> + <s:else> + <span data-original-title="<s:property value="fishingZonesInfos" escapeHtml="false"/>" data-toggle="tooltip" data-placement="left"> + <s:property value="fishingZones"/> + </span> + </s:else> + </td> + <td class="only-in-full-view"> + <s:property value="fishingZonesInfos" /> + </td> + <td> + <s:property value="samplingContext"/> + </td> + <td> + <s:property value="samplingContextInfo"/> + </td> + <td> + <s:property value="individualMeasurementStrategy"/> + </td> + <td class="only-in-full-view"><s:property value="%{formatMonth(periodBegin)}" /></td> + <td class="only-in-full-view"><s:property value="%{formatMonth(periodEnd)}" /></td> + <!-- Months columns --> +<s:iterator value="samplingPlan.months" var="month"> + <s:set var="effort" value="#samplingPlanRow.effortInObservationsPerMonths.get(#month)"/> + <s:set var="now" value="%{isCurrentMonth(#month)}"/> + <s:set var="showPercentage" value="false"/> + <%@include file="../templates/td-effort.jsp" %> +</s:iterator> + + <s:set var="effort" value="#samplingPlanRow.totalObservations"/> + <s:set var="now" value="false"/> + <s:set var="showPercentage" value="true"/> + <%@include file="../templates/td-effort.jsp" %> + + <td> + <s:if test=" ! comment.empty"> + <i title="<s:property value="comment" escapeHtml="true"/>" class="fa fa-comment"></i> + </s:if> + </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"> + <s:if test="authenticatedWaoUser.authorizedToEditSamplingPlan"> + <li> + <s:url action="edit-sample-row!input" id="editSampleRowUrl"> + <s:param name="sampleRowId" value="sampleRowId" /> + </s:url> + <s:a href="%{editSampleRowUrl}"> + <i class="icon-edit"></i> <s:text name="wao.ui.action.editOrDeleteSampleRow" /> + </s:a> + </li> + </s:if> + <s:if test="authenticatedWaoUser.authorizedToViewSampleRowLog"> + <li> + <s:url action="sample-row-log" id="sampleRowLogUrl"> + <s:param name="sampleRowId" value="sampleRowId" /> + </s:url> + <s:a href="%{sampleRowLogUrl}"> + <i class="icon-time"></i> <s:text name="wao.ui.action.viewSampleRowLog" /> + </s:a> + </li> + </s:if> + <li> + <s:url action="sampling-plan!applyFilter" id="sampleRowZoomUrl"> + <s:param name="filter.periodFrom" value="%{formatMonth(firstSampleMonthDate)}"/> + <s:param name="filter.periodTo" value="%{formatMonth(lastSampleMonthDate)}"/> + <s:param name="filter.companyIds" value="%{filter.companyIds}"/> + <s:param name="filter.programNames" value="%{filter.programNames}"/> + <s:param name="filter.sampleRowCodes" value="%{filter.sampleRowCodes}"/> + <s:param name="filter.fishingZoneFacadeNames" value="%{filter.targetSpeciesDcfIds}"/> + <s:param name="filter.fishingZoneSectorNames" value="%{filter.targetSpeciesDcfIds}"/> + <s:param name="filter.fishingGearDcfIds" value="%{filter.targetSpeciesDcfIds}"/> + <s:param name="filter.targetSpeciesDcfIds" value="%{filter.targetSpeciesDcfIds}"/> + </s:url> + <s:a href="%{sampleRowZoomUrl}"> + <i class="icon-filter"></i> <s:text name="wao.ui.action.zoomOnSampleRowPeriod" /> + </s:a> + </li> + <s:if test="authenticatedWaoUser.authorizedToViewBoats && elligibleBoatsProvided"> + <li> + <s:url action="boats!applyFilter" id="viewElligibleBoatsUrl"> + <s:param name="filter.elligibleForSampleRowsFilter.sampleRowCodes" value="code" /> + </s:url> + <s:a href="%{viewElligibleBoatsUrl}"> + <i class="fa fa-anchor"></i> <s:text name="wao.ui.action.viewElligibleBoats" /> + </s:a> + </li> + </s:if> + <s:if test="authenticatedWaoUser.authorizedToViewContacts && sampleRowContactCounts > 0"> + <li> + <s:url action="contacts!applyFilter" id="viewAssociatedContactsUrl"> + <s:param name="filter.sampleRowFilter.sampleRowCodes" value="code" /> + <s:param name="filter.periodFrom" /> + <s:param name="filter.periodTo" /> + </s:url> + <s:a href="%{viewAssociatedContactsUrl}"> + <i class="fa fa-stack-exchange"></i> <s:text name="wao.ui.action.viewAssociatedContacts" /> + </s:a> + </li> + </s:if> + <s:if test="authenticatedWaoUser.authorizedToCreateContact && newContactCreatable"> + <li> + <s:url action="boats!applyFilter" id="createAssociatedContactUrl"> + <s:param name="startBoatSelectionForSampleRowId" value="sampleRowId" /> + </s:url> + <s:a href="%{createAssociatedContactUrl}"> + <i class="icon-plus"></i> <s:text name="wao.ui.action.createAssociatedContact" /> + </s:a> + </li> + </s:if> + </ul> + </div> + </td> + </tr> +<%--Iterate on SampleRows --%> +</s:iterator> +<%--Iterate on Sectors --%> +</s:iterator> +<%--Iterate on Facades--%> +</s:iterator> + + </todby> + <tfoot> + <th colspan="<s:property value="#nbColumnsForProfessionInFullView" />" class="only-in-full-view"> + <s:text name="wao.ui.misc.totals" /> + </th> + <th colspan="<s:property value="#nbColumnsForProfessionInCompactView" />" class="only-in-compact-view"> + <s:text name="wao.ui.misc.totals" /> + </th> + <!-- Months columns --> + <s:iterator value="samplingPlan.months" var="month"> + <s:set var="effort" value="samplingPlan.totalEffortInObservationsPerMonths.get(#month)"/> + <s:set var="now" value="%{isCurrentMonth(#month)}"/> + <s:set var="showPercentage" value="true"/> + <%@include file="../templates/td-effort.jsp" %> + </s:iterator> + + <s:set var="effort" value="samplingPlan.highTotalEffortInObservations"/> + <s:set var="now" value="false"/> + <s:set var="showPercentage" value="true"/> + <%@include file="../templates/td-effort.jsp" %> + + <th colspan="${nbColumnsForOther}"></th> + </tfoot> + </table> + +</html> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2263 in repository wao. See http://git.codelutin.com/wao.git commit 2c6e908c8db51c57862224a7a2ec9b69fd233573 Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Dec 18 09:59:41 2014 +0100 Dans l'écran de gestion des référentiels, on n'affiche que ce qui est pertinent pour scléro --- .../administration/referential-management.jsp | 94 +++++++++++----------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/wao-web/src/main/webapp/WEB-INF/content/administration/referential-management.jsp b/wao-web/src/main/webapp/WEB-INF/content/administration/referential-management.jsp index b550216..28b2b37 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/administration/referential-management.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/administration/referential-management.jsp @@ -51,37 +51,39 @@ </s:form> - <s:form action="import-terrestrial-locations" method="POST" enctype="multipart/form-data"> - - <fieldset> - <legend> - <s:text name="wao.import.terrestrialLocations.prompt" /> - </legend> - - <s:file name="csvFile" cssClass="float-left" /> - - <s:submit type="button"> - <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport" /> - </s:submit> - </fieldset> - - </s:form> - - <s:form action="import-boats" method="POST" enctype="multipart/form-data"> - - <fieldset> - <legend> - <s:text name="wao.import.boats.prompt" /> - </legend> - - <s:file name="csvFile" cssClass="float-left"/> - - <s:submit type="button"> - <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport" /> - </s:submit> - </fieldset> + <s:if test="obsMer || obsVente"> + <s:form action="import-terrestrial-locations" method="POST" enctype="multipart/form-data"> + + <fieldset> + <legend> + <s:text name="wao.import.terrestrialLocations.prompt" /> + </legend> + + <s:file name="csvFile" cssClass="float-left" /> + + <s:submit type="button"> + <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport" /> + </s:submit> + </fieldset> + + </s:form> - </s:form> + <s:form action="import-boats" method="POST" enctype="multipart/form-data"> + + <fieldset> + <legend> + <s:text name="wao.import.boats.prompt" /> + </legend> + + <s:file name="csvFile" cssClass="float-left"/> + + <s:submit type="button"> + <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport" /> + </s:submit> + </fieldset> + + </s:form> + </s:if> <s:if test="obsMer"> <s:form action="import-contact-state-motives" method="POST" enctype="multipart/form-data"> @@ -101,21 +103,23 @@ </s:form> </s:if> - <s:form action="import-species" method="POST" enctype="multipart/form-data"> - - <fieldset> - <legend> - <s:text name="wao.import.species.prompt" /> - </legend> - - <s:file name="csvFile" cssClass="float-left" /> - - <s:submit type="button"> - <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport" /> - </s:submit> - </fieldset> - - </s:form> + <s:if test="sclerochronology"> + <s:form action="import-species" method="POST" enctype="multipart/form-data"> + + <fieldset> + <legend> + <s:text name="wao.import.species.prompt" /> + </legend> + + <s:file name="csvFile" cssClass="float-left" /> + + <s:submit type="button"> + <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport" /> + </s:submit> + </fieldset> + + </s:form> + </s:if> <table class="table table-bordered"> <tr> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2263 in repository wao. See http://git.codelutin.com/wao.git commit 675f00192651555d766d6237e3268c0b57b01305 Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Dec 18 10:27:01 2014 +0100 Suppression d'un fichier obsdeb --- wao-services/src/test/resources/import/samplingPlan-obsdeb.csv | 3 --- 1 file changed, 3 deletions(-) diff --git a/wao-services/src/test/resources/import/samplingPlan-obsdeb.csv b/wao-services/src/test/resources/import/samplingPlan-obsdeb.csv deleted file mode 100644 index 186f9ef..0000000 --- a/wao-services/src/test/resources/import/samplingPlan-obsdeb.csv +++ /dev/null @@ -1,3 +0,0 @@ -PLAN_CODE;REGION_IFREMER_COD;OBSERVATEUR_COD;OBSERVATION_DATE;UNITE_OBSERVATION_COD -2011_D0888;GA;OBS1;05/01/2010;UO007 -2011_D0889;MA;OBS2;25/02/2010;UO087 -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/2263 in repository wao. See http://git.codelutin.com/wao.git commit f4a83c25404158e2e637ef5c7e34e85a70319154 Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Dec 18 11:36:37 2014 +0100 Import du plan d'échantillonnage scléro --- .../main/java/fr/ifremer/wao/entity/Companies.java | 9 +- .../java/fr/ifremer/wao/entity/Organisations.java | 23 +++ .../main/java/fr/ifremer/wao/entity/Specieses.java | 19 ++ .../i18n/wao-persistence_en_GB.properties | 7 +- .../i18n/wao-persistence_fr_FR.properties | 7 +- .../fr/ifremer/wao/services/ObsMerFixtures.java | 222 --------------------- ...singIndividualMeasurementStrategyException.java | 10 + ...ngSclerochronologySamplingContextException.java | 10 + .../services/service/MissingSpeciesException.java | 10 + .../wao/services/service/SamplingPlanService.java | 81 +++++--- .../wao/services/service/WaoServiceSupport.java | 5 + .../administration/OrganisationsService.java | 18 ++ .../service/administration/ReferentialService.java | 9 + .../service/csv/ContactImportExportModel.java | 12 +- ...bsMerObsVenteSamplingPlanImportExportModel.java | 42 ++-- ...atter.java => OrganisationParserFormatter.java} | 48 ++--- .../csv/operations/SpeciesParserFormatter.java | 51 +++++ .../resources/i18n/wao-services_en_GB.properties | 5 + .../resources/i18n/wao-services_fr_FR.properties | 5 + .../wao/services/service/BoatsServiceTest.java | 1 - .../wao/services/service/ContactsServiceTest.java | 1 - .../wao/services/service/ObsMerFixtures.java | 93 +++++++++ .../service/ObsMerSamplingPlanServiceTest.java | 1 - .../services/service/SclerochronologyFixtures.java | 50 +++++ .../SclerochronologySamplingPlanServiceTest.java | 51 +++++ .../ifremer/wao/services/service/WaoFixtures.java | 88 ++++++++ .../src/test/resources/import/echantillonnage.csv | 18 +- .../resources/import/plan-sclerochronologie.csv | 6 + .../wao/web/action/EditSampleRowAction.java | 12 ++ .../action/administration/ImportSpeciesAction.java | 4 +- 30 files changed, 602 insertions(+), 316 deletions(-) diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/Companies.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/Companies.java index b396747..0b657ae 100644 --- a/wao-persistence/src/main/java/fr/ifremer/wao/entity/Companies.java +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/Companies.java @@ -26,14 +26,7 @@ import com.google.common.base.Function; public class Companies { public static Function<Company, String> getName() { - return new GetName(); + return Organisations.getName(); } - protected static class GetName implements Function<Company, String> { - - @Override - public String apply(Company input) { - return input.getName(); - } - } } diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/Organisations.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/Organisations.java new file mode 100644 index 0000000..bdd649b --- /dev/null +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/Organisations.java @@ -0,0 +1,23 @@ +package fr.ifremer.wao.entity; + +import com.google.common.base.Function; +import com.google.common.collect.Ordering; + +public class Organisations { + + public static <T extends Organisation> Function<T, String> getName() { + return new GetName<>(); + } + + public static Ordering<Organisation> comparator() { + return Ordering.natural().onResultOf(getName()); + } + + protected static class GetName<T extends Organisation> implements Function<T, String> { + + @Override + public String apply(T input) { + return input.getName(); + } + } +} diff --git a/wao-persistence/src/main/java/fr/ifremer/wao/entity/Specieses.java b/wao-persistence/src/main/java/fr/ifremer/wao/entity/Specieses.java new file mode 100644 index 0000000..f7f12d6 --- /dev/null +++ b/wao-persistence/src/main/java/fr/ifremer/wao/entity/Specieses.java @@ -0,0 +1,19 @@ +package fr.ifremer.wao.entity; + +import com.google.common.base.Function; + +public class Specieses { + + public static Function<Species, String> getPermanentCode() { + return new GetPermanentCode(); + } + + protected static class GetPermanentCode implements Function<Species, String> { + + @Override + public String apply(Species input) { + return input.getPermanentCode(); + } + } + +} diff --git a/wao-persistence/src/main/resources/i18n/wao-persistence_en_GB.properties b/wao-persistence/src/main/resources/i18n/wao-persistence_en_GB.properties index e4f6dfb..4770f3f 100644 --- a/wao-persistence/src/main/resources/i18n/wao-persistence_en_GB.properties +++ b/wao-persistence/src/main/resources/i18n/wao-persistence_en_GB.properties @@ -21,9 +21,9 @@ GlobalIndicatorValue.GOOD=Level 1 bonus GlobalIndicatorValue.NEUTRAL=Conform GlobalIndicatorValue.VERY_BAD=Level 2 penalty GlobalIndicatorValue.VERY_GOOD=Level 2 bonus -IndividualMeasurementStrategy.SIZE_WEIGHT=Size, weight -IndividualMeasurementStrategy.SIZE_WEIGHT_SEX=Size, weight, sex -IndividualMeasurementStrategy.SIZE_WEIGHT_SEX_MATURITY_AGE=Size, weight, sex, maturity, age +IndividualMeasurementStrategy.SIZE_WEIGHT=Size/Weight +IndividualMeasurementStrategy.SIZE_WEIGHT_SEX=Size/Weight/Sex +IndividualMeasurementStrategy.SIZE_WEIGHT_SEX_MATURITY_AGE=Size/Weight/Sex/Maturity/Age LocationType.AUCTION=Auction LocationType.DISTRICT=District LocationType.PORT=Port @@ -127,6 +127,7 @@ fr.ifremer.wao.entity.FishingGearDcf.TM=Midwater trawls (not specified) fr.ifremer.wao.entity.FishingGearDcf.TMS=Shrimp trawls fr.ifremer.wao.entity.FishingGearDcf.TX=Other trawls (not specified) fr.ifremer.wao.entity.FishingZone=Fishing zones +fr.ifremer.wao.entity.Species=Species fr.ifremer.wao.entity.TargetSpeciesDcf.=Not specified fr.ifremer.wao.entity.TargetSpeciesDcf.ALG=Algae fr.ifremer.wao.entity.TargetSpeciesDcf.ANA=Espèces anadromes diff --git a/wao-persistence/src/main/resources/i18n/wao-persistence_fr_FR.properties b/wao-persistence/src/main/resources/i18n/wao-persistence_fr_FR.properties index 972c780..2b2467c 100644 --- a/wao-persistence/src/main/resources/i18n/wao-persistence_fr_FR.properties +++ b/wao-persistence/src/main/resources/i18n/wao-persistence_fr_FR.properties @@ -21,9 +21,9 @@ GlobalIndicatorValue.GOOD=Bonus de niveau 1 GlobalIndicatorValue.NEUTRAL=Conforme au cahier des charges GlobalIndicatorValue.VERY_BAD=Pénalité de niveau 2 GlobalIndicatorValue.VERY_GOOD=Bonus de niveau 2 -IndividualMeasurementStrategy.SIZE_WEIGHT=Poids, taille -IndividualMeasurementStrategy.SIZE_WEIGHT_SEX=Poids, taille, sexe -IndividualMeasurementStrategy.SIZE_WEIGHT_SEX_MATURITY_AGE=Poids, taille, sexe, maturité, âge +IndividualMeasurementStrategy.SIZE_WEIGHT=Poids/Taille +IndividualMeasurementStrategy.SIZE_WEIGHT_SEX=Poids/Taille/Sexe +IndividualMeasurementStrategy.SIZE_WEIGHT_SEX_MATURITY_AGE=Poids/Taille/Sexe/Maturité/Âge LocationType.AUCTION=Criée LocationType.DISTRICT=Quartier maritime LocationType.PORT=Port @@ -127,6 +127,7 @@ fr.ifremer.wao.entity.FishingGearDcf.TM=Chalut pélagique (non spécifié) fr.ifremer.wao.entity.FishingGearDcf.TMS=Chalut pélagique à crevettes fr.ifremer.wao.entity.FishingGearDcf.TX=Autre chalut (non spécifié) fr.ifremer.wao.entity.FishingZone=Zones de pêche +fr.ifremer.wao.entity.Species=Espèces fr.ifremer.wao.entity.TargetSpeciesDcf.=Non spécifié fr.ifremer.wao.entity.TargetSpeciesDcf.ALG=Algues fr.ifremer.wao.entity.TargetSpeciesDcf.ANA=Espèces anadromes diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java b/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java deleted file mode 100644 index 6b42b3c..0000000 --- a/wao-services/src/main/java/fr/ifremer/wao/services/ObsMerFixtures.java +++ /dev/null @@ -1,222 +0,0 @@ -package fr.ifremer.wao.services; - -/* - * #%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.WaoTechnicalException; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.CompanyTopiaDao; -import fr.ifremer.wao.entity.FishingGearDcf; -import fr.ifremer.wao.entity.FishingGearDcfTopiaDao; -import fr.ifremer.wao.entity.ObsProgram; -import fr.ifremer.wao.entity.TargetSpeciesDcf; -import fr.ifremer.wao.entity.TargetSpeciesDcfTopiaDao; -import fr.ifremer.wao.entity.UserProfile; -import fr.ifremer.wao.entity.UserProfileImpl; -import fr.ifremer.wao.entity.UserProfileTopiaDao; -import fr.ifremer.wao.entity.UserRole; -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.ObsMerSamplingPlanService; -import fr.ifremer.wao.services.service.administration.ReferentialService; -import org.apache.commons.io.IOUtils; - -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; - -public class ObsMerFixtures { - - protected WaoServiceContext serviceContext; - - protected Map<String, Company> companies = new HashMap<>(); - - protected Map<String, WaoUser> waoUsers = new HashMap<>(); - - protected Map<String, UserProfile> userProfiles = new HashMap<>(); - - public ObsMerFixtures(WaoServiceContext serviceContext) { - this.serviceContext = serviceContext; - } - - protected Company getCompany(String companyName) { - Company company = companies.get(companyName); - if (company == null) { - CompanyTopiaDao companyDao = serviceContext.getPersistenceContext().getCompanyDao(); - company = companyDao.create( - Company.PROPERTY_NAME, companyName, - Company.PROPERTY_ACTIVE, true); - companies.put(companyName, company); - serviceContext.getPersistenceContext().commit(); - } - return company; - } - - protected UserProfile getUserProfile(String userRole) { - UserProfile userProfile = userProfiles.get(userRole); - if (userProfile == null) { - switch (userRole) { - case "admin": - userProfile = new UserProfileImpl(); - userProfile.setUserRole(UserRole.ADMIN); - userProfile.setObsProgram(ObsProgram.OBSMER); - userProfile.setCanWrite(true); - break; - case "jmichmuche": - userProfile = new UserProfileImpl(); - userProfile.setUserRole(UserRole.COORDINATOR); - userProfile.setObsProgram(ObsProgram.OBSMER); - userProfile.setCanWrite(true); - break; - default: - throw new IllegalArgumentException("Don't know userRole: " + userRole); - } - UserProfileTopiaDao userProfileDao = serviceContext.getPersistenceContext().getUserProfileDao(); - userProfileDao.create(userProfile); - serviceContext.getPersistenceContext().commit(); - userProfiles.put(userRole, userProfile); - } - return userProfile; - } - - protected WaoUser getWaoUser(String login) { - WaoUser waoUser = waoUsers.get(login); - if (waoUser == null) { - - switch (login) { - case "admin": - waoUser = new WaoUserImpl(); - waoUser.setOrganisation(ifremer()); - waoUser.setLogin(login); - waoUser.setActive(true); - waoUser.addUserProfile(getUserProfile("admin")); - break; - case "jmichmuche": - waoUser = new WaoUserImpl(); - waoUser.setOrganisation(ifremer()); - waoUser.setLogin(login); - waoUser.setActive(true); - waoUser.addUserProfile(getUserProfile("jmichmuche")); - break; - default: - throw new IllegalArgumentException("Don't know user: " + login); - } - - WaoUserTopiaDao waoUserDao = serviceContext.getPersistenceContext().getWaoUserDao(); - waoUserDao.create(waoUser); - serviceContext.getPersistenceContext().commit(); - waoUsers.put(login, waoUser); - } - return waoUser; - } - - public Company ifremer() { - return getCompany("Ifremer"); - } - - public Company oceanet() { - return getCompany("OCEANET"); - } - - public AuthenticatedWaoUser admin() { - WaoUser admin = getWaoUser("admin"); - UserProfile userProfile = getUserProfile("admin"); - AuthenticatedWaoUser authenticatedWaoUser = new AuthenticatedWaoUser(admin, userProfile); - return authenticatedWaoUser; - } - - public AuthenticatedWaoUser jmichmuche() { - WaoUser jmichmuche = getWaoUser("jmichmuche"); - UserProfile userProfile = getUserProfile("jmichmuche"); - AuthenticatedWaoUser authenticatedWaoUser = new AuthenticatedWaoUser(jmichmuche, userProfile); - return authenticatedWaoUser; - } - - public void fishingZones() { - InputStream input = null; - try { - input = getClass().getResourceAsStream("/import/zonesPeche.csv"); - serviceContext.newService(ReferentialService.class).importFishingZones(input); - } catch (ImportErrorException e) { - throw new WaoTechnicalException(e); - } finally { - IOUtils.closeQuietly(input); - } - } - - public void navires() { - InputStream input = null; - try { - input = getClass().getResourceAsStream("/import/navires.csv"); - serviceContext.newService(ReferentialService.class).importBoats(input); - } catch (ImportErrorException e) { - throw new WaoTechnicalException(e); - } finally { - IOUtils.closeQuietly(input); - } - } - - public void samplingPlan() { - ifremer(); - oceanet(); - fishingZones(); - InputStream input = null; - try { - input = getClass().getResourceAsStream("/import/echantillonnage.csv"); - serviceContext.newService(ObsMerSamplingPlanService.class).importSamplingPlan(admin(), input); - } catch (ImportErrorException e) { - throw new WaoTechnicalException(e); - } finally { - IOUtils.closeQuietly(input); - } - } - - public void contacts() { - samplingPlan(); - jmichmuche(); - navires(); - InputStream input = null; - try { - input = getClass().getResourceAsStream("/import/contacts.csv"); - serviceContext.newService(ContactsService.class).importContacts(admin(), input); - } catch (ImportErrorException e) { - throw new WaoTechnicalException(e); - } finally { - IOUtils.closeQuietly(input); - } - } - - public FishingGearDcf ptb() { - FishingGearDcfTopiaDao fishingGearDcfDao = serviceContext.getPersistenceContext().getFishingGearDcfDao(); - FishingGearDcf ptb = fishingGearDcfDao.forCodeEquals("PTB").findUnique(); - return ptb; - } - - public TargetSpeciesDcf def() { - TargetSpeciesDcfTopiaDao fishingGearDcfDao = serviceContext.getPersistenceContext().getTargetSpeciesDcfDao(); - TargetSpeciesDcf def = fishingGearDcfDao.forCodeEquals("DEF").findUnique(); - return def; - } - -} diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingIndividualMeasurementStrategyException.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingIndividualMeasurementStrategyException.java new file mode 100644 index 0000000..1886359 --- /dev/null +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingIndividualMeasurementStrategyException.java @@ -0,0 +1,10 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.entity.SampleRow; + +public class MissingIndividualMeasurementStrategyException extends SampleRowValidationException { + + public MissingIndividualMeasurementStrategyException(SampleRow sampleRow) { + super(sampleRow); + } +} diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingSclerochronologySamplingContextException.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingSclerochronologySamplingContextException.java new file mode 100644 index 0000000..212018a --- /dev/null +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingSclerochronologySamplingContextException.java @@ -0,0 +1,10 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.entity.SampleRow; + +public class MissingSclerochronologySamplingContextException extends SampleRowValidationException { + + public MissingSclerochronologySamplingContextException(SampleRow sampleRow) { + super(sampleRow); + } +} diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingSpeciesException.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingSpeciesException.java new file mode 100644 index 0000000..2a6507f --- /dev/null +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/MissingSpeciesException.java @@ -0,0 +1,10 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.entity.SampleRow; + +public class MissingSpeciesException extends SampleRowValidationException { + + public MissingSpeciesException(SampleRow sampleRow) { + super(sampleRow); + } +} diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java index a091cc1..6df485f 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java @@ -36,7 +36,6 @@ 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; @@ -47,6 +46,7 @@ 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.Organisation; import fr.ifremer.wao.entity.Profession; import fr.ifremer.wao.entity.ProfessionImpl; import fr.ifremer.wao.entity.ProfessionTopiaDao; @@ -159,31 +159,36 @@ public class SamplingPlanService extends WaoServiceSupport { // 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 + if (authenticatedWaoUser.getObsProgram().isSclerochronology()) { + // on est sur un plan de janvier à décembre + fromDate = DateUtils.setMonths(fromDate, 0); - // 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); + // 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); + Date toDate = DateUtils.addMonths(fromDate, 11); newFilter.setPeriodFrom(fromDate); newFilter.setPeriodTo(toDate); @@ -345,6 +350,7 @@ public class SamplingPlanService extends WaoServiceSupport { ImmutableMap<String, Company> allCompanies = Maps.uniqueIndex( + // TODO brendan 15/12/14 getOrganisationsService().getOrganisationsToWorkOnSampleRow(obsProgram); getCompaniesService().getAllCompanies(), TopiaEntities.getTopiaIdFunction() ); @@ -607,6 +613,15 @@ public class SamplingPlanService extends WaoServiceSupport { } catch (NoEffortDefinedException e) { String message = I18n.l(getLocale(), "wao.import.sampleRow.failure.noEffortDefined", lineNumber); throw new ImportErrorException(message); + } catch (MissingSclerochronologySamplingContextException e) { + String message = I18n.l(getLocale(), "wao.import.sampleRow.failure.missingSclerochronologySamplingContext", lineNumber); + throw new ImportErrorException(message); + } catch (MissingIndividualMeasurementStrategyException e) { + String message = I18n.l(getLocale(), "wao.import.sampleRow.failure.missingIndividualMeasurementStrategy", lineNumber); + throw new ImportErrorException(message); + } catch (MissingSpeciesException e) { + String message = I18n.l(getLocale(), "wao.import.sampleRow.failure.missingSpecies", lineNumber); + throw new ImportErrorException(message); } save0(updateSampleRowCommand); @@ -625,8 +640,7 @@ public class SamplingPlanService extends WaoServiceSupport { ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); - CompanyTopiaDao companyDao = getCompanyDao(); - List<Company> activeCompanies = companyDao.forActiveEquals(true).findAll(); + Set<Organisation> organisations = getOrganisationsService().getOrganisationsToWorkOnSampleRow(obsProgram); TerrestrialLocationTopiaDao terrestrialLocationDao = getTerrestrialLocationDao(); List<TerrestrialLocation> terrestrialDistricts = @@ -640,7 +654,7 @@ public class SamplingPlanService extends WaoServiceSupport { ImportModel<SampleRow> samplingPlanImportModel = new ObsMerObsVenteSamplingPlanImportExportModel(getLocale(), obsProgram, - activeCompanies, + organisations, fishingZones, terrestrialDistricts, referentialService); @@ -713,7 +727,10 @@ public class SamplingPlanService extends WaoServiceSupport { SampleMonthWithIllegalExpectedTidesValueException, MissingDcf5CodesException, SampleRowCodeMustBeUniqueException, - NoEffortDefinedException { + NoEffortDefinedException, + MissingSclerochronologySamplingContextException, + MissingSpeciesException, + MissingIndividualMeasurementStrategyException { SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); @@ -725,8 +742,10 @@ public class SamplingPlanService extends WaoServiceSupport { throw new SampleRowCodeMustBeUniqueException(); } + ObsProgram obsProgram = sampleRow.getObsProgram(); + if (updateSampleRowCommand.isCreation()) { - if ( ! sampleRow.getObsProgram().getSampleRowCodePattern().matcher(sampleRow.getCode()).matches()) { + if ( ! obsProgram.getSampleRowCodePattern().matcher(sampleRow.getCode()).matches()) { throw new WrongSampleRowCodeFormatException(sampleRow); } } else { @@ -751,7 +770,7 @@ public class SamplingPlanService extends WaoServiceSupport { throw new MissingFishingZonesException(sampleRow); } - if (sampleRow.getObsProgram().isObsVente()) { + if (obsProgram.isObsVente()) { if (sampleRow.getSamplingStrategy().isSpecificStock() && StringUtils.isEmpty(sampleRow.getProfession().getSpecies())) { throw new MissingProfessionSpeciesException(sampleRow); } @@ -767,8 +786,22 @@ public class SamplingPlanService extends WaoServiceSupport { } } - if (sampleRow.isDcf5CodeEmpty()) { - throw new MissingDcf5CodesException(sampleRow); + if (obsProgram.isObsVente() || obsProgram.isObsMer()) { + if (sampleRow.isDcf5CodeEmpty()) { + throw new MissingDcf5CodesException(sampleRow); + } + } + + if (obsProgram.isSclerochronology()) { + if (sampleRow.getSclerochronologySamplingContext() == null) { + throw new MissingSclerochronologySamplingContextException(sampleRow); + } + if (sampleRow.getSpecies() == null) { + throw new MissingSpeciesException(sampleRow); + } + if (sampleRow.getIndividualMeasurementStrategy() == null) { + throw new MissingIndividualMeasurementStrategyException(sampleRow); + } } } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java index c77f609..ebc60f9 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java @@ -50,6 +50,7 @@ import fr.ifremer.wao.services.WaoService; import fr.ifremer.wao.services.WaoServiceContext; import fr.ifremer.wao.services.WaoWebApplicationContext; import fr.ifremer.wao.services.service.administration.CompaniesService; +import fr.ifremer.wao.services.service.administration.LaboratoriesService; import fr.ifremer.wao.services.service.administration.OrganisationsService; import fr.ifremer.wao.services.service.administration.ReferentialService; import fr.ifremer.wao.services.service.administration.WaoUsersService; @@ -206,4 +207,8 @@ public abstract class WaoServiceSupport implements WaoService { protected LaboratoryTopiaDao getLaboratoryDao() { return getPersistenceContext().getLaboratoryDao(); } + + public LaboratoriesService getLaboratoriesService() { + return newService(LaboratoriesService.class); + } } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/OrganisationsService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/OrganisationsService.java index 2f7f781..8e90623 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/OrganisationsService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/OrganisationsService.java @@ -3,8 +3,10 @@ package fr.ifremer.wao.services.service.administration; import com.google.common.collect.Iterables; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.Laboratory; +import fr.ifremer.wao.entity.ObsProgram; import fr.ifremer.wao.entity.Organisation; import fr.ifremer.wao.entity.OrganisationTopiaDao; +import fr.ifremer.wao.entity.Organisations; import fr.ifremer.wao.services.service.IllegalDeletionException; import fr.ifremer.wao.services.service.WaoServiceSupport; import org.nuiton.topia.persistence.TopiaEntity; @@ -13,6 +15,8 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; public class OrganisationsService extends WaoServiceSupport { @@ -74,4 +78,18 @@ public class OrganisationsService extends WaoServiceSupport { } + public SortedSet<Organisation> getOrganisationsToWorkOnSampleRow(ObsProgram obsProgram) { + + SortedSet<Organisation> organisations = new TreeSet<>(Organisations.comparator()); + + organisations.addAll(getCompaniesService().getAllCompanies()); + + if (obsProgram.isSclerochronology()) { + organisations.addAll(getLaboratoriesService().getAllLaboratories()); + } + + return organisations; + + } + } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java index 9843992..122c634 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/administration/ReferentialService.java @@ -861,4 +861,13 @@ public class ReferentialService extends WaoServiceSupport { commit(); } + + public ImmutableSet<Species> getAllSpecies() { + + List<Species> all = getSpeciesDao().findAll(); + + return ImmutableSet.copyOf(all); + + } + } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java index afe38e9..ab838bd 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ContactImportExportModel.java @@ -26,7 +26,6 @@ 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; import fr.ifremer.wao.entity.ContactImpl; import fr.ifremer.wao.entity.ContactStateMotif; @@ -34,11 +33,12 @@ import fr.ifremer.wao.entity.DataReliability; import fr.ifremer.wao.entity.LocationType; import fr.ifremer.wao.entity.ObsProgram; import fr.ifremer.wao.entity.ObservedDataControl; +import fr.ifremer.wao.entity.Organisation; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.TerrestrialLocation; 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.OrganisationParserFormatter; import fr.ifremer.wao.services.service.csv.operations.ContactStateMotivesParserFormatter; import fr.ifremer.wao.services.service.csv.operations.ContactStateParserFormatter; import fr.ifremer.wao.services.service.csv.operations.DayParserFormatter; @@ -164,13 +164,13 @@ public class ContactImportExportModel implements ImportExportModel<Contact> { modelBuilder.newIgnoredColumn("CONTACT_OBSERVATEURS_SOCIETE"); modelBuilder.newColumnForExport( "CONTACT_OBSERVATEURS_SOCIETE", - new ValueGetter<Contact, Company>() { + new ValueGetter<Contact, Organisation>() { @Override - public Company get(Contact contact) { - return contact.getMainObserver().getCompany(); + public Organisation get(Contact contact) { + return contact.getMainObserver().getOrganisation(); } }, - new CompanyParserFormatter(locale, null) + new OrganisationParserFormatter(locale, null) ); modelBuilder.newColumnForImportExport("CONTACT_ETAT", "contactState", new ContactStateParserFormatter(locale, obsProgram)); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java index 824223f..54204a6 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java @@ -26,9 +26,10 @@ package fr.ifremer.wao.services.service.csv; import com.opensymphony.xwork2.util.logging.Logger; import com.opensymphony.xwork2.util.logging.LoggerFactory; -import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.IndividualMeasurementStrategy; import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.Organisation; import fr.ifremer.wao.entity.Profession; import fr.ifremer.wao.entity.ProfessionImpl; import fr.ifremer.wao.entity.SampleMonth; @@ -36,15 +37,17 @@ 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.SclerochronologySamplingContext; 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.OrganisationParserFormatter; import fr.ifremer.wao.services.service.csv.operations.SampleRowCodeParserFormatter; +import fr.ifremer.wao.services.service.csv.operations.SpeciesParserFormatter; import org.nuiton.csv.Common; import org.nuiton.csv.ExportableColumn; import org.nuiton.csv.ImportExportModel; @@ -59,6 +62,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Set; import java.util.regex.Pattern; /** @@ -115,7 +119,7 @@ public class ObsMerObsVenteSamplingPlanImportExportModel implements ImportExport protected ObsProgram obsProgram; - protected List<Company> companies; + protected Set<Organisation> organisations; protected List<FishingZone> fishingZones; @@ -136,12 +140,12 @@ public class ObsMerObsVenteSamplingPlanImportExportModel implements ImportExport /** Pour l'import */ public ObsMerObsVenteSamplingPlanImportExportModel(Locale locale, ObsProgram obsProgram, - List<Company> companies, List<FishingZone> fishingZones, + Set<Organisation> organisations, List<FishingZone> fishingZones, List<TerrestrialLocation> terrestrialDistricts, ReferentialService referentialService) { this.locale = locale; this.obsProgram = obsProgram; - this.companies = companies; + this.organisations = organisations; this.fishingZones = fishingZones; this.terrestrialDistricts = terrestrialDistricts; this.referentialService = referentialService; @@ -194,7 +198,7 @@ public class ObsMerObsVenteSamplingPlanImportExportModel implements ImportExport modelBuilder = new ModelBuilder<>(); modelBuilder.newColumnForImportExport("PLAN_CODE", SampleRow.PROPERTY_CODE, new SampleRowCodeParserFormatter(locale, obsProgram)); - modelBuilder.newColumnForImportExport("SOCIETE_NOM", SampleRow.PROPERTY_ORGANISATION, new CompanyParserFormatter(locale, companies)); + modelBuilder.newColumnForImportExport("ORGANISATION_NOM", SampleRow.PROPERTY_ORGANISATION, new OrganisationParserFormatter(locale, organisations)); modelBuilder.newColumnForExport("PECHE_FACADE", "facade"); modelBuilder.newIgnoredColumn("PECHE_FACADE"); @@ -204,12 +208,6 @@ public class ObsMerObsVenteSamplingPlanImportExportModel implements ImportExport modelBuilder.newColumnForImportExport("PECHE_DIVISION", SampleRow.PROPERTY_FISHING_ZONE, new FishingZonesParserFormatter(locale, fishingZones)); modelBuilder.newColumnForImportExport("PECHE_AUTRE", SampleRow.PROPERTY_FISHING_ZONES_INFOS); - modelBuilder.newColumnForImportExport("METIER_CODE_DCF5", SampleRow.PROPERTY_DCF5_CODE, new Dcf5CodesParserFormatter(locale, referentialService)); - modelBuilder.newColumnForImportExport("METIER_MAILLAGE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_MESH_SIZE); - modelBuilder.newColumnForImportExport("METIER_TAILLE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_SIZE); - modelBuilder.newColumnForImportExport("METIER_AUTRE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_OTHER); - modelBuilder.newColumnForImportExport("METIER_LIBELLE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_LIBELLE); - modelBuilder.newColumnForImportExport("METIER_ESPECES", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_SPECIES); modelBuilder.newColumnForImportExport("PROGRAMME_CODE", SampleRow.PROPERTY_PROGRAM_NAME); modelBuilder.newColumnForImportExport("PROGRAMME_DEBUT", SampleRow.PROPERTY_PERIOD_BEGIN, MONTH_YEAR_PARSER_FORMATTER); @@ -221,13 +219,29 @@ public class ObsMerObsVenteSamplingPlanImportExportModel implements ImportExport modelBuilder.newColumnForImportExport(headerName, new ExpectedTidesValueGetterSetter(month), Common.INTEGER); } - if (obsProgram == ObsProgram.OBSMER) { + if (obsProgram.isSclerochronology()) { + modelBuilder.newColumnForImportExport("ESPECE_CIBLE", SampleRow.PROPERTY_SPECIES, new SpeciesParserFormatter(locale, referentialService.getAllSpecies())); + modelBuilder.newColumnForImportExport("CONTEXTE", SampleRow.PROPERTY_SCLEROCHRONOLOGY_SAMPLING_CONTEXT, new I18nAbleParserFormatter<>(locale, SclerochronologySamplingContext.values())); + modelBuilder.newColumnForImportExport("CONTEXTE_COMPLEMENT", SampleRow.PROPERTY_SCLEROCHRONOLOGY_SAMPLING_CONTEXT_INFO); + modelBuilder.newColumnForImportExport("MESURES", SampleRow.PROPERTY_INDIVIDUAL_MEASUREMENT_STRATEGY, new I18nAbleParserFormatter<>(locale, IndividualMeasurementStrategy.values())); + } + + if (obsProgram.isObsMer() || obsProgram.isObsVente()) { + modelBuilder.newColumnForImportExport("METIER_CODE_DCF5", SampleRow.PROPERTY_DCF5_CODE, new Dcf5CodesParserFormatter(locale, referentialService)); + modelBuilder.newColumnForImportExport("METIER_MAILLAGE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_MESH_SIZE); + modelBuilder.newColumnForImportExport("METIER_TAILLE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_SIZE); + modelBuilder.newColumnForImportExport("METIER_AUTRE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_OTHER); + modelBuilder.newColumnForImportExport("METIER_LIBELLE", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_LIBELLE); + modelBuilder.newColumnForImportExport("METIER_ESPECES", SampleRow.PROPERTY_PROFESSION + "." + Profession.PROPERTY_SPECIES); + } + + if (obsProgram.isObsMer()) { modelBuilder.newColumnForImportExport("PLAN_DUREE_MOY", SampleRow.PROPERTY_AVERAGE_TIDE_TIME, Common.PRIMITIVE_INTEGER); modelBuilder.newColumnForImportExport("PLAN_NB_OBSERV", SampleRow.PROPERTY_NB_OBSERVANTS, Common.PRIMITIVE_INTEGER); modelBuilder.newColumnForImportExport("TAUX_COUVERTURE_APPLIQUE", SampleRow.PROPERTY_APPLIED_COVERAGE_RATE, Common.DOUBLE); } - if (obsProgram == ObsProgram.OBSVENTE) { + if (obsProgram.isObsVente()) { 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()); diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/CompanyParserFormatter.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/OrganisationParserFormatter.java similarity index 50% rename from wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/CompanyParserFormatter.java rename to wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/OrganisationParserFormatter.java index 1424462..472f0a2 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/CompanyParserFormatter.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/OrganisationParserFormatter.java @@ -25,51 +25,53 @@ package fr.ifremer.wao.services.service.csv.operations; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import fr.ifremer.wao.entity.Companies; -import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.Organisation; +import fr.ifremer.wao.entity.Organisations; import org.apache.commons.lang3.StringUtils; import org.nuiton.csv.ValueParserFormatter; import org.nuiton.i18n.I18n; import java.text.ParseException; -import java.util.List; import java.util.Locale; +import java.util.Set; -/** Parse a company according to it's name. */ -public class CompanyParserFormatter implements ValueParserFormatter<Company> { +/** + * Parse an {@link fr.ifremer.wao.entity.Organisation} according to it's name. + */ +public class OrganisationParserFormatter implements ValueParserFormatter<Organisation> { protected final Locale locale; - protected List<Company> companies; + protected Set<Organisation> organisations; - protected ImmutableMap<String, Company> indexedCompanies; + protected ImmutableMap<String, Organisation> indexedOrganisations; - public CompanyParserFormatter(Locale locale, List<Company> companies) { + public OrganisationParserFormatter(Locale locale, Set<Organisation> organisations) { this.locale = locale; - this.companies = companies; + this.organisations = organisations; } @Override - public String format(Company company) { - String companyName = ""; - if (company != null) { - companyName = company.getName(); + public String format(Organisation organisation) { + String organisationName = ""; + if (organisation != null) { + organisationName = organisation.getName(); } - return companyName; + return organisationName; } @Override - public Company parse(String companyName) throws ParseException { - if (indexedCompanies == null) { - indexedCompanies = Maps.uniqueIndex(companies, Companies.getName()); + public Organisation parse(String organisationName) throws ParseException { + if (indexedOrganisations == null) { + indexedOrganisations = Maps.uniqueIndex(organisations, Organisations.getName()); } - Company company = null; - if (StringUtils.isNotBlank(companyName)) { - company = indexedCompanies.get(companyName.trim()); - if (company == null) { - throw new IllegalArgumentException(I18n.l(locale, "wao.import.contact.failure.unkwonCompany", companyName)); + Organisation organisation = null; + if (StringUtils.isNotBlank(organisationName)) { + organisation = indexedOrganisations.get(organisationName.trim()); + if (organisation == null) { + throw new IllegalArgumentException(I18n.l(locale, "wao.import.sampleRow.failure.unknownOrganisation", organisationName)); } } - return company; + return organisation; } } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SpeciesParserFormatter.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SpeciesParserFormatter.java new file mode 100644 index 0000000..92bea35 --- /dev/null +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/SpeciesParserFormatter.java @@ -0,0 +1,51 @@ +package fr.ifremer.wao.services.service.csv.operations; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import fr.ifremer.wao.entity.Species; +import fr.ifremer.wao.entity.Specieses; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.csv.ValueParserFormatter; +import org.nuiton.i18n.I18n; + +import java.text.ParseException; +import java.util.Locale; + +public class SpeciesParserFormatter implements ValueParserFormatter<Species> { + + protected Locale locale; + + protected ImmutableSet<Species> species; + + protected ImmutableMap<String, Species> indexedSpecies; + + public SpeciesParserFormatter(Locale locale, ImmutableSet<Species> species) { + this.locale = locale; + this.species = species; + } + + @Override + public String format(Species species) { + String speciesName = ""; + if (species != null) { + speciesName = species.getPermanentCode(); + } + return speciesName; + } + + @Override + public Species parse(String speciesPermanentCode) throws ParseException { + if (indexedSpecies == null) { + indexedSpecies = Maps.uniqueIndex(species, Specieses.getPermanentCode()); + } + Species species = null; + if (StringUtils.isNotBlank(speciesPermanentCode)) { + species = indexedSpecies.get(speciesPermanentCode.trim()); + if (species == null) { + throw new IllegalArgumentException(I18n.l(locale, "wao.import.sampleRow.failure.unknownSpecies", speciesPermanentCode)); + } + } + return species; + } +} diff --git a/wao-services/src/main/resources/i18n/wao-services_en_GB.properties b/wao-services/src/main/resources/i18n/wao-services_en_GB.properties index 41b794c..a8a104a 100644 --- a/wao-services/src/main/resources/i18n/wao-services_en_GB.properties +++ b/wao-services/src/main/resources/i18n/wao-services_en_GB.properties @@ -86,14 +86,19 @@ wao.import.sampleRow.failure.codeMustBeUnique=Line %s\: The sample row code must wao.import.sampleRow.failure.fishingZoneMissing=Line %s\: You must precise at least one fishing zone wao.import.sampleRow.failure.missingDcf5Codes=Line %s\: You must precise at least one DCF5 code wao.import.sampleRow.failure.missingFishingZones=Line %s\: You must precise at least one fishing zone +wao.import.sampleRow.failure.missingIndividualMeasurementStrategy= Line %s\: You myst precise measurement strategy wao.import.sampleRow.failure.missingPeriodBegin=Line %s\: You must precise the period beginning wao.import.sampleRow.failure.missingPeriodEnd=Line %s\: You must precise the period end wao.import.sampleRow.failure.missingProfessionSpecies=Line %s\: For this sampling strategy, you must provide the species wao.import.sampleRow.failure.missingProgramName=Line %s\: You must precise the program name wao.import.sampleRow.failure.missingSampleRowCode=Line %s\: You must precise a code for the sample row +wao.import.sampleRow.failure.missingSclerochronologySamplingContext=Line %s\:You must precise the context +wao.import.sampleRow.failure.missingSpecies=Line %s\:You must precise the species wao.import.sampleRow.failure.noEffortDefined=Line %s\: You must precise effort wao.import.sampleRow.failure.sampleMonthWithIllegalExpectedTidesValue=Line %s\: Effort must be positive for month %s wao.import.sampleRow.failure.unknownFishingGearDcfCode=Unknown fishing gear code\: %s +wao.import.sampleRow.failure.unknownOrganisation=Unknown organisation %s +wao.import.sampleRow.failure.unknownSpecies=Unknown species %s wao.import.sampleRow.failure.unknownTargetSpeciesDcfCode=Unknown target species code\: %s wao.import.sampleRow.failure.wrongFishingZone=There is no fishing zone with the code '%s' wao.import.sampleRow.failure.wrongSampleRowCodeFormat=The sample row code '%s' is not compliant with the format "YYYY_PIIII" diff --git a/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties b/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties index a4dc317..01f18dd 100644 --- a/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties +++ b/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties @@ -84,14 +84,19 @@ wao.import.sampleRow.failure.codeMustBeUnique=Ligne %s \: Le code ligne doit êt wao.import.sampleRow.failure.fishingZoneMissing=Ligne %s \: Il faut préciser au moins une zone de pêche wao.import.sampleRow.failure.missingDcf5Codes=Ligne %s \: Il faut préciser au moins un code DCF5 wao.import.sampleRow.failure.missingFishingZones=Ligne %s \: Il faut préciser au moins une zone de pêche +wao.import.sampleRow.failure.missingIndividualMeasurementStrategy=Ligne %s \: il faut préciser l'ensemble de caractéristiques à mesurer wao.import.sampleRow.failure.missingPeriodBegin=Ligne %s \: Il faut préciser le débat de la période wao.import.sampleRow.failure.missingPeriodEnd=Ligne %s \: Il faut préciser la fin de la période wao.import.sampleRow.failure.missingProfessionSpecies=Ligne %s \: Il faut préciser les espèces cibles pour cette stratégie d'échantillonage wao.import.sampleRow.failure.missingProgramName=Ligne %s \: Il faut préciser le programme wao.import.sampleRow.failure.missingSampleRowCode=Ligne %s \: Il faut préciser un code pour a ligne du plan +wao.import.sampleRow.failure.missingSclerochronologySamplingContext=Ligne %s \: Il faut préciser le contexte dans lequel se fera l'échantillonnage +wao.import.sampleRow.failure.missingSpecies=Ligne %s \: Il faut préciser l'espèce cible wao.import.sampleRow.failure.noEffortDefined=Ligne %s \: Il faut préciser un effort sur au moins un mois wao.import.sampleRow.failure.sampleMonthWithIllegalExpectedTidesValue=Ligne %s \: l'effort d'observation doit être positif pour le mois %s wao.import.sampleRow.failure.unknownFishingGearDcfCode=Le code engin %s est inconnu du référentiel +wao.import.sampleRow.failure.unknownOrganisation=L'organisation %s n'est pas connue +wao.import.sampleRow.failure.unknownSpecies=L'espèce %s n'est pas connue wao.import.sampleRow.failure.unknownTargetSpeciesDcfCode=Le code espèce cible %s est inconnu du référentiel wao.import.sampleRow.failure.wrongFishingZone=Le code '%s' ne correspond à aucune zone de pêche connue du référentiel wao.import.sampleRow.failure.wrongSampleRowCodeFormat=Le code '%s' n'est pas un code de ligne valide selon le format "AAAA_PIIII" diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/BoatsServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/BoatsServiceTest.java index 58eaf29..6ec77b0 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/BoatsServiceTest.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/BoatsServiceTest.java @@ -23,7 +23,6 @@ package fr.ifremer.wao.services.service; 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; diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java index ff213a8..ed7f169 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/ContactsServiceTest.java @@ -23,7 +23,6 @@ package fr.ifremer.wao.services.service; 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; diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerFixtures.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerFixtures.java new file mode 100644 index 0000000..e3c1806 --- /dev/null +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerFixtures.java @@ -0,0 +1,93 @@ +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.WaoTechnicalException; +import fr.ifremer.wao.entity.FishingGearDcf; +import fr.ifremer.wao.entity.FishingGearDcfTopiaDao; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.TargetSpeciesDcf; +import fr.ifremer.wao.entity.TargetSpeciesDcfTopiaDao; +import fr.ifremer.wao.entity.UserRole; +import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.WaoServiceContext; +import org.apache.commons.io.IOUtils; + +import java.io.InputStream; + +public class ObsMerFixtures extends WaoFixtures { + + public ObsMerFixtures(WaoServiceContext serviceContext) { + super(serviceContext); + } + + public AuthenticatedWaoUser admin() { + return newAuthenticatedWaoUser("admin", ObsProgram.OBSMER, UserRole.ADMIN); + } + + public AuthenticatedWaoUser jmichmuche() { + return newAuthenticatedWaoUser("jmichmuche", ObsProgram.OBSMER, UserRole.COORDINATOR); + } + + public void samplingPlan() { + ifremer(); + oceanet(); + fishingZones(); + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/echantillonnage.csv"); + serviceContext.newService(ObsMerSamplingPlanService.class).importSamplingPlan(admin(), input); + } catch (ImportErrorException e) { + throw new WaoTechnicalException(e); + } finally { + IOUtils.closeQuietly(input); + } + } + + public void contacts() { + samplingPlan(); + jmichmuche(); + navires(); + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/contacts.csv"); + serviceContext.newService(ContactsService.class).importContacts(admin(), input); + } catch (ImportErrorException e) { + throw new WaoTechnicalException(e); + } finally { + IOUtils.closeQuietly(input); + } + } + + public FishingGearDcf ptb() { + FishingGearDcfTopiaDao fishingGearDcfDao = serviceContext.getPersistenceContext().getFishingGearDcfDao(); + FishingGearDcf ptb = fishingGearDcfDao.forCodeEquals("PTB").findUnique(); + return ptb; + } + + public TargetSpeciesDcf def() { + TargetSpeciesDcfTopiaDao fishingGearDcfDao = serviceContext.getPersistenceContext().getTargetSpeciesDcfDao(); + TargetSpeciesDcf def = fishingGearDcfDao.forCodeEquals("DEF").findUnique(); + return def; + } + +} diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java index 61c6d5b..76f8f4f 100644 --- a/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java @@ -27,7 +27,6 @@ import fr.ifremer.wao.entity.SampleMonth; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.services.AbstractWaoServiceTest; import fr.ifremer.wao.services.FakeWaoServiceContext; -import fr.ifremer.wao.services.ObsMerFixtures; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java new file mode 100644 index 0000000..0310d5e --- /dev/null +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologyFixtures.java @@ -0,0 +1,50 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.WaoTechnicalException; +import fr.ifremer.wao.entity.Laboratory; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.UserRole; +import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.WaoServiceContext; +import fr.ifremer.wao.services.service.administration.LaboratoriesService; +import fr.ifremer.wao.services.service.administration.ReferentialService; +import org.apache.commons.io.IOUtils; + +import java.io.InputStream; + +public class SclerochronologyFixtures extends WaoFixtures { + + public SclerochronologyFixtures(WaoServiceContext serviceContext) { + super(serviceContext); + } + + public AuthenticatedWaoUser admin() { + return newAuthenticatedWaoUser("admin", ObsProgram.SCLEROCHRONOLOGY, UserRole.ADMIN); + } + + public void species() { + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/especes.csv"); + serviceContext.newService(ReferentialService.class).importSpecies(input); + } catch (ImportErrorException e) { + throw new WaoTechnicalException(e); + } finally { + IOUtils.closeQuietly(input); + } + } + + protected boolean emhLaboratoryCreated; + + public void emhLaboratory() { + if ( ! emhLaboratoryCreated) { + ifremer(); + LaboratoriesService service = serviceContext.newService(LaboratoriesService.class); + Laboratory laboratory = service.newLaboratory(); + laboratory.setName("EMH"); + service.save(laboratory); + emhLaboratoryCreated = true; + } + } + +} diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java new file mode 100644 index 0000000..b959dab --- /dev/null +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanServiceTest.java @@ -0,0 +1,51 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.services.AbstractWaoServiceTest; +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 java.io.InputStream; + +public class SclerochronologySamplingPlanServiceTest extends AbstractWaoServiceTest { + + private static final Log log = LogFactory.getLog(SclerochronologySamplingPlanServiceTest.class); + + protected SclerochronologySamplingPlanService service; + + protected SclerochronologyFixtures fixtures; + + protected boolean isDatabaseWithReferential() { + return true; + } + + @Before + public void setUp() { + service = newService(SclerochronologySamplingPlanService.class); + fixtures = new SclerochronologyFixtures(newServiceContext()); + } + + @Test + public void testImportSamplingPlan() { + fixtures.fishingZones(); + fixtures.species(); + fixtures.oceanet(); + fixtures.emhLaboratory(); + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/plan-sclerochronologie.csv"); + service.importSamplingPlan(fixtures.admin(), input); + } catch (ImportErrorException e) { + if (log.isDebugEnabled()) { + log.debug("unexpected exception raised", e); + } + Assert.fail("exception should not be raised"); + } finally { + IOUtils.closeQuietly(input); + } + + } +} \ No newline at end of file diff --git a/wao-services/src/test/java/fr/ifremer/wao/services/service/WaoFixtures.java b/wao-services/src/test/java/fr/ifremer/wao/services/service/WaoFixtures.java new file mode 100644 index 0000000..63e1885 --- /dev/null +++ b/wao-services/src/test/java/fr/ifremer/wao/services/service/WaoFixtures.java @@ -0,0 +1,88 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.WaoTechnicalException; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.CompanyTopiaDao; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.UserProfile; +import fr.ifremer.wao.entity.UserProfileImpl; +import fr.ifremer.wao.entity.UserRole; +import fr.ifremer.wao.entity.WaoUser; +import fr.ifremer.wao.entity.WaoUserImpl; +import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.WaoServiceContext; +import fr.ifremer.wao.services.service.administration.ReferentialService; +import org.apache.commons.io.IOUtils; + +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +public class WaoFixtures { + + protected WaoServiceContext serviceContext; + + protected Map<String, Company> companies = new HashMap<>(); + + public WaoFixtures(WaoServiceContext serviceContext) { + this.serviceContext = serviceContext; + } + + protected Company getCompany(String companyName) { + Company company = companies.get(companyName); + if (company == null) { + CompanyTopiaDao companyDao = serviceContext.getPersistenceContext().getCompanyDao(); + company = companyDao.create( + Company.PROPERTY_NAME, companyName, + Company.PROPERTY_ACTIVE, true); + companies.put(companyName, company); + serviceContext.getPersistenceContext().commit(); + } + return company; + } + + protected AuthenticatedWaoUser newAuthenticatedWaoUser(String login, ObsProgram obsProgram, UserRole userRole) { + WaoUser waoUser = new WaoUserImpl(); + waoUser.setOrganisation(ifremer()); + waoUser.setLogin(login); + waoUser.setActive(true); + UserProfile userProfile = new UserProfileImpl(); + userProfile.setUserRole(userRole); + userProfile.setObsProgram(obsProgram); + userProfile.setCanWrite(true); + waoUser.addUserProfile(userProfile); + return new AuthenticatedWaoUser(waoUser, userProfile); + } + + public Company ifremer() { + return getCompany("IFREMER"); + } + + public Company oceanet() { + return getCompany("OCEANET"); + } + + public void fishingZones() { + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/zonesPeche.csv"); + serviceContext.newService(ReferentialService.class).importFishingZones(input); + } catch (ImportErrorException e) { + throw new WaoTechnicalException(e); + } finally { + IOUtils.closeQuietly(input); + } + } + + public void navires() { + InputStream input = null; + try { + input = getClass().getResourceAsStream("/import/navires.csv"); + serviceContext.newService(ReferentialService.class).importBoats(input); + } catch (ImportErrorException e) { + throw new WaoTechnicalException(e); + } finally { + IOUtils.closeQuietly(input); + } + } +} diff --git a/wao-services/src/test/resources/import/echantillonnage.csv b/wao-services/src/test/resources/import/echantillonnage.csv index beda484..0073eab 100644 --- a/wao-services/src/test/resources/import/echantillonnage.csv +++ b/wao-services/src/test/resources/import/echantillonnage.csv @@ -1,14 +1,14 @@ "PLAN_CODE";"SOCIETE_NOM";"PECHE_DIVISION";"PECHE_AUTRE";"METIER_CODE_DCF5";"METIER_MAILLAGE";"METIER_TAILLE";"METIER_AUTRE";"METIER_LIBELLE";"METIER_ESPECES";"PROGRAMME_CODE";"PROGRAMME_DEBUT";"PROGRAMME_FIN";"12/2009";"01/2010";"02/2010";"03/2010";"04/2010";"05/2010";"06/2010";"07/2010";"08/2010";"09/2010";"10/2010";"11/2010";"12/2010";"01/2011";"02/2011";"03/2011";"PLAN_DUREE_MOY";"PLAN_NB_OBSERV";"PLAN_COMMENT";"TAUX_COUVERTURE_APPLIQUE" -"2010_M0001";"Ifremer";"IId,I";;"DRB_ALG";;;;;;"MA-2009";"03/2010";"01/2011";;;;0;0;0;0;0;0;0;2;0;0;4;;;"1.5";1;"Un petit commentaire";5 -"2010_M0002";"Ifremer";"IId";;"DRH_CAT,DRH_CRU";;;;"Fileyage";"poissons tubes";"MANY";"01/2008";"12/2008";;20;0;0;21;0;0;21;0;0;21;0;0;;;;1;1;;5 -"2010_M0003";"Ifremer";"IId,IV";;"DRH";;;;"balottage en plein air";"divers choses visqueuses";"MA-2009";"03/2010";"01/2011";;;;0;22;0;0;25;0;0;21;0;0;25;;;2;1;;5 -"2009_M0001";"Ifremer";"IId,IV";;"GTR_DEF,GNS_DEF";"110-119";;;"Fileyage à poissons tubes";"poissons plats";"PPP2010";"12/2009";"10/2010";0;1;1;1;2;1;1;1;1;1;2;;;;;;1;1;;5 -"2009_M0002";"Ifremer";"IId";;"GTR_DEF,GNS_DEF";"9888-99";;;"Fileyage à sirènes ";"nymphes";"PPP2010";"12/2009";"10/2010";1;1;1;2;3;4;4;4;4;3;3;;;;;;1;1;;10 -"2009_M0003";"Ifremer";"IV";;"GTR_MOL,GNS";;;;"Fileyages à baleines à bosse";"chameaux";"PPP2010";"12/2009";"10/2010";2;2;2;2;2;2;2;2;2;2;4;;;;;;1;1;;10 -"2009_M0004";"Ifremer";"IId";;"PTB_ALG";">=190";">18";;"Chalutage de fond machiavélique";"gadidés; divers";"PPP2010";"12/2009";"10/2010";1;1;1;1;1;1;1;1;1;1;2;;;;;;3;2;;10 -"2009_M0005";"Ifremer";"IId";;"PTB_ALG";"70-1100";">1140";;"Plongeur de fond sous-marin";"gadidés; divers";"PPP2010";"12/2009";"10/2010";1;1;1;1;1;1;1;1;1;1;2;;;;;;3;2;;10 +"2010_M0001";"IFREMER";"IId,I";;"DRB_ALG";;;;;;"MA-2009";"03/2010";"01/2011";;;;0;0;0;0;0;0;0;2;0;0;4;;;"1.5";1;"Un petit commentaire";5 +"2010_M0002";"IFREMER";"IId";;"DRH_CAT,DRH_CRU";;;;"Fileyage";"poissons tubes";"MANY";"01/2008";"12/2008";;20;0;0;21;0;0;21;0;0;21;0;0;;;;1;1;;5 +"2010_M0003";"IFREMER";"IId,IV";;"DRH";;;;"balottage en plein air";"divers choses visqueuses";"MA-2009";"03/2010";"01/2011";;;;0;22;0;0;25;0;0;21;0;0;25;;;2;1;;5 +"2009_M0001";"IFREMER";"IId,IV";;"GTR_DEF,GNS_DEF";"110-119";;;"Fileyage à poissons tubes";"poissons plats";"PPP2010";"12/2009";"10/2010";0;1;1;1;2;1;1;1;1;1;2;;;;;;1;1;;5 +"2009_M0002";"IFREMER";"IId";;"GTR_DEF,GNS_DEF";"9888-99";;;"Fileyage à sirènes ";"nymphes";"PPP2010";"12/2009";"10/2010";1;1;1;2;3;4;4;4;4;3;3;;;;;;1;1;;10 +"2009_M0003";"IFREMER";"IV";;"GTR_MOL,GNS";;;;"Fileyages à baleines à bosse";"chameaux";"PPP2010";"12/2009";"10/2010";2;2;2;2;2;2;2;2;2;2;4;;;;;;1;1;;10 +"2009_M0004";"IFREMER";"IId";;"PTB_ALG";">=190";">18";;"Chalutage de fond machiavélique";"gadidés; divers";"PPP2010";"12/2009";"10/2010";1;1;1;1;1;1;1;1;1;1;2;;;;;;3;2;;10 +"2009_M0005";"IFREMER";"IId";;"PTB_ALG";"70-1100";">1140";;"Plongeur de fond sous-marin";"gadidés; divers";"PPP2010";"12/2009";"10/2010";1;1;1;1;1;1;1;1;1;1;2;;;;;;3;2;;10 "2009_M0006";"OCEANET";"I,IV";;"DRB_DEF";"70-1100";">1140";;"Leon";"poissons plats";"PPP2010";"12/2009";"10/2010";0;1;0;1;0;1;2;2;2;2;1;;;;;;3;2;; -"2010_M0004";"Ifremer";"IId,IV";;"PTB_DEF,PTB_ALG,DRH";;;;"Chalutage de fond";"gadidés; poissons plats; divers";"BLOB";"01/2010";"12/2010";;3;0;0;3;0;0;3;0;0;3;0;0;;;;3;1;; +"2010_M0004";"IFREMER";"IId,IV";;"PTB_DEF,PTB_ALG,DRH";;;;"Chalutage de fond";"gadidés; poissons plats; divers";"BLOB";"01/2010";"12/2010";;3;0;0;3;0;0;3;0;0;3;0;0;;;;3;1;; "2010_M0005";"OCEANET";"IId";;"DRB";;;;"Kamoulox";"merlu; poissons cerises; divers";"MA-2009";"03/2010";"01/2011";;;;0;5;0;0;5;0;0;6;0;0;3;;;3;1;;15 "2010_M0010";"OCEANET";"I,IV";;"DRB";"70-1100";;;"Kamoulox";"merlu; poissons pommes; divers";"MA-2009";"03/2010";"01/2011";;;;0;5;0;0;5;0;0;6;0;0;3;;;3;1;;15 "2010_M0011";"OCEANET";"I,IV";;"DRB_ANA";"70-1100";;;"Troubidou";"merlu; poissons cerises";"MA-2009";"03/2010";"01/2011";;;;0;5;0;0;5;0;0;6;0;0;3;;;3;1;; diff --git a/wao-services/src/test/resources/import/plan-sclerochronologie.csv b/wao-services/src/test/resources/import/plan-sclerochronologie.csv new file mode 100644 index 0000000..e2cdf2c --- /dev/null +++ b/wao-services/src/test/resources/import/plan-sclerochronologie.csv @@ -0,0 +1,6 @@ +PLAN_CODE;ORGANISATION_NOM;PECHE_DIVISION;PECHE_AUTRE;PROGRAMME_CODE;PROGRAMME_DEBUT;PROGRAMME_FIN;PLAN_COMMENT;ESPECE_CIBLE;CONTEXTE;CONTEXTE_COMPLEMENT;MESURES;01/2015;02/2015;03/2015;04/2015;05/2015;06/2015;07/2015;08/2015;09/2015;10/2015;11/2015;12/2015 +2015_S0001;OCEANET;X;;CAMPAGNE_22;01/2015;12/2015;;1644;Échantillonnage en mer;;Poids/Taille/Sexe;200;;100;0;50;;;;;;;12 +2015_S0002;OCEANET;X;;CAMPAGNE_22;01/2015;12/2015;;1644;Échantillonnage en mer;;Poids/Taille/Sexe;;;;0;;;300;300;;;; +2015_S0003;EMH;X;;CAMPAGNE_22;01/2015;12/2015;;1543;Échantillonnage à terre;;Poids/Taille/Sexe/Maturité/Âge;;200;;100;0;50;;100;0;50;; +2015_S0004;EMH;IV;;RECHERCHE;01/2015;12/2015;;1543;Campagne scientifique;;Poids/Taille/Sexe;;;;200;;100;0;50;;;; +2015_S0005;EMH;IV;;RECHERCHE;01/2015;12/2015;;1543;Campagne scientifique;;Poids/Taille;;200;;100;0;50;;;200;;100;0 diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java index faee62f..814f729 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java @@ -29,11 +29,14 @@ import fr.ifremer.wao.entity.SampleMonth; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.services.service.MissingDcf5CodesException; import fr.ifremer.wao.services.service.MissingFishingZonesException; +import fr.ifremer.wao.services.service.MissingIndividualMeasurementStrategyException; import fr.ifremer.wao.services.service.MissingPeriodBeginException; import fr.ifremer.wao.services.service.MissingPeriodEndException; import fr.ifremer.wao.services.service.MissingProfessionSpeciesException; import fr.ifremer.wao.services.service.MissingProgramNameException; import fr.ifremer.wao.services.service.MissingSampleRowLogCommentException; +import fr.ifremer.wao.services.service.MissingSclerochronologySamplingContextException; +import fr.ifremer.wao.services.service.MissingSpeciesException; import fr.ifremer.wao.services.service.NoEffortDefinedException; import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; import fr.ifremer.wao.services.service.SampleMonthWithIllegalExpectedTidesValueException; @@ -126,6 +129,15 @@ public class EditSampleRowAction extends WaoJspActionSupport implements Preparab addFieldError("updateSampleRowCommand.dcf5Codes", t("wao.ui.form.SampleRow.error.noEffortDefined")); } + // TODO brendan 18/12/14 + catch (MissingIndividualMeasurementStrategyException e) { + throw new UnsupportedOperationException(); + } catch (MissingSclerochronologySamplingContextException e) { + throw new UnsupportedOperationException(); + } catch (MissingSpeciesException e) { + throw new UnsupportedOperationException(); + } + } @Override diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/ImportSpeciesAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/ImportSpeciesAction.java index 88f2b4c..d21b8cc 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/ImportSpeciesAction.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/administration/ImportSpeciesAction.java @@ -4,6 +4,8 @@ import fr.ifremer.wao.services.service.ImportErrorException; import java.io.InputStream; +import static org.nuiton.i18n.I18n.n; + public class ImportSpeciesAction extends AbstractImportReferentialAction { @Override @@ -13,6 +15,6 @@ public class ImportSpeciesAction extends AbstractImportReferentialAction { @Override protected String getSuccessMessage() { - return t("wao.import.species.success"); + return t(n("wao.import.species.success")); } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm