[Suiviobsmer-commits] r515 - in trunk: wao-business/src/main/java/fr/ifremer/wao wao-business/src/main/java/fr/ifremer/wao/service wao-ui/src/main/java/fr/ifremer/wao/ui/components wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/resources/fr/ifremer/wao/ui/components wao-ui/src/main/webapp
Author: fdesbois Date: 2010-06-14 12:47:38 +0000 (Mon, 14 Jun 2010) New Revision: 515 Log: - Clean code + javadoc for Connexion - Add currentYear in layout for copyright - Ano #2331 : Change text to display - Evo #2328 : Order companies and observers by alphabetic Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/FeedBack.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/Layout.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Connexion.java trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml trunk/wao-ui/src/main/webapp/Boats.tml trunk/wao-ui/src/main/webapp/Connexion.tml Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-06-12 19:55:13 UTC (rev 514) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-06-14 12:47:38 UTC (rev 515) @@ -7,6 +7,8 @@ import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.PeriodDates; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; @@ -18,6 +20,8 @@ */ public class WaoQueryBuilder { + private static final Logger logger = LoggerFactory.getLogger(WaoQueryBuilder.class); + public static String ALIAS_SAMPLE_ROW = "SR"; public static String ALIAS_CONTACT = "C"; Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-06-12 19:55:13 UTC (rev 514) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-06-14 12:47:38 UTC (rev 515) @@ -346,11 +346,13 @@ CompanyDAO dao = WaoDAOHelper.getCompanyDAO(transaction); + TopiaQuery query = dao.createQuery().addOrder(Company.NAME); + if (activeOnly) { - results = dao.findAllByActive(activeOnly); - } else { - results = dao.findAll(); + query.addEquals(Company.ACTIVE, activeOnly); } + + results = dao.findAllByQuery(query); return results; } @@ -382,7 +384,8 @@ UserRole.getMatchCodes(UserRole.OBSERVER, UserRole.COORDINATOR); TopiaQuery query = dao.createQuery(). - addEquals(WaoUser.ROLE, matchCodes); + addEquals(WaoUser.ROLE, matchCodes). + addOrder(WaoUser.FIRST_NAME, WaoUser.LAST_NAME); if (company != null) { query.addEquals(WaoUser.COMPANY, company); Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/FeedBack.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/FeedBack.java 2010-06-12 19:55:13 UTC (rev 514) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/FeedBack.java 2010-06-14 12:47:38 UTC (rev 515) @@ -82,7 +82,7 @@ void beginRender(MarkupWriter writer) { // Rendu des messages d'erreur et vidage de la collection - if (!errorMessages.isEmpty()) { + if (hasErrors()) { errors = true; writer.element("div", "class", "fb-error"); for (String message : errorMessages) { @@ -140,7 +140,7 @@ } public boolean hasErrors() { - return errors; + return !errorMessages.isEmpty() || errors; } @Log Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/Layout.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/Layout.java 2010-06-12 19:55:13 UTC (rev 514) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/Layout.java 2010-06-14 12:47:38 UTC (rev 515) @@ -40,6 +40,8 @@ import org.apache.tapestry5.services.Request; import org.slf4j.Logger; +import java.util.Calendar; + /** * Layout * @@ -96,6 +98,11 @@ return true; } + public int getCurrentYear() { + Calendar calendar = Calendar.getInstance(); + return calendar.get(Calendar.YEAR); + } + public boolean isDevEnvironment() { return manager.isDevEnvironment(); } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Connexion.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Connexion.java 2010-06-12 19:55:13 UTC (rev 514) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Connexion.java 2010-06-14 12:47:38 UTC (rev 515) @@ -10,6 +10,7 @@ import fr.ifremer.wao.service.ServiceUser; import fr.ifremer.wao.ui.components.FeedBack; import fr.ifremer.wao.ui.data.AuthenticationUtil; +import fr.ifremer.wao.ui.services.RequiresAuthenticationFilter; import fr.ifremer.wao.ui.services.ServiceAuthentication; import org.apache.tapestry5.Link; import org.apache.tapestry5.OptionModel; @@ -20,6 +21,7 @@ import org.apache.tapestry5.annotations.Log; import org.apache.tapestry5.annotations.Persist; import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.corelib.components.Form; import org.apache.tapestry5.internal.OptionModelImpl; import org.apache.tapestry5.internal.SelectModelImpl; import org.apache.tapestry5.ioc.annotations.Inject; @@ -75,10 +77,12 @@ @Property private boolean showRoleWindow; + @InjectComponent + private Form connexionForm; + void onActivate(Object... activationContext) { if (logger.isDebugEnabled()) { - logger.debug("Activiation context : " + - Arrays.toString(activationContext)); + logger.debug("Activiation context : " + Arrays.toString(activationContext)); } this.activationContext = activationContext; } @@ -87,47 +91,30 @@ return activationContext; } -// /** -// * ON_CHANGE :: Callback method for change event on Login textfield component. -// * Login will be checked to refresh the userRole select using {@link -// * JSONObject} that contains data for select options to display in javascript. -// * -// * @param login User login -// * @return a JSONObject with userRole select data to refresh in Ajax -// */ -// @Log -// JSONObject onChangeFromLogin(String login) { -// JSONObject json = new JSONObject(); -// if (serviceUser.existLogin(login)) { -// -// List<UserRole> roles = serviceUser.getUserRolesByLogin(login); -// -// JSONArray array = new JSONArray(); -// for (UserRole role : roles) { -// JSONObject option = new JSONObject(); -// option.put("name", role.name()); -// option.put("label", role.getLabel()); -// array.put(option); -// } -// json.put("select", array); -// } -// return json; -// } -// + /** + * ON_VALIDATE_FORM :: Callback for validateForm event from connexionForm. + * The login and password from the form will be used to connect the user. + * The result {@link ConnectedUser} will be set to {@code serviceAuthentication}. + * Note that users will more than one role will not have a connection role set + * at this time. The page need to be reloaded to display the appropriate popup + * with user roles list. Two type of errors can be catch during connection : + * <ul> + * <li>BAD_CONNECTION : login or password are not corresponding, forgetPassword + * can be used by user</li> + * <li>ILLEGAL_CONNECTION : user is not active anymore</li> + * </ul> + */ @Log void onValidateFormFromConnexionForm() { try { if (logger.isDebugEnabled()) { - logger.debug("Login : " + login); + logger.debug("Connection for user with login : " + login); } - if (login != null && password != null) { - ConnectedUser user = serviceUser.connect(login, password); - // Authenticate the user in appropriate service - serviceAuthentication.setConnectedUser(user); - if (logger.isDebugEnabled()) { - logger.debug("User connected : " + - user.getFullName()); - } + ConnectedUser user = serviceUser.connect(login, password); + // Authenticate the user in appropriate service + serviceAuthentication.setConnectedUser(user); + if (logger.isDebugEnabled()) { + logger.debug("User connected : " + user.getFullName()); } } catch (WaoBusinessException eee) { if (eee.getType().equals(Type.BAD_CONNECTION)) { @@ -137,8 +124,12 @@ connexionFeedback.addInfo(eee.getMessage()); } if (logger.isDebugEnabled()) { - logger.error("WaoBusinessException : " + eee.getMessage(), eee); + logger.error("WaoBusinessException " + eee.getType() + " : " + + eee.getMessage(), eee); } + // Record error to call onFailure callback, errors in form are + // not displayed, messages are recorded in feedBack component + connexionForm.recordError(eee.getMessage()); } } @@ -146,11 +137,19 @@ return connexionFeedback.hasErrors(); } + /** + * ON_SUCCESS :: Callback method for success event on connexionForm. + * A control on connectedUser roles is done to display the appropriate popup + * if connection role is not set. Otherwise the page will be loaded depends + * on redirectLink. + * + * @return the current page if user need to select a role from his list, + * otherwise the link to the page to load. + * @throws WaoException + * @see #getRedirectLink() + */ @Log Object onSuccessFromConnexionForm() throws WaoException { - if (hasConnexionErrors()) { - return this; - } if (serviceAuthentication.getConnectedUser().getRole() == null) { if (logger.isDebugEnabled()) { logger.debug("Not only one role, window will be open to select the role"); @@ -161,6 +160,27 @@ return getRedirectLink(); } + /** + * ON_FAILURE :: Callback for failure event on connexionForm. The connexion + * page will be reloaded to display errors. + * + * @return the current page + */ + @Log + Object onFailureFromConnexionForm() { + if (logger.isDebugEnabled()) { + logger.debug("Failure, errors are recorded (email = " + email + ")"); + } + return this; + } + + /** + * Retrieve the redirect link to load after connection submission. The + * result link depends on {@code activationContext} provided during redirection + * from {@link RequiresAuthenticationFilter}. + * + * @return the Link to load page after connection + */ private Link getRedirectLink() { String redirectPage = AuthenticationUtil.getRedirectPageName(activationContext); Modified: trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml =================================================================== --- trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml 2010-06-12 19:55:13 UTC (rev 514) +++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml 2010-06-14 12:47:38 UTC (rev 515) @@ -143,7 +143,7 @@ </a> - <a href="http://www.gnu.org/licenses/gpl.html" title="License GPL v3" target="blank"> GPLv3 - </a> - Copyright 2009-2010 + </a> - Copyright 2009-${currentYear} <a href="http://www.ifremer.fr" title="Ifremer" target="blank"> Ifremer</a>, <a href="http://www.codelutin.com" title="Code Lutin" target="blank"> Modified: trunk/wao-ui/src/main/webapp/Boats.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Boats.tml 2010-06-12 19:55:13 UTC (rev 514) +++ trunk/wao-ui/src/main/webapp/Boats.tml 2010-06-14 12:47:38 UTC (rev 515) @@ -303,7 +303,7 @@ </span> <t:if t:test="canCreateNewContactFromElligibleBoat()"> <a t:type="actionlink" t:id="addNewContactFromSampleRow" t:context="elligibleBoat.sampleRow.code" - t:mixins="nuiton/confirm" t:message="literal:Attention, cette ligne du plan est terminée, êtes-vous sûr de vouloir créer un nouveau contact ?" + t:mixins="nuiton/confirm" t:message="literal:Attention, cette ligne du plan est arrivée à échéance, êtes-vous sûr de vouloir créer un nouveau contact ?" t:condition="sampleRowFinished"> <img src="${asset:context:}/img/contact-22px.png" title="Créer un nouveau contact pour ce navire et cette ligne du plan"/> </a> Modified: trunk/wao-ui/src/main/webapp/Connexion.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Connexion.tml 2010-06-12 19:55:13 UTC (rev 514) +++ trunk/wao-ui/src/main/webapp/Connexion.tml 2010-06-14 12:47:38 UTC (rev 515) @@ -56,21 +56,15 @@ <div class="fleft clearfix" id="so-connexion-form"> <p><t:label for="login" /> : </p> <p> - <input t:type="textfield" t:id="login" t:value="login"/> + <input t:type="textfield" t:id="login" t:value="login" t:validate="required"/> <img class="hidden" id="loginValid" src="${asset:context:img/valid-16px.png}" alt="Login valide" title="Login valide" /> <img class="hidden" id="loginInvalid" src="${asset:context:img/invalid-16px.png}" alt="Login invalide" title="Login invalide" /> </p> <p><t:label for="password" /> : </p> - <p><input t:type="passwordfield" t:id="password" t:value="password" /></p> - <!--<p><t:label for="userRole" /> : </p>--> - <!--<p><select t:type="select" t:id="userRole" t:value="userRole" t:model="emptySelectModel"/></p>--> - <!--<div class="fright" id="so-connexion-form-buttons">--> - <!--<input class="ico accept" t:type="submit" value="Connexion" title="Connexion à l'application Wao" />--> - <!--</div>--> + <p><input t:type="passwordfield" t:id="password" t:value="password" t:validate="required"/></p> </div> <div class="fright" id="so-connexion-logo"> <input class="ico" t:type="submit" value="Connexion" title="Connexion à l'application Wao" /> - <!--<img src="${asset:context:img/logo-wao-48px.png}" alt="Logo Obsmer"/>--> </div> </form> </div> @@ -87,7 +81,4 @@ </div> </body> - <!--<div class="acenter"> - <img src="${asset:context:}/img/logo_WAO.png" alt="Logo WAO" title="WAO - Web Applicatif Obsmer"/> - </div>--> </html>
participants (1)
-
fdesbois@users.labs.libre-entreprise.org