Author: fdesbois Date: 2010-06-18 13:39:46 +0000 (Fri, 18 Jun 2010) New Revision: 550 Log: - Evo #2332 : Add display text for validation comments - Remove BusinessUtils, use WaoManager instead Removed: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/BusinessUtils.java 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/Contacts.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java trunk/wao-ui/src/main/webapp/Contacts.tml Deleted: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/BusinessUtils.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/BusinessUtils.java 2010-06-18 13:11:09 UTC (rev 549) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/BusinessUtils.java 2010-06-18 13:39:46 UTC (rev 550) @@ -1,161 +0,0 @@ -/* - * #%L - * Wao :: Web Interface - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2009 - 2010 Ifremer - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package fr.ifremer.wao.ui.data; - -import fr.ifremer.wao.bean.ContactState; -import fr.ifremer.wao.bean.SamplingFilter; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.Contact; -import fr.ifremer.wao.entity.FishingZone; -import fr.ifremer.wao.entity.Profession; -import fr.ifremer.wao.entity.SampleRow; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import org.apache.commons.lang.BooleanUtils; -import org.apache.commons.lang.StringUtils; - -/** - * DataUtils - * - * Created: 3 déc. 2009 - * - * @author fdesbois <fdesbois at codelutin.com> - */ -public class BusinessUtils { - - - public static String getTooltipSampleRow(SampleRow row) { - StringBuilder result = new StringBuilder(); - DateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); - Profession profession = row.getProfession(); - result.append("<strong>Métier : </strong>"). - append(profession.getCodeDCF5()); - if (!StringUtils.isEmpty(profession.getMeshSize())) { - result.append(' ').append(profession.getMeshSize()); - } - if (!StringUtils.isEmpty(profession.getSize())) { - result.append(' ').append(profession.getSize()); - } - if (!StringUtils.isEmpty(profession.getOther())) { - result.append(' ').append(profession.getOther()); - } - result.append(" - ").append(profession.getLibelle()); - if (!StringUtils.isEmpty(profession.getSpecies())) { - result.append("<br /><strong>Espèces cibles : </strong>"). - append(profession.getSpecies()); - } - result.append("<br /><strong>Programme : </strong>"). - append(row.getProgramName()). - append("<br /><strong>Période : </strong> du "). - append(dateFormat.format(row.getPeriodBegin())).append(" au "). - append(dateFormat.format(row.getPeriodEnd())); - - for (FishingZone zone : row.getFishingZone()) { - result.append("<br /><strong>Zone de pêche : </strong>"). - append(zone.getCode()); - } - - return result.toString(); - } - - public static String getTooltipBoat(Boat boat) { - StringBuilder result = new StringBuilder("<strong>"). - append(boat.getImmatriculation()).append("</strong>"). - append("<br /><strong>Quartier : </strong>"). - append(boat.getDistrictCode()). - append("<br /><strong>Longueur : </strong>"). - append(boat.getBoatLength()).append(" m"). - append("<br /><strong>Année de construction : </strong>"). - append(boat.getBuildYear()); - return result.toString(); - } - - public static String getDataSamplingTitle(SamplingFilter filter) { - StringBuilder result = new StringBuilder("Données des marées"); - String separator = " : "; - if (filter.getCompany() != null) { - //result.append(!filtered ? " : " : ", "; - result.append(separator). - append("\nSociété ").append(filter.getCompany().getName()); - separator = ", "; - } - if (StringUtils.isNotEmpty(filter.getProgramName())) { - result.append(separator). - append("\nProgramme ").append(filter.getProgramName()); - separator = ", "; - } - if (filter.getSampleRow() != null) { - Profession profession = filter.getSampleRow().getProfession(); - result.append(separator). - append("\nMétier ").append(profession.getCode()); - if (StringUtils.isNotEmpty(profession.getLibelle())) { - result.append(" - ").append(profession.getLibelle()); - } - if (StringUtils.isNotEmpty(profession.getSpecies())) { - result.append("\nEspèces ("). - append(profession.getSpecies()).append(")"); - } - result.append("\nZones de pêche ("); - for (FishingZone zone : filter.getSampleRow().getFishingZone()) { - result.append(zone.getDistrictCode()).append(' '); - } - result.append(")"); - separator = ", "; - } else { - if (filter.getFacadeName() != null) { - result.append(separator). - append("\nFaçade ").append(filter.getFacadeName()); - separator = ", "; - } - if (filter.getSectorName() != null) { - result.append(separator). - append("\nZone ").append(filter.getSectorName()); - } - } - return result.toString(); - } - - public static String getContactStyle(Contact contact, boolean admin) { - String result = ""; - boolean accepted = BooleanUtils.isTrue(contact.getValidationProgram()) || - (!admin && BooleanUtils.isTrue(contact.getValidationCompany())); - - ContactState state = contact.getContactState(); - if (BooleanUtils.isFalse(contact.getValidationProgram()) || - (!admin && BooleanUtils.isFalse(contact.getValidationCompany()))) { - result = "refused"; - } else if (accepted && state.equals(ContactState.BOARDING_DONE)) { - result = "accepted"; - } else if (accepted && state.isUnfinishedState()) { - result = "unfinished"; - } else if (state.isFinalState()) { - result = "even"; - } else { - result = "odd"; - } - return result; - } -} 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-06-18 13:11:09 UTC (rev 549) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Boats.java 2010-06-18 13:39:46 UTC (rev 550) @@ -48,7 +48,6 @@ import fr.ifremer.wao.ui.components.FeedBack; import fr.ifremer.wao.ui.components.Layout; import fr.ifremer.wao.ui.data.BoatDataSource; -import fr.ifremer.wao.ui.data.BusinessUtils; import fr.ifremer.wao.ui.data.ExportStreamResponse; import fr.ifremer.wao.ui.data.GenericSelectModel; import fr.ifremer.wao.ui.data.RequiresAuthentication; @@ -722,17 +721,17 @@ * * @return the CSS style to apply on contact block * @throws WaoException - * @see BusinessUtils#getContactStyle(Contact, boolean) + * @see WaoManager#getContactStyle(Contact, boolean) */ public String getlastContactStyle() throws WaoException { Contact contact = getCompanyBoatInfos().getLastContact(); - return BusinessUtils.getContactStyle(contact, user.isAdmin()); + return manager.getContactStyle(contact, user.isAdmin()); } /** /////////////////////// FOR EACH ELLIGIBLEBOAT ROW ///////////////// **/ public String getElligibleRowInfos() { - return BusinessUtils.getTooltipSampleRow(elligibleBoat.getSampleRow()); + return manager.getTooltipSampleRow(elligibleBoat.getSampleRow()); } public boolean isElligibleBoatCompanyActiveFalse() { 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-06-18 13:11:09 UTC (rev 549) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-06-18 13:39:46 UTC (rev 550) @@ -345,23 +345,23 @@ return userSelectModel; } - public String getCommentDisplayed() { - if (contact.getComment() != null && contact.getComment().length() > 20) { - return contact.getComment().substring(0, 20) + "..."; + public String getCommentDisplayText(String comment) { + if (comment != null && comment.length() > 20) { + return comment.substring(0, 20) + "..."; } - return contact.getComment(); + return comment; } - public String getCommentTooltip() { - return contact.getComment().replaceAll("\n", "<br />").replaceAll("\r", ""); + public String getCommentTooltip(String comment) { + return manager.getTooltipText(comment); } public String getSampleRowDescription() { - return BusinessUtils.getTooltipSampleRow(contact.getSampleRow()); + return manager.getTooltipSampleRow(contact.getSampleRow()); } public String getBoatDescription() { - return BusinessUtils.getTooltipBoat(contact.getBoat()); + return manager.getTooltipBoat(contact.getBoat()); } public String getTooltipExportFrom() throws WaoException { @@ -376,7 +376,7 @@ } public String getRowClass() { - String result = BusinessUtils.getContactStyle(contact, user.isAdmin()); + String result = manager.getContactStyle(contact, user.isAdmin()); if (contact.getTopiaId().equals(contactSelectedId)) { result = "selected"; } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2010-06-18 13:11:09 UTC (rev 549) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Synthesis.java 2010-06-18 13:39:46 UTC (rev 550) @@ -37,11 +37,11 @@ import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.service.ServiceSynthesis; import fr.ifremer.wao.ui.base.AbstractFilteredPage; -import fr.ifremer.wao.ui.data.BusinessUtils; import fr.ifremer.wao.ui.data.ChartUtils; import fr.ifremer.wao.ui.data.ChartUtils.ChartType; import fr.ifremer.wao.ui.data.RequiresAuthentication; import fr.ifremer.wao.ui.data.SynthesisId; +import fr.ifremer.wao.ui.services.WaoManager; import org.apache.commons.collections.CollectionUtils; import org.apache.tapestry5.Block; import org.apache.tapestry5.ComponentResources; @@ -78,6 +78,9 @@ @RequiresAuthentication({UserRole.ADMIN, UserRole.COORDINATOR, UserRole.OBSERVER}) @IncludeStylesheet("context:css/synthesis.css") public class Synthesis extends AbstractFilteredPage { + + @Inject + private WaoManager manager; @Inject private ServiceSynthesis serviceSynthesis; @@ -201,7 +204,7 @@ String realText = getFilter().getEstimatedTides() ? "Estimé" : "Réalisé"; data.put(realText, res.get(1)); - String title = BusinessUtils.getDataSamplingTitle(getFilter()); + String title = manager.getDataSamplingTitle(getFilter()); return ChartUtils.createCategoryChart(title, "Nb marées", "Mois", getDataSamplingChartType(), data); } Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2010-06-18 13:11:09 UTC (rev 549) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2010-06-18 13:39:46 UTC (rev 550) @@ -29,8 +29,21 @@ import fr.ifremer.wao.WaoContext; import fr.ifremer.wao.WaoException; import fr.ifremer.wao.WaoProperty; +import fr.ifremer.wao.bean.ContactState; +import fr.ifremer.wao.bean.SamplingFilter; +import fr.ifremer.wao.entity.Boat; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.Profession; +import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.service.ServiceUser; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.Date; + +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; import org.apache.tapestry5.ioc.Messages; import org.apache.tapestry5.ioc.services.RegistryShutdownListener; import org.nuiton.util.ApplicationConfig; @@ -157,6 +170,126 @@ return eee.getMessage(); } + public String getTooltipText(String input) { + if (input != null) { + return input.replaceAll("\n", "<br />").replaceAll("\r", ""); + } + return ""; + } + + + public String getTooltipSampleRow(SampleRow row) { + StringBuilder result = new StringBuilder(); + DateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); + Profession profession = row.getProfession(); + result.append("<strong>Métier : </strong>"). + append(profession.getCodeDCF5()); + if (!StringUtils.isEmpty(profession.getMeshSize())) { + result.append(' ').append(profession.getMeshSize()); + } + if (!StringUtils.isEmpty(profession.getSize())) { + result.append(' ').append(profession.getSize()); + } + if (!StringUtils.isEmpty(profession.getOther())) { + result.append(' ').append(profession.getOther()); + } + result.append(" - ").append(profession.getLibelle()); + if (!StringUtils.isEmpty(profession.getSpecies())) { + result.append("\n<strong>Espèces cibles : </strong>"). + append(profession.getSpecies()); + } + result.append("\n<strong>Programme : </strong>"). + append(row.getProgramName()). + append("\n<strong>Période : </strong> du "). + append(dateFormat.format(row.getPeriodBegin())).append(" au "). + append(dateFormat.format(row.getPeriodEnd())); + + for (FishingZone zone : row.getFishingZone()) { + result.append("\n<strong>Zone de pêche : </strong>"). + append(zone.getCode()); + } + + return getTooltipText(result.toString()); + } + + public String getTooltipBoat(Boat boat) { + StringBuilder result = new StringBuilder("<strong>"). + append(boat.getImmatriculation()).append("</strong>"). + append("\n<strong>Quartier : </strong>"). + append(boat.getDistrictCode()). + append("\n<strong>Longueur : </strong>"). + append(boat.getBoatLength()).append(" m"). + append("\n<strong>Année de construction : </strong>"). + append(boat.getBuildYear()); + return getTooltipText(result.toString()); + } + + public String getDataSamplingTitle(SamplingFilter filter) { + StringBuilder result = new StringBuilder("Données des marées"); + String separator = " : "; + if (filter.getCompany() != null) { + //result.append(!filtered ? " : " : ", "; + result.append(separator). + append("\nSociété ").append(filter.getCompany().getName()); + separator = ", "; + } + if (StringUtils.isNotEmpty(filter.getProgramName())) { + result.append(separator). + append("\nProgramme ").append(filter.getProgramName()); + separator = ", "; + } + if (filter.getSampleRow() != null) { + Profession profession = filter.getSampleRow().getProfession(); + result.append(separator). + append("\nMétier ").append(profession.getCode()); + if (StringUtils.isNotEmpty(profession.getLibelle())) { + result.append(" - ").append(profession.getLibelle()); + } + if (StringUtils.isNotEmpty(profession.getSpecies())) { + result.append("\nEspèces ("). + append(profession.getSpecies()).append(")"); + } + result.append("\nZones de pêche ("); + for (FishingZone zone : filter.getSampleRow().getFishingZone()) { + result.append(zone.getDistrictCode()).append(' '); + } + result.append(")"); + separator = ", "; + } else { + if (filter.getFacadeName() != null) { + result.append(separator). + append("\nFaçade ").append(filter.getFacadeName()); + separator = ", "; + } + if (filter.getSectorName() != null) { + result.append(separator). + append("\nZone ").append(filter.getSectorName()); + } + } + return result.toString(); + } + + public String getContactStyle(Contact contact, boolean admin) { + String result = ""; + boolean accepted = BooleanUtils.isTrue(contact.getValidationProgram()) || + (!admin && BooleanUtils.isTrue(contact.getValidationCompany())); + + ContactState state = contact.getContactState(); + if (BooleanUtils.isFalse(contact.getValidationProgram()) || + (!admin && BooleanUtils.isFalse(contact.getValidationCompany()))) { + result = "refused"; + } else if (accepted && state.equals(ContactState.BOARDING_DONE)) { + result = "accepted"; + } else if (accepted && state.isUnfinishedState()) { + result = "unfinished"; + } else if (state.isFinalState()) { + result = "even"; + } else { + result = "odd"; + } + return result; + } + } Modified: trunk/wao-ui/src/main/webapp/Contacts.tml =================================================================== --- trunk/wao-ui/src/main/webapp/Contacts.tml 2010-06-18 13:11:09 UTC (rev 549) +++ trunk/wao-ui/src/main/webapp/Contacts.tml 2010-06-18 13:39:46 UTC (rev 550) @@ -273,13 +273,23 @@ <p:else> <t:if t:test="contact.comment"> - <span t:type="ck/Tooltip" title="Commentaire" t:value="prop:commentTooltip" t:effect="appear"> - ${commentDisplayed} + <span t:type="ck/Tooltip" title="Commentaire" t:value="${getCommentTooltip(contact.comment)}" t:effect="appear"> + ${getCommentDisplayText(contact.comment)} </span> </t:if> </p:else> </t:if> </p:commentCell> + <p:commentCoordinatorCell> + <span t:type="ck/Tooltip" title="Commentaire société" t:value="${getCommentTooltip(contact.commentCoordinator)}" t:effect="appear"> + ${getCommentDisplayText(contact.commentCoordinator)} + </span> + </p:commentCoordinatorCell> + <p:commentAdminCell> + <span t:type="ck/Tooltip" title="Commentaire admin" t:value="${getCommentTooltip(contact.commentAdmin)}" t:effect="appear"> + ${getCommentDisplayText(contact.commentAdmin)} + </span> + </p:commentAdminCell> <p:actionsCell> <t:if t:test="hasActions()"> <t:if t:test="editionMode">