Coser-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- 1258 discussions
r1025 - in trunk: . coser-business/src/main/java/fr/ifremer/coser/control coser-business/src/main/java/fr/ifremer/coser/services coser-ui/src/main/java/fr/ifremer/coser/ui/control coser-ui/src/main/resources/i18n
by echatellier@users.forge.codelutin.com 19 Jul '12
by echatellier@users.forge.codelutin.com 19 Jul '12
19 Jul '12
Author: echatellier
Date: 2012-07-19 11:36:52 +0200 (Thu, 19 Jul 2012)
New Revision: 1025
Url: http://forge.codelutin.com/repositories/revision/coser/1025
Log:
fixes #1320: Regrouper les warning capture/taille par esp?\195?\168ce
Added:
trunk/coser-business/src/main/java/fr/ifremer/coser/control/SpeciesControlError.java
Modified:
trunk/coser-business/src/main/java/fr/ifremer/coser/control/DiffCatchLengthControlError.java
trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java
trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlErrorTreeRenderer.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalControlErrorModel.java
trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties
trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties
trunk/pom.xml
Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/control/DiffCatchLengthControlError.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/control/DiffCatchLengthControlError.java 2012-07-18 10:24:01 UTC (rev 1024)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/control/DiffCatchLengthControlError.java 2012-07-19 09:36:52 UTC (rev 1025)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric
+ * Copyright (C) 2010 - 2012 Ifremer, Codelutin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -36,27 +36,9 @@
* Last update : $Date$
* By : $Author$
*/
-public class DiffCatchLengthControlError extends ControlError implements Comparable<DiffCatchLengthControlError> {
+public class DiffCatchLengthControlError extends SpeciesControlError {
- /** serialVersionUID. */
- private static final long serialVersionUID = -3254763296138201677L;
+ /** serialVersionUID */
+ private static final long serialVersionUID = 6646855823928956144L;
- protected String species;
-
- public String getSpecies() {
- return species;
- }
-
- public void setSpecies(String species) {
- this.species = species;
- }
-
- @Override
- public int compareTo(DiffCatchLengthControlError o) {
- int result = -1;
- if (species != null) {
- result = species.compareTo(o.species);
- }
- return result;
- }
}
Added: trunk/coser-business/src/main/java/fr/ifremer/coser/control/SpeciesControlError.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/control/SpeciesControlError.java (rev 0)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/control/SpeciesControlError.java 2012-07-19 09:36:52 UTC (rev 1025)
@@ -0,0 +1,63 @@
+/*
+ * #%L
+ *
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2012 Ifremer, Codelutin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.coser.control;
+
+/**
+ * Erreur de controle specifique pour les différences des nombres entre
+ * les captures et les tailles pour utilisation typée de cette erreur
+ * (export html) et information supplémentaires (especes).
+ *
+ * @author chatellier
+ * @version $Revision$
+ * @since 1.3
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class SpeciesControlError extends ControlError implements Comparable<SpeciesControlError> {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = -3254763296138201677L;
+
+ protected String species;
+
+ public String getSpecies() {
+ return species;
+ }
+
+ public void setSpecies(String species) {
+ this.species = species;
+ }
+
+ @Override
+ public int compareTo(SpeciesControlError o) {
+ int result = -1;
+ if (species != null) {
+ result = species.compareTo(o.species);
+ }
+ return result;
+ }
+}
Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/control/SpeciesControlError.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java 2012-07-18 10:24:01 UTC (rev 1024)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java 2012-07-19 09:36:52 UTC (rev 1025)
@@ -66,6 +66,7 @@
import fr.ifremer.coser.bean.Project;
import fr.ifremer.coser.control.ControlError;
import fr.ifremer.coser.control.DiffCatchLengthControlError;
+import fr.ifremer.coser.control.SpeciesControlError;
import fr.ifremer.coser.data.AbstractDataEntity;
import fr.ifremer.coser.data.Catch;
import fr.ifremer.coser.data.Haul;
@@ -212,7 +213,7 @@
// valide chaque category
List<ControlError> validationErrors = new ArrayList<ControlError>();
- for (Category category : Category.values()) {
+ /*for (Category category : Category.values()) {
if (category.isDataCategory()) {
// validation de la category seule (generique)
List<ControlError> categoryErrors = validateCategoryXWork(control, category, progress);
@@ -228,7 +229,7 @@
}
progress.nextStep();
}
- }
+ }*/
// validation entre catch et length (specific)
List<? extends ControlError> diffCatchLengthErrors = validateDiffCatchLength(control, progress);
@@ -593,7 +594,7 @@
progress.setTotal(total);
}
- List<DiffCatchLengthControlError> validationErrors = new ArrayList<DiffCatchLengthControlError>();
+ List<SpeciesControlError> validationErrors = new ArrayList<SpeciesControlError>();
// data necessary for compute
SortedSet<String> setYear = new TreeSet<String>();
@@ -715,15 +716,14 @@
// warning si taille = 0 et captures différent de 0
// nomespece, année(s) avec absence de taille
if (lengthNumber == 0 && catchNumber > 0 && !missingYearLengthSpecies.contains(species)) {
- DiffCatchLengthControlError error = new DiffCatchLengthControlError();
+ SpeciesControlError error = new SpeciesControlError();
error.setSpecies(species);
error.setLevel(ValidationLevel.WARNING);
error.setMessage(_("coser.business.control.error.diffCatchLengthMissingYear"));
error.setDetailMessage(_("coser.business.control.error.diffCatchLengthMissingYearDetail", species));
validationErrors.add(error);
missingYearLengthSpecies.add(species);
- }
- else {
+ } else {
// diff entre 4 et 5 = (5-4) * 100 / 5
double min = Math.min(catchNumber, lengthNumber);
// si c'est 0, ou absence de catures, ce n'est pas une erreur
@@ -1216,7 +1216,7 @@
// especes de tailles doivent etre dans especes de captures (fatal)
Collection<String> missingCatchSpeciesNames = CollectionUtils.subtract(lengthSpeciesNames, catchSpeciesNames);
for (String missingCatchSpeciesName : missingCatchSpeciesNames) {
- DiffCatchLengthControlError error = new DiffCatchLengthControlError();
+ SpeciesControlError error = new SpeciesControlError();
error.setLevel(ValidationLevel.FATAL);
error.setSpecies(missingCatchSpeciesName);
error.setMessage(_("coser.business.control.error.missingCatchSpeciesFromLength"));
@@ -1230,7 +1230,7 @@
// especes de captures doivent etre dans especes de tailles (warning)
Collection<String> missingLengthSpeciesNames = CollectionUtils.subtract(catchSpeciesNames, lengthSpeciesNames);
for (String missingLengthSpeciesName : missingLengthSpeciesNames) {
- DiffCatchLengthControlError error = new DiffCatchLengthControlError();
+ SpeciesControlError error = new SpeciesControlError();
error.setLevel(ValidationLevel.WARNING);
error.setSpecies(missingLengthSpeciesName);
error.setMessage(_("coser.business.control.error.missingLengthSpeciesFromCatch"));
Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java 2012-07-18 10:24:01 UTC (rev 1024)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java 2012-07-19 09:36:52 UTC (rev 1025)
@@ -92,11 +92,11 @@
import fr.ifremer.coser.control.ControlError;
import fr.ifremer.coser.control.ControlErrorGroup;
import fr.ifremer.coser.control.DiffCatchLengthControlError;
+import fr.ifremer.coser.control.SpeciesControlError;
import fr.ifremer.coser.data.Catch;
import fr.ifremer.coser.data.Length;
import fr.ifremer.coser.storage.DataStorage;
import fr.ifremer.coser.storage.MemoryDataStorage;
-import freemarker.template.TemplateException;
/**
* Publication service (charts, reports, export, pdf...)
@@ -347,8 +347,8 @@
errorGroup.add(group);
}
- if (validationError instanceof DiffCatchLengthControlError) {
- DiffCatchLengthControlError diffError = (DiffCatchLengthControlError)validationError;
+ if (validationError instanceof SpeciesControlError) {
+ SpeciesControlError diffError = (SpeciesControlError)validationError;
speciesGraph.add(diffError.getSpecies());
}
childErrors.add(validationError);
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlErrorTreeRenderer.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlErrorTreeRenderer.java 2012-07-18 10:24:01 UTC (rev 1024)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlErrorTreeRenderer.java 2012-07-19 09:36:52 UTC (rev 1025)
@@ -33,10 +33,13 @@
import javax.swing.tree.DefaultTreeCellRenderer;
import jaxx.runtime.validator.swing.SwingValidatorUtil;
+
+import org.jdesktop.swingx.treetable.TreeTableNode;
+
import fr.ifremer.coser.CoserConstants.Category;
import fr.ifremer.coser.CoserConstants.ValidationLevel;
+import fr.ifremer.coser.control.ControlError;
import fr.ifremer.coser.control.ControlErrorGroup;
-import fr.ifremer.coser.control.ControlError;
/**
* Renderer pour le table des erreurs globales.
@@ -73,18 +76,19 @@
GlobalControlErrorModel model = (GlobalControlErrorModel)tree.getModel();
JLabel component = (JLabel)super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
+ Object userObject = ((TreeTableNode)value).getUserObject();
ImageIcon icon = null;
String text = null;
String tooltipText = null;
- if (value instanceof String) {
- text = _((String)value) + " (" + model.getChildCount(value) + ")";
+ if (userObject instanceof String) {
+ text = _((String)userObject) + " (" + model.getChildCount(value) + ")";
}
- else if (value instanceof Category) {
- text = _(((Category)value).getTranslationKey()) + " (" + model.getChildCount(value) + ")";
+ else if (userObject instanceof Category) {
+ text = _(((Category)userObject).getTranslationKey()) + " (" + model.getChildCount(value) + ")";
}
- else if (value instanceof ControlErrorGroup) {
- ControlErrorGroup validationErrorGroup = (ControlErrorGroup)value;
+ else if (userObject instanceof ControlErrorGroup) {
+ ControlErrorGroup validationErrorGroup = (ControlErrorGroup)userObject;
ValidationLevel level = validationErrorGroup.getValidationLevel();
switch (level) {
case FATAL:
@@ -104,8 +108,8 @@
String message = validationErrorGroup.getMessage();
text = _(message) + " (" + model.getChildCount(value) + ")";
}
- else if (value instanceof ControlError) {
- ControlError validationError = (ControlError)value;
+ else if (userObject instanceof ControlError) {
+ ControlError validationError = (ControlError)userObject;
ValidationLevel level = validationError.getLevel();
switch (level) {
case FATAL:
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2012-07-18 10:24:01 UTC (rev 1024)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2012-07-19 09:36:52 UTC (rev 1025)
@@ -24,6 +24,7 @@
package fr.ifremer.coser.ui.control;
import static org.nuiton.i18n.I18n._;
+import static org.nuiton.i18n.I18n.n_;
import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
@@ -36,6 +37,7 @@
import java.beans.Introspector;
import java.io.File;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -67,6 +69,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdesktop.swingx.JXTreeTable;
+import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
+import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
+import org.jdesktop.swingx.treetable.TreeTableNode;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.nuiton.widget.SwingSession;
@@ -81,6 +86,7 @@
import fr.ifremer.coser.control.ControlError;
import fr.ifremer.coser.control.ControlErrorGroup;
import fr.ifremer.coser.control.DiffCatchLengthControlError;
+import fr.ifremer.coser.control.SpeciesControlError;
import fr.ifremer.coser.data.AbstractDataEntity;
import fr.ifremer.coser.data.Catch;
import fr.ifremer.coser.data.Haul;
@@ -452,10 +458,12 @@
throw new CoserException("Can't validate data", ex);
}
}
+
+
};
task.execute();
}
-
+
/**
* Called when selection change to display selected bean
* in edition panel.
@@ -514,18 +522,19 @@
*/
public void showSelectedError(ControlView view, TreeSelectionEvent event) {
TreePath selectedError = view.getGlobalControlErrorTable().getTreeSelectionModel().getSelectionPath();
- if (selectedError != null) {
- Object[] pathWay = selectedError.getPath();
+ if (selectedError != null && selectedError.getPathCount() >= 3) {
+ TreeTableNode cateNode = (TreeTableNode)selectedError.getPathComponent(1);
+ Object cateObject = cateNode.getUserObject();
+ TreeTableNode lastNode = (TreeTableNode)selectedError.getLastPathComponent();
+ Object userObject = lastNode.getUserObject();
- // 2 = validation group (middle level)
- // 3 = validation error (last level)
- if (pathWay.length == 4 && pathWay[1] instanceof Category) {
- Category category = (Category)pathWay[1];
+ if (cateObject instanceof Category && userObject instanceof ControlError) {
+ Category category = (Category)cateObject;
// swap category
view.getCategoryComboBoxModel().setSelectedItem(category);
-
- ControlError error = (ControlError)pathWay[3];
+
+ ControlError error = (ControlError)userObject;
List<String> errorLineNumbers = error.getLineNumbers();
// peut être vide, si l'erreur ne porte pas sur un bean en particulier
if (errorLineNumbers != null) {
@@ -555,11 +564,11 @@
/**
* Affiche le menu contextuel de l'arbre qui contient les erreurs de
* validation globales ou les graphes de comparaison captures/taille
- * dans le cas d'un double clic sur une {@link DiffCatchLengthControlError}.
+ * dans le cas d'un double clic sur une {@link SpeciesControlError}.
*
* @param controlView view
* @param event mouse event
- * @see DiffCatchLengthControlError
+ * @see SpeciesControlError
*/
public void globalErrorTableMouseClicked(final ControlView controlView, MouseEvent event) {
@@ -573,20 +582,22 @@
JPopupMenu popupMenu = new JPopupMenu();
// plusieurs lignes selectionnées et pas la premiere colonne (Line index)
- if (selectedError != null) {
- Object[] pathWay = selectedError.getPath();
+ if (selectedError != null && selectedError.getPathCount() >= 3) {
- // 2 = validation group (middle level)
- if (pathWay.length == 3) {
- if (pathWay[1] instanceof Category) {
- final Category category = (Category)pathWay[1];
- final ControlErrorGroup validationGroup = (ControlErrorGroup)pathWay[2];
-
+ TreeTableNode cateNode = (TreeTableNode)selectedError.getPathComponent(1);
+ Object cateObject = cateNode.getUserObject();
+
+ if (cateObject instanceof Category) { // ca peut être 'tout' en String
+ final Category category = (Category)cateObject;
+ final TreeTableNode lastNode = (TreeTableNode)selectedError.getLastPathComponent();
+
+ // selectall n'a d'interet que pour les groupes d'erreurs
+ if (lastNode.getChildCount() > 0) {
JMenuItem replaceMenu = new JMenuItem(_("coser.ui.control.globalErrorMenuSelectAll"));
replaceMenu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- selectAllErrorGroupLines(controlView, category, validationGroup);
+ selectAllErrorGroupLines(controlView, category, lastNode);
}
});
popupMenu.add(replaceMenu);
@@ -617,10 +628,10 @@
// si la selection est une instance de DiffCatchLengthControlError
// affiche le graphe avec l'espece correspondante
if (selectedError != null) {
- Object[] pathWay = selectedError.getPath();
- Object lastComponent = pathWay[pathWay.length - 1];
- if (lastComponent instanceof DiffCatchLengthControlError) {
- DiffCatchLengthControlError error = (DiffCatchLengthControlError)lastComponent;
+ TreeTableNode lastComponent = (TreeTableNode)selectedError.getLastPathComponent();
+ Object userObject = lastComponent.getUserObject();
+ if (userObject instanceof SpeciesControlError) {
+ SpeciesControlError error = (SpeciesControlError)userObject;
String species = error.getSpecies();
displayCompareNumberCatchGraph(controlView, species);
}
@@ -632,38 +643,64 @@
* Selectionne toutes les lignes associés au erreur d'un groupe d'erreur.
*
* @param controlView controlView
- * @param validationGroup validationGroup
+ * @param category la categorie pour switcher les tables
+ * @param lastNode validationGroup
*/
- protected void selectAllErrorGroupLines(ControlView controlView, Category category, ControlErrorGroup validationGroup) {
+ protected void selectAllErrorGroupLines(ControlView controlView, Category category, TreeTableNode lastNode) {
// swap category
controlView.getCategoryComboBoxModel().setSelectedItem(category);
// select all lines
+ JTable displayedTable = getControlDataTable(controlView);
+ ListSelectionModel selectionModel = displayedTable.getSelectionModel();
+ selectionModel.clearSelection();
+ selectAllErrorGroupLines(controlView, lastNode, true);
+ }
+
+ /**
+ * Methode recursive qui selection toutes les lignes correspondant à un
+ * groupe d'erreurs.
+ *
+ * @param controlView
+ * @param lastNode
+ * @param scrollToVisible allow to scroll to visible
+ */
+ protected void selectAllErrorGroupLines(ControlView controlView, TreeTableNode lastNode, boolean scrollToVisible) {
GlobalControlErrorModel model = controlView.getGlobalControlErrorModel();
JTable displayedTable = getControlDataTable(controlView);
ControlTableModel tableModel = (ControlTableModel)displayedTable.getModel();
ListSelectionModel selectionModel = displayedTable.getSelectionModel();
- selectionModel.clearSelection();
- boolean first = true;
- int childCount = model.getChildCount(validationGroup);
+
+ boolean first = scrollToVisible;
+ int childCount = model.getChildCount(lastNode);
for (int indexChild = 0 ; indexChild < childCount ; ++indexChild) {
- ControlError validationError = (ControlError)model.getChild(validationGroup, indexChild);
- List<String> errorLineNumbers = validationError.getLineNumbers();
+ TreeTableNode childNode = (TreeTableNode)model.getChild(lastNode, indexChild);
+ Object userObject = childNode.getUserObject();
- for (String errorLineNumber : errorLineNumbers) {
- int errorLineIndex = tableModel.getRealIndexOfLine(errorLineNumber);
+ if (userObject instanceof ControlErrorGroup) { // recursive
+ selectAllErrorGroupLines(controlView, childNode, first);
+ first = false;
+ } else if (userObject instanceof ControlError) {
+ ControlError validationError = (ControlError)userObject;
+ List<String> errorLineNumbers = validationError.getLineNumbers();
+
+ for (String errorLineNumber : errorLineNumbers) {
+ int errorLineIndex = tableModel.getRealIndexOfLine(errorLineNumber);
- // ca peut arriver si la ligne a été supprimée
- if (errorLineIndex >= 0) {
- selectionModel.addSelectionInterval(errorLineIndex, errorLineIndex);
- if (first) {
- scrollToVisible(displayedTable, errorLineIndex, 0);
- first = false;
+ // ca peut arriver si la ligne a été supprimée
+ if (errorLineIndex >= 0) {
+ selectionModel.addSelectionInterval(errorLineIndex, errorLineIndex);
+ if (first) {
+ scrollToVisible(displayedTable, errorLineIndex, 0);
+ first = false;
+ }
}
}
}
}
}
+
+
/**
* Scroll le viewport de la table à la ligne demandée.
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalControlErrorModel.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalControlErrorModel.java 2012-07-18 10:24:01 UTC (rev 1024)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/GlobalControlErrorModel.java 2012-07-19 09:36:52 UTC (rev 1025)
@@ -3,7 +3,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric
+ * Copyright (C) 2010 - 2012 Ifremer, Codelutin, 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
@@ -26,21 +26,19 @@
import static org.nuiton.i18n.I18n._;
import static org.nuiton.i18n.I18n.n_;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.jdesktop.swingx.treetable.AbstractTreeTableModel;
+import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
+import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
-import fr.ifremer.coser.CoserConstants.Category;
import fr.ifremer.coser.CoserConstants.ValidationLevel;
-import fr.ifremer.coser.control.ControlErrorGroup;
import fr.ifremer.coser.control.ControlError;
+import fr.ifremer.coser.control.ControlErrorGroup;
+import fr.ifremer.coser.control.DiffCatchLengthControlError;
/**
* Global validation table model.
@@ -51,23 +49,19 @@
* Last update : $Date$
* By : $Author$
*/
-public class GlobalControlErrorModel extends AbstractTreeTableModel {
+public class GlobalControlErrorModel extends DefaultTreeTableModel {
protected List<ControlError> controlErrors;
- protected List<Object> controlErrorCategory;
- protected Map<Object, List<ControlErrorGroup>> controlCategoryChild;
- protected Map<ControlErrorGroup, List<ControlError>> controlErrorsChilds;
protected Set<Object> checkedControlErrors;
public GlobalControlErrorModel() {
- super(1);
+ super(null);
}
public void setControlErrors(List<ControlError> controlErrors) {
this.controlErrors = controlErrors;
- getValidationErrorAsMaps(controlErrors);
- modelSupport.fireNewRoot();
-
+ buildGlobalControlErrorTreeModel(controlErrors);
+ checkedControlErrors = new HashSet<Object>();
}
public List<ControlError> getControlErrors() {
@@ -75,60 +69,61 @@
}
/**
- * Convert error list to tree structure.
+ * Utilise une simple liste d'erreur issue du contôle pour en faire
+ * une représentation sous forme d'arbre pour l'utilisateur.
*
- * @param validationErrors list to convert
+ * @param errors errors list to render
*/
- protected void getValidationErrorAsMaps(List<ControlError> validationErrors) {
+ protected void buildGlobalControlErrorTreeModel(List<ControlError> validationErrors) {
- controlCategoryChild = new HashMap<Object, List<ControlErrorGroup>>();
- controlErrorsChilds = new HashMap<ControlErrorGroup, List<ControlError>>();
+ Map<Object, DefaultMutableTreeTableNode> nodeCache = new HashMap<Object, DefaultMutableTreeTableNode>();
+ DefaultMutableTreeTableNode root = new DefaultMutableTreeTableNode(null);
for (ControlError validationError : validationErrors) {
-
Object category = validationError.getCategory() == null ?
n_("coser.ui.control.error.allCategories") : validationError.getCategory();
- List<ControlErrorGroup> errorGroup = controlCategoryChild.get(category);
- if (errorGroup == null) {
- errorGroup = new ArrayList<ControlErrorGroup>();
- controlCategoryChild.put(category, errorGroup);
+
+ // definition du noeud categorie
+ DefaultMutableTreeTableNode categoryNode = nodeCache.get(category);
+ if (categoryNode == null) {
+ categoryNode = new DefaultMutableTreeTableNode(category);
+ root.add(categoryNode);
+ nodeCache.put(category, categoryNode);
}
- ControlErrorGroup group = new ControlErrorGroup(validationError.getCategory(), validationError.getLevel(), validationError.getMessage());
-
- List<ControlError> childErrors = controlErrorsChilds.get(group);
- if (childErrors == null) {
- childErrors = new ArrayList<ControlError>();
- controlErrorsChilds.put(group, childErrors);
- errorGroup.add(group);
+ // definition du noeud de regroupement
+ // des erreurs de categories communes
+ DefaultMutableTreeTableNode parentNode = nodeCache.get(validationError.getMessage());
+ if (parentNode == null) {
+ ControlErrorGroup group = new ControlErrorGroup(validationError.getCategory(), validationError.getLevel(), validationError.getMessage());
+ parentNode = new DefaultMutableTreeTableNode(group);
+ categoryNode.add(parentNode);
+ nodeCache.put(validationError.getMessage(), parentNode);
}
-
- childErrors.add(validationError);
- }
-
- controlErrorCategory = new ArrayList<Object>(controlCategoryChild.keySet());
- Collections.sort(controlErrorCategory, new Comparator<Object>() {
- @Override
- public int compare(Object o1, Object o2) {
- int result = -1;
- if (o1 instanceof String) {
- if (o2 instanceof String) {
- result = ((String)o1).compareTo((String)o2);
- }
+
+ // cas special pour les erreurs DiffCatchLengthControlError
+ // regroupement supplémentaire par espèce
+ if (validationError instanceof DiffCatchLengthControlError) {
+ DiffCatchLengthControlError diffCatchError = (DiffCatchLengthControlError)validationError;
+ String species = diffCatchError.getSpecies();
+ String speciesCategory = _("coser.ui.control.error.diffcatchlenghtspecies", species);
+
+ ControlErrorGroup group = new ControlErrorGroup(validationError.getCategory(), validationError.getLevel(), speciesCategory);
+ DefaultMutableTreeTableNode newParent = nodeCache.get(speciesCategory);
+ if (newParent == null) {
+ newParent = new DefaultMutableTreeTableNode(group);
+ parentNode.add(newParent);
+ nodeCache.put(speciesCategory, newParent);
}
- else if (o1 instanceof Category) {
- if (o2 instanceof Category) {
- result = ((Category)o1).compareTo((Category)o2);
- }
- }
- return result;
+ parentNode = newParent;
}
-
- });
- for (List<ControlErrorGroup> groups : controlCategoryChild.values()) {
- Collections.sort(groups);
+
+ // ajout de l'erreur dans sa categories
+ DefaultMutableTreeTableNode node = new DefaultMutableTreeTableNode(validationError);
+ parentNode.add(node);
}
- checkedControlErrors = new HashSet<Object>();
+
+ setRoot(root);
}
/*
@@ -188,73 +183,7 @@
return result;
}
- /*
- * @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int)
- */
@Override
- public Object getChild(Object parent, int index) {
-
- Object result = null;
-
- if (parent == getRoot()) {
- result = controlErrorCategory.get(index);
- }
- else if (parent instanceof String || parent instanceof Category) {
- result = controlCategoryChild.get(parent).get(index);
- }
- else if (parent instanceof ControlErrorGroup) {
- List<ControlError> childError = controlErrorsChilds.get(parent);
- result = childError.get(index);
- }
-
- return result;
- }
-
- /*
- * @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object)
- */
- @Override
- public int getChildCount(Object parent) {
- int result = 0;
-
- if (parent == getRoot()) {
- if (controlErrorCategory != null) {
- result = controlErrorCategory.size();
- }
- }
- else if (parent instanceof String || parent instanceof Category) {
- result = controlCategoryChild.get(parent).size();
- }
- else if (parent instanceof ControlErrorGroup) {
- List<ControlError> childError = controlErrorsChilds.get(parent);
- result = childError.size();
- }
-
- return result;
- }
-
- /*
- * @see javax.swing.tree.TreeModel#getIndexOfChild(java.lang.Object, java.lang.Object)
- */
- @Override
- public int getIndexOfChild(Object parent, Object child) {
- int result = -1;
-
- if (parent == getRoot()) {
- result = controlErrorCategory.indexOf(child);
- }
- else if (parent instanceof String || parent instanceof Category) {
- result = controlCategoryChild.get(parent).indexOf(child);
- }
- else if (parent instanceof ControlErrorGroup) {
- List<ControlError> childError = controlErrorsChilds.get(parent);
- result = childError.indexOf(child);
- }
-
- return result;
- }
-
- @Override
public boolean isCellEditable(Object node, int column) {
boolean result = false;
if (column == 1) {
@@ -275,12 +204,10 @@
}
// recursive check of sub errors
- if (node instanceof String || node instanceof Category || node instanceof ControlErrorGroup) {
- int childCount = getChildCount(node);
- for (int i = 0 ; i < childCount; ++i) {
- Object child = getChild(node, i);
- setValueAt(value, child, column);
- }
+ int childCount = getChildCount(node);
+ for (int i = 0 ; i < childCount; ++i) {
+ Object child = getChild(node, i);
+ setValueAt(value, child, column);
}
}
}
Modified: trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties
===================================================================
--- trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties 2012-07-18 10:24:01 UTC (rev 1024)
+++ trunk/coser-ui/src/main/resources/i18n/coser-ui_en_GB.properties 2012-07-19 09:36:52 UTC (rev 1025)
@@ -35,6 +35,7 @@
coser.ui.control.dataMenuReplaceAll=Replace in %s in all data
coser.ui.control.deleteLine=Delete line
coser.ui.control.error.allCategories=All categories
+coser.ui.control.error.diffcatchlenghtspecies=Differences between length and catch for %s
coser.ui.control.global.message=Message
coser.ui.control.globalErrorMenuGenerateHTML=Control report
coser.ui.control.globalErrorMenuSelectAll=Select all lines
Modified: trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties
===================================================================
--- trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties 2012-07-18 10:24:01 UTC (rev 1024)
+++ trunk/coser-ui/src/main/resources/i18n/coser-ui_fr_FR.properties 2012-07-19 09:36:52 UTC (rev 1025)
@@ -35,6 +35,7 @@
coser.ui.control.dataMenuReplaceAll=Remplacer dans %s pour toutes les lignes
coser.ui.control.deleteLine=Supprimer la ligne
coser.ui.control.error.allCategories=Toutes les catégories
+coser.ui.control.error.diffcatchlenghtspecies=Différence entre les captures et taille pour %s
coser.ui.control.global.message=Message
coser.ui.control.globalErrorMenuGenerateHTML=Rapport de contrôle
coser.ui.control.globalErrorMenuSelectAll=Sélectionner toutes les lignes
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-07-18 10:24:01 UTC (rev 1024)
+++ trunk/pom.xml 2012-07-19 09:36:52 UTC (rev 1025)
@@ -316,7 +316,7 @@
<roles>
<role>Développeur</role>
</roles>
- <timezone>+2</timezone>
+ <timezone>Europe/Paris</timezone>
</developer>
<developer>
<id>tchemit</id>
@@ -326,7 +326,7 @@
<roles>
<role>Développeur</role>
</roles>
- <timezone>+2</timezone>
+ <timezone>Europe/Paris</timezone>
</developer>
</developers>
1
0
r1024 - in trunk/src/site: . en/rst en/rst/devel rst/devel
by echatellier@users.forge.codelutin.com 18 Jul '12
by echatellier@users.forge.codelutin.com 18 Jul '12
18 Jul '12
Author: echatellier
Date: 2012-07-18 12:24:01 +0200 (Wed, 18 Jul 2012)
New Revision: 1024
Url: http://forge.codelutin.com/repositories/revision/coser/1024
Log:
refs #1334
Added:
trunk/src/site/en/rst/devel/
trunk/src/site/en/rst/devel/textupdate.rst
trunk/src/site/rst/devel/textupdate.rst
Modified:
trunk/src/site/site_en.xml
trunk/src/site/site_fr.xml
Added: trunk/src/site/en/rst/devel/textupdate.rst
===================================================================
--- trunk/src/site/en/rst/devel/textupdate.rst (rev 0)
+++ trunk/src/site/en/rst/devel/textupdate.rst 2012-07-18 10:24:01 UTC (rev 1024)
@@ -0,0 +1,25 @@
+.. -
+.. * #%L
+.. * Coser
+.. *
+.. * $Id$
+.. * $HeadURL$
+.. * %%
+.. * Copyright (C) 2012 Ifremer, Codelutin, Chatellier Eric
+.. * %%
+.. * This program is free software: you can redistribute it and/or modify
+.. * it under the terms of the GNU Lesser General Public License as
+.. * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+.. *
+.. * You should have received a copy of the GNU General Lesser Public
+.. * License along with this program. If not, see
+.. * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+.. * #L%
+.. -
+
Added: trunk/src/site/rst/devel/textupdate.rst
===================================================================
--- trunk/src/site/rst/devel/textupdate.rst (rev 0)
+++ trunk/src/site/rst/devel/textupdate.rst 2012-07-18 10:24:01 UTC (rev 1024)
@@ -0,0 +1,82 @@
+.. -
+.. * #%L
+.. * Coser
+.. *
+.. * $Id$
+.. * $HeadURL$
+.. * %%
+.. * Copyright (C) 2012 Ifremer, Codelutin, Chatellier Eric
+.. * %%
+.. * This program is free software: you can redistribute it and/or modify
+.. * it under the terms of the GNU Lesser General Public License as
+.. * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+.. *
+.. * You should have received a copy of the GNU General Lesser Public
+.. * License along with this program. If not, see
+.. * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+.. * #L%
+.. -
+
+Mise à jour des textes du site
+==============================
+
+Cette documentation détaille comment mettre à jour le contenu textuel du site:
+http://www.ifremer.fr/SIH-indices-campagnes/.
+
+Source
+------
+Pour pouvoir modifier n'importe quel contenu, il faut être développeur autorisé
+à commiter sur le dépôt de source de coser.
+
+Ensuite, il est possible de récupérer les sources via un client subversion:
+ * Windows : http://tortoisesvn.net/
+ * Linux : commande console ``svn``
+
+L'adresse du dépôt à renseigner est : http://svn.forge.codelutin.com/svn/coser/trunk
+
+
+Organisation des dossiers
+-------------------------
+Le répertoire racine est constitué de 3 modules maven:
+
+ * *coser-business* : contenant le code métier (tout le code utilisé par les deux
+ autre modules)
+ * *coser-ui* : client swing
+ * *coser-web* : site internet
+
+Dans le cas de la modification du contenu text du site, le module *coser-web*
+devra être utilisé.
+
+
+Source du modules coser-web
+---------------------------
+Dans le module coser-web, deux groupes de fichiers concerne la modification
+du contenu textuel:
+
+ * ``src/main/webapp/WEB-INF/content`` : qui contient les pages html
+ * ``src/main/resources/fr/ifremer/coser/web`` : qui contient les traductions de
+ texte à inclure dans les pages html
+
+En effet, dans les pages html, on trouve ce genre d'instruction::
+
+ <head>
+ <title><s:text name="message.index.title" /></title>
+ </head>
+
+Cette code défini un titre de page html, contenant la traduction de le clé
+`message.layout.title`.
+
+Et dans les fichiers ``package_en.properties`` et ``package_fr.properties``, on trouve
+respectivement::
+
+ message.index.title=Home
+
+et::
+
+ message.index.title=Accueil
\ No newline at end of file
Modified: trunk/src/site/site_en.xml
===================================================================
--- trunk/src/site/site_en.xml 2012-07-18 10:22:09 UTC (rev 1023)
+++ trunk/src/site/site_en.xml 2012-07-18 10:24:01 UTC (rev 1024)
@@ -78,9 +78,9 @@
<item name="Controls list" href="user/guide_listcontrols.html" />
<item name="Controls modification" href="user/controls.html" />
</item>
- <!-- <item name="Developer" href="developer.html">
- <item name="Coser Project layout" href="devel/directory.html" />
- </item> -->
+ <item name="Developer" href="developer.html">
+ <item name="Update website texts" href="devel/textupdate.html" />
+ </item>
</menu>
<menu ref="modules"/>
Modified: trunk/src/site/site_fr.xml
===================================================================
--- trunk/src/site/site_fr.xml 2012-07-18 10:22:09 UTC (rev 1023)
+++ trunk/src/site/site_fr.xml 2012-07-18 10:24:01 UTC (rev 1024)
@@ -77,10 +77,11 @@
<item name="Avancé" href="user/guide_listcontrols.html">
<item name="Liste des contrôles" href="user/guide_listcontrols.html" />
<item name="Modification des contrôles" href="user/controls.html" />
+
</item>
- <!-- <item name="Développeur" href="developer.html">
- <item name="Coser Project layout" href="devel/directory.html" />
- </item> -->
+ <item name="Développeur" href="developer.html">
+ <item name="Mise à jour des textes du site" href="devel/textupdate.html" />
+ </item>
</menu>
<menu ref="modules"/>
1
0
Author: echatellier
Date: 2012-07-18 12:22:09 +0200 (Wed, 18 Jul 2012)
New Revision: 1023
Url: http://forge.codelutin.com/repositories/revision/coser/1023
Log:
Use released version
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-07-18 09:59:42 UTC (rev 1022)
+++ trunk/pom.xml 2012-07-18 10:22:09 UTC (rev 1023)
@@ -346,7 +346,7 @@
<license.organizationName>Ifremer, Codelutin</license.organizationName>
<!-- Versions -->
- <jaxx.version>2.5.2-SNAPSHOT</jaxx.version>
+ <jaxx.version>2.5.2</jaxx.version>
<i18n.version>2.4.1</i18n.version>
<!-- 2.3.1.1 fails to validate fields in jnlp -->
<struts.version>2.3.4</struts.version>
1
0
r1022 - trunk/coser-web/src/main/webapp/WEB-INF/decorators
by echatellier@users.forge.codelutin.com 18 Jul '12
by echatellier@users.forge.codelutin.com 18 Jul '12
18 Jul '12
Author: echatellier
Date: 2012-07-18 11:59:42 +0200 (Wed, 18 Jul 2012)
New Revision: 1022
Url: http://forge.codelutin.com/repositories/revision/coser/1022
Log:
Remove comments
Modified:
trunk/coser-web/src/main/webapp/WEB-INF/decorators/layout.jsp
trunk/coser-web/src/main/webapp/WEB-INF/decorators/sublayout.jsp
Modified: trunk/coser-web/src/main/webapp/WEB-INF/decorators/layout.jsp
===================================================================
--- trunk/coser-web/src/main/webapp/WEB-INF/decorators/layout.jsp 2012-07-18 09:53:12 UTC (rev 1021)
+++ trunk/coser-web/src/main/webapp/WEB-INF/decorators/layout.jsp 2012-07-18 09:59:42 UTC (rev 1022)
@@ -55,8 +55,7 @@
<div id="conteneur">
<div id="head" class="clearfix">
<a href="http://www.ifremer.fr/sih/" class="logoSIH" target="_blank">Système d'Information Halieutique</a>
- <h1><!-- Indices de populations et de communauté <br/>
- issus des campagnes de <span class="jaune">surveillance halieutique</span> de <span class="jaune">l'Ifremer </span> -->
+ <h1>
<s:text name="message.layout.title" />
</h1>
<a href="http://www.ifremer.fr/" class="logoIfremer" target="_blank">L'Ifremer</a>
Modified: trunk/coser-web/src/main/webapp/WEB-INF/decorators/sublayout.jsp
===================================================================
--- trunk/coser-web/src/main/webapp/WEB-INF/decorators/sublayout.jsp 2012-07-18 09:53:12 UTC (rev 1021)
+++ trunk/coser-web/src/main/webapp/WEB-INF/decorators/sublayout.jsp 2012-07-18 09:59:42 UTC (rev 1022)
@@ -55,8 +55,7 @@
<div id="conteneur_int">
<div id="head" class="clearfix">
<a href="http://www.ifremer.fr/sih/" class="logoSIH" target="_blank">Système d'Information Halieutique</a>
- <h1><!-- Indices de populations et de communauté <br/>
- issus des campagnes de <span class="jaune">surveillance halieutique</span> de <span class="jaune">l'Ifremer </span> -->
+ <h1>
<s:text name="message.layout.title" />
</h1>
<a href="http://www.ifremer.fr/" class="logoIfremer" target="_blank">L'Ifremer</a>
1
0
r1021 - trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control
by echatellier@users.forge.codelutin.com 18 Jul '12
by echatellier@users.forge.codelutin.com 18 Jul '12
18 Jul '12
Author: echatellier
Date: 2012-07-18 11:53:12 +0200 (Wed, 18 Jul 2012)
New Revision: 1021
Url: http://forge.codelutin.com/repositories/revision/coser/1021
Log:
Misc fix
Modified:
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2012-07-18 08:29:15 UTC (rev 1020)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2012-07-18 09:53:12 UTC (rev 1021)
@@ -3,7 +3,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric
+ * Copyright (C) 2010 - 2012 Ifremer, Codelutin, 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
@@ -390,7 +390,6 @@
final ControlService validationService = view.getContextValue(ControlService.class);
final Project project = view.getContextValue(Project.class);
- //final Category category = (Category)view.getCategoryComboBox().getSelectedItem();
final CoserProgressBar progressBar = view.getCheckProgressBar();
SwingWorker<List<ControlError>, Void> task = new SwingWorker<List<ControlError>, Void>() {
@@ -420,7 +419,7 @@
view.setContextValue(charts, "CompareCatchLengthGraph");
view.getCompareNumberCatchLengthButton().setEnabled(true);
- // hack parce que impossible de faire un faire
+ // hack parce que impossible à faire
// sans que les colonnes soit redimentionnées
view.getGlobalControlErrorTable().setAutoCreateColumnsFromModel(false);
@@ -562,7 +561,7 @@
* @param event mouse event
* @see DiffCatchLengthControlError
*/
- public void globalErrorTableMouseCLicked(final ControlView controlView, MouseEvent event) {
+ public void globalErrorTableMouseClicked(final ControlView controlView, MouseEvent event) {
int eventButton = event.getButton();
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2012-07-18 08:29:15 UTC (rev 1020)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2012-07-18 09:53:12 UTC (rev 1021)
@@ -163,7 +163,7 @@
<JXTreeTable id='globalControlErrorTable' treeTableModel="{globalControlErrorModel}"
rootVisible="false" showsRootHandles="true"
treeCellRenderer="{new ControlErrorTreeRenderer()}"
- onMouseClicked="getHandler().globalErrorTableMouseCLicked(this, event)"
+ onMouseClicked="getHandler().globalErrorTableMouseClicked(this, event)"
selectionMode="{ListSelectionModel.SINGLE_SELECTION}" />
<javax.swing.tree.TreeSelectionModel id="globalControlErrorSelectionModel"
javaBean="globalControlErrorTable.getTreeSelectionModel()"
1
0
r1020 - trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project
by echatellier@users.forge.codelutin.com 18 Jul '12
by echatellier@users.forge.codelutin.com 18 Jul '12
18 Jul '12
Author: echatellier
Date: 2012-07-18 10:29:15 +0200 (Wed, 18 Jul 2012)
New Revision: 1020
Url: http://forge.codelutin.com/repositories/revision/coser/1020
Log:
Fix button enabled
Modified:
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx 2012-07-17 16:25:55 UTC (rev 1019)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx 2012-07-18 08:29:15 UTC (rev 1020)
@@ -5,7 +5,7 @@
$Id$
$HeadURL$
%%
- Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric
+ Copyright (C) 2010 - 2012 Ifremer, Codelutin, 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
@@ -45,7 +45,7 @@
<row>
<cell weightx="1" anchor="east" columns="3">
<JButton text="coser.ui.project.openProject"
- enabled="{projectsList.getSelectedIndex() > 0}"
+ enabled="{projectsList.getSelectedIndex() >= 0}"
onActionPerformed="getHandler().loadProject(this)" />
</cell>
</row>
1
0
r1019 - in trunk/coser-ui/src/main/java/fr/ifremer/coser/ui: control project selection
by echatellier@users.forge.codelutin.com 17 Jul '12
by echatellier@users.forge.codelutin.com 17 Jul '12
17 Jul '12
Author: echatellier
Date: 2012-07-17 18:25:55 +0200 (Tue, 17 Jul 2012)
New Revision: 1019
Url: http://forge.codelutin.com/repositories/revision/coser/1019
Log:
Misc improvements
Modified:
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectHandler.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionListsView.jaxx
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2012-07-17 15:28:11 UTC (rev 1018)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2012-07-17 16:25:55 UTC (rev 1019)
@@ -5,7 +5,7 @@
$Id$
$HeadURL$
%%
- Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric
+ Copyright (C) 2010 - 2012 Ifremer, Codelutin, 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
@@ -48,9 +48,6 @@
<row>
<cell fill="horizontal" insets="0" anchor="west" columns="2">
<JToolBar floatable="false">
- <JButton icon="disk.png" text="coser.ui.control.save"
- onActionPerformed="getHandler().saveControl(this)" />
- <JToolBar.Separator />
<JLabel text="coser.ui.control.categorylabel" />
<fr.ifremer.coser.ui.control.ControlCategoryListModel id="categoryComboBoxModel" />
<JComboBox id="categoryComboBox" model="{categoryComboBoxModel}"
@@ -67,11 +64,12 @@
<JToolBar.Separator />
<JButton icon="report.png" onActionPerformed="getHandler().displayLogReport(this)"
text="coser.ui.control.controlreport" />
- <JToolBar.Separator />
+ <Component initializer="javax.swing.Box.createHorizontalGlue()" />
+ <JButton icon="disk.png" text="coser.ui.control.save"
+ onActionPerformed="getHandler().saveControl(this)" />
<JButton icon="accept.png" onActionPerformed="getHandler().validControl(this)"
text="coser.ui.control.validcontrol" toolTipText="coser.ui.control.validcontroltip"
enabled="{isCanValidControl()}"/>
-
</JToolBar>
</cell>
</row>
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectHandler.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectHandler.java 2012-07-17 15:28:11 UTC (rev 1018)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectHandler.java 2012-07-17 16:25:55 UTC (rev 1019)
@@ -33,6 +33,7 @@
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
+import javax.swing.ListSelectionModel;
import javax.swing.SwingWorker;
import javax.swing.filechooser.FileFilter;
@@ -309,7 +310,8 @@
*/
public void loadProject(final ProjectOpenView projectView) {
- final String projectName = (String)projectView.getProjectsComboBox().getSelectedItem();
+ int selectedIndex = projectView.getProjectsList().getSelectedIndex();
+ String projectName = (String)projectView.getProjectsList().getModel().getElementAt(selectedIndex);
ProjectService projectService = projectView.getContextValue(ProjectService.class);
CoserFrame parent = projectView.getContextValue(CoserFrame.class, JAXXUtil.PARENT);
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx 2012-07-17 15:28:11 UTC (rev 1018)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/project/ProjectOpenView.jaxx 2012-07-17 16:25:55 UTC (rev 1019)
@@ -29,20 +29,23 @@
<cell weightx="1" fill="horizontal">
<Table border='{BorderFactory.createTitledBorder(_("coser.ui.project.openProjectTitle"))}'>
<row>
- <cell anchor="west">
+ <cell anchor="north">
<JLabel text="coser.ui.project.project" />
</cell>
- <cell>
+ <cell anchor="north">
<JLabel text='{getContextValue(fr.ifremer.coser.CoserConfig.class).getProjectsDirectory().getAbsolutePath() + java.io.File.separator}' />
</cell>
- <cell anchor="west" weightx="1">
- <JComboBox id="projectsComboBox" model="{new fr.ifremer.coser.ui.project.ProjectNamesListModel(this)}" />
+ <cell fill="both" weightx="1">
+ <JScrollPane>
+ <JList id="projectsList" selectionMode="{javax.swing.ListSelectionModel.SINGLE_SELECTION}"
+ model="{new fr.ifremer.coser.ui.project.ProjectNamesListModel(this)}" />
+ </JScrollPane>
</cell>
</row>
<row>
<cell weightx="1" anchor="east" columns="3">
<JButton text="coser.ui.project.openProject"
- enabled="{projectsComboBox.getSelectedItem() != null}"
+ enabled="{projectsList.getSelectedIndex() > 0}"
onActionPerformed="getHandler().loadProject(this)" />
</cell>
</row>
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx 2012-07-17 15:28:11 UTC (rev 1018)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionDetailsView.jaxx 2012-07-17 16:25:55 UTC (rev 1019)
@@ -63,15 +63,16 @@
</BeanValidator>
<row>
- <cell weightx="1" fill="horizontal">
+ <cell weightx="1" insets="0" fill="horizontal" >
<JToolBar floatable="false">
- <JButton id="saveSelectionButton" text="coser.ui.selection.details.saveSelection"
- icon="disk.png" onActionPerformed="getHandler().saveSelection(this)" />
<JButton icon="report.png" onActionPerformed="getHandler().displayLogReport(this)"
text="coser.ui.selection.selectionreport" />
<JToolBar.Separator />
<JButton icon="arrow_rotate_clockwise.png" onActionPerformed="getHandler().reloadControlData(this)"
text="coser.ui.selection.reloadcontroldata" />
+ <Component initializer="javax.swing.Box.createHorizontalGlue()" />
+ <JButton id="saveSelectionButton" text="coser.ui.selection.details.saveSelection"
+ icon="disk.png" onActionPerformed="getHandler().saveSelection(this)" />
</JToolBar>
</cell>
</row>
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2012-07-17 15:28:11 UTC (rev 1018)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2012-07-17 16:25:55 UTC (rev 1019)
@@ -766,20 +766,6 @@
}
/**
- * Sauvegarde la sélection (partie listes de selection)
- * et affiche un message utilisateur.
- *
- * @param view parent view
- */
- public void saveSelection(SelectionListsView view) {
- boolean saved = saveProjectSelection(view);
- if (saved) {
- JOptionPane.showMessageDialog(view, _("coser.ui.selection.selectionSaved"),
- _("coser.ui.selection.selectionTitle"), JOptionPane.INFORMATION_MESSAGE);
- }
- }
-
- /**
* Sauvegarde la sélection (partie listes de selection).
*
* @param view parent view
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionListsView.jaxx
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionListsView.jaxx 2012-07-17 15:28:11 UTC (rev 1018)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionListsView.jaxx 2012-07-17 16:25:55 UTC (rev 1019)
@@ -55,8 +55,7 @@
<row>
<cell columns="8" weightx="1" fill="horizontal">
<JToolBar floatable="false">
- <JButton id="saveSelectionButton" text="coser.ui.selection.details.saveSelection"
- icon="disk.png" onActionPerformed="getHandler().saveSelection(this)" />
+ <Component initializer="javax.swing.Box.createHorizontalGlue()" />
<JButton id="validSelectionButton" text="coser.ui.selection.details.validSelection"
icon="accept.png" onActionPerformed="getHandler().validSelection(this)" />
</JToolBar>
1
0
r1018 - in trunk: coser-business/src/main/java/fr/ifremer/coser/services coser-business/src/main/resources/i18n coser-business/src/test/java/fr/ifremer/coser/services coser-ui/src/main/java/fr/ifremer/coser/ui/control coser-ui/src/main/java/fr/ifremer/coser/ui/selection
by echatellier@users.forge.codelutin.com 17 Jul '12
by echatellier@users.forge.codelutin.com 17 Jul '12
17 Jul '12
Author: echatellier
Date: 2012-07-17 17:28:11 +0200 (Tue, 17 Jul 2012)
New Revision: 1018
Url: http://forge.codelutin.com/repositories/revision/coser/1018
Log:
fixes #1329 : Sauvegarder les rapports contr?\195?\180le et s?\195?\169lection en PDF
Modified:
trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java
trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java
trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties
trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java
Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2012-07-17 14:03:22 UTC (rev 1017)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2012-07-17 15:28:11 UTC (rev 1018)
@@ -825,14 +825,50 @@
* Genère également les PDF des rapports de contrôle.
*
* @param project project to save
- * @throws CoserBusinessException
+ * @throws CoserBusinessException
+ * @since 1.3
*/
public void validControl(Project project) throws CoserBusinessException {
-
- project.getControl().setValidated(true);
+ Control control = project.getControl();
+ control.setValidated(true);
+
+ // sauvegarde
+ saveProjectControl(project);
+
+ // generate control file as pdf
+ File projectsDirectory = config.getProjectsDirectory();
+ File projectDirectory = new File(projectsDirectory, project.getName());
+ File controlDirectory = new File(projectDirectory, CoserConstants.STORAGE_CONTROL_DIRECTORY);
+ File controlReportPdf = new File(controlDirectory, "control.pdf");
+ publicationService.extractControlLogAsPDF(project, control, controlReportPdf);
}
+
+ /**
+ * Marque la selection comme validée et sauve le projet.
+ *
+ * Genère également les PDF des rapports de selection.
+ *
+ * @param project project to save
+ * @throws CoserBusinessException
+ * @since 1.3
+ */
+ public void validSelection(Project project, Selection selection) throws CoserBusinessException {
+ selection.setValidated(true);
+
+ // sauvegarde
+ saveProjectSelection(project, selection);
+
+ // generate control file as pdf
+ File projectsDirectory = config.getProjectsDirectory();
+ File projectDirectory = new File(projectsDirectory, project.getName());
+ File selectionsDirectory = new File(projectDirectory, CoserConstants.STORAGE_SELECTION_DIRECTORY);
+ File selectionDirectory = new File(selectionsDirectory, selection.getName());
+ File selectionReportPdf = new File(selectionDirectory, "selection.pdf");
+ publicationService.extractSelectionLogAsPDF(project, selection, selectionReportPdf);
+ }
+
/**
* Creer une instance de selection "non sauvegardee" avec les données
* de control (validée) du projet.
Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java 2012-07-17 14:03:22 UTC (rev 1017)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java 2012-07-17 15:28:11 UTC (rev 1018)
@@ -30,8 +30,13 @@
import java.awt.Color;
import java.awt.Shape;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.io.PrintStream;
+import java.io.StringWriter;
+import java.io.Writer;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
@@ -67,11 +72,16 @@
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.statistics.DefaultStatisticalCategoryDataset;
import org.jfree.util.ShapeUtilities;
+import org.w3c.dom.Document;
+import org.xhtmlrenderer.pdf.ITextRenderer;
+import com.lowagie.text.DocumentException;
+
import fr.ifremer.coser.CoserBusinessConfig;
import fr.ifremer.coser.CoserBusinessException;
import fr.ifremer.coser.CoserConstants;
import fr.ifremer.coser.CoserConstants.Category;
+import fr.ifremer.coser.CoserUtils;
import fr.ifremer.coser.bean.AbstractDataContainer;
import fr.ifremer.coser.bean.Control;
import fr.ifremer.coser.bean.Project;
@@ -86,6 +96,7 @@
import fr.ifremer.coser.data.Length;
import fr.ifremer.coser.storage.DataStorage;
import fr.ifremer.coser.storage.MemoryDataStorage;
+import freemarker.template.TemplateException;
/**
* Publication service (charts, reports, export, pdf...)
@@ -421,11 +432,9 @@
out.println("</ul>");
out.println("</body></html>");
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
throw new CoserBusinessException("Can't export errors", ex);
- }
- finally {
+ } finally {
IOUtils.closeQuietly(out);
}
return exportHtmlFile;
@@ -443,40 +452,93 @@
*/
public File extractControlLogAsHTML(Project project, Control control) throws CoserBusinessException {
File exportHtmlFile = null;
- PrintStream out = null;
+ Writer out = null;
try {
exportHtmlFile = File.createTempFile("log-", ".html");
if (log.isInfoEnabled()) {
log.info("Generating HTML report to " + exportHtmlFile.getAbsolutePath());
}
- out = new PrintStream(exportHtmlFile, "utf-8");
+ out = new OutputStreamWriter(new FileOutputStream(exportHtmlFile), "utf-8");
+ extractControlLogAsHTML(project, control, out);
+ } catch (IOException ex) {
+ throw new CoserBusinessException("Can't export logs", ex);
+ } finally {
+ IOUtils.closeQuietly(out);
+ }
+ return exportHtmlFile;
+ }
- out.println("<html><head>");
- out.println("<title>" + _("coser.business.publication.controllogexporttitle", project.getName())+ "</title>");
- out.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
- out.println("</head><body>");
+ /**
+ * Extrait les logs des modifications faites sur un control au format html
+ * dans un flux donné.
+ *
+ * @param project project
+ * @param control data container
+ * @param out output stream
+ * @throws CoserBusinessException
+ * @throws IOException
+ */
+ protected void extractControlLogAsHTML(Project project, Control control, Writer out) throws CoserBusinessException, IOException {
+ out.write("<html><head>");
+ out.write("<title>" + _("coser.business.publication.controllogexporttitle", project.getName())+ "</title>");
+ out.write("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>");
+ out.write("</head><body>");
- // header
- out.println("<h1 style='text-align:center'>" + _("coser.business.publication.controllogexporttitle", project.getName()) + "</h1>");
+ // header
+ out.write("<h1 style='text-align:center'>" + _("coser.business.publication.controllogexporttitle", project.getName()) + "</h1>");
- // partie detail
- extractProjectReport(project, out);
+ // partie detail
+ extractProjectReport(project, out);
- // partie specific : commandes
- extractHistoryCommandReport(project, control, out);
+ // partie specific : commandes
+ extractHistoryCommandReport(project, control, out);
- out.println("</body></html>");
+ out.write("</body></html>");
+ }
+
+ /**
+ * Extrait les logs des modifications faites sur un control au format pdf.
+ *
+ * @param project project
+ * @param control data container
+ * @param pdfFile output pdf file
+ * @return extractedFile
+ * @throws CoserBusinessException
+ * @sincee 1.3
+ *
+ * @see AbstractDataContainer#getHistoryCommands()
+ */
+ public void extractControlLogAsPDF(Project project, Control control, File pdfFile) throws CoserBusinessException {
+
+ OutputStream os = null;
+ try {
+
+ Writer out = new StringWriter();
+ extractControlLogAsHTML(project, control, out);
+ out.flush();
+
+ // get content as w3c document
+ Document document = CoserUtils.parseDocument(out.toString());
+
+ // render template output as pdf
+ os = new FileOutputStream(pdfFile);
+
+ ITextRenderer renderer = new ITextRenderer();
+ renderer.setDocument(document, null);
+ renderer.layout();
+ renderer.createPDF(os);
+
+ os.close();
+ } catch (IOException ex) {
+ throw new CoserBusinessException("Can't generate log pdf", ex);
+ } catch (DocumentException ex) {
+ throw new CoserBusinessException("Can't generate log pdf", ex);
+ } finally {
+ IOUtils.closeQuietly(os);
}
- catch (IOException ex) {
- throw new CoserBusinessException("Can't export logs", ex);
- }
- finally {
- IOUtils.closeQuietly(out);
- }
- return exportHtmlFile;
}
-
+
/**
* Extrait les logs des modifications faites sur une selection au format html.
*
@@ -489,46 +551,61 @@
*/
public File extractSelectionLogAsHTML(Project project, Selection selection) throws CoserBusinessException {
File exportHtmlFile = null;
- PrintStream out = null;
+ Writer out = null;
try {
exportHtmlFile = File.createTempFile("log-", ".html");
if (log.isInfoEnabled()) {
log.info("Generating HTML report to " + exportHtmlFile.getAbsolutePath());
}
- out = new PrintStream(exportHtmlFile, "utf-8");
+ out = new OutputStreamWriter(new FileOutputStream(exportHtmlFile), "utf-8");
+ extractSelectionLogAsHTML(project, selection, out);
+
+ } catch (IOException ex) {
+ throw new CoserBusinessException("Can't export logs", ex);
+ } finally {
+ IOUtils.closeQuietly(out);
+ }
+ return exportHtmlFile;
+ }
- out.println("<html><head>");
- out.println("<title>" + _("coser.business.publication.selectionlogexporttitle", selection.getName(), project.getName())+ "</title>");
- out.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
- out.println("</head><body>");
+ /**
+ * Extrait les logs des modifications faites sur une selection au format html
+ * dans le flux donné.
+ *
+ * @param project project
+ * @param selection data container
+ * @param out output stream
+ * @return extractedFile
+ * @throws IOException
+ * @throws CoserBusinessException
+ *
+ * @see AbstractDataContainer#getHistoryCommands()
+ */
+ protected void extractSelectionLogAsHTML(Project project, Selection selection, Writer out) throws IOException, CoserBusinessException {
+ out.write("<html><head>");
+ out.write("<title>" + _("coser.business.publication.selectionlogexporttitle", selection.getName(), project.getName())+ "</title>");
+ out.write("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>");
+ out.write("</head><body>");
- // header
- out.println("<h1 style='text-align:center'>" + _("coser.business.publication.selectionlogexporttitle", selection.getName(), project.getName()) + "</h1>");
+ // header
+ out.write("<h1 style='text-align:center'>" + _("coser.business.publication.selectionlogexporttitle", selection.getName(), project.getName()) + "</h1>");
- // partie detail
- extractProjectReport(project, out);
+ // partie detail
+ extractProjectReport(project, out);
- // partie resumé de selection
- out.println("<h2>" + _("coser.business.publication.selectionchoices") + "</h2>");
- out.println("<ul>");
- out.println("<li>" + _("coser.business.common.years") + " : " + StringUtils.join(selection.getSelectedYears(), ", ") + "</li>");
- out.println("<li>" + _("coser.business.common.strata") + " : " + StringUtils.join(selection.getSelectedStrata(), ", ") + "</li>");
- out.println("<li>" + _("coser.business.common.species") + " : " + StringUtils.join(selection.getSelectedSpecies(), ", ") + "</li>");
- out.println("</ul>");
+ // partie resumé de selection
+ out.write("<h2>" + _("coser.business.publication.selectionchoices") + "</h2>");
+ out.write("<ul>");
+ out.write("<li>" + _("coser.business.common.years") + " : " + StringUtils.join(selection.getSelectedYears(), ", ") + "</li>");
+ out.write("<li>" + _("coser.business.common.strata") + " : " + StringUtils.join(selection.getSelectedStrata(), ", ") + "</li>");
+ out.write("<li>" + _("coser.business.common.species") + " : " + StringUtils.join(selection.getSelectedSpecies(), ", ") + "</li>");
+ out.write("</ul>");
- // partie specific : commandes
- extractHistoryCommandReport(project, selection, out);
+ // partie specific : commandes
+ extractHistoryCommandReport(project, selection, out);
- out.println("</body></html>");
- }
- catch (IOException ex) {
- throw new CoserBusinessException("Can't export logs", ex);
- }
- finally {
- IOUtils.closeQuietly(out);
- }
- return exportHtmlFile;
+ out.write("</body></html>");
}
/**
@@ -536,32 +613,74 @@
*
* @param project project
* @param out stream
+ * @throws IOException
*/
- protected void extractProjectReport(Project project, PrintStream out) {
+ protected void extractProjectReport(Project project, Writer out) throws IOException {
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT, config.getLocale());
// date du rapport
- out.println("<div style='text-align:right;font-style:italic'>" +
+ out.write("<div style='text-align:right;font-style:italic'>" +
_("coser.business.publication.date") +" : " +
dateFormat.format(new Date()) + "</div>");
// partie projet
- out.println("<h2>" + _("coser.business.publication.projectdetails") + "</h2>");
- out.println("<ul>");
- out.println("<li>" + _("coser.business.publication.creationdate") + " : " + dateFormat.format(project.getCreationDate()));
- out.println("<li>" + _("coser.business.publication.author") + " : " + project.getAuthor() + "</li>");
- out.println("<li>" + _("coser.business.publication.catchfilename") + " : " + commonService.getDataStorageFileName(project, Category.CATCH, null) + "</li>");
- out.println("<li>" + _("coser.business.publication.lengthfilename") + " : " + commonService.getDataStorageFileName(project, Category.LENGTH, null) + "</li>");
- out.println("<li>" + _("coser.business.publication.haulfilename") + " : " + commonService.getDataStorageFileName(project, Category.HAUL, null) + "</li>");
- out.println("<li>" + _("coser.business.publication.stratafilename") + " : " + commonService.getDataStorageFileName(project, Category.STRATA, null) + "</li>");
+ out.write("<h2>" + _("coser.business.publication.projectdetails") + "</h2>");
+ out.write("<ul>");
+ out.write("<li>" + _("coser.business.publication.creationdate") + " : " + dateFormat.format(project.getCreationDate()) + "</li>");
+ out.write("<li>" + _("coser.business.publication.author") + " : " + project.getAuthor() + "</li>");
+ out.write("<li>" + _("coser.business.publication.catchfilename") + " : " + commonService.getDataStorageFileName(project, Category.CATCH, null) + "</li>");
+ out.write("<li>" + _("coser.business.publication.lengthfilename") + " : " + commonService.getDataStorageFileName(project, Category.LENGTH, null) + "</li>");
+ out.write("<li>" + _("coser.business.publication.haulfilename") + " : " + commonService.getDataStorageFileName(project, Category.HAUL, null) + "</li>");
+ out.write("<li>" + _("coser.business.publication.stratafilename") + " : " + commonService.getDataStorageFileName(project, Category.STRATA, null) + "</li>");
if (StringUtils.isNotEmpty(project.getComment())) {
- out.println("<li>" + _("coser.business.publication.comment") + " : " + project.getComment() + "</li>");
+ out.write("<li>" + _("coser.business.publication.comment") + " : " + project.getComment() + "</li>");
}
- out.println("</ul>");
+ out.write("</ul>");
}
/**
+ * Extrait les logs des modifications faites sur une selection au format pdf.
+ *
+ * @param project project
+ * @param selection data container
+ * @return extractedFile
+ * @throws CoserBusinessException
+ * @since 1.3
+ *
+ * @see AbstractDataContainer#getHistoryCommands()
+ */
+ public void extractSelectionLogAsPDF(Project project, Selection selection, File pdfFile) throws CoserBusinessException {
+
+ OutputStream os = null;
+ try {
+
+ Writer out = new StringWriter();
+ extractSelectionLogAsHTML(project, selection, out);
+ out.flush();
+
+ // get content as w3c document
+ Document document = CoserUtils.parseDocument(out.toString());
+
+ // render template output as pdf
+ os = new FileOutputStream(pdfFile);
+
+ ITextRenderer renderer = new ITextRenderer();
+ renderer.setDocument(document, null);
+ renderer.layout();
+ renderer.createPDF(os);
+
+ os.close();
+ } catch (IOException ex) {
+ throw new CoserBusinessException("Can't generate log pdf", ex);
+ } catch (DocumentException ex) {
+ throw new CoserBusinessException("Can't generate log pdf", ex);
+ } finally {
+ IOUtils.closeQuietly(os);
+ }
+ }
+
+ /**
* Partie commune aux export qui effectue en 2 passe la recuperation
* des lignes d'erreur, la recuperation des données correspondant à
* ces lignes dans les fichiers originaux et la sortie des erreurs.
@@ -570,8 +689,9 @@
* @param container data container
* @param out output stream
* @throws CoserBusinessException
+ * @throws IOException
*/
- protected void extractHistoryCommandReport(Project project, AbstractDataContainer container, PrintStream out) throws CoserBusinessException {
+ protected void extractHistoryCommandReport(Project project, AbstractDataContainer container, Writer out) throws CoserBusinessException, IOException {
// first get lines index to get content
Set<String> catchLines = new HashSet<String>();
@@ -611,8 +731,8 @@
Map<String, String[]> strataContent = commonService.getOriginalContent(project, Category.STRATA, strataLines);
// third, generate html report
- out.println("<h2>" + _("coser.business.publication.datamodification") + "</h2>");
- out.println("<ol>");
+ out.write("<h2>" + _("coser.business.publication.datamodification") + "</h2>");
+ out.write("<ol>");
for (Command command : container.getHistoryCommands()) {
Category category = null;
String line = null;
@@ -636,14 +756,14 @@
data = strataContent.get(line);
break;
}
- out.println("<li>" + command.getLogString(container) + "<br/>");
- out.println("<tt style='color:#5F5A59'>" + StringUtils.join(data, ", ") + "</tt><br /></li>");
+ out.write("<li>" + command.getLogString(container) + "<br/>");
+ out.write("<tt style='color:#5F5A59'>" + StringUtils.join(data, ", ") + "</tt><br /></li>");
}
else {
- out.println("<li>" + command.getLogString(container) + "</li>");
+ out.write("<li>" + command.getLogString(container) + "</li>");
}
}
- out.println("</ol>");
+ out.write("</ol>");
}
/**
Modified: trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties
===================================================================
--- trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties 2012-07-17 14:03:22 UTC (rev 1017)
+++ trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties 2012-07-17 15:28:11 UTC (rev 1018)
@@ -111,7 +111,7 @@
coser.business.publication.catchfilename=Nom du fichier captures
coser.business.publication.comment=Commentaire
coser.business.publication.controllogexporttitle=Rapport des modifications (projet %s)
-coser.business.publication.creationdate=Date de créaction
+coser.business.publication.creationdate=Date de création
coser.business.publication.datamodification=Modifications sur les données
coser.business.publication.date=Le
coser.business.publication.errorexportlines=Lignes
Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java
===================================================================
--- trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java 2012-07-17 14:03:22 UTC (rev 1017)
+++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ProjectServiceTest.java 2012-07-17 15:28:11 UTC (rev 1018)
@@ -154,11 +154,47 @@
}
/**
+ * Test que la validation du controle fonctionne et produit bien le pdf
+ * de rapport.
+ *
+ * @throws CoserBusinessException
+ */
+ @Test
+ public void testValidControl() throws CoserBusinessException {
+ Project project = createTestProject(projectService, false);
+ projectService.validControl(project);
+
+ Assert.assertTrue(project.getControl().isValidated());
+ Assert.assertTrue(new File(config.getProjectsDirectory(),
+ project.getName() + File.separator + "control" + File.separator + "control.pdf").exists());
+ }
+
+ /**
* Test que les selections sont bien creer.
*
* @throws CoserBusinessException
*/
@Test
+ public void testValidSelection() throws CoserBusinessException {
+ Project project = createTestProject(projectService, true);
+ Selection selection = projectService.initProjectSelection(project);
+ selection.setName("titi");
+
+ projectService.createProjectSelection(project, selection);
+ projectService.validSelection(project, selection);
+
+ Assert.assertTrue(selection.isValidated());
+ Assert.assertTrue(new File(config.getProjectsDirectory(),
+ project.getName() + File.separator + "selections" + File.separator +
+ "titi" + File.separator + "selection.pdf").exists());
+ }
+
+ /**
+ * Test que les selections sont bien creer.
+ *
+ * @throws CoserBusinessException
+ */
+ @Test
public void testCreateSelection() throws CoserBusinessException {
Project project = createTestProject(projectService, true);
Selection selection = projectService.initProjectSelection(project);
@@ -259,8 +295,6 @@
// doit recharger les données pour être correct
strata = projectService.filterDataYearsAndGetStrata(project, selection, years3);
Assert.assertEquals(3, strata.size());
-
-
}
/**
@@ -317,7 +351,6 @@
projectService.filterDataStrata(project, selection, Collections.singletonList("STR6"));
species = projectService.getProjectSpecies(project, selection, allPpeciesType);
Assert.assertEquals(4, species.size());
-
}
/**
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2012-07-17 14:03:22 UTC (rev 1017)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2012-07-17 15:28:11 UTC (rev 1018)
@@ -1073,7 +1073,6 @@
try {
service.validControl(project);
- saveProjectControl(view);
JOptionPane.showMessageDialog(view, _("coser.ui.control.controlValidated"),
_("coser.ui.control.controlTitle"), JOptionPane.INFORMATION_MESSAGE);
} catch (CoserBusinessException ex) {
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2012-07-17 14:03:22 UTC (rev 1017)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/selection/SelectionHandler.java 2012-07-17 15:28:11 UTC (rev 1018)
@@ -854,14 +854,20 @@
*/
public void validSelection(SelectionListsView view) {
Selection selection = view.getContextValue(Selection.class);
+ Project project = view.getContextValue(Project.class);
+ ProjectService service = view.getContextValue(ProjectService.class);
saveSelectionLists(view, selection);
boolean canBeValidated = checkSelectionListComments(view, selection);
if (canBeValidated) {
- selection.setValidated(true);
- boolean saved = saveProjectSelection(view);
- if (saved) {
+ try {
+ service.validSelection(project, selection);
JOptionPane.showMessageDialog(view, _("coser.ui.selection.selectionValidated"),
- _("coser.ui.selection.selectionTitle"), JOptionPane.INFORMATION_MESSAGE);
+ _("coser.ui.selection.selectionTitle"), JOptionPane.INFORMATION_MESSAGE);
+ } catch (CoserBusinessException ex) {
+ if (log.isErrorEnabled()) {
+ log.error("Can't save selection", ex);
+ }
+ JOptionPane.showMessageDialog(view, ex.getMessage(), _("coser.ui.selection.saveError"), JOptionPane.ERROR_MESSAGE);
}
}
}
1
0
r1017 - in trunk: . coser-business/src/main/java/fr/ifremer/coser/services coser-ui/src/main/java/fr/ifremer/coser
by echatellier@users.forge.codelutin.com 17 Jul '12
by echatellier@users.forge.codelutin.com 17 Jul '12
17 Jul '12
Author: echatellier
Date: 2012-07-17 16:03:22 +0200 (Tue, 17 Jul 2012)
New Revision: 1017
Url: http://forge.codelutin.com/repositories/revision/coser/1017
Log:
Update to struts 2.3.4
Modified:
trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java
trunk/pom.xml
Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java 2012-07-17 09:06:44 UTC (rev 1016)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ControlService.java 2012-07-17 14:03:22 UTC (rev 1017)
@@ -47,11 +47,11 @@
import org.apache.commons.logging.LogFactory;
import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.FileManager;
import com.opensymphony.xwork2.ValidationAwareSupport;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.inject.Container;
-import com.opensymphony.xwork2.util.FileManager;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
import com.opensymphony.xwork2.validator.ActionValidatorManager;
@@ -115,9 +115,8 @@
Container container = conf.getContainer();
// huge improve cache performance
- //FileManager fileManager = container.getInstance(FileManager.class);
- //fileManager.setReloadingConfigs(false);
- FileManager.setReloadingConfigs(false);
+ FileManager fileManager = container.getInstance(FileManager.class);
+ fileManager.setReloadingConfigs(false);
ValueStackFactory stackFactory = container.getInstance(ValueStackFactory.class);
ValueStack vs = stackFactory.createValueStack();
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2012-07-17 09:06:44 UTC (rev 1016)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2012-07-17 14:03:22 UTC (rev 1017)
@@ -34,6 +34,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.i18n.I18n;
+import org.nuiton.i18n.init.ClassPathI18nInitializer;
import org.nuiton.i18n.init.DefaultI18nInitializer;
import org.nuiton.util.ArgumentsParserException;
import org.nuiton.widget.SwingSession;
@@ -104,7 +105,12 @@
public static void launch(final CoserConfig coserConfig) {
// to work in java webstart
- I18n.init(new DefaultI18nInitializer("coser-ui-i18n"), coserConfig.getLocale());
+ try {
+ I18n.init(new DefaultI18nInitializer("coser-ui-i18n"), coserConfig.getLocale());
+ } catch (RuntimeException ex) {
+ // fallback for dev mode
+ I18n.init(new ClassPathI18nInitializer(), coserConfig.getLocale());
+ }
// launch UI
SwingUtilities.invokeLater(new Runnable() {
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2012-07-17 09:06:44 UTC (rev 1016)
+++ trunk/pom.xml 2012-07-17 14:03:22 UTC (rev 1017)
@@ -117,13 +117,13 @@
<dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-utils</artifactId>
- <version>2.5.1</version>
+ <version>2.5.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.nuiton</groupId>
<artifactId>nuiton-validator</artifactId>
- <version>2.5.1</version>
+ <version>2.5.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
@@ -153,12 +153,6 @@
<artifactId>jaxx-runtime</artifactId>
<version>${jaxx.version}</version>
<scope>compile</scope>
- <exclusions>
- <exclusion>
- <artifactId>swingx-core</artifactId>
- <groupId>org.swinglabs</groupId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
@@ -173,12 +167,6 @@
<artifactId>jaxx-widgets</artifactId>
<version>${jaxx.version}</version>
<scope>compile</scope>
- <exclusions>
- <exclusion>
- <artifactId>swingx-core</artifactId>
- <groupId>org.swinglabs</groupId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
@@ -358,10 +346,10 @@
<license.organizationName>Ifremer, Codelutin</license.organizationName>
<!-- Versions -->
- <jaxx.version>2.5.1</jaxx.version>
+ <jaxx.version>2.5.2-SNAPSHOT</jaxx.version>
<i18n.version>2.4.1</i18n.version>
<!-- 2.3.1.1 fails to validate fields in jnlp -->
- <struts.version>2.3.3</struts.version>
+ <struts.version>2.3.4</struts.version>
</properties>
<scm>
1
0
r1016 - in trunk: coser-business/src/main/java/fr/ifremer/coser/services coser-business/src/test/java/fr/ifremer/coser/services coser-ui/src/main/java/fr/ifremer/coser coser-ui/src/main/java/fr/ifremer/coser/ui/control
by echatellier@users.forge.codelutin.com 17 Jul '12
by echatellier@users.forge.codelutin.com 17 Jul '12
17 Jul '12
Author: echatellier
Date: 2012-07-17 11:06:44 +0200 (Tue, 17 Jul 2012)
New Revision: 1016
Url: http://forge.codelutin.com/repositories/revision/coser/1016
Log:
Refactor service to prevent infinite loop
Added:
trunk/coser-business/src/main/java/fr/ifremer/coser/services/CommonService.java
trunk/coser-business/src/test/java/fr/ifremer/coser/services/CommonServiceTest.java
Removed:
trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java
trunk/coser-business/src/test/java/fr/ifremer/coser/services/ImportServiceTest.java
Modified:
trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java
trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java
trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java
trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java
Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/services/CommonService.java (from rev 1014, trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java)
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/CommonService.java (rev 0)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/CommonService.java 2012-07-17 09:06:44 UTC (rev 1016)
@@ -0,0 +1,532 @@
+/*
+ * #%L
+ * Coser :: Business
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 - 2012 Ifremer, Codelutin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.coser.services;
+
+import static org.nuiton.i18n.I18n._;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.util.ArrayUtil;
+
+import au.com.bytecode.opencsv.CSVReader;
+import au.com.bytecode.opencsv.CSVWriter;
+import fr.ifremer.coser.CoserBusinessConfig;
+import fr.ifremer.coser.CoserBusinessException;
+import fr.ifremer.coser.CoserConstants;
+import fr.ifremer.coser.CoserUtils;
+import fr.ifremer.coser.CoserConstants.Category;
+import fr.ifremer.coser.bean.Project;
+import fr.ifremer.coser.data.AbstractDataEntity;
+import fr.ifremer.coser.data.Catch;
+import fr.ifremer.coser.data.Haul;
+import fr.ifremer.coser.data.Length;
+import fr.ifremer.coser.data.Strata;
+import fr.ifremer.coser.storage.DataStorage;
+import fr.ifremer.coser.storage.MemoryDataStorage;
+import fr.ifremer.coser.util.ProgressMonitor;
+import fr.ifremer.coser.util.ProgressReader;
+
+/**
+ * Common methods used by others services only.
+ *
+ * <ul>
+ * <li>csv import/export</li>
+ * <li>file name management</li>
+ * <li>utilities methods</li>
+ * </ul>
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class CommonService {
+
+ protected CoserBusinessConfig config;
+
+ CommonService(CoserBusinessConfig config) {
+ this.config = config;
+ }
+
+ /**
+ * Load file as csv. Check and affect data in project depending on category type.
+ *
+ * @param project project
+ * @param category category
+ * @param file file to load
+ * @return data storage with file content
+ * @throws CoserBusinessException
+ */
+ public DataStorage loadCSVFile(Project project, Category category, File file) throws CoserBusinessException {
+ return loadCSVFile(project, category, file, null);
+ }
+
+ /**
+ * Load file as csv. Check and affect data in project depending on category type.
+ *
+ * @param project project
+ * @param category category
+ * @param file file to load
+ * @param progress progress monitor (can be null)
+ * @return data storage with file content
+ * @throws CoserBusinessException
+ */
+ public DataStorage loadCSVFile(Project project, Category category, File file, ProgressMonitor progress) throws CoserBusinessException {
+ return loadCSVFile(project, category, file, null, false);
+ }
+
+ /**
+ * Load file as csv. Check and affect data in project depending on category type.
+ *
+ * @param project project
+ * @param category category
+ * @param file file to load
+ * @param progress progress monitor (can be null)
+ * @param originalLoading dans le cas d'un reload, la colonne "line" est a prendre en compte
+ * pour les data (elle est absente dans les jeux de données originaux)
+ * @return data storage with file content
+ * @throws CoserBusinessException
+ */
+ public DataStorage loadCSVFile(Project project, Category category, File file, ProgressMonitor progress, boolean originalLoading) throws CoserBusinessException {
+
+ DataStorage content = new MemoryDataStorage();
+
+ CSVReader csvReader = null;
+ try {
+
+ InputStream stream = new FileInputStream(file);
+ Reader reader = new BufferedReader(new InputStreamReader(stream, CoserConstants.CSV_FILE_ENCODING));
+ if (progress != null) {
+ reader = new ProgressReader(reader, progress);
+ }
+ csvReader = new CSVReader(reader, CoserConstants.CSV_SEPARATOR_CHAR);
+
+ // check header
+ String[] line = csvReader.readNext();
+ if (line == null || line.length <= 1) {
+ throw new CoserBusinessException(_("Can't read file '%s'. Check CSV file separator",
+ file.getAbsolutePath()));
+ }
+ else {
+ if (originalLoading) {
+ checkFileHeader(file, category, line);
+ if (category.isDataCategory()) {
+ line = (String[])ArrayUtil.concat(new String[]{AbstractDataEntity.PROPERTY_LINE}, line);
+ }
+ }
+ content.add(line);
+ }
+
+ // pour alimenter la line index (si non reloading)
+ // dans coser, la numérotation des lignes commence à 1
+ int lineIndex = 1;
+ while ((line = csvReader.readNext()) != null) {
+ if (line.length>1) {
+ if (originalLoading && category.isDataCategory()) {
+ // ajout de la colonne "line" en debut (seulement pour les data)
+ line = (String[])ArrayUtil.concat(new String[]{String.valueOf(lineIndex)}, line);
+ lineIndex++;
+ }
+ content.add(line);
+ }
+ }
+ } catch (IOException ex) {
+ throw new CoserBusinessException("Can't read file", ex);
+ }
+ finally {
+ IOUtils.closeQuietly(csvReader);
+ }
+
+ return content;
+ }
+
+ /**
+ * Check csv file header names and order depending on file category.
+ *
+ * @param file file
+ * @param category category
+ * @param line header line to ckeck
+ * @throws CoserBusinessException
+ */
+ protected void checkFileHeader(File file, Category category, String[] line) throws CoserBusinessException {
+
+ String[] enHeaders = null;
+ String[] frHeaders = null;
+
+ switch (category) {
+ case CATCH:
+ enHeaders = Catch.EN_HEADERS;
+ frHeaders = Catch.FR_HEADERS;
+ break;
+ case HAUL:
+ enHeaders = Haul.EN_HEADERS;
+ frHeaders = Haul.FR_HEADERS;
+ break;
+ case LENGTH:
+ enHeaders = Length.EN_HEADERS;
+ frHeaders = Length.FR_HEADERS;
+ break;
+ case STRATA:
+ enHeaders = Strata.EN_HEADERS;
+ frHeaders = Strata.FR_HEADERS;
+ break;
+ case REFTAX_SPECIES:
+ enHeaders = Project.REFTAX_SPECIES_HEADER;
+ break;
+ case TYPE_ESPECES:
+ enHeaders = Project.TYPE_ESPECE_HEADER;
+ break;
+ }
+
+ if (frHeaders != null) {
+ if (!Arrays.equals(line, enHeaders) && !Arrays.equals(line, frHeaders)) {
+ throw new CoserBusinessException(_("Wrong header detected in file %s. Found : %s, expected %s or %s",
+ file.getName(),
+ StringUtils.join(line, ", "),
+ StringUtils.join(frHeaders, ", "),
+ StringUtils.join(enHeaders, ", ")));
+ }
+ }
+ else {
+ if (!Arrays.equals(line, enHeaders)) {
+ throw new CoserBusinessException(_("Wrong header detected in file %s. Found : %s, expected %s",
+ file.getName(),
+ StringUtils.join(line, ", "),
+ StringUtils.join(enHeaders, ", ")));
+ }
+ }
+ }
+
+ /**
+ * Get empty storage for category (filled with just header)
+ *
+ * @param project project
+ * @param category category
+ * @return initialized storage
+ */
+ public DataStorage getEmptyStorage(Project project, Category category) {
+
+ DataStorage dataStorage = new MemoryDataStorage();
+ switch (category) {
+ case CATCH:
+ dataStorage.add(Catch.EN_HEADERS);
+ break;
+ case HAUL:
+ dataStorage.add(Haul.EN_HEADERS);
+ break;
+ case LENGTH:
+ dataStorage.add(Length.EN_HEADERS);
+ break;
+ case STRATA:
+ dataStorage.add(Strata.EN_HEADERS);
+ break;
+ }
+
+ return dataStorage;
+ }
+
+ /**
+ * Store project category data in specified file as csv.
+ *
+ * @param content content to save
+ * @param file file to save to
+ * @throws CoserBusinessException
+ */
+ public void storeData(DataStorage content, File file) throws CoserBusinessException {
+
+ // save content
+ CSVWriter csvWriter = null;
+ try {
+ Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), CoserConstants.CSV_FILE_ENCODING));
+
+ csvWriter = new CSVWriter(writer, CoserConstants.CSV_SEPARATOR_CHAR);
+ Iterator<String[]> itContent = content.iterator();
+ while (itContent.hasNext()) {
+ csvWriter.writeNext(itContent.next());
+ }
+ } catch (IOException ex) {
+ throw new CoserBusinessException("Can't save data", ex);
+ }
+ finally {
+ IOUtils.closeQuietly(csvWriter);
+ }
+ }
+
+ /**
+ * Store data without quoting every columns with "" (r specific demand).
+ *
+ * @param content content to save
+ * @param file file to save to
+ *
+ * @throws CoserBusinessException
+ */
+ public void storeDataWhithoutQuote(DataStorage content, File file) throws CoserBusinessException {
+ // save content
+ Writer writer = null;
+ try {
+ writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), CoserConstants.CSV_FILE_ENCODING));
+
+ Iterator<String[]> itContent = content.iterator();
+ while (itContent.hasNext()) {
+ String[] contentDatas = itContent.next();
+
+ // start at 1 to not output "line" column
+ for (int i = 1 ; i < contentDatas.length ; i++) {
+
+ if (i != 1) {
+ writer.write(CoserConstants.CSV_SEPARATOR_CHAR);
+ }
+
+ String contentData = contentDatas[i];
+ if (contentData.indexOf(CoserConstants.CSV_SEPARATOR_CHAR) > -1) {
+ writer.write("\"" + contentData + "\"");
+ }
+ else {
+ writer.write(contentData);
+ }
+ }
+ writer.write("\n");
+ }
+ } catch (IOException ex) {
+ throw new CoserBusinessException("Can't save data", ex);
+ }
+ finally {
+ IOUtils.closeQuietly(writer);
+ }
+ }
+
+ /**
+ * Lit le fichier demandé et sauve dans une map les lignes demandées.
+ *
+ * @param file file to read
+ * @param lines lines to save content
+ * @return saved content
+ * @throws CoserBusinessException
+ */
+ public Map<String, String[]> getOriginalFileContent(File file, Collection<String> lines) throws CoserBusinessException {
+ Map<String, String[]> content = new HashMap<String, String[]>();
+
+ CSVReader csvReader = null;
+ try {
+
+ Reader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), CoserConstants.CSV_FILE_ENCODING));
+ csvReader = new CSVReader(reader, CoserConstants.CSV_SEPARATOR_CHAR);
+
+ // skip header
+ String[] line = csvReader.readNext();
+
+ // pour alimenter la line index (si non reloading)
+ // dans coser, la numérotation des lignes commence à 1
+ int lineIndex = 1;
+ while ((line = csvReader.readNext()) != null) {
+ String stringLine = String.valueOf(lineIndex);
+ if (lines.contains(stringLine)) {
+ content.put(stringLine, line);
+ }
+ lineIndex++;
+ }
+ }
+ catch (IOException ex) {
+ throw new CoserBusinessException("Can't read file", ex);
+ }
+ finally {
+ IOUtils.closeQuietly(csvReader);
+ }
+
+ return content;
+ }
+
+ /**
+ * Charge un fichier csv (estcomind/estpopind ...) mais sans verification.
+ * C'est a peu pret le meme code qu'au dessus, sauf que le storage est
+ * simplement retourné et que les séparateurs ne sont pas les même.
+ *
+ * @param file file to load
+ * @return data storage with file content
+ * @throws CoserBusinessException
+ */
+ public DataStorage loadCSVFile(File file) throws CoserBusinessException {
+ return loadCSVFile(file, CoserConstants.CSV_SEPARATOR_CHAR);
+ }
+
+ /**
+ * Charge un fichier csv (estcomind/estpopind ...) mais sans verification.
+ * C'est a peu pret le meme code qu'au dessus, sauf que le storage est
+ * simplement retourné et que les séparateurs ne sont pas les même.
+ *
+ * @param file file to load
+ * @param separator separator to use to load file
+ * @return data storage with file content
+ * @throws CoserBusinessException
+ */
+ public DataStorage loadCSVFile(File file, char separator) throws CoserBusinessException {
+
+ DataStorage content = new MemoryDataStorage();
+
+ CSVReader csvReader = null;
+ try {
+
+ InputStream stream = new FileInputStream(file);
+ Reader reader = new BufferedReader(new InputStreamReader(stream, CoserConstants.CSV_FILE_ENCODING));
+ csvReader = new CSVReader(reader, separator);
+
+ // check header
+ String[] line = csvReader.readNext();
+ if (line == null || line.length <= 1) {
+ throw new CoserBusinessException(_("Can't read file '%s'. Check CSV file separator",
+ file.getAbsolutePath()));
+ }
+ else {
+ content.add(line);
+ }
+
+ while ((line = csvReader.readNext()) != null) {
+ if (line.length>1) {
+ content.add(line);
+ }
+ }
+ } catch (IOException ex) {
+ throw new CoserBusinessException("Can't read file", ex);
+ }
+ finally {
+ IOUtils.closeQuietly(csvReader);
+ }
+
+ return content;
+ }
+
+ /**
+ * Retourne le nom de stockage d'un fichier de données suivant la categories
+ * de fichier demandé. Les fichiers sont stockés avec leurs noms originaux
+ * (sauf les fichiers de réference) donc il n'est pas fixe.
+ *
+ * @param project project (containing originals file names)
+ * @param category category to get file name
+ * @param suffix suffix to add into file name
+ * @return storage file name
+ */
+ protected String getDataStorageFileName(Project project, Category category, String suffix) {
+
+ String result = null;
+
+ switch (category) {
+ case CATCH:
+ result = project.getCatchFileName();
+ break;
+ case HAUL:
+ result = project.getHaulFileName();
+ break;
+ case LENGTH:
+ result = project.getLengthFileName();
+ break;
+ case STRATA:
+ result = project.getStrataFileName();
+ break;
+ }
+
+ if (suffix != null) {
+ result = CoserUtils.addSuffixBeforeExtension(result, suffix);
+ }
+
+ return result;
+ }
+
+ /**
+ * Lit tout le fichier associé à la categorie demandé, mais ne retourne
+ * que les données correspondant au numéro de lignes demandée.
+ *
+ * Le contenu retourné ne contient pas le numéro de ligne.
+ *
+ * @param project project
+ * @param category category
+ * @param lines lines to get content
+ * @return content for lines
+ * @throws CoserBusinessException
+ */
+ public Map<String, String[]> getOriginalContent(Project project, Category category, Collection<String> lines) throws CoserBusinessException {
+
+ // ne lit pas un fichier entier pour ne rien chercher
+ if (CollectionUtils.isEmpty(lines)) {
+ return new HashMap<String, String[]>();
+ }
+
+ File projectsDirectory = config.getProjectsDirectory();
+ File projectDirectory = new File(projectsDirectory, project.getName());
+ File originalDirectory = new File(projectDirectory, CoserConstants.STORAGE_ORIGINAL_DIRECTORY);
+ String storageFileName = getDataStorageFileName(project, category, null);
+ File dataFile = new File(originalDirectory, storageFileName);
+
+ Map<String, String[]> contents = getOriginalFileContent(dataFile, lines);
+
+ return contents;
+ }
+
+ /**
+ * Retourne le nom d'affichage d'une especes.
+ *
+ * @param project project
+ * @param species species code
+ * @return species display name
+ */
+ public String getSpeciesDisplayName(Project project, String species) {
+ String displayName = null;
+
+ // load reftax in memory
+ Iterator<String[]> reftax = project.getRefTaxSpecies().iterator(true);
+ while (reftax.hasNext()) {
+ String[] tuple = reftax.next();
+
+ // "C_Perm","NumSys","NivSys","C_VALIDE","L_VALIDE","AA_VALIDE","C_TxP\u00E8re","Taxa"
+ String speciesCode = tuple[3];
+ if (speciesCode.equals(species)) {
+ // nom + auteur (sans ajout de parenthese : important)
+ displayName = tuple[4] + " " + tuple[5];
+ break;
+ }
+ }
+
+ return displayName;
+ }
+}
Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java 2012-07-17 07:09:32 UTC (rev 1015)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ImportService.java 2012-07-17 09:06:44 UTC (rev 1016)
@@ -1,431 +0,0 @@
-/*
- * #%L
- * Coser :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package fr.ifremer.coser.services;
-
-import static org.nuiton.i18n.I18n._;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.nuiton.util.ArrayUtil;
-
-import au.com.bytecode.opencsv.CSVReader;
-import au.com.bytecode.opencsv.CSVWriter;
-import fr.ifremer.coser.CoserBusinessConfig;
-import fr.ifremer.coser.CoserBusinessException;
-import fr.ifremer.coser.CoserConstants;
-import fr.ifremer.coser.CoserConstants.Category;
-import fr.ifremer.coser.bean.Project;
-import fr.ifremer.coser.data.AbstractDataEntity;
-import fr.ifremer.coser.data.Catch;
-import fr.ifremer.coser.data.Haul;
-import fr.ifremer.coser.data.Length;
-import fr.ifremer.coser.data.Strata;
-import fr.ifremer.coser.storage.DataStorage;
-import fr.ifremer.coser.storage.MemoryDataStorage;
-import fr.ifremer.coser.util.ProgressMonitor;
-import fr.ifremer.coser.util.ProgressReader;
-
-/**
- * File import/export service.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class ImportService {
-
- protected CoserBusinessConfig config;
-
- public ImportService(CoserBusinessConfig config) {
- this.config = config;
- }
-
- /**
- * Load file as csv. Check and affect data in project depending on category type.
- *
- * @param project project
- * @param category category
- * @param file file to load
- * @return data storage with file content
- * @throws CoserBusinessException
- */
- public DataStorage loadCSVFile(Project project, Category category, File file) throws CoserBusinessException {
- return loadCSVFile(project, category, file, null);
- }
-
- /**
- * Load file as csv. Check and affect data in project depending on category type.
- *
- * @param project project
- * @param category category
- * @param file file to load
- * @param progress progress monitor (can be null)
- * @return data storage with file content
- * @throws CoserBusinessException
- */
- public DataStorage loadCSVFile(Project project, Category category, File file, ProgressMonitor progress) throws CoserBusinessException {
- return loadCSVFile(project, category, file, null, false);
- }
-
- /**
- * Load file as csv. Check and affect data in project depending on category type.
- *
- * @param project project
- * @param category category
- * @param file file to load
- * @param progress progress monitor (can be null)
- * @param originalLoading dans le cas d'un reload, la colonne "line" est a prendre en compte
- * pour les data (elle est absente dans les jeux de données originaux)
- * @return data storage with file content
- * @throws CoserBusinessException
- */
- public DataStorage loadCSVFile(Project project, Category category, File file, ProgressMonitor progress, boolean originalLoading) throws CoserBusinessException {
-
- DataStorage content = new MemoryDataStorage();
-
- CSVReader csvReader = null;
- try {
-
- InputStream stream = new FileInputStream(file);
- Reader reader = new BufferedReader(new InputStreamReader(stream, CoserConstants.CSV_FILE_ENCODING));
- if (progress != null) {
- reader = new ProgressReader(reader, progress);
- }
- csvReader = new CSVReader(reader, CoserConstants.CSV_SEPARATOR_CHAR);
-
- // check header
- String[] line = csvReader.readNext();
- if (line == null || line.length <= 1) {
- throw new CoserBusinessException(_("Can't read file '%s'. Check CSV file separator",
- file.getAbsolutePath()));
- }
- else {
- if (originalLoading) {
- checkFileHeader(file, category, line);
- if (category.isDataCategory()) {
- line = (String[])ArrayUtil.concat(new String[]{AbstractDataEntity.PROPERTY_LINE}, line);
- }
- }
- content.add(line);
- }
-
- // pour alimenter la line index (si non reloading)
- // dans coser, la numérotation des lignes commence à 1
- int lineIndex = 1;
- while ((line = csvReader.readNext()) != null) {
- if (line.length>1) {
- if (originalLoading && category.isDataCategory()) {
- // ajout de la colonne "line" en debut (seulement pour les data)
- line = (String[])ArrayUtil.concat(new String[]{String.valueOf(lineIndex)}, line);
- lineIndex++;
- }
- content.add(line);
- }
- }
- } catch (IOException ex) {
- throw new CoserBusinessException("Can't read file", ex);
- }
- finally {
- IOUtils.closeQuietly(csvReader);
- }
-
- return content;
- }
-
- /**
- * Check csv file header names and order depending on file category.
- *
- * @param file file
- * @param category category
- * @param line header line to ckeck
- * @throws CoserBusinessException
- */
- protected void checkFileHeader(File file, Category category, String[] line) throws CoserBusinessException {
-
- String[] enHeaders = null;
- String[] frHeaders = null;
-
- switch (category) {
- case CATCH:
- enHeaders = Catch.EN_HEADERS;
- frHeaders = Catch.FR_HEADERS;
- break;
- case HAUL:
- enHeaders = Haul.EN_HEADERS;
- frHeaders = Haul.FR_HEADERS;
- break;
- case LENGTH:
- enHeaders = Length.EN_HEADERS;
- frHeaders = Length.FR_HEADERS;
- break;
- case STRATA:
- enHeaders = Strata.EN_HEADERS;
- frHeaders = Strata.FR_HEADERS;
- break;
- case REFTAX_SPECIES:
- enHeaders = Project.REFTAX_SPECIES_HEADER;
- break;
- case TYPE_ESPECES:
- enHeaders = Project.TYPE_ESPECE_HEADER;
- break;
- }
-
- if (frHeaders != null) {
- if (!Arrays.equals(line, enHeaders) && !Arrays.equals(line, frHeaders)) {
- throw new CoserBusinessException(_("Wrong header detected in file %s. Found : %s, expected %s or %s",
- file.getName(),
- StringUtils.join(line, ", "),
- StringUtils.join(frHeaders, ", "),
- StringUtils.join(enHeaders, ", ")));
- }
- }
- else {
- if (!Arrays.equals(line, enHeaders)) {
- throw new CoserBusinessException(_("Wrong header detected in file %s. Found : %s, expected %s",
- file.getName(),
- StringUtils.join(line, ", "),
- StringUtils.join(enHeaders, ", ")));
- }
- }
- }
-
- /**
- * Get empty storage for category (filled with just header)
- *
- * @param project project
- * @param category category
- * @return initialized storage
- */
- public DataStorage getEmptyStorage(Project project, Category category) {
-
- DataStorage dataStorage = new MemoryDataStorage();
- switch (category) {
- case CATCH:
- dataStorage.add(Catch.EN_HEADERS);
- break;
- case HAUL:
- dataStorage.add(Haul.EN_HEADERS);
- break;
- case LENGTH:
- dataStorage.add(Length.EN_HEADERS);
- break;
- case STRATA:
- dataStorage.add(Strata.EN_HEADERS);
- break;
- }
-
- return dataStorage;
- }
-
- /**
- * Store project category data in specified file as csv.
- *
- * @param content content to save
- * @param file file to save to
- * @throws CoserBusinessException
- */
- public void storeData(DataStorage content, File file) throws CoserBusinessException {
-
- // save content
- CSVWriter csvWriter = null;
- try {
- Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), CoserConstants.CSV_FILE_ENCODING));
-
- csvWriter = new CSVWriter(writer, CoserConstants.CSV_SEPARATOR_CHAR);
- Iterator<String[]> itContent = content.iterator();
- while (itContent.hasNext()) {
- csvWriter.writeNext(itContent.next());
- }
- } catch (IOException ex) {
- throw new CoserBusinessException("Can't save data", ex);
- }
- finally {
- IOUtils.closeQuietly(csvWriter);
- }
- }
-
- /**
- * Store data without quoting every columns with "" (r specific demand).
- *
- * @param content content to save
- * @param file file to save to
- *
- * @throws CoserBusinessException
- */
- public void storeDataWhithoutQuote(DataStorage content, File file) throws CoserBusinessException {
- // save content
- Writer writer = null;
- try {
- writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), CoserConstants.CSV_FILE_ENCODING));
-
- Iterator<String[]> itContent = content.iterator();
- while (itContent.hasNext()) {
- String[] contentDatas = itContent.next();
-
- // start at 1 to not output "line" column
- for (int i = 1 ; i < contentDatas.length ; i++) {
-
- if (i != 1) {
- writer.write(CoserConstants.CSV_SEPARATOR_CHAR);
- }
-
- String contentData = contentDatas[i];
- if (contentData.indexOf(CoserConstants.CSV_SEPARATOR_CHAR) > -1) {
- writer.write("\"" + contentData + "\"");
- }
- else {
- writer.write(contentData);
- }
- }
- writer.write("\n");
- }
- } catch (IOException ex) {
- throw new CoserBusinessException("Can't save data", ex);
- }
- finally {
- IOUtils.closeQuietly(writer);
- }
- }
-
- /**
- * Lit le fichier demandé et sauve dans une map les lignes demandées.
- *
- * @param file file to read
- * @param lines lines to save content
- * @return saved content
- * @throws CoserBusinessException
- */
- public Map<String, String[]> getOriginalFileContent(File file, Collection<String> lines) throws CoserBusinessException {
- Map<String, String[]> content = new HashMap<String, String[]>();
-
- CSVReader csvReader = null;
- try {
-
- Reader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), CoserConstants.CSV_FILE_ENCODING));
- csvReader = new CSVReader(reader, CoserConstants.CSV_SEPARATOR_CHAR);
-
- // skip header
- String[] line = csvReader.readNext();
-
- // pour alimenter la line index (si non reloading)
- // dans coser, la numérotation des lignes commence à 1
- int lineIndex = 1;
- while ((line = csvReader.readNext()) != null) {
- String stringLine = String.valueOf(lineIndex);
- if (lines.contains(stringLine)) {
- content.put(stringLine, line);
- }
- lineIndex++;
- }
- }
- catch (IOException ex) {
- throw new CoserBusinessException("Can't read file", ex);
- }
- finally {
- IOUtils.closeQuietly(csvReader);
- }
-
- return content;
- }
-
- /**
- * Charge un fichier csv (estcomind/estpopind ...) mais sans verification.
- * C'est a peu pret le meme code qu'au dessus, sauf que le storage est
- * simplement retourné et que les séparateurs ne sont pas les même.
- *
- * @param file file to load
- * @return data storage with file content
- * @throws CoserBusinessException
- */
- public DataStorage loadCSVFile(File file) throws CoserBusinessException {
- return loadCSVFile(file, CoserConstants.CSV_SEPARATOR_CHAR);
- }
-
- /**
- * Charge un fichier csv (estcomind/estpopind ...) mais sans verification.
- * C'est a peu pret le meme code qu'au dessus, sauf que le storage est
- * simplement retourné et que les séparateurs ne sont pas les même.
- *
- * @param file file to load
- * @param separator separator to use to load file
- * @return data storage with file content
- * @throws CoserBusinessException
- */
- public DataStorage loadCSVFile(File file, char separator) throws CoserBusinessException {
-
- DataStorage content = new MemoryDataStorage();
-
- CSVReader csvReader = null;
- try {
-
- InputStream stream = new FileInputStream(file);
- Reader reader = new BufferedReader(new InputStreamReader(stream, CoserConstants.CSV_FILE_ENCODING));
- csvReader = new CSVReader(reader, separator);
-
- // check header
- String[] line = csvReader.readNext();
- if (line == null || line.length <= 1) {
- throw new CoserBusinessException(_("Can't read file '%s'. Check CSV file separator",
- file.getAbsolutePath()));
- }
- else {
- content.add(line);
- }
-
- while ((line = csvReader.readNext()) != null) {
- if (line.length>1) {
- content.add(line);
- }
- }
- } catch (IOException ex) {
- throw new CoserBusinessException("Can't read file", ex);
- }
- finally {
- IOUtils.closeQuietly(csvReader);
- }
-
- return content;
- }
-}
Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2012-07-17 07:09:32 UTC (rev 1015)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2012-07-17 09:06:44 UTC (rev 1016)
@@ -112,14 +112,17 @@
protected CoserBusinessConfig config;
- protected ImportService importService;
+ protected CommonService commonService;
protected CommandService commandService;
+ protected PublicationService publicationService;
+
public ProjectService(CoserBusinessConfig config) {
this.config = config;
- importService = new ImportService(config);
+ commonService = new CommonService(config);
commandService = new CommandService(config);
+ publicationService = new PublicationService(config);
}
/**
@@ -203,13 +206,13 @@
throw new CoserBusinessException(_("Can't read file %s for category %s", dataFile.getAbsolutePath(), _(category.getTranslationKey())));
}
- DataStorage dataStorage = importService.loadCSVFile(project, category, dataFile, progress, true);
+ DataStorage dataStorage = commonService.loadCSVFile(project, category, dataFile, progress, true);
addProjectContent(project, control, category, dataStorage, false);
// init empty deleted collection
if (category.isDataCategory()) {
// deleted data
- DataStorage dataStorage2 = importService.getEmptyStorage(project, category);
+ DataStorage dataStorage2 = commonService.getEmptyStorage(project, category);
addProjectContent(project, control, category, dataStorage2, true);
}
}
@@ -228,7 +231,7 @@
// les fichiers de donnees sont stockes dans un repertoire
// "original"
if (category.isDataCategory()) {
- String storageFileName = getDataStorageFileName(project, category, null);
+ String storageFileName = commonService.getDataStorageFileName(project, category, null);
File storageDataFile = new File(originalDirectory, storageFileName);
FileUtils.copyFile(dataFile, storageDataFile);
}
@@ -300,7 +303,7 @@
/**
* Update project maps with new maps.
*
- * Thériquement, si les deux listes sont identiques, cette methode ne fait rien.
+ * Théoriquement, si les deux listes sont identiques, cette methode ne fait rien.
*
* @param project project to update maps
* @param projectDirectory project directory
@@ -355,42 +358,6 @@
}
/**
- * Retourne le nom de stockage d'un fichier de données suivant la categories
- * de fichier demandé. Les fichiers sont stockés avec leurs noms originaux
- * (sauf les fichiers de réference) donc il n'est pas fixe.
- *
- * @param project project (containing originals file names)
- * @param category category to get file name
- * @param suffix suffix to add into file name
- * @return storage file name
- */
- protected String getDataStorageFileName(Project project, Category category, String suffix) {
-
- String result = null;
-
- switch (category) {
- case CATCH:
- result = project.getCatchFileName();
- break;
- case HAUL:
- result = project.getHaulFileName();
- break;
- case LENGTH:
- result = project.getLengthFileName();
- break;
- case STRATA:
- result = project.getStrataFileName();
- break;
- }
-
- if (suffix != null) {
- result = CoserUtils.addSuffixBeforeExtension(result, suffix);
- }
-
- return result;
- }
-
- /**
* Open project without loading data.
*
* Just load non category data (reftax).
@@ -433,7 +400,7 @@
category.getStorageFileName());
if (inputFile.isFile()) {
- DataStorage dataStorage = importService.loadCSVFile(project, category, inputFile);
+ DataStorage dataStorage = commonService.loadCSVFile(project, category, inputFile);
addProjectContent(project, null, category, dataStorage, false);
}
else {
@@ -625,11 +592,11 @@
// seulement les category de données ici
if (category.isDataCategory()) {
- String storageFileName = getDataStorageFileName(project, category, CoserConstants.STORAGE_CONTROL_SUFFIX);
+ String storageFileName = commonService.getDataStorageFileName(project, category, CoserConstants.STORAGE_CONTROL_SUFFIX);
File inputFile = new File(controlDirectory, storageFileName);
if (inputFile.isFile()) {
- DataStorage dataStorage = importService.loadCSVFile(project, category, inputFile);
+ DataStorage dataStorage = commonService.loadCSVFile(project, category, inputFile);
addProjectContent(project, control, category, dataStorage, false);
fileLoaded++;
}
@@ -640,14 +607,14 @@
}
// load deleted file if exists
- storageFileName = getDataStorageFileName(project, category, CoserConstants.STORAGE_DELECTED_SUFFIX);
+ storageFileName = commonService.getDataStorageFileName(project, category, CoserConstants.STORAGE_DELECTED_SUFFIX);
inputFile = new File(controlDirectory, storageFileName);
DataStorage dataStorage = null;
if (inputFile.isFile()) {
- dataStorage = importService.loadCSVFile(project, category, inputFile);
+ dataStorage = commonService.loadCSVFile(project, category, inputFile);
}
else {
- dataStorage = importService.getEmptyStorage(project, category);
+ dataStorage = commonService.getEmptyStorage(project, category);
if (log.isDebugEnabled()) {
log.debug("Can't find file " + inputFile);
}
@@ -662,12 +629,12 @@
for (Category category : Category.values()) {
if (category.isDataCategory()) {
- String storageFileName = getDataStorageFileName(project, category, null);
+ String storageFileName = commonService.getDataStorageFileName(project, category, null);
File storageDataFile = new File(originalDirectory, storageFileName);
// main data
if (storageDataFile.isFile()) {
- DataStorage dataStorage = importService.loadCSVFile(project, category, storageDataFile, null, true);
+ DataStorage dataStorage = commonService.loadCSVFile(project, category, storageDataFile, null, true);
addProjectContent(project, control, category, dataStorage, false);
}
else {
@@ -677,7 +644,7 @@
}
// deleted data
- DataStorage dataStorage = importService.getEmptyStorage(project, category);
+ DataStorage dataStorage = commonService.getEmptyStorage(project, category);
addProjectContent(project, control, category, dataStorage, true);
}
}
@@ -750,11 +717,11 @@
// seulement les category de données ici
if (category.isDataCategory()) {
- String storageFileName = getDataStorageFileName(project, category, CoserConstants.STORAGE_SELECTION_SUFFIX);
+ String storageFileName = commonService.getDataStorageFileName(project, category, CoserConstants.STORAGE_SELECTION_SUFFIX);
File inputFile = new File(selectionDirectory, storageFileName);
if (inputFile.isFile()) {
- DataStorage dataStorage = importService.loadCSVFile(project, category, inputFile);
+ DataStorage dataStorage = commonService.loadCSVFile(project, category, inputFile);
addProjectContent(project, selection, category, dataStorage, false);
}
else {
@@ -810,21 +777,21 @@
if (category.isDataCategory()) {
// save main content
- String storageFileName = getDataStorageFileName(project, category, CoserConstants.STORAGE_CONTROL_SUFFIX);
+ String storageFileName = commonService.getDataStorageFileName(project, category, CoserConstants.STORAGE_CONTROL_SUFFIX);
File controlFile = new File(controlDirectory, storageFileName);
if (log.isDebugEnabled()) {
log.debug("Saving control file : " + controlFile);
}
DataStorage content = getProjectContent(project, control, category, false);
- importService.storeData(content, controlFile);
+ commonService.storeData(content, controlFile);
// save deleted content (if needed)
DataStorage contentDeleted = getProjectContent(project, control, category, true);
// if more content than header
if (contentDeleted.size() > 1) {
- String deletedFileName = getDataStorageFileName(project, category, CoserConstants.STORAGE_DELECTED_SUFFIX);
+ String deletedFileName = commonService.getDataStorageFileName(project, category, CoserConstants.STORAGE_DELECTED_SUFFIX);
File deletedDataFile = new File(controlDirectory, deletedFileName);
- importService.storeData(contentDeleted, deletedDataFile);
+ commonService.storeData(contentDeleted, deletedDataFile);
}
}
}
@@ -851,7 +818,21 @@
}
}
+
+ /**
+ * Marque le controle comme valider et sauve le projet.
+ *
+ * Genère également les PDF des rapports de contrôle.
+ *
+ * @param project project to save
+ * @throws CoserBusinessException
+ */
+ public void validControl(Project project) throws CoserBusinessException {
+
+ project.getControl().setValidated(true);
+ }
+
/**
* Creer une instance de selection "non sauvegardee" avec les données
* de control (validée) du projet.
@@ -1006,14 +987,14 @@
for (Category category : Category.values()) {
if (category.isDataCategory()) {
- String storageFileName = getDataStorageFileName(project, category, CoserConstants.STORAGE_SELECTION_SUFFIX);
+ String storageFileName = commonService.getDataStorageFileName(project, category, CoserConstants.STORAGE_SELECTION_SUFFIX);
File dataFile = new File(selectionDirectory, storageFileName);
if (log.isDebugEnabled()) {
log.debug("Saving selection file : " + dataFile);
}
DataStorage content = getProjectContent(project, selection, category, false);
- importService.storeData(content, dataFile);
+ commonService.storeData(content, dataFile);
// delete data are not saved here
// can't delete data in selection
@@ -2070,33 +2051,6 @@
}
/**
- * Retourne le nom d'affichage d'une especes.
- *
- * @param project project
- * @param species species code
- * @return species display name
- */
- public String getSpeciesDisplayName(Project project, String species) {
- String displayName = null;
-
- // load reftax in memory
- Iterator<String[]> reftax = project.getRefTaxSpecies().iterator(true);
- while (reftax.hasNext()) {
- String[] tuple = reftax.next();
-
- // "C_Perm","NumSys","NivSys","C_VALIDE","L_VALIDE","AA_VALIDE","C_TxP\u00E8re","Taxa"
- String speciesCode = tuple[3];
- if (speciesCode.equals(species)) {
- // nom + auteur (sans ajout de parenthese : important)
- displayName = tuple[4] + " " + tuple[5];
- break;
- }
- }
-
- return displayName;
- }
-
- /**
* Fusion d'especes.
*
* Used un selection ui.
@@ -2753,14 +2707,14 @@
for (Category category : Category.values()) {
if (category.isDataCategory()) {
// originals names without suffix
- String storageFileName = getDataStorageFileName(project, category, null);
+ String storageFileName = commonService.getDataStorageFileName(project, category, null);
File dataFile = new File(projectDirectory, storageFileName);
if (log.isDebugEnabled()) {
log.debug("Saving selection file : " + dataFile);
}
DataStorage content = getProjectContent(project, selection, category, false);
- importService.storeDataWhithoutQuote(content, dataFile);
+ commonService.storeDataWhithoutQuote(content, dataFile);
}
}
@@ -2834,37 +2788,6 @@
}
/**
- * Lit tout le fichier associé à la categorie demandé, mais ne retourne
- * que les données correspondant au numéro de lignes demandée.
- *
- * Le contenu retourné ne contient pas le numéro de ligne.
- *
- * @param project project
- * @param category category
- * @param lines lines to get content
- * @return content for lines
- * @throws CoserBusinessException
- */
- public Map<String, String[]> getOriginalContent(Project project, Category category, Collection<String> lines) throws CoserBusinessException {
- Map<String, String[]> contents = null;
-
- // ne lit pas un fichier entier pour ne rien chercher
- if (CollectionUtils.isEmpty(lines)) {
- return new HashMap<String, String[]>();
- }
-
- File projectsDirectory = config.getProjectsDirectory();
- File projectDirectory = new File(projectsDirectory, project.getName());
- File originalDirectory = new File(projectDirectory, CoserConstants.STORAGE_ORIGINAL_DIRECTORY);
- String storageFileName = getDataStorageFileName(project, category, null);
- File dataFile = new File(originalDirectory, storageFileName);
-
- contents = importService.getOriginalFileContent(dataFile, lines);
-
- return contents;
- }
-
- /**
* Look for project survey name in rsufi result.
* Read estcomind file to known that.
* Used in webservice to know map file names.
@@ -2880,7 +2803,7 @@
// le fichier estcomind est moins gros que l'autre
String estComIndName = rSufiResult.getEstComIndName();
File estComIndFile = new File(resultDirectory, estComIndName);
- DataStorage dataStorage = importService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
// Campagne Indicateur Liste Strate Annee Estimation EcartType CV
Iterator<String[]> itEstComIndData = dataStorage.iterator(true);
while (StringUtils.isEmpty(result) && itEstComIndData.hasNext()) {
Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java 2012-07-17 07:09:32 UTC (rev 1015)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/PublicationService.java 2012-07-17 09:06:44 UTC (rev 1016)
@@ -102,14 +102,11 @@
protected CoserBusinessConfig config;
- protected ProjectService projectService;
+ protected CommonService commonService;
- protected ImportService importService;
-
public PublicationService(CoserBusinessConfig config) {
this.config = config;
- projectService = new ProjectService(config);
- importService = new ImportService(config);
+ commonService = new CommonService(config);
}
/**
@@ -554,10 +551,10 @@
out.println("<ul>");
out.println("<li>" + _("coser.business.publication.creationdate") + " : " + dateFormat.format(project.getCreationDate()));
out.println("<li>" + _("coser.business.publication.author") + " : " + project.getAuthor() + "</li>");
- out.println("<li>" + _("coser.business.publication.catchfilename") + " : " + projectService.getDataStorageFileName(project, Category.CATCH, null) + "</li>");
- out.println("<li>" + _("coser.business.publication.lengthfilename") + " : " + projectService.getDataStorageFileName(project, Category.LENGTH, null) + "</li>");
- out.println("<li>" + _("coser.business.publication.haulfilename") + " : " + projectService.getDataStorageFileName(project, Category.HAUL, null) + "</li>");
- out.println("<li>" + _("coser.business.publication.stratafilename") + " : " + projectService.getDataStorageFileName(project, Category.STRATA, null) + "</li>");
+ out.println("<li>" + _("coser.business.publication.catchfilename") + " : " + commonService.getDataStorageFileName(project, Category.CATCH, null) + "</li>");
+ out.println("<li>" + _("coser.business.publication.lengthfilename") + " : " + commonService.getDataStorageFileName(project, Category.LENGTH, null) + "</li>");
+ out.println("<li>" + _("coser.business.publication.haulfilename") + " : " + commonService.getDataStorageFileName(project, Category.HAUL, null) + "</li>");
+ out.println("<li>" + _("coser.business.publication.stratafilename") + " : " + commonService.getDataStorageFileName(project, Category.STRATA, null) + "</li>");
if (StringUtils.isNotEmpty(project.getComment())) {
out.println("<li>" + _("coser.business.publication.comment") + " : " + project.getComment() + "</li>");
}
@@ -608,10 +605,10 @@
}
// second get content for lines
- Map<String, String[]> catchContent = projectService.getOriginalContent(project, Category.CATCH, catchLines);
- Map<String, String[]> lengthContent = projectService.getOriginalContent(project, Category.LENGTH, lengthLines);
- Map<String, String[]> haulContent = projectService.getOriginalContent(project, Category.HAUL, haulLines);
- Map<String, String[]> strataContent = projectService.getOriginalContent(project, Category.STRATA, strataLines);
+ Map<String, String[]> catchContent = commonService.getOriginalContent(project, Category.CATCH, catchLines);
+ Map<String, String[]> lengthContent = commonService.getOriginalContent(project, Category.LENGTH, lengthLines);
+ Map<String, String[]> haulContent = commonService.getOriginalContent(project, Category.HAUL, haulLines);
+ Map<String, String[]> strataContent = commonService.getOriginalContent(project, Category.STRATA, strataLines);
// third, generate html report
out.println("<h2>" + _("coser.business.publication.datamodification") + "</h2>");
@@ -677,7 +674,7 @@
File estComIndFile = new File(resultDirectory, rsufiResult.getEstComIndName());
// Campagne Indicateur Liste Strate Annee Estimation EcartType CV
- DataStorage dataStorage = importService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
// indicator list to take care
// pour avoir une valeur non nulle si list est null
@@ -734,7 +731,7 @@
// ajout de la traduction de la liste d'indicateur
// les liste sont a1, T1, T2 ...
String listLetter = String.valueOf(localList.charAt(0));
- DataStorage dataStorageType = importService.loadCSVFile(codeTypeEspecesFile, CoserConstants.CSV_SEPARATOR_CHAR);
+ DataStorage dataStorageType = commonService.loadCSVFile(codeTypeEspecesFile, CoserConstants.CSV_SEPARATOR_CHAR);
Iterator<String[]> typeIterator = dataStorageType.iterator(true);
while (typeIterator.hasNext()) {
// "Types";"Commentaire";"NumSys min";"NumSys max";"Code"
@@ -854,7 +851,7 @@
File estPopIndFile = new File(resultDirectory, rsufiResult.getEstPopIndName());
// Campagne Indicateur Liste Species Strate Annee Estimation EcartType CV
- DataStorage dataStorage = importService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
int multiplicator = 1;
int minYear = Integer.MAX_VALUE;
@@ -896,7 +893,7 @@
// get graph title
String title = zoneDisplayName;
title += " - " + indicatorName;
- title += " - " + projectService.getSpeciesDisplayName(project, species);
+ title += " - " + commonService.getSpeciesDisplayName(project, species);
// generate dataset with sorted data
DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset();
@@ -988,7 +985,7 @@
File estComIndFile = new File(resultDirectory, rsufiResult.getEstComIndName());
// Campagne Indicateur Liste Strate Annee Estimation EcartType CV
- DataStorage dataStorage = importService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
DataStorage subDataStorage = new MemoryDataStorage();
Iterator<String[]> estComIndIterator = dataStorage.iterator();
// manage header
@@ -1016,7 +1013,7 @@
}
}
- importService.storeDataWhithoutQuote(subDataStorage, result);
+ commonService.storeDataWhithoutQuote(subDataStorage, result);
} catch (IOException ex) {
throw new CoserBusinessException("Can't save csv file", ex);
}
@@ -1048,7 +1045,7 @@
File estPopIndFile = new File(resultDirectory, rsufiResult.getEstPopIndName());
// Campagne Indicateur Liste Species Strate Annee Estimation EcartType CV
- DataStorage dataStorage = importService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
DataStorage subDataStorage = new MemoryDataStorage();
Iterator<String[]> estPopIndIterator = dataStorage.iterator();
// manage header
@@ -1082,7 +1079,7 @@
}
}
- importService.storeDataWhithoutQuote(subDataStorage, result);
+ commonService.storeDataWhithoutQuote(subDataStorage, result);
} catch (IOException ex) {
throw new CoserBusinessException("Can't save csv file", ex);
}
Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java
===================================================================
--- trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2012-07-17 07:09:32 UTC (rev 1015)
+++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2012-07-17 09:06:44 UTC (rev 1016)
@@ -5,7 +5,7 @@
* $Id$
* $HeadURL$
* %%
- * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric
+ * Copyright (C) 2010 - 2012 Ifremer, Codelutin, Chatellier Eric
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
@@ -101,15 +101,15 @@
/**
* Service specifique à l'interface web de visualisation et à la partie UI
- * qui sert a envouer les resultats vers l'interface web.
+ * qui sert a envoyer les resultats vers l'interface web.
*
* Ce service, contrairement aux autres a un état, les indicateurs et zones
* chargées persistent après chargement, car elle ne peuvent pas changer
* tant que l'application est en cours d'utilisation.
*
* Il faut garder à l'esprit que les projets n'ont pas forcement
- * de resultat, donc le chargement du projet est possible, mais
- * pas les données de controle et les données de selection (dont plutot
+ * de données publiées, donc le chargement du projet est possible, mais
+ * pas les données de controle et les données de selection (donc plutot
* travailler sur les fichiers estcomind/estpopind que sur les 4 tables).
*
* @author chatellier
@@ -124,7 +124,7 @@
protected CoserBusinessConfig config;
- protected ImportService importService;
+ protected CommonService commonService;
protected ProjectService projectService;
@@ -142,7 +142,7 @@
public WebService(CoserBusinessConfig config) {
this.config = config;
- importService = new ImportService(config);
+ commonService = new CommonService(config);
projectService = new ProjectService(config);
publicationService = new PublicationService(config);
@@ -172,7 +172,7 @@
if (indicatorsMap == null) {
indicatorsMap = new MultiKeyMap();
File indicatorsFile = config.getWebIndicatorsFile();
- DataStorage indicatorsStorage = importService.loadCSVFile(indicatorsFile);
+ DataStorage indicatorsStorage = commonService.loadCSVFile(indicatorsFile);
Iterator<String[]> iteratorInd = indicatorsStorage.iterator(true);
while (iteratorInd.hasNext()) {
// "id";"label_fr";"label_en";"unit"
@@ -201,7 +201,7 @@
// l'operation n'est pas obligatoire pour tous les clients
// lourd, le fichier peut donc ne pas exister
if (zoneFile.isFile()) {
- zonesMap = importService.loadCSVFile(zoneFile);
+ zonesMap = commonService.loadCSVFile(zoneFile);
}
else {
// fait volontairement un return new, n'affecte pas l'etat du
@@ -639,7 +639,7 @@
// (les noms de fichiers sont personnalisables)
for (Category category : Category.values()) {
if (category.isDataCategory()) {
- String sourceFileName = projectService.getDataStorageFileName(project, category, null);
+ String sourceFileName = commonService.getDataStorageFileName(project, category, null);
Matcher matcher = CoserUtils.FILENAME_SUFFIX_PATTERN.matcher(sourceFileName);
if (matcher.matches()) {
result &= !(fileName.startsWith(matcher.group(1)) && fileName.endsWith(matcher.group(2)));
@@ -1406,7 +1406,7 @@
File estPopIndFile = new File(resultDirectory, rsufiResult.getEstPopIndName());
// Campagne Indicateur Liste Espece Strate Annee Estimation EcartType CV
- DataStorage dataStorage = importService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
Iterator<String[]> estPopIndIterator = dataStorage.iterator(true);
while (estPopIndIterator.hasNext()) {
@@ -1506,7 +1506,7 @@
File estPopIndFile = new File(resultDirectory, rsufiResult.getEstPopIndName());
// Campagne Indicateur Liste Espece Strate Annee Estimation EcartType CV
- DataStorage dataStorage = importService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estPopIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
Iterator<String[]> estPopIndIterator = dataStorage.iterator(true);
while (estPopIndIterator.hasNext()) {
@@ -1547,7 +1547,7 @@
File estComIndFile = new File(resultDirectory, rsufiResult.getEstComIndName());
// Campagne Indicateur Liste Strate Annee Estimation EcartType CV
- DataStorage dataStorage = importService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
Iterator<String[]> estPopIndIterator = dataStorage.iterator(true);
while (estPopIndIterator.hasNext()) {
@@ -1645,8 +1645,8 @@
File estComIndFile = new File(resultDirectory, rsufiResult.getEstComIndName());
// Campagne Indicateur Liste Strate Annee Estimation EcartType CV
- DataStorage dataStorage = importService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
- DataStorage dataStorageType = importService.loadCSVFile(codeTypeEspecesFile, CoserConstants.CSV_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorageType = commonService.loadCSVFile(codeTypeEspecesFile, CoserConstants.CSV_SEPARATOR_CHAR);
Iterator<String[]> estPopIndIterator = dataStorage.iterator(true);
while (estPopIndIterator.hasNext()) {
@@ -2269,7 +2269,7 @@
Map<String, SortedSet<String>> speciesMap = new HashMap<String, SortedSet<String>>();
// Campagne Indicateur Liste Strate Annee Estimation EcartType CV
- DataStorage dataStorage = importService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
+ DataStorage dataStorage = commonService.loadCSVFile(estComIndFile, CoserConstants.CSV_RESULT_SEPARATOR_CHAR);
Iterator<String[]> estComIndIterator = dataStorage.iterator(true);
while (estComIndIterator.hasNext()) {
String[] tuple = estComIndIterator.next();
Copied: trunk/coser-business/src/test/java/fr/ifremer/coser/services/CommonServiceTest.java (from rev 1014, trunk/coser-business/src/test/java/fr/ifremer/coser/services/ImportServiceTest.java)
===================================================================
--- trunk/coser-business/src/test/java/fr/ifremer/coser/services/CommonServiceTest.java (rev 0)
+++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/CommonServiceTest.java 2012-07-17 09:06:44 UTC (rev 1016)
@@ -0,0 +1,82 @@
+/*
+ * #%L
+ *
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2010 - 2012 Ifremer, Codelutin, Chatellier Eric
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+package fr.ifremer.coser.services;
+
+import java.io.File;
+import java.net.URL;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import fr.ifremer.coser.CoserBusinessException;
+import fr.ifremer.coser.CoserConstants.Category;
+import fr.ifremer.coser.bean.Project;
+
+/**
+ * Project service tests.
+ *
+ * @author chatellier
+ * @version $Revision$
+ *
+ * Last update : $Date$
+ * By : $Author$
+ */
+public class CommonServiceTest extends CoserTestAbstract {
+
+ protected CommonService service;
+
+ @Before
+ public void initService() {
+ service = new CommonService(config);
+ }
+
+ @Test(expected=CoserBusinessException.class)
+ public void testWrongSeparator() throws CoserBusinessException {
+ Project p = new Project();
+
+ URL url = CommonServiceTest.class.getResource("/csv/badformat/capturesbadseparator.csv");
+ File file = new File(url.getFile());
+ service.loadCSVFile(p, Category.CATCH, file, null, true);
+ }
+
+ @Test(expected=CoserBusinessException.class)
+ public void testBadHeaderName() throws CoserBusinessException {
+ Project p = new Project();
+
+ URL url = CommonServiceTest.class.getResource("/csv/badformat/stratesheadername.csv");
+ File file = new File(url.getFile());
+ service.loadCSVFile(p, Category.STRATA, file, null, true);
+ }
+
+ @Test(expected=CoserBusinessException.class)
+ public void testBadHeaderOrder() throws CoserBusinessException {
+ Project p = new Project();
+
+ URL url = CommonServiceTest.class.getResource("/csv/badformat/traitsheaderorder.csv");
+ File file = new File(url.getFile());
+ service.loadCSVFile(p, Category.HAUL, file, null, true);
+ }
+}
Deleted: trunk/coser-business/src/test/java/fr/ifremer/coser/services/ImportServiceTest.java
===================================================================
--- trunk/coser-business/src/test/java/fr/ifremer/coser/services/ImportServiceTest.java 2012-07-17 07:09:32 UTC (rev 1015)
+++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/ImportServiceTest.java 2012-07-17 09:06:44 UTC (rev 1016)
@@ -1,82 +0,0 @@
-/*
- * #%L
- *
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2010 Ifremer, Codelutin, Chatellier Eric
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * #L%
- */
-
-package fr.ifremer.coser.services;
-
-import java.io.File;
-import java.net.URL;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import fr.ifremer.coser.CoserBusinessException;
-import fr.ifremer.coser.CoserConstants.Category;
-import fr.ifremer.coser.bean.Project;
-
-/**
- * Project service tests.
- *
- * @author chatellier
- * @version $Revision$
- *
- * Last update : $Date$
- * By : $Author$
- */
-public class ImportServiceTest extends CoserTestAbstract {
-
- protected ImportService service;
-
- @Before
- public void initService() {
- service = new ImportService(config);
- }
-
- @Test(expected=CoserBusinessException.class)
- public void testWrongSeparator() throws CoserBusinessException {
- Project p = new Project();
-
- URL url = ImportServiceTest.class.getResource("/csv/badformat/capturesbadseparator.csv");
- File file = new File(url.getFile());
- service.loadCSVFile(p, Category.CATCH, file, null, true);
- }
-
- @Test(expected=CoserBusinessException.class)
- public void testBadHeaderName() throws CoserBusinessException {
- Project p = new Project();
-
- URL url = ImportServiceTest.class.getResource("/csv/badformat/stratesheadername.csv");
- File file = new File(url.getFile());
- service.loadCSVFile(p, Category.STRATA, file, null, true);
- }
-
- @Test(expected=CoserBusinessException.class)
- public void testBadHeaderOrder() throws CoserBusinessException {
- Project p = new Project();
-
- URL url = ImportServiceTest.class.getResource("/csv/badformat/traitsheaderorder.csv");
- File file = new File(url.getFile());
- service.loadCSVFile(p, Category.HAUL, file, null, true);
- }
-}
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2012-07-17 07:09:32 UTC (rev 1015)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2012-07-17 09:06:44 UTC (rev 1016)
@@ -42,7 +42,7 @@
import fr.ifremer.coser.services.CommandService;
import fr.ifremer.coser.services.ControlService;
-import fr.ifremer.coser.services.ImportService;
+import fr.ifremer.coser.services.CommonService;
import fr.ifremer.coser.services.ProjectService;
import fr.ifremer.coser.services.PublicationService;
import fr.ifremer.coser.services.WebService;
@@ -146,7 +146,6 @@
context.setContextValue(coserConfig);
context.setContextValue(session);
context.setContextValue(new ProjectService(coserConfig));
- context.setContextValue(new ImportService(coserConfig));
context.setContextValue(new CommandService(coserConfig));
context.setContextValue(new ControlService(coserConfig));
context.setContextValue(new PublicationService(coserConfig));
Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java
===================================================================
--- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2012-07-17 07:09:32 UTC (rev 1015)
+++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2012-07-17 09:06:44 UTC (rev 1016)
@@ -1069,10 +1069,16 @@
*/
public void validControl(ControlView view) {
Project project = view.getContextValue(Project.class);
- project.getControl().setValidated(true);
- saveProjectControl(view);
- JOptionPane.showMessageDialog(view, _("coser.ui.control.controlValidated"),
- _("coser.ui.control.controlTitle"), JOptionPane.INFORMATION_MESSAGE);
+ ProjectService service = view.getContextValue(ProjectService.class);
+
+ try {
+ service.validControl(project);
+ saveProjectControl(view);
+ JOptionPane.showMessageDialog(view, _("coser.ui.control.controlValidated"),
+ _("coser.ui.control.controlTitle"), JOptionPane.INFORMATION_MESSAGE);
+ } catch (CoserBusinessException ex) {
+ throw new CoserException("Can't generate html report", ex);
+ }
}
/**
1
0