r1881 - in isis-fish/trunk: . src/main/java/fr/ifremer/isisfish src/main/java/fr/ifremer/isisfish/datastore src/main/java/fr/ifremer/isisfish/simulator src/main/java/fr/ifremer/isisfish/simulator/factors src/main/java/fr/ifremer/isisfish/simulator/launcher src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh src/main/java/fr/ifremer/isisfish/ui/script src/main/java/fr/ifremer/isisfish/util src/main/resources/i18n src/main/resources/templates src/main/resources/templates/prescript src
Author: chatellier Date: 2009-02-25 15:25:59 +0000 (Wed, 25 Feb 2009) New Revision: 1881 Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/FactorsAnalysePlan.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/ClasspathTemplateLoader.java isis-fish/trunk/src/main/resources/templates/prescript/ isis-fish/trunk/src/main/resources/templates/prescript/factorprescript.ftl isis-fish/trunk/src/main/resources/templates/sensitivity.ftl isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SensitivityStorageTest.java isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java Removed: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/ClasspathTemplateLoader.java Modified: isis-fish/trunk/pom.xml isis-fish/trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/AnalysePlanStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/AnalysePlan.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPreScript.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/Scenario.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/SensitivityCalculator.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties isis-fish/trunk/src/main/resources/templates/analyseplan.ftl isis-fish/trunk/src/main/resources/templates/equation.ftl isis-fish/trunk/src/main/resources/templates/export.ftl isis-fish/trunk/src/main/resources/templates/rule.ftl isis-fish/trunk/src/main/resources/templates/script.ftl isis-fish/trunk/src/main/resources/templates/simulator.ftl Log: Ajout des Storage pour les script de sensibilit?\195?\169s, et des ui pour les g?\195?\169r?\195?\169r. Modified: isis-fish/trunk/pom.xml =================================================================== --- isis-fish/trunk/pom.xml 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/pom.xml 2009-02-25 15:25:59 UTC (rev 1881) @@ -522,9 +522,9 @@ <!-- *** Build Environment ************************************** --> <!-- ************************************************************* --> <scm> - <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/isis-fish/isis-fish/trunk</connection> - <developerConnection>scm:svn:svn+ssh://sletellier at labs.libre-entreprise.org/svnroot/isis-fish/isis-fish/trunk</developerConnection> - <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/isis-fish/trunk/?root=isis-fish</url> + <connection>${maven.scm.connection}</connection> + <developerConnection>${maven.scm.developerConnection}</developerConnection> + <url>${maven.scm.url}</url> </scm> <!--Code Lutin Repository--> Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/IsisFish.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -59,6 +59,7 @@ import fr.ifremer.isisfish.datastore.RegionStorage; import fr.ifremer.isisfish.datastore.RuleStorage; import fr.ifremer.isisfish.datastore.ScriptStorage; +import fr.ifremer.isisfish.datastore.SensitivityStorage; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.datastore.SimulatorStorage; import fr.ifremer.isisfish.simulator.launcher.SimulationService; @@ -344,6 +345,7 @@ RuleStorage.checkout(); ScriptStorage.checkout(); SimulatorStorage.checkout(); + SensitivityStorage.checkout(); // on ne prend pas toutes les simu ni toutes les regions vcs.update(new File(local, SimulationStorage.SIMULATION_PATH), false); Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/AnalysePlanStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/AnalysePlanStorage.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/AnalysePlanStorage.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -1,5 +1,5 @@ -/* - * *##% Copyright (C) 2005 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% + * Copyright (C) 2005 - 2009 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * 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 @@ -16,18 +16,6 @@ * Place - Suite 330, Boston, MA 02111-1307, USA. ##% */ -/******************************************************************************* - * AnalysePlan.java - * - * Created: 17 août 2005 11:11:51 CEST - * - * @author Benjamin POUSSIN <poussin at codelutin.com> - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - package fr.ifremer.isisfish.datastore; import fr.ifremer.isisfish.IsisFishException; @@ -55,11 +43,16 @@ * Class permettant de representer un plan d'analyse. * Un plan d'analyse est un fichier Java que l'on compile si besoin. * <p/> - * Gere les fichiers CVS de type {@link AnalysePlan} (package analyseplans) + * Gere les fichiers VCS de type {@link AnalysePlan} (package analyseplans) * - * @author poussin + * Created: 17 août 2005 11:11:51 CEST + * + * @author Benjamin POUSSIN <poussin at codelutin.com> + * + * @version $Revision$ + * + * Last update: $Date$ by : $Author$ */ - public class AnalysePlanStorage extends JavaSourceStorage implements Docable { // AnalysePlanStorage public final static String ANALYSE_PLAN_PATH = "analyseplans"; @@ -75,7 +68,7 @@ /** - * Contruit un nouveau AnalysePlan storage + * Construit un nouveau AnalysePlan storage * * @param rootSrc repertoire root de stockage des plans * @param directory le repertoire ou devrait se trouver le plan @@ -103,10 +96,10 @@ } /** - * Retourne le storage pour la regle demandée + * Retourne le storage pour le plan demandé * - * @param name le nom de la regle souhaitée - * @return Le storage pour la regle + * @param name le nom du plan souhaité + * @return Le storage pour le plan */ static public AnalysePlanStorage getAnalysePlan(String name) { AnalysePlanStorage result = plansCache.get(name); @@ -120,7 +113,7 @@ /** - * Retourne une nouvelle instance de la regle. Compile le fichier si besoin + * Retourne une nouvelle instance du plan. Compile le fichier si besoin * * @return retourne une nouvelle instance du plan * @throws IsisFishException s'il y a un probleme d'instanciation @@ -131,7 +124,7 @@ } /** - * Permet de recuperer les parametres de la regle. + * Permet de recuperer les parametres du plan. * * @return Une map contenant le nom du parametre et son type * @throws IsisFishException s'il est impossible de retourner une map @@ -258,39 +251,39 @@ } /** - * Retourne la liste des noms de toutes les régions disponible en local qui - * ne sont pas encore sur le serveur CVS + * Retourne la liste des noms de tous les plans disponibles en local qui + * ne sont pas encore sur le serveur VCS. * - * @return liste de noms de regions + * @return liste de noms de plans */ - static public List<String> getNewAnalysePlanNames() { + public static List<String> getNewAnalysePlanNames() { List<String> result = getAnalysePlanNames(); result.removeAll(getRemoteAnalysePlanNames()); return result; } /** - * Retourne la liste des noms de toutes les régions disponible sur le - * serveur CVS + * Retourne la liste des noms de tous les plans disponibles sur le + * serveur VCS. * - * @return la liste des noms de toutes les régions disponible sur le serveur - * CVS. Si le serveur n'est pas disponible la liste retournée est + * @return la liste des noms de tous les plans disponibles sur le serveur + * VCS. Si le serveur n'est pas disponible la liste retournée est * vide. */ - static public List<String> getRemoteAnalysePlanNames() { + public static List<String> getRemoteAnalysePlanNames() { File dir = getAnalysePlanDirectory(); return getRemoteStorageNames(dir); } /** - * Retourne la liste des noms de toutes les régions disponible sur le - * serveur CVS qui ne sont pas encore en local + * Retourne la liste des noms de tous les plans disponibles sur le + * serveur VCS qui ne sont pas encore en local * * @return liste de noms de regions - * @throws org.codelutin.vcs.VCSException + * @throws VCSException */ - static public List<String> getNewRemoteAnalysePlanNames() throws VCSException { + public static List<String> getNewRemoteAnalysePlanNames() throws VCSException { List<String> result = getRemoteAnalysePlanNames(); result.removeAll(getAnalysePlanNames()); return result; Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/CodeSourceStorage.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -1,5 +1,5 @@ /* - * *##% Copyright (C) 2006 Code Lutin, Cédric Pineau, Benjamin Poussin + * *##% Copyright (C) 2006 - 2009 Code Lutin, Cédric Pineau, Benjamin Poussin * * 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 @@ -16,18 +16,6 @@ * Place - Suite 330, Boston, MA 02111-1307, USA. ##% */ -/******************************************************************************* - * CodeSourceStorage.java - * - * Created: 21 janv. 2006 15:20:24 - * - * @author poussin - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - package fr.ifremer.isisfish.datastore; import fr.ifremer.isisfish.IsisFishRuntimeException; @@ -39,14 +27,22 @@ import java.io.IOException; /** - * Classes abstraite permettant la gestion des fichiers de code source + * Classes abstraite permettant la gestion des fichiers de code source. + * * {@link fr.ifremer.isisfish.datastore.ScriptStorage}, * {@link fr.ifremer.isisfish.datastore.RuleStorage}, - * {@link fr.ifremer.isisfish.datastore.ExportStorage} + * {@link fr.ifremer.isisfish.datastore.ExportStorage}, + * {@link fr.ifremer.isisfish.datastore.AnalysePlanStorage}, + * {@link fr.ifremer.isisfish.datastore.SensitivityStorage} + * + * Created: 21 janv. 2006 15:20:24 * * @author poussin + * + * @version $Revision$ + * + * Last update: $Date$ by : $Author$ */ - public abstract class CodeSourceStorage extends VersionStorage { /** @@ -77,9 +73,11 @@ * @param name le nom de la classe * @param suffix l'extension des fichiers */ - protected CodeSourceStorage(File rootSrc, File directory, String name, String suffix) { + protected CodeSourceStorage(File rootSrc, File directory, String name, + String suffix) { // if name end with suffix we don't add suffix to filename - super(rootSrc, name.endsWith(suffix) ? new File(directory, name) : new File(directory, name + suffix)); + super(rootSrc, name.endsWith(suffix) ? new File(directory, name) + : new File(directory, name + suffix)); this.name = name.endsWith(suffix) ? name : name + suffix; } @@ -118,8 +116,7 @@ * @return le contenu du fichier */ public String getContent() { - if (content == null - || getFile().lastModified() > lastContentUpdate + if (content == null || getFile().lastModified() > lastContentUpdate || getFile().length() != lastContentLength) { if (!exists()) { content = ""; @@ -142,7 +139,8 @@ */ public void setContent(String content) throws IOException { this.content = content; - FileUtil.writeString(getFile(), content); + // FIXME hard coded encoding ? + FileUtil.writeString(getFile(), content, "utf-8"); lastContentUpdate = System.nanoTime(); lastContentLength = getFile().length(); } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/RuleStorage.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -1,5 +1,5 @@ -/* - * *##% Copyright (C) 2005 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin +/* *##% + * Copyright (C) 2005 - 2009 Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * 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 @@ -16,18 +16,6 @@ * Place - Suite 330, Boston, MA 02111-1307, USA. ##% */ -/******************************************************************************* - * RuleStorage.java - * - * Created: 17 août 2005 11:11:51 CEST - * - * @author Benjamin POUSSIN <poussin at codelutin.com> - * - * @version $Revision$ - * - * Last update: $Date$ by : $Author$ - */ - package fr.ifremer.isisfish.datastore; import fr.ifremer.isisfish.IsisFishException; @@ -60,7 +48,13 @@ * <p/> * Gere les fichiers VCS de type {@link Rule} (package rules) * - * @author poussin + * Created: 17 août 2005 11:11:51 CEST + * + * @author Benjamin POUSSIN <poussin at codelutin.com> + * + * @version $Revision$ + * + * Last update: $Date$ by : $Author$ */ public class RuleStorage extends JavaSourceStorage implements Docable { // RulesStorage @@ -213,7 +207,7 @@ } /** - * Modifie la valeur d'un attribut pas introspection + * Modifie la valeur d'un attribut par introspection. * * @param name le nom de l'attribut * @param value la valeur de l'attribut Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityStorage.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityStorage.java (rev 0) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/datastore/SensitivityStorage.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -0,0 +1,391 @@ +/* *##% Copyright (C) 2009 Ifremer, Code Lutin + * + * 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.datastore; + +import fr.ifremer.isisfish.IsisFishException; +import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.simulator.factors.SensitivityCalculator; +import fr.ifremer.isisfish.util.Doc; +import fr.ifremer.isisfish.util.DocHelper; +import fr.ifremer.isisfish.util.Docable; +import fr.ifremer.isisfish.vcs.VCSException; + +import static org.codelutin.i18n.I18n._; + +import org.apache.commons.collections.map.ReferenceMap; +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.File; +import java.lang.reflect.Field; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * Cette class permet de stocker les fichiers de calculateur de sensibilité. + * <p/> + * Gere les fichiers VCS de type {@link SensitivityCalculator} (package sensitivity). + * + * Created: 17 août 2005 11:11:51 CEST + * + * @author chatellier <chatellier at codelutin.com> + * @version $Revision: 1628 $ + * Last update: $Date: 2008-11-28 10:25:59 +0100 (ven 28 nov 2008) $ by : $Author: chatellier $ + */ +public class SensitivityStorage extends JavaSourceStorage implements Docable { // SensitivityStorage + + /** to use log facility, just put in your code: log.info(\"...\"); */ + private static Log log = LogFactory.getLog(SensitivityStorage.class); + + /** Emplacement de stockage des fichiers de sensibilité */ + public final static String SENSITIVITY_PATH = "sensitivity"; + + /** Template freemarker pour les scripts de sensibilité. */ + public static final String SENSIVITY_TEMPLATE = "templates/sensitivity.ftl"; + + /** + * Prefix des paramètres de la classe. + * + * ex : public int param_count; + */ + protected final static String PARAM_PREFIX = "param_"; + + /** Cache. */ + protected static Map<String, SensitivityStorage> sensitivityCache = new ReferenceMap(); + + /** + * Build new {@link SensitivityStorage}. + * + * @param rootSrc repertoire root de stockage des calculateurs de sensibilité. + * @param directory le repertoire ou devrait se trouver le calculateur de sensibilité + * @param name le nom du calculateur de sensibilité + */ + protected SensitivityStorage(File rootSrc, File directory, String name) { + super(rootSrc, directory, name); + } + + /** + * Get sensitivity storage directory. + * + * Create directory if not exists. + * + * @return sensitivity storage directory + */ + public static File getSensitivityDirectory() { + File result = IsisFish.config.getDatabaseDirectory(); + result = new File(result, SENSITIVITY_PATH); + result.mkdirs(); + return result; + } + + /** + * Retourne le nom de tous les calculateurs de sensibilité existans. + * + * @return le nom de tous les calculateurs de sensibilité existans en local + */ + public static List<String> getSensitivityNames() { + File dir = getSensitivityDirectory(); + return SensitivityStorage.getStorageNames(dir); + } + + /** + * Retourne le storage pour le calculateur demandé. + * + * @param name le nom du calculateur souhaité + * @return Le {@link SensitivityStorage} pour le calculateur + */ + public static SensitivityStorage getSensitivity(String name) { + SensitivityStorage result = sensitivityCache.get(name); + if (result == null) { + result = new SensitivityStorage(IsisFish.config + .getDatabaseDirectory(), getSensitivityDirectory(), name); + sensitivityCache.put(name, result); + } + return result; + } + + /** + * Retourne une nouvelle instance du calculateur. Compile le fichier si besoin + * + * @return retourne une nouvelle instance du calculateur + * @throws IsisFishException s'il y a un problème d'instanciation + */ + public SensitivityCalculator getNewSensitivityInstance() throws IsisFishException { + Object result = getNewInstance(); + return (SensitivityCalculator) result; + } + + /** + * Permet de recuperer les parametres du calculateur. + * + * @return Une map contenant le nom du parametre et son type + * @throws IsisFishException s'il est impossible de retourner une map + * convenable + */ + public Map<String, Class<?>> getParameterNames() throws IsisFishException { + Map<String, Class<?>> result = null; + // On essai de recuperer les paramètres depuis la classe compilé + // si c possible + try { + if (0 == compile(false, null)) { + SensitivityCalculator calculator = getNewSensitivityInstance(); + result = SensitivityStorage.getParameterNames(calculator); + } + } catch (Exception eee) { + log.info(_("isisfish.error.sensitivity.parameter"), eee); + } + // si on ne reussi pas avec la classe compilé on essai en parsant le + // source + if (result == null) { + try { + //String code = getContent(); + log + .fatal("FIXME a faire recherche des parametre dans le source"); + throw new IsisFishException( + _("isisfish.error.source.parameter")); + // TODO implanter la recherche des parametres. + // Se sont les attributs commencant par 'param_' et ils doivent + // etre public non static, non transient. + // ex: public Date param_Date. + // Lorsqu'on ajoute un champs dans la map il ne faut pas mettre + // le prefix param. + } catch (Exception eee) { + throw new IsisFishException( + _("isisfish.error.source.parameter"), eee); + } + } + return result; + } + + /** + * Recherche par introspection tous les parametres de la classe + * commencant par {@link #PARAM_PREFIX}. + * + * @param calculator le calculateur dont on souhaite les infos de parametre + * @return retourne le nom et le type des parametres du calculateur + */ + public static Map<String, Class<?>> getParameterNames( + SensitivityCalculator calculator) { + Map<String, Class<?>> result = new LinkedHashMap<String, Class<?>>(); + for (Field field : calculator.getClass().getFields()) { + if (field.getName().startsWith(PARAM_PREFIX)) { + result.put(field.getName().substring(PARAM_PREFIX.length()), + field.getType()); + } + } + return result; + } + + /** + * Donne la valeur d'un parametre par introspection. + * + * @param name le nom du parametre + * @param calculator le calculateur dont on souhaite la valeur du parametre + * @return la valeur courante du parametre + * @throws IsisFishException s'il y a un probleme pour recuperer la valeur + */ + public static Object getParameterValue(SensitivityCalculator calculator, + String name) throws IsisFishException { + if (calculator == null || name == null || "".equals(name)) { + return null; + } + try { + String fieldName = PARAM_PREFIX + name; + Field field = calculator.getClass().getDeclaredField(fieldName); + return field.get(calculator); + } catch (IllegalAccessException eee) { + throw new IsisFishException("Can't get plan parameter: " + name, + eee); + } catch (NoSuchFieldException eee) { + throw new IsisFishException("Can't get plan parameter: " + name, + eee); + } + } + + /** + * Modifie la valeur d'un attribut pas introspection. + * + * @param name le nom de l'attribut + * @param value la valeur de l'attribut + * @param calculator le calculator dont on souhaite modifier la valeur de parametre + * @throws IsisFishException s'il y a un probleme + */ + public static void setParameterValue(SensitivityCalculator calculator, + String name, Object value) throws IsisFishException { + try { + String fieldName = PARAM_PREFIX + name; + Field field = calculator.getClass().getDeclaredField(fieldName); + field.set(calculator, value); + } catch (IllegalAccessException eee) { + throw new IsisFishException("Can't modify plan parameter: " + name + + " with '" + value + "'(" + + ObjectUtils.identityToString(value) + ")", eee); + } catch (NoSuchFieldException eee) { + throw new IsisFishException("Can't modify plan parameter: " + name + + " with '" + value + "'(" + + ObjectUtils.identityToString(value) + ")", eee); + } catch (IllegalArgumentException eee) { + throw new IsisFishException("Can't modify plan parameter: " + name + + " with '" + value + "'(" + + ObjectUtils.identityToString(value) + ")", eee); + } + } + + /** + * Recupere les paramètres et leur valeur pour les retourner sous forme + * de chaine. Pour pouvoir par exemple les afficher à l'utilisateur. + * + * @param calculator le calculateur dont on souhaite la valeur du parametre en string + * @return la valeur sous forme de string + * @throws IsisFishException + */ + public static String getParamAsString(SensitivityCalculator calculator) + throws IsisFishException { + StringBuffer result = new StringBuffer(); + + for (String name : getParameterNames(calculator).keySet()) { + Object value = getParameterValue(calculator, name); + + result.append(name).append(" : ").append(value); + result.append("\n"); + } + return result.toString(); + } + + /** + * Effectue un chekout VCS sur le répertoire des calculateurs. + * + * @see VersionStorage#checkout(File, String) + * @see #SENSITIVITY_PATH + * + * @throws VCSException if an error occurs during checkout + */ + public static void checkout() throws VCSException { + checkout(IsisFish.config.getDatabaseDirectory(), SENSITIVITY_PATH); + } + + /** + * Retourne la liste des noms de tous les calculateurs disponibles en local qui + * ne sont pas encore sur le serveur VCS. + * + * @return liste de noms de calculateurs + */ + static public List<String> getNewAnalysePlanNames() { + List<String> result = getSensitivityNames(); + result.removeAll(getRemoteSensitivityNames()); + return result; + } + + /** + * Retourne la liste des noms de tous les calculateurs disponibles sur le + * serveur VCS + * + * @return la liste des noms de tous les calculateurs disponibles sur le serveur + * VCS. Si le serveur n'est pas disponible la liste retournée est + * vide. + */ + static public List<String> getRemoteSensitivityNames() { + File dir = getSensitivityDirectory(); + return getRemoteStorageNames(dir); + + } + + /** + * Retourne la liste des noms de tous les calculateurs disponibles sur le + * serveur VCS qui ne sont pas encore en local. + * + * @return liste de noms de regions + * @throws VCSException + */ + static public List<String> getNewRemoteSensitivityNames() + throws VCSException { + List<String> result = getRemoteSensitivityNames(); + result.removeAll(getSensitivityNames()); + return result; + } + + /** + * @return the @Doc of the underlied {@link SensitivityCalculator} class + * @see DocHelper + * @see Doc + * @see Docable + */ + public Doc getClassDoc() { + Doc result = null; + try { + Class<?> klazz = getCodeClass(); + result = DocHelper.getClassDoc(klazz); + } catch (IsisFishException e) { + if (log.isWarnEnabled()) { + log.warn(_("isisfish.error.not.found.code", this)); + } + } + return result; + } + + /** + * @param fieldName name of the field to inspect + * @return the @Doc of the given field of the underlied {@link SensitivityCalculator} class + * @see DocHelper + * @see Doc + * @see Docable + */ + public Doc getFieldDoc(String fieldName) { + Doc result = null; + try { + Class<?> klazz = getCodeClass(); + result = DocHelper.getFieldDoc(klazz, fieldName); + } catch (Exception e) { + log.warn(_("isisfish.error.not.found.field", fieldName, this)); + } + return result; + } + + /** + * @param paramName the name of the param to inspect + * @return the doc associated with the param, + * (says the field {@link #PARAM_PREFIX} + fieldName) + */ + public Doc getParamDoc(String paramName) { + Doc doc; + doc = getFieldDoc(PARAM_PREFIX + paramName); + return doc; + } + + /** + * <b>Be ware this method require to instanciate a AnalysePlan, so + * it would be better to call as often as possible.</b> + * + * @return the descript of the instanciate AnalysePlan + * @see Doc + * @see Docable + */ + public String getDescription() { + String result = null; + try { + SensitivityCalculator calculator = getNewSensitivityInstance(); + result = calculator == null ? null : calculator.getDescription(); + } catch (Exception e) { + log.warn(_("isisfish.error.not.found.description", this)); + } + return result; + } + +} // SensitivityStorage Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/AnalysePlan.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/AnalysePlan.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/AnalysePlan.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -31,6 +31,8 @@ * * Last update: $Date$ * by : $Author$ + * + * FIXME in english it's "AnalyzePlan" ;) */ public interface AnalysePlan { Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationParameter.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -15,8 +15,6 @@ * Place - Suite 330, Boston, MA 02111-1307, USA. ##% */ - - package fr.ifremer.isisfish.simulator; import static org.codelutin.i18n.I18n._; @@ -73,8 +71,10 @@ /** Logger for this class. */ private static Log log = LogFactory.getLog(SimulationParameter.class); - /** Isis-fish version that permit to do the simulation, must be set just - * before simulation by simulator. */ + /** + * Isis-fish version that permit to do the simulation, must be set just + * before simulation by simulator. + */ protected String isisFishVersion = IsisConfig.getVersion(); /** description de la simulation */ @@ -83,7 +83,7 @@ /** nom de la region sur lequel on simule */ protected String regionName = ""; - /** nombre d'ann?e sur lequel on souhaite simuler */ + /** nombre d'année sur lequel on souhaite simuler */ protected int numberOfYear = 1; /** le nom de l'objet script a utiliser pour faire la simulation */ @@ -101,13 +101,13 @@ /** la liste des populations a utiliser pour la simulation */ protected List<Population> populations = new ArrayList<Population>(); - /** les effectifs initiaux des diff?rentes population */ + /** les effectifs initiaux des différentes population */ protected Map<Population, MatrixND> numbers = new HashMap<Population, MatrixND>(); /** la liste des regles de gestions a utiliser pour la simulation */ protected List<Rule> rules = new ArrayList<Rule>(); - /** la liste des regles potentiellement ajout?e par les plans d'analyse */ + /** la liste des regles potentiellement ajoutée par les plans d'analyse */ protected List<String> extraRules = new ArrayList<String>(); /** la liste des plans a utiliser pour la simulation */ @@ -147,7 +147,7 @@ */ protected boolean onlyExport = false; - transient protected RegionStorage region = null; + protected transient RegionStorage region = null; /** le niveau de log du simulateur à utiliser pendant la simulation , par default info */ protected String simulLogLevel = "info"; Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPreScript.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPreScript.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/SimulationPreScript.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2007 + * Copyright (C) 2007 - 2009 * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -17,53 +17,40 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *##%*/ -/* * - * SimulationPreScript.java - * - * Created: 14 nov. 07 00:06:18 - * - * @author poussin - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ - package fr.ifremer.isisfish.simulator; import static org.codelutin.i18n.I18n._; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.codelutin.topia.TopiaContext; -import org.codelutin.topia.TopiaException; -import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.datastore.SimulationStorage; -import bsh.EvalError; import bsh.Interpreter; - /** + * SimulationPreScript. + * + * Created: 14 nov. 07 00:06:18 + * * @author poussin + * @version $Revision$ * + * Last update: $Date$ + * by : $Author$ */ - public class SimulationPreScript implements SimulationListener { - /** to use log facility, just put in your code: log.info(\"...\"); */ - static private Log log = LogFactory.getLog(SimulationPreScript.class); - - /* (non-Javadoc) + /* * @see fr.ifremer.isisfish.simulator.SimulationListener#afterSimulation(fr.ifremer.isisfish.simulator.SimulationContext) */ + @Override public void afterSimulation(SimulationContext context) { } - /* (non-Javadoc) + /* * @see fr.ifremer.isisfish.simulator.SimulationListener#beforeSimulation(fr.ifremer.isisfish.simulator.SimulationContext) */ + @Override public void beforeSimulation(SimulationContext context) { try { context.message(_("isisfish.message.presimulation.script.execution")); @@ -72,29 +59,29 @@ SimulationParameter parameters = simulation.getParameter(); String presimulationScript = parameters.getPreScript(); if ((parameters.getUsePreScript() || parameters.getUseAnalysePlan()) - && presimulationScript != null && !"".equals(presimulationScript)) { - + && presimulationScript != null + && !"".equals(presimulationScript)) { + // utilisation de la db en memoire que l'on commitera TopiaContext tx = context.getDB(); - + Interpreter bsh = new Interpreter(); bsh.set("context", context); bsh.set("db", tx); bsh.eval("import org.codelutin.topia.*;"); + bsh.eval("import org.codelutin.topia.persistence.*;"); bsh.eval("import fr.ifremer.isisfish.*;"); bsh.eval("import java.util.*;"); bsh.eval("import fr.ifremer.isisfish.types.*;"); bsh.eval("import fr.ifremer.isisfish.types.Date;"); bsh.eval("import fr.ifremer.isisfish.entities.*;"); bsh.eval(presimulationScript); - + tx.commitTransaction(); } } catch (Exception eee) { - throw new SimulationException(_("Can''t evaluate simulation prescript"), eee); + throw new SimulationException( + _("Can't evaluate simulation prescript"), eee); } } - } - - Added: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/FactorsAnalysePlan.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/FactorsAnalysePlan.java (rev 0) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/FactorsAnalysePlan.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -0,0 +1,182 @@ +/* *##% + * Copyright (C) 2009 Code Lutin + * + * 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.simulator.factors; + +import static org.codelutin.i18n.I18n._; + +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaException; +import org.codelutin.topia.persistence.TopiaEntity; + +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.simulator.AnalysePlanContext; +import fr.ifremer.isisfish.simulator.AnalysePlanIndependent; +import fr.ifremer.isisfish.util.Doc; + +/** + * Analyze plan to manage factors. + * + * This plan is independent, because factors do not depend + * each others. + * + * @author chatellier + * @version $Revision: 1.0 $ + * + * Last update : $Date: 23 févr. 2009 $ + * By : $Author: chatellier $ + */ +public class FactorsAnalysePlan implements AnalysePlanIndependent { + + /** to use log facility, just put in your code: log.info("..."); */ + private static Log log = LogFactory.getLog(FactorsAnalysePlan.class); + + /** + * Domaine à utiliser pour le plan d'analyse. + */ + @Doc(value = "Factors design plan") + public DesignPlan designPlan; + + /** + * Map entre les numeros de simulation et les facteurs + * a appliquer à cette simulation. + * + * Start at 0. + */ + protected Map<Integer, List<Factor<? extends Serializable>>> simulationsFactors; + + /* + * @see fr.ifremer.isisfish.simulator.AnalysePlan#getDescription() + */ + @Override + public String getDescription() throws Exception { + return _("Factors analyse plan"); + } + + /* + * @see fr.ifremer.isisfish.simulator.AnalysePlan#getNecessaryResult() + */ + @Override + public String[] getNecessaryResult() { + // return value could not be null + return new String[0]; + } + + /* + * @see fr.ifremer.isisfish.simulator.AnalysePlan#init(fr.ifremer.isisfish.simulator.AnalysePlanContext) + */ + @Override + public void init(AnalysePlanContext context) throws Exception { + + // here to call R ? + SensitivityCalculator sensitivityCalculator = null; + + /*Scenario scenario = sensitivityCalculator.getScenario(designPlan); + scenarioToMap(scenario);*/ + } + + /** + * Convertit un scenario en une map indexée. + * + * Methode a part pour être stéreotypée. + */ + protected void scenarioToMap(Scenario scenario) + throws Exception { + int simulationIndex = 0; + simulationsFactors = new HashMap<Integer, List<Factor<? extends Serializable>>>(); + /*for (List<Factor<? extends Serializable>> scenarioValue : scenario.getFactors()) { + simulationsFactors.put(simulationIndex, scenarioValue); + simulationIndex++; + }*/ + } + + /* + * @see fr.ifremer.isisfish.simulator.AnalysePlan#beforeSimulation(fr.ifremer.isisfish.simulator.AnalysePlanContext, fr.ifremer.isisfish.datastore.SimulationStorage) + */ + @Override + public boolean beforeSimulation(AnalysePlanContext context, + SimulationStorage nextSimulation) throws Exception { + + int simulationNumber = context.getNumber(); + + if (log.isInfoEnabled()) { + log.info("Before simulation number " + simulationNumber); + } + + List<Factor<? extends Serializable>> factors = simulationsFactors.get(simulationNumber); + + if (log.isDebugEnabled()) { + // get specified line in domain array + // to inject into simulation storage + log.debug("Factor used for this simulation" + factors); + } + + putFactorIntoSimulation(factors, nextSimulation); + + // true to do next simulation + return true; + } + + /** + * Put factors value into simulation. + * + * @param factors to put + * @param simulation to put factors into + * @throws TopiaException if db errors + * @throws InvocationTargetException + * @throws IllegalAccessException + */ + protected void putFactorIntoSimulation(List<Factor<? extends Serializable>> factors, SimulationStorage simulation) throws TopiaException, IllegalAccessException, InvocationTargetException { + // inject factors into simulation + TopiaContext rootContext = simulation.getStorage(); + TopiaContext childContext = rootContext.beginTransaction(); + + for (Factor<? extends Serializable> factor : factors) { + Serializable value = factor.getValue(); + String path = factor.getPath(); + + // path is like "org.codelutin.factor#1234567890#0.12242345354#name" + String topiaId = path.substring(0, path.lastIndexOf("#")); + String propertyName = path.substring(0, path.lastIndexOf("#")); + + TopiaEntity entity = childContext.findByTopiaId(topiaId); + BeanUtils.setProperty(entity, propertyName, value); + } + } + + /* + * @see fr.ifremer.isisfish.simulator.AnalysePlan#afterSimulation(fr.ifremer.isisfish.simulator.AnalysePlanContext, fr.ifremer.isisfish.datastore.SimulationStorage) + */ + @Override + public boolean afterSimulation(AnalysePlanContext context, + SimulationStorage lastSimulation) throws Exception { + + // true to do next simulation + return true; + } +} Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/Scenario.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/Scenario.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/Scenario.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -65,7 +65,7 @@ * * @param factors the simulations factors to set */ - public void setSimulationsFactors(List<Factor<? extends Serializable>> factors) { + public void setFactors(List<Factor<? extends Serializable>> factors) { this.factors = factors; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/SensitivityCalculator.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/SensitivityCalculator.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/factors/SensitivityCalculator.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -35,6 +35,14 @@ public interface SensitivityCalculator { /** + * Return calculator description. + * + * @return calculator description + * @throws Exception + */ + String getDescription() throws Exception; + + /** * Envoi un plan a faire analyser par l'outils * d'analyse de sensibilité. * Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/SSHSimulatorLauncher.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -42,10 +42,10 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.datastore.SimulationStorage; import fr.ifremer.isisfish.simulator.SimulationControl; -import fr.ifremer.isisfish.simulator.launcher.ssh.ClasspathTemplateLoader; import fr.ifremer.isisfish.simulator.launcher.ssh.SSHException; import fr.ifremer.isisfish.simulator.launcher.ssh.SSHUserInfo; import fr.ifremer.isisfish.simulator.launcher.ssh.SSHUtils; +import fr.ifremer.isisfish.util.ClasspathTemplateLoader; import freemarker.cache.TemplateLoader; import freemarker.template.Configuration; import freemarker.template.Template; Deleted: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/ClasspathTemplateLoader.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/ClasspathTemplateLoader.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/ClasspathTemplateLoader.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -1,68 +0,0 @@ -/* *##% - * Copyright (C) 2008, 2009 Code Lutin - * - * 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.simulator.launcher.ssh; - -import java.net.URL; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.util.Resource; -import org.codelutin.util.ResourceNotFoundException; - -import freemarker.cache.URLTemplateLoader; - -/** - * Freemarker custom template loader. - * Load template from classpath jars. - * - * @author chatellier - * @version $Revision: 1.0 $ - * - * Last update : $Date: 1 déc. 2008 $ - * By : $Author: chatellier $ - */ -public class ClasspathTemplateLoader extends URLTemplateLoader { - - /** log */ - private static Log log = LogFactory.getLog(ClasspathTemplateLoader.class); - - /* - * @see freemarker.cache.URLTemplateLoader#getURL(java.lang.String) - */ - @Override - protected URL getURL(String name) { - - if (log.isDebugEnabled()) { - log.debug("Loading url template " + name); - } - - URL url = null; - - try { - url = Resource.getURL(name); - } catch (ResourceNotFoundException e) { - // not big deal - // freemarker ask for name_fr_FR, name_fr, name - url = null; - } - - return url; - } - -} Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -28,11 +28,14 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.io.StringWriter; +import java.io.Writer; import java.lang.reflect.Method; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.swing.JOptionPane; import javax.swing.tree.DefaultMutableTreeNode; @@ -43,6 +46,7 @@ import org.codelutin.util.FileUtil; import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.IsisFishRuntimeException; import fr.ifremer.isisfish.datastore.AnalysePlanStorage; import fr.ifremer.isisfish.datastore.CodeSourceStorage; import fr.ifremer.isisfish.datastore.ExportStorage; @@ -50,11 +54,16 @@ import fr.ifremer.isisfish.datastore.JavaSourceStorage; import fr.ifremer.isisfish.datastore.RuleStorage; import fr.ifremer.isisfish.datastore.ScriptStorage; +import fr.ifremer.isisfish.datastore.SensitivityStorage; import fr.ifremer.isisfish.datastore.SimulatorStorage; import fr.ifremer.isisfish.equation.Language; import fr.ifremer.isisfish.ui.widget.ErrorDialogUI; import fr.ifremer.isisfish.ui.widget.editor.GenericCell; +import fr.ifremer.isisfish.util.ClasspathTemplateLoader; import fr.ifremer.isisfish.vcs.VCSException; +import freemarker.cache.TemplateLoader; +import freemarker.template.Configuration; +import freemarker.template.Template; class ScriptFileFilter implements FileFilter { protected FileFilter filter; @@ -71,6 +80,8 @@ /** * ScriptAction. * + * Template are now loaded with freemarker. + * * @author letellier * @version $Revision: 1526 $ * @@ -78,16 +89,35 @@ * by : $Author: tchemit $ */ public class ScriptAction { - + /** to use log facility, just put in your code: log.info(\"...\"); */ private static Log log = LogFactory.getLog(ScriptAction.class); - + protected CodeSourceStorage code; - + protected File fileOpen = null; + protected Configuration freemarkerConfiguration; + + /** + * Constructeur. + * + * Init freemarker. + */ public ScriptAction() { + freemarkerConfiguration = new Configuration(); + + // needed to overwrite "Defaults to default system encoding." + // fix encoding issue on some systems + freemarkerConfiguration.setDefaultEncoding("utf-8"); + + // specific template loader to get template from jars (classpath) + TemplateLoader templateLoader = new ClasspathTemplateLoader(); + freemarkerConfiguration.setTemplateLoader(templateLoader); + + //freemarkerConfiguration.setObjectWrapper(new BeansWrapper()); + } protected void showMsgBox(Exception eee) { @@ -130,6 +160,10 @@ return AnalysePlanStorage.getAnalysePlanNames(); } + public List<String> getSensitivityNames() { + return SensitivityStorage.getSensitivityNames(); + } + public List<String> getCategories() { return FormuleStorage.getCategories(); } @@ -162,6 +196,10 @@ return FormuleStorage.getFormuleDirectory(); } + public File getSensitivityDirectory() { + return SensitivityStorage.getSensitivityDirectory(); + } + /** * Creer un nouveau script, ici un script peut-etre un Script, un Simulator, * un Export. @@ -171,7 +209,7 @@ * ou Export. */ public void newScript(String fileName, String scriptType) { - + if (log.isDebugEnabled()) { log.info("newScript called [" + scriptType + "]"); } @@ -224,8 +262,6 @@ } //TODO do test on category CodeSourceStorage script = null; - String template; - template = mapping.getDefaultContent(); switch (mapping) { case EquationModel: script = FormuleStorage.createFormule(category, realFilename, @@ -246,6 +282,9 @@ case Simulator: script = SimulatorStorage.getSimulator(fileName); break; + case Sensitivity: + script = SensitivityStorage.getSensitivity(fileName); + break; default: log.fatal("ScriptType unknown: " + scriptType); } @@ -259,12 +298,50 @@ .getMessage()), e); } - // add default script content - String content = MessageFormat.format(template, - category.isEmpty() ? "" : '.' + category.replaceAll("\\/", - "."), realFilename, new Date(), IsisFish.config - .getUserName(), IsisFish.config.getUserMail()); - script.setContent(content); + String scriptContent = mapping.getDefaultContent(); + String scriptTemplatePath = mapping.getTemplatePath(); + + if (scriptTemplatePath != null) { + + if (log.isDebugEnabled()) { + log.debug("Parsing freemarker template located in " + + scriptTemplatePath); + } + + // get template + Template template = freemarkerConfiguration + .getTemplate(scriptTemplatePath); + + // context values + Map<String, Object> root = new HashMap<String, Object>(); + // FIXME what is category ? + root.put("category", ""); + root.put("name", realFilename); + root.put("date", new Date()); + root.put("author", IsisFish.config.getUserName()); + root.put("email", IsisFish.config.getUserMail()); + + // process template + Writer out = new StringWriter(); + template.process(root, out); + out.flush(); + script.setContent(out.toString()); + } else if (scriptContent != null) { + // FIXME remove this part when ant script will be in FTL + + // add default script content + String content = MessageFormat.format(scriptContent, + category.isEmpty() ? "" : '.' + category.replaceAll( + "\\/", "."), realFilename, new Date(), + IsisFish.config.getUserName(), IsisFish.config + .getUserMail()); + script.setContent(content); + + } else { + throw new IsisFishRuntimeException( + "There is no content nor templatePath"); + } + code = script; } catch (Exception eee) { returnError(_("isisfish.error.script.create", fileName, eee @@ -304,6 +381,9 @@ case Simulator: script = SimulatorStorage.getSimulator(fileName); break; + case Sensitivity: + script = SensitivityStorage.getSensitivity(fileName); + break; default: log.fatal("ScriptType unknown: " + fileName); } @@ -344,30 +424,30 @@ // save script before commit code.setContent(content); String msg = JOptionPane - .showInputDialog(_("Indiquez vos modifications")); + .showInputDialog(_("isisfish.message.script.commit")); if (msg == null) { result = _("isisfish.message.commit.cancelled"); } else { - + try { code.commit(msg); code.reload(); result = _("isisfish.message.commit.finished"); - } - catch(VCSException e) { - + } catch (VCSException e) { + // FIXME enable/disable button only // if vcs can write JOptionPane.showMessageDialog(null, e.getMessage(), - _("isisfish.common.error"), JOptionPane.ERROR_MESSAGE); - if(log.isWarnEnabled()) { + _("isisfish.common.error"), + JOptionPane.ERROR_MESSAGE); + if (log.isWarnEnabled()) { log.warn("Exception on commit", e); } } } return null; } catch (Exception ex) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Error on script commit", ex); } } @@ -465,7 +545,7 @@ code.update(); code.reload(); } catch (VCSException ex) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Error on script update", ex); } } @@ -474,7 +554,9 @@ public String checkScript(String content) { String resultLog = ""; try { - log.debug("checkScript called"); + if (log.isDebugEnabled()) { + log.debug("checkScript called"); + } // save script before commit code.setContent(content); JavaSourceStorage javaCode = (JavaSourceStorage) code; @@ -498,7 +580,7 @@ resultLog = "ok"; } } catch (IOException ex) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Error on script check", ex); } } @@ -507,7 +589,10 @@ public String evaluateScript(String content) { - log.debug("evaluateScript called"); + if (log.isDebugEnabled()) { + log.debug("evaluateScript called"); + } + String msg = ""; try { String checkResult = checkScript(content); @@ -531,7 +616,7 @@ System.setErr(oldErr); msg = result.toString(); } catch (Exception ex) { - if(log.isErrorEnabled()) { + if (log.isErrorEnabled()) { log.error("Error on script evaluation", ex); } } @@ -540,7 +625,9 @@ public String importScript() { String msg = null; - log.debug("importScript "); + if (log.isDebugEnabled()) { + log.debug("importScript "); + } // TODO : a reimplanter try { msg = _("isisfish.message.import.scripts.file.cancelled"); @@ -587,7 +674,7 @@ } /** enum to encapsulate a script module */ - enum ScriptMapping { + protected enum ScriptMapping { Script( ScriptStorage.getScriptDirectory(), @@ -626,7 +713,8 @@ + "\n" + " /** to use log facility, just put in your code: log.info(\"...\"); */\n" + " static private Log log = LogFactory.getLog({1}.class);\n" - + "\n" + " // add your method here\n" + "'}'\n"), + + "\n" + " // add your method here\n" + "'}'\n", + null), Simulator( SimulatorStorage.getSimulatorDirectory(), @@ -669,8 +757,7 @@ + "\n" + " public void simulate(SimulationContext context) throws Exception '{'\n" + " // put your code here\n" + " '}'\n" - + "\n" + "'}'\n"), - Export( + + "\n" + "'}'\n", null), Export( ExportStorage.getExportDirectory(), /** * 0 = package name, @@ -741,9 +828,9 @@ + "\n" + " public void export(SimulationStorage simulation, Writer out) throws Exception '{'\n" + " // put your code here, and write export with: out.write(\"...\")\n" - + " '}'\n" + "\n" + "'}'\n"), - - Rule( + + " '}'\n" + "\n" + "'}'\n", null), + + Rule( RuleStorage.getRuleDirectory(), /** * 0 = package name, @@ -845,9 +932,10 @@ + " * @param simulation La simulation pour lequel on utilise cette regle\n" + " */\n" + " public void postAction(SimulationContext context, Date date, Metier metier) throws Exception '{'\n" - + " // TODO\n" + " '}'\n" + "\n" + "'}'\n"), + + " // TODO\n" + " '}'\n" + "\n" + "'}'\n", + null), - AnalysePlan( + AnalysePlan( AnalysePlanStorage.getAnalysePlanDirectory(), /** * 0 = package name, @@ -939,10 +1027,9 @@ + " */\n" + " public boolean next(AnalysePlanContext context, SimulationStorage nextSimulation) throws Exception '{'\n" + " return false; // TODO\n" + " '}'\n" - + "\n" + "'}'\n"), + + "\n" + "'}'\n", null), - EquationModel( - FormuleStorage.getFormuleDirectory(), + EquationModel(FormuleStorage.getFormuleDirectory(), /** * 0 = package name, * 1 = class name, @@ -957,22 +1044,37 @@ //" * Last update: $7 $\n" + //" * by : $Author: sletellier $\n" + //" */\n" + - "\n" + "// put your code here\n" + "\n"); + "\n" + "// put your code here\n" + "\n", null), + Sensitivity(SensitivityStorage.getSensitivityDirectory(), null, + SensitivityStorage.SENSIVITY_TEMPLATE); + protected File module; + /** @deprecated content, use #templatePath instead */ protected String defaultContent; + protected String templatePath; - private ScriptMapping(File module, String defaultContent) { + private ScriptMapping(File module, String defaultContent, + String templatePath) { this.module = module; this.defaultContent = defaultContent; + this.templatePath = templatePath; } public File getModule() { return module; } + /** + * @deprecated use #getTemplatePath() instead + * @return + */ public String getDefaultContent() { return defaultContent; } + + public String getTemplatePath() { + return templatePath; + } } } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx 2009-02-25 15:25:59 UTC (rev 1881) @@ -1,6 +1,6 @@ <!-- /* *##% - * Copyright (C) 2005 + * Copyright (C) 2005 - 2009 * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -18,8 +18,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *##%*/ -/* * - * IsisFish.java +/** + * ScriptUI. * * Created: 1 aout 2005 18:37:25 CEST * @@ -67,6 +67,8 @@ f = new File(getContextValue(ScriptAction.class).getRuleDirectory().getPath() + File.separator + selectedValue); } else if (parent.equals("AnalysePlan")) { f = new File(getContextValue(ScriptAction.class).getAnalysePlanDirectory().getPath() + File.separator + selectedValue); + } else if (parent.equals("Sensitivity")) { + f = new File(getContextValue(ScriptAction.class).getSensitivityDirectory().getPath() + File.separator + selectedValue); } else { f = new File(getContextValue(ScriptAction.class).getFormuleDirectory().getPath() + File.separator + parent + File.separator + selectedValue); parent = "EquationModel"; @@ -97,12 +99,14 @@ DefaultMutableTreeNode exportNode = new DefaultMutableTreeNode(new GenericCell("Export", null, null)); DefaultMutableTreeNode ruleNode = new DefaultMutableTreeNode(new GenericCell("Rule", null, null)); DefaultMutableTreeNode analysePlanNode = new DefaultMutableTreeNode(new GenericCell("AnalysePlan", null, null)); + DefaultMutableTreeNode sensitivityNode = new DefaultMutableTreeNode(new GenericCell("Sensitivity", null, null)); DefaultMutableTreeNode equationModelNode = new DefaultMutableTreeNode(new GenericCell("EquationModel", null, null)); setNode(scriptNode, getContextValue(ScriptAction.class).getScriptNames(), "Script"); setNode(simulatorNode, getContextValue(ScriptAction.class).getSimulatorNames(), "Simulator"); setNode(exportNode, getContextValue(ScriptAction.class).getExportNames(), "Export"); setNode(ruleNode, getContextValue(ScriptAction.class).getRuleNames(), "Rule"); setNode(analysePlanNode, getContextValue(ScriptAction.class).getAnalysePlanNames(), "AnalysePlan"); + setNode(sensitivityNode, getContextValue(ScriptAction.class).getSensitivityNames(), "Sensitivity"); setNode(equationModelNode, getContextValue(ScriptAction.class).getCategories(), "EquationModel"); for (Enumeration e = equationModelNode.children(); e.hasMoreElements();){ DefaultMutableTreeNode node = (DefaultMutableTreeNode)e.nextElement(); @@ -114,7 +118,8 @@ treeModel.insertNodeInto(exportNode, rootNode, 2); treeModel.insertNodeInto(ruleNode, rootNode, 3); treeModel.insertNodeInto(analysePlanNode, rootNode, 4); - treeModel.insertNodeInto(equationModelNode, rootNode, 5); + treeModel.insertNodeInto(sensitivityNode, rootNode, 5); + treeModel.insertNodeInto(equationModelNode, rootNode, 6); return treeModel; } protected void setNode(DefaultMutableTreeNode node, java.util.List<String> values, String type) { @@ -271,6 +276,7 @@ <JMenuItem id="miNewExport" text="isisfish.script.menu.txtNewExport" onActionPerformed='newScript("Export")' accelerator="accNewExport"/> <JMenuItem id="miNewRule" text="isisfish.script.menu.txtNewRule" onActionPerformed='newScript("Rule")' accelerator="accNewRule"/> <JMenuItem id="miNewAnalysePlan" text="isisfish.script.menu.txtNewAnalysePlan" onActionPerformed='newScript("AnalysePlan")' accelerator="accNewAnalysePlan"/> + <JMenuItem id="miNewSensitivity" text="isisfish.script.menu.txtNewSensitivity" onActionPerformed='newScript("Sensitivity")' accelerator="accNewSensitivity"/> <JMenuItem id="miNewEquationModel" text="isisfish.script.menu.txtNewEquationModel" onActionPerformed='newScript("EquationModel")' accelerator="accNewEquationModel"/> </JMenu> <JMenuItem id="miSave" text="isisfish.script.menu.save" onActionPerformed="saveScript()" accelerator="accSave"/> Copied: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/ClasspathTemplateLoader.java (from rev 1857, isis-fish/trunk/src/main/java/fr/ifremer/isisfish/simulator/launcher/ssh/ClasspathTemplateLoader.java) =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/ClasspathTemplateLoader.java (rev 0) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/ClasspathTemplateLoader.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -0,0 +1,68 @@ +/* *##% + * Copyright (C) 2008, 2009 Code Lutin + * + * 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.util; + +import java.net.URL; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.util.Resource; +import org.codelutin.util.ResourceNotFoundException; + +import freemarker.cache.URLTemplateLoader; + +/** + * Freemarker custom template loader. + * Load template from classpath jars. + * + * @author chatellier + * @version $Revision: 1.0 $ + * + * Last update : $Date: 1 déc. 2008 $ + * By : $Author: chatellier $ + */ +public class ClasspathTemplateLoader extends URLTemplateLoader { + + /** log */ + private static Log log = LogFactory.getLog(ClasspathTemplateLoader.class); + + /* + * @see freemarker.cache.URLTemplateLoader#getURL(java.lang.String) + */ + @Override + protected URL getURL(String name) { + + if (log.isDebugEnabled()) { + log.debug("Loading url template " + name); + } + + URL url = null; + + try { + url = Resource.getURL(name); + } catch (ResourceNotFoundException e) { + // not big deal + // freemarker ask for name_fr_FR, name_fr, name + url = null; + } + + return url; + } + +} Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/CompileHelper.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -1,5 +1,5 @@ /* *##% - * Copyright (C) 2006 + * Copyright (C) 2006 - 2009 * Code Lutin, Cédric Pineau, Benjamin Poussin * * This program is free software; you can redistribute it and/or @@ -202,7 +202,7 @@ // Options de compilations String classpathAsString = getClassPathAsString(classpath); - ArrayList<String> args = new ArrayList<String>(); + List<String> args = new ArrayList<String>(); args.add("-g"); args.add("-classpath"); args.add(classpathAsString); @@ -240,6 +240,14 @@ } } } + + // FIXME just for test to run in maven + // In this case, current project in not packaged ad jar + // and no META-INF/MANIFEST.MF could be found... + File targetClassesFile = new File("target","classes"); + if (targetClassesFile.isDirectory()) { + result += File.pathSeparator + targetClassesFile.getAbsolutePath(); + } if(log.isDebugEnabled()) { log.debug("CLASSPATH : " + result); 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-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/resources/i18n/isis-fish-en_GB.properties 2009-02-25 15:25:59 UTC (rev 1881) @@ -8,6 +8,7 @@ Can't\ delete\ simulation\ %s\ = Can't\ do\ post\ action\ %s= Can't\ do\ simulation\ %s= +Can't\ evaluate\ simulation\ prescript= Can't\ export\ simulation\ %s= Can't\ get\ changlog= Can't\ get\ result\:\ %1$s=Can't get result\: %1$s @@ -22,11 +23,11 @@ Could\ not\ found\ formule\ type\ %s\ autorised\ type\ are\ %s= Error\ during\ vcs\ initialisation= Error\ while\ uploading\ public\ key\ to\ remote\ serveur\ authorized_keys= +Factors\ analyse\ plan= Generate\ next\ simulation= Import\ one\ java\ file\ script\ source= Import\ simulation\ file\ %s\ in\ directory\ %s\ and\ rename\ from\ %s\ to\ %s= Import\ zipped\ file\ containing\ all\ scripts\ directory\ structure= -Indiquez\ vos\ modifications= Info=Info Jobs\ submited\ is\ not\ ItemSimulation\ but\ was\ %s= Last\ entry\ was\ %s\ extract\ name\ %s= @@ -319,6 +320,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.parameter= isisfish.error.simulation.log.openAppender=could not open appender of simulation %1$s for reason %2$s isisfish.error.simulation.remote.global=Can't launch a simulation on remote server isisfish.error.simulation.remote.wrongportvalue=Connection port value is incorrect \: %s @@ -566,6 +568,7 @@ isisfish.message.result.verif.region=R\u00E9sultat de la v\u00E9rification de la r\u00E9gion isisfish.message.save.finished=Save finished isisfish.message.saveModel.finished=Save model finished +isisfish.message.script.commit=Enter commit message isisfish.message.setting.cache.aspects=Setting Cache aspects isisfish.message.setting.trace.aspects=Setting Trace aspects isisfish.message.simulation.ended=Simulation ended @@ -808,6 +811,7 @@ isisfish.script.menu.txtNewExport=New Export isisfish.script.menu.txtNewRule=New rule isisfish.script.menu.txtNewScript=New script +isisfish.script.menu.txtNewSensitivity=New sensitivity calculator isisfish.script.menu.txtNewSimulator=New simulator isisfish.script.menu.txtVCS=Server isisfish.script.menu.update=Update from server 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-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/resources/i18n/isis-fish-fr_FR.properties 2009-02-25 15:25:59 UTC (rev 1881) @@ -8,6 +8,7 @@ Can't\ delete\ simulation\ %s\ = Can't\ do\ post\ action\ %s= Can't\ do\ simulation\ %s= +Can't\ evaluate\ simulation\ prescript= Can't\ export\ simulation\ %s= Can't\ get\ changlog=Impossible d'obtenir de changelog Can't\ get\ result\:\ %1$s=Can't get result\: %1$s @@ -22,11 +23,11 @@ Could\ not\ found\ formule\ type\ %s\ autorised\ type\ are\ %s= Error\ during\ vcs\ initialisation= Error\ while\ uploading\ public\ key\ to\ remote\ serveur\ authorized_keys= +Factors\ analyse\ plan= Generate\ next\ simulation= Import\ one\ java\ file\ script\ source= Import\ simulation\ file\ %s\ in\ directory\ %s\ and\ rename\ from\ %s\ to\ %s= Import\ zipped\ file\ containing\ all\ scripts\ directory\ structure= -Indiquez\ vos\ modifications= Info=Info Jobs\ submited\ is\ not\ ItemSimulation\ but\ was\ %s= Last\ entry\ was\ %s\ extract\ name\ %s= @@ -319,6 +320,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.parameter= isisfish.error.simulation.log.openAppender=n'a pas pu ouvrir l'appender de la simulation %1$s pour la raison %2$s isisfish.error.simulation.remote.global=Impossible de lancer une simulation sur serveur distant isisfish.error.simulation.remote.wrongportvalue=Le port de connexion a une valeur incorrecte \: %s @@ -566,6 +568,7 @@ isisfish.message.result.verif.region=R\u00E9sultat de la v\u00E9rification de la r\u00E9gion isisfish.message.save.finished=Sauvegarde termin\u00E9e isisfish.message.saveModel.finished=Sauvegarde du mod\u00E8le termin\u00E9e +isisfish.message.script.commit=Indiquez vos modifications isisfish.message.setting.cache.aspects=Mise en place des aspects Cache isisfish.message.setting.trace.aspects=Mise en place des aspects Trace isisfish.message.simulation.ended=Simulation termin\u00E9e @@ -807,8 +810,9 @@ isisfish.script.menu.txtNewEquationModel=Nouvelle formule isisfish.script.menu.txtNewExport=Nouveau script d'export isisfish.script.menu.txtNewRule=Nouvelle r\u00E8gle -isisfish.script.menu.txtNewScript=Nouveau Script -isisfish.script.menu.txtNewSimulator=Nouveau Simulateur +isisfish.script.menu.txtNewScript=Nouveau script +isisfish.script.menu.txtNewSensitivity=Nouveau calculateur de sensibilit\u00E9 +isisfish.script.menu.txtNewSimulator=Nouveau simulateur isisfish.script.menu.txtVCS=Serveur isisfish.script.menu.update=Synchronisation isisfish.script.new=Nouveau Modified: isis-fish/trunk/src/main/resources/templates/analyseplan.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/analyseplan.ftl 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/resources/templates/analyseplan.ftl 2009-02-25 15:25:59 UTC (rev 1881) @@ -26,11 +26,11 @@ /** * ${name}.java * - * Created: ${date} + * Created: ${date?date?string.long} * * @author ${author} <${email}> * @version $Revision: 1545 $ - * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $ + * Last update: $Date: ${date?date?string.long} $ * by : $Author: ${author} $ */ public class ${name} implements AnalysePlan { @@ -54,8 +54,8 @@ * @return L''aide ou la description du plan */ public String getDescription() throws Exception { - // TODO - return _("TODO description plan"); + // TODO change descrition + return _("TODO ${name} description plan"); } /** Modified: isis-fish/trunk/src/main/resources/templates/equation.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/equation.ftl 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/resources/templates/equation.ftl 2009-02-25 15:25:59 UTC (rev 1881) @@ -1,11 +1,11 @@ /** * ${name}. * - * Created: ${date} + * Created: ${date?date?string.long} * * @author ${author} <${email}> * @version $Revision: 1545 $ - * Last update: $Date : ${date} $ + * Last update: $Date : ${date?date?string.long} $ * by : $Author: ${author} $ */ // put your code here Modified: isis-fish/trunk/src/main/resources/templates/export.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/export.ftl 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/resources/templates/export.ftl 2009-02-25 15:25:59 UTC (rev 1881) @@ -16,12 +16,12 @@ /** * ${name}.java * - * Created: ${date} + * Created: ${date?date?string.long} * * @author ${author} <${email}> * @version $Revision: 1545 $ * - * Last update: $Date: ${date} $ + * Last update: $Date: ${date?date?string.long} $ * by : $Author: ${author} $ */ public class ${name} implements Export { Added: isis-fish/trunk/src/main/resources/templates/prescript/factorprescript.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/prescript/factorprescript.ftl (rev 0) +++ isis-fish/trunk/src/main/resources/templates/prescript/factorprescript.ftl 2009-02-25 15:25:59 UTC (rev 1881) @@ -0,0 +1,18 @@ +// inject factors into simulation + +//SimulationStorage simulation = context.getSimulationStorage(); +//SimulationParameter parameters = simulation.getParameter(); +//String presimulationScript = parameters.getPreScript(); + +import org.apache.commons.beanutils.BeanUtils; + +<#list scenario.factors as factor> +// Factor : ${factor.name} +<#assign value=factor.value /> +<#assign path=factor.path /> +<#assign topiaId=path?substring(0, path?last_index_of("#"))/> +<#assign propertyName=path?substring(path?last_index_of("#") + 1)/> +TopiaEntity entity = db.findByTopiaId("${topiaId}"); +BeanUtils.setProperty(entity, "${propertyName}", "${value}"); + +</#list> \ No newline at end of file Modified: isis-fish/trunk/src/main/resources/templates/rule.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/rule.ftl 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/resources/templates/rule.ftl 2009-02-25 15:25:59 UTC (rev 1881) @@ -22,11 +22,11 @@ /** * ${name}.java * - * Created: ${date} + * Created: ${date?date?string.long} * * @author ${author} <${email}> * @version $Revision: 1545 $ - * Last update: $Date: 2008-10-08 16:13:44 +0200 (mer 08 oct 2008) $ + * Last update: $Date: ${date?date?string.long} $ * by : $Author: ${author} $ */ public class ${name} extends AbstractRule { Modified: isis-fish/trunk/src/main/resources/templates/script.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/script.ftl 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/resources/templates/script.ftl 2009-02-25 15:25:59 UTC (rev 1881) @@ -10,12 +10,12 @@ /** * ${name}.java * - * Created: ${date} + * Created: ${date?date?string.long} * * @author ${author} <$email}> * @version $Revision: 0 $ * - * Last update: $Date: ${date} $ + * Last update: $Date: ${date?date?string.long} $ * by : $Author: ${author} $ */ public class ${name} { Added: isis-fish/trunk/src/main/resources/templates/sensitivity.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/sensitivity.ftl (rev 0) +++ isis-fish/trunk/src/main/resources/templates/sensitivity.ftl 2009-02-25 15:25:59 UTC (rev 1881) @@ -0,0 +1,75 @@ +package sensitivity; + +import static org.codelutin.i18n.I18n._; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.codelutin.math.matrix.*; + +import fr.ifremer.isisfish.util.Doc; +import fr.ifremer.isisfish.entities.*; +import fr.ifremer.isisfish.simulator.factors.*; + +/** + * ${name}.java + * + * Created: ${date?date?string.long} + * + * @author ${author} <${email}> + * @version $Revision: 0 $ + * + * Last update: $Date: ${date?date?string.long} $ + * by : $Author: ${author} $ + */ +public class ${name} implements SensitivityCalculator { + + /** to use log facility, just put in your code: log.info("..."); */ + private static Log log = LogFactory.getLog(${name}.class); + + /** + * Return calculator description. + * + * @return calculator description + * @throws Exception + */ + public String getDescription() throws Exception { + // TODO change descrition + return _("TODO ${name} description plan"); + } + + /** + * Envoi un plan a faire analyser par l'outils + * d'analyse de sensibilité. + * + * Retourne un {@link SensitivityScenarios} qui + * représente l'ensemble des scenarios à prendre + * en compte pour les simulations. + * + * @param plan plan a analyser + * + * @return un {@link SensitivityScenarios} + * + * @see DesignPlan + * @see Scenario + * @see SensitivityScenarios + */ + public SensitivityScenarios compute(DesignPlan plan) { + + SensitivityScenarios sensitivityScenarios = new SensitivityScenarios(); + + // FIXME add implemantation + + return null; + } + + /** + * Permet de renvoyer les resultats de simulations + * à l'outils de d'analyse de sensibilité. + * + * @param sensitivityScenarios résultats de scenarios + */ + public void analyzeResult(SensitivityScenarios sensitivityScenarios) { + + } +} \ No newline at end of file Modified: isis-fish/trunk/src/main/resources/templates/simulator.ftl =================================================================== --- isis-fish/trunk/src/main/resources/templates/simulator.ftl 2009-02-25 14:59:16 UTC (rev 1880) +++ isis-fish/trunk/src/main/resources/templates/simulator.ftl 2009-02-25 15:25:59 UTC (rev 1881) @@ -13,13 +13,13 @@ /** * ${name}.java * - * Created: ${date} + * Created: ${date?date?string.long} * * @author ${author} <${email}> * @version $Revision: 1545 $ * - * Last update $Date ${date} $ - * by : $Author: sletellier $ + * Last update $Date ${date?date?string.long} $ + * by : $Author: ${author} $ */ public class ${name} implements Simulator { Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SensitivityStorageTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SensitivityStorageTest.java (rev 0) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/datastore/SensitivityStorageTest.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -0,0 +1,108 @@ +/* *##% + * Copyright (C) 2006 - 2009 + * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * + * 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.datastore; + +import java.io.StringWriter; +import java.io.Writer; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.IsisFish; +import fr.ifremer.isisfish.util.ClasspathTemplateLoader; +import fr.ifremer.isisfish.util.CompileHelper; +import freemarker.cache.TemplateLoader; +import freemarker.template.Configuration; +import freemarker.template.Template; + +/** + * SensitivityStorageTest. + * + * Created: 7 août 2006 11:07:57 + * + * @author poussin + * @version $Revision: 1526 $ + * + * Last update: $Date: 2008-10-07 18:46:13 +0200 (mar 07 oct 2008) $ + * by : $Author: tchemit $ + */ +public class SensitivityStorageTest { + + protected static Configuration freemarkerConfiguration; + + @BeforeClass + public static void init() throws Exception { + TestUtils.init(); + + freemarkerConfiguration = new Configuration(); + + // needed to overwrite "Defaults to default system encoding." + // fix encoding issue on some systems + freemarkerConfiguration.setDefaultEncoding("utf-8"); + + // specific template loader to get template from jars (classpath) + TemplateLoader templateLoader = new ClasspathTemplateLoader(); + freemarkerConfiguration.setTemplateLoader(templateLoader); + + //freemarkerConfiguration.setObjectWrapper(new BeansWrapper()); + } + + /* + * Test method for 'fr.ifremer.isisfish.datastore.ScriptStorage.getScript(String)' + */ + @Test + public void testNewScriptWithCompilation() throws Exception { + + String fileName = "TestSensitivity1"; + + SensitivityStorage sensitivityStorage = SensitivityStorage + .getSensitivity(fileName); + + // get template + Template template = freemarkerConfiguration + .getTemplate(SensitivityStorage.SENSIVITY_TEMPLATE); + + // context values + Map<String, Object> root = new HashMap<String, Object>(); + // FIXME what is category ? + root.put("category", ""); + root.put("name", fileName); + root.put("date", new Date()); + root.put("author", IsisFish.config.getUserName()); + root.put("email", IsisFish.config.getUserMail()); + + // process template + Writer out = new StringWriter(); + template.process(root, out); + out.flush(); + sensitivityStorage.setContent(out.toString()); + + // 0 = compile success + // FIXME don't work in maven + int compileResult = sensitivityStorage.compile(false, null); + Assert.assertEquals(0, compileResult); + } + +} Added: isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java =================================================================== --- isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java (rev 0) +++ isis-fish/trunk/src/test/java/fr/ifremer/isisfish/simulator/SimulationPreScriptTest.java 2009-02-25 15:25:59 UTC (rev 1881) @@ -0,0 +1,273 @@ +/* *##% + * Copyright (C) 2009 Code Lutin + * + * 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.simulator; + +import java.io.IOException; +import java.io.Serializable; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.math.matrix.MatrixFactory; +import org.codelutin.math.matrix.MatrixND; +import org.codelutin.topia.TopiaContext; +import org.codelutin.topia.TopiaException; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +import fr.ifremer.TestUtils; +import fr.ifremer.isisfish.IsisFishDAOHelper; +import fr.ifremer.isisfish.datastore.SimulationStorage; +import fr.ifremer.isisfish.datastore.StorageException; +import fr.ifremer.isisfish.entities.PopulationSeasonInfo; +import fr.ifremer.isisfish.entities.PopulationSeasonInfoDAO; +import fr.ifremer.isisfish.entities.VesselType; +import fr.ifremer.isisfish.entities.VesselTypeDAO; +import fr.ifremer.isisfish.simulator.factors.ContinuousDomain; +import fr.ifremer.isisfish.simulator.factors.DiscreteDomain; +import fr.ifremer.isisfish.simulator.factors.Factor; +import fr.ifremer.isisfish.simulator.factors.Scenario; +import fr.ifremer.isisfish.util.ClasspathTemplateLoader; +import freemarker.cache.TemplateLoader; +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; + +/** + * Test for simulation prescript. + * + * Creer un populationSeasonInfoDAO. + * Affectation de la matrice m1. + * Le prescript doit la changer en m2. + * + * @author chatellier + * @version $Revision: 1.0 $ + * + * Last update : $Date: 24 févr. 2009 $ + * By : $Author: chatellier $ + */ + at Ignore +public class SimulationPreScriptTest { + + private static final Log log = LogFactory.getLog(SimulationPreScriptTest.class); + + //protected TopiaContext rootContext; + + protected static Template template; + + @BeforeClass + public static void init() throws Exception { + TestUtils.init(); + + Configuration freemarkerConfiguration = new Configuration(); + + // needed to overwrite "Defaults to default system encoding." + // fix encoding issue on some systems + freemarkerConfiguration.setDefaultEncoding("utf-8"); + + // specific template loader to get template from jars (classpath) + TemplateLoader templateLoader = new ClasspathTemplateLoader(); + freemarkerConfiguration.setTemplateLoader(templateLoader); + + // get template + template = freemarkerConfiguration + .getTemplate("templates/prescript/factorprescript.ftl"); + } + + @Before + public void setUp() { + System.setProperty("hibernate.hbm2ddl.auto", "create"); + } + + @After + public void tearDown() { + System.setProperty("hibernate.hbm2ddl.auto", ""); + } + + /** + * Creer un simulation. + * + * @throws IOException + * @throws TemplateException + * @throws StorageException + * @throws TopiaException + */ + @Test + public void testFactorPreScriptFactorInt() throws IOException, TemplateException, StorageException, TopiaException { + + String topiaId = null; + + // init simulation + SimulationContext context = SimulationContext.get(); + SimulationParameter params = new SimulationParameter(); + SimulationStorage simulation = SimulationStorage.create("test_1_int", params); + TopiaContext storageContext = simulation.getStorage(); + TopiaContext childStorageContext = storageContext.beginTransaction(); + VesselTypeDAO vesselTypeDAO = IsisFishDAOHelper.getVesselTypeDAO(childStorageContext); + VesselType vesselType = vesselTypeDAO.create(); + vesselType.setLength(4); + vesselType.update(); + topiaId = vesselType.getTopiaId(); + childStorageContext.commitTransaction(); + + // factor + Factor<Integer> factor = new Factor<Integer>("testint"); + ContinuousDomain<Integer> domain = new ContinuousDomain<Integer>(); + domain.setMinBound(0); + domain.setMaxBound(50); + factor.setDomain(domain); + factor.setPath(topiaId + "#length"); + factor.setValueForIdentifier(49); + + // scenario + Scenario scenario = new Scenario(); + List<Factor<? extends Serializable>> factors = new ArrayList<Factor<? extends Serializable>>(); + factors.add(factor); + scenario.setFactors(factors); + + // context values + Map<String, Object> root = new HashMap<String, Object>(); + root.put("scenario", scenario); + + // process template + Writer out = new StringWriter(); + template.process(root, out); + out.flush(); + String scriptContent = out.toString(); + log.info("Script = " + scriptContent); + + // + SimulationPreScript simulationPreScript = new SimulationPreScript(); + params.setUsePreScript(true); + params.setPreScript(scriptContent); + + context.setSimulationStorage(simulation); + simulationPreScript.beforeSimulation(context); + + // try to find previous entity + vesselType = vesselTypeDAO.findByTopiaId(topiaId); + Assert.assertEquals(49, vesselType.getLength()); + } + + /** + * Creer un simulation. + * Creer un populationSeasonInfoDAO. + * Affectation de la matrice m1. + * Le prescript doit la changer en m2. + * + * @throws IOException + * @throws TemplateException + * @throws StorageException + * @throws TopiaException + */ + @Test + public void testFactorPreScriptFactorMatrix() throws IOException, TemplateException, StorageException, TopiaException { + + // matrix 1 + MatrixND matrix1 = MatrixFactory.getInstance().create("test1", + new int[] { 3, 2 }, new String[] { "col1", "col2" }); + matrix1.setValue(new int[] { 0, 0 }, 13); + matrix1.setValue(new int[] { 0, 1 }, -14); + matrix1.setValue(new int[] { 1, 0 }, 21); + matrix1.setValue(new int[] { 1, 1 }, 2); + matrix1.setValue(new int[] { 2, 0 }, 12); + matrix1.setValue(new int[] { 2, 1 }, -1); + + // matrix 2 + MatrixND matrix2 = MatrixFactory.getInstance().create("test2", + new int[] { 2, 3 }, new String[] { "col1", "col2" }); + matrix2.setValue(new int[] { 0, 0 }, 9999); + matrix2.setValue(new int[] { 0, 1 }, 15000); + matrix2.setValue(new int[] { 0, 2 }, -40000); + matrix2.setValue(new int[] { 1, 0 }, 21345); + matrix2.setValue(new int[] { 1, 1 }, 81000); + matrix2.setValue(new int[] { 1, 2 }, -13000); + + String topiaId = null; + + // init simulation + SimulationContext context = SimulationContext.get(); + SimulationParameter params = new SimulationParameter(); + SimulationStorage simulation = SimulationStorage.create("test_2_matrix", params); + TopiaContext storageContext = simulation.getStorage(); + TopiaContext childStorageContext = storageContext.beginTransaction(); + PopulationSeasonInfoDAO populationSeasonInfoDAO = IsisFishDAOHelper.getPopulationSeasonInfoDAO(childStorageContext); + PopulationSeasonInfo populationSeasonInfo = populationSeasonInfoDAO.create(); + populationSeasonInfo.setMigrationMatrix(matrix1); + populationSeasonInfo.update(); + topiaId = populationSeasonInfo.getTopiaId(); + childStorageContext.commitTransaction(); + childStorageContext.closeContext(); + + // factor + Factor<MatrixND> factor1 = new Factor<MatrixND>("testmatrix"); + DiscreteDomain<MatrixND> domain1 = new DiscreteDomain<MatrixND>(); + domain1.getValues().put("m1", matrix1); + factor1.setDomain(domain1); + factor1.setPath("org.codelutin.math.matrix.MatrixND#563456293453#2.456347646#dim"); + factor1.setValueForIdentifier("m1"); + + // factor + Factor<MatrixND> factor2 = new Factor<MatrixND>("testmatrix"); + DiscreteDomain<MatrixND> domain2 = new DiscreteDomain<MatrixND>(); + domain2.getValues().put("m2", matrix1); + factor2.setDomain(domain2); + factor2.setPath("org.codelutin.math.matrix.MatrixND#563456293453#2.456347646#dim"); + factor2.setValueForIdentifier("m2"); + + // scenario + Scenario scenario = new Scenario(); + List<Factor<? extends Serializable>> factors = new ArrayList<Factor<? extends Serializable>>(); + factors.add(factor1); + factors.add(factor2); + scenario.setFactors(factors); + + // context values + Map<String, Object> root = new HashMap<String, Object>(); + root.put("scenario", scenario); + + // process template + Writer out = new StringWriter(); + template.process(root, out); + out.flush(); + String scriptContent = out.toString(); + log.info("Script = " + scriptContent); + + // + SimulationPreScript simulationPreScript = new SimulationPreScript(); + params.setUsePreScript(true); + params.setPreScript(scriptContent); + + context.setSimulationStorage(simulation); + simulationPreScript.beforeSimulation(context); + + // try to find previous entity + populationSeasonInfo = populationSeasonInfoDAO.findByTopiaId(topiaId); + Assert.assertEquals(matrix2, populationSeasonInfo.getMigrationMatrix()); + } +}
participants (1)
-
chatellier@users.labs.libre-entreprise.org