Author: bleny Date: 2012-03-13 11:28:19 +0100 (Tue, 13 Mar 2012) New Revision: 1560 Url: http://forge.codelutin.com/repositories/revision/wao/1560 Log: Anomalie #964 controles au remplissage du formulaire par l'observateur : motifs de refus Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2012-03-13 09:48:53 UTC (rev 1559) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2012-03-13 10:28:19 UTC (rev 1560) @@ -379,50 +379,32 @@ // Non abouti, Refus ou Refus Définitif if (success && contactState.isUnfinishedState()) { - boolean contactMustHaveAMotif = contact.getObsProgram() == ObsProgram.OBSMER - && (contactState == ContactState.CONTACT_REFUSED - || contactState == ContactState.CONTACT_DEFINITELY_REFUSED); - if (contactMustHaveAMotif) { + if (oldContact != null) { - if (contact.getContactStateMotif() == null) { - success = false; - message = WaoUtils._("wao.business.contact.validation.contactStateMotifMissing"); - } + String newComment = contact.getComment(); - } else { + boolean commentDefined = StringUtils.isNotEmpty(newComment); + boolean commentChanged = commentDefined && + !newComment.equals(oldContact.getComment()); - if (contact.getContactStateMotif() != null) { - success = false; - message = WaoUtils._("wao.business.contact.validation.contactStateMotifUnwanted"); - } + // Ano #2540 : NPE on oldState, extract boolean for + // previous unfinishedState case + boolean previousUnfinishedState = commentDefined && + oldContact.getContactState() != null && oldContact.getContactState().isUnfinishedState(); - if (oldContact != null) { + // Ano #2440 : no restriction if previous state is unfinished + if (previousUnfinishedState || commentChanged) { - String newComment = contact.getComment(); + // RAZ des champs + contact.setObservationBeginDate(null); + contact.setObservationEndDate(null); + contact.setMammalsCapture(false); + contact.setMammalsObservation(false); + contact.setDataInputDate(null); - boolean commentDefined = StringUtils.isNotEmpty(newComment); - boolean commentChanged = commentDefined && - !newComment.equals(oldContact.getComment()); - - // Ano #2540 : NPE on oldState, extract boolean for - // previous unfinishedState case - boolean previousUnfinishedState = commentDefined && - oldContact.getContactState() != null && oldContact.getContactState().isUnfinishedState(); - - // Ano #2440 : no restriction if previous state is unfinished - if (previousUnfinishedState || commentChanged) { - - // RAZ des champs - contact.setObservationBeginDate(null); - contact.setObservationEndDate(null); - contact.setMammalsCapture(false); - contact.setMammalsObservation(false); - contact.setDataInputDate(null); - - } else { - success = false; - message = WaoUtils._("wao.business.contact.validation.commentMissingForState", contact.getContactState().toString()); - } + } else { + success = false; + message = WaoUtils._("wao.business.contact.validation.commentMissingForState", contact.getContactState().toString()); } } // Observation réalisée @@ -451,6 +433,19 @@ // Ici, les contrôle spécifique à ObsMer if (success && contact.getObsProgram() == ObsProgram.OBSMER) { + boolean contactMustHaveAMotif = contact.getObsProgram() == ObsProgram.OBSMER + && (contactState == ContactState.CONTACT_REFUSED + || contactState == ContactState.CONTACT_DEFINITELY_REFUSED); + if (contactMustHaveAMotif && contact.getContactStateMotif() == null) { + success = false; + message = WaoUtils._("wao.business.contact.validation.contactStateMotifMissing"); + } + + if ( ! contactMustHaveAMotif && contact.getContactStateMotif() != null) { + success = false; + message = WaoUtils._("wao.business.contact.validation.contactStateMotifUnwanted"); + } + if (log.isDebugEnabled()) { log.debug("validationProgram = " + contact.getValidationProgram()); }