Author: bleny Date: 2012-09-06 19:18:01 +0200 (Thu, 06 Sep 2012) New Revision: 1622 Url: http://forge.codelutin.com/repositories/revision/wao/1622 Log: fixes #1463 Dans le formulaire de modification d'une ligne du plan, impossible d'utiliser un code DCF jamais utilis?\195?\169 auparavant Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferential.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialAbstract.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.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-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2012-08-30 14:47:31 UTC (rev 1621) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2012-09-06 17:18:01 UTC (rev 1622) @@ -335,30 +335,38 @@ String message, Object... args) throws WaoException { - if (log.isDebugEnabled()) { - log.debug(_(message, args), eee); - } - if (!(eee instanceof WaoException)) { - //if (!(eee instanceof TopiaException)) { + if (transaction == null) { + if (log.isWarnEnabled()) { + log.warn("no transaction to rollback"); + } + } else { + if (transaction.isClosed()) { + if (log.isWarnEnabled()) { + log.warn("transaction is already closed, will not rollback: " + transaction); + } + } else { try { - if (transaction != null && !transaction.isClosed()) { - if (log.isInfoEnabled()) { - log.info("Saving annulation : Transaction rollback"); - } - transaction.rollbackTransaction(); - //transaction.closeContext(); + if (log.isWarnEnabled()) { + log.warn("transaction rollback: " + transaction); } - } catch (TopiaException eeee) { - treateError(eeee, n_("wao.error.context.rollback")); + transaction.rollbackTransaction(); + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("unable to rollback " + e); + } + throw new TopiaRuntimeException(e); } - //} - if (eee instanceof SQLGrammarException && log.isErrorEnabled()) { - log.error("SQL executed with error : " + - ((SQLGrammarException)eee).getSQL()); } + } + + if (log.isErrorEnabled()) { + log.error(WaoUtils._(message, args), eee); + } + + if (eee instanceof WaoException) { + throw (WaoException) eee; + } else { throw new WaoException(message, eee, args); - } else { - throw (WaoException)eee; } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferential.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferential.java 2012-08-30 14:47:31 UTC (rev 1621) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferential.java 2012-09-06 17:18:01 UTC (rev 1622) @@ -6,7 +6,9 @@ import fr.ifremer.wao.bean.ReferentialState; import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.entity.ContactStateMotif; +import fr.ifremer.wao.entity.FishingGearDCF; import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.TargetSpeciesDCF; import fr.ifremer.wao.entity.TerrestrialDivision; import fr.ifremer.wao.entity.TerrestrialLocation; import fr.ifremer.wao.io.ImportResults; @@ -47,4 +49,8 @@ void updateReferentialMeta(String entityClassFqn) throws WaoException; + List<FishingGearDCF> getAllFishingGearDCFs() throws WaoException; + + List<TargetSpeciesDCF> getAllTargetSpeciesDCFs() throws WaoException; + } //ServiceReferential Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialAbstract.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialAbstract.java 2012-08-30 14:47:31 UTC (rev 1621) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialAbstract.java 2012-09-06 17:18:01 UTC (rev 1622) @@ -1,12 +1,17 @@ package fr.ifremer.wao.service; +import fr.ifremer.wao.WaoDAOHelper; import fr.ifremer.wao.WaoException; import fr.ifremer.wao.bean.ContactState; import fr.ifremer.wao.bean.ObsProgram; import fr.ifremer.wao.bean.ReferentialState; import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.entity.ContactStateMotif; +import fr.ifremer.wao.entity.FishingGearDCF; +import fr.ifremer.wao.entity.FishingGearDCFDAO; import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.TargetSpeciesDCF; +import fr.ifremer.wao.entity.TargetSpeciesDCFDAO; import fr.ifremer.wao.entity.TerrestrialDivision; import fr.ifremer.wao.entity.TerrestrialLocation; import fr.ifremer.wao.io.ImportResults; @@ -64,6 +69,10 @@ protected abstract void executeUpdateReferentialMeta(TopiaContext transaction, String entityClassFqn) throws Exception; + protected abstract List<FishingGearDCF> executeGetAllFishingGearDCF(TopiaContext transaction) throws Exception; + + protected abstract List<TargetSpeciesDCF> executeGetAllTargetSpeciesDCF(TopiaContext transaction) throws Exception; + @Override public List<FishingZone> getFishingZones() throws WaoException { TopiaContext transaction = null; @@ -357,15 +366,53 @@ try { executeUpdateReferentialMeta(transaction, entityClassFqn); - + } finally { closeTransaction(transaction); } - + } catch (Exception eee) { - treateError(transaction, eee, I18n.n_("wao.error.serviceReferential.updateReferentialMeta")); + treateError(transaction, eee, I18n.n_("wao.error.serviceReferential.updateReferentialMeta")); } - + } + @Override + public List<FishingGearDCF> getAllFishingGearDCFs() throws WaoException { + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + + try { + List<FishingGearDCF> result = executeGetAllFishingGearDCF(transaction); + return result; + } finally { + closeTransaction(transaction); + } + + } catch (Exception eee) { + treateError(transaction, eee, I18n.n_("wao.error.serviceReferential.getAllFishingGearDCFs")); + } + return null; + } + + @Override + public List<TargetSpeciesDCF> getAllTargetSpeciesDCFs() throws WaoException { + TopiaContext transaction = null; + try { + transaction = beginTransaction(); + + try { + List<TargetSpeciesDCF> result = executeGetAllTargetSpeciesDCF(transaction); + return result; + } finally { + closeTransaction(transaction); + } + + } catch (Exception eee) { + treateError(transaction, eee, I18n.n_("wao.error.serviceReferential.getAllTargetSpeciesDCFs")); + } + return null; + } + } //ServiceReferentialAbstract 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 2012-08-30 14:47:31 UTC (rev 1621) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2012-09-06 17:18:01 UTC (rev 1622) @@ -901,4 +901,17 @@ return referentialStates; } + @Override + public List<FishingGearDCF> executeGetAllFishingGearDCF(TopiaContext transaction) throws Exception { + FishingGearDCFDAO fishingGearDCFDAO = WaoDAOHelper.getFishingGearDCFDAO(transaction); + List<FishingGearDCF> all = fishingGearDCFDAO.findAll(); + return all; + } + + @Override + public List<TargetSpeciesDCF> executeGetAllTargetSpeciesDCF(TopiaContext transaction) throws Exception { + TargetSpeciesDCFDAO fishingGearDCFDAO = WaoDAOHelper.getTargetSpeciesDCFDAO(transaction); + List<TargetSpeciesDCF> all = fishingGearDCFDAO.findAll(); + return all; + } } 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 2012-08-30 14:47:31 UTC (rev 1621) +++ trunk/wao-business/src/main/resources/i18n/wao-business_en_GB.properties 2012-09-06 17:18:01 UTC (rev 1622) @@ -214,11 +214,13 @@ wao.error.serviceNews.newNews= wao.error.serviceNews.saveNews= wao.error.serviceReferential.getAllContactStateMotifs= +wao.error.serviceReferential.getAllFishingGearDCFs= wao.error.serviceReferential.getAllObsDebCodes= wao.error.serviceReferential.getAllObservationUnits= wao.error.serviceReferential.getAllPorts= wao.error.serviceReferential.getAllPortsAndAuctions= wao.error.serviceReferential.getAllRegionIfremers= +wao.error.serviceReferential.getAllTargetSpeciesDCFs= wao.error.serviceReferential.getAllTerrestrialDistricts= wao.error.serviceReferential.getAllTerrestrialLocations= wao.error.serviceReferential.getCodesDCF5Contains= 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 2012-08-30 14:47:31 UTC (rev 1621) +++ trunk/wao-business/src/main/resources/i18n/wao-business_fr_FR.properties 2012-09-06 17:18:01 UTC (rev 1622) @@ -213,11 +213,13 @@ wao.error.serviceNews.newNews= wao.error.serviceNews.saveNews=Impossible d'enregistrer la news ayant pour titre '%1$s' wao.error.serviceReferential.getAllContactStateMotifs= +wao.error.serviceReferential.getAllFishingGearDCFs= wao.error.serviceReferential.getAllObsDebCodes= wao.error.serviceReferential.getAllObservationUnits= wao.error.serviceReferential.getAllPorts= wao.error.serviceReferential.getAllPortsAndAuctions= wao.error.serviceReferential.getAllRegionIfremers= +wao.error.serviceReferential.getAllTargetSpeciesDCFs= wao.error.serviceReferential.getAllTerrestrialDistricts= wao.error.serviceReferential.getAllTerrestrialLocations= wao.error.serviceReferential.getCodesDCF5Contains= Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2012-08-30 14:47:31 UTC (rev 1621) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SampleRowForm.java 2012-09-06 17:18:01 UTC (rev 1622) @@ -29,7 +29,6 @@ import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.bean.ConnectedUser; import fr.ifremer.wao.bean.ObsProgram; -import fr.ifremer.wao.bean.SamplingFilter; import fr.ifremer.wao.bean.SamplingFilterImpl; import fr.ifremer.wao.bean.SamplingStrategy; import fr.ifremer.wao.bean.UserRole; @@ -90,8 +89,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.LinkedList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static org.nuiton.i18n.I18n.n_; @@ -761,18 +761,16 @@ sampleRowForm.recordError("Vous devez associer au moins un code DCF5"); } else { // check that codes exist in the reference - SamplingFilter noFilter = new SamplingFilterImpl(); - List<String> existingFishingGearCodes = new LinkedList<String>(); + Set<String> existingFishingGearCodes = new HashSet<String>(); // filling existingFishingGearCodes - for (FishingGearDCF dcfGear : serviceSampling.getDCFGears(noFilter)) { + for (FishingGearDCF dcfGear : serviceReferential.getAllFishingGearDCFs()) { existingFishingGearCodes.add(dcfGear.getCode()); } - List<String> existingTargetSpeciesCodes = new LinkedList<String>(); - for (TargetSpeciesDCF dcfSpecies : serviceSampling.getDCFSpecies(noFilter)) { + Set<String> existingTargetSpeciesCodes = new HashSet<String>(); + for (TargetSpeciesDCF dcfSpecies : serviceReferential.getAllTargetSpeciesDCFs()) { existingTargetSpeciesCodes.add(dcfSpecies.getCode()); } - for (DCF5Code code : getSampleRow().getdCF5Code()) { if ( ! existingFishingGearCodes.contains(code.getFishingGearCode())) { sampleRowForm.recordError(code.getFishingGearCode() + " n'est pas un code d'engin valide");