Author: bleny Date: 2014-06-20 21:20:31 +0200 (Fri, 20 Jun 2014) New Revision: 2079 Url: http://forge.codelutin.com/projects/wao/repository/revisions/2079 Log: refs #4488 contacts for obsvente, finished ? Added: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/IllegalAcceptationException.java Modified: branches/wao-4.0-obsvente/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java branches/wao-4.0-obsvente/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocations.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java branches/wao-4.0-obsvente/wao-services/src/main/resources/i18n/wao-services_en_GB.properties branches/wao-4.0-obsvente/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_en_GB.properties branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/contacts.jsp branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp Modified: branches/wao-4.0-obsvente/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java =================================================================== --- branches/wao-4.0-obsvente/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocationImpl.java 2014-06-20 19:20:31 UTC (rev 2079) @@ -23,6 +23,8 @@ import org.apache.commons.lang3.builder.ToStringBuilder; import org.nuiton.i18n.I18n; +import java.util.Locale; + public class TerrestrialLocationImpl extends TerrestrialLocationAbstract { @Override @@ -78,7 +80,7 @@ } else { // it's a port or an auction description.append(getName()).append(" (") .append(getCode()).append(", ") - .append(getLocationType()).append(", "); + .append(I18n.l(Locale.FRANCE, getLocationType().getI18nKey())).append(", "); // add the port name only if it's different of the name // because most of the time it's redundant if (getPortName() != null && ! getPortName().equals(getName())) { Modified: branches/wao-4.0-obsvente/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocations.java =================================================================== --- branches/wao-4.0-obsvente/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocations.java 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-persistence/src/main/java/fr/ifremer/wao/entity/TerrestrialLocations.java 2014-06-20 19:20:31 UTC (rev 2079) @@ -22,7 +22,10 @@ */ import com.google.common.base.Function; +import com.google.common.collect.Ordering; +import java.util.Comparator; + public class TerrestrialLocations { public static Function<TerrestrialLocation, String> getDistrictCode() { @@ -37,6 +40,14 @@ return new GetRegionIfremerCode(); } + public static Comparator<TerrestrialLocation> nameComparator() { + return Ordering.natural().onResultOf(getName()); + } + + public static Function<TerrestrialLocation, String> getName() { + return new GetName(); + } + protected static class GetDistrictCode implements Function<TerrestrialLocation, String> { @Override @@ -60,4 +71,12 @@ return input.getRegionIfremerCode(); } } + + protected static class GetName implements Function<TerrestrialLocation, String> { + + @Override + public String apply(TerrestrialLocation input) { + return input.getName(); + } + } } Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java 2014-06-20 19:20:31 UTC (rev 2079) @@ -423,6 +423,9 @@ } catch (MissingContactTerrestrialLocationException e) { String message = l(l, "wao.import.contact.failure.missingTerrestrialLocation", lineNumber); throw new ImportErrorException(message); + } catch (IllegalAcceptationException e) { + String message = l(l, "wao.import.contact.failure.illegalAcceptation", lineNumber); + throw new ImportErrorException(message); } save0(updateContactCommand); @@ -472,7 +475,7 @@ MissingContactDataInputDateException, ContactRestitutionDateBeforeDataInputDateException, MissingContactDataReliabilityException, - MissingContactCommentAdminException, MissingContactTerrestrialLocationException { + MissingContactCommentAdminException, MissingContactTerrestrialLocationException, IllegalAcceptationException { if (needUpdate) { Preconditions.checkState(!updateContactCommand.isCreation()); @@ -661,16 +664,16 @@ //--- if (ContactState.OBSERVATION_DONE == contactState) { - if (contact.getObservedDataControl() == null) { + if (contact.getObsProgram().isObsMer() && contact.getObservedDataControl() == null) { throw new MissingContactObservedDataControlException(contact); - } else if (contact.getObservedDataControl().equals(ObservedDataControl.CORRECTION_ASKED)) { + } else if (ObservedDataControl.CORRECTION_ASKED.equals(contact.getObservedDataControl())) { throw new ContactWithObservedDataControlToCorrectionAskedException(contact); } } // Pour valider un contact société, il faut que le contact aie une date de transmission Date restitution = contact.getRestitution(); - if (ObservedDataControl.ACCEPTED == contact.getObservedDataControl() && restitution == null) { + if (ObservedDataControl.ACCEPTED.equals(contact.getObservedDataControl()) && restitution == null) { throw new MissingContactRestitutionException(contact); } if (dataInputDate == null && restitution != null) { @@ -687,6 +690,11 @@ throw new MissingContactCommentAdminException(contact); } + if (contact.getValidationProgram() != null && contact.getValidationCompany() == null) { + + throw new IllegalAcceptationException(contact); + } + if (BooleanUtils.isTrue(contact.getValidationProgram())) { //--- Added: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/IllegalAcceptationException.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/IllegalAcceptationException.java (rev 0) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/IllegalAcceptationException.java 2014-06-20 19:20:31 UTC (rev 2079) @@ -0,0 +1,10 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.entity.Contact; + +public class IllegalAcceptationException extends WaoContactValidationException { + + public IllegalAcceptationException(Contact contact) { + super(contact); + } +} Modified: branches/wao-4.0-obsvente/wao-services/src/main/resources/i18n/wao-services_en_GB.properties =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-services/src/main/resources/i18n/wao-services_en_GB.properties 2014-06-20 19:20:31 UTC (rev 2079) @@ -40,6 +40,7 @@ wao.import.contact.failure.dataInputDateBeforeToday=La date de saisie des données doit être antérieur à la date du jour wao.import.contact.failure.districtMissing=You need to precise the boat district wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers=Main observer can not be also a secondary observer +wao.import.contact.failure.illegalAcceptation= wao.import.contact.failure.invalidObservationBeginDate=La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne wao.import.contact.failure.locationTypeMissing=The type of the location must be filled wao.import.contact.failure.mismatchCompanyForObserver=L'observateur %s n'est pas membre de la société %s Modified: branches/wao-4.0-obsvente/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-services/src/main/resources/i18n/wao-services_fr_FR.properties 2014-06-20 19:20:31 UTC (rev 2079) @@ -37,6 +37,7 @@ wao.import.contact.failure.dataInputDateBeforeObservationEndDate=La date de saisie des données doit être postérieure à la date de fin d'observation wao.import.contact.failure.districtMissing=Il faut préciser le code d'un quartier maritime wao.import.contact.failure.duplicatedMainObserverInSecondaryObservers=L'utilisateur référant ne doit pas se trouver aussi parmi les observateurs secondaires +wao.import.contact.failure.illegalAcceptation= wao.import.contact.failure.invalidObservationBeginDate=Ligne %s \: La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne wao.import.contact.failure.locationTypeMissing=Le type du lieu doit être renseigné wao.import.contact.failure.mismatchCompanyForObserver=Ligne %s \: L'observateur %s n'est pas membre de la société %s Modified: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditContactAction.java 2014-06-20 19:20:31 UTC (rev 2079) @@ -32,6 +32,7 @@ import fr.ifremer.wao.entity.ObservedDataControl; import fr.ifremer.wao.entity.SamplingStrategy; import fr.ifremer.wao.entity.TerrestrialLocation; +import fr.ifremer.wao.entity.TerrestrialLocations; import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.entity.WaoUsers; import fr.ifremer.wao.services.AuthenticatedWaoUser; @@ -44,6 +45,7 @@ import fr.ifremer.wao.services.service.ContactWithObservedDataControlToCorrectionAskedException; import fr.ifremer.wao.services.service.ContactsService; import fr.ifremer.wao.services.service.DuplicatedContactMainObserverInSecondaryObserversException; +import fr.ifremer.wao.services.service.IllegalAcceptationException; import fr.ifremer.wao.services.service.InvalidContactObservationBeginDateException; import fr.ifremer.wao.services.service.MismatchContactMainObserverCompanyException; import fr.ifremer.wao.services.service.MismatchContactSecondaryObserverCompanyException; @@ -75,6 +77,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.TreeSet; /** * Created on 4/6/14. @@ -237,7 +240,9 @@ terrestrialLocations = new LinkedHashMap<>(); List<TerrestrialLocation> terrestrialLocationInDistricts = referentialService.getTerrestrialLocationInDistricts(updateContactCommand.getContact().getSampleRow().getTerrestrialLocations()); - for (TerrestrialLocation terrestrialLocation : terrestrialLocationInDistricts) { + Set<TerrestrialLocation> sortedTerrestrialLocations = new TreeSet<>(TerrestrialLocations.nameComparator()); + sortedTerrestrialLocations.addAll(terrestrialLocationInDistricts); + for (TerrestrialLocation terrestrialLocation : sortedTerrestrialLocations) { terrestrialLocations.put(terrestrialLocation.getTopiaId(), terrestrialLocation.getDescription()); } } @@ -334,6 +339,8 @@ } catch (MissingContactTerrestrialLocationException e) { throw new UnsupportedOperationException(); + } catch (IllegalAcceptationException e) { + throw new IllegalStateException("should never occur", e); } } Modified: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ValidateContactJsonAction.java 2014-06-20 19:20:31 UTC (rev 2079) @@ -37,6 +37,7 @@ import fr.ifremer.wao.services.service.ContactWithObservedDataControlToCorrectionAskedException; import fr.ifremer.wao.services.service.ContactsService; import fr.ifremer.wao.services.service.DuplicatedContactMainObserverInSecondaryObserversException; +import fr.ifremer.wao.services.service.IllegalAcceptationException; import fr.ifremer.wao.services.service.InvalidContactObservationBeginDateException; import fr.ifremer.wao.services.service.MismatchContactMainObserverCompanyException; import fr.ifremer.wao.services.service.MismatchContactSecondaryObserverCompanyException; @@ -238,6 +239,9 @@ } catch (MissingContactMammalsInfoException e) { errorMessage = t("wao.ui.form.Contact.error.missingContactMammalsInfo"); + } catch (IllegalAcceptationException e) { + errorMessage = t("wao.ui.form.Contact.error.illegalAcceptationException"); + } if (isSuccessful()) { Modified: branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_en_GB.properties =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_en_GB.properties 2014-06-20 19:20:31 UTC (rev 2079) @@ -286,6 +286,7 @@ wao.ui.form.Contact.error.dataInputDateAfterToday=The data input date cannot be after tomorrow wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate=The data input date cannot be before observation end date wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers=The main observer cannot also be a secondary observer +wao.ui.form.Contact.error.illegalAcceptationException= wao.ui.form.Contact.error.invalidObservationBeginDate=The observation begin date must be a date in a month with an expected effort in the sampling plan wao.ui.form.Contact.error.mismatchCompanyForObserver=Observers must belong to the company attached to the sample row wao.ui.form.Contact.error.missingComment=The comment is mandatory Modified: branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-web/src/main/resources/i18n/wao-web_fr_FR.properties 2014-06-20 19:20:31 UTC (rev 2079) @@ -286,6 +286,7 @@ wao.ui.form.Contact.error.dataInputDateAfterToday=La date de saisie des données doit être antérieure à la date du jour wao.ui.form.Contact.error.dataInputDateBeforeObservationEndDate=La date de saisie des données doit être postérieure à la date de fin d'observation wao.ui.form.Contact.error.duplicatedMainObserverInSecondaryObservers=L'utilisateur référant ne doit pas se trouver aussi parmi les observateurs secondaires +wao.ui.form.Contact.error.illegalAcceptationException= wao.ui.form.Contact.error.invalidObservationBeginDate=La date de début de la marée doit correspondre à un mois valide (non vide) de la ligne wao.ui.form.Contact.error.mismatchCompanyForObserver=L'observateur %s n'est pas membre de la société %s wao.ui.form.Contact.error.missingComment=Il faut préciser un commentaire pour l'état '%s' Modified: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/contacts.jsp =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/contacts.jsp 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/contacts.jsp 2014-06-20 19:20:31 UTC (rev 2079) @@ -60,6 +60,13 @@ filterLabel: "<s:text name="wao.ui.field.FishingZone.sectorName"/>", filterValuesField: 'sampleRowsFilterValues.fishingZoneSectorNames', }, + <s:if test="obsVente"> + { + filterName: 'terrestrialLocationIds', + filterLabel: "<s:text name="wao.ui.field.Contact.terrestrialLocation"/>", + filterValuesField: 'terrestrialLocations' + }, + </s:if> { filterName: 'sampleRowFilter.fishingGearDcfIds', filterLabel: "<s:text name="wao.ui.entity.fishingGearDCF"/>", @@ -103,12 +110,31 @@ filterLabel: "<s:text name="wao.ui.field.Contact.validationProgram"/>", filterValuesField: 'programAcceptations' }, + <s:if test="obsMer"> + { + filterName: 'observedDataControls', + filterLabel: "<s:text name="wao.ui.field.Contact.observedDataControl"/>", + filterValuesField: 'observedDataControls' + }, + </s:if> + <s:if test="obsVente"> + { + filterName: 'sampleRowFilter.samplingStrategies', + filterLabel: "<s:text name="wao.ui.field.SampleRow.samplingStrategy"/>", + filterValuesField: 'sampleRowsFilterValues.samplingStrategies' + }, + { + filterName: 'actualSamplingStrategies', + filterLabel: "<s:text name="wao.ui.field.Contact.samplingStrategy"/>", + filterValuesField: 'actualSamplingStrategies' + }, + { + filterName: 'completeSamplings', + filterLabel: "<s:text name="wao.ui.field.Contact.completeSampling"/>", + filterValuesField: 'completeSamplings' + }, + </s:if> { - filterName: 'observedDataControls', - filterLabel: "<s:text name="wao.ui.field.Contact.observedDataControl"/>", - filterValuesField: 'observedDataControls' - }, - { filterName: 'dataReliabilities', filterLabel: "<s:text name="wao.ui.field.Contact.dataReliability"/>", filterValuesField: 'dataReliabilities' @@ -318,6 +344,7 @@ <th class="only-in-full-view"><s:text name="wao.ui.contacts.division"/></th> <s:if test="obsVente"> <th><s:text name="wao.ui.field.Contact.terrestrialLocation"/></th> + <th><s:text name="wao.ui.field.SampleRow.samplingStrategy"/></th> </s:if> <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.company"/></th> <th><s:text name="wao.ui.contacts.observers"/></th> @@ -413,6 +440,11 @@ <td> <s:property value="terrestrialLocation.description"/> </td> + <td> + <s:if test="sampleRow.samplingStrategy != null"> + <s:text name="%{sampleRow.samplingStrategy.i18nKey}"/> + </s:if> + </td> </s:if> <td class="only-in-full-view"> <s:property value="sampleRow.company.name"/> Modified: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp 2014-06-20 17:38:35 UTC (rev 2078) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-contact-input.jsp 2014-06-20 19:20:31 UTC (rev 2079) @@ -243,7 +243,7 @@ list="terrestrialLocations" emptyOption="true" disabled="%{!#editObservationReport}" - cssClass="input-xxlarge select2" + cssClass="input-xxlarge" /> <s:select name="updateContactCommand.contact.samplingStrategy"