Author: fdesbois Date: 2010-04-01 13:51:21 +0000 (Thu, 01 Apr 2010) New Revision: 403 Modified: trunk/changelog.txt trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties Log: - Clean ServiceBoatImpl - Add changelog for last issue resolved Modified: trunk/changelog.txt =================================================================== --- trunk/changelog.txt 2010-04-01 13:28:03 UTC (rev 402) +++ trunk/changelog.txt 2010-04-01 13:51:21 UTC (rev 403) @@ -31,6 +31,7 @@ Anomalies +++++++++ +- [fdesbois] Ano #2237 : Impossible de changer les zones de pêche - [fdesbois] Ano #2235 : Temp d'affichage page contacts ou plan d'échantillonnage - [fdesbois] Ano #2228 : Erreur d'affichage de la synthèse : réactivité de la Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-04-01 13:28:03 UTC (rev 402) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-04-01 13:51:21 UTC (rev 403) @@ -70,95 +70,41 @@ */ public class ServiceBoatImpl extends ServiceBoatAbstract { - private static final Logger log = LoggerFactory.getLogger(ServiceBoatImpl.class); + private static final Logger log = + LoggerFactory.getLogger(ServiceBoatImpl.class); -// protected TopiaContext rootContext; -// -// public ServiceBoatImpl() throws WaoExceptionO { -// rootContext = WaoContextO.getTopiaRootContext(); -// } - @Override public Map<Integer, Boat> executeGetBoatsByFilter(TopiaContext transaction, List<Object> errorArgs, BoatFilter filter) throws TopiaException { -// TopiaContext transaction = null; -// Map<Integer, Boat> results = new HashMap<Integer, Boat>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// -// transaction = rootContext.beginTransaction(); - BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); - TopiaQuery query = dao.createQuery("B"); + BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); + TopiaQuery query = dao.createQuery("B"); - query = createQueryForBoatFilter(query, filter); + query = createQueryForBoatFilter(query, filter); -// if (StringUtils.isNotEmpty(filter.getOrderBy())) { -// query.addOrder("B." + filter.getOrderBy()); -// } + query.addLoad(Boat.ACTIVITY_CALENDAR); - query.addLoad(Boat.ACTIVITY_CALENDAR); + if (log.isDebugEnabled()) { + log.debug("Query : " + query); + } - if (log.isDebugEnabled()) { - log.debug("Query : " + query); - } - - return dao.findAllMappedByQuery(query, Boat.IMMATRICULATION, Integer.class); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getBoatsByFilter ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de filtrer la liste des navires", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return results; + return dao.findAllMappedByQuery(query, + Boat.IMMATRICULATION, Integer.class); } @Override public int executeGetNbBoatsByFilter(TopiaContext transaction, List<Object> errorArgs, BoatFilter filter) throws TopiaException { -// TopiaContext transaction = null; -// int result = 0; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// -// transaction = rootContext.beginTransaction(); + BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); + TopiaQuery query = dao.createQuery("B"); - BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); - TopiaQuery query = dao.createQuery("B"); + query = createQueryForBoatFilter(query, filter); - query = createQueryForBoatFilter(query, filter); - - return query.executeCount(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getNbBoatsByFilter ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de filtrer la liste des navires", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return result; + return query.executeCount(); } - protected TopiaQuery createQueryForBoatFilter(TopiaQuery query, BoatFilter filter) throws TopiaException { + protected TopiaQuery createQueryForBoatFilter(TopiaQuery query, + BoatFilter filter) throws TopiaException { String main = query.getMainAlias(); query = filter.prepareQueryForBoat(query, main).addDistinct(); @@ -166,15 +112,19 @@ if (filter.isSamplingFiltered()) { // Add join for ElligibleBoat //String elligibleBoatClassName = ElligibleBoat.class.getName(); - query.addFrom(ElligibleBoat.class, "E").add("E." + ElligibleBoat.BOAT + " = " + main); - query = filter.prepareQueryForSampling(query, "E." + ElligibleBoat.SAMPLE_ROW); + query.addFrom(ElligibleBoat.class, "E"). + add("E." + ElligibleBoat.BOAT + " = " + main); + query = filter.prepareQueryForSampling(query, + "E." + ElligibleBoat.SAMPLE_ROW); // Company if (filter.getCompany() != null) { - //query.add("E." + ElligibleBoat.SAMPLE_ROW + "." + SampleRow.COMPANY, filter.getCompany()); // Test only valid ElligibleBoat for that company - query.add("E." + ElligibleBoat.COMPANY_ACTIVE + " = :booleanTrue " + - "OR (E." + ElligibleBoat.COMPANY_ACTIVE + " IS NULL AND E." + ElligibleBoat.GLOBAL_ACTIVE + " = :booleanTrue)"); + query.add("E." + ElligibleBoat.COMPANY_ACTIVE + + " = :booleanTrue " + + "OR (E." + ElligibleBoat.COMPANY_ACTIVE + + " IS NULL AND E." + ElligibleBoat.GLOBAL_ACTIVE + + " = :booleanTrue)"); query.addParam("booleanTrue", Boolean.TRUE); } } @@ -217,77 +167,52 @@ result.setElligibleBoats(elligibleBoats); result.setDeletedElligibleBoats(new ArrayList<ElligibleBoat>()); -// TopiaContext transaction = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// -// transaction = rootContext.beginTransaction(); + BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); - BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); + Boat boat = dao.findByImmatriculation(boatImmatriculation); - Boat boat = dao.findByImmatriculation(boatImmatriculation); - - BoatInfosDAO boatInfosDAO = WaoDAOHelper.getBoatInfosDAO(transaction); - BoatInfos boatInfos = boatInfosDAO.findByProperties( - BoatInfos.BOAT, boat, BoatInfos.COMPANY, company); - if (boatInfos == null) { - boatInfos = new BoatInfosImpl(); - boatInfos.setBoat(boat); - boatInfos.setCompany(company); - } else { - // load data - boatInfos.getBoat(); - } + BoatInfosDAO boatInfosDAO = WaoDAOHelper.getBoatInfosDAO(transaction); + BoatInfos boatInfos = boatInfosDAO.findByProperties( + BoatInfos.BOAT, boat, BoatInfos.COMPANY, company); + if (boatInfos == null) { + boatInfos = new BoatInfosImpl(); + boatInfos.setBoat(boat); + boatInfos.setCompany(company); + } else { // load data - boatInfos.getBoat().sizeActivityCalendar(); - - result.setBoatInfos(boatInfos); + boatInfos.getBoat(); + } + // load data + boatInfos.getBoat().sizeActivityCalendar(); - for (ElligibleBoat elligible : boat.getElligibleBoat()) { - SampleRow sampleRow = elligible.getSampleRow(); + result.setBoatInfos(boatInfos); - // SampleRow non closed only - //if (!sampleRow.isFinished()) { + for (ElligibleBoat elligible : boat.getElligibleBoat()) { + SampleRow sampleRow = elligible.getSampleRow(); - String companyId = sampleRow.getCompany() != null ? - sampleRow.getCompany().getTopiaId() : ""; + // SampleRow non closed only + //if (!sampleRow.isFinished()) { - if (companyId.equals(company.getTopiaId())) { - elligibleBoats.put(sampleRow.getCode(), elligible); - } - //} - } + String companyId = sampleRow.getCompany() != null ? + sampleRow.getCompany().getTopiaId() : ""; - // Last contact - ContactDAO contactDAO = WaoDAOHelper.getContactDAO(transaction); - TopiaQuery query = contactDAO.createQueryLastContactForBoat(boat, company). - addLoad(Contact.SAMPLE_ROW, Contact.OBSERVER); - - Contact contact = contactDAO.findByQuery(query); + if (companyId.equals(company.getTopiaId())) { + elligibleBoats.put(sampleRow.getCode(), elligible); + } + //} + } - if (contact != null) { - result.setLastContact(contact); - } - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getCompanyBoatInfos ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -//// transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "Impossible de récupérer les informations du navire " + -// "immatriculé '" + boatImmatriculation + "'" + -// " pour la société '" + company.getName() + "'", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + // Last contact + ContactDAO contactDAO = WaoDAOHelper.getContactDAO(transaction); + TopiaQuery query = contactDAO.createQueryLastContactForBoat(boat, company). + addLoad(Contact.SAMPLE_ROW, Contact.OBSERVER); + + Contact contact = contactDAO.findByQuery(query); + + if (contact != null) { + result.setLastContact(contact); + } + return result; } @@ -295,55 +220,31 @@ public void executeCreateUpdateCompanyBoatInfos(TopiaContext transaction, List<Object> errorArgs, CompanyBoatInfos companyBoatInfos) throws TopiaException { -// TopiaContext transaction = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - Boat boat = companyBoatInfos.getBoatInfos().getBoat(); - Company company = companyBoatInfos.getCompany(); - errorArgs.add(boat.getImmatriculation()); - errorArgs.add(company.getName()); + Boat boat = companyBoatInfos.getBoatInfos().getBoat(); + Company company = companyBoatInfos.getCompany(); + errorArgs.add(boat.getImmatriculation()); + errorArgs.add(company.getName()); - BoatInfosDAO dao = WaoDAOHelper.getBoatInfosDAO(transaction); + BoatInfosDAO dao = WaoDAOHelper.getBoatInfosDAO(transaction); - BoatInfos boatInfos = companyBoatInfos.getBoatInfos(); - context.prepareTopiaId(BoatInfos.class, boatInfos); - dao.update(boatInfos); + BoatInfos boatInfos = companyBoatInfos.getBoatInfos(); + context.prepareTopiaId(BoatInfos.class, boatInfos); + dao.update(boatInfos); - ElligibleBoatDAO elligibleDAO = WaoDAOHelper.getElligibleBoatDAO(transaction); + ElligibleBoatDAO elligibleDAO = WaoDAOHelper.getElligibleBoatDAO(transaction); - for (ElligibleBoat elligible : companyBoatInfos.getElligibleBoatsValues()) { - context.prepareTopiaId(ElligibleBoat.class, elligible); - elligibleDAO.update(elligible); - } + for (ElligibleBoat elligible : companyBoatInfos.getElligibleBoatsValues()) { + context.prepareTopiaId(ElligibleBoat.class, elligible); + elligibleDAO.update(elligible); + } - // Delete ElligibleBoats for the company - for (ElligibleBoat elligible : companyBoatInfos.getDeletedElligibleBoats()) { - elligibleDAO.delete(elligible); - } + // Delete ElligibleBoats for the company + for (ElligibleBoat elligible : companyBoatInfos.getDeletedElligibleBoats()) { + elligibleDAO.delete(elligible); + } - transaction.commitTransaction(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ createUpdateCompanyBoatInfos ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// //transaction.closeContext(); -// } catch (Exception eee) { -// Boat boat = companyBoatInfos.getBoatInfos().getBoat(); -// Company company = companyBoatInfos.getCompany(); -// WaoContextO.serviceException(transaction, -// "Impossible de créer ou modifier les informations liés au navire " + -// boat.getImmatriculation() + " pour la société " + company.getName(), eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + transaction.commitTransaction(); } @Override @@ -352,119 +253,51 @@ String immatriculations) throws TopiaException, WaoBusinessException { List<Boat> boats = new ArrayList<Boat>(); -// TopiaContext transaction = null; if (StringUtils.isEmpty(immatriculations)) { return boats; } -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); + BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); - Pattern pattern = Pattern.compile("\\d{6}"); - Matcher matcher = pattern.matcher(immatriculations); - while(matcher.find()) { - String res = matcher.group(); - int immatriculation = Integer.parseInt(res); - Boat boat = dao.findByImmatriculation(immatriculation); - if (boat == null) { - throw new WaoBusinessException(Type.NOT_EXISTS, - ServiceBoat.class, - "Immatriculation " + immatriculation + - " incorrect, ne référence aucun navire"); - } - boats.add(boat); + Pattern pattern = Pattern.compile("\\d{6}"); + Matcher matcher = pattern.matcher(immatriculations); + while(matcher.find()) { + String res = matcher.group(); + int immatriculation = Integer.parseInt(res); + Boat boat = dao.findByImmatriculation(immatriculation); + if (boat == null) { + throw new WaoBusinessException(Type.NOT_EXISTS, + ServiceBoat.class, + "Immatriculation " + immatriculation + + " incorrect, ne référence aucun navire"); } - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getBoatsByImmatriculations ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "La chaîne d'immatriculations est incorrect ! Chaque immatriculation doit posséder 6 chiffres", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + boats.add(boat); + } + return boats; } @Override public Boat executeGetBoat(TopiaContext transaction, List<Object> errorArgs, String boatId) throws TopiaException { -// TopiaContext transaction = null; -// Boat result = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); + BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); - return dao.findByTopiaId(boatId); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getBoat ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de charger le navire", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return result; + return dao.findByTopiaId(boatId); } @Override public List<String> executeGetBoatNamesStartWith(TopiaContext transaction, List<Object> errorArgs, String input) throws TopiaException { -// TopiaContext transaction = null; -// List<String> results = new ArrayList<String>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - input = StringUtils.upperCase(input); + input = StringUtils.upperCase(input); - errorArgs.add(input); + errorArgs.add(input); - BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); + BoatDAO dao = WaoDAOHelper.getBoatDAO(transaction); - return dao.createQuery().addDistinct().setSelect(Boat.NAME). - add(Boat.NAME, Op.LIKE, input + "%").execute(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getBoatNamesStartWith ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "Impossible de récupérer les navires avec un nom commencant par '" + input + "'", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return results; + return dao.createQuery().addDistinct().setSelect(Boat.NAME). + add(Boat.NAME, Op.LIKE, input + "%").execute(); } /** @@ -486,138 +319,113 @@ @Override public int[] executeImportBoatCsv(TopiaContext transaction, InputStream input) throws TopiaException, IOException, WaoBusinessException { -// TopiaContext transaction = null; int[] result = new int[]{0,0}; -// try { -// transaction = rootContext.beginTransaction(); -// long startTime = System.currentTimeMillis(); - CsvReader reader = new CsvReader(input, context.getCsvCharset()); - reader.readHeaders(); - long tic; + CsvReader reader = new CsvReader(input, context.getCsvCharset()); + reader.readHeaders(); + long tic; - BoatDAO boatDAO = WaoDAOHelper.getBoatDAO(transaction); - ShipOwnerDAO shipOwnerDAO = WaoDAOHelper.getShipOwnerDAO(transaction); + BoatDAO boatDAO = WaoDAOHelper.getBoatDAO(transaction); + ShipOwnerDAO shipOwnerDAO = WaoDAOHelper.getShipOwnerDAO(transaction); - Map<String, ShipOwner> availableShipOwners = new HashMap<String, ShipOwner>(); + Map<String, ShipOwner> availableShipOwners = new HashMap<String, ShipOwner>(); - tic = System.currentTimeMillis(); - Pattern pattern = Pattern.compile("\\d{6}"); - while(reader.readRecord()) { - result[0]++; + tic = System.currentTimeMillis(); + Pattern pattern = Pattern.compile("\\d{6}"); + while(reader.readRecord()) { + result[0]++; - if (log.isDebugEnabled()) { - log.debug(" " + Arrays.asList(reader.getValues())); - } + if (log.isDebugEnabled()) { + log.debug(" " + Arrays.asList(reader.getValues())); + } - String imma = ImportHelper.read(reader, BOAT.NAVS_COD); - Matcher matcher = pattern.matcher(imma); - if (!matcher.find()) { - throw new WaoBusinessException(Type.SYNTAX, - ServiceBoat.class, - "L'immatriculation ne comporte pas 6 chiffres"); - } + String imma = ImportHelper.read(reader, BOAT.NAVS_COD); + Matcher matcher = pattern.matcher(imma); + if (!matcher.find()) { + throw new WaoBusinessException(Type.SYNTAX, + ServiceBoat.class, + "L'immatriculation ne comporte pas 6 chiffres"); + } - int immatriculation = Integer.parseInt(imma); + int immatriculation = Integer.parseInt(imma); - String boatName = - ImportHelper.read(reader, BOAT.CARN_NOM); - int boatLength = - ImportHelper.readInt(reader, BOAT.CARN_LONGUEUR_HT); - int buildYear = - ImportHelper.readInt(reader, BOAT.CARN_ANNEE); - String districtCode = - ImportHelper.read(reader, BOAT.QUARTIER_IMMA); - String shipOwnerCode = - ImportHelper.read(reader, BOAT.PER_COD); - String shipOwnerLastName = - ImportHelper.read(reader, BOAT.PER_NOM); - String shipOwnerFirstName = - ImportHelper.read(reader, BOAT.PER_PRENOM); - - String activeStr = ImportHelper.read(reader, BOAT.NAVS_ACTIVE); - boolean active = !activeStr.equals(BOAT.getBoatInactiveCode()); + String boatName = + ImportHelper.read(reader, BOAT.CARN_NOM); + int boatLength = + ImportHelper.readInt(reader, BOAT.CARN_LONGUEUR_HT); + int buildYear = + ImportHelper.readInt(reader, BOAT.CARN_ANNEE); + String districtCode = + ImportHelper.read(reader, BOAT.QUARTIER_IMMA); + String shipOwnerCode = + ImportHelper.read(reader, BOAT.PER_COD); + String shipOwnerLastName = + ImportHelper.read(reader, BOAT.PER_NOM); + String shipOwnerFirstName = + ImportHelper.read(reader, BOAT.PER_PRENOM); - if (log.isTraceEnabled()) { - log.trace("Active : " + active + " (" + activeStr + ")"); - } + String activeStr = ImportHelper.read(reader, BOAT.NAVS_ACTIVE); + boolean active = !activeStr.equals(BOAT.getBoatInactiveCode()); - // Find existing boat with immatriculation - Boat boat = boatDAO.findByImmatriculation(immatriculation); + if (log.isTraceEnabled()) { + log.trace("Active : " + active + " (" + activeStr + ")"); + } - if (boat == null) { - boat = boatDAO.create( - Boat.IMMATRICULATION, immatriculation); - result[1]++; - } - boat.setName(boatName); - boat.setDistrictCode(districtCode); - boat.setBuildYear(buildYear); - boat.setBoatLength(boatLength); - boat.setActive(active); + // Find existing boat with immatriculation + Boat boat = boatDAO.findByImmatriculation(immatriculation); - // Find existing shipOwner with code - ShipOwner shipOwner = availableShipOwners.get(shipOwnerCode); + if (boat == null) { + boat = boatDAO.create( + Boat.IMMATRICULATION, immatriculation); + result[1]++; + } + boat.setName(boatName); + boat.setDistrictCode(districtCode); + boat.setBuildYear(buildYear); + boat.setBoatLength(boatLength); + boat.setActive(active); - // If not available, select it from database - if (shipOwner == null) { - shipOwner = shipOwnerDAO.findByCode(shipOwnerCode); + // Find existing shipOwner with code + ShipOwner shipOwner = availableShipOwners.get(shipOwnerCode); - // If not exist yet, create it - if (shipOwner == null) { - shipOwner = shipOwnerDAO.create( - ShipOwner.CODE, shipOwnerCode); - } + // If not available, select it from database + if (shipOwner == null) { + shipOwner = shipOwnerDAO.findByCode(shipOwnerCode); - availableShipOwners.put(shipOwnerCode, shipOwner); + // If not exist yet, create it + if (shipOwner == null) { + shipOwner = shipOwnerDAO.create( + ShipOwner.CODE, shipOwnerCode); } - shipOwner.setFirstName(shipOwnerFirstName); - shipOwner.setLastName(shipOwnerLastName); - boat.setShipOwner(shipOwner); + availableShipOwners.put(shipOwnerCode, shipOwner); + } + shipOwner.setFirstName(shipOwnerFirstName); + shipOwner.setLastName(shipOwnerLastName); - if (result[0] % 1000 == 0) { - availableShipOwners.clear(); + boat.setShipOwner(shipOwner); - transaction.commitTransaction(); - tic = ImportHelper.logTimeAndMemory( - log, tic, "navires ligne " + result[0]); - } + if (result[0] % 1000 == 0) { + availableShipOwners.clear(); + + transaction.commitTransaction(); + tic = ImportHelper.logTimeAndMemory( + log, tic, "navires ligne " + result[0]); } - - // For the last rows - transaction.commitTransaction(); + } -// long stopTime = System.currentTimeMillis(); -// -// String execTime = DurationFormatUtils.formatDurationHMS(stopTime - startTime); -// -// if (log.isInfoEnabled()) { -// log.info("Durée de l'import : " + execTime); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "Problème d'import du fichier CSV. Vérifiez l'en-tête du fichier : [ NAVS_COD,CARN_NOM," + -// "CARN_LONGUEUR_HT,CARN_ANNEE,QUARTIER_IMMA,PER_COD,PER_NOM,PER_PRENOM,NAVS_ACTIVE ]"/* et l'encodage [ UTF-8 ] */ + -// " Voir documentation pour plus de détails.", -// eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + // For the last rows + transaction.commitTransaction(); + return result; } @Override public InputStream executeExportBoatCsv(TopiaContext transaction, BoatFilter filter) throws Exception { -// TopiaContext transaction = null; InputStream result = null; CsvWriter writer = null; try { -// transaction = rootContext.beginTransaction(); - File file = File.createTempFile("wao-boats-", ".csv"); file.deleteOnExit(); @@ -696,16 +504,12 @@ } result = new FileInputStream(file); - //transaction.closeContext(); } catch (Exception eee) { throw eee; -// WaoContextO.serviceException(transaction, -// "Impossible d'exporter les navires sélectionnés", eee); } finally { if (writer != null) { writer.close(); } -// WaoContextO.closeTransaction(transaction); } return result; } @@ -714,14 +518,9 @@ public void executeImportActivityCalendarCsv(InputStream input) throws IOException { if (!context.isActivityCalendarImportRun()) { -// try { - ActivityCalendarImport calendarImport = - new ActivityCalendarImport(context, input); - new Thread(calendarImport).start(); -// } catch (IOException eee) { -// WaoContextO.serviceException(null, -// "Problème d'import du fichier CSV des calendriers d'activité", eee); -// } + ActivityCalendarImport calendarImport = + new ActivityCalendarImport(context, input); + new Thread(calendarImport).start(); } } @@ -733,67 +532,44 @@ errorArgs.add(boat.getName()); errorArgs.add(boat.getImmatriculation()); -// TopiaContext transaction = null; ActivityCalendar result = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - ActivityCalendarDAO dao = WaoDAOHelper.getActivityCalendarDAO(transaction); + ActivityCalendarDAO dao = WaoDAOHelper.getActivityCalendarDAO(transaction); - TopiaQuery query = dao.createQuery("A"). - add("A." + ActivityCalendar.BOAT, boat); + TopiaQuery query = dao.createQuery("A"). + add("A." + ActivityCalendar.BOAT, boat); - TopiaQuery subquery = dao.createQuery("B"). - setSelect("MAX(B." + ActivityCalendar.YEAR + ")"). - add("B." + ActivityCalendar.BOAT + " = A." + ActivityCalendar.BOAT). - addGroup("B." + ActivityCalendar.BOAT); + TopiaQuery subquery = dao.createQuery("B"). + setSelect("MAX(B." + ActivityCalendar.YEAR + ")"). + add("B." + ActivityCalendar.BOAT + " = A." + ActivityCalendar.BOAT). + addGroup("B." + ActivityCalendar.BOAT); - query.add("A." + ActivityCalendar.YEAR + " = (" + subquery.fullQuery() + ")"); + query.add("A." + ActivityCalendar.YEAR + " = (" + subquery.fullQuery() + ")"); - query.addLoad(ActivityCalendar.BOAT); - result = dao.findByQuery(query); + query.addLoad(ActivityCalendar.BOAT); + result = dao.findByQuery(query); - // load other complex data from collections - List<ActivityMonth> months = result.getActivityMonth(); - for (ActivityMonth month : months) { - List<ActivityProfession> professions = month.getActivityProfession(); - for (ActivityProfession profession : professions) { - List<ActivityZone> zones = profession.getActivityZone(); - zones.size(); - } + // load other complex data from collections + List<ActivityMonth> months = result.getActivityMonth(); + for (ActivityMonth month : months) { + List<ActivityProfession> professions = month.getActivityProfession(); + for (ActivityProfession profession : professions) { + List<ActivityZone> zones = profession.getActivityZone(); + zones.size(); } + } - // Log ActivityCalendar access only for non admin user - if (!user.isAdmin()) { - Company company = user.getCompany(); - // FIXME-FD20100401 Find a way to avoid using old context for - // logging access on ActivityCalendar - WaoContextO.addActivityCalendarAccessLog( - "Calendrier " + result.getYear() + " du navire " + - boat.getName() + " (" + boat.getImmatriculation() + ") vu " + - "par " + user.getFullName() + " de la société " + - company.getName()); - } - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getLastActivityCalendar ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "Impossible de charger le dernier calendrier d'activité du navire " + -// boat.getName() + " (" + boat.getImmatriculation() + ")", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + // Log ActivityCalendar access only for non admin user + if (!user.isAdmin()) { + Company company = user.getCompany(); + // FIXME-FD20100401 Find a way to avoid using old context for + // logging access on ActivityCalendar + WaoContextO.addActivityCalendarAccessLog( + "Calendrier " + result.getYear() + " du navire " + + boat.getName() + " (" + boat.getImmatriculation() + ") vu " + + "par " + user.getFullName() + " de la société " + + company.getName()); + } return result; } Modified: trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-04-01 13:28:03 UTC (rev 402) +++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-04-01 13:51:21 UTC (rev 403) @@ -4,19 +4,19 @@ wao.error.context.rollback= wao.error.context.start= wao.error.context.stop= -wao.error.serviceBoat.createUpdateCompanyBoatInfos= -wao.error.serviceBoat.exportBoatCsv= +wao.error.serviceBoat.createUpdateCompanyBoatInfos=Impossible de cr\u00E9er ou modifier les informations li\u00E9s au navire %1$d pour la soci\u00E9t\u00E9 %2$s +wao.error.serviceBoat.exportBoatCsv=Impossible d'exporter les navires s\u00E9lectionn\u00E9s wao.error.serviceBoat.getActivityCalendarLogAccessFile= wao.error.serviceBoat.getActivityCalendarLogFile= -wao.error.serviceBoat.getBoat= -wao.error.serviceBoat.getBoatNamesStartWith= -wao.error.serviceBoat.getBoatsByFilter= -wao.error.serviceBoat.getBoatsByImmatriculations= -wao.error.serviceBoat.getCompanyBoatInfos= -wao.error.serviceBoat.getLastActivityCalendar= -wao.error.serviceBoat.getNbBoatsByFilter= -wao.error.serviceBoat.importActivityCalendarCsv= -wao.error.serviceBoat.importBoatCsv= +wao.error.serviceBoat.getBoat=Impossible de charger le navire +wao.error.serviceBoat.getBoatNamesStartWith=Impossible de r\u00E9cup\u00E9rer les navires avec un nom commencant par '%1$s' +wao.error.serviceBoat.getBoatsByFilter=Impossible de filtrer la liste des navires +wao.error.serviceBoat.getBoatsByImmatriculations=La cha\u00EEne d'immatriculations est incorrect \! Chaque immatriculation doit poss\u00E9der 6 chiffres +wao.error.serviceBoat.getCompanyBoatInfos=Impossible de r\u00E9cup\u00E9rer les informations du navire immatricul\u00E9 %1$d pour la soci\u00E9t\u00E9 %2$s +wao.error.serviceBoat.getLastActivityCalendar=Impossible de charger le dernier calendrier d'activit\u00E9 du navire %1$s (%2$d) +wao.error.serviceBoat.getNbBoatsByFilter=Impossible de filtrer la liste des navires +wao.error.serviceBoat.importActivityCalendarCsv=Probl\u00E8me d'import du fichier CSV des calendriers d'activit\u00E9 +wao.error.serviceBoat.importBoatCsv=Probl\u00E8me d'import du fichier CSV. V\u00E9rifiez l'en-t\u00EAte du fichier \: [ NAVS_COD,CARN_NOM,CARN_LONGUEUR_HT,CARN_ANNEE,QUARTIER_IMMA,PER_COD,PER_NOM,PER_PRENOM,NAVS_ACTIVE ]. Voir documentation pour plus de d\u00E9tails. wao.error.serviceNews.getNews= wao.error.serviceNews.saveNews= wao.error.serviceReferential.getFacades=