Author: fdesbois Date: 2010-01-26 10:03:42 +0000 (Tue, 26 Jan 2010) New Revision: 272 Modified: trunk/changelog.txt trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java Log: Evo #2047 : Careful of existing contacts during import : a validated contact is not updated from import. Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2010-01-25 19:10:30 UTC (rev 271) +++ trunk/changelog.txt 2010-01-26 10:03:42 UTC (rev 272) @@ -7,6 +7,7 @@ Note Il est préférable de supprimer la base de données existante d'une version 0.1.1 avant le déploiement de cette version. +- [fdesbois] Evo #2047 : Revoir mise à jour des contacts lors d'un import (impossible d'écraser un contact existant validé) - [fdesbois] Evo #2035 : Ajouter pourcentage sur le total sur chaque ligne du plan - [fdesbois] Evo #2041 : Modifier codes couleurs sur les contacts - [fdesbois] Ano #2040 : Problème de sauvegarde du programme lors de la création d'une ligne d'échantillonnage Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java 2010-01-25 19:10:30 UTC (rev 271) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java 2010-01-26 10:03:42 UTC (rev 272) @@ -371,7 +371,12 @@ time = new GregorianCalendar(Locale.FRENCH); time.setTime(timeFormat.parse(code)); } else { + // Use current date with no time as a reference if no code is set time.setTime(SuiviObsmerContext.getCurrentDate()); + time.set(Calendar.HOUR_OF_DAY, 0); + time.set(Calendar.MINUTE, 0); + time.set(Calendar.SECOND, 0); + time.set(Calendar.MILLISECOND, 0); } Calendar result = new GregorianCalendar(Locale.FRENCH); 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-25 19:10:30 UTC (rev 271) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2010-01-26 10:03:42 UTC (rev 272) @@ -350,7 +350,7 @@ // FIXME-FD20100104 findContains not optimized in TopiaDAOImpl company = companyDAO.findContainsUser(observer); // For a user, check if the observer as the same company as the current user - } else if (!observer.getCompany().getTopiaId().equals(company.getTopiaId())) { + } else if (!observer.getCompany().equals(company)) { throw new SuiviObsmerBusinessException(Type.IMPORT_ERROR, this.getClass(), "Erreur ligne " + currRow + " : " + "L'observateur avec pour login '" + observerId + "' n'appartient pas à votre société !"); @@ -382,67 +382,42 @@ } elligible.setCompanyActive(Boolean.TRUE); - // The boat must be elligible for the row -// TopiaQuery<Boat> boatQuery = boatDAO.createQuery("B"). -// addFrom(ElligibleBoat.class.getName() + " E"). -// add("E.sampleRow", row).add("E.boat = B"). -// add(Boat.IMMATRICULATION, boatImmatriculation); -// -// if (!user.getAdmin()) { -// // Constraint on companyActive for elligibleBoat for a simple user -// boatQuery.add("E.companyActive = :booleanTrue OR (E.companyActive IS NULL AND E.globalActive = :booleanTrue)"). -// addParam("booleanTrue", Boolean.TRUE); -// } -// -// Boat boat = boatQuery.executeToEntity(); -// -// if (boat == null) { -// ElligibleBoatDAO elligibleDAO = SuiviObsmerModelDAOHelper.getElligibleBoatDAO(transaction); -// -// } - Contact contact = null; - // Check if createDate exist String createDateString = ImportHelper.read(reader, CONTACT.CONT_CREATION); - //Date createDate = !StringUtils.isEmpty(createDateString) ? dateFormat.parse(createDateString) : null; - String contactCode = ImportHelper.read(reader, CONTACT.CONT_CODE); Date createDate = ImportHelper.parseContactCreateDate(contactCode, createDateString); - if (log.isTraceEnabled()) { - log.trace("Ligne " + currRow + " : Create date : " + createDate); + + if (log.isDebugEnabled()) { + log.debug("Ligne " + currRow + " : Create date : " + createDate); } - if (!StringUtils.isEmpty(contactCode) && !StringUtils.isEmpty(createDateString)) { + if (/*!StringUtils.isEmpty(contactCode) && */StringUtils.isNotEmpty(createDateString)) { // Get entity from database contact = dao.createQuery(). add(TopiaEntity.TOPIA_CREATE_DATE, createDate). - add("user.company", company). + add(Contact.USER + "." + User.COMPANY, company). add(Contact.BOAT, boat). add(Contact.SAMPLE_ROW, row). executeToEntity(); } + if (contact != null && contact.getValidationCompany() != null) { + result.addError(currRow, "Le contact est déjà validé dans l'application et ne peut pas être importé"); + result.incNbRefused(); + continue; + } + // 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); -// String tideEndString = ImportHelper.read(reader, CONTACT.CONT_FIN_MAREE); -// String nbObservantsString = ImportHelper.read(reader, CONTACT.CONT_NB_OBSERV); -// String dataInputString = ImportHelper.read(reader, CONTACT.CONT_ALLEGRO); - -// Date tideBegin = !StringUtils.isEmpty(tideBeginString) ? dateFormat.parse(tideBeginString) : null; -// Date tideEnd = !StringUtils.isEmpty(tideEndString) ? dateFormat.parse(tideEndString) : null; -// Date dataInput = !StringUtils.isEmpty(dataInputString) ? dateFormat.parse(dataInputString) : null; -// int nbObservants = !StringUtils.isEmpty(nbObservantsString) ? Integer.parseInt(nbObservantsString) : 0; Date tideBegin = ImportHelper.readDate(reader, CONTACT.CONT_DEBUT_MAREE); Date tideEnd = ImportHelper.readDate(reader, CONTACT.CONT_FIN_MAREE); Date dataInput = ImportHelper.readDate(reader, CONTACT.CONT_ALLEGRO); @@ -455,6 +430,7 @@ boolean mammalsObsv = ImportHelper.parseContactMammals(reader, CONTACT.CONT_MAM_OBS); + contact.setUser(observer); contact.setState(state); contact.setTideBeginDate(tideBegin); contact.setTideEndDate(tideEnd);