Author: fdesbois Date: 2010-03-26 18:26:03 +0000 (Fri, 26 Mar 2010) New Revision: 393 Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PgMigrationCallback.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java trunk/wao-business/src/main/resources/oldmappings/WaoModel/1.1/fr/ifremer/wao/entity/SampleRowLogImpl.hbm.xml trunk/wao-business/src/main/xmi/wao.properties trunk/wao-business/src/main/xmi/wao.zargo 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/Administration.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ExceptionReport.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowHistoric.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/UserProfile.java trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml trunk/wao-ui/src/main/webapp/SampleRowForm.tml trunk/wao-ui/src/main/webapp/SampleRowHistoric.tml trunk/wao-ui/src/main/webapp/SamplingPlan.tml trunk/wao-ui/src/main/webapp/css/sampling.css Log: - Evo #1960 : Manage comment (sampleRowLog) for coordinator on sampleRow (use sampleRowHistoric page) - Migration -> change admin column by author from sampleRowLog - Improve FeedBack and Layout for fatal errors using afterRender Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PgMigrationCallback.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/PgMigrationCallback.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/PgMigrationCallback.java 2010-03-26 18:26:03 UTC (rev 393) @@ -42,4 +42,10 @@ queries.add("ALTER TABLE Contact RENAME state1 TO state;"); } + @Override + protected void changeSampleRowLogAdminColumn_1_1(List<String> queries) { + // Evo #1960 : change column name admin to author for sampleRowLog + queries.add("ALTER TABLE SampleRowLog RENAME admin TO author;"); + } + } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-03-26 18:26:03 UTC (rev 393) @@ -47,9 +47,11 @@ List<String> queries = new ArrayList<String>(); - createUserRoleColumn_1_1(queries); +// createUserRoleColumn_1_1(queries); +// +// changeContactStateColumn_1_1(queries); - changeContactStateColumn_1_1(queries); + changeSampleRowLogAdminColumn_1_1(queries); String[] strings = queries.toArray(new String[queries.size()]); @@ -60,6 +62,9 @@ protected abstract void changeContactStateColumn_1_1(List<String> queries); + protected abstract void changeSampleRowLogAdminColumn_1_1( + List<String> queries); + @Override public boolean askUser(Version dbVersion, Version applicationVersion, Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2010-03-26 18:26:03 UTC (rev 393) @@ -23,6 +23,7 @@ import fr.ifremer.wao.WaoContext; import fr.ifremer.wao.WaoException; +import fr.ifremer.wao.WaoModelDAOHelper; import java.io.Serializable; import java.util.ArrayList; import java.util.Calendar; @@ -31,6 +32,7 @@ import java.util.Iterator; import java.util.List; import org.apache.commons.lang.BooleanUtils; +import org.nuiton.topia.TopiaContext; import org.nuiton.util.DateUtils; import org.nuiton.util.PeriodDates; import org.slf4j.Logger; @@ -269,4 +271,52 @@ return month != null; } + @Override + public SampleRowLog getNewSampleRowLog(WaoUser user) { + SampleRowLog rowLog = new SampleRowLogImpl(); + rowLog.setSampleRow(this); + rowLog.setAuthor(user); + return rowLog; + } + + /** + * Save a sampleRowLog to the sampleRow. This log is used to comment the + * row. For a comment added by a coordinator, a mail will be sent to the + * admin. + * + * @param rowLog the sampleRowLog to save + * @throws WaoException + */ + @Override + public void saveSampleRowLog(SampleRowLog rowLog) throws WaoException { + TopiaContext transaction = null; + try { + if (log.isInfoEnabled()) { + WaoUser author = rowLog.getAuthor(); + log.info("W:[ saveSampleRowLog ] : " + + "authorName = " + author.getFullName() + + " _ authorRole = " + author.getUserRole()); + } + + transaction = WaoContext.getTopiaRootContext().beginTransaction(); + + SampleRowLogDAO logDAO = + WaoModelDAOHelper.getSampleRowLogDAO(transaction); + + logDAO.create(rowLog); + + transaction.commitTransaction(); + + // Send mail to admin if author is a coordinator : + // WaoContext.PROP_EMAIL_FROM + + } catch (Exception eee) { + WaoContext.serviceException(transaction, + "Impossible d'enregistrer le commentaire écrit par " + + rowLog.getAuthor().getFullName(), eee); + } finally { + WaoContext.closeTransaction(transaction); + } + } + } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-03-26 18:26:03 UTC (rev 393) @@ -412,7 +412,8 @@ //transaction.closeContext(); } catch (Exception eee) { WaoContext.serviceException(transaction, - "Impossible de charger la ligne d'échantillon ayant pour identifiant : " + sampleRowId, + "Impossible de charger la ligne d'échantillon ayant pour" + + " identifiant : " + sampleRowId, eee); } finally { WaoContext.closeTransaction(transaction); @@ -421,6 +422,46 @@ } @Override + public SampleRow getSampleRowByCode(WaoUser user, String sampleRowCode) + throws WaoException { + TopiaContext transaction = null; + SampleRow result = null; + try { + if (log.isInfoEnabled()) { + log.info("W:[ getSampleRowByCode ] : " + + "sampleRowCode = " + sampleRowCode); + } + transaction = rootContext.beginTransaction(); + + SampleRowDAO dao = WaoModelDAOHelper.getSampleRowDAO(transaction); + + TopiaQuery query = dao.createQuery(). + add(SampleRow.CODE, sampleRowCode); + + if (!user.isAdmin()) { + query.add(SampleRow.COMPANY, user.getCompany()); + } + + result = dao.findByQuery(query); + + if (result == null) { + throw new WaoBusinessException(Type.NOT_EXISTS, + ServiceSampling.class, "La ligne du plan avec " + + "pour code " + sampleRowCode + " est introuvable !"); + } + + } catch (Exception eee) { + WaoContext.serviceException(transaction, + "Impossible de charger la ligne " + + "d'échantillon ayant pour code : " + sampleRowCode, + eee); + } finally { + WaoContext.closeTransaction(transaction); + } + return result; + } + + @Override public void deleteSampleRow(SampleRow sampleRow) throws WaoException { TopiaContext transaction = null; try { 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-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-03-26 18:26:03 UTC (rev 393) @@ -37,9 +37,9 @@ import fr.ifremer.wao.entity.WaoUserDAO; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang.StringUtils; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.topia.framework.TopiaQuery.Op; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -229,26 +229,44 @@ try { transaction = rootContext.beginTransaction(); - String userType = user.isAdmin() ? "administrateur" : "observateur"; - String msgBegin = "L'" + userType + " '" + user.getLogin() + "' ne peut pas être supprimé"; - String msgEnd = "Vous pouvez cependant le désactiver pour qu'il ne puisse plus se connecter."; + String userType = StringUtils.lowerCase( + user.getUserRole().getLibelle()); + String msgBegin = "L'" + userType + " '" + user.getLogin() + "'" + + " ne peut pas être supprimé"; + String msgEnd = "Vous pouvez cependant le désactiver pour qu'il" + + " ne puisse plus se connecter."; - if (user.isAdmin()) { - SampleRowLogDAO logDAO = WaoModelDAOHelper.getSampleRowLogDAO(transaction); - List<SampleRowLog> results = logDAO.findAllByAdmin(user); + boolean isCoordinator = + user.getUserRole().equals(UserRole.COORDINATOR); + + if (user.isAdmin() || isCoordinator) { + SampleRowLogDAO logDAO = + WaoModelDAOHelper.getSampleRowLogDAO(transaction); + List<SampleRowLog> results = logDAO.findAllByAuthor(user); if (!results.isEmpty()) { - throw new WaoBusinessException(Type.ALREADY_EXISTS, this.getClass(), - msgBegin + " car il a participé à la modification du plan d'échantillonnage. " + msgEnd); + String msg = ""; + if (isCoordinator) { + msg = " car il a ajouté des commentaires sur le plan " + + "d'échantillonnage."; + } else { + msg = " car il a participé" + + " à la modification du plan d'échantillonnage. "; + } + throw new WaoBusinessException(Type.ALREADY_EXISTS, + this.getClass(), msgBegin + msg + msgEnd); } } else { - ContactDAO contactDAO = WaoModelDAOHelper.getContactDAO(transaction); + ContactDAO contactDAO = + WaoModelDAOHelper.getContactDAO(transaction); List<Contact> results = contactDAO.findAllByObserver(user); if (!results.isEmpty()) { - throw new WaoBusinessException(Type.ALREADY_EXISTS, this.getClass(), - msgBegin + " car il est lié à plusieurs contacts existants. " + msgEnd); + throw new WaoBusinessException(Type.ALREADY_EXISTS, + this.getClass(), + msgBegin + " car il est lié à plusieurs contacts" + + " existants. " + msgEnd); } } @@ -260,7 +278,8 @@ transaction.commitTransaction(); //transaction.closeContext(); } catch (Exception eee) { - WaoContext.serviceException(transaction, "Impossible de créer ou de mettre à jour l'utilisateur", eee); + WaoContext.serviceException(transaction, "Impossible de créer ou" + + " de mettre à jour l'utilisateur", eee); } finally { WaoContext.closeTransaction(transaction); } Modified: trunk/wao-business/src/main/resources/oldmappings/WaoModel/1.1/fr/ifremer/wao/entity/SampleRowLogImpl.hbm.xml =================================================================== --- trunk/wao-business/src/main/resources/oldmappings/WaoModel/1.1/fr/ifremer/wao/entity/SampleRowLogImpl.hbm.xml 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-business/src/main/resources/oldmappings/WaoModel/1.1/fr/ifremer/wao/entity/SampleRowLogImpl.hbm.xml 2010-03-26 18:26:03 UTC (rev 393) @@ -8,6 +8,6 @@ <property name="logText" type="text" access="field" column="logText" node="logText"/> <property name="comment" type="text" access="field" column="comment" node="comment"/> <many-to-one name="sampleRow" class="fr.ifremer.wao.entity.SampleRowImpl" column="sampleRow" node="sampleRow/@topiaId" embed-xml="false"/> - <many-to-one name="admin" class="fr.ifremer.wao.entity.WaoUserImpl" column="admin" lazy="false" node="admin/@topiaId" embed-xml="false"/> + <many-to-one name="author" class="fr.ifremer.wao.entity.WaoUserImpl" column="author" lazy="false" node="author/@topiaId" embed-xml="false"/> </class> </hibernate-mapping> Modified: trunk/wao-business/src/main/xmi/wao.properties =================================================================== --- trunk/wao-business/src/main/xmi/wao.properties 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-business/src/main/xmi/wao.properties 2010-03-26 18:26:03 UTC (rev 393) @@ -14,7 +14,7 @@ fr.ifremer.wao.entity.SampleRow.attribute.elligibleBoat.tagvalue.orderBy=companyActive fr.ifremer.wao.entity.SampleRow.attribute.sampleRowLog.tagvalue.lazy=false fr.ifremer.wao.entity.SampleRow.attribute.sampleRowLog.tagvalue.orderBy=topiaCreateDate desc -fr.ifremer.wao.entity.SampleRowLog.attribute.admin.tagvalue.lazy=false +fr.ifremer.wao.entity.SampleRowLog.attribute.author.tagvalue.lazy=false fr.ifremer.wao.entity.FishingZone.attribute.sampleRow.tagvalue.orderBy=code Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) 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-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/FeedBack.java 2010-03-26 18:26:03 UTC (rev 393) @@ -22,8 +22,11 @@ import java.util.ArrayList; import java.util.List; +import org.apache.tapestry5.BindingConstants; import org.apache.tapestry5.ComponentResources; import org.apache.tapestry5.MarkupWriter; +import org.apache.tapestry5.annotations.Log; +import org.apache.tapestry5.annotations.Parameter; import org.apache.tapestry5.ioc.annotations.Inject; /** @@ -49,6 +52,9 @@ */ public class FeedBack { + @Parameter(defaultPrefix = BindingConstants.LITERAL, value= "true") + private boolean autoClear; + /** Messages d'erreur */ private List<String> errorMessages; @@ -60,6 +66,8 @@ @Inject private ComponentResources resources; + private boolean reload; + public FeedBack() { errorMessages = new ArrayList<String>(); infoMessages = new ArrayList<String>(); @@ -78,7 +86,9 @@ } writer.end(); } - errorMessages.clear(); + if (autoClear) { + errorMessages.clear(); + } // Rendu des messages d'info et vidage de la collection if (!infoMessages.isEmpty()) { @@ -124,4 +134,19 @@ public boolean hasErrors() { return errors; } + + @Log + public void reload() { + reload = true; + } + + public boolean hasBeeanReloaded() { + return reload; + } + + @Log + public void clearErrors() { + errorMessages.clear(); + reload = false; + } } 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-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/Layout.java 2010-03-26 18:26:03 UTC (rev 393) @@ -41,6 +41,7 @@ import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.services.Request; +import org.slf4j.Logger; /** * Layout @@ -89,12 +90,37 @@ @Inject private Request request; + @Inject + private Logger logger; + + private boolean fatal = false; + void setupRender() { if(isCurrentUserExists() && !canShowPage()) { - contentFeedback.addError("Vous n'êtes pas autorisé à accéder à cette page !"); + contentFeedback.addError("Vous n'êtes pas autorisé à accéder" + + " à cette page !"); } } + boolean afterRender() { + // Check if fatal errors has been added to the layout + // Reload the page if feedBack hasn't been reloaded yet to display + // errors + if (fatal && contentFeedback.hasErrors() && + !contentFeedback.hasBeeanReloaded()) { + if (logger.isInfoEnabled()) { + logger.info("[ FATAL ] Reload the page to display" + + " errors"); + } + contentFeedback.reload(); + return false; + } + // Clear errors after page render + contentFeedback.clearErrors(); + fatal = false; + return true; + } + /** * Test if the current user in session is a valid user. * Test topia id existence because WaoUser can be empty when session is lost @@ -103,7 +129,6 @@ * @see fr.ifremer.wao.ui.services.AppModule# * contributeApplicationStateManager(MappedConfiguration) */ - @Log public boolean isCurrentUserExists() { return StringUtils.isNotEmpty(currentUser.getTopiaId()); } @@ -180,6 +205,38 @@ return true; } + public boolean displayBody() { + return canShowPage() && !fatal; + } + + /** + * Add an info message to the layout. + * + * @param message of the info + */ + public void addInfo(String message) { + contentFeedback.addInfo(message); + } + + /** + * Add an error to the layout : display the body any way. + * + * @param message of the error + */ + public void addError(String message) { + contentFeedback.addError(message); + } + + /** + * Add a fatal error to the layout : don't display the page body. + * + * @param message of the error + */ + public void addFatal(String message) { + contentFeedback.addError(message); + fatal = true; + } + @Log Object onSuccessFromConnexionForm() throws WaoException { try { Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-03-26 18:26:03 UTC (rev 393) @@ -146,9 +146,9 @@ void onSuccessFromImportFishingZones() { try { int result = serviceReferential.importFishingZoneCsv(fishingZoneCsvFile.getStream()); - layout.getFeedBack().addInfo(result + " zones de pêche importées"); + layout.addInfo(result + " zones de pêche importées"); } catch (WaoException eee) { - layout.getFeedBack().addError(eee.getMessage()); + layout.addError(eee.getMessage()); } } @@ -254,9 +254,9 @@ serviceUser.deleteUser(user); user = null; userId = null; - layout.getFeedBack().addInfo("Utilisateur supprimé avec succès !"); + layout.addInfo("Utilisateur supprimé avec succès !"); } catch (WaoBusinessException eee) { - layout.getFeedBack().addError(eee.getMessage()); + layout.addError(eee.getMessage()); } } } @@ -276,7 +276,7 @@ serviceUser.createUpdateUser(user, generatePassword); userId = user.getId(); } catch (WaoBusinessException eee) { - layout.getFeedBack().addError(eee.getMessage()); + layout.addError(eee.getMessage()); } } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-03-26 18:26:03 UTC (rev 393) @@ -185,9 +185,9 @@ int[] result = serviceBoat.importBoatCsv(boatsCsvFile.getStream()); // Suppress persitant list of boats boats = null; - layout.getFeedBack().addInfo(result[0] + " navires importés dont " + result[1] + " nouveaux"); + layout.addInfo(result[0] + " navires importés dont " + result[1] + " nouveaux"); } catch (WaoException eee) { - layout.getFeedBack().addError(eee.getMessage()); + layout.addError(eee.getMessage()); } } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-03-26 18:26:03 UTC (rev 393) @@ -210,13 +210,13 @@ ImportResults result = serviceContact.importContactCsv(user, contactsCsvFile.getStream()); // Suppress persitant list of contacts contacts = null; - layout.getFeedBack().addInfo(result.getNbRowsImported() + " contacts importés, " + + layout.addInfo(result.getNbRowsImported() + " contacts importés, " + result.getNbRowsRefused() + " refusés."); for (String error : result.getErrors()) { - layout.getFeedBack().addInfo(error); + layout.addInfo(error); } } catch (WaoBusinessException eee) { - layout.getFeedBack().addError(eee.getMessage()); + layout.addError(eee.getMessage()); } //return importBoatsForm.getHasErrors() ? importBoatsForm : this; } @@ -622,7 +622,7 @@ oldComment = null; contactEdited = null; } catch (WaoException eee) { - layout.getFeedBack().addError(eee.getMessage()); + layout.addError(eee.getMessage()); } } return this; @@ -647,8 +647,7 @@ serviceContact.saveContact(contact, Boolean.FALSE); contactSelectedId = contact.getTopiaId(); } else { - layout.getFeedBack(). - addError("Un contact en cours existe déjà pour ce navire"); + layout.addError("Un contact en cours existe déjà pour ce navire"); } } } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ExceptionReport.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ExceptionReport.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/ExceptionReport.java 2010-03-26 18:26:03 UTC (rev 393) @@ -56,13 +56,14 @@ public void reportException(Throwable eee) { this.exception = getWaoException(eee); if (exception != null) { - layout.getFeedBack().addError(exception.getMessage()); + layout.addError(exception.getMessage()); this.exception = exception.getCause(); } else { this.exception = eee; log.error("Unexpected exception", eee); } - layout.getFeedBack().addError("Erreur : " + this.exception.getClass().getSimpleName() + " : " + this.exception.getMessage()); + layout.addError("Erreur : " + this.exception.getClass().getSimpleName() + + " : " + this.exception.getMessage()); } protected Throwable getWaoException(Throwable eee) { Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2010-03-26 18:26:03 UTC (rev 393) @@ -509,7 +509,8 @@ sampleRow = serviceSampling.getSampleRow(sampleRowId); propertyChange = new WaoPropertyChangeListener(); for (SampleMonth month : sampleRow.getSampleMonth()) { - month.addPropertyChangeListener(SampleMonth.EXPECTED_TIDES_VALUE, propertyChange); + month.addPropertyChangeListener( + SampleMonth.EXPECTED_TIDES_VALUE, propertyChange); } } else { sampleRow = serviceSampling.getNewSampleRow(); @@ -520,9 +521,7 @@ public SampleRowLog getSampleRowLog() throws WaoException { if (sampleRowLog == null) { - sampleRowLog = new SampleRowLogImpl(); - sampleRowLog.setSampleRow(getSampleRow()); - sampleRowLog.setAdmin(user); + sampleRowLog = getSampleRow().getNewSampleRowLog(user); } return sampleRowLog; } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowHistoric.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowHistoric.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowHistoric.java 2010-03-26 18:26:03 UTC (rev 393) @@ -21,17 +21,25 @@ package fr.ifremer.wao.ui.pages; +import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoException; +import fr.ifremer.wao.bean.UserRole; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRowLog; +import fr.ifremer.wao.entity.WaoUser; import fr.ifremer.wao.service.ServiceSampling; import fr.ifremer.wao.ui.base.WaoPage; +import fr.ifremer.wao.ui.components.FeedBack; +import fr.ifremer.wao.ui.components.Layout; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Locale; +import org.apache.commons.lang.StringUtils; import org.apache.tapestry5.annotations.IncludeStylesheet; +import org.apache.tapestry5.annotations.InjectComponent; import org.apache.tapestry5.annotations.Persist; import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.ioc.annotations.Inject; import org.slf4j.Logger; @@ -51,16 +59,22 @@ @Override public boolean isOnlyForAdmin() { - return true; + return false; } @Inject private Logger log; + @SessionState + private WaoUser user; + + @InjectComponent + private Layout layout; + @Inject private ServiceSampling serviceSampling; - private String sampleRowId; + private String sampleRowCode; @Persist private SampleRow sampleRow; @@ -68,25 +82,43 @@ @Property private SampleRowLog sampleRowLog; + private SampleRowLog newLog; + + @InjectComponent + private FeedBack addCommentInfo; + void onActivate(String id) { - sampleRowId = id; + sampleRowCode = id; } String onPassivate() { - return sampleRowId; + return sampleRowCode; } void setupRender() throws WaoException { - sampleRow = null; - getSampleRow(); + if (StringUtils.isEmpty(sampleRowCode)) { + layout.addFatal("L'historique ne peut pas être affiché : " + + "Aucun code de ligne n'est spécifié dans l'url. "); + } else { + + try { + sampleRow = null; + getSampleRow(); + } catch (WaoBusinessException eee) { + layout.addFatal("L'historique ne peut pas être affiché : " + + eee.getMessage()); + } + + if (canAddComment()) { + addCommentInfo.addInfo("L'ajout d'un commentaire enverra" + + " un email aux administrateurs du programme Obsmer"); + } + } } public SampleRow getSampleRow() throws WaoException { if (sampleRow == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getSampleRow]"); - } - sampleRow = serviceSampling.getSampleRow(sampleRowId); + sampleRow = serviceSampling.getSampleRowByCode(user, sampleRowCode); } return sampleRow; } @@ -104,5 +136,22 @@ } return content; } + + public SampleRowLog getNewLog() throws WaoException { + if (newLog == null) { + newLog = getSampleRow().getNewSampleRowLog(user); + } + return newLog; + } + + public boolean canAddComment() { + return user.getUserRole().equals(UserRole.COORDINATOR); + } + + public void onSuccessFromAddComment() throws WaoException { + if (canAddComment()) { + sampleRow.saveSampleRowLog(newLog); + } + } } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-03-26 18:26:03 UTC (rev 393) @@ -114,13 +114,13 @@ void onSuccessFromImportSamplingPlan() throws WaoException { try { ImportResults result = serviceSampling.importSamplingPlanCsv(samplingPlanCsvFile.getStream()); - layout.getFeedBack().addInfo(result.getNbRowsImported() + " lignes du plan importés, " + + layout.addInfo(result.getNbRowsImported() + " lignes du plan importés, " + result.getNbRowsRefused() + " refusés."); for (String error : result.getErrors()) { - layout.getFeedBack().addInfo(error); + layout.addInfo(error); } } catch (WaoBusinessException eee) { - layout.getFeedBack().addError(eee.getMessage()); + layout.addError(eee.getMessage()); } } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/UserProfile.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/UserProfile.java 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/UserProfile.java 2010-03-26 18:26:03 UTC (rev 393) @@ -96,7 +96,7 @@ userEditable.setPasswordChanged(true); } serviceUser.createUpdateUser(userEditable, false); - layout.getFeedBack().addInfo("Modifications enregistrées avec succès !"); + layout.addInfo("Modifications enregistrées avec succès !"); } catch (WaoBusinessException eee) { userForm.recordError(eee.getMessage()); // if (log.isErrorEnabled()) { 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-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/Layout.tml 2010-03-26 18:26:03 UTC (rev 393) @@ -72,8 +72,8 @@ </ul> <div id="${contentId}"> - <t:feedback t:id="contentFeedback" /> - <t:if t:test="canShowPage()"> + <t:feedback t:id="contentFeedback" t:autoClear="false"/> + <t:if t:test="displayBody()"> <t:body /> </t:if> </div> Modified: trunk/wao-ui/src/main/webapp/SampleRowForm.tml =================================================================== --- trunk/wao-ui/src/main/webapp/SampleRowForm.tml 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/webapp/SampleRowForm.tml 2010-03-26 18:26:03 UTC (rev 393) @@ -171,7 +171,7 @@ </fieldset> <fieldset class="clearfix"> <t:errors t:banner="message:errors-banner"/> - <p><label>Enregistrement fait par : </label>${sampleRowLog.admin.fullName}</p> + <p><label>Enregistrement fait par : </label>${sampleRowLog.author.fullName}</p> <t:unless t:test="createMode"> <p><label>Commentaire sur la modification* :</label></p> <p><input t:type="textarea" t:id="updateComment" cols="50" rows="5" value="sampleRowLog.comment"/></p> Modified: trunk/wao-ui/src/main/webapp/SampleRowHistoric.tml =================================================================== --- trunk/wao-ui/src/main/webapp/SampleRowHistoric.tml 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/webapp/SampleRowHistoric.tml 2010-03-26 18:26:03 UTC (rev 393) @@ -4,14 +4,35 @@ <h1>Historique de la ligne ${sampleRow.code}</h1> <p class="aright">créée le <t:output t:format="dateFormat" t:value="sampleRow.topiaCreateDate"/></p> <hr /> + <t:if t:test="canAddComment()"> + <form t:type="form" t:id="addComment" class="comment-form" action="post"> + <fieldset> + <legend>Ajouter un commentaire</legend> + <t:feedback t:id="addCommentInfo" /> + <p>Auteur : ${newLog.author.fullName}</p> + <p><label t:type="label" for="newComment">Commentaire</label> :</p> + <p> + <textarea t:type="textarea" t:id="newComment" t:value="newLog.comment" cols="90" rows="3" t:validate="required"> + ${newLog.comment} + </textarea> + </p> + <p class="aright"><input type="submit" t:type="submit" class="ico save" value="Save" title="Ajouter un nouveau commentaire" /></p> + </fieldset> + </form> + </t:if> <div class="so-samplerow-log" t:type="loop" t:source="sampleRow.sampleRowLog" t:value="sampleRowLog"> - <p class="head"> - Modification du + <p class="head-${sampleRowLog.author.userRole.name()}"> + <t:if t:test="sampleRowLog.author.admin"> + Modification du + <p:else>Commentaire ajouté le</p:else> + </t:if> <strong><t:output t:format="dateFormat" t:value="sampleRowLog.topiaCreateDate"/></strong> - par <strong>${sampleRowLog.admin.fullName}</strong> + par <strong>${sampleRowLog.author.fullName}</strong> </p> - <p class="content"><t:outputraw value="content"/></p> - <p>Commentaire : </p> + <t:if t:test="sampleRowLog.logText"> + <p class="content"><t:outputraw value="content"/></p> + <p>Commentaire : </p> + </t:if> <p class="comment"> ${sampleRowLog.comment} </p> Modified: trunk/wao-ui/src/main/webapp/SamplingPlan.tml =================================================================== --- trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/webapp/SamplingPlan.tml 2010-03-26 18:26:03 UTC (rev 393) @@ -170,13 +170,13 @@ <img src="${asset:context:}/img/boat-unavailable-22px.png" alt="Navire impossible" title="Accès aux navires impossible, ligne terminée"/> </p:else> </t:if> + <a t:type="pagelink" t:page="sampleRowHistoric" t:context="row.code"> + <img src="${asset:context:}/img/clock-22px.png" alt="Historique" title="Voir historique de la ligne"/> + </a> <t:if t:test="user.admin"> <a t:type="pagelink" t:page="sampleRowForm" t:context="row.topiaId"> <img src="${asset:context:}/img/edit.png" alt="Modifier" title="Modifier la ligne"/> </a> - <a t:type="pagelink" t:page="sampleRowHistoric" t:context="row.topiaId"> - <img src="${asset:context:}/img/clock-22px.png" alt="Historique" title="Voir historique de la ligne"/> - </a> <t:unless t:test="row.hasSampleMonthRealTideTime()"> <a t:type="actionlink" t:id="deleteSampleRow" t:context="rowIndex" title="Supprimer la ligne d'échantillon" t:mixins="confirm" t:message="Etes-vous sûr de vouloir supprimer définitivement la ligne ${row.code} du plan d\'échantillonnage ?"> Modified: trunk/wao-ui/src/main/webapp/css/sampling.css =================================================================== --- trunk/wao-ui/src/main/webapp/css/sampling.css 2010-03-25 18:18:36 UTC (rev 392) +++ trunk/wao-ui/src/main/webapp/css/sampling.css 2010-03-26 18:26:03 UTC (rev 393) @@ -242,7 +242,19 @@ text-align: center; } -div#so-samplerow-historic div.so-samplerow-log p.head { +div#so-samplerow-historic form.comment-form fieldset { + width: 50%; + margin-left: auto; + margin-right: auto; + padding: 10px; + margin-bottom: 10px; +} + +div#so-samplerow-historic div.so-samplerow-log p.head-COORDINATOR { + color: #19A28D; +} + +div#so-samplerow-historic div.so-samplerow-log p.head-ADMIN { color: #007CC2; }