Author: fdesbois Date: 2010-04-01 13:55:30 +0000 (Thu, 01 Apr 2010) New Revision: 404 Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceNewsImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties Log: Clean ServiceNewsImpl and ServiceReferentialImpl Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceNewsImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceNewsImpl.java 2010-04-01 13:51:21 UTC (rev 403) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceNewsImpl.java 2010-04-01 13:55:30 UTC (rev 404) @@ -47,83 +47,31 @@ private static final Logger logger = LoggerFactory.getLogger(ServiceNewsImpl.class); -// protected TopiaContext rootContext; -// -// public ServiceNewsImpl() throws WaoExceptionO { -// rootContext = WaoContextO.getTopiaRootContext(); -// } - @Override public List<News> executeGetNews(TopiaContext transaction) throws TopiaException { -// TopiaContext transaction = null; -// List<News> results = new ArrayList<News>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - NewsDAO dao = WaoDAOHelper.getNewsDAO(transaction); - - return dao.findAllWithOrder(TopiaEntity.TOPIA_CREATE_DATE + - " DESC"); + NewsDAO dao = WaoDAOHelper.getNewsDAO(transaction); -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getNews ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "Impossible de récupérer l'ensemble des news", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return results; + return dao.findAllWithOrder(TopiaEntity.TOPIA_CREATE_DATE + " DESC"); } @Override public void executeSaveNews(TopiaContext transaction, List<Object> errorArgs, News news, boolean delete) throws TopiaException { -// TopiaContext transaction = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - errorArgs.add(news.getTitle()); + errorArgs.add(news.getTitle()); - NewsDAO dao = WaoDAOHelper.getNewsDAO(transaction); + NewsDAO dao = WaoDAOHelper.getNewsDAO(transaction); - if (delete) { - dao.delete(news); - } else { - context.prepareTopiaId(News.class, news); - dao.update(news); - } + if (delete) { + dao.delete(news); + } else { + context.prepareTopiaId(News.class, news); + dao.update(news); + } - transaction.commitTransaction(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ saveNews ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "Impossible de récupérer l'ensemble des news", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + transaction.commitTransaction(); } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2010-04-01 13:51:21 UTC (rev 403) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2010-04-01 13:55:30 UTC (rev 404) @@ -57,90 +57,40 @@ private static final Logger log = LoggerFactory.getLogger(ServiceReferentialImpl.class); -// protected TopiaContext rootContext; -// -// public ServiceReferentialImpl() throws WaoExceptionO { -// rootContext = WaoContextO.getTopiaRootContext(); -// } - @Override public List<String> executeGetFacades(TopiaContext transaction, SamplingFilter filter) throws TopiaException { -// TopiaContext transaction = null; -// List<String> results = new ArrayList<String>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction); - TopiaQuery query = dao.createQuery("F"); + FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction); + TopiaQuery query = dao.createQuery("F"); - query = prepareQueryForFishingZoneFilter(query, filter); + query = prepareQueryForFishingZoneFilter(query, filter); - return (List<String>)query.addDistinct(). - setSelect("F." + FishingZone.FACADE_NAME).execute(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getFacades ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de charger la liste des facades", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return results; + return (List<String>)query.addDistinct(). + setSelect("F." + FishingZone.FACADE_NAME).execute(); } @Override public List<String> executeGetSectors(TopiaContext transaction, SamplingFilter filter) throws TopiaException { -// TopiaContext transaction = null; -// List<String> results = new ArrayList<String>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction); - TopiaQuery query = dao.createQuery("F"); + FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction); + TopiaQuery query = dao.createQuery("F"); - query = prepareQueryForFishingZoneFilter(query, filter); + query = prepareQueryForFishingZoneFilter(query, filter); - if (StringUtils.isNotEmpty(filter.getFacadeName())) { - query.add("F." + FishingZone.FACADE_NAME, filter.getFacadeName()); - } + if (StringUtils.isNotEmpty(filter.getFacadeName())) { + query.add("F." + FishingZone.FACADE_NAME, filter.getFacadeName()); + } - return (List<String>)query.addDistinct(). - setSelect("F." + FishingZone.SECTOR_NAME).execute(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getSectors ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de charger la liste des secteurs de pêche", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return results; + return (List<String>)query.addDistinct(). + setSelect("F." + FishingZone.SECTOR_NAME).execute(); } - protected TopiaQuery prepareQueryForFishingZoneFilter(TopiaQuery query, SamplingFilter filter) throws TopiaException { - if (filter.getCompany() != null || StringUtils.isNotEmpty(filter.getProgramName())) { + protected TopiaQuery prepareQueryForFishingZoneFilter(TopiaQuery query, + SamplingFilter filter) throws TopiaException { + if (filter.getCompany() != null || + StringUtils.isNotEmpty(filter.getProgramName())) { query.addFrom(SampleRow.class.getName() + " S"). add("S IN elements(F." + FishingZone.SAMPLE_ROW + ")"); } @@ -159,114 +109,54 @@ @Override public List<Profession> executeGetProfessions(TopiaContext transaction) throws TopiaException { -// TopiaContext transaction = null; -// List<Profession> results = new ArrayList<Profession>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - ProfessionDAO dao = WaoDAOHelper.getProfessionDAO(transaction); + ProfessionDAO dao = WaoDAOHelper.getProfessionDAO(transaction); - return dao.findAll(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getProfessions ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "Impossible de charger la liste des métiers", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return results; + return dao.findAll(); } @Override public List<FishingZone> executeGetFishingZones(TopiaContext transaction) throws TopiaException { -// TopiaContext transaction = null; -// List<FishingZone> results = new ArrayList<FishingZone>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction); + FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction); - return dao.findAll(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getFishingZones ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "Impossible de charger la liste des zones de pêche", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return results; + return dao.findAll(); } @Override public int executeImportFishingZoneCsv(TopiaContext transaction, InputStream input) throws TopiaException, IOException { -// TopiaContext transaction = null; int result = 0; -// try { -// transaction = rootContext.beginTransaction(); - CsvReader reader = new CsvReader(input, context.getCsvCharset()); - reader.readHeaders(); + CsvReader reader = new CsvReader(input, context.getCsvCharset()); + reader.readHeaders(); - FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction); + FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction); - while(reader.readRecord()) { - if (log.isTraceEnabled()) { - log.trace(" " + Arrays.asList(reader.getValues())); - } + while(reader.readRecord()) { + if (log.isTraceEnabled()) { + log.trace(" " + Arrays.asList(reader.getValues())); + } - String facadeName = - ImportHelper.read(reader, FISHING_ZONE.PECHE_FACADE); - String sectorName = - ImportHelper.read(reader, FISHING_ZONE.PECHE_ZONE); - String districtCode = - ImportHelper.read(reader, FISHING_ZONE.PECHE_DIVISION); + String facadeName = + ImportHelper.read(reader, FISHING_ZONE.PECHE_FACADE); + String sectorName = + ImportHelper.read(reader, FISHING_ZONE.PECHE_ZONE); + String districtCode = + ImportHelper.read(reader, FISHING_ZONE.PECHE_DIVISION); - FishingZone zone = dao.findByDistrictCode(districtCode); - - if (zone == null) { - zone = dao.create(FishingZone.DISTRICT_CODE, districtCode); - } - zone.setFacadeName(facadeName); - zone.setSectorName(sectorName); - result++; + FishingZone zone = dao.findByDistrictCode(districtCode); + + if (zone == null) { + zone = dao.create(FishingZone.DISTRICT_CODE, districtCode); } + zone.setFacadeName(facadeName); + zone.setSectorName(sectorName); + result++; + } - transaction.commitTransaction(); -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, -// "Problème d'import du fichier CSV. Vérifiez l'en-tête du fichier : [ PECHE_DIVISION," + -// "PECHE_ZONE,PECHE_FACADE ]. Voir documentation pour plus de détails.", -// eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + transaction.commitTransaction(); 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:51:21 UTC (rev 403) +++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-04-01 13:55:30 UTC (rev 404) @@ -17,10 +17,10 @@ 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= -wao.error.serviceReferential.getFishingZones= -wao.error.serviceReferential.getProfessions= -wao.error.serviceReferential.getSectors= -wao.error.serviceReferential.importFishingZoneCsv= +wao.error.serviceNews.getNews=Impossible de r\u00E9cup\u00E9rer l'ensemble des news +wao.error.serviceNews.saveNews=Impossible d'enregistrer la news ayant pour titre \'%1$s\' +wao.error.serviceReferential.getFacades=Impossible de charger la liste des facades +wao.error.serviceReferential.getFishingZones=Impossible de charger la liste des secteurs de p\u00EAche +wao.error.serviceReferential.getProfessions=Impossible de charger la liste des m\u00E9tiers +wao.error.serviceReferential.getSectors=Impossible de charger la liste des zones de p\u00EAche +wao.error.serviceReferential.importFishingZoneCsv=Probl\u00E8me d'import du fichier CSV. V\u00E9rifiez l'en-t\u00EAte du fichier : [ PECHE_DIVISION,PECHE_ZONE,PECHE_FACADE ]. Voir documentation pour plus de d\u00E9tails.