Author: fdesbois Date: 2010-01-24 19:30:15 +0000 (Sun, 24 Jan 2010) New Revision: 264 Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImpl.java trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.properties trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/BoatImplTest.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/BoatInfosImplTest.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImplTest.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/base/AbstractFilteredPage.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/BoatDataSource.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/ContactDataSource.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java trunk/suiviobsmer-ui/src/main/webapp/Boats.tml trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css Log: - Debug boatInfos managment - Change position of company filter + interpret company selected for facades and sectors in filters forms - Clean names in services + suppress deprecated fields in SampleMonth (problem with addRealTideTime resolved) - Other cleaning and javadoc fixes Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java 2010-01-24 19:30:15 UTC (rev 264) @@ -25,10 +25,9 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import java.io.Serializable; -import java.util.Calendar; -import java.util.GregorianCalendar; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import org.nuiton.topia.TopiaContext; -import org.nuiton.util.PeriodDates; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,61 +55,61 @@ // return period; // } - protected Calendar getCalendar() { - Calendar calendar = new GregorianCalendar(); - if (getPeriodDate() != null) { - calendar.setTime(getPeriodDate()); - } - return calendar; - } +// protected Calendar getCalendar() { +// Calendar calendar = new GregorianCalendar(); +// if (getPeriodDate() != null) { +// calendar.setTime(getPeriodDate()); +// } +// return calendar; +// } +// +// /** +// * @since 0.0.3 new attribute periodDate +// * @deprecated +// */ +// @Override +// @Deprecated +// public int getPeriodMonth() { +// return getCalendar().get(Calendar.MONTH) + 1; +// } +// +// /** +// * @since 0.0.3 new attribute periodDate +// * @deprecated +// */ +// @Override +// @Deprecated +// public int getPeriodYear() { +// return getCalendar().get(Calendar.YEAR); +// } +// +// /** +// * @since 0.0.3 new attribute periodDate +// * @param month +// * @deprecated +// */ +// @Override +// @Deprecated +// public void setPeriodMonth(int month) { +// Calendar calendar = getCalendar(); +// calendar.set(Calendar.MONTH, month - 1); +// setPeriodDate(calendar.getTime()); +// } +// +// /** +// * @since 0.0.3 new attribute periodDate +// * @param year +// * @deprecated +// */ +// @Override +// @Deprecated +// public void setPeriodYear(int year) { +// Calendar calendar = getCalendar(); +// calendar.set(Calendar.YEAR, year); +// setPeriodDate(calendar.getTime()); +// } /** - * @since 0.0.3 new attribute periodDate - * @deprecated - */ - @Override - @Deprecated - public int getPeriodMonth() { - return getCalendar().get(Calendar.MONTH) + 1; - } - - /** - * @since 0.0.3 new attribute periodDate - * @deprecated - */ - @Override - @Deprecated - public int getPeriodYear() { - return getCalendar().get(Calendar.YEAR); - } - - /** - * @since 0.0.3 new attribute periodDate - * @param month - * @deprecated - */ - @Override - @Deprecated - public void setPeriodMonth(int month) { - Calendar calendar = getCalendar(); - calendar.set(Calendar.MONTH, month - 1); - setPeriodDate(calendar.getTime()); - } - - /** - * @since 0.0.3 new attribute periodDate - * @param year - * @deprecated - */ - @Override - @Deprecated - public void setPeriodYear(int year) { - Calendar calendar = getCalendar(); - calendar.set(Calendar.YEAR, year); - setPeriodDate(calendar.getTime()); - } - - /** * Method could be use to add some time for realTidesValue or * remove time with a negative nbDays. * If nbDays is negative and superior to the current value, @@ -120,19 +119,20 @@ */ @Override public void addRealTideTime(int nbDays) throws SuiviObsmerException { - int result = getRealTidesValue() + nbDays; - if (result < 0) { - result = 0; - } TopiaContext transaction = null; try { transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); SampleMonthDAO dao = SuiviObsmerModelDAOHelper.getSampleMonthDAO(transaction); - SampleMonth month = dao.findByTopiaId(this.getTopiaId()); + SampleMonth month = dao.findByTopiaId(getTopiaId()); + int result = month.getRealTidesValue() + nbDays; + if (result < 0) { + result = 0; + } + month.setRealTidesValue(result); if (log.isDebugEnabled()) { - log.debug("Change realTideTime from " + getRealTidesValue() + " to " + result); + log.debug("Change realTideTime from " + month.getRealTidesValue() + " to " + result); } transaction.commitTransaction(); @@ -140,8 +140,14 @@ } catch (Exception eee) { SuiviObsmerContext.serviceException(transaction, "Impossible d'enregistrer le nombre de marées réels pour le mois de " + - this.getPeriodMonth() + "/" + this.getPeriodYear() + " [ligne : " + this.getSampleRow().getCode() + "]", eee); + formatMonth() + " [ligne : " + this.getSampleRow().getCode() + "]", eee); } } + @Override + public String formatMonth() { + DateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); + return dateFormat.format(getPeriodDate()); + } + } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java 2010-01-24 19:30:15 UTC (rev 264) @@ -24,6 +24,8 @@ import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.SuiviObsmerException; import java.io.Serializable; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -31,6 +33,7 @@ import java.util.Iterator; import java.util.List; import org.apache.commons.lang.BooleanUtils; +import org.nuiton.util.DateUtils; import org.nuiton.util.PeriodDates; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,12 +65,17 @@ if (getSampleMonth() == null) { return null; } - Calendar ref = new GregorianCalendar(); - ref.setTime(date); +// Calendar ref = new GregorianCalendar(); +// ref.setTime(date); //log.info("Ref : " + date); for (SampleMonth curr : getSampleMonth()) { //log.info("Curr month : " + curr.getPeriodDate() + " : " + curr.getPeriodMonth() + " / " + curr.getPeriodYear()); - if (ref.get(Calendar.MONTH) == (curr.getPeriodMonth()-1) && ref.get(Calendar.YEAR) == curr.getPeriodYear()) { +// if (ref.get(Calendar.MONTH) == (curr.getPeriodMonth()-1) && ref.get(Calendar.YEAR) == curr.getPeriodYear()) { +// return curr; +// } + Date min = DateUtils.setFirstDayOfMonth(curr.getPeriodDate()); + Date max = DateUtils.setLastDayOfMonth(curr.getPeriodDate()); + if (DateUtils.between(date, min, max)) { return curr; } } @@ -201,17 +209,20 @@ } @Override - public void addRealTideTime(Contact contact) throws SuiviObsmerException { + public boolean addRealTideTime(Contact contact) throws SuiviObsmerException { if (contact.getTideEndDate() == null || contact.getTideBeginDate() == null) { - return; + return false; } //int nbDays = contact.getTideNbDays(); //getDifferenceDays(contact); SampleMonth month = getSampleMonth(contact.getTideBeginDate()); - if (log.isTraceEnabled()) { - log.trace("Add 1 tide for " + - month.getPeriodMonth() + "/" + month.getPeriodYear() + " [" + this.getCode() + "]"); + if (month == null) { + return false; } + if (log.isTraceEnabled()) { + log.trace("Add 1 tide for " + month.formatMonth() + " [" + this.getCode() + "]"); + } month.addRealTideTime(1); + return true; } @Override @@ -222,8 +233,7 @@ //int nbDays = contact.getTideNbDays(); //getDifferenceDays(contact); SampleMonth month = getSampleMonth(contact.getTideBeginDate()); if (log.isTraceEnabled()) { - log.trace("Remove 1 tide for " + - month.getPeriodMonth() + "/" + month.getPeriodYear() + " [" + this.getCode() + "]"); + log.trace("Remove 1 tide for " + month.formatMonth() + " [" + this.getCode() + "]"); } month.addRealTideTime(-1); } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java 2010-01-24 19:30:15 UTC (rev 264) @@ -94,6 +94,8 @@ query.addOrder("B." + filter.getOrderBy()); } + query.addLoad(Boat.ACTIVITY_CALENDAR); + if (log.isDebugEnabled()) { log.debug("Query : " + query); } @@ -106,6 +108,27 @@ } return results; } + + @Override + public int getNbBoatsByFilter(BoatFilter filter) throws SuiviObsmerException { + TopiaContext transaction = null; + int result = 0; + try { + transaction = rootContext.beginTransaction(); + + BoatDAO dao = SuiviObsmerModelDAOHelper.getBoatDAO(transaction); + TopiaQuery<Boat> query = dao.createQuery("B"); + + query = createQueryForBoatFilter(query, filter); + + result = query.executeCount(); + + transaction.closeContext(); + } catch (Exception eee) { + SuiviObsmerContext.serviceException(transaction, "Impossible de filtrer la liste des navires", eee); + } + return result; + } protected TopiaQuery<Boat> createQueryForBoatFilter(TopiaQuery<Boat> query, BoatFilter filter) { String main = query.getMainAlias(); @@ -131,36 +154,18 @@ return query; } - @Override - public int countBoatsByFilter(BoatFilter filter) throws SuiviObsmerException { - TopiaContext transaction = null; - int result = 0; - try { - transaction = rootContext.beginTransaction(); - - BoatDAO dao = SuiviObsmerModelDAOHelper.getBoatDAO(transaction); - TopiaQuery<Boat> query = dao.createQuery("B"); - - query = createQueryForBoatFilter(query, filter); - - result = query.executeCount(); - - transaction.closeContext(); - } catch (Exception eee) { - SuiviObsmerContext.serviceException(transaction, "Impossible de filtrer la liste des navires", eee); - } - return result; - } - /** - * Get boat infos and elligible boats for a company and a boat. This method is useful to get sampleRows elligibles for - * the boat. Only sampleRows not closed linked with the company argument will be returned. - * The result give a Map with sampleRowCode in key and ElligibleBoat in value. The ElligibleBoat entity - * contains the SampleRow and attributes useful to know if the link is active or specific for the company. + * Get boat infos and elligible boats for a company and a boat. This method + * is useful to get sampleRows elligibles for the boat. Only sampleRows not + * closed linked with the company argument will be returned. The result give + * a Map with sampleRowCode in key and ElligibleBoat in value. + * The ElligibleBoat entity contains the SampleRow and attributes useful + * to know if the link is active or specific for the company. + * * @param boatImmatriculation immatriculation of the boat * @param company the Company to filter the ElligibleBoats - * @return an ElligibleBoatsCompany wich contains the map of ElligibleBoat, the company and an empty list for - * deleted elements + * @return an ElligibleBoatsCompany wich contains the map of ElligibleBoat, + * the company and an empty list for deleted elements. */ @Override public CompanyBoatInfos getCompanyBoatInfos(int boatImmatriculation, Company company) @@ -269,7 +274,7 @@ } @Override - public List<Boat> getBoats(String immatriculations) throws SuiviObsmerException { + public List<Boat> getBoatsByImmatriculations(String immatriculations) throws SuiviObsmerException { List<Boat> boats = new ArrayList<Boat>(); TopiaContext transaction = null; if (StringUtils.isEmpty(immatriculations)) { @@ -320,19 +325,22 @@ } @Override - public List<Boat> getAllBoats() throws SuiviObsmerException { + public List<String> getBoatNamesStartWith(String input) throws SuiviObsmerException { TopiaContext transaction = null; - List<Boat> results = new ArrayList<Boat>(); + List<String> results = new ArrayList<String>(); try { transaction = rootContext.beginTransaction(); + input = StringUtils.upperCase(input); + BoatDAO dao = SuiviObsmerModelDAOHelper.getBoatDAO(transaction); - results = dao.findAll(); + results = (List<String>)dao.createQuery().addDistinct().setSelect(Boat.NAME).add(Boat.NAME, Op.LIKE, input + "%").execute(); transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerContext.serviceException(transaction, "Unable to get all boats", eee); + SuiviObsmerContext.serviceException(transaction, + "Impossible de récupérer les navires avec un nom commencant par '" + input + "'", eee); } return results; } @@ -340,12 +348,13 @@ /** * Import boats from a CSV file. Warning, must be UTF-8 encoding. * Use of CsvReader to manage InputStream and create or update boats. - * Header file must be : NAVS_COD,CARN_NOM,CARN_LONGUEUR_HT,CARN_ANNEE,QUARTIER_IMMA,PER_COD, - * PER_NOM,PER_PRENOM. + * Header file must be : NAVS_COD,CARN_NOM,CARN_LONGUEUR_HT,CARN_ANNEE, + * QUARTIER_IMMA,PER_COD, PER_NOM,PER_PRENOM. * Existing boats (with same immatriculation) are updated. + * * @param input Stream corresponding to Csv file - * @return an array with two int : the first corresponding to total number of boats imported and - * the second corresponding only to new boats added. + * @return an array with two int : the first corresponding to total number + * of boats imported and the second corresponding only to new boats added. * @throws SuiviObsmerException * @see com.csvreader.CsvReader */ @@ -387,32 +396,9 @@ String activeStr = reader.get(BOAT.NAVS_ACTIVE.name()).trim(); boolean active = !activeStr.equals("I"); - - // Find existing boat with immatriculation - // - -// long tic1 = System.currentTimeMillis(); Boat boat = boatDAO.findByImmatriculation(immatriculation); -// long tic2 = System.currentTimeMillis(); -// if (log.isDebugEnabled()) { -// log.debug("findByImmatriculation : " + (tic2 - tic1)); -// } -// -// tic1 = System.currentTimeMillis(); -// Boat boat = QueryBuilder.getBoatByImmatriculation(transaction, immatriculation); -// tic2 = System.currentTimeMillis(); -// if (log.isDebugEnabled()) { -// log.debug("findByImmatriculation SQL : " + (tic2 - tic1)); -// } -// tic1 = System.currentTimeMillis(); - //Boat boat = new TopiaQuery(Boat.class).add(Boat.IMMATRICULATION, immatriculation).executeToEntity(transaction); -// tic2 = System.currentTimeMillis(); -// if (log.isDebugEnabled()) { -// log.debug("findByImmatriculation TopiaQuery : " + (tic2 - tic1)); -// } - if (boat == null) { boat = boatDAO.create(Boat.IMMATRICULATION, immatriculation); result[1]++; @@ -451,16 +437,6 @@ transaction.commitTransaction(); tic = ImportHelper.logTimeAndMemory(log, tic, "navires ligne " + result[0]); -// if (log.isInfoEnabled()) { -// log.info("RUNNING... Import navires ligne " + result[0]); -// Runtime runtime = Runtime.getRuntime(); -// long mem = (runtime.totalMemory() - runtime.freeMemory()) / 1048576; -// //long memMega = mem / 1024 / 1024; -// log.info("Memory : " + mem + " Mo"); -// tic2 = System.currentTimeMillis(); -// log.info("Time : " + DurationFormatUtils.formatDurationHMS(tic2 - tic1)); -// tic1 = System.currentTimeMillis(); -// } } } @@ -545,36 +521,9 @@ @Override public InputStream getActivityCalendarLogFile() throws FileNotFoundException { InputStream result = null; -// try { - String filename = - SuiviObsmerContext.getProperty(SuiviObsmerContext.PROP_FILENAME_LOG_ACTIVITY); - File file = new File(filename); - result = new FileInputStream(file); -// } catch (FileNotFoundException eee) { -// SuiviObsmerContext.serviceException(null, -// "Fichier de log inexistant", eee); -// } + String filename = SuiviObsmerContext.getProperty(SuiviObsmerContext.PROP_FILENAME_LOG_ACTIVITY); + File file = new File(filename); + result = new FileInputStream(file); return result; } - - @Override - public List<String> getBoatNamesStartWith(String input) throws SuiviObsmerException { - TopiaContext transaction = null; - List<String> results = new ArrayList<String>(); - try { - transaction = rootContext.beginTransaction(); - - input = StringUtils.upperCase(input); - - BoatDAO dao = SuiviObsmerModelDAOHelper.getBoatDAO(transaction); - - results = (List<String>)dao.createQuery().addDistinct().setSelect(Boat.NAME).add(Boat.NAME, Op.LIKE, input + "%").execute(); - - transaction.closeContext(); - } catch (Exception eee) { - SuiviObsmerContext.serviceException(transaction, - "Impossible de récupérer les navires avec un nom commencant par '" + input + "'", eee); - } - return results; - } } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2010-01-24 19:30:15 UTC (rev 264) @@ -31,6 +31,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.bean.ContactState; +import java.io.IOException; import java.io.InputStream; import org.nuiton.topia.framework.TopiaQuery; import fr.ifremer.suiviobsmer.bean.states.ContactStateEnum; @@ -58,6 +59,8 @@ import java.nio.charset.Charset; import java.text.DateFormat; import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -92,7 +95,7 @@ } @Override - public Map<String, Contact> getContactsByFilter(ContactFilter filter) throws SuiviObsmerException { + public Map<String, Contact> getContacts(ContactFilter filter) throws SuiviObsmerException { Map<String, Contact> results = new HashMap<String, Contact>(); TopiaContext transaction = null; try { @@ -121,7 +124,7 @@ } @Override - public int countContactsByFilter(ContactFilter filter) throws SuiviObsmerException { + public int getNbContacts(ContactFilter filter) throws SuiviObsmerException { TopiaContext transaction = null; int result = 0; try { @@ -307,10 +310,11 @@ TopiaContext transaction = null; ImportResults result = new ImportResultsImpl(); int currRow = 1; + CsvReader reader = null; try { transaction = rootContext.beginTransaction(); - CsvReader reader = new CsvReader(input, Charset.forName("UTF-8")); + reader = new CsvReader(input, Charset.forName("UTF-8")); reader.readHeaders(); ContactDAO dao = SuiviObsmerModelDAOHelper.getContactDAO(transaction); @@ -420,12 +424,14 @@ } // new contact to import + boolean newContact = false; if (contact == null) { contact = dao.create( TopiaEntity.TOPIA_CREATE_DATE, createDate, Contact.USER, observer, Contact.SAMPLE_ROW, row, Contact.BOAT, boat); + newContact = true; } // String tideBeginString = ImportHelper.read(reader, CONTACT.CONT_DEBUT_MAREE); @@ -457,15 +463,27 @@ contact.setMammalsObservation(mammalsObsv); contact.setDataInputDate(dataInput); - // Import validations only for superadmin : useful for archives - if (user.getAdmin() && user.getLogin().equals("admin")) { + // Import validations only for superadmin and a new contact : useful for archives + if (newContact && user.getAdmin() && user.getLogin().equals("admin")) { + if (log.isDebugEnabled()) { + log.debug("SuperAdmin import :: validations"); + } Boolean companyValidation = ImportHelper.parseContactValidation(reader, CONTACT.CONT_SOCIETE_VALID); Boolean programValidation = ImportHelper.parseContactValidation(reader, CONTACT.CONT_PROGRAM_VALID); contact.setValidationCompany(companyValidation); contact.setValidationProgram(programValidation); + + // Add realTideTime for this contact if validations are ok and state is BOARDING_DONE if (BooleanUtils.isTrue(companyValidation) && BooleanUtils.isNotFalse(programValidation) && contact.getState().equals(ContactState.BOARDING_DONE.toString())) { - contact.getSampleRow().addRealTideTime(contact); + boolean ok = contact.getSampleRow().addRealTideTime(contact); + if (!ok) { + DateFormat dateFormat1 = new SimpleDateFormat("MM/yyyy"); + result.addError(currRow, "Impossible de mettre à jour le nombre de marée réels, vérifiez le mois " + + "de " + dateFormat1.format(contact.getTideBeginDate()) + " pour la ligne du plan " + row.getCode()); + result.incNbRefused(); + continue; + } } } @@ -503,6 +521,13 @@ "Erreur ligne " + currRow + " : " + "Le format des dates est incorrect, il doit être de la forme : JJ/MM/AAAA", eee); } catch (Exception eee) { + if (log.isDebugEnabled()) { + try { + log.debug("Ligne : " + currRow + " :: " + Arrays.toString(reader.getValues())); + } catch (IOException ex) { + log.error("Reader error", ex); + } + } SuiviObsmerContext.serviceException(transaction, "Impossible d'importer les contacts", eee); } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImpl.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImpl.java 2010-01-24 19:30:15 UTC (rev 264) @@ -26,6 +26,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.SuiviObsmerContext; +import fr.ifremer.suiviobsmer.entity.Company; import fr.ifremer.suiviobsmer.entity.FishingZone; import fr.ifremer.suiviobsmer.entity.FishingZoneDAO; import fr.ifremer.suiviobsmer.entity.Profession; @@ -66,7 +67,7 @@ } @Override - public List<String> getFacadesByUser(User user) throws SuiviObsmerException { + public List<String> getFacades(Company company) throws SuiviObsmerException { TopiaContext transaction = null; List<String> results = new ArrayList<String>(); try { @@ -75,10 +76,10 @@ FishingZoneDAO dao = SuiviObsmerModelDAOHelper.getFishingZoneDAO(transaction); TopiaQuery<FishingZone> query = dao.createQuery("F"); - if (!user.getAdmin()) { + if (company != null) { query.addFrom(SampleRow.class.getName() + " S"). add("S IN elements(F." + FishingZone.SAMPLE_ROW + ")"). - add("S." + SampleRow.COMPANY, user.getCompany()); + add("S." + SampleRow.COMPANY, company); } results = (List<String>)query.setSelect("DISTINCT F." + FishingZone.FACADE_NAME).execute(); @@ -91,7 +92,7 @@ } @Override - public List<String> getSectorsByUser(User user, String facadeName) throws SuiviObsmerException { + public List<String> getSectors(Company company, String facadeName) throws SuiviObsmerException { TopiaContext transaction = null; List<String> results = new ArrayList<String>(); try { @@ -100,13 +101,13 @@ FishingZoneDAO dao = SuiviObsmerModelDAOHelper.getFishingZoneDAO(transaction); TopiaQuery<FishingZone> query = dao.createQuery("F"); - if (!user.getAdmin()) { + if (company != null) { query.addFrom(SampleRow.class.getName() + " S"). add("S IN elements(F." + FishingZone.SAMPLE_ROW + ")"). - add("S." + SampleRow.COMPANY, user.getCompany()); + add("S." + SampleRow.COMPANY, company); } - if (!StringUtils.isEmpty(facadeName)) { + if (StringUtils.isNotEmpty(facadeName)) { query.add("F." + FishingZone.FACADE_NAME, facadeName); } Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.properties =================================================================== --- trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.properties 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.properties 2010-01-24 19:30:15 UTC (rev 264) @@ -3,7 +3,7 @@ fr.ifremer.suiviobsmer.entity.Company.attribute.user.tagvalue.lazy=false fr.ifremer.suiviobsmer.entity.SampleRow.attribute.sampleMonth.tagvalue.lazy=false -fr.ifremer.suiviobsmer.entity.SampleRow.attribute.sampleMonth.tagvalue.orderBy=periodYear,periodMonth +fr.ifremer.suiviobsmer.entity.SampleRow.attribute.sampleMonth.tagvalue.orderBy=periodDate fr.ifremer.suiviobsmer.entity.SampleRow.attribute.fishingZone.tagvalue.lazy=false fr.ifremer.suiviobsmer.entity.SampleRow.attribute.fishingZone.tagvalue.orderBy=facadeName,sectorName,districtCode fr.ifremer.suiviobsmer.entity.SampleRow.attribute.profession.tagvalue.lazy=false Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo =================================================================== (Binary files differ) Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/BoatImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/BoatImplTest.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/BoatImplTest.java 2010-01-24 19:30:15 UTC (rev 264) @@ -106,7 +106,7 @@ InputStream input = getClass().getResourceAsStream("/import/navires.csv"); ServiceBoat serviceBoat = new ServiceBoatImpl(); serviceBoat.importBoatCsv(input); - List<Boat> boats = serviceBoat.getBoats("174258"); + List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174258"); Boat boat = boats.get(0); TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/BoatInfosImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/BoatInfosImplTest.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/BoatInfosImplTest.java 2010-01-24 19:30:15 UTC (rev 264) @@ -94,7 +94,7 @@ InputStream input = getClass().getResourceAsStream("/import/navires.csv"); ServiceBoat serviceBoat = new ServiceBoatImpl(); serviceBoat.importBoatCsv(input); - List<Boat> boats = serviceBoat.getBoats("174258"); + List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174258"); Boat boat = boats.get(0); TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java 2010-01-24 19:30:15 UTC (rev 264) @@ -93,8 +93,8 @@ SampleMonthDAO monthDAO = SuiviObsmerModelDAOHelper.getSampleMonthDAO(transaction); SampleMonth month = monthDAO.create(SampleMonth.SAMPLE_ROW, row); - month.setPeriodMonth(4); - month.setPeriodYear(2009); + Calendar calendar = new GregorianCalendar(2009, 3, 1); + month.setPeriodDate(calendar.getTime()); row.addSampleMonth(month); transaction.commitTransaction(); Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java 2010-01-24 19:30:15 UTC (rev 264) @@ -166,10 +166,10 @@ service.importBoatCsv(input); String immatriculations = "174592 978419 273129"; - List<Boat> results = service.getBoats(immatriculations); + List<Boat> results = service.getBoatsByImmatriculations(immatriculations); assertEquals(3, results.size()); immatriculations = "174592 \\ èè-- ç999 àà \n\n 978419 00 ççç 273129"; - results = service.getBoats(immatriculations); + results = service.getBoatsByImmatriculations(immatriculations); assertEquals(3, results.size()); } @@ -233,7 +233,7 @@ transaction.closeContext(); // Set company and elligibleBoats '174592 177474' for row1 - List<Boat> boats = service.getBoats("174592 177474"); + List<Boat> boats = service.getBoatsByImmatriculations("174592 177474"); row1.setCompany(company); serviceSampling.createUpdateSampleRow(row1, boats, new SampleRowLogImpl()); // Set company only for row2 @@ -251,7 +251,7 @@ InputStream input = getClass().getResourceAsStream("/import/navires.csv"); service.importBoatCsv(input); - List<Boat> boats = service.getBoats("174592"); + List<Boat> boats = service.getBoatsByImmatriculations("174592"); Boat boat = boats.get(0); // Two rows created : 2009_3 & 2010_4 and one Company : "TARTANPION" @@ -328,26 +328,9 @@ /** EXEC METHOD **/ Contact result = companyBoatInfos.getLastContact(); Assert.assertEquals(contact1.getTopiaId(), result.getTopiaId()); - - } /** - * Test of getAllBoats method, of class ServiceBoatImpl. - * @throws Exception - */ - @Test - public void testGetAllBoats() throws Exception { - log.info("getAllBoats"); - - InputStream input = getClass().getResourceAsStream("/import/navires.csv"); - service.importBoatCsv(input); - - List<Boat> boats = service.getAllBoats(); - assertEquals(6, boats.size()); - } - - /** * Test of importBoatCsv method, of class ServiceBoatImpl. * @throws Exception */ @@ -362,7 +345,7 @@ assertEquals(6, nbBoats[1]); // Check boat 174592 is active &nd boat 177474 is inactive - List<Boat> results = service.getBoats("174592 177474"); + List<Boat> results = service.getBoatsByImmatriculations("174592 177474"); assertTrue(results.get(0).getActive()); assertFalse(results.get(1).getActive()); } Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImplTest.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImplTest.java 2010-01-24 19:30:15 UTC (rev 264) @@ -82,10 +82,8 @@ InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); service.importFishingZoneCsv(input); - User user = new UserImpl(); - user.setAdmin(true); - List<String> facades = service.getFacadesByUser(user); + List<String> facades = service.getFacades(null); assertEquals(3, facades.size()); assertTrue(facades.contains("Atlantique")); assertTrue(facades.contains("Mer du Nord")); @@ -98,10 +96,8 @@ InputStream input = getClass().getResourceAsStream("/import/zonesPeche.csv"); service.importFishingZoneCsv(input); - User user = new UserImpl(); - user.setAdmin(true); - List<String> sectors = service.getSectorsByUser(user, null); + List<String> sectors = service.getSectors(null, null); assertEquals(5, sectors.size()); assertTrue(sectors.contains("Manche")); assertTrue(sectors.contains("Mer du Nord")); @@ -109,7 +105,7 @@ assertTrue(sectors.contains("Golfe de Gascogne")); assertTrue(sectors.contains("Méditerranée")); - sectors = service.getSectorsByUser(user, "Atlantique"); + sectors = service.getSectors(null, "Atlantique"); assertEquals(2, sectors.size()); assertTrue(sectors.contains("Manche Ouest")); assertTrue(sectors.contains("Golfe de Gascogne")); Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java 2010-01-24 19:30:15 UTC (rev 264) @@ -134,17 +134,17 @@ profession1.setLibelle("Chalutage de poissons tubes"); List<SampleMonth> months = new ArrayList<SampleMonth>(); - for (int i= 1; i <= 12; i++) { + for (int i = 0; i < 12; i++) { SampleMonth month = new SampleMonthImpl(); - month.setPeriodMonth(i); - month.setPeriodYear(2009); + Calendar calendar = new GregorianCalendar(2009, i, 1); + month.setPeriodDate(calendar.getTime()); month.setExpectedTidesValue(3); months.add(month); } - for (int i= 1; i <= 3; i++) { + for (int i = 0; i < 3; i++) { SampleMonth month = new SampleMonthImpl(); - month.setPeriodMonth(i); - month.setPeriodYear(2010); + Calendar calendar = new GregorianCalendar(2010, i, 1); + month.setPeriodDate(calendar.getTime()); month.setExpectedTidesValue(4); months.add(month); } @@ -162,7 +162,7 @@ row.setFishingZonesInfos("port tres loin du champ"); /** EXEC CREATE **/ - List<Boat> boats = serviceBoat.getBoats("174592 978419 273129"); + List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174592 978419 273129"); service.createUpdateSampleRow(row, boats, new SampleRowLogImpl()); assertNotNull(row.getTopiaId()); assertNotNull(row.getProfession().getTopiaId()); @@ -428,7 +428,7 @@ input = getClass().getResourceAsStream("/import/navires.csv"); ServiceBoat serviceBoat = new ServiceBoatImpl(); serviceBoat.importBoatCsv(input); - List<Boat> boats = serviceBoat.getBoats("174592 978419 273129"); + List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174592 978419 273129"); service.createUpdateSampleRow(row, boats, new SampleRowLogImpl()); /** EXEC METHOD **/ Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/base/AbstractFilteredPage.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/base/AbstractFilteredPage.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/base/AbstractFilteredPage.java 2010-01-24 19:30:15 UTC (rev 264) @@ -145,7 +145,7 @@ if (getFilter().getCompany() != null) { companyId = getFilter().getCompany().getTopiaId(); } - } else { + } else if (!user.getAdmin()) { if (log.isDebugEnabled()) { log.debug("Company filtered : " + user.getCompany()); } @@ -187,7 +187,7 @@ log.info("BUSINESS REQUEST [getFacades]"); } List<OptionModel> options = new ArrayList<OptionModel>(); - for (String facadeName : serviceReferential.getFacadesByUser(user)) { + for (String facadeName : serviceReferential.getFacades(getFilter().getCompany())) { options.add(new OptionModelImpl(facadeName,facadeName)); } facadeSelectModel = new SelectModelImpl(null, options); @@ -201,7 +201,7 @@ log.info("BUSINESS REQUEST [getSectors]"); } List<OptionModel> options = new ArrayList<OptionModel>(); - for (String sectorName : serviceReferential.getSectorsByUser(user, getFilter().getFacadeName())) { + for (String sectorName : serviceReferential.getSectors(getFilter().getCompany(), getFilter().getFacadeName())) { options.add(new OptionModelImpl(sectorName,sectorName)); } sectorSelectModel = new SelectModelImpl(null, options); @@ -212,7 +212,7 @@ public GenericSelectModel<SampleRow> getSampleRowSelectModel() throws SuiviObsmerException { if (sampleRowSelectModel == null) { if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getSampleRowsForUser]"); + log.info("BUSINESS REQUEST [getSampleRowsByFilter]"); } // WARN : no use of sampleRow filter @@ -330,27 +330,61 @@ private boolean edited; + /** + * EVENT :: selected on refreshByCompany submit button. Reset selects for + * company selected : facades, sectors, sampleRows and observers. + * This method set the state to edited, you can use + * {@link AbstractFilteredPage#isEdited() } method to test it. + * + * @throws SuiviObsmerException + * @see AbstractFilteredPage#onSelectedFromRefreshByFacade() + */ + public void onSelectedFromRefreshByCompany() throws SuiviObsmerException { + // Reset facades + getFilter().setFacadeName(null); + onSelectedFromRefreshByFacade(); + resetFacadeSelect(); + // Reset observers + getFilter().setObserver(null); + observerSelectModel = null; + getObserverSelectModel(); + edited = true; + } + + /** + * EVENT :: selected on refreshByFacade submit button. Reset selects for + * facade selected : sectors and sampleRows. + * This method set the state to edited, you can use + * {@link AbstractFilteredPage#isEdited() } method to test it. + * + * @throws SuiviObsmerException + * @see AbstractFilteredPage#onSelectedFromRefreshBySector() + */ public void onSelectedFromRefreshByFacade() throws SuiviObsmerException { + // Reset sectors getFilter().setSectorName(null); onSelectedFromRefreshBySector(); resetSectorSelect(); } + /** + * EVENT :: selected on refreshBySector submit button. After refreshing + * data selected, reset selects for sector selected : sampleRows. + * This method set the state to edited, you can use + * {@link AbstractFilteredPage#isEdited() } method to test it. + * + * @throws SuiviObsmerException + * @see AbstractFilteredPage#onSelectedFromSearch() + */ public void onSelectedFromRefreshBySector() throws SuiviObsmerException { + // Update selected data onSelectedFromSearch(); + // Reset sampleRows; getFilter().setSampleRow(null); resetSampleRowSelect(); edited = true; } - public void onSelectedFromRefreshByCompany() throws SuiviObsmerException { - onSelectedFromSearch(); - getFilter().setObserver(null); - observerSelectModel = null; - getObserverSelectModel(); - edited = true; - } - protected boolean isEdited() { return edited; } Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/BoatDataSource.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/BoatDataSource.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/BoatDataSource.java 2010-01-24 19:30:15 UTC (rev 264) @@ -66,9 +66,9 @@ @Override protected int count() throws SuiviObsmerException { if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [countBoatsByFilter]"); + log.info("BUSINESS REQUEST [getNbBoatsByFilter]"); } - return service.countBoatsByFilter(filter); + return service.getNbBoatsByFilter(filter); } @Override Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/ContactDataSource.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/ContactDataSource.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/ContactDataSource.java 2010-01-24 19:30:15 UTC (rev 264) @@ -46,15 +46,15 @@ } filter.setStartIndex(startIndex); filter.setEndIndex(endIndex); - return serviceContact.getContactsByFilter(filter); + return serviceContact.getContacts(filter); } @Override protected int count() throws SuiviObsmerException { if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [countContactsByFilter]"); + log.info("BUSINESS REQUEST [getNbContacts]"); } - return serviceContact.countContactsByFilter(filter); + return serviceContact.getNbContacts(filter); } } 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 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2010-01-24 19:30:15 UTC (rev 264) @@ -37,6 +37,7 @@ 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.AbstractFilteredPage; import fr.ifremer.suiviobsmer.ui.data.BusinessUtils; import fr.ifremer.suiviobsmer.ui.base.GenericSelectModel; @@ -58,6 +59,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.tapestry5.Block; import org.apache.tapestry5.EventContext; +import org.apache.tapestry5.PersistenceConstants; import org.apache.tapestry5.StreamResponse; import org.apache.tapestry5.annotations.IncludeStylesheet; import org.apache.tapestry5.annotations.InjectComponent; @@ -142,7 +144,7 @@ } // Initialize filters using AbstractFilteredPage superclass - initSelectFilters(true, false); + initSelectFilters(false, false); companyBoatInfos = null; //boatSelectedImmatriculation = null; @@ -464,10 +466,14 @@ return false; } - Block onActionFromShowBoatInfos(Integer boatImma) { + Block onActionFromShowBoatInfos(Integer boatImma) throws SuiviObsmerException { boatSelectedImmatriculation = boatImma; // Suppress persistant boat informations - companyBoatInfos = null; + companyBoatInfos = null; + + if (user.getAdmin() && getCompany() != null) { + companySelectedId = getCompany().getTopiaId(); + } return boatsZone.getBody(); } @@ -495,6 +501,17 @@ private Date boardingFromDate; + private GenericSelectModel<Company> companies; + + @Inject + private ServiceUser serviceUser; + + @Property + @Persist(PersistenceConstants.FLASH) + private String companySelectedId; + + private Company company; + /*@Persist private SuiviObsmerPropertyChangeListener propertyChange;*/ @@ -512,36 +529,62 @@ } public CompanyBoatInfos getCompanyBoatInfos() throws SuiviObsmerException { - if (companyBoatInfos == null && boatSelectedImmatriculation != null) { + if (companyBoatInfos == null && boatSelectedImmatriculation != null && getCompany() != null) { if (log.isInfoEnabled()) { log.info("BUSINESS REQUEST [getElligibleBoats]"); - } - // Use filter to retrieve company - Company company = getFilter().getCompany() != null ? getFilter().getCompany() : user.getCompany(); - companyBoatInfos = - serviceBoat.getCompanyBoatInfos(boatSelectedImmatriculation, company); + } + companyBoatInfos = serviceBoat.getCompanyBoatInfos(boatSelectedImmatriculation, getCompany()); } return companyBoatInfos; } /** - * Used to get the selected boat name. This method is useful to avoid problems when using only boatInfos. - * Actually, the name is displayed when the boat is selected. + * Retrieve companies select model for admin user. Only active companies + * will be used for this model. * - * @return + * @return the GenericSelectModel<Company> * @throws SuiviObsmerException */ - public String getBoatName() throws SuiviObsmerException { - Boat selectedBoat = null; - if (getBoatInfos() != null) { - selectedBoat = getBoatInfos().getBoat(); - } else { - selectedBoat = getBoats().get(boatSelectedImmatriculation); + public GenericSelectModel<Company> getCompanies() throws SuiviObsmerException { + if (companies == null) { + if (log.isDebugEnabled()) { + log.debug("BUSINESS REQUEST [getCompanies]"); + } + List<Company> results = serviceUser.getCompanies(true); + companies = new GenericSelectModel<Company>(results, Company.class, "name","topiaId",propertyAccess); } - return selectedBoat.getName(); + return companies; } /** + * Get the current company. The user one if it's not an admin or the + * selected one otherwise. + * + * @return the current Company + * @throws SuiviObsmerException + */ + public Company getCompany() throws SuiviObsmerException { + if (company == null) { + if (StringUtils.isNotEmpty(companySelectedId)) { + company = getCompanies().findObject(companySelectedId); + } else if (!user.getAdmin()) { + company = user.getCompany(); + } + } + return company; + } + + /** + * Used to get the selected boat. + * + * @return the selected boat from the grid + * @throws SuiviObsmerException + */ + public Boat getBoatSelected() throws SuiviObsmerException { + return getBoats().get(boatSelectedImmatriculation); + } + + /** * Date for calculate boardings done for the selected boat. All boardings (number of contacts) will be calculated from this date. * Initialized as 12 months from today, but can be set by user. * @@ -566,6 +609,9 @@ } public BoatInfos getBoatInfos() throws SuiviObsmerException { + if (getCompanyBoatInfos() == null) { + return null; + } return getCompanyBoatInfos().getBoatInfos(); } @@ -607,10 +653,7 @@ /** /////////////////////// ACTIONS //////////////////////////////////// **/ Block onSuccessFromCompanySelectForm() throws SuiviObsmerException { - // Must be call to refresh company data from select - super.onSelectedFromSearch(); companyBoatInfos = null; - // boatSelectedImmatriculation is getting from Persist("flash") getCompanyBoatInfos(); return boatInfosZone.getBody(); } @@ -685,12 +728,10 @@ } Object onActionFromAddNewContactFromSampleRow(String sampleRowCode) throws SuiviObsmerException { - // Get selected boat from BoatInfos - boat = getBoatInfos().getBoat(); // Get sampleRow from elligibleBoat list ElligibleBoat elligible = getCompanyBoatInfos().getElligibleBoat(sampleRowCode); sampleRow = elligible.getSampleRow(); - contacts.createNewContact(boat, sampleRow); + contacts.createNewContact(getBoatSelected(), sampleRow); return contacts; } @@ -700,13 +741,11 @@ private BoatActivityCalendar calendarPage; public boolean hasActivityCalendar() throws SuiviObsmerException { - boat = getBoatInfos().getBoat(); - return boat.sizeActivityCalendar() != 0; + return getBoatSelected().sizeActivityCalendar() != 0; } Object onActionFromShowLastActivityCalendar() throws SuiviObsmerException { - boat = getBoatInfos().getBoat(); - calendarPage.setBoat(boat); + calendarPage.setBoat(getBoatSelected()); return calendarPage; } } Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2010-01-24 19:30:15 UTC (rev 264) @@ -157,7 +157,7 @@ if (contactFilter == null) { contactFilter = new ContactFilterImpl(); // Initialized to 12 months before the current day - Date fromDate = DateUtils.createDateAfterToday(0, -12, 0); + Date fromDate = DateUtils.createDateAfterToday(0, -6, 0); contactFilter.setFromDate(fromDate); } return contactFilter; Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java 2010-01-24 19:30:15 UTC (rev 264) @@ -593,7 +593,7 @@ "Vous devez ajouter au moins une zone de pêche à la ligne"); } - boats = serviceBoat.getBoats(immatriculations); + boats = serviceBoat.getBoatsByImmatriculations(immatriculations); // Update sampleRowCode from program only if changed } else if (isCreateMode()) { String rowCode = serviceSampling.getNewSampleRowCode(periodBegin); Modified: trunk/suiviobsmer-ui/src/main/webapp/Boats.tml =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2010-01-24 19:30:15 UTC (rev 264) @@ -48,7 +48,7 @@ <!-- Filtres --> <!--t:filters t:title="Filtres de recherche" t:mainId="so-boats-filters"--> - <div t:type="zone" class="so-filters" t:id="filtersZone" t:update="show" id="so-boats-filters"> + <div t:type="zone" class="so-filters" t:id="filtersZone" id="so-boats-filters"> <fieldset> <legend>Filtres de recherche</legend> <div class="aright"> @@ -105,8 +105,8 @@ <div t:type="zone" t:id="boatsZone" t:update="show" class="clearfix"> <!-- BOATLIST:: --> <div class="fleft" id="so-boats-list"> - <h1>Liste des navires</h1> - <div t:type="grid" t:source="boats" t:row="boat" + <h1>Liste de ${boats.availableRows} navires</h1> + <div t:type="grid" t:source="boats" t:row="boat" t:inPlace="true" t:include="name, immatriculation, districtCode, boatLength, buildYear" t:rowClass="prop:rowStyle" t:rowsPerPage="20"> <p:nameCell> <t:if t:test="canCreateNewContactFromList()"> @@ -128,15 +128,15 @@ <t:unless t:test="activityCalendarImportRun"> <!-- HEADER For admin --> <t:if t:test="user.admin"> - <h2>Informations sur <!--${companyBoatInfos.boatInfos.boat.name}-->${boatName}</h2> + <h2>Informations sur ${boatSelected.name}</h2> <form t:type="form" t:id="companySelectForm" t:zone="so-boats-boat-infos"> <t:label t:for="company" /> : - <input t:type="select" t:id="company" t:model="companySelectModel" t:value="companyId" /> + <input t:type="select" t:id="company" t:model="companies" t:value="companySelectedId" /> <input t:type="submit" class="ico search" t:id="searchCompany" value="Search" /> </form> </t:if> <!-- BODY - delegator --> - <t:if t:test="filter.company"> + <t:if t:test="companyBoatInfos"> <t:delegate to="activeBoatInfosBlock" /> </t:if> <!-- BODY - activity calendar --> Modified: trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml 2010-01-24 19:30:15 UTC (rev 264) @@ -19,7 +19,7 @@ </a> </div> <!-- FILTRES --> -<div t:type="zone" class="so-filters" t:id="filtersZone" t:update="show" t:visible="prop:filtersVisible" id="so-contacts-filters"> +<div t:type="zone" class="so-filters" t:id="filtersZone" t:visible="prop:filtersVisible" id="so-contacts-filters"> <fieldset> <legend>Recherche avancée</legend> <div class="so-filters-form"> @@ -27,6 +27,18 @@ <t:errors /> <div class="t-beaneditor"> <div> + <t:label t:for="fromDate" />: + <input t:type="datefield" class="width70" t:id="fromDate" value="contactFilter.fromDate" /> + <t:if t:test="user.admin"> + <t:label t:for="company" />: + <input t:type="select" t:id="company" t:model="companySelectModel" value="companyId"/> + <input t:type="submit" class="ico22px refresh" t:id="refreshByCompany" value="Refresh" + title="Rafraîchir les filtres en fonction de la société sélectionnée"/> + </t:if> + <t:label t:for="observer" />: + <select t:type="select" t:id="observer" t:model="observerSelectModel" value="observerId" /> + </div><p> </p> + <div> <!-- Boat filter --> <label>Navire </label> <t:label t:for="boatImmatriculation" />: @@ -56,18 +68,6 @@ </t:label> </div><p> </p> <div> - <t:label t:for="fromDate" />: - <input t:type="datefield" class="width70" t:id="fromDate" value="contactFilter.fromDate" /> - <t:if t:test="user.admin"> - <t:label t:for="company" />: - <input t:type="select" t:id="company" t:model="companySelectModel" value="companyId"/> - <input t:type="submit" class="ico22px refresh" t:id="refreshByCompany" value="Refresh" - title="Rafraîchir les observateurs en fonction de la société sélectionnée"/> - </t:if> - <t:label t:for="observer" />: - <select t:type="select" t:id="observer" t:model="observerSelectModel" value="observerId" /> - </div><p> </p> - <div> <t:label t:for="state" />: <select t:type="select" t:id="state" value="contactFilter.state"/> <label>Validation société: </label> @@ -124,7 +124,8 @@ </fieldset> </div> <!-- CONTACT LIST --> -<t:zone t:id="gridZone" t:update="show"> +<p><strong>${contacts.availableRows} contacts trouvés</strong></p> +<!--<t:zone t:id="gridZone" t:update="show">--> <form t:type="form" t:id="contactsForm" t:zone="gridZone"> <t:errors id="so-contact-form-errors" t:banner="message:contactsForm-errors-banner"/> <div t:type="grid" t:source="contacts" t:row="contact" class="t-data-grid ${gridClass}" t:model="contactModel" t:rowClass="prop:rowClass" @@ -293,6 +294,6 @@ </p:actionsCell> </div> </form> -</t:zone> +<!--</t:zone>--> </t:layout> Modified: trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-01-24 19:30:15 UTC (rev 264) @@ -46,7 +46,7 @@ <div class="acenter" id="so-datasampling"> <fieldset> <legend>Filtres</legend> - <div t:type="zone" t:id="filtersZone" class="so-filters-form" id="so-datasampling-filters" t:update="show"> + <div t:type="zone" t:id="filtersZone" class="so-filters-form" id="so-datasampling-filters"> <!--<div t:type="zone" t:id="dataSamplingFiltersZone" t:update="show" id="so-datasampling-filters">--> <form t:type="form" t:id="filtersForm" t:zone="so-datasampling-filters"> <t:errors /> @@ -57,6 +57,12 @@ <input t:type="datefield" class="width70" t:id="periodBegin" t:value="filter.period.fromDate" /> <t:label t:for="periodEnd" />: <input t:type="datefield" class="width70" t:id="periodEnd" t:value="filter.period.thruDate" /> + <t:if t:test="user.admin"> + <t:label t:for="company" />: + <input t:type="select" t:id="company" t:model="companySelectModel" value="companyId"/> + <input t:type="submit" class="ico22px refresh" t:id="refreshByCompany" value="Refresh" + title="Rafraîchir les filtres en fonction de la société sélectionnée"/> + </t:if> </div> <div class="filterRow" t:type="zone" t:id="sampleRowZone" t:update="show"> <t:label t:for="facadeName" />: @@ -67,18 +73,11 @@ <select t:type="select" t:id="sectorName" t:model="sectorSelectModel" value="filter.sectorName" /> <input t:type="submit" class="ico22px refresh" t:id="refreshBySector" value="Refresh" title="Rafraîchir les métiers en fonction de la zone sélectionnée"/> - + <t:label t:for="sampleRow" />: + <input t:type="select" t:id="sampleRow" t:model="sampleRowSelectModel" value="sampleRowId" /> <!--<t:label t:for="program" />: <input t:type="select" t:id="program" t:model="programSelectModel" value="programId" />--> </div> - <div> - <t:label t:for="sampleRow" />: - <input t:type="select" t:id="sampleRow" t:model="sampleRowSelectModel" value="sampleRowId" /> - <t:if t:test="user.admin"> - <t:label t:for="company" />: - <input t:type="select" t:id="company" t:model="companySelectModel" value="companyId"/> - </t:if> - </div> <div class="t-beaneditor-row aright"> <input t:type="submit" class="ico search-32px" t:id="search" value="Search" /> <input t:type="submit" class="ico undo" t:id="reset" value="Reset" /> Modified: trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css 2010-01-23 18:16:17 UTC (rev 263) +++ trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css 2010-01-24 19:30:15 UTC (rev 264) @@ -60,7 +60,7 @@ }*/ div#so-datasampling fieldset { - width: 60%; + width: 70%; margin-left: auto; margin-right: auto; text-align: left;