[Suiviobsmer-commits] r407 - in trunk: wao-business/src/main/java/fr/ifremer/wao wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/resources/i18n wao-business/src/main/xmi wao-business/src/test/java/fr/ifremer/wao wao-business/src/test/java/fr/ifremer/wao/entity wao-business/src/test/java/fr/ifremer/wao/service wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/java/fr/ifremer/wao/ui/services
Author: fdesbois Date: 2010-04-01 16:46:41 +0000 (Thu, 01 Apr 2010) New Revision: 407 Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatInfosImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowImplTest.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialImplTest.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java Log: use ServiceTransformer for ServiceSampling Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java 2010-04-01 16:46:41 UTC (rev 407) @@ -1,9 +1,16 @@ package fr.ifremer.wao; +import fr.ifremer.wao.entity.ActivityCalendar; +import java.io.IOException; import java.util.Date; +import org.apache.log4j.Level; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.RollingFileAppender; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Class only used for entities. The entities can't have WaoContext, so @@ -18,9 +25,14 @@ * par : $Author$ */ public class WaoUtils { + + private static final Logger logger = + LoggerFactory.getLogger(WaoUtils.class); private static WaoContextImplementor context; + private static org.apache.log4j.Logger activityCalendarAccessLogger; + static void setContext(WaoContextImplementor context) { WaoUtils.context = context; } @@ -36,7 +48,41 @@ public static Date getCurrentDate() { return context.getCurrentDate(); } + + // TEMP + public static void addActivityCalendarAccessLog(String message) + throws IOException { + if (activityCalendarAccessLogger == null) { + // Define appender configuration only once + String filename = + WaoProperty.FILENAME_LOG_ACTIVITY_ACCESS.getValue(); + PatternLayout layout = new PatternLayout(); + layout.setConversionPattern("%d %m%n"); + RollingFileAppender appender = new RollingFileAppender(); + appender.setName("ActivityCalendarAccess"); + appender.setFile(filename); + appender.setImmediateFlush(true); + appender.setMaxFileSize("2MB"); + appender.setMaxBackupIndex(10); + appender.setAppend(true); + appender.setThreshold(Level.INFO); + appender.setLayout(layout); + appender.activateOptions(); + + activityCalendarAccessLogger = + org.apache.log4j.Logger.getLogger(ActivityCalendar.class); + + activityCalendarAccessLogger.addAppender(appender); + } + + if (logger.isDebugEnabled()) { + logger.debug("message : " + message); + } + + activityCalendarAccessLogger.info(message); + } + /** * This method must be removed. Use {@link WaoContext} instance instead. * 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 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-04-01 16:46:41 UTC (rev 407) @@ -25,9 +25,9 @@ import com.csvreader.CsvWriter; import fr.ifremer.wao.WaoBusinessException; import fr.ifremer.wao.WaoBusinessException.Type; -import fr.ifremer.wao.WaoContextO; import fr.ifremer.wao.WaoDAOHelper; import fr.ifremer.wao.WaoProperty; +import fr.ifremer.wao.WaoUtils; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaQuery; import org.nuiton.topia.framework.TopiaQuery.Op; @@ -565,7 +565,7 @@ Company company = user.getCompany(); // FIXME-FD20100401 Find a way to avoid using old context for // logging access on ActivityCalendar - WaoContextO.addActivityCalendarAccessLog( + WaoUtils.addActivityCalendarAccessLog( "Calendrier " + result.getYear() + " du navire " + boat.getName() + " (" + boat.getImmatriculation() + ") vu " + "par " + user.getFullName() + " de la société " + Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-04-01 16:46:41 UTC (rev 407) @@ -28,7 +28,7 @@ import fr.ifremer.wao.WaoBusinessException.Type; import fr.ifremer.wao.WaoExceptionO; import fr.ifremer.wao.WaoDAOHelper; -import fr.ifremer.wao.WaoContextO; +import fr.ifremer.wao.WaoException; import fr.ifremer.wao.bean.FacadeRow; import fr.ifremer.wao.bean.FacadeRowImpl; import fr.ifremer.wao.bean.ImportResults; @@ -55,7 +55,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DurationFormatUtils; import org.nuiton.topia.TopiaContext; @@ -80,33 +79,35 @@ * Mise a jour: $Date$ * par : $Author$ */ -public class ServiceSamplingImpl implements ServiceSampling { +public class ServiceSamplingImpl extends ServiceSamplingAbstract { private static final Logger log = LoggerFactory.getLogger(ServiceSamplingImpl.class); - protected TopiaContext rootContext; - - public ServiceSamplingImpl() throws WaoExceptionO { - rootContext = WaoContextO.getTopiaRootContext(); +// protected TopiaContext rootContext; +// + public ServiceSamplingImpl() { +// rootContext = context.getTopiaRootContext(); prepareBinderForProfession(); } @Override - public void createUpdateSampleRow(SampleRow row, List<Boat> boats, SampleRowLog rowLog) throws WaoExceptionO { - TopiaContext transaction = null; + public void executeCreateUpdateSampleRow(TopiaContext transaction, + SampleRow row, List<Boat> boats, SampleRowLog rowLog) + throws TopiaException, Exception { +// TopiaContext transaction = null; TopiaContext transaction2 = null; try { - long startTime = 0; - if (log.isDebugEnabled()) { - startTime = System.currentTimeMillis(); - } - transaction = rootContext.beginTransaction(); +// long startTime = 0; +// if (log.isDebugEnabled()) { +// startTime = System.currentTimeMillis(); +// } +// transaction = rootContext.beginTransaction(); SampleRowLogDAO logDAO = WaoDAOHelper.getSampleRowLogDAO(transaction); - WaoContextO.prepareTopiaId(SampleRowLog.class, rowLog); + context.prepareTopiaId(SampleRowLog.class, rowLog); logDAO.update(rowLog); - boolean newRow = WaoContextO.prepareTopiaId(SampleRow.class, row); + boolean newRow = context.prepareTopiaId(SampleRow.class, row); if (log.isDebugEnabled()) { log.debug("new sampleRow : " + newRow); @@ -121,7 +122,7 @@ Company oldCompany = null; Map<String, SampleMonth> oldMonths = new HashMap<String, SampleMonth>(); List<FishingZone> oldZones = new ArrayList<FishingZone>(); - transaction2 = rootContext.beginTransaction(); + transaction2 = context.beginTransaction(); // UPDATE if (!newRow) { // Prepare data for logging or deleting oldMonths @@ -161,7 +162,7 @@ // Save Profession ProfessionDAO professionDAO = WaoDAOHelper.getProfessionDAO(transaction); - WaoContextO.prepareTopiaId(Profession.class, row.getProfession()); + context.prepareTopiaId(Profession.class, row.getProfession()); rowLog.addChangeProfession(oldProfession, row.getProfession()); professionDAO.update(row.getProfession()); @@ -181,7 +182,7 @@ } // Create or update months for (SampleMonth month : newMonths) { - boolean monthCreated = WaoContextO.prepareTopiaId(SampleMonth.class, month); + boolean monthCreated = context.prepareTopiaId(SampleMonth.class, month); String date = dateFormat.format(month.getPeriodDate()); if (monthCreated) { // log create month @@ -247,23 +248,24 @@ } transaction.commitTransaction(); - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ createUpdateSampleRow ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - } +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ createUpdateSampleRow ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// } //transaction.closeContext(); } catch (Exception eee) { - WaoContextO.serviceException(transaction, - "Impossible de sauvegarder la ligne d'échantillon", eee); + throw eee; +// context.serviceException(transaction, +// "Impossible de sauvegarder la ligne d'échantillon", eee); } finally { - try { +// try { transaction2.closeContext(); - } catch (TopiaException eee) { - log.error("Error closing transaction", eee); - } - WaoContextO.closeTransaction(transaction); +// } catch (TopiaException eee) { +// log.error("Error closing transaction", eee); +// } +// context.closeTransaction(transaction); } } @@ -299,18 +301,20 @@ // } @Override - public FacadeRow getSampleRowsOrderedByFishingZone(PeriodDates period, Company company) throws WaoExceptionO { - TopiaContext transaction = null; + public FacadeRow executeGetSampleRowsOrderedByFishingZone( + TopiaContext transaction, + PeriodDates period, Company company) throws TopiaException { +// TopiaContext transaction = null; FacadeRow result = new FacadeRowImpl(); - try { - long startTime = 0; - if (log.isDebugEnabled()) { - startTime = System.currentTimeMillis(); - } +// try { +// long startTime = 0; +// if (log.isDebugEnabled()) { +// startTime = System.currentTimeMillis(); +// } if (period.getFromDate() == null || period.getThruDate() == null) { throw new IllegalArgumentException("PeriodBegin date and/or PeriodEnd date can't be null !"); } - transaction = rootContext.beginTransaction(); +// transaction = rootContext.beginTransaction(); SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); @@ -333,13 +337,13 @@ // Load data //query.addLoad(SampleRow.PROFESSION, SampleRow.COMPANY); - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ before query getSampleRowsOrderedByFishingZone ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - startTime = System.currentTimeMillis(); - } +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ before query getSampleRowsOrderedByFishingZone ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// startTime = System.currentTimeMillis(); +// } if (log.isDebugEnabled()) { log.debug("Query : " + query); @@ -353,33 +357,34 @@ result.addRow(row); } - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ getSampleRowsOrderedByFishingZone exec query ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - } - - //transaction.closeContext(); - } catch (Exception eee) { - WaoContextO.serviceException(transaction, - "Impossible de récupérer la liste des lignes du plan d'échantillonnage", eee); - } finally { - WaoContextO.closeTransaction(transaction); - } +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ getSampleRowsOrderedByFishingZone exec query ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// } +// +// //transaction.closeContext(); +// } catch (Exception eee) { +// context.serviceException(transaction, +// "Impossible de récupérer la liste des lignes du plan d'échantillonnage", eee); +// } finally { +// context.closeTransaction(transaction); +// } return result; } @Override - public List<String> getPrograms(Company company) throws WaoExceptionO { - TopiaContext transaction = null; - List<String> results = new ArrayList<String>(); - try { - long startTime = 0; - if (log.isDebugEnabled()) { - startTime = System.currentTimeMillis(); - } - transaction = rootContext.beginTransaction(); + public List<String> executeGetPrograms(TopiaContext transaction, + Company company) throws TopiaException { +// TopiaContext transaction = null; +// List<String> results = new ArrayList<String>(); +// try { +// long startTime = 0; +// if (log.isDebugEnabled()) { +// startTime = System.currentTimeMillis(); +// } +// transaction = rootContext.beginTransaction(); SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); TopiaQuery query = dao.createQuery(); @@ -388,127 +393,139 @@ query.add(SampleRow.COMPANY, company); } - results = (List<String>)query.setSelect("DISTINCT " + SampleRow.PROGRAM_NAME).execute(); + return (List<String>)query.addDistinct(). + setSelect(SampleRow.PROGRAM_NAME).execute(); - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ getPrograms ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - } - - //transaction.closeContext(); - } catch (Exception eee) { - WaoContextO.serviceException(transaction, - "Impossible de charger la liste des programmes", eee); - } finally { - WaoContextO.closeTransaction(transaction); - } - return results; +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ getPrograms ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// } +// +// //transaction.closeContext(); +// } catch (Exception eee) { +// context.serviceException(transaction, +// "Impossible de charger la liste des programmes", eee); +// } finally { +// context.closeTransaction(transaction); +// } +// return results; } @Override - public List<SampleRow> getSampleRowsByFilter(SamplingFilter filter) throws WaoExceptionO { - TopiaContext transaction = null; - List<SampleRow> results = new ArrayList<SampleRow>(); - try { - long startTime = 0; - if (log.isDebugEnabled()) { - startTime = System.currentTimeMillis(); - } - transaction = rootContext.beginTransaction(); + public List<SampleRow> executeGetSampleRowsByFilter( + TopiaContext transaction, SamplingFilter filter) + throws TopiaException { +// TopiaContext transaction = null; +// List<SampleRow> results = new ArrayList<SampleRow>(); +// try { +// long startTime = 0; +// if (log.isDebugEnabled()) { +// startTime = System.currentTimeMillis(); +// } +// transaction = rootContext.beginTransaction(); SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); - TopiaQuery query = dao.createQuery("S").addDistinct().addOrder("S." + SampleRow.CODE); + TopiaQuery query = dao.createQuery("S"). + addDistinct().addOrder("S." + SampleRow.CODE); query = filter.prepareQueryForSampling(query, "S"); - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ after prepareQueryForSampling ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - startTime = System.currentTimeMillis(); - } +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ after prepareQueryForSampling ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// startTime = System.currentTimeMillis(); +// } if (log.isDebugEnabled()) { log.debug("Query : " + query); } - results = dao.findAllByQuery(query); + return dao.findAllByQuery(query); - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ getSampleRowsByFilter exec query ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - startTime = System.currentTimeMillis(); - } - - //transaction.closeContext(); - } catch (Exception eee) { - WaoContextO.serviceException(transaction, - "Impossible de récupérer la liste des lignes du plan d'échantillonnage", eee); - } finally { - WaoContextO.closeTransaction(transaction); - } - return results; +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ getSampleRowsByFilter exec query ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// startTime = System.currentTimeMillis(); +// } +// +// //transaction.closeContext(); +// } catch (Exception eee) { +// context.serviceException(transaction, +// "Impossible de récupérer la liste des lignes du plan d'échantillonnage", eee); +// } finally { +// context.closeTransaction(transaction); +// } +// return results; } @Override - public SampleRow getSampleRow(String sampleRowId) throws WaoExceptionO { - TopiaContext transaction = null; - SampleRow result = null; - try { - long startTime = 0; - if (log.isDebugEnabled()) { - startTime = System.currentTimeMillis(); - } - transaction = rootContext.beginTransaction(); + public SampleRow executeGetSampleRow(TopiaContext transaction, + List<Object> errorArgs, String sampleRowId) throws TopiaException { +// TopiaContext transaction = null; +// SampleRow result = null; +// try { +// long startTime = 0; +// if (log.isDebugEnabled()) { +// startTime = System.currentTimeMillis(); +// } +// transaction = rootContext.beginTransaction(); + errorArgs.add(sampleRowId); + SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); - result = dao.findByTopiaId(sampleRowId); + SampleRow result = dao.findByTopiaId(sampleRowId); result.sizeSampleMonth(); result.sizeElligibleBoat(); - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ getSampleRow ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - } + return result; - //transaction.closeContext(); - } catch (Exception eee) { - WaoContextO.serviceException(transaction, - "Impossible de charger la ligne d'échantillon ayant pour" + - " identifiant : " + sampleRowId, - eee); - } finally { - WaoContextO.closeTransaction(transaction); - } - return result; +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ getSampleRow ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// } +// +// //transaction.closeContext(); +// } catch (Exception eee) { +// context.serviceException(transaction, +// "Impossible de charger la ligne d'échantillon ayant pour" + +// " identifiant : " + sampleRowId, +// eee); +// } finally { +// context.closeTransaction(transaction); +// } +// return result; } @Override - public SampleRow getSampleRowByCode(WaoUser user, String sampleRowCode) - throws WaoExceptionO { - TopiaContext transaction = null; - SampleRow result = null; - try { - long startTime = 0; - if (log.isDebugEnabled()) { - startTime = System.currentTimeMillis(); - } - if (log.isInfoEnabled()) { - log.info("W:[ getSampleRowByCode ] : " + - "sampleRowCode = " + sampleRowCode); - } - transaction = rootContext.beginTransaction(); + public SampleRow executeGetSampleRowByCode(TopiaContext transaction, + List<Object> errorArgs, WaoUser user, String sampleRowCode) + throws TopiaException, WaoBusinessException { +// TopiaContext transaction = null; +// SampleRow result = null; +// try { +// long startTime = 0; +// if (log.isDebugEnabled()) { +// startTime = System.currentTimeMillis(); +// } +// if (log.isInfoEnabled()) { +// log.info("W:[ getSampleRowByCode ] : " + +// "sampleRowCode = " + sampleRowCode); +// } +// transaction = rootContext.beginTransaction(); + errorArgs.add(sampleRowCode); + SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); TopiaQuery query = dao.createQuery(). @@ -519,7 +536,7 @@ } query.addLoad(SampleRow.SAMPLE_ROW_LOG); - result = dao.findByQuery(query); + SampleRow result = dao.findByQuery(query); if (result == null) { throw new WaoBusinessException(Type.NOT_EXISTS, @@ -527,34 +544,39 @@ "pour code " + sampleRowCode + " est introuvable !"); } - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ getSampleRowByCode ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - } - - } catch (Exception eee) { - WaoContextO.serviceException(transaction, - "Impossible de charger la ligne " + - "d'échantillon ayant pour code : " + sampleRowCode, - eee); - } finally { - WaoContextO.closeTransaction(transaction); - } - return result; + return result; + +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ getSampleRowByCode ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// } +// +// } catch (Exception eee) { +// context.serviceException(transaction, +// "Impossible de charger la ligne " + +// "d'échantillon ayant pour code : " + sampleRowCode, +// eee); +// } finally { +// context.closeTransaction(transaction); +// } +// return result; } @Override - public void deleteSampleRow(SampleRow sampleRow) throws WaoExceptionO { - TopiaContext transaction = null; - try { - long startTime = 0; - if (log.isDebugEnabled()) { - startTime = System.currentTimeMillis(); - } - transaction = rootContext.beginTransaction(); + public void executeDeleteSampleRow(TopiaContext transaction, + List<Object> errorArgs, SampleRow sampleRow) throws TopiaException { +// TopiaContext transaction = null; +// try { +// long startTime = 0; +// if (log.isDebugEnabled()) { +// startTime = System.currentTimeMillis(); +// } +// transaction = rootContext.beginTransaction(); + errorArgs.add(sampleRow.getCode()); + SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); SampleRow row = dao.findByTopiaId(sampleRow.getTopiaId()); @@ -563,44 +585,47 @@ transaction.commitTransaction(); - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ deleteSampleRow ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - } - //transaction.closeContext(); - } catch (Exception eee) { - WaoContextO.serviceException(transaction, - "Impossible de supprimer la ligne d'échantillon : " + sampleRow.getCode(), - eee); - } finally { - WaoContextO.closeTransaction(transaction); - } +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ deleteSampleRow ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// } +// //transaction.closeContext(); +// } catch (Exception eee) { +// context.serviceException(transaction, +// "Impossible de supprimer la ligne d'échantillon : " + sampleRow.getCode(), +// eee); +// } finally { +// context.closeTransaction(transaction); +// } } @Override - public String getNewSampleRowCode(Date beginDate) throws WaoExceptionO { - TopiaContext transaction = null; - String result = null; + public String executeGetNewSampleRowCode(TopiaContext transaction, + Date beginDate) throws TopiaException { +// TopiaContext transaction = null; +// String result = null; if (beginDate == null) { - return result; + return null; } - try { - long startTime = 0; - if (log.isDebugEnabled()) { - startTime = System.currentTimeMillis(); - } - transaction = rootContext.beginTransaction(); +// try { +// long startTime = 0; +// if (log.isDebugEnabled()) { +// startTime = System.currentTimeMillis(); +// } +// transaction = rootContext.beginTransaction(); Calendar begin = new GregorianCalendar(); begin.setTime(beginDate); int year = begin.get(Calendar.YEAR); SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); - TopiaQuery query = dao.createQuery().add(SampleRow.CODE, Op.LIKE, year + "_%"); + TopiaQuery query = + dao.createQuery().add(SampleRow.CODE, Op.LIKE, year + "_%"); - String maxCode = query.executeToString("MAX(" + SampleRow.CODE + ")"); + String maxCode = + query.executeToString("MAX(" + SampleRow.CODE + ")"); if (log.isDebugEnabled()) { log.debug("Max code found : " + maxCode); @@ -612,28 +637,28 @@ num = Integer.parseInt(part[1]) + 1; } String str = StringUtils.leftPad("" + num, 4, "0"); - result = year + "_" + str; + return year + "_" + str; - if (log.isDebugEnabled()) { - long stopTime = System.currentTimeMillis(); - log.debug("W:[ getNewSampleRowCode ] Time = " + - DurationFormatUtils.formatDurationHMS( - stopTime - startTime)); - } - - //transaction.closeContext(); - } catch (Exception eee) { - WaoContextO.serviceException(transaction, - "Impossible de récupérer un nouveau code pour une ligne d'échantillonnage", - eee); - } finally { - WaoContextO.closeTransaction(transaction); - } - return result; +// if (log.isDebugEnabled()) { +// long stopTime = System.currentTimeMillis(); +// log.debug("W:[ getNewSampleRowCode ] Time = " + +// DurationFormatUtils.formatDurationHMS( +// stopTime - startTime)); +// } +// +// //transaction.closeContext(); +// } catch (Exception eee) { +// context.serviceException(transaction, +// "Impossible de récupérer un nouveau code pour une ligne d'échantillonnage", +// eee); +// } finally { +// context.closeTransaction(transaction); +// } +// return result; } @Override - public SampleRow getNewSampleRow() { + public SampleRow executeGetNewSampleRow() { SampleRow row = new SampleRowImpl(); row.setProfession(new ProfessionImpl()); row.setFishingZone(new ArrayList<FishingZone>()); @@ -644,7 +669,7 @@ } @Override - public SampleMonth getNewSampleMonth(Date period, SampleRow row) { + public SampleMonth executeGetNewSampleMonth(Date period, SampleRow row) { SampleMonth month = new SampleMonthImpl(); month.setSampleRow(row); month.setPeriodDate(period); @@ -660,7 +685,7 @@ * @return a new Profession */ @Override - public Profession getNewProfession(Profession profession) { + public Profession executeGetNewProfession(Profession profession) { Profession newProfession = new ProfessionImpl(); // Use of Binder previously initialized to copy the existing // profession in a new one @@ -690,18 +715,24 @@ } @Override - public InputStream exportSamplingPlanCsv(WaoUser user, PeriodDates period) throws WaoExceptionO { - TopiaContext transaction = null; - InputStream result = null; + public InputStream executeExportSamplingPlanCsv(TopiaContext transaction, + List<Object> errorArgs, WaoUser user, PeriodDates period) + throws TopiaException, Exception { +// TopiaContext transaction = null; +// InputStream result = null; CsvWriter writer = null; try { - transaction = rootContext.beginTransaction(); +// transaction = rootContext.beginTransaction(); + DateFormat dateFormat = SAMPLING.getDateFormat(); + errorArgs.add(dateFormat.format(period.getFromDate())); + errorArgs.add(dateFormat.format(period.getThruDate())); + File file = File.createTempFile("wao-samplingPlan-", ".csv"); file.deleteOnExit(); FileOutputStream output = new FileOutputStream(file); - writer = new CsvWriter(output, ',', WaoContextO.getCsvCharset()); + writer = new CsvWriter(output, ',', context.getCsvCharset()); // Get min and max dates to have the biggest period // Date min = (Date)query.executeToObject("MIN(S." + SampleRow.PERIOD_BEGIN + ")"); @@ -711,7 +742,8 @@ period.setPattern(SAMPLING.defaultDatePattern()); List<String> monthHeaders = period.getFormatedMonths(); - SamplingExport export = new SamplingExport(writer, user, monthHeaders); + SamplingExport export = + new SamplingExport(writer, user, monthHeaders); export.writeHeaders(); @@ -733,7 +765,6 @@ List<SampleRow> rows = dao.findAllByQuery(query); - DateFormat dateFormat = SAMPLING.getDateFormat(); NumberFormat numberFormat = SAMPLING.getNumberFormat(); for (SampleRow row : rows) { @@ -806,34 +837,41 @@ export.writeRecord(); } - result = new FileInputStream(file); + return new FileInputStream(file); } catch (Exception eee) { - DateFormat dateFormat = SAMPLING.getDateFormat(); - WaoContextO.serviceException(transaction, - "Impossible d'exporter le plan d'échantillonnage sur la période du " + - dateFormat.format(period.getFromDate()) + " au " + - dateFormat.format(period.getThruDate()), eee); + throw eee; +// DateFormat dateFormat = SAMPLING.getDateFormat(); +// context.serviceException(transaction, +// "Impossible d'exporter le plan d'échantillonnage sur la période du " + +// dateFormat.format(period.getFromDate()) + " au " + +// dateFormat.format(period.getThruDate()), eee); } finally { if (writer != null) { writer.close(); } - WaoContextO.closeTransaction(transaction); +// context.closeTransaction(transaction); } - return result; + } @Override - public ImportResults importSamplingPlanCsv(InputStream input) throws WaoExceptionO { - TopiaContext transaction = null; + public ImportResults executeImportSamplingPlanCsv(TopiaContext transaction, + List<Object> errorArgs, InputStream input) + throws WaoBusinessException, IOException, + TopiaException, ParseException { +// TopiaContext transaction = null; ImportResults result = new ImportResultsImpl(); //int[] result = new int[3]; int currRow = 0; SampleRow row = null; - try { - transaction = rootContext.beginTransaction(); +// try { +// transaction = rootContext.beginTransaction(); - CsvReader reader = new CsvReader(input, WaoContextO.getCsvCharset()); + errorArgs.add(currRow); + errorArgs.add(null); + + CsvReader reader = new CsvReader(input, context.getCsvCharset()); reader.readHeaders(); SampleRowDAO dao = WaoDAOHelper.getSampleRowDAO(transaction); @@ -855,6 +893,9 @@ continue; } + errorArgs.set(0, currRow); + errorArgs.set(1, code); + String districts = ImportHelper.read(reader, FISHING_ZONE.PECHE_DIVISION); @@ -901,21 +942,21 @@ //transaction.closeContext(); - } catch (NumberFormatException eee) { - WaoContextO.serviceException(transaction, - "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "] : " + - "Le format de la durée moyenne des marées est incorrect, il doit être de la forme : 1.9 ", eee); - } catch (ParseException eee) { - WaoContextO.serviceException(transaction, - "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "] : " + - "Le format des dates est incorrect, il doit être de la forme : MM/AAAA", eee); - } catch (Exception eee) { - WaoContextO.serviceException(transaction, - "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "]", - eee); - } finally { - WaoContextO.closeTransaction(transaction); - } +// } catch (NumberFormatException eee) { +// context.serviceException(transaction, +// "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "] : " + +// "Le format de la durée moyenne des marées est incorrect, il doit être de la forme : 1.9 ", eee); +// } catch (ParseException eee) { +// context.serviceException(transaction, +// "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "] : " + +// "Le format des dates est incorrect, il doit être de la forme : MM/AAAA", eee); +// } catch (Exception eee) { +// context.serviceException(transaction, +// "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "]", +// eee); +// } finally { +// context.closeTransaction(transaction); +// } return result; } @@ -976,10 +1017,10 @@ * @param currRow Row number in the line for the SampleRow * @param row SampleRow linked with districts (from Csv file) * @throws TopiaException for dao errors - * @throws WaoException if a FishingZone doesn't exist. + * @throws WaoBusinessException if a FishingZone doesn't exist. */ protected void importFishingZones(TopiaContext transaction, String districts, int currRow, SampleRow row) - throws TopiaException, WaoExceptionO { + throws TopiaException, WaoBusinessException { FishingZoneDAO dao = WaoDAOHelper.getFishingZoneDAO(transaction); Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-04-01 16:46:41 UTC (rev 407) @@ -60,128 +60,81 @@ private static final Logger log = LoggerFactory.getLogger(ServiceUserImpl.class); -// protected TopiaContext rootContext; -// -// public ServiceUserImpl() throws WaoExceptionO { -// rootContext = WaoContextO.getTopiaRootContext(); -// } - @Override public WaoUser executeConnect(TopiaContext transaction, String login, String password) throws TopiaException, WaoBusinessException { -// TopiaContext transaction = null; -// WaoUser user = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); + WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); - String passwordEncoded = context.encodeString(password); - WaoUser user = dao.findByProperties( - WaoUser.LOGIN, login, - WaoUser.PASSWORD, passwordEncoded); + String passwordEncoded = context.encodeString(password); + WaoUser user = dao.findByProperties( + WaoUser.LOGIN, login, + WaoUser.PASSWORD, passwordEncoded); - if (user != null && user.getActive()) { - // load company entity - user.getCompany(); - } else if (user != null && !user.getActive()) { - throw new WaoBusinessException(Type.ILLEGAL_CONNECTION, - this.getClass(), - "Vous n'avez plus les droits nécessaires pour" + - " vous connecter. Veuillez contacter un" + - " administrateur."); - } else { - throw new WaoBusinessException(Type.BAD_CONNECTION, - this.getClass(), - "Identifiant ou mot de passe incorrects, " + - "veuillez réessayer."); - } + if (user != null && user.getActive()) { + // load company entity + user.getCompany(); + } else if (user != null && !user.getActive()) { + throw new WaoBusinessException(Type.ILLEGAL_CONNECTION, + this.getClass(), + "Vous n'avez plus les droits nécessaires pour" + + " vous connecter. Veuillez contacter un" + + " administrateur."); + } else { + throw new WaoBusinessException(Type.BAD_CONNECTION, + this.getClass(), + "Identifiant ou mot de passe incorrects, " + + "veuillez réessayer."); + } - return user; - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ connect ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Une erreur est survenue lors de la demande de connexion", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + return user; } @Override public void executeForgetPassword(TopiaContext transaction, - String login) throws WaoBusinessException, TopiaException, EmailException { -// TopiaContext transaction = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } - if (!login.contains("@")) { - throw new WaoBusinessException(Type.SYNTAX, - this.getClass(), "Votre identifiant n'est pas" + - " un email valide, " + - "veuillez contacter un administrateur pour " + - "qu'il puisse changer votre mot de passe."); - } + String login) throws WaoBusinessException, TopiaException, + EmailException { -// transaction = rootContext.beginTransaction(); + if (!login.contains("@")) { + throw new WaoBusinessException(Type.SYNTAX, + this.getClass(), "Votre identifiant n'est pas" + + " un email valide, " + + "veuillez contacter un administrateur pour " + + "qu'il puisse changer votre mot de passe."); + } - WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); + WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); - WaoUser user = dao.findByLogin(login); - if (user == null) { - throw new WaoBusinessException(Type.NOT_EXISTS, - this.getClass(), - "L'email '" + login + "' n'est pas " + - "référencé dans l'application."); - } + WaoUser user = dao.findByLogin(login); + if (user == null) { + throw new WaoBusinessException(Type.NOT_EXISTS, + this.getClass(), + "L'email '" + login + "' n'est pas " + + "référencé dans l'application."); + } - String password = context.createRandomString(8); - String passwordEncoded = context.encodeString(password); - user.setPassword(passwordEncoded); + String password = context.createRandomString(8); + String passwordEncoded = context.encodeString(password); + user.setPassword(passwordEncoded); - String subject = "[WAO] Mot de passe oublié"; - String msg = "Bonjour,\n\n" + - "\tUn nouveau mot de passe a été généré pour votre" + - " identifiant " + login + " :\n" + - "\t\t * mot de passe = " + password + "\n\n" + - "Vous pouvez modifier votre password en accédant à " + - "la page de gestion de votre profile utilisateur :\n\n" + - "\t\thttp://" + WaoProperty.SERVER_PATH.getValue() + "\n\n" + - "Cordialement,\n\n" + - "L'Equipe WAO"; + String subject = "[WAO] Mot de passe oublié"; + String msg = "Bonjour,\n\n" + + "\tUn nouveau mot de passe a été généré pour votre" + + " identifiant " + login + " :\n" + + "\t\t * mot de passe = " + password + "\n\n" + + "Vous pouvez modifier votre password en accédant à " + + "la page de gestion de votre profile utilisateur :\n\n" + + "\t\thttp://" + WaoProperty.SERVER_PATH.getValue() + "\n\n" + + "Cordialement,\n\n" + + "L'Equipe WAO"; - context.sendEmail(user.getLogin(), subject, msg); - if (log.isDebugEnabled()) { - log.debug("send email to : " + user.getLogin()); - } + context.sendEmail(user.getLogin(), subject, msg); + if (log.isDebugEnabled()) { + log.debug("send email to : " + user.getLogin()); + } - transaction.commitTransaction(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ forgetPassword ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de créer ou de mettre à jour l'utilisateur", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + transaction.commitTransaction(); } @Override @@ -189,326 +142,205 @@ WaoUser user, boolean generatePassword) throws TopiaException, IllegalArgumentException, WaoBusinessException, EmailException { -// TopiaContext transaction = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } - if (user == null) { - throw new IllegalArgumentException("user parameter can't be null"); - } -// transaction = rootContext.beginTransaction(); + if (user == null) { + throw new IllegalArgumentException("user parameter can't be null"); + } - WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); - - boolean newUser = context.prepareTopiaId(WaoUser.class, user); + WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); - // Check for a new user if login already exists - if (newUser) { - WaoUser existUser = dao.findByLogin(user.getLogin()); - if (existUser != null) { - throw new WaoBusinessException(Type.ALREADY_EXISTS, - this.getClass(), - "Un utilisateur existe déjà avec ce login " + - user.getLogin()); - } + boolean newUser = context.prepareTopiaId(WaoUser.class, user); + + // Check for a new user if login already exists + if (newUser) { + WaoUser existUser = dao.findByLogin(user.getLogin()); + if (existUser != null) { + throw new WaoBusinessException(Type.ALREADY_EXISTS, + this.getClass(), + "Un utilisateur existe déjà avec ce login " + + user.getLogin()); } + } - String password = user.getPassword(); + String password = user.getPassword(); - if (generatePassword) { - password = context.createRandomString(8); - user.setPasswordChanged(true); + if (generatePassword) { + password = context.createRandomString(8); + user.setPasswordChanged(true); // if (log.isDebugEnabled()) { // log.debug("show generated password : " + password); // } - } - // For a password set manually by user or generated - if (user.isPasswordChanged()) { - String passwordEncoded = context.encodeString(password); - user.setPassword(passwordEncoded); - } - - dao.update(user); + } + // For a password set manually by user or generated + if (user.isPasswordChanged()) { + String passwordEncoded = context.encodeString(password); + user.setPassword(passwordEncoded); + } - // FIXME-JC20100122 Use REGEX instead of @ to test if the login is - // a valid email - if (user.getLogin().contains("@") && user.isPasswordChanged()) { - String subject = "[WAO] "; - String msg = "Bonjour,\n\n"; - if (newUser) { - subject += "Création de votre compte"; - msg += "\tVous avez été inscris sur le site WAO :" + - " Web Applicatif Obsmer. Vos identifiants de " + - "connexion sont :\n" + - "\t\t * identifiant = " + user.getLogin() + "\n" + - "\t\t * mot de passe = " + password + "\n\n" + - "Vous pouvez modifier votre mot de passe en " + - "accédant à la page de gestion de votre profil" + - " utilisateur:\n\n" + - "\t\thttp://" + WaoProperty.SERVER_PATH.getValue() + "\n\n"; + dao.update(user); + + // FIXME-JC20100122 Use REGEX instead of @ to test if the login is + // a valid email + if (user.getLogin().contains("@") && user.isPasswordChanged()) { + String subject = "[WAO] "; + String msg = "Bonjour,\n\n"; + if (newUser) { + subject += "Création de votre compte"; + msg += "\tVous avez été inscris sur le site WAO :" + + " Web Applicatif Obsmer. Vos identifiants de " + + "connexion sont :\n" + + "\t\t * identifiant = " + user.getLogin() + "\n" + + "\t\t * mot de passe = " + password + "\n\n" + + "Vous pouvez modifier votre mot de passe en " + + "accédant à la page de gestion de votre profil" + + " utilisateur:\n\n" + + "\t\thttp://" + WaoProperty.SERVER_PATH.getValue() + "\n\n"; + } else { + subject += "Modification de votre compte"; + if (generatePassword) { + msg += "\tVotre mot de passe de connexion à " + + "l'application WAO a été modifié : " + + "" + password + "\n\n"; } else { - subject += "Modification de votre compte"; - if (generatePassword) { - msg += "\tVotre mot de passe de connexion à " + - "l'application WAO a été modifié : " + - "" + password + "\n\n"; - } else { - msg += "\tVotre changement de mot de passe à bien " + - "été enregistré.\n" + - "Pour des raisons de sécurité, le nouveau " + - "mot de passe n'est pas précisé dans ce message.\n" + - "Vous pouvez faire une nouvelle demande " + - "de mot de passe en cas de perte sur la" + - " page de connexion ou en " + - "répondant à ce message.\n\n"; - } + msg += "\tVotre changement de mot de passe à bien " + + "été enregistré.\n" + + "Pour des raisons de sécurité, le nouveau " + + "mot de passe n'est pas précisé dans ce message.\n" + + "Vous pouvez faire une nouvelle demande " + + "de mot de passe en cas de perte sur la" + + " page de connexion ou en " + + "répondant à ce message.\n\n"; } - msg += "Cordialement,\n\n" + - "L'Equipe WAO"; - - context.sendEmail(user.getLogin(), subject, msg); + } + msg += "Cordialement,\n\n" + + "L'Equipe WAO"; + + context.sendEmail(user.getLogin(), subject, msg); // if (log.isDebugEnabled()) { // log.debug("send email to : " + user.getLogin()); // } - } + } - transaction.commitTransaction(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ createUpdateUser ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de créer ou de mettre à jour l'utilisateur", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + transaction.commitTransaction(); } @Override public void executeDeleteUser(TopiaContext transaction , WaoUser user) throws WaoBusinessException, TopiaException { -// TopiaContext transaction = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - String userType = StringUtils.lowerCase( - user.getUserRole().getLibelle()); - String msgBegin = "L'" + userType + " '" + user.getLogin() + "'" + - " ne peut pas être supprimé"; - String msgEnd = "Vous pouvez cependant le désactiver pour qu'il" + - " ne puisse plus se connecter."; + String userType = StringUtils.lowerCase( + user.getUserRole().getLibelle()); + String msgBegin = "L'" + userType + " '" + user.getLogin() + "'" + + " ne peut pas être supprimé"; + String msgEnd = "Vous pouvez cependant le désactiver pour qu'il" + + " ne puisse plus se connecter."; - boolean isCoordinator = - user.getUserRole().equals(UserRole.COORDINATOR); + boolean isCoordinator = + user.getUserRole().equals(UserRole.COORDINATOR); - if (user.isAdmin() || isCoordinator) { - SampleRowLogDAO logDAO = - WaoDAOHelper.getSampleRowLogDAO(transaction); - List<SampleRowLog> results = logDAO.findAllByAuthor(user); - - if (!results.isEmpty()) { - String msg = ""; - if (isCoordinator) { - msg = " car il a ajouté des commentaires sur le plan " + - "d'échantillonnage."; - } else { - msg = " car il a participé" + - " à la modification du plan d'échantillonnage. "; - } - throw new WaoBusinessException(Type.ALREADY_EXISTS, - this.getClass(), msgBegin + msg + msgEnd); - } - } else { + if (user.isAdmin() || isCoordinator) { + SampleRowLogDAO logDAO = + WaoDAOHelper.getSampleRowLogDAO(transaction); + List<SampleRowLog> results = logDAO.findAllByAuthor(user); - ContactDAO contactDAO = - WaoDAOHelper.getContactDAO(transaction); - List<Contact> results = contactDAO.findAllByObserver(user); - - if (!results.isEmpty()) { - throw new WaoBusinessException(Type.ALREADY_EXISTS, - this.getClass(), - msgBegin + " car il est lié à plusieurs contacts" + - " existants. " + msgEnd); + if (!results.isEmpty()) { + String msg = ""; + if (isCoordinator) { + msg = " car il a ajouté des commentaires sur le plan " + + "d'échantillonnage."; + } else { + msg = " car il a participé" + + " à la modification du plan d'échantillonnage. "; } + throw new WaoBusinessException(Type.ALREADY_EXISTS, + this.getClass(), msgBegin + msg + msgEnd); } + } else { + ContactDAO contactDAO = + WaoDAOHelper.getContactDAO(transaction); + List<Contact> results = contactDAO.findAllByObserver(user); - WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); + if (!results.isEmpty()) { + throw new WaoBusinessException(Type.ALREADY_EXISTS, + this.getClass(), + msgBegin + " car il est lié à plusieurs contacts" + + " existants. " + msgEnd); + } + } - dao.delete(user); - transaction.commitTransaction(); + WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ deleteUser ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de créer ou" + -// " de mettre à jour l'utilisateur", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + dao.delete(user); + + transaction.commitTransaction(); } @Override public void executeCreateUpdateCompany(TopiaContext transaction, Company company) throws TopiaException, IllegalArgumentException { -// TopiaContext transaction = null; -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } - if (company == null) { - throw new IllegalArgumentException("company parameter can't be null"); - } -// transaction = rootContext.beginTransaction(); + if (company == null) { + throw new IllegalArgumentException("company parameter " + + "can't be null"); + } - CompanyDAO dao = WaoDAOHelper.getCompanyDAO(transaction); + CompanyDAO dao = WaoDAOHelper.getCompanyDAO(transaction); - context.prepareTopiaId(Company.class, company); - dao.update(company); + context.prepareTopiaId(Company.class, company); + dao.update(company); - transaction.commitTransaction(); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ createUpdateCompany ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// //transaction.closeContext(); -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de créer ou de mettre à jour la société", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + transaction.commitTransaction(); } @Override public List<Company> executeGetCompanies(TopiaContext transaction, boolean activeOnly) throws TopiaException { -// TopiaContext transaction = null; + List<Company> results = new ArrayList<Company>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - CompanyDAO dao = WaoDAOHelper.getCompanyDAO(transaction); + CompanyDAO dao = WaoDAOHelper.getCompanyDAO(transaction); - if (activeOnly) { - results = dao.findAllByActive(activeOnly); - } else { - results = dao.findAll(); - } - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getCompanies ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de récupérer la liste des sociétés", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } + if (activeOnly) { + results = dao.findAllByActive(activeOnly); + } else { + results = dao.findAll(); + } + return results; } @Override public List<WaoUser> executeGetUsersByCompany(TopiaContext transaction, List<Object> errorArgs, Company company) throws TopiaException { -// TopiaContext transaction = null; -// List<WaoUser> results = new ArrayList<WaoUser>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - errorArgs.add(company.getName()); + errorArgs.add(company.getName()); - WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); + WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); - TopiaQuery query = dao.createQuery(). - add(WaoUser.COMPANY, company). - addOrder(WaoUser.FIRST_NAME, WaoUser.LAST_NAME); + TopiaQuery query = dao.createQuery(). + add(WaoUser.COMPANY, company). + addOrder(WaoUser.FIRST_NAME, WaoUser.LAST_NAME); - return dao.findAllByQuery(query); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getUsersByCompany ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de récupérer " + -// "la liste des utilisateurs de la société " + -// company.getName(), eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return results; + return dao.findAllByQuery(query); } @Override public List<WaoUser> executeGetObservers(TopiaContext transaction, boolean activeOnly) throws TopiaException { -// TopiaContext transaction = null; -// List<WaoUser> results = new ArrayList<WaoUser>(); -// try { -// long startTime = 0; -// if (log.isDebugEnabled()) { -// startTime = System.currentTimeMillis(); -// } -// transaction = rootContext.beginTransaction(); - WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); - TopiaQuery query = dao.createQuery(). - add(WaoUser.ROLE, UserRole.OBSERVER.ordinal(), - UserRole.COORDINATOR.ordinal()); + WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); + TopiaQuery query = dao.createQuery(). + add(WaoUser.ROLE, UserRole.OBSERVER.ordinal(), + UserRole.COORDINATOR.ordinal()); - if (activeOnly) { - query.add(WaoUser.ACTIVE, Boolean.TRUE); - } + if (activeOnly) { + query.add(WaoUser.ACTIVE, Boolean.TRUE); + } - return dao.findAllByQuery(query); - -// if (log.isDebugEnabled()) { -// long stopTime = System.currentTimeMillis(); -// log.debug("W:[ getObservers ] Time = " + -// DurationFormatUtils.formatDurationHMS( -// stopTime - startTime)); -// } -// } catch (Exception eee) { -// WaoContextO.serviceException(transaction, "Impossible de récupérer la liste des observateurs", eee); -// } finally { -// WaoContextO.closeTransaction(transaction); -// } -// return results; + return dao.findAllByQuery(query); } @Override Modified: trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-04-01 16:46:41 UTC (rev 407) @@ -29,6 +29,19 @@ wao.error.serviceReferential.getProfessions= wao.error.serviceReferential.getSectors= wao.error.serviceReferential.importFishingZoneCsv= +wao.error.serviceSampling.createUpdateSampleRow= +wao.error.serviceSampling.deleteSampleRow= +wao.error.serviceSampling.exportSamplingPlanCsv= +wao.error.serviceSampling.getNewProfession= +wao.error.serviceSampling.getNewSampleMonth= +wao.error.serviceSampling.getNewSampleRow= +wao.error.serviceSampling.getNewSampleRowCode= +wao.error.serviceSampling.getPrograms= +wao.error.serviceSampling.getSampleRow= +wao.error.serviceSampling.getSampleRowByCode= +wao.error.serviceSampling.getSampleRowsByFilter= +wao.error.serviceSampling.getSampleRowsOrderedByFishingZone= +wao.error.serviceSampling.importSamplingPlanCsv= wao.error.serviceUser.connect= wao.error.serviceUser.createUpdateCompany= wao.error.serviceUser.createUpdateUser= 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 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-04-01 16:46:41 UTC (rev 407) @@ -29,12 +29,25 @@ 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. -wao.error.serviceUser.connect= -wao.error.serviceUser.createUpdateCompany= -wao.error.serviceUser.createUpdateUser= -wao.error.serviceUser.deleteUser= -wao.error.serviceUser.forgetPassword= -wao.error.serviceUser.getCompanies= -wao.error.serviceUser.getNewUser= -wao.error.serviceUser.getObservers= -wao.error.serviceUser.getUsersByCompany= +wao.error.serviceSampling.createUpdateSampleRow= +wao.error.serviceSampling.deleteSampleRow= +wao.error.serviceSampling.exportSamplingPlanCsv= +wao.error.serviceSampling.getNewProfession= +wao.error.serviceSampling.getNewSampleMonth= +wao.error.serviceSampling.getNewSampleRow= +wao.error.serviceSampling.getNewSampleRowCode= +wao.error.serviceSampling.getPrograms= +wao.error.serviceSampling.getSampleRow= +wao.error.serviceSampling.getSampleRowByCode= +wao.error.serviceSampling.getSampleRowsByFilter= +wao.error.serviceSampling.getSampleRowsOrderedByFishingZone= +wao.error.serviceSampling.importSamplingPlanCsv= +wao.error.serviceUser.connect=Une erreur est survenue lors de la demande de connexion +wao.error.serviceUser.createUpdateCompany=Impossible de cr\u00E9er ou de mettre \u00E0 jour la soci\u00E9t\u00E9 +wao.error.serviceUser.createUpdateUser=Impossible de cr\u00E9er ou de mettre \u00E0 jour l'utilisateur +wao.error.serviceUser.deleteUser=Impossible de supprimer l'utilisateur +wao.error.serviceUser.forgetPassword=Impossible d'envoyer le mail d'oubli de mot de passe +wao.error.serviceUser.getCompanies=Impossible de r\u00E9cup\u00E9rer la liste des soci\u00E9t\u00E9s +wao.error.serviceUser.getNewUser=Impossible d'instancier un nouvel utilisateur +wao.error.serviceUser.getObservers=Impossible de r\u00E9cup\u00E9rer la liste des observateurs +wao.error.serviceUser.getUsersByCompany=Impossible de r\u00E9cup\u00E9rer la liste des utilisateurs de la soci\u00E9t\u00E9 %1$s Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-04-01 16:46:41 UTC (rev 407) @@ -138,7 +138,7 @@ public ServiceSampling getServiceSampling() throws WaoExceptionO { ServiceSamplingImpl instance = new ServiceSamplingImpl(); -// instance.setContext(context); + instance.setContext(context); return instance; } Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatInfosImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatInfosImplTest.java 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/entity/BoatInfosImplTest.java 2010-04-01 16:46:41 UTC (rev 407) @@ -21,7 +21,6 @@ package fr.ifremer.wao.entity; -import fr.ifremer.wao.WaoRunner; import fr.ifremer.wao.TestManager; import org.junit.After; import org.junit.AfterClass; Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowImplTest.java 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/entity/SampleRowImplTest.java 2010-04-01 16:46:41 UTC (rev 407) @@ -23,8 +23,6 @@ import fr.ifremer.wao.WaoExceptionO; import fr.ifremer.wao.WaoDAOHelper; -import fr.ifremer.wao.WaoRunner; -import fr.ifremer.wao.WaoContextO; import fr.ifremer.wao.TestManager; import java.util.Calendar; import java.util.Date; Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialImplTest.java 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceReferentialImplTest.java 2010-04-01 16:46:41 UTC (rev 407) @@ -22,8 +22,8 @@ package fr.ifremer.wao.service; import fr.ifremer.wao.WaoExceptionO; -import fr.ifremer.wao.WaoRunner; import fr.ifremer.wao.TestManager; +import fr.ifremer.wao.WaoException; import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.bean.SamplingFilterImpl; import fr.ifremer.wao.entity.FishingZone; Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-04-01 16:46:41 UTC (rev 407) @@ -23,6 +23,7 @@ import fr.ifremer.wao.WaoBusinessException; +import fr.ifremer.wao.WaoException; import fr.ifremer.wao.WaoExceptionO; import fr.ifremer.wao.bean.FacadeRow; import fr.ifremer.wao.bean.ImportResults; @@ -147,7 +148,7 @@ InputStream result = null; try { result = serviceSampling.exportSamplingPlanCsv(user, getPeriod()); - } catch (WaoExceptionO eee) { + } catch (WaoException eee) { throw new IOException(eee); } return result; Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java 2010-04-01 15:49:29 UTC (rev 406) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java 2010-04-01 16:46:41 UTC (rev 407) @@ -29,7 +29,6 @@ import org.apache.tapestry5.ioc.MappedConfiguration; import org.apache.tapestry5.ioc.ServiceBinder; import org.apache.tapestry5.ioc.annotations.EagerLoad; -import org.apache.tapestry5.ioc.annotations.InjectService; import org.apache.tapestry5.ioc.services.RegistryShutdownHub; import org.apache.tapestry5.services.ApplicationStateContribution; import org.apache.tapestry5.services.ApplicationStateCreator; @@ -56,8 +55,8 @@ // is provided inline, or requires more initialization than simply // invoking the constructor. // binder.bind(ServiceNews.class, ServiceNewsImpl.class); - binder.bind(ServiceUser.class, ServiceUserImpl.class); - binder.bind(ServiceSampling.class, ServiceSamplingImpl.class); +// binder.bind(ServiceUser.class, ServiceUserImpl.class); +// binder.bind(ServiceSampling.class, ServiceSamplingImpl.class); // binder.bind(ServiceReferential.class, ServiceReferentialImpl.class); // binder.bind(ServiceBoat.class, ServiceBoatImpl.class); binder.bind(ServiceContact.class, ServiceContactImpl.class); @@ -90,6 +89,18 @@ return instance; } + public ServiceUser buildServiceUser(WaoManager manager) { + ServiceUserImpl instance = new ServiceUserImpl(); + instance.setContext(manager.getContext()); + return instance; + } + + public ServiceSampling buildServiceSampling(WaoManager manager) { + ServiceSamplingImpl instance = new ServiceSamplingImpl(); + instance.setContext(manager.getContext()); + return instance; + } + public static void contributeApplicationDefaults( MappedConfiguration<String, String> configuration) { // Contributions to ApplicationDefaults will override any contributions to
participants (1)
-
fdesbois@users.labs.libre-entreprise.org