[Suiviobsmer-commits] r113 - in trunk: . suiviobsmer-business suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl suiviobsmer-business/src/test/resources/import suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages suiviobsmer-ui/src/main/webapp suiviobsmer-ui/src/main/webapp/css
Author: fdesbois Date: 2009-12-08 13:08:53 +0000 (Tue, 08 Dec 2009) New Revision: 113 Added: trunk/suiviobsmer-business/changelog.txt Modified: trunk/README.txt trunk/changelog.txt trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java trunk/suiviobsmer-business/src/test/resources/import/echantillonnage.csv trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Contacts.properties trunk/suiviobsmer-ui/src/main/webapp/Boats.tml trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css Log: Minor corrections (see changelog) Modified: trunk/README.txt =================================================================== --- trunk/README.txt 2009-12-07 18:58:12 UTC (rev 112) +++ trunk/README.txt 2009-12-08 13:08:53 UTC (rev 113) @@ -7,5 +7,9 @@ ------------------ login = admin -passwor = password +password = password +Format des fichiers en CSV +-------------------------- + +Encodage UTF-8 obligatoire. Préconisation d'OpenOffice pour la sauvegarde des fichiers. Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2009-12-07 18:58:12 UTC (rev 112) +++ trunk/changelog.txt 2009-12-08 13:08:53 UTC (rev 113) @@ -1 +1,6 @@ +0.0.1-alpha-2 + - [08-12-2009] [desbois] ANO SamplingPlan : Caractère de fin manquant sur l'affichage des zones de pêche + - [08-12-2009] [desbois] EVO Contacts : Renommage colonne "Mammifères" en "Observations et captures accidentelles" + - [08-12-2009] [desbois] EVO BoatInfos : Renomage texte "... embarquements dont X dans votre société..." par "... embarquements dont X pour votre société..." + - [08-12-2009] [desbois] ANO BoatInfos : Lien présent pour la création d'un contact lorsque la ligne du plan est barré Added: trunk/suiviobsmer-business/changelog.txt =================================================================== --- trunk/suiviobsmer-business/changelog.txt (rev 0) +++ trunk/suiviobsmer-business/changelog.txt 2009-12-08 13:08:53 UTC (rev 113) @@ -0,0 +1 @@ + Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java 2009-12-07 18:58:12 UTC (rev 112) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java 2009-12-08 13:08:53 UTC (rev 113) @@ -327,6 +327,8 @@ public int[] importSamplingPlanCsv(InputStream input) throws SuiviObsmerException { TopiaContext transaction = null; int[] result = new int[3]; + int currRow = 0; + SampleRow row = null; try { transaction = rootContext.beginTransaction(); @@ -337,7 +339,6 @@ int nbImported = 0; int nbRefused = 0; - int currRow = 0; while(reader.readRecord()) { currRow++; @@ -356,7 +357,7 @@ int[] programEnd = getMonthAndYear(reader.get("PROGRAMME_FIN").trim()); String districts = reader.get("PECHE_DIVISION"); - SampleRow row = dao.findByCode(code); + row = dao.findByCode(code); // Refuse existing SampleRow if (row != null) { if (log.isInfoEnabled()) { @@ -403,10 +404,18 @@ result[0] = nbImported; result[1] = nbRefused; + } catch (NumberFormatException eee) { + SuiviObsmerUtils.serviceException(transaction, + "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "] : " + + "Le format de la durée moyenne des marées est incorrect, il doit être de la forme : 1.9 ", eee); + } catch (ParseException eee) { + SuiviObsmerUtils.serviceException(transaction, + "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "] : " + + "Le format des dates est incorrect, il doit être de la forme : MM/AAAA", eee); } catch (Exception eee) { SuiviObsmerUtils.serviceException(transaction, "Problème d'import du fichier CSV. Voir documentation pour plus de détails sur " + - "les en-têtes autorisés.", + "les en-têtes autorisés et le format des données.", eee); } return result; @@ -535,7 +544,9 @@ String fishingZoneInfos = reader.get("PECHE_AUTRE").trim(); int nbObservants = Integer.parseInt(reader.get("PLAN_NB_OBSERV").trim()); - double averageTideTime = Double.parseDouble(reader.get("PLAN_DUREE_MOY").trim()); + String averageStr = reader.get("PLAN_DUREE_MOY").trim(); + averageStr = averageStr.replaceAll(",", "."); + double averageTideTime = Double.parseDouble(averageStr); sampleRow.setFishingZonesInfos(fishingZoneInfos); sampleRow.setNbObservants(nbObservants); @@ -550,7 +561,7 @@ int lastMonthColumnId = firstMonthColumnId + nbTotalColumns - nbFixedColumns; for (int i = firstMonthColumnId; i < lastMonthColumnId; i++) { - + int[] monthAndYear = getMonthAndYear(reader.getHeader(i)); Integer monthValue = StringUtils.isEmpty(reader.get(i)) ? null : Integer.parseInt(reader.get(i)); Modified: trunk/suiviobsmer-business/src/test/resources/import/echantillonnage.csv =================================================================== --- trunk/suiviobsmer-business/src/test/resources/import/echantillonnage.csv 2009-12-07 18:58:12 UTC (rev 112) +++ trunk/suiviobsmer-business/src/test/resources/import/echantillonnage.csv 2009-12-08 13:08:53 UTC (rev 113) @@ -1,5 +1,5 @@ "PLAN_CODE","SOCIETE_NOM","PECHE_DIVISION","PECHE_AUTRE","METIER_CODE_DCF5","METIER_MAILLAGE","METIER_TAILLE","METIER_AUTRE","METIER_LIBELLE","METIER_ESPECES","PROGRAMME_CODE","PROGRAMME_DEBUT","PROGRAMME_FIN",12/2009,01/2010,02/2010,03/2010,04/2010,05/2010,06/2010,07/2010,08/2010,09/2010,10/2010,11/2010,12/2010,01/2011,02/2011,03/2011,"PLAN_DUREE_MOY","PLAN_NB_OBSERV","PLAN_COMMENT" -"2010_1",TARTANPION,"IId / I",,"DB_MOL",,,,,,"MA-2009",03/2010,01/2011,,,,0,0,0,0,0,0,0,2,0,0,4,,,"1.5",1, +"2010_1",TARTANPION,"IId / I",,"DB_MOL",,,,,,"MA-2009",03/2010,01/2011,,,,0,0,0,0,0,0,0,2,0,0,4,,,"1,5",1, "2010_2",,"IId",,"GTR_DEAEF et ANS_DEF",,,,"Fileyage","poissons tubes","MANY",01/2008,12/2008,,20,0,0,21,0,0,21,0,0,21,0,0,,,,1,1, "2010_3",,"IId / IV",,"ORM",,,,"balottage en plein air","divers choses visqueuses","MA-2009",03/2010,01/2011,,,,0,22,0,0,25,0,0,21,0,0,25,,,2,1, "2009_1",,"IId / IV",,"GTR_DEF et GNS_DEF","110-119",,,"Fileyage à poissons tubes","poissons plats","PPP2010",12/2009,10/2010,0,1,1,1,2,1,1,1,1,1,2,,,,,,1,1, Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2009-12-07 18:58:12 UTC (rev 112) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2009-12-08 13:08:53 UTC (rev 113) @@ -18,543 +18,544 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * ##%* */ - -package fr.ifremer.suiviobsmer.ui.pages; - -import fr.ifremer.suiviobsmer.SuiviObsmerException; -import fr.ifremer.suiviobsmer.bean.BoatFilterImpl; -import fr.ifremer.suiviobsmer.entity.Boat; -import fr.ifremer.suiviobsmer.entity.BoatInfos; -import fr.ifremer.suiviobsmer.bean.BoatFilter; -import fr.ifremer.suiviobsmer.bean.ElligibleBoatsCompany; -import fr.ifremer.suiviobsmer.entity.Company; -import fr.ifremer.suiviobsmer.entity.ElligibleBoat; -import fr.ifremer.suiviobsmer.entity.FishingZone; -import fr.ifremer.suiviobsmer.entity.Profession; -import fr.ifremer.suiviobsmer.entity.SampleRow; -import fr.ifremer.suiviobsmer.entity.User; -import fr.ifremer.suiviobsmer.services.ServiceBoat; -import fr.ifremer.suiviobsmer.services.ServiceReferential; -import fr.ifremer.suiviobsmer.services.ServiceSampling; -import fr.ifremer.suiviobsmer.services.ServiceUser; -import fr.ifremer.suiviobsmer.ui.base.BusinessUtils; -import fr.ifremer.suiviobsmer.ui.base.GenericSelectModel; -import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage; -import fr.ifremer.suiviobsmer.ui.components.Layout; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.Map; -import org.apache.commons.lang.BooleanUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.tapestry5.Block; -import org.apache.tapestry5.EventContext; -import org.apache.tapestry5.annotations.IncludeStylesheet; -import org.apache.tapestry5.annotations.InjectComponent; -import org.apache.tapestry5.annotations.InjectPage; -import org.apache.tapestry5.annotations.Log; -import org.apache.tapestry5.annotations.Persist; -import org.apache.tapestry5.annotations.Property; -import org.apache.tapestry5.annotations.SessionState; -import org.apache.tapestry5.corelib.components.Form; -import org.apache.tapestry5.corelib.components.Zone; -import org.apache.tapestry5.ioc.annotations.Inject; -import org.apache.tapestry5.ioc.services.PropertyAccess; -import org.apache.tapestry5.upload.services.UploadedFile; -import org.slf4j.Logger; - -/** - * Boats - * - * Created: 9 nov. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - at IncludeStylesheet("context:css/boats.css") -public class Boats implements SuiviObsmerPage { - - @Override - public boolean isOnlyForAdmin() { - return false; - } - - @Inject - private Logger log; - - @InjectComponent - private Layout layout; - - @SessionState - @Property - private User user; - - @Inject - private ServiceReferential serviceReferential; - - @Inject - private ServiceSampling serviceSampling; - - @Inject - private ServiceBoat serviceBoat; - - @Inject - private PropertyAccess propertyAccess; - - @Property - private String sampleRowCode; - - void setupRender() throws SuiviObsmerException { - sampleRow = null; - getSampleRow(); - professionSelectModel = null; - getProfessionSelectModel(); - fishingZoneSelectModel = null; - getFishingZoneSelectModel(); - sampleRowSelectModel = null; - getSampleRowSelectModel(); - - // Suppress persistant boat informations for selected boat - boatInfos = null; - elligibleSampleRows = null; - if (isSampleRowExists()) { - filtersHidden = false; - boats = null; - professionId = getSampleRow().getProfession().getTopiaId(); - fishingZoneId = getSampleRow().getFirstFishingZone().getTopiaId(); - getBoatFilter().setSampleRowCode(getSampleRow().getCode()); - } - } - -// public User getUser() { -// return layout.getCurrentUser(); -// } - - void onActivate(EventContext ec) { - if (ec.getCount() > 0) { - sampleRowCode = ec.get(String.class, 0); - } - } - - String onPassivate() { - return sampleRowCode; - } - - /**************************** Import Form ******************************************/ - - /** - * Fichier CSV contenant une liste de navires. - */ - @Property - private UploadedFile boatsCsvFile; - - @InjectComponent - private Form importBoatsForm; - - /** - * Récupération des exceptions du champs d'upload de fichier. - */ - /*Object onUploadException(FileUploadException ex) { - createListForm.recordError("Upload exception: " + ex.getMessage()); - return this; - }*/ - - @Log - void onSuccessFromImportBoatsForm() { - //importBoatsForm.clearErrors(); - try { - 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"); - } catch (SuiviObsmerException eee) { - layout.getFeedBack().addError(eee.getMessage()); - } - //return importBoatsForm.getHasErrors() ? importBoatsForm : this; - } - - /**************************** Filters Form *****************************************/ - - @Persist - private BoatFilter boatFilter; - - @Persist - private SampleRow sampleRow; - - @Persist - private GenericSelectModel<SampleRow> sampleRowSelectModel; - - @Persist - private GenericSelectModel<Profession> professionSelectModel; - - @Property - private String professionId; - - @Persist - private GenericSelectModel<FishingZone> fishingZoneSelectModel; - - @Property - private String fishingZoneId; - - @Persist - private boolean filtersHidden; - - @InjectComponent - private Zone filtersZone; - - public BoatFilter getBoatFilter() throws SuiviObsmerException { - if (boatFilter == null) { - boatFilter = new BoatFilterImpl(); - if (log.isDebugEnabled()) { - log.debug("new BoatFilter"); - } - if (!user.getAdmin()) { - if (log.isDebugEnabled()) { - log.debug("set company for boatFilter"); - } - boatFilter.setCompany(user.getCompany()); - } - } - return boatFilter; - } - - public SampleRow getSampleRow() throws SuiviObsmerException { - if (sampleRow == null && !StringUtils.isEmpty(sampleRowCode)) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getSampleRow]"); - } - sampleRow = serviceSampling.getSampleRow(sampleRowCode); - } - return sampleRow; - } - - public boolean isSampleRowExists() throws SuiviObsmerException { - return getSampleRow() != null; - } - - public GenericSelectModel<SampleRow> getSampleRowSelectModel() throws SuiviObsmerException { - if (sampleRowSelectModel == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getSampleRowsForUser]"); - } - /*List<OptionModel> options = new ArrayList<OptionModel>(); - for (String code : serviceSampling.getSampleRowCodesForUser(getUser())) { - options.add(new OptionModelImpl(code,code)); - } - sampleRowSelectModel = new SelectModelImpl(null, options);*/ - List<SampleRow> sampleRows = serviceSampling.getSampleRowsForUser(user); - sampleRowSelectModel = new GenericSelectModel<SampleRow>(sampleRows, SampleRow.class, - "code", "code", propertyAccess); - } - return sampleRowSelectModel; - } - - public GenericSelectModel<Profession> getProfessionSelectModel() throws SuiviObsmerException { - if (professionSelectModel == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getProfessions]"); - } - List<Profession> professions = serviceReferential.getProfessions(); - professionSelectModel = new GenericSelectModel<Profession>(professions, Profession.class, - "code", "topiaId", propertyAccess); - } - return professionSelectModel; - } - - public GenericSelectModel<FishingZone> getFishingZoneSelectModel() throws SuiviObsmerException { - if (fishingZoneSelectModel == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getFishingZones]"); - } - List<FishingZone> fishingZones = null; - if (isSampleRowExists()) { - fishingZones = getSampleRow().getFishingZone(); - } else { - fishingZones = serviceReferential.getFishingZones(); - } - fishingZoneSelectModel = new GenericSelectModel<FishingZone>(fishingZones, FishingZone.class, - "code", "topiaId", propertyAccess); - } - return fishingZoneSelectModel; - } - - public boolean isFiltersHidden() { - return filtersHidden; - } - - public String getHiddenClass() { - return isFiltersHidden() ? "hidden" : ""; - } - - Block onActionFromShowFilters() { - filtersHidden = false; - return filtersZone.getBody(); - } - - Block onActionFromHideFilters() { - filtersHidden = true; - return filtersZone.getBody(); - } - - void onSelectedFromReset() { - // Suppress persistant boat filter - boatFilter = null; - } - - void onSelectedFromSearch() throws SuiviObsmerException { - if (log.isDebugEnabled()) { - //log.debug("SUBMIT : facadeChange=" + facadeChangeSelected); - log.debug("FILTER : fishingZone=" + boatFilter.getFishingZone()); - log.debug("FILTER : sampleRowCode=" + boatFilter.getSampleRowCode()); - log.debug("FILTER : profession=" + boatFilter.getProfession()); - log.debug("FILTER : boatName=" + boatFilter.getBoatName()); - log.debug("FILTER : boatImmatriculation=" + boatFilter.getBoatImmatriculation()); - log.debug("FILTER : boatDistrictCode=" + boatFilter.getBoatDistrictCode()); - log.debug("FILTER : company=" + boatFilter.getCompany()); - } - Profession profession = getProfessionSelectModel().findObject(professionId); - FishingZone fishingZone = getFishingZoneSelectModel().findObject(fishingZoneId); - boatFilter.setProfession(profession); - boatFilter.setFishingZone(fishingZone); - } - - void onSuccessFromFiltersForm() throws SuiviObsmerException { - // Suppress persistant boats list to get new one with filter - boats = null; - // Suppress persistant immatriculation for boat selected - boatSelectedImmatriculation = null; - // Suppress persistant boat informations for boat selected - boatInfos = null; - elligibleSampleRows = null; - } - - /**************************** Boats List *****************************************/ - - @Persist - private Map<Integer, Boat> boats; - - @Property - private Integer boatSelectedImmatriculation; - - @Property - private Boat boat; - - private boolean even = true; - - @InjectComponent - private Zone boatsZone; - - public Map<Integer, Boat> getBoats() throws SuiviObsmerException { - if (boats == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getBoatsByFilter]"); - } - boats = serviceBoat.getBoatsByFilter(boatFilter); - } - return boats; - } - - public String getRowClass() { - String result = ""; - even = !even; - if (boatSelectedImmatriculation != null && - boat.getImmatriculation() == boatSelectedImmatriculation) { - result = "selected"; - } else if (!boat.getActive()) { - result = "refused"; - } else { - result = even ? "even" : "odd"; - } - return result; - } - - public DateFormat getDateFormat() { - return new SimpleDateFormat("dd/MM/yyyy"); - } - - Block onActionFromShowBoatInfos(Integer boatImma) { - boatSelectedImmatriculation = boatImma; - // Suppress persistant boat informations - boatInfos = null; - elligibleSampleRows = null; - return boatsZone.getBody(); - } - - /**************************** Boat selected Infos *************************/ - - @Persist - private BoatInfos boatInfos; - - @Persist - private ElligibleBoatsCompany elligibleSampleRows; - - @InjectComponent - private Zone boatInfosZone; - - @Inject - private Block displayBoatInfos; - - @Inject - private Block editBoatInfos; - - /** - * Current element for professionLibelles loop - */ - @Property - private ElligibleBoat elligibleBoat; - - @Property - private String boatInfosSampleRowCode; - - private boolean boatInfosEditable; - - @Inject - private ServiceUser serviceUser; - - private GenericSelectModel<Company> companySelectModel; - - @Property - private String companyId; - - /*@Persist - private SuiviObsmerPropertyChangeListener propertyChange;*/ - - public Block getActiveBoatInfosBlock() { - if (boatInfosEditable) { - return editBoatInfos; - } - return displayBoatInfos; - } - - public BoatInfos getBoatInfos() throws SuiviObsmerException { - if (boatInfos == null && boatSelectedImmatriculation != null) { - Boat selectedBoat = getBoats().get(boatSelectedImmatriculation); - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [boat.getBoatInfos]"); - log.info("BUSINESS REQUEST [getElligibleBoats]"); - } - boatInfos = selectedBoat.getBoatInfos(getCompany()); - elligibleSampleRows = - serviceBoat.getElligibleBoats(boatSelectedImmatriculation, getCompany()); - } - return boatInfos; - } - - public ElligibleBoatsCompany getElligibleSampleRows() throws SuiviObsmerException { -// if (elligibleSampleRows == null && boatSelectedImmatriculation != null) { -// Boat selectedBoat = getBoats().get(boatSelectedImmatriculation); -// if (log.isInfoEnabled()) { -// -// } -// } - return elligibleSampleRows; - } - - public String getElligibleRowInfos() { - return BusinessUtils.getTooltipSampleRow(elligibleBoat.getSampleRow()); - } - - public boolean isElligibleBoatCompanyActiveFalse() { - return BooleanUtils.isFalse(elligibleBoat.getCompanyActive()); - } - - public String getElligibleRowClass() { - boolean condition1 = elligibleBoat.getCompanyActive() == null && !elligibleBoat.getGlobalActive(); - - return condition1 || isElligibleBoatCompanyActiveFalse() ? "line-through" : ""; - } - - public Company getCompany() throws SuiviObsmerException { - if (user.getAdmin() && companyId != null) { - return getCompanySelectModel().findObject(companyId); - } - return user.getCompany(); - } - - public GenericSelectModel<Company> getCompanySelectModel() throws SuiviObsmerException { - if (companySelectModel == null) { - if (log.isDebugEnabled()) { - log.debug("BUSINESS REQUEST [getCompanies]"); - } - List<Company> companies = serviceUser.getCompanies(); - companySelectModel = new GenericSelectModel<Company>(companies,Company.class, - "name","topiaId",propertyAccess); - } - return companySelectModel; - } - - Block onSuccessFromCompanySelectForm() { - return boatInfosZone.getBody(); - } - - Block onActionFromEditBoatInfos() { - boatInfosEditable = true; - return boatInfosZone.getBody(); - } - - Block onActionFromCancelEditBoatInfos() throws SuiviObsmerException { - /*if (propertyChange.isChanged()) { - if (log.isDebugEnabled()) { - log.debug("Change property"); - } - }*/ - // Set boatSelectedImmatriculation for boatInfos to reinitialize it (next getBoatInfos() call) - boatSelectedImmatriculation = getBoatInfos().getBoat().getImmatriculation(); - // Suppress boatInfos to get the one from serviceBoat (not updated yet) - boatInfos = null; - return boatInfosZone.getBody(); - } - - void onSelectedFromAddBoatInfosSampleRow() throws SuiviObsmerException { - // We stay in edition mode - boatInfosEditable = true; - if (!StringUtils.isEmpty(boatInfosSampleRowCode)) { - SampleRow row = getSampleRowSelectModel().findObject(boatInfosSampleRowCode); - elligibleSampleRows.setNewElement(row); - } - } - - void onSelectedFromRemoveBoatInfosSampleRow(String sampleRowCode) throws SuiviObsmerException { - boatInfosEditable = true; - elligibleSampleRows.removeElement(sampleRowCode); - } - - void onSelectedFromActiveBoatInfosSampleRow(String sampleRowCode) throws SuiviObsmerException { - boatInfosEditable = true; - elligibleSampleRows.activeElement(sampleRowCode); - } - - Block onSuccessFromBoatInfosForm() throws SuiviObsmerException { - if (!boatInfosEditable) { - // Save data - serviceBoat.createUpdateBoatInfos(boatInfos, elligibleSampleRows); - } - return boatInfosZone.getBody(); - } - - /**************************** Create new contact **************************/ - - @InjectPage - private Contacts contacts; - - Object onActionFromAddNewContactFromBoat(int boatImmatriculation) throws SuiviObsmerException { - // Get selected sampleRow - sampleRow = getSampleRow(); - // Get boat from list - boat = getBoats().get(boatImmatriculation); - contacts.createNewContact(boat, sampleRow); - return contacts; - } - - Object onActionFromAddNewContactFromSampleRow(String sampleRowCode) throws SuiviObsmerException { - // Get selected boat from BoatInfos - boat = getBoatInfos().getBoat(); - // Get sampleRow from elligibleBoat list - sampleRow = getSampleRowSelectModel().findObject(sampleRowCode); - contacts.createNewContact(boat, sampleRow); - return contacts; - } -} + +package fr.ifremer.suiviobsmer.ui.pages; + +import fr.ifremer.suiviobsmer.SuiviObsmerException; +import fr.ifremer.suiviobsmer.bean.BoatFilterImpl; +import fr.ifremer.suiviobsmer.entity.Boat; +import fr.ifremer.suiviobsmer.entity.BoatInfos; +import fr.ifremer.suiviobsmer.bean.BoatFilter; +import fr.ifremer.suiviobsmer.bean.ElligibleBoatsCompany; +import fr.ifremer.suiviobsmer.entity.Company; +import fr.ifremer.suiviobsmer.entity.ElligibleBoat; +import fr.ifremer.suiviobsmer.entity.FishingZone; +import fr.ifremer.suiviobsmer.entity.Profession; +import fr.ifremer.suiviobsmer.entity.SampleRow; +import fr.ifremer.suiviobsmer.entity.User; +import fr.ifremer.suiviobsmer.services.ServiceBoat; +import fr.ifremer.suiviobsmer.services.ServiceReferential; +import fr.ifremer.suiviobsmer.services.ServiceSampling; +import fr.ifremer.suiviobsmer.services.ServiceUser; +import fr.ifremer.suiviobsmer.ui.base.BusinessUtils; +import fr.ifremer.suiviobsmer.ui.base.GenericSelectModel; +import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage; +import fr.ifremer.suiviobsmer.ui.components.Layout; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Map; +import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.tapestry5.Block; +import org.apache.tapestry5.EventContext; +import org.apache.tapestry5.annotations.IncludeStylesheet; +import org.apache.tapestry5.annotations.InjectComponent; +import org.apache.tapestry5.annotations.InjectPage; +import org.apache.tapestry5.annotations.Log; +import org.apache.tapestry5.annotations.Persist; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.annotations.SessionState; +import org.apache.tapestry5.corelib.components.Form; +import org.apache.tapestry5.corelib.components.Zone; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.ioc.services.PropertyAccess; +import org.apache.tapestry5.upload.services.UploadedFile; +import org.slf4j.Logger; + +/** + * Boats + * + * Created: 9 nov. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + at IncludeStylesheet("context:css/boats.css") +public class Boats implements SuiviObsmerPage { + + @Override + public boolean isOnlyForAdmin() { + return false; + } + + @Inject + private Logger log; + + @InjectComponent + private Layout layout; + + @SessionState + @Property + private User user; + + @Inject + private ServiceReferential serviceReferential; + + @Inject + private ServiceSampling serviceSampling; + + @Inject + private ServiceBoat serviceBoat; + + @Inject + private PropertyAccess propertyAccess; + + @Property + private String sampleRowCode; + + void setupRender() throws SuiviObsmerException { + sampleRow = null; + getSampleRow(); + professionSelectModel = null; + getProfessionSelectModel(); + fishingZoneSelectModel = null; + getFishingZoneSelectModel(); + sampleRowSelectModel = null; + getSampleRowSelectModel(); + + // Suppress persistant boat informations for selected boat + boatInfos = null; + elligibleSampleRows = null; + if (isSampleRowExists()) { + filtersHidden = false; + boats = null; + professionId = getSampleRow().getProfession().getTopiaId(); + fishingZoneId = getSampleRow().getFirstFishingZone().getTopiaId(); + getBoatFilter().setSampleRowCode(getSampleRow().getCode()); + } + } + +// public User getUser() { +// return layout.getCurrentUser(); +// } + + void onActivate(EventContext ec) { + if (ec.getCount() > 0) { + sampleRowCode = ec.get(String.class, 0); + } + } + + String onPassivate() { + return sampleRowCode; + } + + /**************************** Import Form ******************************************/ + + /** + * Fichier CSV contenant une liste de navires. + */ + @Property + private UploadedFile boatsCsvFile; + + @InjectComponent + private Form importBoatsForm; + + /** + * Récupération des exceptions du champs d'upload de fichier. + */ + /*Object onUploadException(FileUploadException ex) { + createListForm.recordError("Upload exception: " + ex.getMessage()); + return this; + }*/ + + @Log + void onSuccessFromImportBoatsForm() { + //importBoatsForm.clearErrors(); + try { + 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"); + } catch (SuiviObsmerException eee) { + layout.getFeedBack().addError(eee.getMessage()); + } + //return importBoatsForm.getHasErrors() ? importBoatsForm : this; + } + + /**************************** Filters Form *****************************************/ + + @Persist + private BoatFilter boatFilter; + + @Persist + private SampleRow sampleRow; + + @Persist + private GenericSelectModel<SampleRow> sampleRowSelectModel; + + @Persist + private GenericSelectModel<Profession> professionSelectModel; + + @Property + private String professionId; + + @Persist + private GenericSelectModel<FishingZone> fishingZoneSelectModel; + + @Property + private String fishingZoneId; + + @Persist + private boolean filtersHidden; + + @InjectComponent + private Zone filtersZone; + + public BoatFilter getBoatFilter() throws SuiviObsmerException { + if (boatFilter == null) { + boatFilter = new BoatFilterImpl(); + if (log.isDebugEnabled()) { + log.debug("new BoatFilter"); + } + if (!user.getAdmin()) { + if (log.isDebugEnabled()) { + log.debug("set company for boatFilter"); + } + boatFilter.setCompany(user.getCompany()); + } + } + return boatFilter; + } + + public SampleRow getSampleRow() throws SuiviObsmerException { + if (sampleRow == null && !StringUtils.isEmpty(sampleRowCode)) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getSampleRow]"); + } + sampleRow = serviceSampling.getSampleRow(sampleRowCode); + } + return sampleRow; + } + + public boolean isSampleRowExists() throws SuiviObsmerException { + return getSampleRow() != null; + } + + public GenericSelectModel<SampleRow> getSampleRowSelectModel() throws SuiviObsmerException { + if (sampleRowSelectModel == null) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getSampleRowsForUser]"); + } + /*List<OptionModel> options = new ArrayList<OptionModel>(); + for (String code : serviceSampling.getSampleRowCodesForUser(getUser())) { + options.add(new OptionModelImpl(code,code)); + } + sampleRowSelectModel = new SelectModelImpl(null, options);*/ + List<SampleRow> sampleRows = serviceSampling.getSampleRowsForUser(user); + sampleRowSelectModel = new GenericSelectModel<SampleRow>(sampleRows, SampleRow.class, + "code", "code", propertyAccess); + } + return sampleRowSelectModel; + } + + public GenericSelectModel<Profession> getProfessionSelectModel() throws SuiviObsmerException { + if (professionSelectModel == null) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getProfessions]"); + } + List<Profession> professions = serviceReferential.getProfessions(); + professionSelectModel = new GenericSelectModel<Profession>(professions, Profession.class, + "code", "topiaId", propertyAccess); + } + return professionSelectModel; + } + + public GenericSelectModel<FishingZone> getFishingZoneSelectModel() throws SuiviObsmerException { + if (fishingZoneSelectModel == null) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getFishingZones]"); + } + List<FishingZone> fishingZones = null; + if (isSampleRowExists()) { + fishingZones = getSampleRow().getFishingZone(); + } else { + fishingZones = serviceReferential.getFishingZones(); + } + fishingZoneSelectModel = new GenericSelectModel<FishingZone>(fishingZones, FishingZone.class, + "code", "topiaId", propertyAccess); + } + return fishingZoneSelectModel; + } + + public boolean isFiltersHidden() { + return filtersHidden; + } + + public String getHiddenClass() { + return isFiltersHidden() ? "hidden" : ""; + } + + Block onActionFromShowFilters() { + filtersHidden = false; + return filtersZone.getBody(); + } + + Block onActionFromHideFilters() { + filtersHidden = true; + return filtersZone.getBody(); + } + + void onSelectedFromReset() { + // Suppress persistant boat filter + boatFilter = null; + sampleRowCode = null; + } + + void onSelectedFromSearch() throws SuiviObsmerException { + if (log.isDebugEnabled()) { + //log.debug("SUBMIT : facadeChange=" + facadeChangeSelected); + log.debug("FILTER : fishingZone=" + boatFilter.getFishingZone()); + log.debug("FILTER : sampleRowCode=" + boatFilter.getSampleRowCode()); + log.debug("FILTER : profession=" + boatFilter.getProfession()); + log.debug("FILTER : boatName=" + boatFilter.getBoatName()); + log.debug("FILTER : boatImmatriculation=" + boatFilter.getBoatImmatriculation()); + log.debug("FILTER : boatDistrictCode=" + boatFilter.getBoatDistrictCode()); + log.debug("FILTER : company=" + boatFilter.getCompany()); + } + Profession profession = getProfessionSelectModel().findObject(professionId); + FishingZone fishingZone = getFishingZoneSelectModel().findObject(fishingZoneId); + boatFilter.setProfession(profession); + boatFilter.setFishingZone(fishingZone); + } + + void onSuccessFromFiltersForm() throws SuiviObsmerException { + // Suppress persistant boats list to get new one with filter + boats = null; + // Suppress persistant immatriculation for boat selected + boatSelectedImmatriculation = null; + // Suppress persistant boat informations for boat selected + boatInfos = null; + elligibleSampleRows = null; + } + + /**************************** Boats List *****************************************/ + + @Persist + private Map<Integer, Boat> boats; + + @Property + private Integer boatSelectedImmatriculation; + + @Property + private Boat boat; + + private boolean even = true; + + @InjectComponent + private Zone boatsZone; + + public Map<Integer, Boat> getBoats() throws SuiviObsmerException { + if (boats == null) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getBoatsByFilter]"); + } + boats = serviceBoat.getBoatsByFilter(boatFilter); + } + return boats; + } + + public String getRowClass() { + String result = ""; + even = !even; + if (boatSelectedImmatriculation != null && + boat.getImmatriculation() == boatSelectedImmatriculation) { + result = "selected"; + } else if (!boat.getActive()) { + result = "refused"; + } else { + result = even ? "even" : "odd"; + } + return result; + } + + public DateFormat getDateFormat() { + return new SimpleDateFormat("dd/MM/yyyy"); + } + + Block onActionFromShowBoatInfos(Integer boatImma) { + boatSelectedImmatriculation = boatImma; + // Suppress persistant boat informations + boatInfos = null; + elligibleSampleRows = null; + return boatsZone.getBody(); + } + + /**************************** Boat selected Infos *************************/ + + @Persist + private BoatInfos boatInfos; + + @Persist + private ElligibleBoatsCompany elligibleSampleRows; + + @InjectComponent + private Zone boatInfosZone; + + @Inject + private Block displayBoatInfos; + + @Inject + private Block editBoatInfos; + + /** + * Current element for professionLibelles loop + */ + @Property + private ElligibleBoat elligibleBoat; + + @Property + private String boatInfosSampleRowCode; + + private boolean boatInfosEditable; + + @Inject + private ServiceUser serviceUser; + + private GenericSelectModel<Company> companySelectModel; + + @Property + private String companyId; + + /*@Persist + private SuiviObsmerPropertyChangeListener propertyChange;*/ + + public Block getActiveBoatInfosBlock() { + if (boatInfosEditable) { + return editBoatInfos; + } + return displayBoatInfos; + } + + public BoatInfos getBoatInfos() throws SuiviObsmerException { + if (boatInfos == null && boatSelectedImmatriculation != null) { + Boat selectedBoat = getBoats().get(boatSelectedImmatriculation); + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [boat.getBoatInfos]"); + log.info("BUSINESS REQUEST [getElligibleBoats]"); + } + boatInfos = selectedBoat.getBoatInfos(getCompany()); + elligibleSampleRows = + serviceBoat.getElligibleBoats(boatSelectedImmatriculation, getCompany()); + } + return boatInfos; + } + + public ElligibleBoatsCompany getElligibleSampleRows() throws SuiviObsmerException { +// if (elligibleSampleRows == null && boatSelectedImmatriculation != null) { +// Boat selectedBoat = getBoats().get(boatSelectedImmatriculation); +// if (log.isInfoEnabled()) { +// +// } +// } + return elligibleSampleRows; + } + + public String getElligibleRowInfos() { + return BusinessUtils.getTooltipSampleRow(elligibleBoat.getSampleRow()); + } + + public boolean isElligibleBoatCompanyActiveFalse() { + return BooleanUtils.isFalse(elligibleBoat.getCompanyActive()); + } + + public String getElligibleRowClass() { + boolean condition1 = elligibleBoat.getCompanyActive() == null && !elligibleBoat.getGlobalActive(); + + return condition1 || isElligibleBoatCompanyActiveFalse() ? "line-through" : ""; + } + + public Company getCompany() throws SuiviObsmerException { + if (user.getAdmin() && companyId != null) { + return getCompanySelectModel().findObject(companyId); + } + return user.getCompany(); + } + + public GenericSelectModel<Company> getCompanySelectModel() throws SuiviObsmerException { + if (companySelectModel == null) { + if (log.isDebugEnabled()) { + log.debug("BUSINESS REQUEST [getCompanies]"); + } + List<Company> companies = serviceUser.getCompanies(); + companySelectModel = new GenericSelectModel<Company>(companies,Company.class, + "name","topiaId",propertyAccess); + } + return companySelectModel; + } + + Block onSuccessFromCompanySelectForm() { + return boatInfosZone.getBody(); + } + + Block onActionFromEditBoatInfos() { + boatInfosEditable = true; + return boatInfosZone.getBody(); + } + + Block onActionFromCancelEditBoatInfos() throws SuiviObsmerException { + /*if (propertyChange.isChanged()) { + if (log.isDebugEnabled()) { + log.debug("Change property"); + } + }*/ + // Set boatSelectedImmatriculation for boatInfos to reinitialize it (next getBoatInfos() call) + boatSelectedImmatriculation = getBoatInfos().getBoat().getImmatriculation(); + // Suppress boatInfos to get the one from serviceBoat (not updated yet) + boatInfos = null; + return boatInfosZone.getBody(); + } + + void onSelectedFromAddBoatInfosSampleRow() throws SuiviObsmerException { + // We stay in edition mode + boatInfosEditable = true; + if (!StringUtils.isEmpty(boatInfosSampleRowCode)) { + SampleRow row = getSampleRowSelectModel().findObject(boatInfosSampleRowCode); + elligibleSampleRows.setNewElement(row); + } + } + + void onSelectedFromRemoveBoatInfosSampleRow(String sampleRowCode) throws SuiviObsmerException { + boatInfosEditable = true; + elligibleSampleRows.removeElement(sampleRowCode); + } + + void onSelectedFromActiveBoatInfosSampleRow(String sampleRowCode) throws SuiviObsmerException { + boatInfosEditable = true; + elligibleSampleRows.activeElement(sampleRowCode); + } + + Block onSuccessFromBoatInfosForm() throws SuiviObsmerException { + if (!boatInfosEditable) { + // Save data + serviceBoat.createUpdateBoatInfos(boatInfos, elligibleSampleRows); + } + return boatInfosZone.getBody(); + } + + /**************************** Create new contact **************************/ + + @InjectPage + private Contacts contacts; + + Object onActionFromAddNewContactFromBoat(int boatImmatriculation) throws SuiviObsmerException { + // Get selected sampleRow + sampleRow = getSampleRow(); + // Get boat from list + boat = getBoats().get(boatImmatriculation); + contacts.createNewContact(boat, sampleRow); + return contacts; + } + + Object onActionFromAddNewContactFromSampleRow(String sampleRowCode) throws SuiviObsmerException { + // Get selected boat from BoatInfos + boat = getBoatInfos().getBoat(); + // Get sampleRow from elligibleBoat list + sampleRow = getSampleRowSelectModel().findObject(sampleRowCode); + contacts.createNewContact(boat, sampleRow); + return contacts; + } +} Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java 2009-12-07 18:58:12 UTC (rev 112) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java 2009-12-08 13:08:53 UTC (rev 113) @@ -18,318 +18,318 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * ##%* */ - -package fr.ifremer.suiviobsmer.ui.pages; - - -import fr.ifremer.suiviobsmer.SuiviObsmerException; -import fr.ifremer.suiviobsmer.entity.Company; -import fr.ifremer.suiviobsmer.entity.FishingZone; -import fr.ifremer.suiviobsmer.entity.SampleMonth; -import fr.ifremer.suiviobsmer.entity.SampleRow; -import fr.ifremer.suiviobsmer.entity.User; -import fr.ifremer.suiviobsmer.services.ServiceSampling; -import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage; -import fr.ifremer.suiviobsmer.ui.components.Layout; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import org.apache.tapestry5.annotations.IncludeStylesheet; -import org.apache.tapestry5.annotations.InjectComponent; -import org.apache.tapestry5.annotations.Log; -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.apache.tapestry5.upload.services.UploadedFile; -import fr.ifremer.suiviobsmer.PeriodDates; -import org.slf4j.Logger; - -/** - * SampingPlan - * - * Created: 9 nov. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - at IncludeStylesheet("context:css/sampling.css") -public class SamplingPlan implements SuiviObsmerPage { - - @Override - public boolean isOnlyForAdmin() { - return false; - } - - @Inject - private Logger log; - - @Inject - private ServiceSampling serviceSampling; - - @InjectComponent - private Layout layout; - - @SessionState - @Property - private User user; - - /** - * Page initialization - */ - void setupRender() { - periodBegin = getPeriod().getFromDate(); - periodEnd = getPeriod().getThruDate(); - } - - /** - * Get current user from Layout component - * @return current user - */ -// public User getUser() { -// return layout.getCurrentUser(); -// } - - /**************************** IMPORT (ADMIN) *******************************/ - - /** - * Fichier CSV contenant un plan d'échantillonnage - */ - @Property - private UploadedFile samplingPlanCsvFile; - - @Log - void onSuccessFromImportSamplingPlan() { - try { - int[] result = serviceSampling.importSamplingPlanCsv(samplingPlanCsvFile.getStream()); - layout.getFeedBack().addInfo(result[0] + " lignes du plan importés, " + - result[1] + " refusés (voir documentation)"); - } catch (SuiviObsmerException eee) { - layout.getFeedBack().addError(eee.getMessage()); - } - } - - /**************************** PERIOD SELECTION *****************************/ - - @Persist - private PeriodDates period; - - @Property - private Date periodBegin; - - @Property - private Date periodEnd; - - public PeriodDates getPeriod() { - if (period == null) { - period = PeriodDates.createMonthsPeriodFromToday(11); - } - return period; - } - - void onSuccessFromPeriodForm() { - if (periodBegin != null && periodEnd != null) { - period.setFromDate(periodBegin); - period.setThruDate(periodEnd); - } - } - - /**************************** MAIN TABLE ***********************************/ - - /** ------------------------- DATA -------------------------------------- **/ - - /** - * Main data for samplingPlan : List of SampleRow ordered by FishingZone. - */ - private List<SampleRow> data; - - private List<Date> months; - - @Property - private Date month; - - /** - * Current SampleRow from loop - */ - @Property - private SampleRow row; - - @Property - private String currentFacadeName; - - @Property - private String currentSectorName; - - /** - * Return List of SampleRow from suiviobsmer-business - * @return List of SampleRow - * @throws SuiviObsmerException - */ - public List<SampleRow> getData() throws SuiviObsmerException { - if (data == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getSampleRowsOrderedByFishingZone]"); - } - Company company = null; - if (!user.getAdmin()) { - company = user.getCompany(); - } - data = serviceSampling.getSampleRowsOrderedByFishingZone( - getPeriod().getFromDate(), getPeriod().getThruDate(), company); - } - return data; - } - - public List<Date> getMonths() { - if (months == null) { - months = getPeriod().getMonths(); - } - return months; - } - - public boolean isFacadeChanged() { - FishingZone zone = row.getFirstFishingZone(); - if (!zone.getFacadeName().equals(currentFacadeName)) { - currentFacadeName = zone.getFacadeName(); - return true; - } - return false; - } - - public boolean isSectorChanged() { - FishingZone zone = row.getFirstFishingZone(); - if (!zone.getSectorName().equals(currentSectorName)) { - currentSectorName = zone.getSectorName(); - return true; - } - return false; - } - - public String getCompanyName() { - return row.getCompany() != null ? row.getCompany().getName() : ""; - } - - public boolean isCurrentMonth() { - String currentStr = getDateFormat().format(new Date()); - String monthStr = getDateFormat().format(month); - return currentStr.equals(monthStr); - } - - public Integer getNbTidesExpected() { - SampleMonth sampleMonth = row.getSampleMonth(month); - if (sampleMonth != null) { - return sampleMonth.getExpectedTidesValue(); - } - return null; - } - - public String getFishingZones() { - String result = ""; - for (FishingZone zone : row.getFishingZone()) { - result += zone.getDistrictCode() + ", "; - } - return result.substring(0, result.length()-3); - } - - public Integer getNbTidesReal() { - SampleMonth sampleMonth = row.getSampleMonth(month); - if (sampleMonth != null) { - return sampleMonth.getRealTidesValue(); - } - return null; - } - - public boolean hasNbTidesReal() { - // test with current month ???? - Date current = new Date(); - return month.before(current) && !isCurrentMonth() && getNbTidesReal() != null; - } - - public int getTotalTidesExpected() { - int total = 0; - for (Date currentMonth : getMonths()) { - SampleMonth sampleMonth = row.getSampleMonth(currentMonth); - if (sampleMonth != null) { - total += sampleMonth.getExpectedTidesValue(); - } - } - return total; - } - - public int getTotalTidesReal() { - int total = 0; - for (Date currentMonth : getMonths()) { - SampleMonth sampleMonth = row.getSampleMonth(currentMonth); - if (sampleMonth != null) { - total += sampleMonth.getRealTidesValue(); - } - } - return total; - } - - /** ------------------------- HTML & STYLE ------------------------------ **/ - - @Property - private int rowIndex; - - public int getNbColumnsForProfession() { - // code, program.name, fishingZone.districts, profession.code, profession.libelle - int fixed = 5; - if (user.getAdmin()) { - // company, program.periodBegin, program.periodEnd, fishingZonesInfos - // profession.meshSize, profession.size, profession.other, profession.species - fixed += 8; - } - return fixed; - } - - public int getNbColumnsForMonths() { - return getMonths().size() + 1; - } - - public int getNbColumnsForOther() { - return 3; - } - - public int getNbColumnsTotal() { - return getNbColumnsForProfession() + - getNbColumnsForMonths() + getNbColumnsForOther(); - } - - public String getMainClass() { - return user.getAdmin() ? "admin" : "user"; - } - - public String getParityClass() { - return rowIndex % 2 == 0 ? "even" : "odd"; - } - - public String getActionsClass() { - return user.getAdmin() ? "width70" : "width30"; - } - - public String getRealTidesClass() { - String result = "real-warning"; - if (getNbTidesReal() < getNbTidesExpected()) { - result += "-inf"; - } else if (getNbTidesReal() > getNbTidesExpected()) { - result += "-sup"; - } - return result; - } - - public String getMonthCurrentClass() { - return isCurrentMonth() ? "current" : ""; - } - - public DateFormat getDateFormat() { - return new SimpleDateFormat("MM/yyyy"); - } - - /** ------------------------- ACTIONS ----------------------------------- **/ - -} + +package fr.ifremer.suiviobsmer.ui.pages; + + +import fr.ifremer.suiviobsmer.SuiviObsmerException; +import fr.ifremer.suiviobsmer.entity.Company; +import fr.ifremer.suiviobsmer.entity.FishingZone; +import fr.ifremer.suiviobsmer.entity.SampleMonth; +import fr.ifremer.suiviobsmer.entity.SampleRow; +import fr.ifremer.suiviobsmer.entity.User; +import fr.ifremer.suiviobsmer.services.ServiceSampling; +import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage; +import fr.ifremer.suiviobsmer.ui.components.Layout; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import org.apache.tapestry5.annotations.IncludeStylesheet; +import org.apache.tapestry5.annotations.InjectComponent; +import org.apache.tapestry5.annotations.Log; +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.apache.tapestry5.upload.services.UploadedFile; +import fr.ifremer.suiviobsmer.PeriodDates; +import org.slf4j.Logger; + +/** + * SampingPlan + * + * Created: 9 nov. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + at IncludeStylesheet("context:css/sampling.css") +public class SamplingPlan implements SuiviObsmerPage { + + @Override + public boolean isOnlyForAdmin() { + return false; + } + + @Inject + private Logger log; + + @Inject + private ServiceSampling serviceSampling; + + @InjectComponent + private Layout layout; + + @SessionState + @Property + private User user; + + /** + * Page initialization + */ + void setupRender() { + periodBegin = getPeriod().getFromDate(); + periodEnd = getPeriod().getThruDate(); + } + + /** + * Get current user from Layout component + * @return current user + */ +// public User getUser() { +// return layout.getCurrentUser(); +// } + + /**************************** IMPORT (ADMIN) *******************************/ + + /** + * Fichier CSV contenant un plan d'échantillonnage + */ + @Property + private UploadedFile samplingPlanCsvFile; + + @Log + void onSuccessFromImportSamplingPlan() { + try { + int[] result = serviceSampling.importSamplingPlanCsv(samplingPlanCsvFile.getStream()); + layout.getFeedBack().addInfo(result[0] + " lignes du plan importés, " + + result[1] + " refusés (voir documentation)"); + } catch (SuiviObsmerException eee) { + layout.getFeedBack().addError(eee.getMessage()); + } + } + + /**************************** PERIOD SELECTION *****************************/ + + @Persist + private PeriodDates period; + + @Property + private Date periodBegin; + + @Property + private Date periodEnd; + + public PeriodDates getPeriod() { + if (period == null) { + period = PeriodDates.createMonthsPeriodFromToday(11); + } + return period; + } + + void onSuccessFromPeriodForm() { + if (periodBegin != null && periodEnd != null) { + period.setFromDate(periodBegin); + period.setThruDate(periodEnd); + } + } + + /**************************** MAIN TABLE ***********************************/ + + /** ------------------------- DATA -------------------------------------- **/ + + /** + * Main data for samplingPlan : List of SampleRow ordered by FishingZone. + */ + private List<SampleRow> data; + + private List<Date> months; + + @Property + private Date month; + + /** + * Current SampleRow from loop + */ + @Property + private SampleRow row; + + @Property + private String currentFacadeName; + + @Property + private String currentSectorName; + + /** + * Return List of SampleRow from suiviobsmer-business + * @return List of SampleRow + * @throws SuiviObsmerException + */ + public List<SampleRow> getData() throws SuiviObsmerException { + if (data == null) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getSampleRowsOrderedByFishingZone]"); + } + Company company = null; + if (!user.getAdmin()) { + company = user.getCompany(); + } + data = serviceSampling.getSampleRowsOrderedByFishingZone( + getPeriod().getFromDate(), getPeriod().getThruDate(), company); + } + return data; + } + + public List<Date> getMonths() { + if (months == null) { + months = getPeriod().getMonths(); + } + return months; + } + + public boolean isFacadeChanged() { + FishingZone zone = row.getFirstFishingZone(); + if (!zone.getFacadeName().equals(currentFacadeName)) { + currentFacadeName = zone.getFacadeName(); + return true; + } + return false; + } + + public boolean isSectorChanged() { + FishingZone zone = row.getFirstFishingZone(); + if (!zone.getSectorName().equals(currentSectorName)) { + currentSectorName = zone.getSectorName(); + return true; + } + return false; + } + + public String getCompanyName() { + return row.getCompany() != null ? row.getCompany().getName() : ""; + } + + public boolean isCurrentMonth() { + String currentStr = getDateFormat().format(new Date()); + String monthStr = getDateFormat().format(month); + return currentStr.equals(monthStr); + } + + public Integer getNbTidesExpected() { + SampleMonth sampleMonth = row.getSampleMonth(month); + if (sampleMonth != null) { + return sampleMonth.getExpectedTidesValue(); + } + return null; + } + + public String getFishingZones() { + String result = ""; + for (FishingZone zone : row.getFishingZone()) { + result += zone.getDistrictCode() + ", "; + } + return result.substring(0, result.length()-2); + } + + public Integer getNbTidesReal() { + SampleMonth sampleMonth = row.getSampleMonth(month); + if (sampleMonth != null) { + return sampleMonth.getRealTidesValue(); + } + return null; + } + + public boolean hasNbTidesReal() { + // test with current month ???? + Date current = new Date(); + return month.before(current) && !isCurrentMonth() && getNbTidesReal() != null; + } + + public int getTotalTidesExpected() { + int total = 0; + for (Date currentMonth : getMonths()) { + SampleMonth sampleMonth = row.getSampleMonth(currentMonth); + if (sampleMonth != null) { + total += sampleMonth.getExpectedTidesValue(); + } + } + return total; + } + + public int getTotalTidesReal() { + int total = 0; + for (Date currentMonth : getMonths()) { + SampleMonth sampleMonth = row.getSampleMonth(currentMonth); + if (sampleMonth != null) { + total += sampleMonth.getRealTidesValue(); + } + } + return total; + } + + /** ------------------------- HTML & STYLE ------------------------------ **/ + + @Property + private int rowIndex; + + public int getNbColumnsForProfession() { + // code, program.name, fishingZone.districts, profession.code, profession.libelle + int fixed = 5; + if (user.getAdmin()) { + // company, program.periodBegin, program.periodEnd, fishingZonesInfos + // profession.meshSize, profession.size, profession.other, profession.species + fixed += 8; + } + return fixed; + } + + public int getNbColumnsForMonths() { + return getMonths().size() + 1; + } + + public int getNbColumnsForOther() { + return 3; + } + + public int getNbColumnsTotal() { + return getNbColumnsForProfession() + + getNbColumnsForMonths() + getNbColumnsForOther(); + } + + public String getMainClass() { + return user.getAdmin() ? "admin" : "user"; + } + + public String getParityClass() { + return rowIndex % 2 == 0 ? "even" : "odd"; + } + + public String getActionsClass() { + return user.getAdmin() ? "width70" : "width30"; + } + + public String getRealTidesClass() { + String result = "real-warning"; + if (getNbTidesReal() < getNbTidesExpected()) { + result += "-inf"; + } else if (getNbTidesReal() > getNbTidesExpected()) { + result += "-sup"; + } + return result; + } + + public String getMonthCurrentClass() { + return isCurrentMonth() ? "current" : ""; + } + + public DateFormat getDateFormat() { + return new SimpleDateFormat("MM/yyyy"); + } + + /** ------------------------- ACTIONS ----------------------------------- **/ + +} Modified: trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Contacts.properties =================================================================== --- trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Contacts.properties 2009-12-07 18:58:12 UTC (rev 112) +++ trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Contacts.properties 2009-12-08 13:08:53 UTC (rev 113) @@ -16,6 +16,6 @@ boatName-label: Navire boatImmatriculation-label: N\u00B0 boatDistrictCode-label: CQ -mammals-label: Mammif\u00E8res +mammals-label: Observations et captures accidentelles dataInputDate-label: Saisie des donn\u00E9es dans Allegro comment-label: Commentaire Modified: trunk/suiviobsmer-ui/src/main/webapp/Boats.tml =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2009-12-07 18:58:12 UTC (rev 112) +++ trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2009-12-08 13:08:53 UTC (rev 113) @@ -145,7 +145,7 @@ <p class="sep"> </p> <p> <strong>${boatInfos.nbBoarding}</strong> embarquements - dont <strong>${boatInfos.nbBoardingForCompany}</strong> dans votre société + dont <strong>${boatInfos.nbBoardingForCompany}</strong> pour votre société depuis le <strong><t:output value="boatInfos.firstBoardingDate" format="dateFormat" /></strong> </p> <p class="sep"> </p> @@ -157,9 +157,11 @@ ${elligibleBoat.sampleRow.code} </span> </span> - <a t:type="actionlink" t:id="addNewContactFromSampleRow" t:context="elligibleBoat.sampleRow.code"> - <img src="${asset:context:}/img/contact-22px.png" title="Créer un nouveau contact pour ce navire et cette ligne du plan"/> - </a> + <t:unless t:test="elligibleBoatCompanyActiveFalse"> + <a t:type="actionlink" t:id="addNewContactFromSampleRow" t:context="elligibleBoat.sampleRow.code"> + <img src="${asset:context:}/img/contact-22px.png" title="Créer un nouveau contact pour ce navire et cette ligne du plan"/> + </a> + </t:unless> </li> </ul> <t:if t:test="boatInfos.comment"> Modified: trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css 2009-12-07 18:58:12 UTC (rev 112) +++ trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css 2009-12-08 13:08:53 UTC (rev 113) @@ -61,6 +61,10 @@ text-align: center; } +div#so-contacts table.t-data-grid thead tr th.mammals { + white-space: normal; +} + div#so-contacts table.t-data-grid thead tr th.actions { width: 90px; }
participants (1)
-
fdesbois@users.labs.libre-entreprise.org