r1933 - in trunk: wao-persistence/src/main/java/fr/ifremer/wao/entity wao-persistence/src/main/xmi wao-services/src/main/java/fr/ifremer/wao/services/service wao-web/src/main/resources/fr/ifremer/wao/services/service wao-web/src/main/webapp/WEB-INF/content/obsmer
Author: bleny Date: 2014-05-13 14:37:37 +0200 (Tue, 13 May 2014) New Revision: 1933 Url: http://forge.codelutin.com/projects/wao/repository/revisions/1933 Log: refs #4490 add a warn message before creation of a contact for an expired sample row Added: trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/BoatDetails-conversion.properties Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java trunk/wao-persistence/src/main/xmi/wao-model.zargo trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatDetails.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2014-05-13 09:45:36 UTC (rev 1932) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2014-05-13 12:37:37 UTC (rev 1933) @@ -292,4 +292,17 @@ } return trulyElligibleBoats; } + + @Override + public boolean isExpired(Date date) { + boolean expired = true; + if (isSampleMonthNotEmpty()) { + for (SampleMonth sampleMonth : getSampleMonth()) { + if (sampleMonth.getPeriodDate().after(date) || sampleMonth.isPeriodDatesContains(date)) { + expired = false; + } + } + } + return expired; + } } Modified: trunk/wao-persistence/src/main/xmi/wao-model.zargo =================================================================== (Binary files differ) Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatDetails.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatDetails.java 2014-05-13 09:45:36 UTC (rev 1932) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/BoatDetails.java 2014-05-13 12:37:37 UTC (rev 1933) @@ -28,13 +28,18 @@ import fr.ifremer.wao.entity.SampleRow; import java.io.Serializable; +import java.util.Date; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; public class BoatDetails implements Serializable { private static final long serialVersionUID = 1L; + protected Date now; + protected ObsProgram obsProgram; protected BoatInfos boatInfos; @@ -43,7 +48,8 @@ protected long contactsCount; - public BoatDetails(ObsProgram obsProgram, BoatInfos boatInfos, Contact mostRecentContact, long contactsCount) { + public BoatDetails(Date now, ObsProgram obsProgram, BoatInfos boatInfos, Contact mostRecentContact, long contactsCount) { + this.now = now; this.obsProgram = obsProgram; this.boatInfos = boatInfos; this.mostRecentContact = mostRecentContact; @@ -68,7 +74,7 @@ List<SampleRow> elligibleForSampleRows = new LinkedList<>(); for (ElligibleBoat elligibleBoat : boatInfos.getBoat().getElligibleBoat()) { SampleRow sampleRow = elligibleBoat.getSampleRow(); - if (sampleRow.getCompany().equals(boatInfos.getCompany()) && sampleRow.getObsProgram().equals(obsProgram)) { + if (boatInfos.getCompany().equals(sampleRow.getCompany()) && sampleRow.getObsProgram().equals(obsProgram)) { if (elligibleBoat.isBoatElligible()) { elligibleForSampleRows.add(sampleRow); } @@ -77,6 +83,16 @@ return elligibleForSampleRows; } + public Set<String> getExpiredSampleRowIds() { + Set<String> expiredSampleRowIds = new HashSet<>(); + for (SampleRow sampleRow : getElligibleForSampleRows()) { + if (sampleRow.isExpired(now)) { + expiredSampleRowIds.add(sampleRow.getTopiaId()); + } + } + return expiredSampleRowIds; + } + public long getContactsCount() { return contactsCount; } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java 2014-05-13 09:45:36 UTC (rev 1932) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerBoatsService.java 2014-05-13 12:37:37 UTC (rev 1933) @@ -175,8 +175,10 @@ filter.getSampleRowFilter().setCompanyIds(ImmutableSet.of(companyId)); long contactsCount = getContactDao().count(filter); - BoatDetails boatDetails = new BoatDetails(obsProgram, boatInfos, mostRecentContact, contactsCount); + Date now = serviceContext.getNow(); + BoatDetails boatDetails = new BoatDetails(now, obsProgram, boatInfos, mostRecentContact, contactsCount); + return boatDetails; } Added: trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/BoatDetails-conversion.properties =================================================================== --- trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/BoatDetails-conversion.properties (rev 0) +++ trunk/wao-web/src/main/resources/fr/ifremer/wao/services/service/BoatDetails-conversion.properties 2014-05-13 12:37:37 UTC (rev 1933) @@ -0,0 +1 @@ +expiredSampleRowIds=org.nuiton.web.struts2.converters.JsonConverter Modified: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp 2014-05-13 09:45:36 UTC (rev 1932) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/boat-details.jsp 2014-05-13 12:37:37 UTC (rev 1933) @@ -82,9 +82,19 @@ // création d'un contact depuis une ligne éligible - $('input[name="sampleRowId"]').change(function () { - $('#createContactFromBoatButton').removeAttr('disabled'); + var $createContactFromBoatButton = $('#createContactFromBoatButton'); + var $sampleRowIdInput = $('input[name="sampleRowId"]'); + var expiredSampleRowIds = <s:property value="boatDetails.expiredSampleRowIds" escapeHtml="false"/> + $sampleRowIdInput.change(function () { + $createContactFromBoatButton.removeAttr('disabled'); }); + $createContactFromBoatButton.click(function (e) { + var selectedSampleRowIsExpired = $.inArray($('input[name="sampleRowId"]:checked').val(), expiredSampleRowIds); + var confirmMessage = "<s:text name="wao.ui.contacts.createFromBoat.warn"/>"; + if (selectedSampleRowIsExpired && ! confirm(confirmMessage)) { + e.preventDefault(); + } + }); }); </script>
participants (1)
-
bleny@users.forge.codelutin.com