Author: chatellier
Date: 2009-12-21 16:18:27 +0000 (Mon, 21 Dec 2009)
New Revision: 2858
Added:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/HorizontalEntityVisitor.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExplorer.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExport.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExportFactorXML.java
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/export/
isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/export/RegionExplorerTest.java
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.h2.db
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/46.t43.lob.db
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/47.t43.lob.db
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/48.t43.lob.db
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/49.t43.lob.db
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/50.t43.lob.db
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/51.t43.lob.db
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/52.t43.lob.db
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/53.t43.lob.db
isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/54.t43.lob.db
Modified:
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java
isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx
isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties
isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties
Log:
Ajout d'une premiere version de l'export des priopri?\195?\169tes factorisables d'une r?\195?\169gion.
Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/HorizontalEntityVisitor.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/HorizontalEntityVisitor.java (rev 0)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/HorizontalEntityVisitor.java 2009-12-21 16:18:27 UTC (rev 2858)
@@ -0,0 +1,161 @@
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin, Chatellier Eric
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package fr.ifremer.isisfish.mexico.export;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.EntityVisitor;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import fr.ifremer.isisfish.entities.Equation;
+
+/**
+ * Parcourt en largeur du model et délegation à un autre visiteur.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ *
+ * @deprecated use those from topia
+ */
+ at Deprecated
+public class HorizontalEntityVisitor implements EntityVisitor {
+
+ /** Class logger. */
+ private static Log log = LogFactory.getLog(HorizontalEntityVisitor.class);
+
+ /** Delegate visitor. */
+ protected EntityVisitor delegateVisitor;
+
+ /** Cache used to remember entity during exploration. */
+ protected List<TopiaEntity> alreadyExplored;
+
+ /** Entity to be visited later. */
+ protected List<TopiaEntity> toVisitEntities;
+
+ /**
+ * Constructor.
+ *
+ * @param delegateVisitor delegate visitor
+ */
+ public HorizontalEntityVisitor(EntityVisitor delegateVisitor) {
+ this.delegateVisitor = delegateVisitor;
+ this.alreadyExplored = new ArrayList<TopiaEntity>();
+ this.toVisitEntities = new ArrayList<TopiaEntity>();
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#start(org.nuiton.topia.persistence.TopiaEntity)
+ */
+ @Override
+ public void start(TopiaEntity entity) {
+ delegateVisitor.start(entity);
+ if (!alreadyExplored.contains(entity)) {
+ alreadyExplored.add(entity);
+ }
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Object)
+ */
+ @Override
+ public void visit(TopiaEntity e, String name, Class<?> type, Object value) {
+ // si c'est une entité
+ if (value instanceof TopiaEntity && !(value instanceof Equation)) {
+ TopiaEntity entity = (TopiaEntity) value;
+ toVisitEntities.add(entity);
+ } else {
+ delegateVisitor.visit(e, name, type, value);
+ }
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Class, java.lang.Object)
+ */
+ @Override
+ public void visit(TopiaEntity e, String name, Class<?> collectionType,
+ Class<?> type, Object value) {
+
+ Collection<?> values = (Collection<?>) value;
+ if (values != null && !values.isEmpty()) {
+ int i = 0;
+ for (Object currentValue : values) {
+ visit(e, name, type, collectionType, i++, currentValue);
+ }
+ }
+
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Class, int, java.lang.Object)
+ */
+ @Override
+ public void visit(TopiaEntity e, String name, Class<?> collectionType,
+ Class<?> type, int index, Object value) {
+ // si c'est une entité
+ if (value instanceof TopiaEntity) {
+ TopiaEntity entity = (TopiaEntity) value;
+
+ toVisitEntities.add(entity);
+ } else {
+ delegateVisitor.visit(e, name, collectionType, type, index, value);
+ }
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#end(org.nuiton.topia.persistence.TopiaEntity)
+ */
+ @Override
+ public void end(TopiaEntity entity) {
+ delegateVisitor.end(entity);
+
+ // here, must revisit all remembered entities
+ List<TopiaEntity> currentEntities = new ArrayList<TopiaEntity>(toVisitEntities);
+ // TODO verify if clearing here is enought
+ toVisitEntities.clear();
+ for (TopiaEntity currentEntity : currentEntities) {
+ try {
+ if (!alreadyExplored.contains(currentEntity)) {
+ currentEntity.accept(this);
+ }
+ } catch (TopiaException ex) {
+ if (log.isErrorEnabled()) {
+ log.error("Error on horizontal exploration", ex);
+ }
+ }
+ }
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#clear()
+ */
+ @Override
+ public void clear() {
+ alreadyExplored.clear();
+ toVisitEntities.clear();
+ delegateVisitor.clear();
+ }
+} // HorizontallyEntityVisitor
Property changes on: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/HorizontalEntityVisitor.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExplorer.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExplorer.java (rev 0)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExplorer.java 2009-12-21 16:18:27 UTC (rev 2858)
@@ -0,0 +1,116 @@
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin, Chatellier Eric
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package fr.ifremer.isisfish.mexico.export;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.TopiaException;
+
+import fr.ifremer.isisfish.entities.Cell;
+import fr.ifremer.isisfish.entities.FisheryRegion;
+import fr.ifremer.isisfish.entities.Gear;
+import fr.ifremer.isisfish.entities.Metier;
+import fr.ifremer.isisfish.entities.Port;
+import fr.ifremer.isisfish.entities.SetOfVessels;
+import fr.ifremer.isisfish.entities.Species;
+import fr.ifremer.isisfish.entities.Strategy;
+import fr.ifremer.isisfish.entities.TripType;
+import fr.ifremer.isisfish.entities.VesselType;
+import fr.ifremer.isisfish.entities.Zone;
+
+/**
+ * Region explorer.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class RegionExplorer {
+
+ /** Class logger. */
+ private static Log log = LogFactory.getLog(RegionExplorer.class);
+
+ /**
+ * Explore region and call export on each entity found.
+ *
+ * @param region region to explore
+ * @param regionExport region export implementation
+ * @throws TopiaException
+ */
+ public void explore(FisheryRegion region, RegionExport regionExport) throws TopiaException {
+
+ regionExport.beginExport();
+
+ HorizontalEntityVisitor visitor = new HorizontalEntityVisitor(regionExport);
+
+ // explore cells
+ for (Cell cell : region.getCell()) {
+ cell.accept(visitor);
+ }
+
+ // explore zone
+ for (Zone zone : region.getZone()) {
+ zone.accept(visitor);
+ }
+
+ // explore ports
+ for (Port port : region.getPort()) {
+ port.accept(visitor);
+ }
+
+ // explore species and population
+ for (Species species : region.getSpecies()) {
+ species.accept(visitor);
+ }
+
+ // explore gears
+ for (Gear gear : region.getGear()) {
+ gear.accept(visitor);
+ }
+
+ // explore metier
+ for (Metier metier : region.getMetier()) {
+ metier.accept(visitor);
+ }
+
+ // explore tripType
+ for (TripType tripType : region.getTripType()) {
+ tripType.accept(visitor);
+ }
+
+ // explore vesselType
+ for (VesselType vesselType : region.getVesselType()) {
+ vesselType.accept(visitor);
+ }
+
+ // explore setOfVessels
+ for (SetOfVessels setOfVessels : region.getSetOfVessels()) {
+ setOfVessels.accept(visitor);
+ }
+
+ // explore strategy
+ for (Strategy strategy : region.getStrategy()) {
+ strategy.accept(visitor);
+ }
+
+ regionExport.endExport();
+ }
+} // RegionExplorer
Property changes on: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExplorer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExport.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExport.java (rev 0)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExport.java 2009-12-21 16:18:27 UTC (rev 2858)
@@ -0,0 +1,43 @@
+/* *##%
+ * Copyright (C) 2009 Code Lutin, Chatellier Eric
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package fr.ifremer.isisfish.mexico.export;
+
+import org.nuiton.topia.persistence.EntityVisitor;
+
+/**
+ * Region export interface.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public interface RegionExport extends EntityVisitor {
+
+ /**
+ * Called at export begin.
+ */
+ void beginExport();
+
+ /**
+ * Called at export end.
+ */
+ void endExport();
+}
Property changes on: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExport.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExportFactorXML.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExportFactorXML.java (rev 0)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExportFactorXML.java 2009-12-21 16:18:27 UTC (rev 2858)
@@ -0,0 +1,261 @@
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin, Chatellier Eric
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package fr.ifremer.isisfish.mexico.export;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.beanutils.ConvertUtilsBean;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.math.matrix.MatrixND;
+import org.nuiton.topia.persistence.TopiaEntity;
+
+import fr.ifremer.isisfish.entities.EffortDescription;
+import fr.ifremer.isisfish.entities.Equation;
+import fr.ifremer.isisfish.entities.PopulationGroup;
+import fr.ifremer.isisfish.entities.PopulationSeasonInfo;
+import fr.ifremer.isisfish.entities.StrategyMonthInfo;
+import fr.ifremer.isisfish.mexico.MexicoHelper;
+import fr.ifremer.isisfish.types.RangeOfValues;
+import fr.ifremer.isisfish.types.TimeUnit;
+import fr.ifremer.isisfish.ui.sensitivity.SensitivityUtils;
+import fr.ifremer.isisfish.util.ConverterUtil;
+
+/**
+ * Export implementation for factor into xml.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class RegionExportFactorXML implements RegionExport {
+
+ /** Class logger. */
+ private static Log log = LogFactory.getLog(RegionExportFactorXML.class);
+
+ protected File outputFile;
+
+ protected StringBuffer stringBuffer;
+
+ protected String lastReadName;
+
+ public RegionExportFactorXML(File outputFile) {
+ this.outputFile = outputFile;
+ }
+
+
+ /*
+ * @see fr.ifremer.isisfish.mexico.export.RegionExport#beginExport()
+ */
+ @Override
+ public void beginExport() {
+ stringBuffer = new StringBuffer();
+ stringBuffer.append("<regionFactors>");
+ stringBuffer.append("<factors>");
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#start(org.nuiton.topia.persistence.TopiaEntity)
+ */
+ @Override
+ public void start(TopiaEntity entity) {
+ lastReadName = null;
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Object)
+ */
+ @Override
+ public void visit(TopiaEntity entity, String propertyName, Class<?> type, Object value) {
+
+ // FIXME this mechanism won't work if name is not the first attribute
+ // in visitor. (need to be fixed)
+ if ("name".equals(propertyName)) {
+ lastReadName = (String)value;
+ }
+
+ // build factor name (entityName.propertyName)
+ String factorClass = entity.getClass().getSimpleName();
+ // if there is a "Impl" in entityName, remove it
+ factorClass = factorClass.replaceFirst("Impl", "");
+
+ // FIXME propertyName with capitalize first letter is a bad idea
+ String factorName = factorClass + "." + StringUtils.capitalize(propertyName);
+
+ // test if factor name is enabled
+ // TODO move SensitivityUtils outside of UI
+ boolean enabled = SensitivityUtils.isSensitivityFactorEnabled(factorName);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Testing if attribute (" + factorName + ") is factor enabled : " + enabled);
+ }
+
+ if (enabled) {
+ String exportFactorName = getUniqueFactorName(entity, factorClass, propertyName);
+ String stringValue = getStringValue(entity, type, value);
+
+ stringBuffer.append("<!-- " + factorName + " -->");
+ stringBuffer.append("<factor name=\"" + exportFactorName + "\"");
+ stringBuffer.append(" type=\"" + type.getSimpleName() + "\"");
+ stringBuffer.append(">");
+ stringBuffer.append("<target>" + entity.getTopiaId() + "#" + propertyName + "</target>");
+ stringBuffer.append("<value>" + stringValue + "</value>");
+ stringBuffer.append("</factor>");
+ }
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Class, java.lang.Object)
+ */
+ @Override
+ public void visit(TopiaEntity entity, String propertyName, Class<?> collectionType,
+ Class<?> type, Object value) {
+ visit(entity, propertyName, type, value);
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#visit(org.nuiton.topia.persistence.TopiaEntity, java.lang.String, java.lang.Class, java.lang.Class, int, java.lang.Object)
+ */
+ @Override
+ public void visit(TopiaEntity entity, String propertyName, Class<?> collectionType,
+ Class<?> type, int index, Object value) {
+
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#end(org.nuiton.topia.persistence.TopiaEntity)
+ */
+ @Override
+ public void end(TopiaEntity entity) {
+
+ }
+
+ /*
+ * @see org.nuiton.topia.persistence.EntityVisitor#clear()
+ */
+ @Override
+ public void clear() {
+
+ }
+
+ /*
+ * @see fr.ifremer.isisfish.mexico.export.RegionExport#endExport()
+ */
+ @Override
+ public void endExport() {
+ stringBuffer.append("</factors>");
+ stringBuffer.append("</regionFactors>");
+ String xml = MexicoHelper.formatXML(stringBuffer.toString());
+
+ try {
+ FileUtils.writeStringToFile(outputFile, xml);
+ } catch (IOException ex) {
+ if (log.isErrorEnabled()) {
+ log.error("Can't wrtie xml content to output file", ex);
+ }
+ }
+ }
+
+ /**
+ * Get factor name.
+ *
+ * Dans la majorité des cas, on a un {@link lastReadName} défini. Dans les
+ * autre cas, il faut chercher un meilleur nom.
+ *
+ * @param entity entity to get factor name
+ * @param factorClass entity short class name
+ * @param propertyName property name
+ * @return unique name for factor
+ */
+ protected String getUniqueFactorName(TopiaEntity entity, String factorClass,
+ String propertyName) {
+
+ String exportFactorName = null;
+
+ if (lastReadName != null) {
+ exportFactorName = factorClass + "." + lastReadName + "." + propertyName;
+ }
+ else {
+ // test each entities
+ if (entity instanceof EffortDescription) {
+ EffortDescription newEntity = (EffortDescription)entity;
+ // FIXME newEntity.getSetOfVessels() is null ???
+ exportFactorName = factorClass + ".";
+ exportFactorName += RandomStringUtils.randomAlphanumeric(8); // getSetOfVessels().getName()
+ exportFactorName += "." + newEntity.getPossibleMetiers() + "." + propertyName;
+ }
+ else if (entity instanceof PopulationGroup) {
+ PopulationGroup newEntity = (PopulationGroup)entity;
+ exportFactorName = factorClass + "." + newEntity.getPopulation().getName();
+ exportFactorName += "." + newEntity.getId() + "." + propertyName;
+ }
+ else if (entity instanceof PopulationSeasonInfo) {
+ PopulationSeasonInfo newEntity = (PopulationSeasonInfo)entity;
+ exportFactorName = factorClass + "." + newEntity.getPopulation().getName() + ".";
+ exportFactorName += newEntity.getFirstMonth() + "." + newEntity.getLastMonth() + "." + propertyName;
+ }
+ else if (entity instanceof StrategyMonthInfo) {
+ StrategyMonthInfo newEntity = (StrategyMonthInfo)entity;
+ exportFactorName = factorClass + "." + newEntity.getStrategy().getName() + ".";
+ exportFactorName += newEntity.getMonth() + "." + propertyName;
+ }
+ }
+
+ return exportFactorName;
+ }
+
+ /**
+ * Get string value.
+ *
+ * @param entity entity
+ * @param type value type
+ * @param value value
+ */
+ protected String getStringValue(TopiaEntity entity, Class<?> type, Object value) {
+
+ String result = null;
+
+ if (type.isAssignableFrom(TimeUnit.class)) {
+ result = String.valueOf(((TimeUnit)value).getTime());
+ }
+ else if (type.isAssignableFrom(MatrixND.class)) {
+ ConvertUtilsBean beanUtils = ConverterUtil.getConverter(null);
+ result = beanUtils.convert(value);
+ }
+ else if (type.isAssignableFrom(RangeOfValues.class)) {
+ result = String.valueOf(((RangeOfValues)value).getValues());
+ }
+ else if (type.isAssignableFrom(Equation.class)) {
+ // not initialized equation can be null :(
+ if (value != null) {
+ result = String.valueOf(((Equation)value).getContent());
+ result = StringEscapeUtils.escapeXml(result);
+ }
+ }
+
+ return result;
+ }
+}
Property changes on: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/mexico/export/RegionExportFactorXML.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java 2009-12-21 15:08:40 UTC (rev 2857)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputAction.java 2009-12-21 16:18:27 UTC (rev 2858)
@@ -72,6 +72,9 @@
import fr.ifremer.isisfish.entities.TargetSpecies;
import fr.ifremer.isisfish.entities.TargetSpeciesDAO;
import fr.ifremer.isisfish.entities.Zone;
+import fr.ifremer.isisfish.mexico.export.RegionExplorer;
+import fr.ifremer.isisfish.mexico.export.RegionExport;
+import fr.ifremer.isisfish.mexico.export.RegionExportFactorXML;
import fr.ifremer.isisfish.types.Month;
import fr.ifremer.isisfish.ui.input.check.CheckRegion;
import fr.ifremer.isisfish.ui.input.check.CheckResult;
@@ -96,10 +99,6 @@
/** Class logger. */
private static Log log = LogFactory.getLog(InputAction.class);
- public InputAction() {
-
- }
-
/**
* Exporter la region dans un zip.
*
@@ -1312,4 +1311,42 @@
ErrorHelper.showErrorDialog(_("isisfish.error.region.check"), eee);
}
}
+
+ /**
+ * Explore region and exporte any enabled sensitivity factor name with value.
+ *
+ * @param parentComponent parent component
+ * @param fisheryRegion fishery region to export
+ */
+ public void exportRegionSensitivityFactors(InputUI parentComponent, FisheryRegion fisheryRegion) {
+
+ try {
+ File exportFile = FileUtil.getFile(_("isisfish.input.sensitivity.export.title"),
+ _("isisfish.common.ok"), parentComponent, ".*\\.xml", "XML Files");
+
+ // make sur that filename ends with ".xml"
+ if (!exportFile.getAbsolutePath().endsWith(".xml")) {
+ exportFile = new File(exportFile.getAbsolutePath() + ".xml");
+ }
+
+ if (exportFile != null) {
+ parentComponent.setStatusMessage(_("isisfish.input.sensitivity.export.running"), true);
+ RegionExplorer explorer = new RegionExplorer();
+ RegionExport exportXML = new RegionExportFactorXML(exportFile);
+ explorer.explore(fisheryRegion, exportXML);
+ parentComponent.setStatusMessage(_("isisfish.input.sensitivity.export.complete"));
+ }
+ else {
+ if (log.isDebugEnabled()) {
+ log.debug("Export action canceled");
+ }
+ parentComponent.setStatusMessage(_("isisfish.input.sensitivity.export.cancel"));
+ }
+ } catch (Exception eee) {
+ if (log.isErrorEnabled()) {
+ log.error(_("isisfish.error.sensitivity.export"), eee);
+ }
+ ErrorHelper.showErrorDialog(_("isisfish.error.sensitivity.export"), eee);
+ }
+ }
}
Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx
===================================================================
--- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx 2009-12-21 15:08:40 UTC (rev 2857)
+++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/input/InputUI.jaxx 2009-12-21 16:18:27 UTC (rev 2858)
@@ -221,21 +221,24 @@
</script>
<JMenuBar id="menu" constraints='BorderLayout.NORTH'>
<JMenu text="isisfish.common.region">
- <JMenuItem text="isisfish.input.menu.importRegion" onActionPerformed="importRegion()" accelerator="accNew"/>
- <JMenuItem text="isisfish.input.menu.importRenameRegion" onActionPerformed="importRegionAndRename()" accelerator="accNew"/>
- <JMenuItem text="isisfish.input.menu.importRegionV2" onActionPerformed="importV2Region()" accelerator="accNew"/>
- <JMenuItem text="isisfish.input.menu.importRegionSimulation" onActionPerformed="importRegionFromSimulation()" accelerator="accImportFromSimulation"/>
- <JMenuItem text="isisfish.input.menu.exportRegion" enabled='{getRegion() != null}' onActionPerformed="exportRegion()" accelerator="accExport"/>
- <JMenuItem text="isisfish.input.menu.copyRegion" enabled='{getRegion() != null}' onActionPerformed="copyRegion()" accelerator="accExport"/>
+ <JMenuItem text="isisfish.input.menu.importRegion" onActionPerformed="importRegion()" />
+ <JMenuItem text="isisfish.input.menu.importRenameRegion" onActionPerformed="importRegionAndRename()" />
+ <JMenuItem text="isisfish.input.menu.importRegionV2" onActionPerformed="importV2Region()" />
+ <JMenuItem text="isisfish.input.menu.importRegionSimulation" onActionPerformed="importRegionFromSimulation()" />
+ <JMenuItem text="isisfish.input.menu.exportRegion" enabled='{getRegion() != null}' onActionPerformed="exportRegion()" />
+ <JMenuItem text="isisfish.input.menu.copyRegion" enabled='{getRegion() != null}' onActionPerformed="copyRegion()" />
<JSeparator/>
- <JMenuItem name="miRemove" text="isisfish.input.menu.removeLocaly" enabled='{getRegion() != null}' onActionPerformed="removeRegion()" accelerator="accRemove"/>
+ <JMenuItem name="miRemove" text="isisfish.input.menu.removeLocaly" enabled='{getRegion() != null}' onActionPerformed="removeRegion()" />
</JMenu>
<JMenu text="isisfish.input.menu.server">
- <JMenuItem text="isisfish.input.menu.addRegion" enabled='{getRegion() != null}' onActionPerformed="commitRegionInCVS()" accelerator="accAdd"/>
- <JMenuItem text="isisfish.input.menu.commit" enabled='{getRegion() != null}' onActionPerformed="commitRegionInCVS()" accelerator="accCommitVCS"/>
+ <JMenuItem text="isisfish.input.menu.addRegion" enabled='{getRegion() != null}' onActionPerformed="commitRegionInCVS()" />
+ <JMenuItem text="isisfish.input.menu.commit" enabled='{getRegion() != null}' onActionPerformed="commitRegionInCVS()" />
<JSeparator/>
- <JMenuItem name="miRemove" text="isisfish.input.menu.removeLocalyRemotely" enabled='{getRegion() != null}' onActionPerformed="removeRegion()" accelerator="accRemove"/>
+ <JMenuItem name="miRemove" text="isisfish.input.menu.removeLocalyRemotely" enabled='{getRegion() != null}' onActionPerformed="removeRegion()" />
</JMenu>
+ <JMenu text="isisfish.input.menu.sensitivity">
+ <JMenuItem text="isisfish.input.menu.sensitivity.export" enabled='{getRegion() != null}' onActionPerformed="getAction().exportRegionSensitivityFactors(this, getRegion())" />
+ </JMenu>
</JMenuBar>
<JSplitPane oneTouchExpandable="true" dividerLocation="200" orientation="HORIZONTAL" constraints='BorderLayout.CENTER'>
<JPanel layout='{new BorderLayout()}' minimumSize="{new java.awt.Dimension(0,0)}">
Modified: isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties
===================================================================
--- isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties 2009-12-21 15:08:40 UTC (rev 2857)
+++ isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties 2009-12-21 16:18:27 UTC (rev 2858)
@@ -44,6 +44,7 @@
Remote\ information\ file\ doesn't\ exists\ %s=
Rename\ data\ directory\ to\ %s=
Show\ help=
+Show\ version=
SimulationExecutor\ started\ with\ %s\ thread\ for\ %s=
Ssh\ key\ found\ '%s'\ will\ be\ used\ to\ connect\ to=
Stop\ simulation\ plan,\ because\ can't\ call\ afterSimulation\ correctly\ on\ plan\ %s=
@@ -348,6 +349,7 @@
isisfish.error.script.import=Can't import file for reason %1$s
isisfish.error.script.load=Can't load file %1$s for reason %2$s
isisfish.error.script.save=Can't save file %1$s for reason %2$s
+isisfish.error.sensitivity.export=Can't do region factors export
isisfish.error.simulation.addanalyseplan=Can't add analyze plan
isisfish.error.simulation.addrule=Can't add rule
isisfish.error.simulation.getparametervalue=Can't get parameter value
@@ -492,9 +494,15 @@
isisfish.input.menu.importRenameRegion=Import region and rename
isisfish.input.menu.removeLocaly=Remove localy
isisfish.input.menu.removeLocalyRemotely=Remove localy and remotely
+isisfish.input.menu.sensitivity=Mexico
+isisfish.input.menu.sensitivity.export=Export database factors
isisfish.input.menu.server=Server
isisfish.input.newRegion=New region
isisfish.input.selectRegion=Select region
+isisfish.input.sensitivity.export.cancel=Factor export canceled
+isisfish.input.sensitivity.export.complete=Factor export complete
+isisfish.input.sensitivity.export.running=Exporting factors...
+isisfish.input.sensitivity.export.title=Export factors
isisfish.input.title=Fishery input
isisfish.input.tree.cells=Cells
isisfish.input.tree.gears=Gears
Modified: isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties
===================================================================
--- isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties 2009-12-21 15:08:40 UTC (rev 2857)
+++ isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties 2009-12-21 16:18:27 UTC (rev 2858)
@@ -44,6 +44,7 @@
Remote\ information\ file\ doesn't\ exists\ %s=
Rename\ data\ directory\ to\ %s=
Show\ help=
+Show\ version=
SimulationExecutor\ started\ with\ %s\ thread\ for\ %s=
Ssh\ key\ found\ '%s'\ will\ be\ used\ to\ connect\ to=
Stop\ simulation\ plan,\ because\ can't\ call\ afterSimulation\ correctly\ on\ plan\ %s=
@@ -348,6 +349,7 @@
isisfish.error.script.import=N'a pas pu importer pour la raison suivante %1$s
isisfish.error.script.load=N'a pas pu charger le fichier %1$s pour la raison suivante %2$s
isisfish.error.script.save=N'a pas pu sauver le fichier %1$s pour la raison suivante %2$s
+isisfish.error.sensitivity.export=Error lors de l'export des facteurs de la r\u00E9gion
isisfish.error.simulation.addanalyseplan=Impossible d'ajouter un plan d'analyze
isisfish.error.simulation.addrule=Impossible d'ajouter une r\u00E8gle
isisfish.error.simulation.getparametervalue=Impossible d'obtenir la valeur du param\u00E8tre
@@ -492,9 +494,15 @@
isisfish.input.menu.importRenameRegion=Importer une r\u00E9gion et la renommer
isisfish.input.menu.removeLocaly=Supprimer localement
isisfish.input.menu.removeLocalyRemotely=Supprimer localement et \u00E0 distance
+isisfish.input.menu.sensitivity=Mexico
+isisfish.input.menu.sensitivity.export=Exporter les facteurs
isisfish.input.menu.server=Serveur
isisfish.input.newRegion=Nouvelle r\u00E9gion
isisfish.input.selectRegion=S\u00E9lectionnez une r\u00E9gion
+isisfish.input.sensitivity.export.cancel=Export des facteurs annul\u00E9
+isisfish.input.sensitivity.export.complete=Export des facteurs r\u00E9ussit
+isisfish.input.sensitivity.export.running=Export des facteurs en cours...
+isisfish.input.sensitivity.export.title=Exporter les facteurs
isisfish.input.title=Saisie de la p\u00EAcherie
isisfish.input.tree.cells=Mailles
isisfish.input.tree.gears=Engins
Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/export/RegionExplorerTest.java
===================================================================
--- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/export/RegionExplorerTest.java (rev 0)
+++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/export/RegionExplorerTest.java 2009-12-21 16:18:27 UTC (rev 2858)
@@ -0,0 +1,132 @@
+/* *##%
+ * Copyright (C) 2009 Ifremer, Code Lutin, Chatellier Eric
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *##%*/
+
+package fr.ifremer.isisfish.mexico.export;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+
+import fr.ifremer.isisfish.AbstractIsisFishTest;
+import fr.ifremer.isisfish.datastore.RegionStorage;
+import fr.ifremer.isisfish.datastore.StorageException;
+import fr.ifremer.isisfish.entities.FisheryRegion;
+import fr.ifremer.isisfish.ui.sensitivity.SensitivityUtils;
+
+/**
+ * Test class for {@link RegionExplorer}.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class RegionExplorerTest extends AbstractIsisFishTest {
+
+ /** Class logger. */
+ private static Log log = LogFactory.getLog(RegionExplorerTest.class);
+
+ /**
+ * Explore all region values and perform export implementation as xml.
+ *
+ * @throws TopiaException
+ * @throws StorageException
+ * @throws IOException
+ */
+ @Test
+ public void testExportRegionFactorsAsXml() throws TopiaException, StorageException, IOException {
+
+ // get region to export
+ RegionStorage regionStorage = RegionStorage.getRegion("BaseMotosICA");
+ TopiaContext context = regionStorage.getStorage().beginTransaction();
+ FisheryRegion fisheryRegion = RegionStorage.getFisheryRegion(context);
+
+ // export implementation
+ File file = File.createTempFile("xmlexport-", ".xml");
+ file.deleteOnExit();
+ RegionExportFactorXML xmlFactorExport = new RegionExportFactorXML(file);
+
+ // explore region (export as xml)
+ RegionExplorer explorer = new RegionExplorer();
+ explorer.explore(fisheryRegion, xmlFactorExport);
+ String xmlExport = FileUtils.readFileToString(file);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Export xml is : \n" + xmlExport);
+ }
+
+ // ========== here some tests ==========
+ // all factors must have a non null name
+ Assert.assertTrue("A factor has a null name", xmlExport.indexOf("name=\"null\"") == -1);
+ Assert.assertTrue("A factor has no name", xmlExport.indexOf("name=\"\"") == -1);
+
+ // must be present (for BaseMotosICA base)
+ // equation is a special case (entity too)
+ Assert.assertTrue("An equation factor is missing", xmlExport.indexOf("Population.Anchois_long.growth") != -1);
+
+ // close all
+ context.closeContext();
+ }
+
+ /**
+ * Test que toutes les entités et propriétés définies dans le fichier de
+ * sensibilité sont présentes dans le contenu xml.
+ *
+ * @throws TopiaException
+ * @throws StorageException
+ * @throws IOException
+ */
+ @Test
+ public void testAllEntityPresence() throws TopiaException, StorageException, IOException {
+ // get region to export
+ RegionStorage regionStorage = RegionStorage.getRegion("Golfe de Gascogne");
+ TopiaContext context = regionStorage.getStorage().beginTransaction();
+ FisheryRegion fisheryRegion = RegionStorage.getFisheryRegion(context);
+
+ // export implementation
+ File file = File.createTempFile("xmlexport-", ".xml");
+ file.deleteOnExit();
+ RegionExportFactorXML xmlFactorExport = new RegionExportFactorXML(file);
+
+ // explore region (export as xml)
+ RegionExplorer explorer = new RegionExplorer();
+ explorer.explore(fisheryRegion, xmlFactorExport);
+ String xmlExport = FileUtils.readFileToString(file);
+
+ // test that all sensitity properties appear in xml content
+ // entity part and property part must appear in factors names
+ for (String property : SensitivityUtils.getProperties().stringPropertyNames()) {
+ String entityPart = property.substring(0, property.indexOf('.'));
+ Assert.assertTrue("Entity " + entityPart + " is not present in xml export", xmlExport.indexOf(entityPart) != -1);
+
+ String propertyPart = property.substring(property.indexOf('.'));
+ Assert.assertTrue("Property " + property + " is not present in xml export", xmlExport.indexOf(propertyPart) != -1);
+ }
+
+ // close all
+ context.closeContext();
+ }
+}
Property changes on: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/mexico/export/RegionExplorerTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.h2.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.h2.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/46.t43.lob.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/46.t43.lob.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/47.t43.lob.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/47.t43.lob.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/48.t43.lob.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/48.t43.lob.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/49.t43.lob.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/49.t43.lob.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/50.t43.lob.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/50.t43.lob.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/51.t43.lob.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/51.t43.lob.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/52.t43.lob.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/52.t43.lob.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/53.t43.lob.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/53.t43.lob.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/54.t43.lob.db
===================================================================
(Binary files differ)
Property changes on: isis-fish/trunk/src/test/resources/test-database/regions/Golfe de Gascogne/data/data.lobs.db/54.t43.lob.db
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream