Author: bleny Date: 2014-05-19 12:14:12 +0200 (Mon, 19 May 2014) New Revision: 1955 Url: http://forge.codelutin.com/projects/wao/repository/revisions/1955 Log: fixes #5092 review observer in contact-form Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateContactCommand.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-contact-input.jsp Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java 2014-05-16 15:59:16 UTC (rev 1954) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerContactsService.java 2014-05-19 10:14:12 UTC (rev 1955) @@ -190,11 +190,13 @@ updateContactCommand.setAdmin(authenticatedWaoUser.isAdmin()); + Contact contact; + if (optionalContactId.isPresent()) { String contactId = optionalContactId.get(); - Contact contact = getContact(contactId); + contact = getContact(contactId); updateContactCommand.setContact(contact); @@ -202,7 +204,7 @@ } else { - Contact contact = new ContactImpl(); + contact = new ContactImpl(); contact.setObsProgram(authenticatedWaoUser.getObsProgram()); @@ -211,6 +213,11 @@ updateContactCommand.setCreation(true); } + String mainObserverId = contact.getMainObserver().getTopiaId(); + updateContactCommand.setMainObserverId(mainObserverId); + Set<String> secondaryObserversTopiaIds = contact.getSecondaryObserversTopiaIds(); + updateContactCommand.setSecondaryObserverIds(secondaryObserversTopiaIds); + return updateContactCommand; } @@ -319,7 +326,7 @@ } try { - preValidate(authenticatedWaoUser, updateContactCommand, false); + validate(authenticatedWaoUser, updateContactCommand, false); } catch (ContactNotUpdatableException e) { String message = l(l, "wao.import.contact.failure.not.updatable", lineNumber); throw new ImportErrorException(message); @@ -403,9 +410,21 @@ commit(); } - public void preValidate(AuthenticatedWaoUser authenticatedWaoUser, - UpdateContactCommand updateContactCommand, - boolean needUpdate) throws + public void preValidate(UpdateContactCommand updateContactCommand) { + + String mainObserverId = updateContactCommand.getMainObserverId(); + + WaoUser mainObserver = getWaoUserDao().forTopiaIdEquals(mainObserverId).findUnique(); + updateContactCommand.getContact().setMainObserver(mainObserver); + + List<WaoUser> secondaryObservers = getWaoUserDao().forTopiaIdIn(updateContactCommand.getSecondaryObserverIds()).findAll(); + updateContactCommand.getContact().setSecondaryObservers(new HashSet<>(secondaryObservers)); + + } + + public void validate(AuthenticatedWaoUser authenticatedWaoUser, + UpdateContactCommand updateContactCommand, + boolean needUpdate) throws ContactNotUpdatableException, MissingContactMainObserverException, MismatchContactMainObserverCompanyException, Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateContactCommand.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateContactCommand.java 2014-05-16 15:59:16 UTC (rev 1954) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateContactCommand.java 2014-05-19 10:14:12 UTC (rev 1955) @@ -28,6 +28,8 @@ import org.apache.commons.lang3.ObjectUtils; import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; /** * Created on 4/6/14. @@ -51,6 +53,10 @@ protected String oldMammalsInfo; + protected String mainObserverId; + + protected Set<String> secondaryObserverIds = new HashSet<>(); + public boolean isCreation() { return creation; } @@ -158,4 +164,20 @@ } return mammalsInfosChanged; } + + public String getMainObserverId() { + return mainObserverId; + } + + public void setMainObserverId(String mainObserverId) { + this.mainObserverId = mainObserverId; + } + + public Set<String> getSecondaryObserverIds() { + return secondaryObserverIds; + } + + public void setSecondaryObserverIds(Set<String> secondaryObserverIds) { + this.secondaryObserverIds = secondaryObserverIds; + } } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java 2014-05-16 15:59:16 UTC (rev 1954) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/WaoServiceSupport.java 2014-05-19 10:14:12 UTC (rev 1955) @@ -56,6 +56,7 @@ import fr.ifremer.wao.services.WaoWebApplicationContext; import fr.ifremer.wao.services.service.administration.CompaniesService; import fr.ifremer.wao.services.service.administration.ReferentialService; +import fr.ifremer.wao.services.service.administration.WaoUsersService; import fr.ifremer.wao.services.service.mail.EmailService; import java.util.Date; @@ -110,6 +111,10 @@ return newService(EmailService.class); } + protected WaoUsersService getWaoUsersService() { + return newService(WaoUsersService.class); + } + protected BoatTopiaDao getBoatDao() { return getPersistenceContext().getBoatDao(); } Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java 2014-05-16 15:59:16 UTC (rev 1954) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditContactAction.java 2014-05-19 10:14:12 UTC (rev 1955) @@ -205,10 +205,12 @@ @Override public void validate() { + service.preValidate(updateContactCommand); + AuthenticatedWaoUser authenticatedWaoUser = session.getAuthenticatedWaoUser(); try { - service.preValidate(authenticatedWaoUser, updateContactCommand, true); + service.validate(authenticatedWaoUser, updateContactCommand, true); } catch (ContactNotUpdatableException e) { session.addErrorMessages(t("wao.ui.contacts.validation.failure.not.updatable")); Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java 2014-05-16 15:59:16 UTC (rev 1954) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ValidateContactJsonAction.java 2014-05-19 10:14:12 UTC (rev 1955) @@ -166,7 +166,7 @@ AuthenticatedWaoUser authenticatedWaoUser = session.getAuthenticatedWaoUser(); try { - service.preValidate(authenticatedWaoUser, updateContactCommand, true); + service.validate(authenticatedWaoUser, updateContactCommand, true); } catch (ContactNotUpdatableException e) { session.addErrorMessages(t("wao.ui.contacts.validation.failure.not.updatable")); Modified: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-contact-input.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-contact-input.jsp 2014-05-16 15:59:16 UTC (rev 1954) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-contact-input.jsp 2014-05-19 10:14:12 UTC (rev 1955) @@ -186,22 +186,23 @@ <s:set name="editObservers" value="%{authenticatedWaoUser.isAuthorizedToEditContactObservers(updateContactCommand.contact)}"/> - <s:select name="updateContactCommand.contact.mainObserver.topiaId" + <s:select name="updateContactCommand.mainObserverId" + value="%{updateContactCommand.mainObserverId}" label="%{getText('wao.ui.field.Contact.mainObserver')}" list="observers" emptyOption="true" disabled="%{!#editObservers}" - cssClass="select2 input-large" + cssClass="input-large" /> <s:if test="authenticatedWaoUser.isAuthorizedToDisplayContactSecondaryObservers(updateContactCommand.contact)"> - <s:select name="updateContactCommand.contact.secondaryObservers" - value="%{updateContactCommand.contact.secondaryObserversTopiaIds}" + <s:select name="updateContactCommand.secondaryObserverIds" + value="%{updateContactCommand.secondaryObserverIds}" label="%{getText('wao.ui.field.Contact.secondaryObservers')}" list="observers" multiple="true" disabled="%{!#editObservers}" - cssClass="select2 input-xlarge" + cssClass="input-xlarge" /> </s:if>