Author: tchemit Date: 2014-03-19 11:54:43 +0100 (Wed, 19 Mar 2014) New Revision: 1158 Url: http://forge.codelutin.com/projects/coser/repository/revisions/1158 Log: fixes #4690 : Pouvoir s?\195?\169lectionner les r?\195?\169sultats echobase et les publier depuis le client Added: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/GlobalResult.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/CopyRepositoryCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetResultNameCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetResultNameCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CopyRepositoryRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetResultNameRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ClientResultService.java trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/ trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/MultipleFileFilter.java trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneEchobaseFileFilter.java trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneRSufiResultFileFilter.java trunk/coser-business/src/test/resources/web/echobaseprojects/project1/project.echobase trunk/coser-business/src/test/resources/web/echobaseprojects/project2/project.echobase trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/ExportUploadDialog.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultTableModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultZoneRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/SelectUploadResultView.jaxx Removed: trunk/coser-business/src/test/resources/web/echobaseprojects/project1/project.properties trunk/coser-business/src/test/resources/web/echobaseprojects/project2/project.properties Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserUtils.java trunk/coser-business/src/main/java/fr/ifremer/coser/bean/EchoBaseProject.java trunk/coser-business/src/main/java/fr/ifremer/coser/bean/IndicatorMap.java trunk/coser-business/src/main/java/fr/ifremer/coser/bean/RSufiResultPath.java trunk/coser-business/src/main/java/fr/ifremer/coser/bean/SpeciesListMap.java trunk/coser-business/src/main/java/fr/ifremer/coser/bean/SpeciesMap.java trunk/coser-business/src/main/java/fr/ifremer/coser/bean/ZoneMap.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryType.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryType.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java trunk/coser-business/src/main/java/fr/ifremer/coser/storage/DataStorage.java trunk/coser-business/src/main/java/fr/ifremer/coser/storage/MemoryDataStorage.java trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ExportUploadDialog.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultTableRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultTableModel.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultZoneRenderer.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectUploadResultView.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionEditResultDialog.jaxx trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxModel.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserUtils.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/CoserUtils.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/CoserUtils.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -22,6 +22,18 @@ package fr.ifremer.coser; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.util.FileUtil; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.File; +import java.io.FileFilter; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; @@ -37,23 +49,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.commons.lang3.StringUtils; -import org.w3c.dom.Document; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - /** * Coser utility class. - * + * * @author chatellier * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ + * <p/> + * Last update : $Date$ + * By : $Author$ */ public class CoserUtils { @@ -66,13 +69,13 @@ * Converti une collection de string en une string * delimité par les () pour pouvoir être facilement relu par * {@link #splitWithBrackets(String, char)} - * + * * @param args * @return string */ public static String convertBracketString(List<String> args) { StringBuffer buffer = new StringBuffer(); - + Iterator<String> itArgs = args.iterator(); while (itArgs.hasNext()) { buffer.append('('); @@ -93,15 +96,15 @@ /** * Split line counting opened ( and ) and take care about escaped \\). - * - * @param str string to parse + * + * @param str string to parse * @param separator to take care * @return string splited */ protected static List<String> splitWithBrackets(String str, char separator) { List<String> result = new ArrayList<String>(); - + StringBuffer op = new StringBuffer(); // stack of {([< currently open int opened = 0; boolean escapeNext = false; @@ -111,8 +114,7 @@ if (escapeNext) { op.append(c); escapeNext = false; - } - else if (c == '\\') { + } else if (c == '\\') { escapeNext = true; } else if (c == '(') { op.append(c); @@ -124,15 +126,14 @@ if (opened == 0) { result.add(op.toString()); op = new StringBuffer(); - } - else { + } else { op.append(c); } } else { op.append(c); } } - + if (op.length() > 0) { result.add(op.toString()); } @@ -142,7 +143,7 @@ /** * Parse la string avec les gestions des () en les supprimant. - * + * * @param argsString string to parse * @return parse list */ @@ -169,12 +170,12 @@ /** * Dans un nom de fichier, ajoute un suffix dans le nom du fichier * juste avant l'extension. - * + * <p/> * Exemple : - * captures.csv > captures_co.csv (ajout du suffix _co) - * captures > captures_co (si pas d'extension) - * - * @param str nom du fichier + * captures.csv > captures_co.csv (ajout du suffix _co) + * captures > captures_co (si pas d'extension) + * + * @param str nom du fichier * @param suffix suffix a ajouter * @return nouveau nom du fichier */ @@ -183,8 +184,7 @@ Matcher matcher = FILENAME_SUFFIX_PATTERN.matcher(str); if (matcher.matches()) { result = matcher.group(1) + suffix + matcher.group(2); - } - else { + } else { result = str + suffix; } return result; @@ -192,7 +192,7 @@ /** * Split string as string list using "," separator. - * + * * @param str string to split * @return string list */ @@ -204,10 +204,10 @@ /** * Convert string to {@link Document}. - * + * * @param content content * @return document - * @throws IOException + * @throws IOException */ public static Document parseDocument(String content) throws IOException { Document result = null; @@ -226,15 +226,15 @@ /** * Sort a map by value. * See http://stackoverflow.com/a/2581754/1165234 - * + * * @param map map to sort * @return sorted map */ public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortByValue(Map<K, V> map) { List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet()); - Collections.sort( list, new Comparator<Map.Entry<K, V>>() { - public int compare( Map.Entry<K, V> o1, Map.Entry<K, V> o2 ) { - return (o1.getValue()).compareTo( o2.getValue() ); + Collections.sort(list, new Comparator<Map.Entry<K, V>>() { + public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { + return (o1.getValue()).compareTo(o2.getValue()); } }); LinkedHashMap<K, V> result = new LinkedHashMap<K, V>(); @@ -246,8 +246,8 @@ /** * Sort a collection with order defined by a LinkedHashMap keySet. - * - * @param map map containing order in keys + * + * @param map map containing order in keys * @param list list to sort * @return list sorted */ @@ -256,4 +256,32 @@ keys.retainAll(list); return keys; } + + /** + * N'utilise pas la methode de commons-fileutils, car lorsqu'un répertoire + * est refusé, il ne descend pas dans les sous répertoire alors que dans + * notre cas il le faut. + * + * @param srcDir source directory to copy + * @param destDir destination directory + * @param fileFilter file filter for file to copy + * @throws IOException + */ + public static void customCopyDirectory(File srcDir, + File destDir, + FileFilter fileFilter) throws IOException { + List<File> files = FileUtil.getFilteredElements(srcDir, null, true); + for (File file : files) { + if (fileFilter.accept(file)) { + String path = file.getPath().substring(srcDir.getPath().length()); + + File destFile = new File(destDir, path); + if (file.isDirectory()) { + FileUtils.forceMkdir(destFile); + } else { + FileUtils.copyFile(file, destFile); + } + } + } + } } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/EchoBaseProject.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/EchoBaseProject.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/EchoBaseProject.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -24,6 +24,7 @@ import com.google.common.base.Charsets; import com.google.common.base.Function; +import com.google.common.base.Preconditions; import com.google.common.io.Files; import org.apache.commons.io.IOUtils; import org.apache.commons.io.filefilter.RegexFileFilter; @@ -50,7 +51,7 @@ private static final long serialVersionUID = 1L; - public static final String METADATA_FILE = "project.properties"; + public static final String METADATA_FILE = "project.echobase"; /** * Base directory of the project. @@ -73,6 +74,7 @@ protected boolean publiableResult; public EchoBaseProject(File basedir) { + Preconditions.checkNotNull(basedir); this.basedir = basedir; } @@ -196,6 +198,19 @@ } } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof EchoBaseProject)) return false; + EchoBaseProject that = (EchoBaseProject) o; + return basedir.equals(that.basedir); + } + + @Override + public int hashCode() { + return basedir.hashCode(); + } + protected File getMetaDataFile() { return new File(basedir, METADATA_FILE); } Added: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/GlobalResult.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/GlobalResult.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/GlobalResult.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,166 @@ +package fr.ifremer.coser.bean; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin + * %% + * 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% + */ + +import com.google.common.base.Preconditions; + +import java.io.File; +import java.io.Serializable; +import java.util.Date; + +/** + * To box a rsufi result, or a echobase result. + * + * TODO Should use the result request API instead, but no more time for this. + * + * Created on 3/17/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GlobalResult implements Serializable { + + private static final long serialVersionUID = 1L; + + protected final RSufiResultPath rsufiProject; + + protected final EchoBaseProject echobaseProject; + + public GlobalResult(RSufiResultPath result) { + Preconditions.checkNotNull(result); + this.rsufiProject = result; + this.echobaseProject = null; + } + + public GlobalResult(EchoBaseProject echoBaseProject) { + Preconditions.checkNotNull(echoBaseProject); + this.echobaseProject = echoBaseProject; + this.rsufiProject = null; + } + + public static boolean isRsufiProject(File projectDirectory) { + boolean result = projectDirectory.isDirectory(); + if (result) { + File file = new File(projectDirectory, EchoBaseProject.METADATA_FILE); + result = file.exists() && file.isFile(); + } + return result; + } + + public static boolean isEchobaseProject(File projectDirectory) { + boolean result = projectDirectory.isDirectory(); + if (result) { + File file = new File(projectDirectory, EchoBaseProject.METADATA_FILE); + result = file.exists() && file.isFile(); + } + return result; + } + + public boolean isRsufi() { + return rsufiProject != null; + } + + public boolean isEchoBase() { + return echobaseProject != null; + } + + public Date getCreationDate() { + Date result; + if (isRsufi()) { + result = rsufiProject.getRsufiResult().getCreationDate(); + } else { + result = echobaseProject.getCreationDate(); + } + return result; + } + + public String getZone() { + String result; + if (isRsufi()) { + result = rsufiProject.getRsufiResult().getZone(); + } else { + result = echobaseProject.getZoneName(); + } + return result; + } + + public RSufiResultPath getRsufiProject() { + return rsufiProject; + } + + public EchoBaseProject getEchobaseProject() { + return echobaseProject; + } + + public boolean isPubliableResult() { + return isRsufi() ? rsufiProject.getRsufiResult().isPubliableResult() : echobaseProject.isPubliableResult(); + } + + public boolean isIndicatorsResult() { + return !isRsufi() || rsufiProject.getRsufiResult().isPubliableResult(); + } + + public void setIndicatorsResult(boolean indicatorsResult) { + if (isRsufi()) { + rsufiProject.getRsufiResult().setIndicatorsResult(indicatorsResult); + } + } + + public boolean isMapsResult() { + return !isRsufi() || rsufiProject.getRsufiResult().isMapsResult(); + } + + public void setMapsResult(boolean mapsResult) { + if (isRsufi()) { + rsufiProject.getRsufiResult().setMapsResult(mapsResult); + } + } + + public boolean isDataAllowed() { + return !isRsufi() || rsufiProject.getRsufiResult().isDataAllowed(); + } + + public void setDataAllowed(boolean dataAllowed) { + if (isRsufi()) { + rsufiProject.getRsufiResult().setDataAllowed(dataAllowed); + } + } + + @Override + public int hashCode() { + return isRsufi() ? rsufiProject.hashCode() : echobaseProject.hashCode(); + } + + @Override + public boolean equals(Object obj) { + boolean result = obj instanceof GlobalResult && + (isRsufi() ? rsufiProject.equals(obj) : echobaseProject.equals(obj)); + return result; + } + + public String getName() { + return isRsufi() ? String.format("%s/%s/%s", rsufiProject.getProject().getName(), + rsufiProject.getSelection().getName(), + rsufiProject.getRsufiResult().getName()) : echobaseProject.getName(); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/GlobalResult.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/IndicatorMap.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/IndicatorMap.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/IndicatorMap.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory; import java.io.File; +import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.Locale; @@ -47,8 +48,10 @@ * @author Tony Chemit <chemit@codelutin.com> * @since 1.5 */ -public class IndicatorMap { +public class IndicatorMap implements Serializable { + private static final long serialVersionUID = 1L; + /** Logger. */ private static final Log log = LogFactory.getLog(IndicatorMap.class); Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/RSufiResultPath.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/RSufiResultPath.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/RSufiResultPath.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -22,24 +22,30 @@ package fr.ifremer.coser.bean; +import com.google.common.base.Preconditions; + +import java.io.Serializable; + /** * Object utilitaire represantant un path vers un résultat (projet / selection * / rsufiresult) utilisé par l'interface d'admin et l'upload de resultat * vers l'interface web. - * + * <p/> * L'egalité et le hashcode sont basé sur les {@link Project#name}, * {@link Selection#name}, et {@link RSufiResult#name}. - * + * <p/> * Les attribut sont finaux car le hashcode est basé dessus. - * + * * @author chatellier * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ + * <p/> + * Last update : $Date$ + * By : $Author$ */ -public class RSufiResultPath { +public class RSufiResultPath implements Serializable { + private static final long serialVersionUID = 1L; + /** Final project. */ protected final Project project; @@ -51,12 +57,15 @@ /** * Constructor with full path. - * - * @param project project (can't be null) - * @param selection selection (can't be null) + * + * @param project project (can't be null) + * @param selection selection (can't be null) * @param rsufiResult rsufiresult (can't be null) */ public RSufiResultPath(Project project, Selection selection, RSufiResult rsufiResult) { + Preconditions.checkNotNull(project); + Preconditions.checkNotNull(selection); + Preconditions.checkNotNull(rsufiResult); this.project = project; this.selection = selection; this.rsufiResult = rsufiResult; @@ -64,7 +73,7 @@ /** * Get project. - * + * * @return project */ public Project getProject() { @@ -73,7 +82,7 @@ /** * Get selection. - * + * * @return selection */ public Selection getSelection() { @@ -82,7 +91,7 @@ /** * Get result. - * + * * @return result */ public RSufiResult getRsufiResult() { @@ -104,7 +113,7 @@ if (!(obj instanceof RSufiResultPath)) { result = false; } else { - RSufiResultPath other = (RSufiResultPath)obj; + RSufiResultPath other = (RSufiResultPath) obj; result &= project.getName().equals(other.project.getName()); result &= selection.getName().equals(other.selection.getName()); result &= rsufiResult.getName().equals(other.rsufiResult.getName()); Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/SpeciesListMap.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/SpeciesListMap.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/SpeciesListMap.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -31,6 +31,7 @@ import org.nuiton.i18n.I18n; import java.io.File; +import java.io.Serializable; import java.util.Collection; import java.util.Iterator; import java.util.Locale; @@ -42,8 +43,10 @@ * @author Tony Chemit <chemit@codelutin.com> * @since 1.5 */ -public class SpeciesListMap { +public class SpeciesListMap implements Serializable { + private static final long serialVersionUID = 1L; + /** * Species' list storage. */ Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/SpeciesMap.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/SpeciesMap.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/SpeciesMap.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils; import java.io.File; +import java.io.Serializable; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -39,8 +40,10 @@ * @author Tony Chemit <chemit@codelutin.com> * @since 1.5 */ -public class SpeciesMap { +public class SpeciesMap implements Serializable { + private static final long serialVersionUID = 1L; + /** * Species' storage. */ Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/ZoneMap.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/ZoneMap.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/ZoneMap.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -29,6 +29,7 @@ import fr.ifremer.coser.storage.MemoryDataStorage; import java.io.File; +import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -45,8 +46,10 @@ * @author Tony Chemit <chemit@codelutin.com> * @since 1.5 */ -public class ZoneMap { +public class ZoneMap implements Serializable{ + private static final long serialVersionUID = 1L; + protected final DataStorage storage; public ZoneMap(File zonesFile) { Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryType.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryType.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryType.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -24,10 +24,11 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import fr.ifremer.coser.result.CoserCommand; import fr.ifremer.coser.result.CoserRequest; import fr.ifremer.coser.result.ResultType; -import fr.ifremer.coser.result.CoserCommand; import fr.ifremer.coser.result.repository.ResultRepositoryType; +import fr.ifremer.coser.result.repository.echobase.command.CopyRepositoryCommand; import fr.ifremer.coser.result.repository.echobase.command.DeleteResultsCommand; import fr.ifremer.coser.result.repository.echobase.command.ExtractRawDataAndResultsCommand; import fr.ifremer.coser.result.repository.echobase.command.ExtractRawDataCommand; @@ -40,6 +41,7 @@ import fr.ifremer.coser.result.repository.echobase.command.GetMapResultCommand; import fr.ifremer.coser.result.repository.echobase.command.GetPopulationIndicatorResultDataCommand; import fr.ifremer.coser.result.repository.echobase.command.GetPopulationIndicatorResultGraphCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetResultNameCommand; import fr.ifremer.coser.result.repository.echobase.command.GetSpeciesForExtractRawDataAndResultsCommand; import fr.ifremer.coser.result.repository.echobase.command.GetSpeciesForMapResultCommand; import fr.ifremer.coser.result.repository.echobase.command.GetSpeciesForPopulationIndicatorResultCommand; @@ -49,6 +51,7 @@ import fr.ifremer.coser.result.repository.echobase.command.GetZonesForExtractRawDataCommand; import fr.ifremer.coser.result.repository.echobase.command.GetZonesForMapResultCommand; import fr.ifremer.coser.result.repository.echobase.command.GetZonesForPopulationIndicatorResultCommand; +import fr.ifremer.coser.result.request.CopyRepositoryRequest; import fr.ifremer.coser.result.request.DeleteResultsRequest; import fr.ifremer.coser.result.request.ExtractRawDataAndResultsRequest; import fr.ifremer.coser.result.request.ExtractRawDataRequest; @@ -61,6 +64,7 @@ import fr.ifremer.coser.result.request.GetMapResultRequest; import fr.ifremer.coser.result.request.GetPopulationIndicatorResultDataRequest; import fr.ifremer.coser.result.request.GetPopulationIndicatorResultGraphRequest; +import fr.ifremer.coser.result.request.GetResultNameRequest; import fr.ifremer.coser.result.request.GetSpeciesForExtractRawDataAndResultsRequest; import fr.ifremer.coser.result.request.GetSpeciesForMapResultRequest; import fr.ifremer.coser.result.request.GetSpeciesForPopulationIndicatorResultRequest; @@ -146,6 +150,10 @@ // delete results result.put(DeleteResultsRequest.class, DeleteResultsCommand.class); + + // add results + result.put(GetResultNameRequest.class, GetResultNameCommand.class); + result.put(CopyRepositoryRequest.class, CopyRepositoryCommand.class); return result; } Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/CopyRepositoryCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/CopyRepositoryCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/CopyRepositoryCommand.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,58 @@ +package fr.ifremer.coser.result.repository.echobase.command; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * 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% + */ + +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.CoserUtils; +import fr.ifremer.coser.result.request.CopyRepositoryRequest; +import fr.ifremer.coser.result.result.VoidResult; +import org.apache.commons.io.filefilter.FileFilterUtils; + +import java.io.File; +import java.io.IOException; + +/** + * Created on 3/18/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class CopyRepositoryCommand extends AbstractEchoBaseCommand<CopyRepositoryRequest> { + + @Override + public boolean accept(CopyRepositoryRequest request) { + return repository.matchZone(request); + } + + @Override + public VoidResult execute(CopyRepositoryRequest request) { + File basedir = repository.getBasedir(); + File targetDirectory = request.getTargetDirectory(); + try { + CoserUtils.customCopyDirectory(basedir, targetDirectory, FileFilterUtils.trueFileFilter()); + } catch (IOException e) { + throw new CoserTechnicalException("Could not copy files", e); + } + return newVoidResult(); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/CopyRepositoryCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetResultNameCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetResultNameCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetResultNameCommand.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,52 @@ +package fr.ifremer.coser.result.repository.echobase.command; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * 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% + */ + +import com.google.common.collect.Maps; +import fr.ifremer.coser.result.request.GetResultNameRequest; +import fr.ifremer.coser.result.result.MapResult; + +import java.util.Map; + +/** + * Created on 3/18/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetResultNameCommand extends AbstractEchoBaseCommand<GetResultNameRequest> { + + @Override + public boolean accept(GetResultNameRequest request) { + return repository.matchExtractTypeList(request); + } + + @Override + public MapResult execute(GetResultNameRequest request) { + String zoneId = repository.getZone(); + String resultname = repository.getProjectName(); + Map<String, String> map = Maps.newHashMap(); + map.put(zoneId, resultname); + return newMapResult(map); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetResultNameCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryType.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryType.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryType.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -24,9 +24,9 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import fr.ifremer.coser.result.CoserCommand; import fr.ifremer.coser.result.CoserRequest; import fr.ifremer.coser.result.ResultType; -import fr.ifremer.coser.result.CoserCommand; import fr.ifremer.coser.result.repository.ResultRepositoryType; import fr.ifremer.coser.result.repository.legacy.command.DeleteResultsCommand; import fr.ifremer.coser.result.repository.legacy.command.ExtractRawDataAndResultsCommand; @@ -40,6 +40,7 @@ import fr.ifremer.coser.result.repository.legacy.command.GetMapResultCommand; import fr.ifremer.coser.result.repository.legacy.command.GetPopulationIndicatorResultDataCommand; import fr.ifremer.coser.result.repository.legacy.command.GetPopulationIndicatorResultGraphCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetResultNameCommand; import fr.ifremer.coser.result.repository.legacy.command.GetSpeciesForExtractRawDataAndResultsCommand; import fr.ifremer.coser.result.repository.legacy.command.GetSpeciesForMapResultCommand; import fr.ifremer.coser.result.repository.legacy.command.GetSpeciesForPopulationIndicatorResultCommand; @@ -61,6 +62,7 @@ import fr.ifremer.coser.result.request.GetMapResultRequest; import fr.ifremer.coser.result.request.GetPopulationIndicatorResultDataRequest; import fr.ifremer.coser.result.request.GetPopulationIndicatorResultGraphRequest; +import fr.ifremer.coser.result.request.GetResultNameRequest; import fr.ifremer.coser.result.request.GetSpeciesForExtractRawDataAndResultsRequest; import fr.ifremer.coser.result.request.GetSpeciesForMapResultRequest; import fr.ifremer.coser.result.request.GetSpeciesForPopulationIndicatorResultRequest; @@ -149,6 +151,10 @@ // delete results result.put(DeleteResultsRequest.class, DeleteResultsCommand.class); + + // add results + result.put(GetResultNameRequest.class, GetResultNameCommand.class); + return result; } } Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetResultNameCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetResultNameCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetResultNameCommand.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,54 @@ +package fr.ifremer.coser.result.repository.legacy.command; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * 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% + */ + +import com.google.common.collect.Maps; +import fr.ifremer.coser.result.request.GetResultNameRequest; +import fr.ifremer.coser.result.result.MapResult; + +import java.util.Map; + +/** + * Created on 3/18/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetResultNameCommand extends AbstractLegacyCommand<GetResultNameRequest> { + + @Override + public boolean accept(GetResultNameRequest request) { + return repository.matchExtractTypeList(request); + } + + @Override + public MapResult execute(GetResultNameRequest request) { + String zoneId = repository.getZone(); + String resultname = repository.getProjectName() + "/" + + repository.getSelectionName() + "/" + + repository.getResultName(); + Map<String, String> map = Maps.newHashMap(); + map.put(zoneId, resultname); + return newMapResult(map); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetResultNameCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CopyRepositoryRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CopyRepositoryRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CopyRepositoryRequest.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,71 @@ +package fr.ifremer.coser.result.request; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * 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% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.coser.result.CoserRequest; +import org.apache.commons.collections4.CollectionUtils; + +import java.io.File; +import java.util.List; + +/** + * Created on 3/18/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class CopyRepositoryRequest implements CoserRequest, CoserRequestZoneListAware { + + private static final long serialVersionUID = 1L; + + protected List<String> zoneList; + + protected File targetDirectory; + + public File getTargetDirectory() { + return targetDirectory; + } + + public void setTargetDirectory(File targetDirectory) { + Preconditions.checkNotNull(targetDirectory); + this.targetDirectory = targetDirectory; + } + + @Override + public boolean isFilled() { + return targetDirectory != null && CollectionUtils.isNotEmpty(zoneList); + } + + @Override + public List<String> getZoneList() { + return zoneList; + } + + @Override + public void setZoneList(List<String> zoneList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(zoneList)); + this.zoneList = zoneList; + + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CopyRepositoryRequest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetResultNameRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetResultNameRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetResultNameRequest.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,59 @@ +package fr.ifremer.coser.result.request; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * 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% + */ + +import com.google.common.base.Preconditions; +import fr.ifremer.coser.result.CoserRequest; +import fr.ifremer.coser.util.DataType; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.List; + +/** + * Created on 3/18/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetResultNameRequest implements CoserRequest, CoserRequestExtractTypeListAware { + + private static final long serialVersionUID = 1L; + + protected List<DataType> extractTypeList; + + @Override + public List<DataType> getExtractTypeList() { + return extractTypeList; + } + + @Override + public void setExtractTypeList(List<DataType> extractTypeList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(extractTypeList)); + this.extractTypeList = extractTypeList; + } + + @Override + public boolean isFilled() { + return CollectionUtils.isNotEmpty(extractTypeList); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetResultNameRequest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ClientResultService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ClientResultService.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ClientResultService.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,579 @@ +package fr.ifremer.coser.services; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * 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% + */ + +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import fr.ifremer.coser.CoserBusinessConfig; +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.CoserConstants; +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.bean.EchoBaseProject; +import fr.ifremer.coser.bean.GlobalResult; +import fr.ifremer.coser.bean.Project; +import fr.ifremer.coser.bean.RSufiResult; +import fr.ifremer.coser.bean.RSufiResultPath; +import fr.ifremer.coser.bean.Selection; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepositoryType; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepositoryType; +import fr.ifremer.coser.util.InputStreamKnownSizeBody; +import fr.ifremer.coser.util.ProgressMonitor; +import fr.ifremer.coser.util.ProgressStream; +import fr.ifremer.coser.util.io.MultipleFileFilter; +import fr.ifremer.coser.util.io.OneEchobaseFileFilter; +import fr.ifremer.coser.util.io.OneRSufiResultFileFilter; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.filefilter.FileFilterUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.Consts; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.HttpClientBuilder; +import org.nuiton.util.FileUtil; +import org.nuiton.util.StringUtil; +import org.nuiton.util.ZipUtil; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +import static org.nuiton.i18n.I18n.t; + +/** + * Service to be used only by the ui client to extract and publish results. + * <p/> + * Created on 3/17/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class ClientResultService { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ClientResultService.class); + + protected CoserBusinessConfig config; + + protected ProjectService projectService; + + public ClientResultService(CoserBusinessConfig config) { + this.config = config; + this.projectService = new ProjectService(config); + } + + // --------------------------------------------------------------------- // + // --- Public API ------------------------------------------------------ // + // --------------------------------------------------------------------- // + + /** + * Retourne tous les projets qui ont des résultats. + * <p/> + * De la forme d'une liste de de path (à la tree path) : + * ProjetName/SelectionName/ResultName + * + * @param beginDate begin date (can be null) + * @param endDate end date (can be null) + * @param onlyPubliableResult select only publiable results + * @return results paths + * @throws CoserBusinessException + */ + public List<GlobalResult> findAllProjectWithResult(Date beginDate, + Date endDate, + boolean onlyPubliableResult) throws CoserBusinessException { + List<GlobalResult> results = Lists.newArrayList(); + + // loop on projets + File projectsDirectory = config.getProjectsDirectory(); + File[] projects = projectsDirectory.listFiles(); + if (projects != null) { + for (File existingProject : projects) { + if (existingProject.isDirectory()) { + + if (GlobalResult.isEchobaseProject(existingProject)) { + + Collection<GlobalResult> echoBaseResults = + getEchoBaseResults(existingProject, + beginDate, + endDate, + onlyPubliableResult); + results.addAll(echoBaseResults); + } else { + + Collection<GlobalResult> rsufiResults = + getRsufiResults(existingProject, + beginDate, + endDate, + onlyPubliableResult); + results.addAll(rsufiResults); + } + } + } + } + + return results; + } + + /** + * Upload user selected result to coser web front-end using common http + * client. + * <p/> + * TODO remove les 4 listes s'il y a mieux. + * + * @param selectedResults selected result (collection of project/selection/rsufiresult) + * @param indicatorsResults results selected as indicator results + * @param mapResults results selected as map result + * @param publishDataResults results selected as results published with data + * @param login remote admin login + * @param password remote admin password + * @param progress progress monitor + * @return upload error status or {@code null} if no error + * @throws CoserBusinessException + */ + public String performResultUpload(Collection<GlobalResult> selectedResults, + Collection<GlobalResult> indicatorsResults, + Collection<GlobalResult> mapResults, + Collection<GlobalResult> publishDataResults, + String login, + String password, + ProgressMonitor progress) throws CoserBusinessException { + + + // first copy prepare directory with only necessary data + // ie project with only selected selections + // and selection with only selected results + + progress.setCurrent(0); + progress.setText(t("coser.business.uploadresult.modifyResultOptions")); + modifyRSufiResults(selectedResults, indicatorsResults, mapResults, publishDataResults); + + progress.setText(t("coser.business.uploadresult.checkcollision")); + checkDataCollision(selectedResults); + + progress.setText(t("coser.business.uploadresult.preparezip")); + + // default extract to temp directory with data sources + File prepareZip = performResultExtract(selectedResults, publishDataResults, null); + + progress.setText(t("coser.business.uploadresult.sendzip")); + progress.setTotal((int) prepareZip.length()); + + // then upload zip file to website + try { + MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); + multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + + multipartEntityBuilder.setCharset(Consts.UTF_8); + + // login/password param (password encoded) + multipartEntityBuilder.addBinaryBody("login", login.getBytes()); + String sha1password = StringUtil.encodeSHA1(password); + multipartEntityBuilder.addBinaryBody("sha1Password", sha1password.getBytes()); + + // file param + ProgressStream stream = new ProgressStream(new FileInputStream(prepareZip), progress); + InputStreamKnownSizeBody fileBody = new InputStreamKnownSizeBody(stream, prepareZip.length(), + "application/zip", prepareZip.getName()); + multipartEntityBuilder.addPart("resultFile", fileBody); + + HttpPost httppost = new HttpPost(config.getWebUploadURL()); + httppost.setEntity(multipartEntityBuilder.build()); + + if (log.isInfoEnabled()) { + log.info("Uploading " + prepareZip + " to " + httppost.getURI()); + } + + HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); + HttpResponse response = httpClientBuilder.build().execute(httppost); + + String uploadStatus = null; + + if (response.getStatusLine().getStatusCode() != 200) { + uploadStatus = response.getStatusLine().getReasonPhrase(); + } + + FileUtils.forceDelete(prepareZip); + + return uploadStatus; + + } catch (ClientProtocolException ex) { + throw new CoserBusinessException("Can't upload file", ex); + } catch (IOException ex) { + throw new CoserBusinessException("Can't upload file", ex); + } + } + + // --------------------------------------------------------------------- // + // --- Internal methods ------------------------------------------------ // + // --------------------------------------------------------------------- // + + protected Collection<GlobalResult> getEchoBaseResults(File existingProject, + Date beginDate, + Date endDate, + boolean onlyPubliableResult) { + // echobase project + EchoBaseProject echoBaseProject = new EchoBaseProject(existingProject); + try { + echoBaseProject.load(); + } catch (IOException e) { + throw new CoserTechnicalException("Could not load echobase project", e); + } + GlobalResult result = new GlobalResult(echoBaseProject); + boolean candidate = isCandidateResult(result, beginDate, endDate, onlyPubliableResult); + List<GlobalResult> results = Lists.newArrayList(); + if (candidate) { + results.add(result); + } + return results; + } + + protected Collection<GlobalResult> getRsufiResults(File existingProject, + Date beginDate, + Date endDate, + boolean onlyPubliableResult) { + List<GlobalResult> results = Lists.newArrayList(); + + // rsufi project + String projectName = existingProject.getName(); + Project p = new Project(projectName); + + // loop on selections + File selectionsDirectory = new File(existingProject, CoserConstants.STORAGE_SELECTION_DIRECTORY); + File[] selections = selectionsDirectory.listFiles(); + if (selections != null) { + for (File existingSelection : selections) { + if (existingSelection.isDirectory()) { + String selectionName = existingSelection.getName(); + Selection s = new Selection(selectionName); + + // loop on result + File rsufisDirectory = new File(existingSelection, CoserConstants.STORAGE_RESULTS_DIRECTORY); + File[] rSufiResults = rsufisDirectory.listFiles(); + if (rSufiResults != null) { + for (File rSufiResult : rSufiResults) { + if (rSufiResult.isDirectory()) { + RSufiResult r; + try { + r = projectService.getRSufiResult(rSufiResult); + } catch (CoserBusinessException e) { + throw new CoserTechnicalException("Could not load rsufi result", e); + } + + RSufiResultPath path = new RSufiResultPath(p, s, r); + GlobalResult result = new GlobalResult(path); + boolean candidate = isCandidateResult(result, beginDate, endDate, onlyPubliableResult); + if (candidate) { + results.add(result); + } + } + } + } + } + } + } + return results; + } + + /** + * Test if result is valid with filtering. + * + * @param rsufiResult rsufi result to test + * @param beginDate begin date (can be null) + * @param endDate end date (can be null) + * @param onlyPubliableResult select only publiable results + * @return if result is valid candidate + */ + protected boolean isCandidateResult(GlobalResult rsufiResult, Date beginDate, + Date endDate, boolean onlyPubliableResult) { + + boolean result = true; + + if (beginDate != null) { + result = rsufiResult.getCreationDate().compareTo(beginDate) >= 0; + } + + if (endDate != null) { + result &= rsufiResult.getCreationDate().compareTo(endDate) <= 0; + } + + if (onlyPubliableResult) { + result &= rsufiResult.isPubliableResult(); + } + + return result; + } + + /** + * Modifie les types et options de certains résultats rsufi (map result, + * data sources result). + * + * @param selectedResults selected result (collection of project/selection/rsufiresult) + * @param indicatorsResults results selected as indicator results + * @param mapResults map results + * @param publishDataResults publish data results + */ + protected void modifyRSufiResults(Collection<GlobalResult> selectedResults, + Collection<GlobalResult> indicatorsResults, + Collection<GlobalResult> mapResults, + Collection<GlobalResult> publishDataResults) { + + // TODO echatellier 20110117 revoir ce code + + // attention, il faut sauver tout les resultats, sinon, les + // decochage de type map / publish result ne seront pas pris en compte + + // reset type map and data source for all + for (GlobalResult selectedResult : selectedResults) { + selectedResult.setIndicatorsResult(false); + selectedResult.setMapsResult(false); + selectedResult.setDataAllowed(false); + } + + // set map type + for (GlobalResult indicatorsResult : indicatorsResults) { + indicatorsResult.setIndicatorsResult(true); + } + + // set map type + for (GlobalResult mapResult : mapResults) { + mapResult.setMapsResult(true); + } + + // set data type + for (GlobalResult publishDataResult : publishDataResults) { + publishDataResult.setDataAllowed(true); + } + + // save all selected results + for (GlobalResult selectedGlobalResult : selectedResults) { + + if (selectedGlobalResult.isRsufi()) { + + RSufiResultPath selectedResult = selectedGlobalResult.getRsufiProject(); + Project project = selectedResult.getProject(); + Selection selection = selectedResult.getSelection(); + RSufiResult rsufiResult = selectedResult.getRsufiResult(); + + File projectDirectory = new File(config.getProjectsDirectory(), project.getName()); + File selectionsDirectory = new File(projectDirectory, CoserConstants.STORAGE_SELECTION_DIRECTORY); + File selectionDirectory = new File(selectionsDirectory, selection.getName()); + File resultsDirectory = new File(selectionDirectory, CoserConstants.STORAGE_RESULTS_DIRECTORY); + File resultDirectory = new File(resultsDirectory, rsufiResult.getName()); + + try { + projectService.saveRSufiResult(resultDirectory, rsufiResult); + } catch (CoserBusinessException e) { + throw new CoserTechnicalException("Could not save rsufi results", e); + } + } else { + EchoBaseProject selectedResult = selectedGlobalResult.getEchobaseProject(); + try { + selectedResult.save(); + } catch (IOException e) { + throw new CoserTechnicalException("Could not save echobaseProject", e); + } + } + + } + } + + /** + * Met à jour les fichiers de propriétés des resultats (maps, dataSource) + * and check for duplicated couple (zoneid/resulttype (map) upload). + * + * @param selectedResults result id to check + */ + protected void checkDataCollision(Collection<GlobalResult> selectedResults) { + + Collection<String> resultZoneTypeIds = Lists.newArrayList(); + + for (GlobalResult selectedResult : selectedResults) { + + String resultZoneTypeId; + + if (selectedResult.isRsufi()) { + RSufiResult rsufiResult = selectedResult.getRsufiProject().getRsufiResult(); + + // on creer une clé composé pour l'id du resultat + resultZoneTypeId = rsufiResult.getZone() + String.valueOf(rsufiResult.isMapsResult()); + } else { + EchoBaseProject echobaseProject = selectedResult.getEchobaseProject(); + resultZoneTypeId = echobaseProject.getZoneName() + String.valueOf(true); + } + if (resultZoneTypeIds.contains(resultZoneTypeId)) { + throw new CoserTechnicalException(t("coser.business.resultupload.duplicatedresult2", + selectedResult.getName(), + selectedResult.getZone())); + } else { + resultZoneTypeIds.add(resultZoneTypeId); + } + } + } + + /** + * Extract directory to custom directory. + * + * @param selectedResults selected result paths + * @param extractDirectory extract directory (can be null) + * @param publishDataResults result paths flaged with results export + * @return extracted file (no automatically deleted) + */ + public File performResultExtract(Collection<GlobalResult> selectedResults, + Collection<GlobalResult> publishDataResults, + File extractDirectory) { + File result; + try { + + // create zip file name if not random name + if (extractDirectory == null) { + result = File.createTempFile("Coserextract-", ".zip"); + } else { + // extract in a specific directory + DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); + String zipName = "Coserextract" + dateFormat.format(new Date()) + ".zip"; + result = new File(extractDirectory, zipName); + } + + // where to extract files to zip + File tempExtractDirectory = FileUtil.createTempDirectory("CoserExtractTemp", "dummy"); + + // copy rsufi results + performResultExtractForRSufi(tempExtractDirectory, + selectedResults, + publishDataResults); + + // copy echobase results + performResultExtractForEchoBase(tempExtractDirectory, + selectedResults, + publishDataResults); + + // get all files to compress + Collection<File> files = FileUtil.getFilteredElements(tempExtractDirectory, + FileFilterUtils.trueFileFilter(), + true); + + // create zip file + ZipUtil.compressFiles(result, tempExtractDirectory, files, false); + + // delete temp files + FileUtils.deleteDirectory(tempExtractDirectory); + + } catch (IOException e) { + throw new CoserTechnicalException("Can't prepare upload data", e); + } + return result; + } + + /** + * Extract directory to custom directory. + * + * @param extractDirectory extract directory + * @param selectedResults selected result paths + * @param publishDataResults result paths flaged with results export + */ + protected void performResultExtractForRSufi(File extractDirectory, + Collection<GlobalResult> selectedResults, + Collection<GlobalResult> publishDataResults) { + + Preconditions.checkNotNull(extractDirectory); + try { + + File projectsDirectory = config.getProjectsDirectory(); + + File rsufiDirectory = new File(extractDirectory, LegacyResultRepositoryType.ID); + FileUtils.forceMkdir(rsufiDirectory); + + // copy selectively all data to target directory + MultipleFileFilter mFileFilters = new MultipleFileFilter(); + for (GlobalResult globalProject : selectedResults) { + if (globalProject.isRsufi()) { + RSufiResultPath path = globalProject.getRsufiProject(); + // load projet, needed to known source data file name + Project project = path.getProject(); + project = projectService.openProject(project.getName()); + + OneRSufiResultFileFilter oneRFF = new OneRSufiResultFileFilter( + config.getProjectsDirectory(), + project, + path.getSelection(), + path.getRsufiResult(), + publishDataResults.contains(globalProject)); + mFileFilters.add(oneRFF); + } + } + + // copie vers le dossier dedie + FileUtils.copyDirectory(projectsDirectory, rsufiDirectory, mFileFilters); + } catch (CoserBusinessException e) { + throw new CoserTechnicalException("Can't prepare upload data", e); + } catch (IOException e) { + throw new CoserTechnicalException("Can't prepare upload data", e); + } + } + + /** + * Extract directory to custom directory. + * + * @param selectedResults selected result paths + * @param publishDataResults result paths flaged with results export + */ + protected void performResultExtractForEchoBase(File extractDirectory, + Collection<GlobalResult> selectedResults, + Collection<GlobalResult> publishDataResults) { + Preconditions.checkNotNull(extractDirectory); + try { + + File projectsDirectory = config.getProjectsDirectory(); + + File echobaseDirectory = new File(extractDirectory, EchoBaseResultRepositoryType.ID); + FileUtils.forceMkdir(echobaseDirectory); + + // creation du filter + MultipleFileFilter mFileFilters = new MultipleFileFilter(); + for (GlobalResult globalProject : selectedResults) { + if (globalProject.isEchoBase()) { + EchoBaseProject echobaseProject = globalProject.getEchobaseProject(); + OneEchobaseFileFilter fileFilter = + new OneEchobaseFileFilter(echobaseProject, + publishDataResults.contains(globalProject)); + mFileFilters.add(fileFilter); + } + } + + // copie vers le dossier dedie + FileUtils.copyDirectory(projectsDirectory, echobaseDirectory, mFileFilters); + + } catch (IOException e) { + throw new CoserTechnicalException("Can't prepare upload data", e); + } + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ClientResultService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native 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 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -122,7 +122,9 @@ * * Last update : $Date$ * By : $Author$ + * @deprecated since 1.5, should never be used, code too ugly and *simple* (dummy simple?) */ +@Deprecated public class WebService { private static final Log log = LogFactory.getLog(WebService.class); Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/storage/DataStorage.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/storage/DataStorage.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/storage/DataStorage.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -22,6 +22,7 @@ package fr.ifremer.coser.storage; +import java.io.Serializable; import java.util.Iterator; /** @@ -36,7 +37,7 @@ * Last update : $Date$ * By : $Author$ */ -public interface DataStorage extends Iterable<String[]> { +public interface DataStorage extends Iterable<String[]> , Serializable { /** * Add new data into storage. Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/storage/MemoryDataStorage.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/storage/MemoryDataStorage.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/storage/MemoryDataStorage.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -46,6 +46,8 @@ */ public class MemoryDataStorage implements DataStorage { + private static final long serialVersionUID = 1L; + /** Stockage des données. */ protected List<String> listStorage; Added: trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/MultipleFileFilter.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/MultipleFileFilter.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/MultipleFileFilter.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,55 @@ +package fr.ifremer.coser.util.io; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chatellier Eric, Chemit Tony + * %% + * 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% + */ + +import com.google.common.collect.Lists; + +import java.io.File; +import java.io.FileFilter; +import java.util.Collection; +import java.util.Iterator; + +/** + * Aggrege plusieurs file filters. + * + * @since 1.5 + */ +public class MultipleFileFilter implements FileFilter { + + protected Collection<FileFilter> fileFilters = Lists.newArrayList(); + + public void add(FileFilter f) { + fileFilters.add(f); + } + + @Override + public boolean accept(File pathname) { + + boolean result = false; + Iterator<FileFilter> it = fileFilters.iterator(); + while (it.hasNext() && !result) { + result = it.next().accept(pathname); + } + return result; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/MultipleFileFilter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneEchobaseFileFilter.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneEchobaseFileFilter.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneEchobaseFileFilter.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,71 @@ +package fr.ifremer.coser.util.io; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * 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% + */ + +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.bean.EchoBaseProject; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; + +/** + * Filter pour un resultat echobase donné. + * Created on 3/19/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class OneEchobaseFileFilter implements FileFilter { + + protected final String basedir; + + protected final boolean publishData; + + protected final String rawDataBasedir; + + public OneEchobaseFileFilter(EchoBaseProject project, + boolean publishData) { + this.publishData = publishData; + try { + this.basedir = project.getBasedir().getCanonicalPath(); + this.rawDataBasedir = project.getRawDataDirectory().getCanonicalPath(); + } catch (IOException e) { + throw new CoserTechnicalException("Could not get canonical path", e); + } + } + + @Override + public boolean accept(File pathname) { + try { + String currentPathName = pathname.getCanonicalPath(); + boolean result = currentPathName.startsWith(basedir); + if (result && !publishData) { + result = !currentPathName.startsWith(rawDataBasedir); + } + return result; + } catch (IOException e) { + throw new CoserTechnicalException("Could not get canonical path", e); + } + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneEchobaseFileFilter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneRSufiResultFileFilter.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneRSufiResultFileFilter.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneRSufiResultFileFilter.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,129 @@ +package fr.ifremer.coser.util.io; + +/* + * #%L + * Coser :: Business + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chatellier Eric, Chemit Tony + * %% + * 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% + */ + +import fr.ifremer.coser.CoserConstants; +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.CoserUtils; +import fr.ifremer.coser.bean.Project; +import fr.ifremer.coser.bean.RSufiResult; +import fr.ifremer.coser.bean.Selection; + +import java.io.File; +import java.io.FileFilter; +import java.io.IOException; +import java.util.regex.Matcher; + +/** + * Filter pour un resultat rsufi donné. + * <p/> + * Attention, implémentation que ne doit fonctionner que avec ZipUtil + * car meme si on refuse en répertoire, il redemande quand même + * les fils (et il faut qu'il les demande) + * + * @since 1.5 + */ +public class OneRSufiResultFileFilter implements FileFilter { + + protected File projectsDirectory; + + /** Doit etre un project chargé avec nom de fichier originaux. */ + protected Project project; + + protected Selection selection; + + protected RSufiResult rsufi; + + protected boolean exportWithData; + + public OneRSufiResultFileFilter(File projectsDirectory, + Project project, + Selection selection, + RSufiResult rsufi, + boolean exportWithData) { + this.projectsDirectory = projectsDirectory; + this.project = project; + this.selection = selection; + this.rsufi = rsufi; + this.exportWithData = exportWithData; + } + + @Override + public boolean accept(File pathname) { + + boolean result; + + try { + String currentPathName = pathname.getCanonicalPath() + File.separator; + + File projectDirectory = new File(projectsDirectory, project.getName()); + File selectionsDirectory = new File(projectDirectory, CoserConstants.STORAGE_SELECTION_DIRECTORY); + File selectionDirectory = new File(selectionsDirectory, selection.getName()); + File resultsDirectory = new File(selectionDirectory, CoserConstants.STORAGE_RESULTS_DIRECTORY); + File resultDirectory = new File(resultsDirectory, rsufi.getName()); + + String projectPath = projectDirectory.getCanonicalPath() + File.separator; + String selectionsPath = selectionsDirectory.getCanonicalPath() + File.separator; + String selectionPath = selectionDirectory.getCanonicalPath() + File.separator; + String resultsPath = resultsDirectory.getCanonicalPath() + File.separator; + String resultPath = resultDirectory.getCanonicalPath() + File.separator; + + // on prend + // - tout ce qu'il y a dans le projet + // - sauf le répertoire "selections" + // - ou la selection entierement + // - sauf le répertoire result + // - ou le resultat entierrement + result = (currentPathName.startsWith(projectPath) + && !currentPathName.startsWith(selectionsPath)) + || (currentPathName.startsWith(selectionPath) + && !currentPathName.startsWith(resultsPath)) + || currentPathName.startsWith(resultPath); + + // cas ou les données sources ne doivent pas être exporter + // condition sur les noms de fichiers ? + if (!exportWithData) { + String fileName = pathname.getName(); + + // on exclu tout les fichiers qui commencent + // par les memes noms de fichiers que ceux du projet + // (les noms de fichiers sont personnalisables) + for (CoserConstants.Category category : CoserConstants.Category.values()) { + if (category.isDataCategory()) { + String sourceFileName = project.getDataStorageFileName(category, null); + Matcher matcher = CoserUtils.FILENAME_SUFFIX_PATTERN.matcher(sourceFileName); + if (matcher.matches()) { + result &= !(fileName.startsWith(matcher.group(1)) && fileName.endsWith(matcher.group(2))); + } else { + result &= !fileName.startsWith(sourceFileName); + } + } + } + } + } catch (IOException ex) { + throw new CoserTechnicalException("Can't get system canonical path"); + } + + return result; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/util/io/OneRSufiResultFileFilter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/test/resources/web/echobaseprojects/project1/project.echobase (from rev 1156, trunk/coser-business/src/test/resources/web/echobaseprojects/project1/project.properties) =================================================================== --- trunk/coser-business/src/test/resources/web/echobaseprojects/project1/project.echobase (rev 0) +++ trunk/coser-business/src/test/resources/web/echobaseprojects/project1/project.echobase 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,27 @@ +### +# #%L +# Coser :: Business +# %% +# Copyright (C) 2010 - 2014 Ifremer, Codelutin +# %% +# 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% +### +project.author=tc +project.facadeName=atlantique +project.zoneName=gdgciem8 +project.surveyName=PELGAS +project.comment=PELGAS-ATL +project.creationDate=1394126084855 Deleted: trunk/coser-business/src/test/resources/web/echobaseprojects/project1/project.properties =================================================================== --- trunk/coser-business/src/test/resources/web/echobaseprojects/project1/project.properties 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/test/resources/web/echobaseprojects/project1/project.properties 2014-03-19 10:54:43 UTC (rev 1158) @@ -1,27 +0,0 @@ -### -# #%L -# Coser :: Business -# %% -# Copyright (C) 2010 - 2014 Ifremer, Codelutin -# %% -# 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% -### -project.author=tc -project.facadeName=atlantique -project.zoneName=gdgciem8 -project.surveyName=PELGAS -project.comment=PELGAS-ATL -project.creationDate=1394126084855 Copied: trunk/coser-business/src/test/resources/web/echobaseprojects/project2/project.echobase (from rev 1156, trunk/coser-business/src/test/resources/web/echobaseprojects/project2/project.properties) =================================================================== --- trunk/coser-business/src/test/resources/web/echobaseprojects/project2/project.echobase (rev 0) +++ trunk/coser-business/src/test/resources/web/echobaseprojects/project2/project.echobase 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,27 @@ +### +# #%L +# Coser :: Business +# %% +# Copyright (C) 2010 - 2014 Ifremer, Codelutin +# %% +# 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% +### +project.author=tc +project.facadeName=atlantique +project.zoneName=gdgciem8-2 +project.surveyName=PELGAS +project.comment=PELGASSE-ATL +project.creationDate=1394126084855 Deleted: trunk/coser-business/src/test/resources/web/echobaseprojects/project2/project.properties =================================================================== --- trunk/coser-business/src/test/resources/web/echobaseprojects/project2/project.properties 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-business/src/test/resources/web/echobaseprojects/project2/project.properties 2014-03-19 10:54:43 UTC (rev 1158) @@ -1,27 +0,0 @@ -### -# #%L -# Coser :: Business -# %% -# Copyright (C) 2010 - 2014 Ifremer, Codelutin -# %% -# 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% -### -project.author=tc -project.facadeName=atlantique -project.zoneName=gdgciem8-2 -project.surveyName=PELGAS -project.comment=PELGASSE-ATL -project.creationDate=1394126084855 Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/Coser.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -26,6 +26,7 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; +import fr.ifremer.coser.services.ClientResultService; import jaxx.runtime.context.DefaultApplicationContext; import jaxx.runtime.swing.session.SwingSession; @@ -42,7 +43,6 @@ import fr.ifremer.coser.services.ControlService; import fr.ifremer.coser.services.ProjectService; import fr.ifremer.coser.services.PublicationService; -import fr.ifremer.coser.services.WebService; import fr.ifremer.coser.ui.CoserFrame; /** @@ -149,7 +149,9 @@ context.setContextValue(new CommandService(coserConfig)); context.setContextValue(new ControlService(coserConfig)); context.setContextValue(new PublicationService(coserConfig)); - context.setContextValue(new WebService(coserConfig)); +// context.setContextValue(new WebService(coserConfig)); + context.setContextValue(new ClientResultService(coserConfig)); + context.setContextValue(new DefaultCoserApplicationContext(coserConfig)); // init frame with session reloading CoserFrame frame = new CoserFrame(context); Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -67,8 +67,7 @@ import fr.ifremer.coser.ui.project.ProjectHandler; import fr.ifremer.coser.ui.project.ProjectOpenView; import fr.ifremer.coser.ui.project.ProjectSummaryView; -import fr.ifremer.coser.ui.result.ResultHandler; -import fr.ifremer.coser.ui.result.SelectUploadResultView; +import fr.ifremer.coser.ui.publication.SelectUploadResultView; import fr.ifremer.coser.ui.selection.SelectionHandler; import fr.ifremer.coser.ui.selection.SelectionView; import fr.ifremer.coser.ui.selection.replay.SelectionReplayHandler; @@ -579,12 +578,10 @@ */ public void showPublishResultView() { SelectUploadResultView selectUploadResultView = new SelectUploadResultView(view); - ResultHandler handler = new ResultHandler(); - selectUploadResultView.setHandler(handler); - handler.init(selectUploadResultView); + selectUploadResultView.getHandler().init(selectUploadResultView); // restore session size - SwingSession session = (SwingSession)view.getContextValue(SwingSession.class); + SwingSession session = view.getContextValue(SwingSession.class); session.add(selectUploadResultView); setMainComponent(selectUploadResultView); Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/ExportUploadDialog.jaxx (from rev 1156, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ExportUploadDialog.jaxx) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/ExportUploadDialog.jaxx (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/ExportUploadDialog.jaxx 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,83 @@ +<!-- + #%L + Coser :: UI + %% + Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric, Chemit Tony + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 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 Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<JDialog title="coser.ui.uploadresult.exportUploadTitle" modal="true"> + <Table> + <GlobalResultHandler id="handler"/> + <row> + <cell weightx="1" weighty="1" fill="both"> + <Table border='{BorderFactory.createTitledBorder(t("coser.ui.uploadresult.extractChoice"))}'> + <row> + <cell fill="horizontal"> + <JLabel text="coser.ui.uploadresult.extractTo"/> + </cell> + <cell weightx="1" fill="horizontal"> + <JTextField id="extractToTextField"/> + </cell> + <cell> + <JButton text="coser.ui.common.selectFile" + onActionPerformed="handler.selectExportDirectory(this, extractToTextField)"/> + </cell> + </row> + <row> + <cell columns="3" anchor="east"> + <JButton text="coser.ui.uploadresult.extract" + onActionPerformed="handler.performExtractResult(this)"/> + </cell> + </row> + </Table> + </cell> + </row> + <row> + <cell weightx="1" weighty="1" fill="both"> + <Table border='{BorderFactory.createTitledBorder(t("coser.ui.uploadresult.uploadChoice"))}'> + <row> + <cell fill="horizontal"> + <JLabel text="coser.ui.uploadresult.uploadLogin"/> + </cell> + <cell weightx="1" fill="horizontal"> + <JTextField id="uploadLogintextField"/> + </cell> + </row> + <row> + <cell fill="horizontal"> + <JLabel text="coser.ui.uploadresult.uploadPassword"/> + </cell> + <cell fill="horizontal"> + <JPasswordField id="uploadPasswordtextField"/> + </cell> + </row> + <row> + <cell columns="2" anchor="east"> + <JButton text="coser.ui.uploadresult.upload" + onActionPerformed="handler.performUploadResult(this)"/> + </cell> + </row> + <row> + <cell weightx="1" fill="horizontal" columns="2"> + <fr.ifremer.coser.ui.util.CoserProgressBar id="uploadProgressBar" stringPainted="true"/> + </cell> + </row> + </Table> + </cell> + </row> + </Table> +</JDialog> Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultHandler.java (from rev 1156, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultHandler.java) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultHandler.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultHandler.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,279 @@ +/* + * #%L + * Coser :: UI + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric, Chemit Tony + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.publication; + +import com.google.common.collect.Lists; +import fr.ifremer.coser.CoserBusinessException; +import fr.ifremer.coser.CoserConfig; +import fr.ifremer.coser.CoserException; +import fr.ifremer.coser.bean.GlobalResult; +import fr.ifremer.coser.services.ClientResultService; +import fr.ifremer.coser.ui.common.CommonHandler; +import fr.ifremer.coser.ui.util.CoserProgressBar; +import fr.ifremer.coser.ui.util.ErrorHelper; +import jaxx.runtime.JAXXUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; + +import javax.swing.JFileChooser; +import javax.swing.JOptionPane; +import javax.swing.JTextField; +import javax.swing.SwingWorker; +import java.io.File; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import static org.nuiton.i18n.I18n.t; + +/** + * Handler for rsufi result management. + * + * @author chatellier + * @version $Revision$ + * <p/> + * Last update : $Date$ + * By : $Author$ + */ +public class GlobalResultHandler extends CommonHandler { + + /** + * Initialise la vue (principalement en recuperant les données. + * + * @param view view + */ + public void init(SelectUploadResultView view) { + + //SwingUtil.fixTableColumnWidth(view.getSelectedProjectTable(), 1, 25); + //SwingUtil.fixTableColumnWidth(view.getAvailableProjectTable(), 1, 25); + view.getAvailableResultTable().setDefaultRenderer(String[].class, new GlobalResultRenderer()); + view.getSelectedResultTable().setDefaultRenderer(String[].class, new GlobalResultRenderer()); + view.getAvailableResultTable().setDefaultRenderer(String.class, new GlobalResultZoneRenderer(view)); + view.getSelectedResultTable().setDefaultRenderer(String.class, new GlobalResultZoneRenderer(view)); + + // initialise les données avec les filtres par default + updateAvailableResultsFilter(view); + view.getSelectedResultTableModel().setResultPaths(Lists.<GlobalResult>newArrayList()); + + } + + /** + * Met à jour les données de la table apres la modification d'un + * ou plusieurs filtre. + * + * @param view view + */ + public void updateAvailableResultsFilter(SelectUploadResultView view) { + + // get filter + Date beginDate = view.getFilterBeginDate().getDate(); + Date endDate = view.getFilterEndDate().getDate(); + boolean onlyPubliable = view.getPubliableResults().isSelected(); + + // get result + ClientResultService webService = view.getContextValue(ClientResultService.class); + + try { + List<GlobalResult> results = webService.findAllProjectWithResult(beginDate, endDate, onlyPubliable); + view.getAvailableResultTableModel().setResultPaths(results); + } catch (CoserBusinessException ex) { + throw new CoserException("Can't get results", ex); + } + } + + /** + * Add selected result in available table to selected table. + * + * @param view view + */ + public void addAvailableResult(SelectUploadResultView view) { + + // get new result to add + List<GlobalResult> currentResult = view.getSelectedResultTableModel().getResultPaths(); + int[] selectedAvailableRows = view.getAvailableResultTable().getSelectedRows(); + for (int selectedAvailableRow : selectedAvailableRows) { + GlobalResult resultData = view.getAvailableResultTableModel().getResultPaths().get(selectedAvailableRow); + if (!currentResult.contains(resultData)) { + currentResult.add(resultData); + + // indicator results are auto selected + // can be done only here + view.getSelectedResultTableModel().getIndicatorResults().add(resultData); + if (resultData.isEchoBase()) { + + // auto-select publish map + view.getSelectedResultTableModel().getMapResults().add(resultData); + } + } + } + + // les collisions ne peuvent pas être détecté a ce moment. + // seulement lors du clic sur le bouton export/upload + + view.getSelectedResultTableModel().setResultPaths(currentResult); + } + + /** + * Remove selected result from selected list. + * + * @param view view + */ + public void removeSelectedResult(SelectUploadResultView view) { + List<GlobalResult> currentResult = view.getSelectedResultTableModel().getResultPaths(); + int[] selectedSelectedRows = view.getSelectedResultTable().getSelectedRows(); + // need to remove reverse order + for (int index = selectedSelectedRows.length - 1; index >= 0; --index) { + int selectedSelectedRow = selectedSelectedRows[index]; + currentResult.remove(selectedSelectedRow); + } + view.getSelectedResultTableModel().setResultPaths(currentResult); + } + + /** + * Perform file upload to coser server after selection by user. + * + * @param view view + */ + public void performUploadResult(final ExportUploadDialog view) { + + // get authen options + final String login = view.getUploadLogintextField().getText(); + final String password = new String(view.getUploadPasswordtextField().getPassword()); + + // get result selected by user + SelectUploadResultView parentView = view.getContextValue(SelectUploadResultView.class, JAXXUtil.PARENT); + final Collection<GlobalResult> selectedResults = parentView.getSelectedResultTableModel().getResultPaths(); + final Collection<GlobalResult> indicatorResults = parentView.getSelectedResultTableModel().getIndicatorResults(); + final Collection<GlobalResult> mapResults = parentView.getSelectedResultTableModel().getMapResults(); + final Collection<GlobalResult> publishDataResults = parentView.getSelectedResultTableModel().getPublishDataResults(); + if (CollectionUtils.isNotEmpty(selectedResults)) { + + SwingWorker<String, Void> task = new SwingWorker<String, Void>() { + @Override + protected String doInBackground() { + try { + setWaitCursor(view); + + // get progress bar + CoserProgressBar progressBar = view.getUploadProgressBar(); + ClientResultService webService = view.getContextValue(ClientResultService.class); + String status = webService.performResultUpload(selectedResults, + indicatorResults, + mapResults, + publishDataResults, + login, + password, + progressBar); + return status; + } catch (CoserBusinessException ex) { + throw new CoserException(ex.getMessage(), ex); + } + } + + @Override + protected void done() { + + // laisser cet appel, sinon les exceptions sont silencieuse + try { + String status = get(); + + if (StringUtils.isNotEmpty(status)) { + JOptionPane.showMessageDialog(view, t("coser.ui.uploadresult.resultsuploaderror", status), + t("coser.ui.uploadresult.title"), JOptionPane.ERROR_MESSAGE); + } else { + JOptionPane.showMessageDialog(view, t("coser.ui.uploadresult.resultsuploaded"), + t("coser.ui.uploadresult.title"), JOptionPane.INFORMATION_MESSAGE); + } + + view.dispose(); + } catch (Exception ex) { + //throw new CoserException("Can't get upload status", ex); + // FIXME chatellier 20110126 le dispatch global marche pas ? :( + ErrorHelper errorHelper = new ErrorHelper(view.getContextValue(CoserConfig.class)); + errorHelper.showErrorDialog(view, ex.getMessage(), ex); + } finally { + setDefaultCursor(view); + } + } + }; + task.execute(); + } + } + + /** + * Perform file upload to coser server after selection by user. + * + * @param view view + */ + public void performExtractResult(ExportUploadDialog view) { + + // get extract directory + String extractPath = view.getExtractToTextField().getText(); + File extractDirectory = new File(extractPath); + + SelectUploadResultView parentView = view.getContextValue(SelectUploadResultView.class, JAXXUtil.PARENT); + List<GlobalResult> selectedResult = parentView.getSelectedResultTableModel().getResultPaths(); + Set<GlobalResult> publishDataResults = parentView.getSelectedResultTableModel().getPublishDataResults(); + ClientResultService webService = view.getContextValue(ClientResultService.class); + try { + setWaitCursor(view); + + webService.performResultExtract(selectedResult, publishDataResults, extractDirectory); + JOptionPane.showMessageDialog(view, t("coser.ui.uploadresult.resultsextracted"), + t("coser.ui.uploadresult.title"), JOptionPane.INFORMATION_MESSAGE); + view.dispose(); + } finally { + setDefaultCursor(view); + } + } + + /** + * Just display export / upload dialog. + * + * @param view parent view + */ + public void showExportUploadDialog(SelectUploadResultView view) { + ExportUploadDialog dialog = new ExportUploadDialog(view); + dialog.setLocationRelativeTo(view); + dialog.setVisible(true); + } + + /** + * Select result file (directory only). + * + * @param view view + * @param textComponent text component to set selected file + */ + public void selectExportDirectory(ExportUploadDialog view, JTextField textComponent) { + CoserConfig config = view.getContextValue(CoserConfig.class); + JFileChooser selectFileChooser = getFileChooserInstance(config.getProjectsDirectory()); + selectFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + + int result = selectFileChooser.showOpenDialog(view); + if (result == JFileChooser.APPROVE_OPTION) { + File selectedFile = selectFileChooser.getSelectedFile(); + textComponent.setText(selectedFile.getAbsolutePath()); + } + } +} Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultRenderer.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultRenderer.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,65 @@ +package fr.ifremer.coser.ui.publication; + +/* + * #%L + * Coser :: UI + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import fr.ifremer.coser.bean.GlobalResult; +import fr.ifremer.coser.bean.RSufiResultPath; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; +import java.awt.Component; + +/** + * Created on 3/17/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GlobalResultRenderer extends DefaultTableCellRenderer { + + private static final long serialVersionUID = 1L; + + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + + Object localValue = value; + if (value instanceof GlobalResult) { + GlobalResult g = (GlobalResult) value; + if (g.isRsufi()) { + RSufiResultPath rsufiResultPath = g.getRsufiProject(); + localValue = rsufiResultPath.getProject().getName() + "/" + + rsufiResultPath.getSelection().getName() + "/" + + rsufiResultPath.getRsufiResult().getName(); + } else { + localValue = g.getEchobaseProject().getName(); + } + } + return super.getTableCellRendererComponent(table, localValue, isSelected, hasFocus, + row, column); + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultRenderer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultTableModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultTableModel.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultTableModel.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,239 @@ +package fr.ifremer.coser.ui.publication; + +/* + * #%L + * Coser :: UI + * %% + * Copyright (C) 2010 - 2014 Ifremer, Codelutin, Chemit Tony + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Sets; +import fr.ifremer.coser.bean.GlobalResult; + +import javax.swing.table.AbstractTableModel; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created on 3/17/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GlobalResultTableModel extends AbstractTableModel { + + private static final long serialVersionUID = 1L; + + /** Les données de la table. */ + protected List<GlobalResult> resultPaths; + + /** Les résultats marqués comme etant des données d'indicateurs. */ + protected Set<GlobalResult> indicatorResults; + + /** Les résultats marqué comme étant des données de map. */ + protected Set<GlobalResult> mapResults; + + /** Les résultat dont la publication des données est autorisée. */ + protected Set<GlobalResult> publishDataResults; + + /** Selected table tablemodel (do not show all columns). */ + protected boolean selected; + + public GlobalResultTableModel(boolean selected) { + this.selected = selected; + + // les selections ne sont jamais supprimé + // mais vu l'equivalence equals/hascode + // ca ne doit pas poser de problemes + indicatorResults = Sets.newHashSet(); + mapResults = Sets.newHashSet(); + publishDataResults = Sets.newHashSet(); + } + + public void setResultPaths(List<GlobalResult> resultPaths) { + this.resultPaths = resultPaths; + fireTableDataChanged(); + } + + public List<GlobalResult> getResultPaths() { + return resultPaths; + } + + public Set<GlobalResult> getIndicatorResults() { + return indicatorResults; + } + + public Set<GlobalResult> getMapResults() { + return mapResults; + } + + public Set<GlobalResult> getPublishDataResults() { + return publishDataResults; + } + + @Override + public int getRowCount() { + int result = 0; + if (resultPaths != null) { + result = resultPaths.size(); + } + return result; + } + + @Override + public String getColumnName(int column) { + String result = null; + switch (column) { + case 0: + result = t("coser.ui.uploadresult.creationDate"); + break; + case 1: + result = t("coser.ui.uploadresult.path"); + break; + case 2: + result = t("coser.ui.uploadresult.zone"); + break; + case 3: + result = t("coser.ui.uploadresult.indicatorResult"); + break; + case 4: + result = t("coser.ui.uploadresult.mapResult"); + break; + case 5: + result = t("coser.ui.uploadresult.publishData"); + break; + } + return result; + } + + @Override + public Class<?> getColumnClass(int columnIndex) { + Class<?> result = null; + switch (columnIndex) { + case 0: + result = Date.class; + break; + case 1: + result = String[].class; + break; + case 2: + result = String.class; + break; + case 3: + result = Boolean.class; + break; + case 4: + result = Boolean.class; + break; + case 5: + result = Boolean.class; + break; + } + return result; + } + + @Override + public int getColumnCount() { + int result = 3; + if (selected) { + result = 6; + } + return result; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + + Object result = null; + + GlobalResult data = resultPaths.get(rowIndex); + switch (columnIndex) { + case 0: + result = data.getCreationDate(); + break; + case 1: + result = data; + break; + case 2: + result = data.getZone(); + break; + case 3: + result = indicatorResults.contains(data); + break; + case 4: + result = mapResults.contains(data); + break; + case 5: + result = publishDataResults.contains(data); + break; + } + + return result; + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + + GlobalResult data = resultPaths.get(rowIndex); + + boolean editable; + if (data.isEchoBase()) { + + // can only edit publish data column + editable = columnIndex >= 5; + } else { + + // can edit indicator - map and publish data columns + editable = columnIndex >= 3; + } + + return editable; + } + + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + + GlobalResult data = resultPaths.get(rowIndex); + + if (columnIndex == 3) { + Boolean bValue = (Boolean) aValue; + if (bValue) { + indicatorResults.add(data); + } else { + indicatorResults.remove(data); + } + } else if (columnIndex == 4) { + Boolean bValue = (Boolean) aValue; + if (bValue) { + mapResults.add(data); + } else { + mapResults.remove(data); + } + } else if (columnIndex == 5) { + Boolean bValue = (Boolean) aValue; + if (bValue) { + publishDataResults.add(data); + } else { + publishDataResults.remove(data); + } + } + } +} Property changes on: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultTableModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultZoneRenderer.java (from rev 1156, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultZoneRenderer.java) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultZoneRenderer.java (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/GlobalResultZoneRenderer.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,69 @@ +/* + * #%L + * Coser :: UI + * %% + * Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chemit Tony + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 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 Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.ui.publication; + +import fr.ifremer.coser.CoserApplicationContext; +import fr.ifremer.coser.bean.ZoneMap; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; +import java.awt.Component; + +/** + * Available and selected result zone renderer. + * + * @author chemit + */ +public class GlobalResultZoneRenderer extends DefaultTableCellRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = -9030155088814184637L; + + protected SelectUploadResultView view; + + protected ZoneMap zoneMap; + + public GlobalResultZoneRenderer(SelectUploadResultView view) { + this.view = view; + } + + @Override + public Component getTableCellRendererComponent(JTable table, + Object value, + boolean isSelected, + boolean hasFocus, + int row, + int column) { + if (zoneMap == null) { + zoneMap = view.getContextValue(CoserApplicationContext.class).getZoneMap(); + } + + Object localValue = value; + if (value != null && value instanceof String) { + String zoneId = (String) value; + localValue = zoneMap.getZoneFullName(zoneId); + } + return super.getTableCellRendererComponent(table, localValue, isSelected, hasFocus, + row, column); + } +} Copied: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/SelectUploadResultView.jaxx (from rev 1156, trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectUploadResultView.jaxx) =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/SelectUploadResultView.jaxx (rev 0) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/publication/SelectUploadResultView.jaxx 2014-03-19 10:54:43 UTC (rev 1158) @@ -0,0 +1,107 @@ +<!-- + #%L + Coser :: UI + %% + Copyright (C) 2010 - 2011 Ifremer, Codelutin, Chatellier Eric, Chemit Tony + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 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 Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --> +<Table> + <GlobalResultHandler id="handler"/> + + <row> + <cell weightx="1" fill="horizontal"> + <JLabel text="coser.ui.uploadresult.explanation"/> + </cell> + </row> + <row> + <cell weightx="1" fill="horizontal"> + <JLabel text="coser.ui.uploadresult.availableResults"/> + </cell> + </row> + <row> + <cell weightx="1" fill="horizontal"> + <Table> + <row> + <cell> + <JLabel text="coser.ui.uploadresult.filter.beginDate"/> + </cell> + <cell> + <JXDatePicker id="filterBeginDate" + onActionPerformed="handler.updateAvailableResultsFilter(this)"/> + </cell> + <cell> + <JLabel text="coser.ui.uploadresult.filter.endDate"/> + </cell> + <cell> + <JXDatePicker id="filterEndDate" + onActionPerformed="handler.updateAvailableResultsFilter(this)"/> + </cell> + <cell> + <JLabel text="coser.ui.uploadresult.filter.publiableResults"/> + </cell> + <cell> + <JCheckBox id="publiableResults" selected="true" + onActionPerformed="handler.updateAvailableResultsFilter(this)"/> + </cell> + </row> + </Table> + </cell> + </row> + <row> + <cell weightx="1" weighty="1" fill="both"> + <JScrollPane> + <GlobalResultTableModel id="availableResultTableModel" initializer='new GlobalResultTableModel(false)'/> + <JTable id="availableResultTable" model="{getAvailableResultTableModel()}"/> + <ListSelectionModel javaBean="availableResultTable.getSelectionModel()" + onValueChanged="addResultButton.setEnabled(getAvailableResultTable().getSelectedRow() != -1)"/> + </JScrollPane> + </cell> + </row> + <row> + <cell weightx="1" anchor="center"> + <JButton id="addResultButton" text="coser.ui.uploadresult.addResults" + onActionPerformed="handler.addAvailableResult(this)" enabled="false"/> + </cell> + </row> + <row> + <cell weightx="1" fill="horizontal"> + <JLabel text="coser.ui.uploadresult.selectedResults"/> + </cell> + </row> + <row> + <cell weightx="1" weighty="1" fill="both"> + <JScrollPane> + <GlobalResultTableModel id="selectedResultTableModel" initializer='new GlobalResultTableModel(true)'/> + <JTable id="selectedResultTable" model="{getSelectedResultTableModel()}"/> + <ListSelectionModel javaBean="selectedResultTable.getSelectionModel()" + onValueChanged="removeResultButton.setEnabled(getSelectedResultTable().getSelectedRow() != -1)"/> + </JScrollPane> + </cell> + </row> + <row> + <cell weightx="1" anchor="center"> + <JButton id="removeResultButton" text="coser.ui.uploadresult.removeResults" + onActionPerformed="handler.removeSelectedResult(this)" enabled="false"/> + </cell> + </row> + <row> + <cell weightx="1" anchor="east"> + <JButton text="coser.ui.uploadresult.exportupload" + onActionPerformed="handler.showExportUploadDialog(this)"/> + </cell> + </row> +</Table> Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ExportUploadDialog.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ExportUploadDialog.jaxx 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ExportUploadDialog.jaxx 2014-03-19 10:54:43 UTC (rev 1158) @@ -19,6 +19,7 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> +<!--@Deprecated--> <JDialog title="coser.ui.uploadresult.exportUploadTitle" modal="true"> <Table> <ResultHandler id="handler" javaBean="null" /> Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultHandler.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultHandler.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -83,9 +83,11 @@ /** * Met à jour les données de la table apres la modification d'un * ou plusieurs filtre. - * + * <strong>Important:</strong> does not work any longer + * * @param view view */ + @Deprecated public void updateAvailableResultsFilter(SelectUploadResultView view) { // get filter @@ -149,9 +151,11 @@ /** * Perform file upload to coser server after selection by user. - * + * <strong>Important:</strong> does not work any longer + * * @param view view */ + @Deprecated public void performUploadResult(final ExportUploadDialog view) { // get authen options @@ -215,12 +219,14 @@ task.execute(); } } - + /** * Perform file upload to coser server after selection by user. - * + * <strong>Important:</strong> does not work any longer + * * @param view view */ + @Deprecated public void performExtractResult(ExportUploadDialog view) { // get extract directory Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultTableRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultTableRenderer.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ResultTableRenderer.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -22,68 +22,69 @@ package fr.ifremer.coser.ui.result; -import static org.nuiton.i18n.I18n.t; +import fr.ifremer.coser.CoserApplicationContext; +import fr.ifremer.coser.bean.ZoneMap; +import fr.ifremer.coser.ui.selection.SelectionRsufiView; -import java.awt.Component; - import javax.swing.JTable; import javax.swing.table.DefaultTableCellRenderer; +import java.awt.Component; -import fr.ifremer.coser.CoserBusinessException; -import fr.ifremer.coser.CoserException; -import fr.ifremer.coser.services.WebService; -import fr.ifremer.coser.ui.selection.SelectionRsufiView; +import static org.nuiton.i18n.I18n.t; /** * Selection result table renderer. - * + * * @author chatellier * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ + * <p/> + * Last update : $Date$ + * By : $Author$ */ public class ResultTableRenderer extends DefaultTableCellRenderer { /** serialVersionUID. */ private static final long serialVersionUID = -9030155088814184637L; - protected SelectionRsufiView view; +// protected SelectionRsufiView view; + protected ZoneMap zoneMap; + public ResultTableRenderer(SelectionRsufiView view) { - this.view = view; +// this.view = view; + this.zoneMap = view.getContextValue(CoserApplicationContext.class).getZoneMap(); } @Override public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, int row, int column) { + boolean isSelected, boolean hasFocus, int row, int column) { Object localValue = value; - + switch (column) { case 2: if (value != null) { - // get web service - try { - WebService webService = view.getContextValue(WebService.class); - localValue = webService.getZoneFullName((String)value); - } catch (CoserBusinessException ex) { - throw new CoserException("Can't get zone name", ex); - } + localValue = zoneMap.getZoneFullName((String) value); +// // get web service +// try { +// WebService webService = view.getContextValue(WebService.class); +// localValue = webService.getZoneFullName((String)value); +// } catch (CoserBusinessException ex) { +// throw new CoserException("Can't get zone name", ex); +// } } break; case 5: case 6: - boolean availale = (Boolean)value; + boolean availale = (Boolean) value; if (availale) { localValue = t("coser.ui.common.yes"); - } - else { + } else { localValue = t("coser.ui.common.no"); } break; } return super.getTableCellRendererComponent(table, localValue, isSelected, hasFocus, - row, column); + row, column); } } Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultRenderer.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultRenderer.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -38,6 +38,7 @@ * Last update : $Date$ * By : $Author$ */ +@Deprecated public class RsufiResultRenderer extends DefaultTableCellRenderer { /** serialVersionUID. */ Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultTableModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultTableModel.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultTableModel.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -44,6 +44,7 @@ * Last update : $Date$ * By : $Author$ */ +@Deprecated public class RsufiResultTableModel extends AbstractTableModel { /** serialVersionUID. */ Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultZoneRenderer.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultZoneRenderer.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/RsufiResultZoneRenderer.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -40,6 +40,7 @@ * Last update : $Date$ * By : $Author$ */ +@Deprecated public class RsufiResultZoneRenderer extends DefaultTableCellRenderer { /** serialVersionUID. */ Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectUploadResultView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectUploadResultView.jaxx 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectUploadResultView.jaxx 2014-03-19 10:54:43 UTC (rev 1158) @@ -19,6 +19,7 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> + <!--@Deprecated--> <Table> <ResultHandler id="handler" javaBean="null" /> Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionAddResultDialog.jaxx 2014-03-19 10:54:43 UTC (rev 1158) @@ -72,7 +72,7 @@ <JLabel text="coser.ui.result.zone" /> </cell> <cell fill="horizontal" columns="2"> - <ZoneComboBoxModel id="resultZoneComboModel" javaBean="new ZoneComboBoxModel(getContextValue(fr.ifremer.coser.services.WebService.class))" /> + <ZoneComboBoxModel id="resultZoneComboModel" javaBean="ZoneComboBoxModel.newModel(this)" /> <JComboBox id="resultZoneCombo" model="{getResultZoneComboModel()}" renderer="{new ZoneComboBoxRenderer()}" onActionPerformed='getRsufiResult().setZone((String)resultZoneCombo.getSelectedItem())'/> Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionEditResultDialog.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionEditResultDialog.jaxx 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/SelectionEditResultDialog.jaxx 2014-03-19 10:54:43 UTC (rev 1158) @@ -58,7 +58,7 @@ <JLabel text="coser.ui.result.zone" /> </cell> <cell fill="horizontal"> - <ZoneComboBoxModel id="resultZoneComboModel" javaBean="new ZoneComboBoxModel(getContextValue(fr.ifremer.coser.services.WebService.class))" + <ZoneComboBoxModel id="resultZoneComboModel" javaBean="ZoneComboBoxModel.newModel(this)" selectedItem="{getRsufiResult().getZone()}"/> <JComboBox id="resultZoneCombo" model="{getResultZoneComboModel()}" renderer="{new ZoneComboBoxRenderer()}" Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxModel.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxModel.java 2014-03-19 09:38:30 UTC (rev 1157) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/result/ZoneComboBoxModel.java 2014-03-19 10:54:43 UTC (rev 1158) @@ -22,23 +22,22 @@ package fr.ifremer.coser.ui.result; +import fr.ifremer.coser.CoserApplicationContext; +import fr.ifremer.coser.storage.DataStorage; +import jaxx.runtime.JAXXObject; + import javax.swing.DefaultComboBoxModel; -import fr.ifremer.coser.CoserBusinessException; -import fr.ifremer.coser.CoserException; -import fr.ifremer.coser.services.WebService; -import fr.ifremer.coser.storage.DataStorage; - /** * Zone combo box model. * Contains zone list defined in "matchzone" file common to web side and client * side. - * + * * @author chatellier * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ + * <p/> + * Last update : $Date$ + * By : $Author$ */ public class ZoneComboBoxModel extends DefaultComboBoxModel { @@ -47,14 +46,24 @@ protected DataStorage zonesMap; - public ZoneComboBoxModel(WebService webService) { - try { - zonesMap = webService.getZonesMap(); - } catch (CoserBusinessException ex) { - throw new CoserException("Can't get zone list", ex); - } + public static ZoneComboBoxModel newModel(JAXXObject ui) { + CoserApplicationContext contextValue = ui.getContextValue(CoserApplicationContext.class); + DataStorage storage = contextValue.getZoneMap().getStorage(); + return new ZoneComboBoxModel(storage); } + public ZoneComboBoxModel(DataStorage zonesMap) { + this.zonesMap = zonesMap; + } + +// public ZoneComboBoxModel(WebService webService) { +// try { +// zonesMap = webService.getZonesMap(); +// } catch (CoserBusinessException ex) { +// throw new CoserException("Can't get zone list", ex); +// } +// } + @Override public int getSize() { // -1 for header