r1145 - in trunk: coser-business/src/main/java/fr/ifremer/coser coser-business/src/main/java/fr/ifremer/coser/bean coser-business/src/main/java/fr/ifremer/coser/result coser-business/src/main/java/fr/ifremer/coser/result/repository coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy coser-business/src/main/java/fr/ifremer
Author: tchemit Date: 2014-03-12 18:35:43 +0100 (Wed, 12 Mar 2014) New Revision: 1145 Url: http://forge.codelutin.com/projects/coser/repository/revisions/1145 Log: refs #4664 review Result API (using Command pattern), need to finish the web part Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/MapResult.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/ResultType.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/VoidResult.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryCommandEngine.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryType.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryCommandEngine.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/echobase/command/ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/DeleteResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/ExtractRawDataAndResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/ExtractRawDataCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetAllResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetCommunityIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForCommunityIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForExtractRawDataAndResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForPopulationIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetMapResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetPopulationIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesForMapResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesForPopulationIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesListForCommunityIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesListForExtractRawDataAndResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForCommunityIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForExtractRawDataAndResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForExtractRawDataCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForMapResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForPopulationIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryCommandEngine.java 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/command/ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/DeleteResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/ExtractRawDataAndResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/ExtractRawDataCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetAllResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetCommunityIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForCommunityIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForExtractRawDataAndResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForPopulationIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetMapResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetPopulationIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesForMapResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesForPopulationIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesListForCommunityIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesListForExtractRawDataAndResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForCommunityIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForExtractRawDataCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForMapResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForPopulationIndicatorResultCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesListForExtractRawDataAndResultsCommand.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/AbstractGetIndicatorResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestIndicatorAware.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneListAware.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteResultsRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRawDataAndResultsRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRawDataRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetAllResultsRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetCommunityIndicatorResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForCommunityIndicatorResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForExtractRawDataAndResultsRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForPopulationIndicatorResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetMapResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetPopulationIndicatorResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesForMapResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesForPopulationIndicatorResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesListForCommunityIndicatorResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesListForExtractRawDataAndResultsRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForCommunityIndicatorResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForExtractRawDataAndResultsRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForExtractRawDataRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForMapResultRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForPopulationIndicatorResultRequest.java trunk/coser-business/src/main/resources/META-INF/ trunk/coser-business/src/main/resources/META-INF/services/ trunk/coser-business/src/main/resources/META-INF/services/fr.ifremer.coser.result.repository.ResultRepositoryType trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/ReloadProjectsAction.java Removed: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/RequestUnavailableForProducerException.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/CommunityIndicatorResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/ExtractResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/MapResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/PopulationIndicatorResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/RawDataResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/CommunityIndicatorResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/ExtractResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/MapResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/PopulationIndicatorResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/RawDataResultProducer.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CommunityIndicatorRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/IndicatorRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/MapRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/PopulationIndicatorRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/RawDataRequest.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserServiceContext.java trunk/coser-business/src/main/java/fr/ifremer/coser/DefaultCoserServiceContext.java trunk/coser-business/src/main/java/fr/ifremer/coser/bean/EchoBaseProject.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserResultEngine.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepository.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryProvider.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepository.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryProvider.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepository.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryProvider.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestBuilder.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneAware.java trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryTest.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationContext.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceHelper.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/DeleteProjectsAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/ListProjectsAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/PerformLoginAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDataAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDownloadAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/IndicatorAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/ZoneAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/common/CommonIndicator.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/common/CoserAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapDataAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SpeciesAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ZoneAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDataAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDownloadAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/IndicatorAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/SpeciesAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/ZoneAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/search/ExtractAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/source/SourceAction.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/source/ZoneAction.java trunk/coser-web/src/main/resources/i18n/coser-web_en_GB.properties trunk/coser-web/src/main/resources/i18n/coser-web_fr_FR.properties trunk/coser-web/src/main/resources/log4j.properties trunk/coser-web/src/main/webapp/WEB-INF/content/admin/list-projects.jsp Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserServiceContext.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/CoserServiceContext.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/CoserServiceContext.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -25,6 +25,7 @@ import fr.ifremer.coser.bean.IndicatorMap; import fr.ifremer.coser.bean.ZoneMap; import fr.ifremer.coser.result.repository.ResultRepositoryProvider; +import fr.ifremer.coser.result.repository.ResultRepositoryType; import java.util.Set; @@ -38,8 +39,10 @@ CoserBusinessConfig getConfig(); - Set<ResultRepositoryProvider<?>> getProviders(); + Set<ResultRepositoryType> getResultRepositoryTypes(); + Set<ResultRepositoryProvider<?>> getResultRepositoryProviders(); + IndicatorMap getIndicatorsMap(); ZoneMap getZonesMap(); Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/DefaultCoserServiceContext.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/DefaultCoserServiceContext.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/DefaultCoserServiceContext.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,11 +22,16 @@ * #L% */ +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; import fr.ifremer.coser.bean.IndicatorMap; import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.CoserResultEngine; import fr.ifremer.coser.result.repository.ResultRepositoryProvider; +import fr.ifremer.coser.result.repository.ResultRepositoryType; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepositoryProvider; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepositoryProvider; +import java.util.ServiceLoader; import java.util.Set; /** @@ -43,9 +48,14 @@ protected CoserBusinessConfig config; /** + * Available type of result repositories (loaded by service loader). + */ + protected Set<ResultRepositoryType> resultRepositoryTypes; + + /** * Result repositories providers. */ - protected Set<ResultRepositoryProvider<?>> providers; + protected Set<ResultRepositoryProvider<?>> resultRepositoryProviders; /** * Cache of indicator definition. @@ -61,20 +71,47 @@ this.config = config; } + public static Set<ResultRepositoryProvider<?>> createDefaultRepositoryProviders(CoserBusinessConfig config) { + Preconditions.checkNotNull(config); + Set<ResultRepositoryProvider<?>> result = Sets.newHashSet(); + + // add legacy map repository + Preconditions.checkNotNull(config.getWebMapsProjectsDirectory()); + result.add(new LegacyResultRepositoryProvider(config.getWebMapsProjectsDirectory())); + + // add legacy indicators repository + Preconditions.checkNotNull(config.getWebIndicatorsProjectsDirectory()); + result.add(new LegacyResultRepositoryProvider(config.getWebIndicatorsProjectsDirectory())); + + // add EchoBase repository + Preconditions.checkNotNull(config.getWebEchobaseProjectsDirectory()); + result.add(new EchoBaseResultRepositoryProvider(config.getWebEchobaseProjectsDirectory())); + return result; + } + @Override public CoserBusinessConfig getConfig() { return config; } @Override - public Set<ResultRepositoryProvider<?>> getProviders() { - if (providers == null) { - providers = CoserResultEngine.createDefaultRepositoryProviders(config); + public Set<ResultRepositoryType> getResultRepositoryTypes() { + if (resultRepositoryTypes == null) { + ServiceLoader<ResultRepositoryType> loader = ServiceLoader.load(ResultRepositoryType.class); + resultRepositoryTypes = Sets.newHashSet(loader); } - return providers; + return resultRepositoryTypes; } @Override + public Set<ResultRepositoryProvider<?>> getResultRepositoryProviders() { + if (resultRepositoryProviders == null) { + resultRepositoryProviders = createDefaultRepositoryProviders(config); + } + return resultRepositoryProviders; + } + + @Override public IndicatorMap getIndicatorsMap() { if (indicatorsMap == null) { indicatorsMap = new IndicatorMap(config.getWebIndicatorsFile()); 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-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/EchoBaseProject.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -71,6 +71,9 @@ protected Date creationDate; + /** Result publiable. */ + protected boolean publiableResult; + public EchoBaseProject(File basedir) { this.basedir = basedir; } @@ -131,6 +134,14 @@ this.creationDate = creationDate; } + public boolean isPubliableResult() { + return publiableResult; + } + + public void setPubliableResult(boolean publiableResult) { + this.publiableResult = publiableResult; + } + public File getSpeciesDefinitionFile() { return new File(basedir, "species.csv"); } @@ -207,6 +218,8 @@ if (creationDate != null) { props.setProperty("project.creationDate", String.valueOf(creationDate.getTime())); } + props.setProperty("project.publiableResult", String.valueOf(publiableResult)); + return props; } @@ -230,6 +243,10 @@ Date date = new Date(Long.parseLong(props.getProperty("project.creationDate"))); setCreationDate(date); } + if (props.containsKey("project.publiableResult")) { + boolean v = Boolean.valueOf(props.getProperty("project.publiableResult")); + setPubliableResult(v); + } } public static FilenameFilter newMapSpeciesFilenameFilter(String surveyName) { Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserResultEngine.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserResultEngine.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserResultEngine.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -26,13 +26,11 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; -import fr.ifremer.coser.CoserBusinessConfig; import fr.ifremer.coser.CoserServiceContext; import fr.ifremer.coser.result.repository.ResultRepository; +import fr.ifremer.coser.result.repository.ResultRepositoryCommandEngine; import fr.ifremer.coser.result.repository.ResultRepositoryProvider; -import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepositoryProvider; -import fr.ifremer.coser.result.repository.legacy.LegacyResultRepositoryProvider; -import org.apache.commons.collections4.MapUtils; +import fr.ifremer.coser.result.repository.ResultRepositoryType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -41,16 +39,13 @@ import java.util.Set; /** - * To request some results on the web server side. + * To execute command all over coser result repositories. * <p/> * This new API will let us to define any result format to be queried. * <p/> * Created on 3/4/14. * * @author Tony Chemit <chemit@codelutin.com> - * @see ResultRepositoryProvider - * @see ResultRepository - * @see CoserResult * @since 1.5 */ public class CoserResultEngine { @@ -58,31 +53,8 @@ /** Logger. */ private static final Log log = LogFactory.getLog(CoserResultEngine.class); - public static Set<ResultRepositoryProvider<?>> createDefaultRepositoryProviders(CoserBusinessConfig config) { - Preconditions.checkNotNull(config); - Set<ResultRepositoryProvider<?>> result = Sets.newHashSet(); + protected Set<ResultRepositoryCommandEngine> repositories; - // add legacy map repository - Preconditions.checkNotNull(config.getWebMapsProjectsDirectory()); - result.add(new LegacyResultRepositoryProvider(config.getWebMapsProjectsDirectory())); - - // add legacy indicators repository - Preconditions.checkNotNull(config.getWebIndicatorsProjectsDirectory()); - result.add(new LegacyResultRepositoryProvider(config.getWebIndicatorsProjectsDirectory())); - - // add EchoBase repository - Preconditions.checkNotNull(config.getWebEchobaseProjectsDirectory()); - result.add(new EchoBaseResultRepositoryProvider(config.getWebEchobaseProjectsDirectory())); - return result; - } - - /** - * Result repositories loaded lazy from their provider. - * - * @see #getRepositories() - */ - protected Set<ResultRepository> repositories; - protected final CoserServiceContext serviceContext; public CoserResultEngine(CoserServiceContext serviceContext) { @@ -90,84 +62,96 @@ this.serviceContext = serviceContext; } + public Map<String, ResultRepositoryType> getRepositoryTypes() { + Map<String, ResultRepositoryType> result = Maps.newHashMap(); + for (ResultRepositoryType resultRepositoryType : serviceContext.getResultRepositoryTypes()) { + result.put(resultRepositoryType.getId(), resultRepositoryType); + } + return result; + } + public void resetRepositories() { this.repositories = null; } - public Map<String, String> getAvailableExtractTypes() { - Map<String, String> result = Maps.newLinkedHashMap(); - return result; - } + public CoserResult getUniqueResult(CoserRequest request) throws DuplicatedResultException { - public Map<String, String> getAvailableZones(CoserRequest request) { - Map<String, String> result = Maps.newHashMap(); - for (ResultRepository repository : getRepositories()) { - Map<String, String> resultForRepository = repository.getAvailableZones(request); - if (MapUtils.isNotEmpty(resultForRepository)) { - result.putAll(resultForRepository); - } - } - return result; - } + Preconditions.checkArgument(request.isFilled()); - public Map<String, String> getAvailableSpecies(CoserRequest request) { - Map<String, String> result = Maps.newHashMap(); - for (ResultRepository repository : getRepositories()) { - Map<String, String> resultForRepository = repository.getAvailableSpecies(request); - if (MapUtils.isNotEmpty(resultForRepository)) { - result.putAll(resultForRepository); - } + ResultRepositoryCommandEngine repository = getMatchingRepository(request); + + if (repository == null) { + throw new NoResultRepositoryFoundException("No result repository matching request", request); } + CoserResult result = repository.executeRequest(request); + if (result == null) { + throw new NoResultFoundException(repository.getResultRepository().getId(), request); + } return result; } - public Map<String, String> getAvailableIndicators(CoserRequest request) { - Map<String, String> result = Maps.newHashMap(); - for (ResultRepository repository : getRepositories()) { - Map<String, String> resultForRepository = repository.getAvailableIndicators(request); - if (MapUtils.isNotEmpty(resultForRepository)) { - result.putAll(resultForRepository); + public List<CoserResult> getMultipleResult(CoserRequest request) throws DuplicatedResultException { + + Preconditions.checkArgument(request.isFilled()); + + List<CoserResult> result = Lists.newArrayList(); + for (ResultRepositoryCommandEngine repository : getRepositories()) { + if (repository.acceptRequest(request)) { + + CoserResult repositoryResult = repository.executeRequest(request); + result.add(repositoryResult); } } return result; } - public CoserResult getResult(CoserRequest request) throws DuplicatedResultException { + protected ResultRepositoryCommandEngine getMatchingRepository(CoserRequest request) throws DuplicatedResultException { - Preconditions.checkArgument(request.isFilled()); + List<ResultRepositoryCommandEngine> repositoryList = Lists.newArrayList(); - ResultRepository repository = getMatchingRepository(request); + for (ResultRepositoryCommandEngine resultRepository : getRepositories()) { - if (repository == null) { - throw new NoResultRepositoryFoundException("No result repository matching request", request); + if (resultRepository.acceptRequest(request)) { + repositoryList.add(resultRepository); + } } - CoserResult result = repository.getResult(request); - if (result == null) { - throw new NoResultFoundException(repository.getId(), request); + + ResultRepositoryCommandEngine repository; + switch (repositoryList.size()) { + case 0: + repository = null; + break; + case 1: + repository = repositoryList.get(0); + break; + default: + throw new DuplicatedResultException( + repositoryList.toArray(new ResultRepository[repositoryList.size()])); } - return result; + return repository; } - protected Set<ResultRepository> getRepositories() { + protected Set<ResultRepositoryCommandEngine> getRepositories() { if (repositories == null) { Set<String> ids = Sets.newHashSet(); repositories = Sets.newHashSet(); - for (ResultRepositoryProvider repositoryProvider : serviceContext.getProviders()) { + for (ResultRepositoryProvider repositoryProvider : serviceContext.getResultRepositoryProviders()) { Set<ResultRepository> resultRepositories = repositoryProvider.loadRepositories(serviceContext); // check all repository use a unique id for (ResultRepository resultRepository : resultRepositories) { String id = resultRepository.getId(); if (log.isDebugEnabled()) { - log.debug("Try to register resultrepository: " + id); + log.debug("Try to register result Repository: " + id); } if (!ids.add(id)) { // there is already a repository with this id throw new ResultRepositoryInitializationException(repositoryProvider, "Duplicate result repository with id: " + id, null); } + ResultRepositoryCommandEngine repositoryCommandEngine = repositoryProvider.newEngine(resultRepository); + repositories.add(repositoryCommandEngine); } - repositories.addAll(resultRepositories); } if (log.isInfoEnabled()) { log.info("Found " + repositories.size() + " result repository(ies)."); @@ -175,30 +159,4 @@ } return repositories; } - - protected ResultRepository getMatchingRepository(CoserRequest request) throws DuplicatedResultException { - - List<ResultRepository> repositoryList = Lists.newArrayList(); - - for (ResultRepository resultRepository : getRepositories()) { - - if (resultRepository.acceptResult(request)) { - repositoryList.add(resultRepository); - } - } - - ResultRepository repository; - switch (repositoryList.size()) { - case 0: - repository = null; - break; - case 1: - repository = repositoryList.get(0); - break; - default: - throw new DuplicatedResultException( - repositoryList.toArray(new ResultRepository[repositoryList.size()])); - } - return repository; - } } Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/MapResult.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/MapResult.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/MapResult.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,56 @@ +package fr.ifremer.coser.result; + +/* + * #%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 java.util.Map; + +/** + * Created on 3/12/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class MapResult implements CoserResult { + + private static final long serialVersionUID = 1L; + + protected final String source; + + protected final Map<String, String> map; + + public MapResult(String source, Map<String, String> map) { + this.map = map; + this.source = source; + } + + @Override + public String getSource() { + return source; + } + + @Override + public Map<String, String> getResult() { + return map; + } + +} \ No newline at end of file Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/MapResult.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/ResultType.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/ResultType.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/ResultType.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,37 @@ +package fr.ifremer.coser.result; + +/* + * #%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% + */ + +/** + * Type of result we can get on a result repository. + * <p/> + * Created on 3/12/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public enum ResultType { + MAP, + INDICATOR, + MAP_AND_INDICATOR +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/ResultType.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/VoidResult.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/VoidResult.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/VoidResult.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,50 @@ +package fr.ifremer.coser.result; + +/* + * #%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% + */ + +/** + * Created on 3/12/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class VoidResult implements CoserResult { + + private static final long serialVersionUID = 1L; + + protected final String source; + + public VoidResult(String source) { + this.source = source; + } + + @Override + public String getSource() { + return source; + } + + @Override + public Void getResult() { + return null; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/VoidResult.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/RequestUnavailableForProducerException.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/RequestUnavailableForProducerException.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/RequestUnavailableForProducerException.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,49 +0,0 @@ -package fr.ifremer.coser.result.repository; - -/* - * #%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% - */ - -/** - * When a request ask a unavailable result of a producer. - * <p/> - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class RequestUnavailableForProducerException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public static RequestUnavailableForProducerException newException(String methodName, ResultProducer<?> producer) { - return new RequestUnavailableForProducerException(methodName, producer.getRepository().getId()); - } - - protected final String methodName; - - protected final String repositoryId; - - protected RequestUnavailableForProducerException(String methodName, String repositoryId) { - this.methodName = methodName; - this.repositoryId = repositoryId; - } -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,52 +0,0 @@ -package fr.ifremer.coser.result.repository; - -/* - * #%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.result.CoserRequest; -import fr.ifremer.coser.result.CoserResult; - -import java.util.Map; - -/** - * To execute a result. - * <p/> - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public interface ResultProducer<R extends CoserRequest> { - - ResultRepository getRepository(); - - boolean acceptResult(R request); - - Map<String, String> getAvailableZones(R request); - - Map<String, String> getAvailableSpecies(R request); - - Map<String, String> getAvailableIndicators(R request); - - CoserResult produceResult(R request); - -} Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepository.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepository.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepository.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,11 +22,6 @@ * #L% */ -import fr.ifremer.coser.result.CoserRequest; -import fr.ifremer.coser.result.CoserResult; - -import java.util.Map; - /** * General contract of a repository of results in CoserWeb. * <p/> @@ -43,43 +38,7 @@ String getId(); /** - * Get all available zones for the given request. - * - * @param request request - * @return all available zones for the given request + * @return the type of result repository */ - <R extends CoserRequest> Map<String, String> getAvailableZones(R request); - - /** - * Get all available species (or speciesList) for the given request. - * - * @param request request - * @return all available species for the given request. - */ - <R extends CoserRequest> Map<String, String> getAvailableSpecies(R request); - - /** - * Get all available indicators for the given request. - * - * @param request request - * @return all available indicators for the given request. - */ - <R extends CoserRequest> Map<String, String> getAvailableIndicators(R request); - - /** - * @param request request to test - * @return {@code true} if this repository has some result for the given - * request, {@code false} otherwise - */ - <R extends CoserRequest> boolean acceptResult(R request); - - /** - * Get result for the given request. - * <p/> - * We assume here that the repository has a result for the given request. - * - * @param request request to obtain result - * @return the result for the given request - */ - <R extends CoserRequest> CoserResult getResult(R request); + ResultRepositoryType getResultRepositoryType(); } Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,50 @@ +package fr.ifremer.coser.result.repository; + +/* + * #%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.result.CoserRequest; +import fr.ifremer.coser.result.CoserResult; + +/** + * To execute a command on a result. + * <p/> + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public interface ResultRepositoryCommand<Repo extends ResultRepository, Request extends CoserRequest> { + + Class<Request> getRequestType(); + + boolean accept(Repo repository, Request request); + + CoserResult execute(Repo repository, Request request); + +// Map<String, String> getAvailableZones(Repo repository, Request request); +// +// Map<String, String> getAvailableSpecies(Repo repository, Request request); +// +// Map<String, String> getAvailableIndicators(Repo repository, Request request); + +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryCommandEngine.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryCommandEngine.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryCommandEngine.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,56 @@ +package fr.ifremer.coser.result.repository; + +/* + * #%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 fr.ifremer.coser.result.CoserRequest; +import fr.ifremer.coser.result.CoserResult; + +/** + * To execute commands on a result repository. + * <p/> + * Created on 3/12/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public interface ResultRepositoryCommandEngine { + + ResultRepository getResultRepository(); + + /** + * @param request request to test + * @return {@code true} if this repository has some result for the given + * request, {@code false} otherwise + */ + <R extends CoserRequest> boolean acceptRequest(R request); + + /** + * Execute given request. + * <p/> + * We assume here that the repository has a result for the given request. + * + * @param request request to execute + * @return the result for the given request + */ + <R extends CoserRequest> CoserResult executeRequest(R request); +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryCommandEngine.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/ResultRepositoryProvider.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryProvider.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryProvider.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -42,4 +42,6 @@ * @return the set of provided result repositories. */ Set<R> loadRepositories(CoserServiceContext serviceContext) throws ResultRepositoryInitializationException; + + ResultRepositoryCommandEngine newEngine(R repository); } Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryType.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryType.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryType.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,50 @@ +package fr.ifremer.coser.result.repository; + +/* + * #%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 fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.request.GetAllResultsRequest; + +import java.io.Serializable; +import java.util.Set; + +/** + * To define a new type of result repository. + * <p/> + * This contract does nothing in special, but is just loaded by + * a service loader to know all possible result repositories type. + * <p/> + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @see GetAllResultsRequest + * @since 1.5 + */ +public interface ResultRepositoryType extends Serializable { + + String getId(); + + String getLabelKey(); + + Set<ResultType> getResultTypes(); +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryType.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/CommunityIndicatorResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/CommunityIndicatorResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/CommunityIndicatorResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,441 +0,0 @@ -package fr.ifremer.coser.result.repository.echobase; - -/* - * #%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.CoserTechnicalException; -import fr.ifremer.coser.bean.EchoBaseProject; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.Reports; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.CommunityIndicatorRequest; -import fr.ifremer.coser.storage.DataStorage; -import fr.ifremer.coser.storage.DataStorages; -import fr.ifremer.coser.storage.MemoryDataStorage; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.CategoryAxis; -import org.jfree.chart.axis.CategoryLabelPositions; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.CategoryItemRenderer; -import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; -import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; -import org.nuiton.util.FileUtil; -import org.nuiton.util.ZipUtil; - -import java.awt.Color; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class CommunityIndicatorResultProducer implements ResultProducer<CommunityIndicatorRequest> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(CommunityIndicatorResultProducer.class); - - protected final EchoBaseResultRepository repository; - - protected final Reports reports; - - protected final EchoBaseProject project; - - public CommunityIndicatorResultProducer(EchoBaseResultRepository repository) { - this.repository = repository; - this.project = repository.project; - this.reports = repository.reports; - } - - @Override - public EchoBaseResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(CommunityIndicatorRequest request) { - return repository.matchFacade(request) && - repository.matchZone(request) && - matchIndicatorAndSpeciesList(request); - } - - @Override - public Map<String, String> getAvailableZones(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - - boolean match = repository.matchFacade(request); - - Map<String, String> result = null; - if (match) { - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); - result = zonesMap.getSubZonesMap(project.getZoneName(), allowedZones); - } - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - Preconditions.checkNotNull(request.getIndicator()); - - boolean match = repository.matchFacade(request) && - repository.matchZone(request) && - matchIndicator(request); - - Map<String, String> result = null; - - if (match) { - // get all speciesList for given facade + zone + indicator - Set<String> speciesList = repository.getCommunityIndicatorSpecies(request.getIndicator()); - result = repository.getSpeciesMap().getSpeciesSubMap(speciesList); - } - return result; - } - - @Override - public Map<String, String> getAvailableIndicators(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - - Map<String, String> result = null; - boolean match = repository.matchFacade(request) && repository.matchZone(request); - if (match) { - - // get all indicators for given facade + zone - Set<String> indicatorList = repository.getCommunityIndicators(); - result = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); - } - return result; - } - - @Override - public FileResult produceResult(CommunityIndicatorRequest r) { - - File file = null; - switch (r.getResultType()) { - case DATA: - file = getCommunityIndicatorDataFile(r.getLocale(), - r.getIndicator(), - r.getSpecies()); - break; - - case GRAPH: - file = getCommunityIndicatorGraphFile(r.getLocale(), - r.getZone(), - r.getIndicator(), - r.getSpecies()); - break; - } - FileResult result = new FileResult(repository.getId(), file); - return result; - } - - - protected File getCommunityIndicatorDataFile(Locale locale, - String indicator, - String speciesList) { - - try { - - File tempDir = FileUtil.createTempDirectory("coser-chart-population-indicator", "-tmp"); - - File baseDir = new File(tempDir, project.getSurveyName()); - FileUtils.forceMkdir(baseDir); - - // ajout du fichier csv avec les indicateurs - DataStorage dataStorage = new MemoryDataStorage(); - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(false); - - // add header - dataStorage.add(iterator.next()); - - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { - dataStorage.add(tuple); - } - } - File csvFile = DataStorages.save(dataStorage, "coser-chart-community-indicator", - ".csv" - ); - - File csvFileCopied = new File(baseDir, indicator + ".csv"); - FileUtils.copyFile(csvFile, csvFileCopied); - FileUtils.forceDelete(csvFile); - - //TODO See what to generate here (we don't have any selection in echobase results). -// // ajout du fichier d'information sur les espèces incluses dans -// // les calculs des indicateurs de communautés -// // load project (without data to get reftax data) -// Project project = path.getProject(); -// Selection selection = path.getSelection(); -// File metaFile = webService.generateMetaFilePDF(project, -// selection, -// resultDirectory, -// rSufiResult, -// indicator, -// locale); -// File metaFileCopied = new File(baseDir, "Information.pdf"); -// FileUtils.copyFile(metaFile, metaFileCopied); - - // make zip - File result = File.createTempFile("coser-chart-community-indicator", ".zip"); - result.deleteOnExit(); - ZipUtil.compress(result, baseDir); - - // clean directory - FileUtils.deleteDirectory(tempDir); - return result; - } catch (Exception e) { - throw new CoserTechnicalException("Can't create zip file", e); - } - } - - protected File getCommunityIndicatorGraphFile(Locale locale, - String zone, - String indicator, - String speciesList) { - - // indicator list to take care - // pour avoir une valeur non nulle si list est null - // on prend dans ce cas la premiere valeur trouvée - String localList = speciesList; - - if (log.isDebugEnabled()) { - log.debug("Searching list for indicator : " + indicator); - } - - int multiplicator = 1; - int minYear = Integer.MAX_VALUE; - int maxYear = Integer.MIN_VALUE; - boolean indicatorFound = false; - Map<Integer, Double[]> graphData = new HashMap<Integer, Double[]>(); - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - // Campagne Indicateur Liste Strate Annee Estimation EcartType CV - String[] tuple = iterator.next(); - String indicatorList = tuple[2]; - - if (repository.matchIndicatorIndicator(tuple, indicator)) { - indicatorFound = true; - - // si pas de list selectionnée, on prend la premiere - if (StringUtils.isBlank(localList)) { - localList = indicatorList; - } - - if (indicatorList.equals(localList)) { - Double estimation = Double.parseDouble(tuple[5]); - Double ecart = Double.parseDouble(tuple[6]); - int year = Integer.parseInt(tuple[4]); - - if (year < minYear) { - minYear = year; - } - if (year > maxYear) { - maxYear = year; - } - graphData.put(year, new Double[]{estimation, ecart}); - - // si les données sont énormes, on affiche les données - // / multiplicator et on le mentionne dans la légende - if (estimation > 1e9) { - multiplicator = 1000000; - } - if (estimation > 1e6 && multiplicator < 1000000) { - multiplicator = 1000; - } - } - } - } - - File result = null; - - // avec l'extraction des données, on peut demander a générer un graphique - // sur un indicateur qui n'est pas présent dans le projet courant, - // dans ce cas, on retourne null - if (indicatorFound) { - - String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); - String indicatorName = repository.getIndicatorsMap().getIndicatorValue(indicator, locale); - String unit = repository.getIndicatorsMap().getIndicatorUnit(indicator); - - // get graph title - String chartTitle = zoneDisplayName; - chartTitle += " - " + indicatorName; - - // ajout de la traduction de la liste d'indicateur - // les liste sont a1, T1, T2 ... - String listLetter = String.valueOf(localList.charAt(0)); - Iterator<String[]> typeIterator = repository.getSpeciesMap().iterator(true); - while (typeIterator.hasNext()) { - // "Types";"Commentaire";"NumSys min";"NumSys max";"Code" - String[] tuple = typeIterator.next(); - if (tuple[4].equals(listLetter)) { - /// gestion du groupe "Tous" - // cas special, c'est la seule valeur du fichier - // code type espece qui a besoin d'une traduction - if (tuple[4].equalsIgnoreCase("T")) { - if ("fr".equals(locale.getLanguage())) { - chartTitle += " - " + "Tous Liste " + localList.charAt(1); - } else if ("es".equals(locale.getLanguage())) { - chartTitle += " - " + "Todo Lista " + localList.charAt(1); - } else { - chartTitle += " - " + "All List " + localList.charAt(1); - } - } else { - // ajout de la traduction du nom de liste plus le numéro - if ("fr".equals(locale.getLanguage())) { - chartTitle += " - " + tuple[0] + " Liste " + localList.charAt(1); - } else if ("es".equals(locale.getLanguage())) { - chartTitle += " - " + tuple[0] + " Lista " + localList.charAt(1); - } else { - chartTitle += " - " + tuple[0] + " List " + localList.charAt(1); - } - } - break; - } - } - - // generate dataset with sorted data - DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); - for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { - Double[] entry = graphData.get(indexYear); - if (entry != null) { - Double estimation = entry[0] / multiplicator; - Double ecart = entry[1] / multiplicator; - statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); - } else { - statisticalDataset.add(null, null, "Serie1", indexYear); - } - } - - // configure chart - //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); - String yearAxis = reports.getYearChartTitle(locale); - - CategoryAxis categoryAxis = new CategoryAxis(yearAxis); - categoryAxis.setCategoryMargin(0); - categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); - // label horizontaux - String legendY = indicatorName; - if (multiplicator != 1) { - // affiche par exemple : cm * 1000 - legendY += " (" + unit + "*" + multiplicator + ")"; - } else if (StringUtils.isNotEmpty(unit)) { - legendY += " (" + unit + ")"; - } - ValueAxis valueAxis = new NumberAxis(legendY); - valueAxis.setUpperMargin(0.1); - - CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); - - // n'affiche pas les nombre sur le graphique - //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); - //renderer.setBaseItemLabelGenerator(itemLabelGenerator); - //renderer.setBaseItemLabelsVisible(true); - - CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); - plot.setOrientation(PlotOrientation.VERTICAL); - JFreeChart chart = new JFreeChart(chartTitle, - JFreeChart.DEFAULT_TITLE_FONT, plot, true); - - // remove series legend - chart.removeLegend(); - // white background - chart.setBackgroundPaint(Color.WHITE); - - try { - result = File.createTempFile("coser-chart-community-indicator-", ".png"); - result.deleteOnExit(); - ChartUtilities.saveChartAsPNG(result, chart, 800, 400); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't save chart", ex); - } - } - - return result; - } - - // --------------------------------------------------------------------- // - // --- Matchers -------------------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchIndicator(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getIndicator()); - - String indicator = request.getIndicator(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorIndicator(tuple, indicator)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchIndicatorAndSpeciesList(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getIndicator()); - Preconditions.checkNotNull(request.getSpecies()); - - String indicator = request.getIndicator(); - String speciesList = request.getSpecies(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { - result = true; - break; - } - } - return result; - } -} Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepository.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepository.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepository.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -25,25 +25,16 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; import com.google.common.collect.Sets; import fr.ifremer.coser.CoserServiceContext; import fr.ifremer.coser.bean.EchoBaseProject; import fr.ifremer.coser.bean.IndicatorMap; import fr.ifremer.coser.bean.SpeciesMap; import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.CoserRequest; -import fr.ifremer.coser.result.CoserResult; import fr.ifremer.coser.result.Reports; -import fr.ifremer.coser.result.repository.ResultProducer; import fr.ifremer.coser.result.repository.ResultRepository; -import fr.ifremer.coser.result.request.CommunityIndicatorRequest; import fr.ifremer.coser.result.request.CoserRequestFacadeAware; import fr.ifremer.coser.result.request.CoserRequestZoneAware; -import fr.ifremer.coser.result.request.ExtractRequest; -import fr.ifremer.coser.result.request.MapRequest; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; -import fr.ifremer.coser.result.request.RawDataRequest; import fr.ifremer.coser.storage.DataStorage; import fr.ifremer.coser.storage.DataStorages; import org.apache.commons.logging.Log; @@ -53,7 +44,6 @@ import java.io.FilenameFilter; import java.util.Iterator; import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -68,11 +58,6 @@ private static final Log log = LogFactory.getLog(EchoBaseResultRepository.class); /** - * Id of result source. - */ - public static final String ID = "echobase"; - - /** * Project definition. */ protected final EchoBaseProject project; @@ -112,12 +97,11 @@ */ protected final Reports reports; - protected final Map<String, ResultProducer<?>> resultProducers; - - public EchoBaseResultRepository(CoserServiceContext serviceContext, EchoBaseProject project) { - this.serviceContext = serviceContext; + public EchoBaseResultRepository(CoserServiceContext serviceContext, + EchoBaseProject project) { Preconditions.checkNotNull(serviceContext); Preconditions.checkNotNull(project); + this.serviceContext = serviceContext; this.project = project; this.mapsDirectory = project.getMapsDirectory(); this.reports = new Reports(); @@ -127,13 +111,6 @@ this.speciesCodeToMapFile = EchoBaseProject.newSpeciesCodeToMapFileName(surveyName); this.mapSpeciesFilenameFilter = EchoBaseProject.newMapSpeciesFilenameFilter(surveyName); - this.resultProducers = Maps.newHashMap(); - this.resultProducers.put(MapRequest.class.getName(), new MapResultProducer(this)); - this.resultProducers.put(CommunityIndicatorRequest.class.getName(), new CommunityIndicatorResultProducer(this)); - this.resultProducers.put(PopulationIndicatorRequest.class.getName(), new PopulationIndicatorResultProducer(this)); - this.resultProducers.put(RawDataRequest.class.getName(), new RawDataResultProducer(this)); - this.resultProducers.put(ExtractRequest.class.getName(), new ExtractResultProducer(this)); - if (log.isInfoEnabled()) { log.info("New result repository: " + getId()); } @@ -145,95 +122,77 @@ @Override public String getId() { - return ID + "::" + project.getBasedir(); + return EchoBaseResultRepositoryType.ID + "::" + project.getBasedir(); } @Override - public <R extends CoserRequest> Map<String, String> getAvailableZones(R request) { - Preconditions.checkNotNull(request); - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); + public EchoBaseResultRepositoryType getResultRepositoryType() { + return EchoBaseResultRepositoryType.INSTANCE; + } - Map<String, String> result = resultProducer.getAvailableZones(request); - return result; + public File getBasedir() { + return project.getBasedir(); } - @Override - public <R extends CoserRequest> Map<String, String> getAvailableSpecies(R request) { - Preconditions.checkNotNull(request); - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); + public EchoBaseProject getProject() { + return project; + } - Map<String, String> result = resultProducer.getAvailableSpecies(request); - return result; + public String getProjectName() { + return project.getName(); } - @Override - public <R extends CoserRequest> Map<String, String> getAvailableIndicators(R request) { - Preconditions.checkNotNull(request); - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); + public Reports getReports() { + return reports; + } - Map<String, String> result = resultProducer.getAvailableIndicators(request); - return result; + public String getSurveyName() { + return project.getSurveyName(); } - @Override - public <R extends CoserRequest> boolean acceptResult(R request) { - Preconditions.checkNotNull(request); - Preconditions.checkArgument(request.isFilled()); + public String getZone() { + return project.getZoneName(); + } - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); - boolean result = resultProducer.acceptResult(request); - return result; + public boolean isMapsResult() { + return true; } - @Override - public <R extends CoserRequest> CoserResult getResult(R request) { - Preconditions.checkNotNull(request); - Preconditions.checkArgument(request.isFilled()); - Preconditions.checkArgument(acceptResult(request)); - - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); - - CoserResult result = resultProducer.produceResult(request); - return result; + public boolean isIndicatorsResult() { + return true; } - protected <R extends CoserRequest> ResultProducer<R> getProducer(R request) { - String requestTypeName = request.getClass().getName(); - return (ResultProducer<R>) resultProducers.get(requestTypeName); + public boolean isPubliableResult() { + return project.isPubliableResult(); } // --------------------------------------------------------------------- // // --- Matchers -------------------------------------------------------- // // --------------------------------------------------------------------- // - protected boolean matchFacade(CoserRequestFacadeAware request) { + public boolean matchFacade(CoserRequestFacadeAware request) { return project.getFacadeName().equals(request.getFacade()); } - protected boolean matchZone(CoserRequestZoneAware request) { + public boolean matchZone(CoserRequestZoneAware request) { return project.getZoneName().equals(request.getZone()); } - protected boolean matchIndicatorSpecies(String[] tuple, String species) { + public boolean matchIndicatorSpecies(String[] tuple, String species) { String speciesCode = tuple[3]; boolean result = species.equals(speciesCode); return result; } - protected boolean matchIndicatorIndicator(String[] tuple, String indicator) { + public boolean matchIndicatorIndicator(String[] tuple, String indicator) { String indicatorCode = tuple[1]; boolean result = indicator.equals(indicatorCode); return result; } - protected boolean matchIndicatorSpeciesAndIndicator(String[] tuple, - String species, - String indicator) { + public boolean matchIndicatorSpeciesAndIndicator(String[] tuple, + String species, + String indicator) { String speciesCode = tuple[3]; String indicatorCode = tuple[1]; boolean result = species.equals(speciesCode) && @@ -241,9 +200,9 @@ return result; } - protected boolean matchCommunityIndicatorAndSpeciesList(String[] tuple, - String indicator, - String speciesList) { + public boolean matchCommunityIndicatorAndSpeciesList(String[] tuple, + String indicator, + String speciesList) { String indicatorCode = tuple[1]; String speciesListCode = tuple[2]; boolean result = indicator.equals(indicatorCode) && @@ -251,15 +210,15 @@ return result; } - protected boolean matchIndicatorList(String[] tuple, List<String> indicatorList) { + public boolean matchIndicatorList(String[] tuple, List<String> indicatorList) { String indicatorCode = tuple[1]; boolean result = indicatorList.contains(indicatorCode); return result; } - protected boolean matchIndicatorListAndSpeciesList(String[] tuple, - List<String> indicatorList, - List<String> speciesList) { + public boolean matchIndicatorListAndSpeciesList(String[] tuple, + List<String> indicatorList, + List<String> speciesList) { String indicatorCode = tuple[1]; String speciesCode = tuple[3]; boolean result = indicatorList.contains(indicatorCode) && @@ -271,7 +230,7 @@ // --- Get Map result -------------------------------------------------- // // --------------------------------------------------------------------- // - protected File getMapSpeciesFile(String species) { + public File getMapSpeciesFile(String species) { String fileName = speciesCodeToMapFile.apply(species); File file = fileName == null ? null : new File(mapsDirectory, fileName); return file; @@ -281,7 +240,7 @@ // --- Get species lists ----------------------------------------------- // // --------------------------------------------------------------------- // - protected Set<String> getMapSpecies() { + public Set<String> getMapSpecies() { Set<String> result = Sets.newHashSet(); File[] files = project.getMapsDirectory().listFiles(mapSpeciesFilenameFilter); if (files != null) { @@ -291,7 +250,7 @@ return result; } - protected Set<String> getPopulationIndicatorSpecies() { + public Set<String> getPopulationIndicatorSpecies() { Set<String> result = Sets.newHashSet(); Iterator<String[]> iterator = loadPopulationIndicatorStorage(true); while (iterator.hasNext()) { @@ -302,7 +261,7 @@ return result; } - protected Set<String> getCommunityIndicatorSpecies() { + public Set<String> getCommunityIndicatorSpecies() { Iterator<String[]> iterator = loadCommunityIndicatorStorage(true); Set<String> result = Sets.newHashSet(); while (iterator.hasNext()) { @@ -313,7 +272,7 @@ return result; } - protected Set<String> getCommunityIndicatorSpecies(String indicator) { + public Set<String> getCommunityIndicatorSpecies(String indicator) { Iterator<String[]> iterator = loadCommunityIndicatorStorage(true); Set<String> result = Sets.newHashSet(); while (iterator.hasNext()) { @@ -330,7 +289,7 @@ // --- Get indicator lists --------------------------------------------- // // --------------------------------------------------------------------- // - protected Set<String> getCommunityIndicators() { + public Set<String> getCommunityIndicators() { Iterator<String[]> iterator = loadCommunityIndicatorStorage(true); Set<String> result = Sets.newHashSet(); while (iterator.hasNext()) { @@ -341,7 +300,7 @@ return result; } - protected Set<String> getPopulationIndicators() { + public Set<String> getPopulationIndicators() { Iterator<String[]> iterator = loadPopulationIndicatorStorage(true); Set<String> result = Sets.newHashSet(); while (iterator.hasNext()) { @@ -369,7 +328,7 @@ // --- Get definition maps --------------------------------------------- // // --------------------------------------------------------------------- // - protected SpeciesMap getSpeciesMap() { + public SpeciesMap getSpeciesMap() { if (speciesMap == null) { File file = project.getSpeciesDefinitionFile(); speciesMap = new SpeciesMap(file); @@ -377,7 +336,7 @@ return speciesMap; } - protected IndicatorMap getIndicatorsMap() { + public IndicatorMap getIndicatorsMap() { return serviceContext.getIndicatorsMap(); } @@ -389,7 +348,7 @@ // --- storage util methods -------------------------------------------- // // --------------------------------------------------------------------- // - protected Iterator<String[]> loadPopulationIndicatorStorage(boolean skipFirstLine) { + public Iterator<String[]> loadPopulationIndicatorStorage(boolean skipFirstLine) { File file = project.getPopulationIndicatorsFile(); // Campagne Indicateur Liste Espece Strate Annee Estimation EcartType CV DataStorage dataStorage = DataStorages.load(file); @@ -397,7 +356,7 @@ return iterator; } - protected Iterator<String[]> loadCommunityIndicatorStorage(boolean skipFirstLine) { + public Iterator<String[]> loadCommunityIndicatorStorage(boolean skipFirstLine) { File file = project.getCommunityIndicatorsFile(); // Campagne Indicateur Liste Espece Strate Annee Estimation EcartType CV DataStorage dataStorage = DataStorages.load(file); Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryCommandEngine.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryCommandEngine.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryCommandEngine.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,135 @@ +package fr.ifremer.coser.result.repository.echobase; + +/* + * #%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 com.google.common.collect.Maps; +import fr.ifremer.coser.result.CoserRequest; +import fr.ifremer.coser.result.CoserResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.ResultRepositoryCommandEngine; +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; +import fr.ifremer.coser.result.repository.echobase.command.GetAllResultsCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetCommunityIndicatorResultCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetIndicatorsForCommunityIndicatorResultCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetIndicatorsForExtractRawDataAndResultsCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetIndicatorsForPopulationIndicatorResultCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetMapResultCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetPopulationIndicatorResultCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetSpeciesListForExtractRawDataAndResultsCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetSpeciesForMapResultCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetSpeciesForPopulationIndicatorResultCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetSpeciesListForCommunityIndicatorResultCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetZonesForCommunityIndicatorResultCommand; +import fr.ifremer.coser.result.repository.echobase.command.GetZonesForExtractRawDataAndResultsCommand; +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 java.util.Map; + +/** + * Created on 3/12/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class EchoBaseResultRepositoryCommandEngine implements ResultRepositoryCommandEngine { + + protected final EchoBaseResultRepository resultRepository; + + protected final Map<String, ResultRepositoryCommand<EchoBaseResultRepository, ?>> commands; + + public EchoBaseResultRepositoryCommandEngine(EchoBaseResultRepository resultRepository) { + this.resultRepository = resultRepository; + this.commands = Maps.newHashMap(); + + // get map result + loadCommand(new GetZonesForMapResultCommand()); + loadCommand(new GetSpeciesForMapResultCommand()); + loadCommand(new GetMapResultCommand()); + + // get community indicator result + loadCommand(new GetZonesForCommunityIndicatorResultCommand()); + loadCommand(new GetIndicatorsForCommunityIndicatorResultCommand()); + loadCommand(new GetSpeciesListForCommunityIndicatorResultCommand()); + loadCommand(new GetCommunityIndicatorResultCommand()); + + // get population indicator result + loadCommand(new GetZonesForPopulationIndicatorResultCommand()); + loadCommand(new GetSpeciesForPopulationIndicatorResultCommand()); + loadCommand(new GetIndicatorsForPopulationIndicatorResultCommand()); + loadCommand(new GetPopulationIndicatorResultCommand()); + + // get all results + loadCommand(new GetAllResultsCommand()); + + // extract raw data + loadCommand(new GetZonesForExtractRawDataCommand()); + loadCommand(new ExtractRawDataCommand()); + + // extract raw data and results + loadCommand(new GetZonesForExtractRawDataAndResultsCommand()); + loadCommand(new GetSpeciesListForExtractRawDataAndResultsCommand()); + loadCommand(new GetIndicatorsForExtractRawDataAndResultsCommand()); + loadCommand(new ExtractRawDataAndResultsCommand()); + + // delete results + loadCommand(new DeleteResultsCommand()); + } + + @Override + public EchoBaseResultRepository getResultRepository() { + return resultRepository; + } + + @Override + public <R extends CoserRequest> boolean acceptRequest(R request) { + + ResultRepositoryCommand<EchoBaseResultRepository, R> command = getCommand(request); + boolean result = command.accept(resultRepository, request); + return result; + } + + @Override + public <R extends CoserRequest> CoserResult executeRequest(R request) { + ResultRepositoryCommand<EchoBaseResultRepository, R> command = getCommand(request); + CoserResult result = command.execute(resultRepository, request); + return result; + } + + protected <R extends CoserRequest> ResultRepositoryCommand<EchoBaseResultRepository, R> getCommand(R request) { + Preconditions.checkNotNull(request); + String requestTypeName = request.getClass().getName(); + ResultRepositoryCommand<EchoBaseResultRepository, ?> resultRepositoryCommand = commands.get(requestTypeName); + Preconditions.checkNotNull(resultRepositoryCommand); + return (ResultRepositoryCommand<EchoBaseResultRepository, R>) resultRepositoryCommand; + } + + protected void loadCommand(ResultRepositoryCommand<EchoBaseResultRepository, ?> command) { + String name = command.getRequestType().getName(); + this.commands.put(name, command); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryCommandEngine.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/echobase/EchoBaseResultRepositoryProvider.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryProvider.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryProvider.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -27,6 +27,7 @@ import fr.ifremer.coser.CoserServiceContext; import fr.ifremer.coser.bean.EchoBaseProject; import fr.ifremer.coser.result.ResultRepositoryInitializationException; +import fr.ifremer.coser.result.repository.ResultRepositoryCommandEngine; import fr.ifremer.coser.result.repository.ResultRepositoryProvider; import org.apache.commons.io.filefilter.AbstractFileFilter; import org.apache.commons.io.filefilter.AndFileFilter; @@ -100,4 +101,9 @@ } return result; } + + @Override + public ResultRepositoryCommandEngine newEngine(EchoBaseResultRepository repository) { + return new EchoBaseResultRepositoryCommandEngine(repository); + } } Added: 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 (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryType.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,65 @@ +package fr.ifremer.coser.result.repository.echobase; + +/* + * #%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.collect.Sets; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.repository.ResultRepositoryType; + +import java.util.Set; + +import static org.nuiton.i18n.I18n.n; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class EchoBaseResultRepositoryType implements ResultRepositoryType { + + /** + * Id of result source. + */ + public static final String ID = "echobase"; + + protected static final EchoBaseResultRepositoryType INSTANCE = new EchoBaseResultRepositoryType(); + + private static final long serialVersionUID = 1L; + + @Override + public String getId() { + return ID; + } + + @Override + public String getLabelKey() { + return n("coser.business.result.repository.type.echobase"); + } + + @Override + public Set<ResultType> getResultTypes() { + return Sets.immutableEnumSet(ResultType.MAP_AND_INDICATOR); + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryType.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/ExtractResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/ExtractResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/ExtractResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,780 +0,0 @@ -package fr.ifremer.coser.result.repository.echobase; - -/* - * #%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.Maps; -import com.google.common.collect.Sets; -import fr.ifremer.coser.CoserTechnicalException; -import fr.ifremer.coser.bean.EchoBaseProject; -import fr.ifremer.coser.bean.IndicatorMap; -import fr.ifremer.coser.bean.SpeciesMap; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.Reports; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.ExtractRequest; -import fr.ifremer.coser.storage.DataStorage; -import fr.ifremer.coser.storage.DataStorages; -import fr.ifremer.coser.storage.MemoryDataStorage; -import fr.ifremer.coser.util.DataType; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.collections4.keyvalue.MultiKey; -import org.apache.commons.collections4.map.MultiKeyMap; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.CategoryAxis; -import org.jfree.chart.axis.CategoryLabelPositions; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.CategoryItemRenderer; -import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; -import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; -import org.nuiton.util.FileUtil; -import org.nuiton.util.ZipUtil; - -import java.awt.Color; -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class ExtractResultProducer implements ResultProducer<ExtractRequest> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ExtractResultProducer.class); - - protected final EchoBaseResultRepository repository; - - protected final Reports reports; - - protected final EchoBaseProject project; - - public ExtractResultProducer(EchoBaseResultRepository repository) { - this.repository = repository; - this.project = repository.project; - this.reports = repository.reports; - } - - @Override - public EchoBaseResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(ExtractRequest request) { - return matchExtractTypeSet(request) && - matchZoneList(request) && - (matchPopulationIndicatorListAndSpeciesList(request) || - matchCommunityIndicatorListAndSpeciesList(request)); - } - - @Override - public Map<String, String> getAvailableZones(ExtractRequest request) { - - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(null); - Map<String, String> result = zonesMap.getSubZonesMap(project.getZoneName(), allowedZones); - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(ExtractRequest request) { - Preconditions.checkNotNull(request.getZoneList()); - - boolean match = matchZoneList(request); - - Map<String, String> result = null; - if (match) { - Set<String> speciesList = Sets.newHashSet(); - - // get all species for population indicators - speciesList.addAll(repository.getPopulationIndicatorSpecies()); - // get all species for community indicators - speciesList.addAll(repository.getCommunityIndicatorSpecies()); - result = repository.getSpeciesMap().getSpeciesSubMap(speciesList); - } - return result; - } - - @Override - public Map<String, String> getAvailableIndicators(ExtractRequest request) { - Preconditions.checkNotNull(request.getZoneList()); - Preconditions.checkNotNull(request.getExtractTypeList()); - - Map<String, String> result = null; - - boolean match = matchZoneList(request); - if (match) { - - Set<String> indicatorList = null; - - if (request.getExtractTypeList().contains(DataType.COMMUNITY)) { - - // get all community indicators for given zone - indicatorList = repository.getCommunityIndicators(); - } else if (request.getExtractTypeList().contains(DataType.POPULATION)) { - - // get all population indicators for given zone - indicatorList = repository.getPopulationIndicators(); - } - - if (indicatorList != null) { - result = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); - } - } - return result; - } - - @Override - public FileResult produceResult(ExtractRequest r) { - - Locale locale = r.getLocale(); - List<String> zoneList = r.getZoneList(); - List<DataType> extractTypeList = r.getExtractTypeList(); - List<String> speciesList = r.getSpeciesList(); - List<String> communityIndicatorList = r.getCommunityIndicatorList(); - List<String> populationIndicatorList = r.getPopulationIndicatorList(); - - File resultZip = null; - File tempDir = null; - try { - tempDir = FileUtil.createTempDirectory("coser-extract-", "-tmp"); - - File subDir = new File(tempDir, "Indicateurs_Ifremer"); - FileUtils.forceMkdir(subDir); - - // les sources se retrouve dans le zip a cote du pdf - if (extractTypeList.contains(DataType.SOURCE)) { - if (log.isDebugEnabled()) { - log.debug("Extracting sources"); - } - File srcDir = new File(subDir, "sources"); - extractSource(srcDir); - } - - // les cartes doivent se retrouver dans le pdf - MultiKeyMap pdfMaps = null; - if (extractTypeList.contains(DataType.MAP)) { - if (log.isDebugEnabled()) { - log.debug("Extracting maps"); - } - String zone = project.getZoneName(); - SpeciesMap speciesMap = repository.getSpeciesMap(); - for (String species : speciesList) { - File mapFile = repository.getMapSpeciesFile(species); - pdfMaps.put(zone, speciesMap.getSpeciesName(species), mapFile); - } - } - - // les graphiques sont également dans le pdf - MultiKeyMap pdfCharts = null; - if (CollectionUtils.isNotEmpty(communityIndicatorList) || - CollectionUtils.isNotEmpty(populationIndicatorList)) { - if (log.isDebugEnabled()) { - log.debug("Extracting charts"); - } - pdfCharts = extractCharts(speciesList, - communityIndicatorList, - populationIndicatorList, - locale); - } - - // generate pdf if necessary - if (MapUtils.isNotEmpty(pdfMaps) || MapUtils.isNotEmpty(pdfCharts)) { - if (log.isDebugEnabled()) { - log.debug("Generated Extract PDF"); - } - reports.generateExtractPDF(subDir, - zoneList, - pdfMaps, - pdfCharts, - repository.getZonesMap(), - locale); - } - - // fichier de décharge en pdf - if (log.isDebugEnabled()) { - log.debug("Generated decharge PDF"); - } - String filename = reports.getDechargeFilename(locale); - File dechargePDF = new File(subDir, filename); - reports.generateDechargePDF(dechargePDF, locale, null, null); - - // make zip - if (log.isDebugEnabled()) { - log.debug("Make final archive"); - } - resultZip = File.createTempFile("coser-extract-", ".zip"); - resultZip.deleteOnExit(); - ZipUtil.compress(resultZip, subDir); - - // clean directory - FileUtils.deleteDirectory(tempDir); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't create zip file", ex); - } finally { - // clean directory - FileUtils.deleteQuietly(tempDir); - } - - FileResult result = new FileResult(repository.getId(), resultZip); - return result; - } - - /** - * Generate raw data after selection in a sub directory (named of the zone) of the given directory. - * - * @param directory where to generate file - */ - protected void extractSource(File directory) { - - //TODO - } - - /** - * Retourne les indicateurs calculés avec leurs traductions scientifique - * pour la zone et l'especes souhaitées. - * - * @param species especes (if {@code null} look for com indicators - * @param comIndicators comIndicator - * @param popIndicators popIndicators - * @param locale locale - * @return la liste des indicateurs (zone, speciesname, [graphfile, graphdata]) - */ - protected MultiKeyMap extractCharts(Collection<String> species, - Collection<String> comIndicators, - Collection<String> popIndicators, - Locale locale) { - - MultiKeyMap chartFileAndDatas = new MultiKeyMap(); - - String zone = project.getZoneName(); - String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); - - if (CollectionUtils.isNotEmpty(comIndicators)) { - Map<String, Pair<File, String>> chartFileAndDataCom = getRsufiResultComCharts(comIndicators, - zoneDisplayName, - repository.getIndicatorsMap(), - locale, - 650, - 430); - // put in multimap as zone,speciesname, data - for (Map.Entry<String, Pair<File, String>> entry : chartFileAndDataCom.entrySet()) { - chartFileAndDatas.put(zone, entry.getKey(), entry.getValue()); - } - } - - if (CollectionUtils.isNotEmpty(popIndicators)) { - Map<String, Pair<File, String>> chartFileAndDataPop = getRsufiResultPopCharts(species, - popIndicators, - zoneDisplayName, - repository.getIndicatorsMap(), - locale, - 650, - 430); - // put in multimap as zone,speciesname, data - for (Map.Entry<String, Pair<File, String>> entry : chartFileAndDataPop.entrySet()) { - chartFileAndDatas.put(zone, entry.getKey(), entry.getValue()); - } - } - - return chartFileAndDatas; - } - - /** - * Generate community graph for selected indicators. - * Used by web ui extraction. - * - * @param indicators indicators to extract - * @param zoneDisplayName zone full name - * @param indicatorMap indicator localized map - * @param locale locale - * @param width graph width - * @param height graph height - * @return maps of generated graph image (temp file) and data indexed by natural key (indicator - species) - */ - public Map<String, Pair<File, String>> getRsufiResultComCharts(Collection<String> indicators, - String zoneDisplayName, - IndicatorMap indicatorMap, - Locale locale, - int width, int height) { - - Map<String, Pair<File, String>> result = Maps.newHashMap(); - - int multiplicator = 1; - int minYear = Integer.MAX_VALUE; - int maxYear = Integer.MIN_VALUE; - - Map<String, Map<Integer, Double[]>> indicatorGraphData = new HashMap<String, Map<Integer, Double[]>>(); - Map<String, String> indicatorLists = new HashMap<String, String>(); - Map<String, DataStorage> indicatorStorages = new HashMap<String, DataStorage>(); - - // Campagne Indicateur Liste Strate Annee Estimation EcartType CV - Iterator<String[]> estComIndIterator = repository.loadCommunityIndicatorStorage(true); - while (estComIndIterator.hasNext()) { - // Campagne Indicateur Liste Strate Annee Estimation EcartType CV - String[] tuple = estComIndIterator.next(); - String indicatorCode = tuple[1]; - String indicatorList = tuple[2]; - - if (indicators.contains(indicatorCode)) { - - // si pas de list selectionnée, on prend la premiere - String localList = indicatorLists.get(indicatorCode); - if (StringUtils.isBlank(localList)) { - localList = indicatorList; - indicatorLists.put(indicatorCode, localList); - } - - if (indicatorList.equals(localList)) { - Double estimation = Double.parseDouble(tuple[5]); - Double ecart = Double.parseDouble(tuple[6]); - int year = Integer.parseInt(tuple[4]); - - if (year < minYear) { - minYear = year; - } - if (year > maxYear) { - maxYear = year; - } - Map<Integer, Double[]> graphData = indicatorGraphData.get(indicatorCode); - if (graphData == null) { - graphData = new HashMap<Integer, Double[]>(); - indicatorGraphData.put(indicatorCode, graphData); - } - graphData.put(year, new Double[]{estimation, ecart}); - - // si les données sont énormes, on affiche les données - // / multiplicator et on le mentionne dans la légende - if (estimation > 1e9) { - multiplicator = 1000000; - } - if (estimation > 1e6 && multiplicator < 1000000) { - multiplicator = 1000; - } - - // for data part - DataStorage subDataStorage = indicatorStorages.get(indicatorCode); - if (subDataStorage == null) { - subDataStorage = new MemoryDataStorage(); - if ("fr".equals(locale.getLanguage())) { - subDataStorage.add(new String[]{"Campagne", "Indice", "Liste", "Strate", "Année", "Estimation", "EcartType", "CV"}); - } else { - subDataStorage.add(new String[]{"Survey", "Index", "List", "Stratum", "Year", "Estimate", "StandardDeviation", "CV"}); - } - indicatorStorages.put(indicatorCode, subDataStorage); - } - subDataStorage.add(tuple); - } - } - } - - // avec l'extraction des données, on peut demander a générer un graphique - // sur un indicateur qui n'est pas présent dans le projet courant, - // dans ce cas, on retourne null - for (String indicator : indicatorGraphData.keySet()) { - // get graph title - String chartTitle = zoneDisplayName; - String indicatorName = indicatorMap.getIndicatorValue(indicator, locale); - String unit = indicatorMap.getIndicatorUnit(indicator); - chartTitle += " - " + indicatorName; - - // ajout de la traduction de la liste d'indicateur - // les liste sont a1, T1, T2 ... - String localList = indicatorLists.get(indicator); - String listLetter = String.valueOf(localList.charAt(0)); - Iterator<String[]> typeIterator = repository.getSpeciesMap().iterator(true); - while (typeIterator.hasNext()) { - // "Types";"Commentaire";"NumSys min";"NumSys max";"Code" - String[] tuple = typeIterator.next(); - if (tuple[4].equals(listLetter)) { - /// gestion du groupe "Tous" - // cas special, c'est la seule valeur du fichier - // code type espece qui a besoin d'une traduction - if (tuple[4].equalsIgnoreCase("T")) { - if ("fr".equals(locale.getLanguage())) { - chartTitle += " - " + "Tous Liste " + localList.charAt(1); - } else if ("es".equals(locale.getLanguage())) { - chartTitle += " - " + "Todo Lista " + localList.charAt(1); - } else { - chartTitle += " - " + "All List " + localList.charAt(1); - } - } else { - // ajout de la traduction du nom de liste plus le numéro - if ("fr".equals(locale.getLanguage())) { - chartTitle += " - " + tuple[0] + " Liste " + localList.charAt(1); - } else if ("es".equals(locale.getLanguage())) { - chartTitle += " - " + tuple[0] + " Lista " + localList.charAt(1); - } else { - chartTitle += " - " + tuple[0] + " List " + localList.charAt(1); - } - } - break; - } - } - - // generate dataset with sorted data - Map<Integer, Double[]> graphData = indicatorGraphData.get(indicator); - DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); - for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { - Double[] entry = graphData.get(indexYear); - if (entry != null) { - Double estimation = entry[0] / multiplicator; - Double ecart = entry[1] / multiplicator; - statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); - } else { - statisticalDataset.add(null, null, "Serie1", indexYear); - } - } - - // configure chart - //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); - String yearAxis = reports.getYearChartTitle(locale); - CategoryAxis categoryAxis = new CategoryAxis(yearAxis); - categoryAxis.setCategoryMargin(0); - categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); - // label horizontaux - String legendY = indicatorName; - if (multiplicator != 1) { - // affiche par exemple : cm * 1000 - legendY += " (" + unit + "*" + multiplicator + ")"; - } else if (StringUtils.isNotEmpty(unit)) { - legendY += " (" + unit + ")"; - } - ValueAxis valueAxis = new NumberAxis(legendY); - valueAxis.setUpperMargin(0.1); - - CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); - - // n'affiche pas les nombre sur le graphique - //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); - //renderer.setBaseItemLabelGenerator(itemLabelGenerator); - //renderer.setBaseItemLabelsVisible(true); - - CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); - plot.setOrientation(PlotOrientation.VERTICAL); - JFreeChart chart = new JFreeChart(chartTitle, - JFreeChart.DEFAULT_TITLE_FONT, plot, true); - - // remove series legend - chart.removeLegend(); - // white background - chart.setBackgroundPaint(Color.WHITE); - - try { - File chartFile = File.createTempFile("coser-community-chart-", ".png"); - chartFile.deleteOnExit(); - ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); - //ByteArrayOutputStream out = new ByteArrayOutputStream(); - //ChartUtilities.writeChartAsPNG(out, chart, width, height); - - // data extraction - DataStorage subDataStorage = indicatorStorages.get(indicator); - StringWriter writer = new StringWriter(); - DataStorages.save(subDataStorage, writer); - - // add chart file dans chart data in result - result.put(indicator, Pair.of(chartFile, writer.toString())); - writer.close(); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't save chart", ex); - } - } - - return result; - } - - /** - * Generate population graph for selected species and indicator. - * - * @param species species to extract - * @param indicators indicators to extract - * @param zoneDisplayName zone full name - * @param indicatorMap indicator localized map - * @param locale locale - * @param width graph width - * @param height graph height - * @return maps of generated graph image (temp file) and data indexed by natural key (indicator - species) - */ - public Map<String, Pair<File, String>> getRsufiResultPopCharts(Collection<String> species, - Collection<String> indicators, - String zoneDisplayName, - IndicatorMap indicatorMap, - Locale locale, - int width, - int height) { - - Map<String, Pair<File, String>> result = Maps.newHashMap(); - - int multiplicator = 1; - int minYear = Integer.MAX_VALUE; - int maxYear = Integer.MIN_VALUE; - - MultiKeyMap indicatorGraphData = new MultiKeyMap(); - MultiKeyMap indicatorStorages = new MultiKeyMap(); - - // Campagne Indicateur Liste Species Strate Annee Estimation EcartType CV - Iterator<String[]> estPopIndIterator = repository.loadPopulationIndicatorStorage(true); - while (estPopIndIterator.hasNext()) { - String[] tuple = estPopIndIterator.next(); - - String speciesCode = tuple[3]; - String indicatorCode = tuple[1]; - if (species.contains(speciesCode) && indicators.contains(indicatorCode)) { - - // XXX echatellier, maybe take care of list here ? - - Double estimation = Double.parseDouble(tuple[6]); - Double ecart = Double.parseDouble(tuple[7]); - int year = Integer.parseInt(tuple[5]); - - if (year < minYear) { - minYear = year; - } - if (year > maxYear) { - maxYear = year; - } - Map<Integer, Double[]> graphData = (Map<Integer, Double[]>) indicatorGraphData.get(indicatorCode, speciesCode); - if (graphData == null) { - graphData = new HashMap<Integer, Double[]>(); - indicatorGraphData.put(indicatorCode, speciesCode, graphData); - } - graphData.put(year, new Double[]{estimation, ecart}); - - // si les données sont énormes, on affiche les données - // / multiplicator et on le mentionne dans la légende - if (estimation > 1e9) { - multiplicator = 1000000; - } - if (estimation > 1e6 && multiplicator < 1000000) { - multiplicator = 1000; - } - - // for data part - DataStorage subDataStorage = (DataStorage) indicatorStorages.get(indicatorCode, speciesCode); - if (subDataStorage == null) { - subDataStorage = new MemoryDataStorage(); - if ("fr".equals(locale.getLanguage())) { - subDataStorage.add(new String[]{"Campagne", "Indice", "Liste", "Espèce", "Strate", "Annee", "Estimation", "EcartType", "CV"}); - } else { - subDataStorage.add(new String[]{"Survey", "Index", "List", "Species", "Stratum", "Year", "Estimate", "StandardDeviation", "CV"}); - } - indicatorStorages.put(indicatorCode, speciesCode, subDataStorage); - } - subDataStorage.add(tuple); - } - } - - // avec l'extraction des données, on peut demander a générer un graphique - // sur un indicateur qui n'est pas présent dans le projet courant, - // dans ce cas, on retourne null - for (MultiKey indicatorSpecies : (Set<MultiKey>) indicatorGraphData.keySet()) { - String indicator = (String) indicatorSpecies.getKey(0); - String aSpecies = (String) indicatorSpecies.getKey(1); - // get graph title - String title = zoneDisplayName; - String indicatorName = indicatorMap.getIndicatorValue(indicator, locale); - String unit = indicatorMap.getIndicatorUnit(indicator); - title += " - " + indicatorName; - title += " - " + repository.getSpeciesMap().getReportDisplayName(aSpecies); - - // generate dataset with sorted data - DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); - Map<Integer, Double[]> graphData = (Map<Integer, Double[]>) indicatorGraphData.get(indicator, aSpecies); - for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { - Double[] entry = graphData.get(indexYear); - if (entry != null) { - Double estimation = entry[0] / multiplicator; - Double ecart = entry[1] / multiplicator; - statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); - } else { - statisticalDataset.add(null, null, "Serie1", indexYear); - } - } - - - // configure chart - //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); - String yearAxis = reports.getYearChartTitle(locale); - CategoryAxis categoryAxis = new CategoryAxis(yearAxis); - categoryAxis.setCategoryMargin(0); - categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); - // label horizontaux - String legendY = indicatorName; - if (multiplicator != 1) { - // affiche par exemple : cm * 1000 - legendY += " (" + unit + "*" + multiplicator + ")"; - } else if (StringUtils.isNotEmpty(unit)) { - legendY += " (" + unit + ")"; - } - ValueAxis valueAxis = new NumberAxis(legendY); - valueAxis.setUpperMargin(0.1); - - CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); - - // n'affiche pas les nombre sur le graphique - //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); - //renderer.setBaseItemLabelGenerator(itemLabelGenerator); - //renderer.setBaseItemLabelsVisible(true); - - CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); - plot.setOrientation(PlotOrientation.VERTICAL); - JFreeChart chart = new JFreeChart(title, - JFreeChart.DEFAULT_TITLE_FONT, plot, true); - - // remove series legend - chart.removeLegend(); - // white background - chart.setBackgroundPaint(Color.WHITE); - - try { - File chartFile = File.createTempFile("coser-population-chart-", ".png"); - chartFile.deleteOnExit(); - ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); - //ByteArrayOutputStream out = new ByteArrayOutputStream(); - //ChartUtilities.writeChartAsPNG(out, chart, width, height); - - // data extraction - DataStorage subDataStorage = (DataStorage) indicatorStorages.get(indicator, aSpecies); - StringWriter writer = new StringWriter(); - DataStorages.save(subDataStorage, writer); - - // add chart file dans chart data in result - result.put(indicator + "-" + aSpecies, Pair.of(chartFile, writer.toString())); - writer.close(); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't save chart", ex); - } - } - - return result; - } - - // --------------------------------------------------------------------- // - // --- Matchers -------------------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchExtractTypeSet(ExtractRequest request) { - //TODO Should deal also with raw-data type - return !request.getExtractTypeList().contains(DataType.SOURCE); - } - - protected boolean matchZoneList(ExtractRequest request) { - return request.getZoneList().contains(project.getZoneName()); - } - - protected boolean matchCommunityIndicatorList(ExtractRequest request) { - Preconditions.checkNotNull(request.getCommunityIndicatorList()); - - List<String> indicatorList = request.getCommunityIndicatorList(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorList(tuple, indicatorList)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchPopulationIndicatorList(ExtractRequest request) { - Preconditions.checkNotNull(request.getPopulationIndicatorList()); - - List<String> indicatorList = request.getPopulationIndicatorList(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorList(tuple, indicatorList)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchPopulationIndicatorListAndSpeciesList(ExtractRequest request) { - Preconditions.checkNotNull(request.getPopulationIndicatorList()); - - List<String> indicatorList = request.getPopulationIndicatorList(); - List<String> speciesList = request.getSpeciesList(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchCommunityIndicatorListAndSpeciesList(ExtractRequest request) { - Preconditions.checkNotNull(request.getCommunityIndicatorList()); - - List<String> indicatorList = request.getCommunityIndicatorList(); - List<String> speciesList = request.getSpeciesList(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { - result = true; - break; - } - } - return result; - } -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/MapResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/MapResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/MapResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,124 +0,0 @@ -package fr.ifremer.coser.result.repository.echobase; - -/* - * #%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.bean.EchoBaseProject; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.repository.RequestUnavailableForProducerException; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.MapRequest; - -import java.io.File; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class MapResultProducer implements ResultProducer<MapRequest> { - - protected final EchoBaseResultRepository repository; - - protected final EchoBaseProject project; - - public MapResultProducer(EchoBaseResultRepository repository) { - this.repository = repository; - this.project = repository.project; - } - - @Override - public EchoBaseResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(MapRequest request) { - return repository.matchFacade(request) && - repository.matchZone(request) && - matchSpecies(request); - } - - @Override - public Map<String, String> getAvailableZones(MapRequest request) { - Preconditions.checkNotNull(request.getFacade()); - - boolean match = repository.matchFacade(request); - - Map<String, String> result = null; - if (match) { - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); - result = zonesMap.getSubZonesMap(project.getZoneName(), allowedZones); - } - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(MapRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - - Map<String, String> result = null; - - boolean match = repository.matchFacade(request) && repository.matchZone(request); - if (match) { - // get all map species for given facade + zone - Set<String> speciesList = repository.getMapSpecies(); - result = repository.getSpeciesMap().getSpeciesSubMap(speciesList); - } - return result; - } - - @Override - public Map<String, String> getAvailableIndicators(MapRequest request) { - throw RequestUnavailableForProducerException.newException("getAvailableIndicators", this); - } - - @Override - public FileResult produceResult(MapRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - Preconditions.checkNotNull(request.getSpecies()); - - File resultZip = repository.getMapSpeciesFile(request.getSpecies()); - - FileResult result = new FileResult(repository.getId(), resultZip); - return result; - } - - // --------------------------------------------------------------------- // - // --- Matchers -------------------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchSpecies(MapRequest request) { - String species = request.getSpecies(); - File file = repository.getMapSpeciesFile(species); - return file != null && file.exists(); - } -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/PopulationIndicatorResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/PopulationIndicatorResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/PopulationIndicatorResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,341 +0,0 @@ -package fr.ifremer.coser.result.repository.echobase; - -/* - * #%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.CoserTechnicalException; -import fr.ifremer.coser.bean.EchoBaseProject; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.Reports; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; -import fr.ifremer.coser.storage.DataStorage; -import fr.ifremer.coser.storage.DataStorages; -import fr.ifremer.coser.storage.MemoryDataStorage; -import org.apache.commons.lang3.StringUtils; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.CategoryAxis; -import org.jfree.chart.axis.CategoryLabelPositions; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.CategoryItemRenderer; -import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; -import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; - -import java.awt.Color; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class PopulationIndicatorResultProducer implements ResultProducer<PopulationIndicatorRequest> { - - protected final EchoBaseResultRepository repository; - - protected final Reports reports; - - protected final EchoBaseProject project; - - public PopulationIndicatorResultProducer(EchoBaseResultRepository repository) { - this.repository = repository; - this.project = repository.project; - this.reports = repository.reports; - } - - @Override - public EchoBaseResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(PopulationIndicatorRequest request) { - return repository.matchFacade(request) && - repository.matchZone(request) && - matchSpeciesAndIndicator(request); - } - - @Override - public Map<String, String> getAvailableZones(PopulationIndicatorRequest request) { - boolean match = repository.matchFacade(request); - - Map<String, String> result = null; - if (match) { - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); - result = zonesMap.getSubZonesMap(project.getZoneName(), allowedZones); - } - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - - Map<String, String> result = null; - boolean match = repository.matchFacade(request) && repository.matchZone(request); - - if (match) { - // get all population indicator species for given facade + zone - Set<String> speciesList = repository.getPopulationIndicatorSpecies(); - result = repository.getSpeciesMap().getSpeciesSubMap(speciesList); - } - - return result; - } - - @Override - public Map<String, String> getAvailableIndicators(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - - Map<String, String> result = null; - boolean match = repository.matchFacade(request) && repository.matchZone(request); - if (match) { - - // get all indicators for given facade + zone - Set<String> indicatorList = repository.getCommunityIndicators(); - result = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); - } - return result; - } - - @Override - public FileResult produceResult(PopulationIndicatorRequest r) { - - File file = null; - switch (r.getResultType()) { - case DATA: - file = getPopulationIndicatorDataFile(r.getIndicator(), - r.getSpecies()); - break; - - case GRAPH: - file = getPopulationIndicatorGraphFile(r.getLocale(), - r.getZone(), - r.getIndicator(), - r.getSpecies()); - break; - } - - - FileResult result = new FileResult(repository.getId(), file); - return result; - } - - protected File getPopulationIndicatorDataFile(String species, String indicator) { - - DataStorage dataStorage = new MemoryDataStorage(); - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(false); - - // add header - dataStorage.add(iterator.next()); - - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorSpeciesAndIndicator(tuple, species, indicator)) { - dataStorage.add(tuple); - } - } - File result = DataStorages.save(dataStorage, "coser-chart-population-indicator", - ".csv" - ); - return result; - } - - protected File getPopulationIndicatorGraphFile(Locale locale, - String zone, - String species, - String indicator) { - - - int multiplicator = 1; - int minYear = Integer.MAX_VALUE; - int maxYear = Integer.MIN_VALUE; - boolean indicatorFound = false; - Map<Integer, Double[]> graphData = new HashMap<Integer, Double[]>(); - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - - if (repository.matchIndicatorSpeciesAndIndicator(tuple, species, indicator)) { - indicatorFound = true; - - // XXX echatellier, maybe take care of list here ? - - Double estimation = Double.parseDouble(tuple[6]); - Double ecart = Double.parseDouble(tuple[7]); - int year = Integer.parseInt(tuple[5]); - - if (year < minYear) { - minYear = year; - } - if (year > maxYear) { - maxYear = year; - } - graphData.put(year, new Double[]{estimation, ecart}); - - // si les données sont énormes, on affiche les données - // / multiplicator et on le mentionne dans la légende - if (estimation > 1e9) { - multiplicator = 1000000; - } - if (estimation > 1e6 && multiplicator < 1000000) { - multiplicator = 1000; - } - } - } - - File result = null; - - // avec l'extraction des données, on peut demander a générer un graphique - // sur un indicateur qui n'est pas présent dans le projet courant, - // dans ce cas, on retourne null - if (indicatorFound) { - - String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); - String indicatorName = repository.getIndicatorsMap().getIndicatorValue(indicator, locale); - String unit = repository.getIndicatorsMap().getIndicatorUnit(indicator); - - // get graph title - String title = zoneDisplayName; - title += " - " + indicatorName; - title += " - " + repository.getSpeciesMap().getReportDisplayName(species); - - // generate dataset with sorted data - DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); - for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { - Double[] entry = graphData.get(indexYear); - if (entry != null) { - Double estimation = entry[0] / multiplicator; - Double ecart = entry[1] / multiplicator; - statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); - } else { - statisticalDataset.add(null, null, "Serie1", indexYear); - } - } - - // configure chart - //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); - String yearAxis = reports.getYearChartTitle(locale); - CategoryAxis categoryAxis = new CategoryAxis(yearAxis); - categoryAxis.setCategoryMargin(0); - categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); - // label horizontaux - String legendY = indicatorName; - if (multiplicator != 1) { - // affiche par exemple : cm * 1000 - legendY += " (" + unit + "*" + multiplicator + ")"; - } else if (StringUtils.isNotEmpty(unit)) { - legendY += " (" + unit + ")"; - } - ValueAxis valueAxis = new NumberAxis(legendY); - valueAxis.setUpperMargin(0.1); - - CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); - - // n'affiche pas les nombre sur le graphique - //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); - //renderer.setBaseItemLabelGenerator(itemLabelGenerator); - //renderer.setBaseItemLabelsVisible(true); - - CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); - plot.setOrientation(PlotOrientation.VERTICAL); - JFreeChart chart = new JFreeChart(title, - JFreeChart.DEFAULT_TITLE_FONT, plot, true); - - // remove series legend - chart.removeLegend(); - // white background - chart.setBackgroundPaint(Color.WHITE); - - try { - result = File.createTempFile("coser-chart-population-indicator-", ".png"); - result.deleteOnExit(); - ChartUtilities.saveChartAsPNG(result, chart, 800, 400); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't save chart", ex); - } - } - - return result; - } - - // --------------------------------------------------------------------- // - // --- Matchers -------------------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchSpecies(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getSpecies()); - - String species = request.getSpecies(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorSpecies(tuple, species)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchSpeciesAndIndicator(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getSpecies()); - Preconditions.checkNotNull(request.getIndicator()); - - String species = request.getSpecies(); - String indicator = request.getIndicator(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorSpeciesAndIndicator(tuple, species, indicator)) { - result = true; - break; - } - } - return result; - } - -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/RawDataResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/RawDataResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/RawDataResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,103 +0,0 @@ -package fr.ifremer.coser.result.repository.echobase; - -/* - * #%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.bean.EchoBaseProject; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.repository.RequestUnavailableForProducerException; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.RawDataRequest; - -import java.util.List; -import java.util.Map; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class RawDataResultProducer implements ResultProducer<RawDataRequest> { - - protected final EchoBaseResultRepository repository; - - protected final EchoBaseProject project; - - public RawDataResultProducer(EchoBaseResultRepository repository) { - this.repository = repository; - this.project = repository.project; - - } - - @Override - public EchoBaseResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(RawDataRequest request) { - return repository.matchFacade(request) && - repository.matchZone(request); - } - - @Override - public Map<String, String> getAvailableZones(RawDataRequest request) { - Preconditions.checkNotNull(request.getFacade()); - - boolean match = repository.matchFacade(request); - - Map<String, String> result = null; - if (match) { - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); - result = zonesMap.getSubZonesMap(project.getZoneName(), allowedZones); - } - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(RawDataRequest request) { - throw RequestUnavailableForProducerException.newException("getAvailableSpecies", this); - } - - @Override - public Map<String, String> getAvailableIndicators(RawDataRequest request) { - throw RequestUnavailableForProducerException.newException("getAvailableIndicators", this); - } - - @Override - public FileResult produceResult(RawDataRequest r) { - - //TODO - throw RequestUnavailableForProducerException.newException("produceResult", this); - } - - - // --------------------------------------------------------------------- // - // --- Matchers ------------------------------------------------------- // - // --------------------------------------------------------------------- // - - //TODO -} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/DeleteResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/DeleteResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/DeleteResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,109 @@ +package fr.ifremer.coser.result.repository.echobase.command; + +/* + * #%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 fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.result.CoserResult; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.VoidResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepositoryType; +import fr.ifremer.coser.result.request.DeleteResultsRequest; +import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class DeleteResultsCommand implements ResultRepositoryCommand<EchoBaseResultRepository, DeleteResultsRequest> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(DeleteResultsCommand.class); + + @Override + public Class<DeleteResultsRequest> getRequestType() { + return DeleteResultsRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + DeleteResultsRequest request) { + boolean result = matchRepositoryType(request) && + matchResultType(request) && + matchPublish(repository) && + matchZone(repository, request); + return result; + } + + @Override + public CoserResult execute(EchoBaseResultRepository repository, + DeleteResultsRequest request) { + File basedir = repository.getBasedir(); + if (log.isInfoEnabled()) { + log.info("Will delete project at: " + basedir); + } + try { + FileUtils.deleteDirectory(basedir); + } catch (IOException e) { + throw new CoserTechnicalException("Could not delete project at: " + basedir, e); + } + return new VoidResult(repository.getId()); + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchRepositoryType(DeleteResultsRequest request) { + boolean result = request.getResultRepositoryType().equals(EchoBaseResultRepositoryType.ID); + return result; + } + + protected boolean matchResultType(DeleteResultsRequest request) { + ResultType resultType = request.getResultType(); + boolean result = ResultType.MAP_AND_INDICATOR == resultType; + return result; + } + + protected boolean matchPublish(EchoBaseResultRepository repository) { + boolean result = repository.isPubliableResult(); + return result; + } + + protected boolean matchZone(EchoBaseResultRepository repository, + DeleteResultsRequest request) { + List<String> zoneList = request.getZoneList(); + boolean result = zoneList.contains(repository.getZone()); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/DeleteResultsCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/ExtractRawDataAndResultsCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/ExtractResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/ExtractRawDataAndResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/ExtractRawDataAndResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,720 @@ +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.base.Preconditions; +import com.google.common.collect.Maps; +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.bean.IndicatorMap; +import fr.ifremer.coser.bean.SpeciesMap; +import fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.ExtractRawDataAndResultsRequest; +import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.storage.DataStorages; +import fr.ifremer.coser.storage.MemoryDataStorage; +import fr.ifremer.coser.util.DataType; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.collections4.keyvalue.MultiKey; +import org.apache.commons.collections4.map.MultiKeyMap; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.CategoryLabelPositions; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; +import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; +import org.nuiton.util.FileUtil; +import org.nuiton.util.ZipUtil; + +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class ExtractRawDataAndResultsCommand implements ResultRepositoryCommand<EchoBaseResultRepository, ExtractRawDataAndResultsRequest> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ExtractRawDataAndResultsCommand.class); + + @Override + public Class<ExtractRawDataAndResultsRequest> getRequestType() { + return ExtractRawDataAndResultsRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + ExtractRawDataAndResultsRequest request) { + return matchExtractTypeSet(request) && + matchZoneList(repository, request) && + (matchPopulationIndicatorListAndSpeciesList(repository, request) || + matchCommunityIndicatorListAndSpeciesList(repository, request)); + } + + @Override + public FileResult execute(EchoBaseResultRepository repository, + ExtractRawDataAndResultsRequest r) { + + Locale locale = r.getLocale(); + List<String> zoneList = r.getZoneList(); + List<DataType> extractTypeList = r.getExtractTypeList(); + List<String> speciesList = r.getSpeciesList(); + List<String> communityIndicatorList = r.getCommunityIndicatorList(); + List<String> populationIndicatorList = r.getPopulationIndicatorList(); + + File resultZip = null; + File tempDir = null; + try { + tempDir = FileUtil.createTempDirectory("coser-extract-", "-tmp"); + + File subDir = new File(tempDir, "Indicateurs_Ifremer"); + FileUtils.forceMkdir(subDir); + + // les sources se retrouve dans le zip a cote du pdf + if (extractTypeList.contains(DataType.SOURCE)) { + if (log.isDebugEnabled()) { + log.debug("Extracting sources"); + } + File srcDir = new File(subDir, "sources"); + extractSource(srcDir); + } + + // les cartes doivent se retrouver dans le pdf + MultiKeyMap pdfMaps = null; + if (extractTypeList.contains(DataType.MAP)) { + if (log.isDebugEnabled()) { + log.debug("Extracting maps"); + } + String zone = repository.getZone(); + SpeciesMap speciesMap = repository.getSpeciesMap(); + for (String species : speciesList) { + File mapFile = repository.getMapSpeciesFile(species); + pdfMaps.put(zone, speciesMap.getSpeciesName(species), mapFile); + } + } + + // les graphiques sont également dans le pdf + MultiKeyMap pdfCharts = null; + if (CollectionUtils.isNotEmpty(communityIndicatorList) || + CollectionUtils.isNotEmpty(populationIndicatorList)) { + if (log.isDebugEnabled()) { + log.debug("Extracting charts"); + } + pdfCharts = extractCharts(repository, + speciesList, + communityIndicatorList, + populationIndicatorList, + locale); + } + + // generate pdf if necessary + if (MapUtils.isNotEmpty(pdfMaps) || MapUtils.isNotEmpty(pdfCharts)) { + if (log.isDebugEnabled()) { + log.debug("Generated Extract PDF"); + } + repository.getReports().generateExtractPDF(subDir, + zoneList, + pdfMaps, + pdfCharts, + repository.getZonesMap(), + locale); + } + + // fichier de décharge en pdf + if (log.isDebugEnabled()) { + log.debug("Generated decharge PDF"); + } + String filename = repository.getReports().getDechargeFilename(locale); + File dechargePDF = new File(subDir, filename); + repository.getReports().generateDechargePDF(dechargePDF, locale, null, null); + + // make zip + if (log.isDebugEnabled()) { + log.debug("Make final archive"); + } + resultZip = File.createTempFile("coser-extract-", ".zip"); + resultZip.deleteOnExit(); + ZipUtil.compress(resultZip, subDir); + + // clean directory + FileUtils.deleteDirectory(tempDir); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't create zip file", ex); + } finally { + // clean directory + FileUtils.deleteQuietly(tempDir); + } + + FileResult result = new FileResult(repository.getId(), resultZip); + return result; + } + + /** + * Generate raw data after selection in a sub directory (named of the zone) of the given directory. + * + * @param directory where to generate file + */ + protected void extractSource(File directory) { + + //TODO + } + + /** + * Retourne les indicateurs calculés avec leurs traductions scientifique + * pour la zone et l'especes souhaitées. + * + * @param species especes (if {@code null} look for com indicators + * @param comIndicators comIndicator + * @param popIndicators popIndicators + * @param locale locale + * @return la liste des indicateurs (zone, speciesname, [graphfile, graphdata]) + */ + protected MultiKeyMap extractCharts(EchoBaseResultRepository repository, + Collection<String> species, + Collection<String> comIndicators, + Collection<String> popIndicators, + Locale locale) { + + MultiKeyMap chartFileAndDatas = new MultiKeyMap(); + + String zone = repository.getZone(); + String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); + + if (CollectionUtils.isNotEmpty(comIndicators)) { + Map<String, Pair<File, String>> chartFileAndDataCom = getRsufiResultComCharts(repository, + comIndicators, + zoneDisplayName, + repository.getIndicatorsMap(), + locale, + 650, + 430); + // put in multimap as zone,speciesname, data + for (Map.Entry<String, Pair<File, String>> entry : chartFileAndDataCom.entrySet()) { + chartFileAndDatas.put(zone, entry.getKey(), entry.getValue()); + } + } + + if (CollectionUtils.isNotEmpty(popIndicators)) { + Map<String, Pair<File, String>> chartFileAndDataPop = getRsufiResultPopCharts(repository, + species, + popIndicators, + zoneDisplayName, + repository.getIndicatorsMap(), + locale, + 650, + 430); + // put in multimap as zone,speciesname, data + for (Map.Entry<String, Pair<File, String>> entry : chartFileAndDataPop.entrySet()) { + chartFileAndDatas.put(zone, entry.getKey(), entry.getValue()); + } + } + + return chartFileAndDatas; + } + + /** + * Generate community graph for selected indicators. + * Used by web ui extraction. + * + * @param indicators indicators to extract + * @param zoneDisplayName zone full name + * @param indicatorMap indicator localized map + * @param locale locale + * @param width graph width + * @param height graph height + * @return maps of generated graph image (temp file) and data indexed by natural key (indicator - species) + */ + public Map<String, Pair<File, String>> getRsufiResultComCharts(EchoBaseResultRepository repository, + Collection<String> indicators, + String zoneDisplayName, + IndicatorMap indicatorMap, + Locale locale, + int width, int height) { + + Map<String, Pair<File, String>> result = Maps.newHashMap(); + + int multiplicator = 1; + int minYear = Integer.MAX_VALUE; + int maxYear = Integer.MIN_VALUE; + + Map<String, Map<Integer, Double[]>> indicatorGraphData = new HashMap<String, Map<Integer, Double[]>>(); + Map<String, String> indicatorLists = new HashMap<String, String>(); + Map<String, DataStorage> indicatorStorages = new HashMap<String, DataStorage>(); + + // Campagne Indicateur Liste Strate Annee Estimation EcartType CV + Iterator<String[]> estComIndIterator = repository.loadCommunityIndicatorStorage(true); + while (estComIndIterator.hasNext()) { + // Campagne Indicateur Liste Strate Annee Estimation EcartType CV + String[] tuple = estComIndIterator.next(); + String indicatorCode = tuple[1]; + String indicatorList = tuple[2]; + + if (indicators.contains(indicatorCode)) { + + // si pas de list selectionnée, on prend la premiere + String localList = indicatorLists.get(indicatorCode); + if (StringUtils.isBlank(localList)) { + localList = indicatorList; + indicatorLists.put(indicatorCode, localList); + } + + if (indicatorList.equals(localList)) { + Double estimation = Double.parseDouble(tuple[5]); + Double ecart = Double.parseDouble(tuple[6]); + int year = Integer.parseInt(tuple[4]); + + if (year < minYear) { + minYear = year; + } + if (year > maxYear) { + maxYear = year; + } + Map<Integer, Double[]> graphData = indicatorGraphData.get(indicatorCode); + if (graphData == null) { + graphData = new HashMap<Integer, Double[]>(); + indicatorGraphData.put(indicatorCode, graphData); + } + graphData.put(year, new Double[]{estimation, ecart}); + + // si les données sont énormes, on affiche les données + // / multiplicator et on le mentionne dans la légende + if (estimation > 1e9) { + multiplicator = 1000000; + } + if (estimation > 1e6 && multiplicator < 1000000) { + multiplicator = 1000; + } + + // for data part + DataStorage subDataStorage = indicatorStorages.get(indicatorCode); + if (subDataStorage == null) { + subDataStorage = new MemoryDataStorage(); + if ("fr".equals(locale.getLanguage())) { + subDataStorage.add(new String[]{"Campagne", "Indice", "Liste", "Strate", "Année", "Estimation", "EcartType", "CV"}); + } else { + subDataStorage.add(new String[]{"Survey", "Index", "List", "Stratum", "Year", "Estimate", "StandardDeviation", "CV"}); + } + indicatorStorages.put(indicatorCode, subDataStorage); + } + subDataStorage.add(tuple); + } + } + } + + // avec l'extraction des données, on peut demander a générer un graphique + // sur un indicateur qui n'est pas présent dans le projet courant, + // dans ce cas, on retourne null + for (String indicator : indicatorGraphData.keySet()) { + // get graph title + String chartTitle = zoneDisplayName; + String indicatorName = indicatorMap.getIndicatorValue(indicator, locale); + String unit = indicatorMap.getIndicatorUnit(indicator); + chartTitle += " - " + indicatorName; + + // ajout de la traduction de la liste d'indicateur + // les liste sont a1, T1, T2 ... + String localList = indicatorLists.get(indicator); + String listLetter = String.valueOf(localList.charAt(0)); + Iterator<String[]> typeIterator = repository.getSpeciesMap().iterator(true); + while (typeIterator.hasNext()) { + // "Types";"Commentaire";"NumSys min";"NumSys max";"Code" + String[] tuple = typeIterator.next(); + if (tuple[4].equals(listLetter)) { + /// gestion du groupe "Tous" + // cas special, c'est la seule valeur du fichier + // code type espece qui a besoin d'une traduction + if (tuple[4].equalsIgnoreCase("T")) { + if ("fr".equals(locale.getLanguage())) { + chartTitle += " - " + "Tous Liste " + localList.charAt(1); + } else if ("es".equals(locale.getLanguage())) { + chartTitle += " - " + "Todo Lista " + localList.charAt(1); + } else { + chartTitle += " - " + "All List " + localList.charAt(1); + } + } else { + // ajout de la traduction du nom de liste plus le numéro + if ("fr".equals(locale.getLanguage())) { + chartTitle += " - " + tuple[0] + " Liste " + localList.charAt(1); + } else if ("es".equals(locale.getLanguage())) { + chartTitle += " - " + tuple[0] + " Lista " + localList.charAt(1); + } else { + chartTitle += " - " + tuple[0] + " List " + localList.charAt(1); + } + } + break; + } + } + + // generate dataset with sorted data + Map<Integer, Double[]> graphData = indicatorGraphData.get(indicator); + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { + Double[] entry = graphData.get(indexYear); + if (entry != null) { + Double estimation = entry[0] / multiplicator; + Double ecart = entry[1] / multiplicator; + statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); + } else { + statisticalDataset.add(null, null, "Serie1", indexYear); + } + } + + // configure chart + //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); + String yearAxis = repository.getReports().getYearChartTitle(locale); + CategoryAxis categoryAxis = new CategoryAxis(yearAxis); + categoryAxis.setCategoryMargin(0); + categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + // label horizontaux + String legendY = indicatorName; + if (multiplicator != 1) { + // affiche par exemple : cm * 1000 + legendY += " (" + unit + "*" + multiplicator + ")"; + } else if (StringUtils.isNotEmpty(unit)) { + legendY += " (" + unit + ")"; + } + ValueAxis valueAxis = new NumberAxis(legendY); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart(chartTitle, + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + // remove series legend + chart.removeLegend(); + // white background + chart.setBackgroundPaint(Color.WHITE); + + try { + File chartFile = File.createTempFile("coser-community-chart-", ".png"); + chartFile.deleteOnExit(); + ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); + //ByteArrayOutputStream out = new ByteArrayOutputStream(); + //ChartUtilities.writeChartAsPNG(out, chart, width, height); + + // data extraction + DataStorage subDataStorage = indicatorStorages.get(indicator); + StringWriter writer = new StringWriter(); + DataStorages.save(subDataStorage, writer); + + // add chart file dans chart data in result + result.put(indicator, Pair.of(chartFile, writer.toString())); + writer.close(); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't save chart", ex); + } + } + + return result; + } + + /** + * Generate population graph for selected species and indicator. + * + * @param species species to extract + * @param indicators indicators to extract + * @param zoneDisplayName zone full name + * @param indicatorMap indicator localized map + * @param locale locale + * @param width graph width + * @param height graph height + * @return maps of generated graph image (temp file) and data indexed by natural key (indicator - species) + */ + public Map<String, Pair<File, String>> getRsufiResultPopCharts(EchoBaseResultRepository repository, + Collection<String> species, + Collection<String> indicators, + String zoneDisplayName, + IndicatorMap indicatorMap, + Locale locale, + int width, + int height) { + + Map<String, Pair<File, String>> result = Maps.newHashMap(); + + int multiplicator = 1; + int minYear = Integer.MAX_VALUE; + int maxYear = Integer.MIN_VALUE; + + MultiKeyMap indicatorGraphData = new MultiKeyMap(); + MultiKeyMap indicatorStorages = new MultiKeyMap(); + + // Campagne Indicateur Liste Species Strate Annee Estimation EcartType CV + Iterator<String[]> estPopIndIterator = repository.loadPopulationIndicatorStorage(true); + while (estPopIndIterator.hasNext()) { + String[] tuple = estPopIndIterator.next(); + + String speciesCode = tuple[3]; + String indicatorCode = tuple[1]; + if (species.contains(speciesCode) && indicators.contains(indicatorCode)) { + + // XXX echatellier, maybe take care of list here ? + + Double estimation = Double.parseDouble(tuple[6]); + Double ecart = Double.parseDouble(tuple[7]); + int year = Integer.parseInt(tuple[5]); + + if (year < minYear) { + minYear = year; + } + if (year > maxYear) { + maxYear = year; + } + Map<Integer, Double[]> graphData = (Map<Integer, Double[]>) indicatorGraphData.get(indicatorCode, speciesCode); + if (graphData == null) { + graphData = new HashMap<Integer, Double[]>(); + indicatorGraphData.put(indicatorCode, speciesCode, graphData); + } + graphData.put(year, new Double[]{estimation, ecart}); + + // si les données sont énormes, on affiche les données + // / multiplicator et on le mentionne dans la légende + if (estimation > 1e9) { + multiplicator = 1000000; + } + if (estimation > 1e6 && multiplicator < 1000000) { + multiplicator = 1000; + } + + // for data part + DataStorage subDataStorage = (DataStorage) indicatorStorages.get(indicatorCode, speciesCode); + if (subDataStorage == null) { + subDataStorage = new MemoryDataStorage(); + if ("fr".equals(locale.getLanguage())) { + subDataStorage.add(new String[]{"Campagne", "Indice", "Liste", "Espèce", "Strate", "Annee", "Estimation", "EcartType", "CV"}); + } else { + subDataStorage.add(new String[]{"Survey", "Index", "List", "Species", "Stratum", "Year", "Estimate", "StandardDeviation", "CV"}); + } + indicatorStorages.put(indicatorCode, speciesCode, subDataStorage); + } + subDataStorage.add(tuple); + } + } + + // avec l'extraction des données, on peut demander a générer un graphique + // sur un indicateur qui n'est pas présent dans le projet courant, + // dans ce cas, on retourne null + for (MultiKey indicatorSpecies : (Set<MultiKey>) indicatorGraphData.keySet()) { + String indicator = (String) indicatorSpecies.getKey(0); + String aSpecies = (String) indicatorSpecies.getKey(1); + // get graph title + String title = zoneDisplayName; + String indicatorName = indicatorMap.getIndicatorValue(indicator, locale); + String unit = indicatorMap.getIndicatorUnit(indicator); + title += " - " + indicatorName; + title += " - " + repository.getSpeciesMap().getReportDisplayName(aSpecies); + + // generate dataset with sorted data + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + Map<Integer, Double[]> graphData = (Map<Integer, Double[]>) indicatorGraphData.get(indicator, aSpecies); + for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { + Double[] entry = graphData.get(indexYear); + if (entry != null) { + Double estimation = entry[0] / multiplicator; + Double ecart = entry[1] / multiplicator; + statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); + } else { + statisticalDataset.add(null, null, "Serie1", indexYear); + } + } + + // configure chart + //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); + String yearAxis = repository.getReports().getYearChartTitle(locale); + CategoryAxis categoryAxis = new CategoryAxis(yearAxis); + categoryAxis.setCategoryMargin(0); + categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + // label horizontaux + String legendY = indicatorName; + if (multiplicator != 1) { + // affiche par exemple : cm * 1000 + legendY += " (" + unit + "*" + multiplicator + ")"; + } else if (StringUtils.isNotEmpty(unit)) { + legendY += " (" + unit + ")"; + } + ValueAxis valueAxis = new NumberAxis(legendY); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart(title, + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + // remove series legend + chart.removeLegend(); + // white background + chart.setBackgroundPaint(Color.WHITE); + + try { + File chartFile = File.createTempFile("coser-population-chart-", ".png"); + chartFile.deleteOnExit(); + ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); + //ByteArrayOutputStream out = new ByteArrayOutputStream(); + //ChartUtilities.writeChartAsPNG(out, chart, width, height); + + // data extraction + DataStorage subDataStorage = (DataStorage) indicatorStorages.get(indicator, aSpecies); + StringWriter writer = new StringWriter(); + DataStorages.save(subDataStorage, writer); + + // add chart file dans chart data in result + result.put(indicator + "-" + aSpecies, Pair.of(chartFile, writer.toString())); + writer.close(); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't save chart", ex); + } + } + + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchExtractTypeSet(ExtractRawDataAndResultsRequest request) { + //TODO Should deal also with raw-data type + return !request.getExtractTypeList().contains(DataType.SOURCE); + } + + protected boolean matchZoneList(EchoBaseResultRepository repository, + ExtractRawDataAndResultsRequest request) { + return request.getZoneList().contains(repository.getZone()); + } + + protected boolean matchCommunityIndicatorList(EchoBaseResultRepository repository, + ExtractRawDataAndResultsRequest request) { + Preconditions.checkNotNull(request.getCommunityIndicatorList()); + + List<String> indicatorList = request.getCommunityIndicatorList(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorList(tuple, indicatorList)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchPopulationIndicatorList(EchoBaseResultRepository repository, + ExtractRawDataAndResultsRequest request) { + Preconditions.checkNotNull(request.getPopulationIndicatorList()); + + List<String> indicatorList = request.getPopulationIndicatorList(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorList(tuple, indicatorList)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchPopulationIndicatorListAndSpeciesList(EchoBaseResultRepository repository, + ExtractRawDataAndResultsRequest request) { + Preconditions.checkNotNull(request.getPopulationIndicatorList()); + + List<String> indicatorList = request.getPopulationIndicatorList(); + List<String> speciesList = request.getSpeciesList(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchCommunityIndicatorListAndSpeciesList(EchoBaseResultRepository repository, + ExtractRawDataAndResultsRequest request) { + Preconditions.checkNotNull(request.getCommunityIndicatorList()); + + List<String> indicatorList = request.getCommunityIndicatorList(); + List<String> speciesList = request.getSpeciesList(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { + result = true; + break; + } + } + return result; + } +} Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/ExtractRawDataCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/RawDataResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/ExtractRawDataCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/ExtractRawDataCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,63 @@ +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.result.FileResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.ExtractRawDataRequest; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class ExtractRawDataCommand implements ResultRepositoryCommand<EchoBaseResultRepository, ExtractRawDataRequest> { + + @Override + public Class<ExtractRawDataRequest> getRequestType() { + return ExtractRawDataRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + ExtractRawDataRequest request) { + return repository.matchFacade(request) && + repository.matchZone(request); + } + + @Override + public FileResult execute(EchoBaseResultRepository repository, + ExtractRawDataRequest r) { + + //TODO + throw new IllegalStateException("TODO!"); + } + + // --------------------------------------------------------------------- // + // --- Matchers ------------------------------------------------------- // + // --------------------------------------------------------------------- // + + //TODO +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetAllResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetAllResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetAllResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,86 @@ +package fr.ifremer.coser.result.repository.echobase.command; + +/* + * #%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.collect.Maps; +import fr.ifremer.coser.result.CoserResult; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepositoryType; +import fr.ifremer.coser.result.request.GetAllResultsRequest; + +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetAllResultsCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetAllResultsRequest> { + + @Override + public Class<GetAllResultsRequest> getRequestType() { + return GetAllResultsRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetAllResultsRequest request) { + boolean result = matchRepositoryType(request) && + matchResultType(request) && + matchPublish(repository); + return result; + } + + @Override + public CoserResult execute(EchoBaseResultRepository repository, + GetAllResultsRequest request) { + Map<String, String> map = Maps.newHashMap(); + map.put(repository.getZone(), repository.getSurveyName()); + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchRepositoryType(GetAllResultsRequest request) { + boolean result = request.getResultRepositoryType().equals(EchoBaseResultRepositoryType.ID); + return result; + } + + protected boolean matchResultType(GetAllResultsRequest request) { + ResultType resultType = request.getResultType(); + boolean result = ResultType.MAP_AND_INDICATOR == resultType; + return result; + } + + protected boolean matchPublish(EchoBaseResultRepository repository) { + boolean result = repository.isPubliableResult(); + return result; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetAllResultsCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetCommunityIndicatorResultCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/CommunityIndicatorResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetCommunityIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetCommunityIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,379 @@ +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.base.Preconditions; +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetCommunityIndicatorResultRequest; +import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.storage.DataStorages; +import fr.ifremer.coser.storage.MemoryDataStorage; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.CategoryLabelPositions; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; +import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; +import org.nuiton.util.FileUtil; +import org.nuiton.util.ZipUtil; + +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetCommunityIndicatorResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetCommunityIndicatorResultRequest> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(GetCommunityIndicatorResultCommand.class); + + @Override + public Class<GetCommunityIndicatorResultRequest> getRequestType() { + return GetCommunityIndicatorResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, GetCommunityIndicatorResultRequest request) { + return repository.matchFacade(request) && + repository.matchZone(request) && + matchIndicatorAndSpeciesList(repository, request); + } + + @Override + public FileResult execute(EchoBaseResultRepository repository, GetCommunityIndicatorResultRequest r) { + + File file = null; + switch (r.getIndicatorResultType()) { + case DATA: + file = getCommunityIndicatorDataFile(repository, + r.getLocale(), + r.getIndicator(), + r.getSpecies()); + break; + + case GRAPH: + file = getCommunityIndicatorGraphFile(repository, + r.getLocale(), + r.getZone(), + r.getIndicator(), + r.getSpecies()); + break; + } + FileResult result = new FileResult(repository.getId(), file); + return result; + } + + + protected File getCommunityIndicatorDataFile(EchoBaseResultRepository repository, Locale locale, + String indicator, + String speciesList) { + + try { + + File tempDir = FileUtil.createTempDirectory("coser-chart-population-indicator", "-tmp"); + + File baseDir = new File(tempDir, repository.getSurveyName()); + FileUtils.forceMkdir(baseDir); + + // ajout du fichier csv avec les indicateurs + DataStorage dataStorage = new MemoryDataStorage(); + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(false); + + // add header + dataStorage.add(iterator.next()); + + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { + dataStorage.add(tuple); + } + } + File csvFile = DataStorages.save(dataStorage, "coser-chart-community-indicator", + ".csv" + ); + + File csvFileCopied = new File(baseDir, indicator + ".csv"); + FileUtils.copyFile(csvFile, csvFileCopied); + FileUtils.forceDelete(csvFile); + + //TODO See what to generate here (we don't have any selection in echobase results). +// // ajout du fichier d'information sur les espèces incluses dans +// // les calculs des indicateurs de communautés +// // load project (without data to get reftax data) +// Project project = path.getProject(); +// Selection selection = path.getSelection(); +// File metaFile = webService.generateMetaFilePDF(project, +// selection, +// resultDirectory, +// rSufiResult, +// indicator, +// locale); +// File metaFileCopied = new File(baseDir, "Information.pdf"); +// FileUtils.copyFile(metaFile, metaFileCopied); + + // make zip + File result = File.createTempFile("coser-chart-community-indicator", ".zip"); + result.deleteOnExit(); + ZipUtil.compress(result, baseDir); + + // clean directory + FileUtils.deleteDirectory(tempDir); + return result; + } catch (Exception e) { + throw new CoserTechnicalException("Can't create zip file", e); + } + } + + protected File getCommunityIndicatorGraphFile(EchoBaseResultRepository repository, + Locale locale, + String zone, + String indicator, + String speciesList) { + + // indicator list to take care + // pour avoir une valeur non nulle si list est null + // on prend dans ce cas la premiere valeur trouvée + String localList = speciesList; + + if (log.isDebugEnabled()) { + log.debug("Searching list for indicator : " + indicator); + } + + int multiplicator = 1; + int minYear = Integer.MAX_VALUE; + int maxYear = Integer.MIN_VALUE; + boolean indicatorFound = false; + Map<Integer, Double[]> graphData = new HashMap<Integer, Double[]>(); + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + // Campagne Indicateur Liste Strate Annee Estimation EcartType CV + String[] tuple = iterator.next(); + String indicatorList = tuple[2]; + + if (repository.matchIndicatorIndicator(tuple, indicator)) { + indicatorFound = true; + + // si pas de list selectionnée, on prend la premiere + if (StringUtils.isBlank(localList)) { + localList = indicatorList; + } + + if (indicatorList.equals(localList)) { + Double estimation = Double.parseDouble(tuple[5]); + Double ecart = Double.parseDouble(tuple[6]); + int year = Integer.parseInt(tuple[4]); + + if (year < minYear) { + minYear = year; + } + if (year > maxYear) { + maxYear = year; + } + graphData.put(year, new Double[]{estimation, ecart}); + + // si les données sont énormes, on affiche les données + // / multiplicator et on le mentionne dans la légende + if (estimation > 1e9) { + multiplicator = 1000000; + } + if (estimation > 1e6 && multiplicator < 1000000) { + multiplicator = 1000; + } + } + } + } + + File result = null; + + // avec l'extraction des données, on peut demander a générer un graphique + // sur un indicateur qui n'est pas présent dans le projet courant, + // dans ce cas, on retourne null + if (indicatorFound) { + + String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); + String indicatorName = repository.getIndicatorsMap().getIndicatorValue(indicator, locale); + String unit = repository.getIndicatorsMap().getIndicatorUnit(indicator); + + // get graph title + String chartTitle = zoneDisplayName; + chartTitle += " - " + indicatorName; + + // ajout de la traduction de la liste d'indicateur + // les liste sont a1, T1, T2 ... + String listLetter = String.valueOf(localList.charAt(0)); + Iterator<String[]> typeIterator = repository.getSpeciesMap().iterator(true); + while (typeIterator.hasNext()) { + // "Types";"Commentaire";"NumSys min";"NumSys max";"Code" + String[] tuple = typeIterator.next(); + if (tuple[4].equals(listLetter)) { + /// gestion du groupe "Tous" + // cas special, c'est la seule valeur du fichier + // code type espece qui a besoin d'une traduction + if (tuple[4].equalsIgnoreCase("T")) { + if ("fr".equals(locale.getLanguage())) { + chartTitle += " - " + "Tous Liste " + localList.charAt(1); + } else if ("es".equals(locale.getLanguage())) { + chartTitle += " - " + "Todo Lista " + localList.charAt(1); + } else { + chartTitle += " - " + "All List " + localList.charAt(1); + } + } else { + // ajout de la traduction du nom de liste plus le numéro + if ("fr".equals(locale.getLanguage())) { + chartTitle += " - " + tuple[0] + " Liste " + localList.charAt(1); + } else if ("es".equals(locale.getLanguage())) { + chartTitle += " - " + tuple[0] + " Lista " + localList.charAt(1); + } else { + chartTitle += " - " + tuple[0] + " List " + localList.charAt(1); + } + } + break; + } + } + + // generate dataset with sorted data + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { + Double[] entry = graphData.get(indexYear); + if (entry != null) { + Double estimation = entry[0] / multiplicator; + Double ecart = entry[1] / multiplicator; + statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); + } else { + statisticalDataset.add(null, null, "Serie1", indexYear); + } + } + + // configure chart + //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); + String yearAxis = repository.getReports().getYearChartTitle(locale); + + CategoryAxis categoryAxis = new CategoryAxis(yearAxis); + categoryAxis.setCategoryMargin(0); + categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + // label horizontaux + String legendY = indicatorName; + if (multiplicator != 1) { + // affiche par exemple : cm * 1000 + legendY += " (" + unit + "*" + multiplicator + ")"; + } else if (StringUtils.isNotEmpty(unit)) { + legendY += " (" + unit + ")"; + } + ValueAxis valueAxis = new NumberAxis(legendY); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart(chartTitle, + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + // remove series legend + chart.removeLegend(); + // white background + chart.setBackgroundPaint(Color.WHITE); + + try { + result = File.createTempFile("coser-chart-community-indicator-", ".png"); + result.deleteOnExit(); + ChartUtilities.saveChartAsPNG(result, chart, 800, 400); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't save chart", ex); + } + } + + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchIndicator(EchoBaseResultRepository repository, + GetCommunityIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getIndicator()); + + String indicator = request.getIndicator(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorIndicator(tuple, indicator)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchIndicatorAndSpeciesList(EchoBaseResultRepository repository, + GetCommunityIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getIndicator()); + Preconditions.checkNotNull(request.getSpecies()); + + String indicator = request.getIndicator(); + String speciesList = request.getSpecies(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { + result = true; + break; + } + } + return result; + } +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForCommunityIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForCommunityIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForCommunityIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,64 @@ +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.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetIndicatorsForCommunityIndicatorResultRequest; + +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetIndicatorsForCommunityIndicatorResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetIndicatorsForCommunityIndicatorResultRequest> { + + @Override + public Class<GetIndicatorsForCommunityIndicatorResultRequest> getRequestType() { + return GetIndicatorsForCommunityIndicatorResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetIndicatorsForCommunityIndicatorResultRequest request) { + return repository.matchFacade(request) && + repository.matchZone(request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetIndicatorsForCommunityIndicatorResultRequest request) { + + Set<String> indicatorList = repository.getCommunityIndicators(); + Map<String, String> map = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForCommunityIndicatorResultCommand.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/GetIndicatorsForExtractRawDataAndResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForExtractRawDataAndResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForExtractRawDataAndResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,93 @@ +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.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetIndicatorsForExtractRawDataAndResultsRequest; +import fr.ifremer.coser.util.DataType; + +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetIndicatorsForExtractRawDataAndResultsCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetIndicatorsForExtractRawDataAndResultsRequest> { + + @Override + public Class<GetIndicatorsForExtractRawDataAndResultsRequest> getRequestType() { + return GetIndicatorsForExtractRawDataAndResultsRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetIndicatorsForExtractRawDataAndResultsRequest request) { + return matchExtractTypeSet(request) && matchZoneList(repository, request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetIndicatorsForExtractRawDataAndResultsRequest request) { + + Set<String> indicatorList = null; + + if (request.getExtractTypeList().contains(DataType.COMMUNITY)) { + + // get all community indicators for given zone + indicatorList = repository.getCommunityIndicators(); + } else if (request.getExtractTypeList().contains(DataType.POPULATION)) { + + // get all population indicators for given zone + indicatorList = repository.getPopulationIndicators(); + } + + Map<String, String> map = null; + + if (indicatorList != null) { + map = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); + } + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchExtractTypeSet(GetIndicatorsForExtractRawDataAndResultsRequest request) { + //TODO Should deal also with raw-data type + return !request.getExtractTypeList().contains(DataType.SOURCE); + } + + protected boolean matchZoneList(EchoBaseResultRepository repository, + GetIndicatorsForExtractRawDataAndResultsRequest request) { + return request.getZoneList().contains(repository.getZone()); + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForExtractRawDataAndResultsCommand.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/GetIndicatorsForPopulationIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForPopulationIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForPopulationIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,90 @@ +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.base.Preconditions; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetIndicatorsForPopulationIndicatorResultRequest; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetIndicatorsForPopulationIndicatorResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetIndicatorsForPopulationIndicatorResultRequest> { + + @Override + public Class<GetIndicatorsForPopulationIndicatorResultRequest> getRequestType() { + return GetIndicatorsForPopulationIndicatorResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetIndicatorsForPopulationIndicatorResultRequest request) { + return repository.matchFacade(request) && + repository.matchZone(request) && + matchSpecies(repository, request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetIndicatorsForPopulationIndicatorResultRequest request) { + + Set<String> indicatorList = repository.getCommunityIndicators(); + Map<String, String> map = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchSpecies(EchoBaseResultRepository repository, + GetIndicatorsForPopulationIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getSpecies()); + + String species = request.getSpecies(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorSpecies(tuple, species)) { + result = true; + break; + } + } + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetIndicatorsForPopulationIndicatorResultCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetMapResultCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/MapResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetMapResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetMapResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,74 @@ +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.base.Preconditions; +import fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetMapResultRequest; + +import java.io.File; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetMapResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetMapResultRequest> { + + @Override + public Class<GetMapResultRequest> getRequestType() { + return GetMapResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetMapResultRequest request) { + return repository.matchFacade(request) && + repository.matchZone(request) && + matchSpecies(repository, request); + } + + @Override + public FileResult execute(EchoBaseResultRepository repository, + GetMapResultRequest request) { + + File file = repository.getMapSpeciesFile(request.getSpecies()); + + FileResult result = new FileResult(repository.getId(), file); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchSpecies(EchoBaseResultRepository repository, + GetMapResultRequest request) { + String species = request.getSpecies(); + File file = repository.getMapSpeciesFile(species); + return file != null && file.exists(); + } +} Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetPopulationIndicatorResultCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/PopulationIndicatorResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetPopulationIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetPopulationIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,283 @@ +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.base.Preconditions; +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetPopulationIndicatorResultRequest; +import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.storage.DataStorages; +import fr.ifremer.coser.storage.MemoryDataStorage; +import org.apache.commons.lang3.StringUtils; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.CategoryLabelPositions; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; +import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; + +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetPopulationIndicatorResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetPopulationIndicatorResultRequest> { + + @Override + public Class<GetPopulationIndicatorResultRequest> getRequestType() { + return GetPopulationIndicatorResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, GetPopulationIndicatorResultRequest request) { + return repository.matchFacade(request) && + repository.matchZone(request) && + matchSpeciesAndIndicator(repository, request); + } + + @Override + public FileResult execute(EchoBaseResultRepository repository, GetPopulationIndicatorResultRequest r) { + + File file = null; + switch (r.getIndicatorResultType()) { + case DATA: + file = getPopulationIndicatorDataFile(repository, + r.getIndicator(), + r.getSpecies()); + break; + + case GRAPH: + file = getPopulationIndicatorGraphFile(repository, + r.getLocale(), + r.getZone(), + r.getIndicator(), + r.getSpecies()); + break; + } + + + FileResult result = new FileResult(repository.getId(), file); + return result; + } + + protected File getPopulationIndicatorDataFile(EchoBaseResultRepository repository, String species, String indicator) { + + DataStorage dataStorage = new MemoryDataStorage(); + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(false); + + // add header + dataStorage.add(iterator.next()); + + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorSpeciesAndIndicator(tuple, species, indicator)) { + dataStorage.add(tuple); + } + } + File result = DataStorages.save(dataStorage, "coser-chart-population-indicator", + ".csv" + ); + return result; + } + + protected File getPopulationIndicatorGraphFile(EchoBaseResultRepository repository, Locale locale, + String zone, + String species, + String indicator) { + + + int multiplicator = 1; + int minYear = Integer.MAX_VALUE; + int maxYear = Integer.MIN_VALUE; + boolean indicatorFound = false; + Map<Integer, Double[]> graphData = new HashMap<Integer, Double[]>(); + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + + if (repository.matchIndicatorSpeciesAndIndicator(tuple, species, indicator)) { + indicatorFound = true; + + // XXX echatellier, maybe take care of list here ? + + Double estimation = Double.parseDouble(tuple[6]); + Double ecart = Double.parseDouble(tuple[7]); + int year = Integer.parseInt(tuple[5]); + + if (year < minYear) { + minYear = year; + } + if (year > maxYear) { + maxYear = year; + } + graphData.put(year, new Double[]{estimation, ecart}); + + // si les données sont énormes, on affiche les données + // / multiplicator et on le mentionne dans la légende + if (estimation > 1e9) { + multiplicator = 1000000; + } + if (estimation > 1e6 && multiplicator < 1000000) { + multiplicator = 1000; + } + } + } + + File result = null; + + // avec l'extraction des données, on peut demander a générer un graphique + // sur un indicateur qui n'est pas présent dans le projet courant, + // dans ce cas, on retourne null + if (indicatorFound) { + + String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); + String indicatorName = repository.getIndicatorsMap().getIndicatorValue(indicator, locale); + String unit = repository.getIndicatorsMap().getIndicatorUnit(indicator); + + // get graph title + String title = zoneDisplayName; + title += " - " + indicatorName; + title += " - " + repository.getSpeciesMap().getReportDisplayName(species); + + // generate dataset with sorted data + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { + Double[] entry = graphData.get(indexYear); + if (entry != null) { + Double estimation = entry[0] / multiplicator; + Double ecart = entry[1] / multiplicator; + statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); + } else { + statisticalDataset.add(null, null, "Serie1", indexYear); + } + } + + // configure chart + //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); + String yearAxis = repository.getReports().getYearChartTitle(locale); + CategoryAxis categoryAxis = new CategoryAxis(yearAxis); + categoryAxis.setCategoryMargin(0); + categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + // label horizontaux + String legendY = indicatorName; + if (multiplicator != 1) { + // affiche par exemple : cm * 1000 + legendY += " (" + unit + "*" + multiplicator + ")"; + } else if (StringUtils.isNotEmpty(unit)) { + legendY += " (" + unit + ")"; + } + ValueAxis valueAxis = new NumberAxis(legendY); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart(title, + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + // remove series legend + chart.removeLegend(); + // white background + chart.setBackgroundPaint(Color.WHITE); + + try { + result = File.createTempFile("coser-chart-population-indicator-", ".png"); + result.deleteOnExit(); + ChartUtilities.saveChartAsPNG(result, chart, 800, 400); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't save chart", ex); + } + } + + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchSpecies(EchoBaseResultRepository repository, + GetPopulationIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getSpecies()); + + String species = request.getSpecies(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorSpecies(tuple, species)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchSpeciesAndIndicator(EchoBaseResultRepository repository, + GetPopulationIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getSpecies()); + Preconditions.checkNotNull(request.getIndicator()); + + String species = request.getSpecies(); + String indicator = request.getIndicator(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorSpeciesAndIndicator(tuple, species, indicator)) { + result = true; + break; + } + } + return result; + } + +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesForMapResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesForMapResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesForMapResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,64 @@ +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.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetSpeciesForMapResultRequest; + +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesForMapResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetSpeciesForMapResultRequest> { + + @Override + public Class<GetSpeciesForMapResultRequest> getRequestType() { + return GetSpeciesForMapResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetSpeciesForMapResultRequest request) { + return repository.matchFacade(request) && + repository.matchZone(request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetSpeciesForMapResultRequest request) { + + Set<String> speciesList = repository.getMapSpecies(); + Map<String, String> map = repository.getSpeciesMap().getSpeciesSubMap(speciesList); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesForMapResultCommand.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/GetSpeciesForPopulationIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesForPopulationIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesForPopulationIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,64 @@ +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.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetSpeciesForPopulationIndicatorResultRequest; + +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesForPopulationIndicatorResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetSpeciesForPopulationIndicatorResultRequest> { + + @Override + public Class<GetSpeciesForPopulationIndicatorResultRequest> getRequestType() { + return GetSpeciesForPopulationIndicatorResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetSpeciesForPopulationIndicatorResultRequest request) { + return repository.matchFacade(request) && + repository.matchZone(request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetSpeciesForPopulationIndicatorResultRequest request) { + + Set<String> speciesList = repository.getPopulationIndicatorSpecies(); + Map<String, String> map = repository.getSpeciesMap().getSpeciesSubMap(speciesList); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesForPopulationIndicatorResultCommand.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/GetSpeciesListForCommunityIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesListForCommunityIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesListForCommunityIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,89 @@ +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.base.Preconditions; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetSpeciesListForCommunityIndicatorResultRequest; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesListForCommunityIndicatorResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetSpeciesListForCommunityIndicatorResultRequest> { + + @Override + public Class<GetSpeciesListForCommunityIndicatorResultRequest> getRequestType() { + return GetSpeciesListForCommunityIndicatorResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetSpeciesListForCommunityIndicatorResultRequest request) { + return repository.matchFacade(request) && + repository.matchZone(request) && + matchIndicator(repository, request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetSpeciesListForCommunityIndicatorResultRequest request) { + + Set<String> speciesList = repository.getCommunityIndicatorSpecies(request.getIndicator()); + Map<String, String> map = repository.getSpeciesMap().getSpeciesSubMap(speciesList); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchIndicator(EchoBaseResultRepository repository, + GetSpeciesListForCommunityIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getIndicator()); + + String indicator = request.getIndicator(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorIndicator(tuple, indicator)) { + result = true; + break; + } + } + return result; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesListForCommunityIndicatorResultCommand.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/GetSpeciesListForExtractRawDataAndResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesListForExtractRawDataAndResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesListForExtractRawDataAndResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,84 @@ +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.Sets; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetSpeciesListForExtractRawDataAndResultsRequest; +import fr.ifremer.coser.util.DataType; + +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesListForExtractRawDataAndResultsCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetSpeciesListForExtractRawDataAndResultsRequest> { + + @Override + public Class<GetSpeciesListForExtractRawDataAndResultsRequest> getRequestType() { + return GetSpeciesListForExtractRawDataAndResultsRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetSpeciesListForExtractRawDataAndResultsRequest request) { + return matchExtractTypeSet(request) && matchZoneList(repository, request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetSpeciesListForExtractRawDataAndResultsRequest request) { + + Set<String> speciesList = Sets.newHashSet(); + // get all species for population indicators + speciesList.addAll(repository.getPopulationIndicatorSpecies()); + // get all species for community indicators + speciesList.addAll(repository.getCommunityIndicatorSpecies()); + + Map<String, String> map = repository.getSpeciesMap().getSpeciesSubMap(speciesList); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchExtractTypeSet(GetSpeciesListForExtractRawDataAndResultsRequest request) { + //TODO Should deal also with raw-data type + return !request.getExtractTypeList().contains(DataType.SOURCE); + } + + protected boolean matchZoneList(EchoBaseResultRepository repository, + GetSpeciesListForExtractRawDataAndResultsRequest request) { + return request.getZoneList().contains(repository.getZone()); + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetSpeciesListForExtractRawDataAndResultsCommand.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/GetZonesForCommunityIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForCommunityIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForCommunityIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,64 @@ +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.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetZonesForCommunityIndicatorResultRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForCommunityIndicatorResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetZonesForCommunityIndicatorResultRequest> { + + @Override + public Class<GetZonesForCommunityIndicatorResultRequest> getRequestType() { + return GetZonesForCommunityIndicatorResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetZonesForCommunityIndicatorResultRequest request) { + return repository.matchFacade(request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetZonesForCommunityIndicatorResultRequest request) { + + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForCommunityIndicatorResultCommand.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/GetZonesForExtractRawDataAndResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForExtractRawDataAndResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForExtractRawDataAndResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,65 @@ +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.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetZonesForExtractRawDataAndResultsRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForExtractRawDataAndResultsCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetZonesForExtractRawDataAndResultsRequest> { + + @Override + public Class<GetZonesForExtractRawDataAndResultsRequest> getRequestType() { + return GetZonesForExtractRawDataAndResultsRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetZonesForExtractRawDataAndResultsRequest request) { + return true; + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetZonesForExtractRawDataAndResultsRequest r) { + + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(null); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForExtractRawDataAndResultsCommand.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/GetZonesForExtractRawDataCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForExtractRawDataCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForExtractRawDataCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,63 @@ +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.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetZonesForExtractRawDataRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForExtractRawDataCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetZonesForExtractRawDataRequest> { + + @Override + public Class<GetZonesForExtractRawDataRequest> getRequestType() { + return GetZonesForExtractRawDataRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetZonesForExtractRawDataRequest request) { + return repository.matchFacade(request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetZonesForExtractRawDataRequest request) { + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForExtractRawDataCommand.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/GetZonesForMapResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForMapResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForMapResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,65 @@ +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.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetZonesForMapResultRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForMapResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetZonesForMapResultRequest> { + + @Override + public Class<GetZonesForMapResultRequest> getRequestType() { + return GetZonesForMapResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetZonesForMapResultRequest request) { + return repository.matchFacade(request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetZonesForMapResultRequest request) { + + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForMapResultCommand.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/GetZonesForPopulationIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForPopulationIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForPopulationIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,64 @@ +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.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepository; +import fr.ifremer.coser.result.request.GetZonesForPopulationIndicatorResultRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForPopulationIndicatorResultCommand implements ResultRepositoryCommand<EchoBaseResultRepository, GetZonesForPopulationIndicatorResultRequest> { + + @Override + public Class<GetZonesForPopulationIndicatorResultRequest> getRequestType() { + return GetZonesForPopulationIndicatorResultRequest.class; + } + + @Override + public boolean accept(EchoBaseResultRepository repository, + GetZonesForPopulationIndicatorResultRequest request) { + return repository.matchFacade(request); + } + + @Override + public MapResult execute(EchoBaseResultRepository repository, + GetZonesForPopulationIndicatorResultRequest request) { + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/command/GetZonesForPopulationIndicatorResultCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/CommunityIndicatorResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/CommunityIndicatorResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/CommunityIndicatorResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,455 +0,0 @@ -package fr.ifremer.coser.result.repository.legacy; - -/* - * #%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.CoserTechnicalException; -import fr.ifremer.coser.bean.RSufiResultPath; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.Reports; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.CommunityIndicatorRequest; -import fr.ifremer.coser.services.ProjectService; -import fr.ifremer.coser.storage.DataStorage; -import fr.ifremer.coser.storage.DataStorages; -import fr.ifremer.coser.storage.MemoryDataStorage; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.CategoryAxis; -import org.jfree.chart.axis.CategoryLabelPositions; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.CategoryItemRenderer; -import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; -import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; -import org.nuiton.util.FileUtil; -import org.nuiton.util.ZipUtil; - -import java.awt.Color; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class CommunityIndicatorResultProducer implements ResultProducer<CommunityIndicatorRequest> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(CommunityIndicatorResultProducer.class); - - protected final LegacyResultRepository repository; - - protected final Reports reports; - - protected final RSufiResultPath path; - - protected final File basedir; - - protected final ProjectService projectService; - - protected final String surveyName; - - public CommunityIndicatorResultProducer(LegacyResultRepository repository) { - this.repository = repository; - this.path = repository.path; - this.reports = repository.reports; - this.projectService = repository.projectService; - this.basedir = repository.basedir; - this.surveyName = repository.surveyName; - } - - @Override - public LegacyResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(CommunityIndicatorRequest request) { - return repository.indicatorsResult && - repository.matchFacade(request) && - repository.matchZone(request) && - matchIndicatorAndSpeciesList(request); - } - - @Override - public Map<String, String> getAvailableZones(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - - boolean match = repository.matchFacade(request); - - Map<String, String> result = null; - if (match) { - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); - result = zonesMap.getSubZonesMap(path.getRsufiResult().getZone(), allowedZones); - } - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - Preconditions.checkNotNull(request.getIndicator()); - - Map<String, String> result = null; - - boolean match = repository.indicatorsResult && - repository.matchFacade(request) && - repository.matchZone(request) && - matchIndicator(request); - if (match) { - - // get all map species for given facade + zone - result = repository.getCommunityIndicatorSpecies(request.getLocale(), - request.getIndicator()); - } - return result; - } - - @Override - public Map<String, String> getAvailableIndicators(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - - Map<String, String> result = null; - - boolean match = repository.indicatorsResult && - repository.matchFacade(request) && - repository.matchZone(request); - if (match) { - - // get all indicators for given facade + zone - Set<String> indicatorList = repository.getCommunityIndicators(); - result = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); - } - - return result; - } - - @Override - public FileResult produceResult(CommunityIndicatorRequest request) { - - File file = null; - switch (request.getResultType()) { - case DATA: - file = getCommunityIndicatorDataFile(request.getLocale(), - request.getIndicator(), - request.getSpecies()); - break; - - case GRAPH: - file = getCommunityIndicatorGraphFile(request.getLocale(), - request.getZone(), - request.getIndicator(), - request.getSpecies()); - break; - } - FileResult result = new FileResult(repository.getId(), file); - return result; - } - - - protected File getCommunityIndicatorDataFile(Locale locale, - String indicator, - String speciesList) { - - try { - - File tempDir = FileUtil.createTempDirectory("coser-chart-population-indicator", "-tmp"); - - File baseDir = new File(tempDir, surveyName); - FileUtils.forceMkdir(baseDir); - - // ajout du fichier csv avec les indicateurs - DataStorage dataStorage = new MemoryDataStorage(); - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(false); - - // add header - dataStorage.add(iterator.next()); - - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { - dataStorage.add(tuple); - } - } - File csvFile = DataStorages.save(dataStorage, "coser-chart-community-indicator", - ".csv" - ); - - File csvFileCopied = new File(baseDir, indicator + ".csv"); - FileUtils.copyFile(csvFile, csvFileCopied); - FileUtils.forceDelete(csvFile); - - // ajout du fichier d'information sur les espèces incluses dans - // les calculs des indicateurs de communautés - // load project (without data to get reftax data) - File metaFile = reports.generateMetaFilePDF(path, - repository.resultDirectory, - locale, - repository.getIndicatorsMap() - ); - File metaFileCopied = new File(baseDir, "Information.pdf"); - FileUtils.copyFile(metaFile, metaFileCopied); - - // make zip - File result = File.createTempFile("coser-chart-community-indicator", ".zip"); - result.deleteOnExit(); - ZipUtil.compress(result, baseDir); - - // clean directory - FileUtils.deleteDirectory(tempDir); - return result; - } catch (Exception e) { - throw new CoserTechnicalException("Can't create zip file", e); - } - } - - protected File getCommunityIndicatorGraphFile(Locale locale, - String zone, - String indicator, - String speciesList) { - - // indicator list to take care - // pour avoir une valeur non nulle si list est null - // on prend dans ce cas la premiere valeur trouvée - String localList = speciesList; - - if (log.isDebugEnabled()) { - log.debug("Searching list for indicator : " + indicator); - } - - int multiplicator = 1; - int minYear = Integer.MAX_VALUE; - int maxYear = Integer.MIN_VALUE; - boolean indicatorFound = false; - Map<Integer, Double[]> graphData = new HashMap<Integer, Double[]>(); - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - // Campagne Indicateur Liste Strate Annee Estimation EcartType CV - String[] tuple = iterator.next(); - String indicatorList = tuple[2]; - - if (repository.matchCommunityIndicator(tuple, indicator)) { - indicatorFound = true; - - // si pas de list selectionnée, on prend la premiere - if (StringUtils.isBlank(localList)) { - localList = indicatorList; - } - - if (indicatorList.equals(localList)) { - Double estimation = Double.parseDouble(tuple[5]); - Double ecart = Double.parseDouble(tuple[6]); - int year = Integer.parseInt(tuple[4]); - - if (year < minYear) { - minYear = year; - } - if (year > maxYear) { - maxYear = year; - } - graphData.put(year, new Double[]{estimation, ecart}); - - // si les données sont énormes, on affiche les données - // / multiplicator et on le mentionne dans la légende - if (estimation > 1e9) { - multiplicator = 1000000; - } - if (estimation > 1e6 && multiplicator < 1000000) { - multiplicator = 1000; - } - } - } - } - - File result = null; - - // avec l'extraction des données, on peut demander a générer un graphique - // sur un indicateur qui n'est pas présent dans le projet courant, - // dans ce cas, on retourne null - if (indicatorFound) { - - String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); - String indicatorName = repository.getIndicatorsMap().getIndicatorValue(indicator, locale); - String unit = repository.getIndicatorsMap().getIndicatorUnit(indicator); - - // get graph title - String chartTitle = zoneDisplayName; - chartTitle += " - " + indicatorName; - - String speciesListName = repository.getSpeciesListMap().getSpeciesListName(locale, localList); - chartTitle += " - " + speciesListName; -// // ajout de la traduction de la liste d'indicateur -// // les liste sont a1, T1, T2 ... -// String listLetter = String.valueOf(localList.charAt(0)); -// Iterator<String[]> typeIterator = repository.getSpeciesListMap().iterator(true); -// while (typeIterator.hasNext()) { -// // "Types";"Commentaire";"NumSys min";"NumSys max";"Code" -// String[] tuple = typeIterator.next(); -// if (tuple[4].equals(listLetter)) { -// /// gestion du groupe "Tous" -// // cas special, c'est la seule valeur du fichier -// // code type espece qui a besoin d'une traduction -// if (tuple[4].equalsIgnoreCase("T")) { -// if ("fr".equals(locale.getLanguage())) { -// chartTitle += " - " + "Tous Liste " + localList.charAt(1); -// } else if ("es".equals(locale.getLanguage())) { -// chartTitle += " - " + "Todo Lista " + localList.charAt(1); -// } else { -// chartTitle += " - " + "All List " + localList.charAt(1); -// } -// } else { -// // ajout de la traduction du nom de liste plus le numéro -// if ("fr".equals(locale.getLanguage())) { -// chartTitle += " - " + tuple[0] + " Liste " + localList.charAt(1); -// } else if ("es".equals(locale.getLanguage())) { -// chartTitle += " - " + tuple[0] + " Lista " + localList.charAt(1); -// } else { -// chartTitle += " - " + tuple[0] + " List " + localList.charAt(1); -// } -// } -// break; -// } -// } - - // generate dataset with sorted data - DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); - for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { - Double[] entry = graphData.get(indexYear); - if (entry != null) { - Double estimation = entry[0] / multiplicator; - Double ecart = entry[1] / multiplicator; - statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); - } else { - statisticalDataset.add(null, null, "Serie1", indexYear); - } - } - - // configure chart - //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); - String yearAxis = reports.getYearChartTitle(locale); - - CategoryAxis categoryAxis = new CategoryAxis(yearAxis); - categoryAxis.setCategoryMargin(0); - categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); - // label horizontaux - String legendY = indicatorName; - if (multiplicator != 1) { - // affiche par exemple : cm * 1000 - legendY += " (" + unit + "*" + multiplicator + ")"; - } else if (StringUtils.isNotEmpty(unit)) { - legendY += " (" + unit + ")"; - } - ValueAxis valueAxis = new NumberAxis(legendY); - valueAxis.setUpperMargin(0.1); - - CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); - - // n'affiche pas les nombre sur le graphique - //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); - //renderer.setBaseItemLabelGenerator(itemLabelGenerator); - //renderer.setBaseItemLabelsVisible(true); - - CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); - plot.setOrientation(PlotOrientation.VERTICAL); - JFreeChart chart = new JFreeChart(chartTitle, - JFreeChart.DEFAULT_TITLE_FONT, plot, true); - - // remove series legend - chart.removeLegend(); - // white background - chart.setBackgroundPaint(Color.WHITE); - - try { - result = File.createTempFile("coser-chart-community-indicator-", ".png"); - result.deleteOnExit(); - ChartUtilities.saveChartAsPNG(result, chart, 800, 400); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't save chart", ex); - } - } - - return result; - } - - // --------------------------------------------------------------------- // - // --- Matchers ------------------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchIndicator(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getIndicator()); - - String indicator = request.getIndicator(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchCommunityIndicator(tuple, indicator)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchIndicatorAndSpeciesList(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getIndicator()); - Preconditions.checkNotNull(request.getSpecies()); - - String indicator = request.getIndicator(); - String speciesList = request.getSpecies(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { - result = true; - break; - } - } - return result; - } -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/ExtractResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/ExtractResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/ExtractResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,835 +0,0 @@ -package fr.ifremer.coser.result.repository.legacy; - -/* - * #%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.Maps; -import fr.ifremer.coser.CoserBusinessException; -import fr.ifremer.coser.CoserTechnicalException; -import fr.ifremer.coser.bean.IndicatorMap; -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.bean.SpeciesMap; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.Reports; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.ExtractRequest; -import fr.ifremer.coser.services.ProjectService; -import fr.ifremer.coser.storage.DataStorage; -import fr.ifremer.coser.storage.DataStorages; -import fr.ifremer.coser.storage.MemoryDataStorage; -import fr.ifremer.coser.util.DataType; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.collections4.keyvalue.MultiKey; -import org.apache.commons.collections4.map.MultiKeyMap; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.CategoryAxis; -import org.jfree.chart.axis.CategoryLabelPositions; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.CategoryItemRenderer; -import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; -import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; -import org.nuiton.util.FileUtil; -import org.nuiton.util.ZipUtil; - -import java.awt.Color; -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class ExtractResultProducer implements ResultProducer<ExtractRequest> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ExtractResultProducer.class); - - protected final LegacyResultRepository repository; - - protected final Reports reports; - - protected final RSufiResultPath path; - - protected final File basedir; - - protected final ProjectService projectService; - - public ExtractResultProducer(LegacyResultRepository repository) { - this.repository = repository; - this.path = repository.path; - this.reports = repository.reports; - this.projectService = repository.projectService; - this.basedir = repository.basedir; - } - - @Override - public LegacyResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(ExtractRequest request) { - return matchExtractTypeSet(request) && - matchZoneList(request) && - (matchPopulationIndicatorListAndSpeciesList(request) || - matchCommunityIndicatorListAndSpeciesList(request)); - } - - @Override - public Map<String, String> getAvailableZones(ExtractRequest request) { - - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(null); - Map<String, String> result = zonesMap.getSubZonesMap(path.getRsufiResult().getZone(), allowedZones); - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(ExtractRequest request) { - Preconditions.checkNotNull(request.getZoneList()); - - Map<String, String> result = null; - - boolean match = matchZoneList(request); - - if (match) { - result = Maps.newHashMap(); - - // get all species for population indicators - result.putAll(repository.getPopulationIndicatorSpecies()); - // get all species for community indicators - result.putAll(repository.getCommunityIndicatorSpecies()); - } - return result; - } - - @Override - public Map<String, String> getAvailableIndicators(ExtractRequest request) { - Preconditions.checkNotNull(request.getZoneList()); - Preconditions.checkNotNull(request.getExtractTypeList()); - - Map<String, String> result = null; - - boolean match = matchZoneList(request); - if (match) { - - Set<String> indicatorList = null; - - if (request.getExtractTypeList().contains(DataType.COMMUNITY)) { - - // get all community indicators for given zone - indicatorList = repository.getCommunityIndicators(); - } else if (request.getExtractTypeList().contains(DataType.POPULATION)) { - - // get all population indicators for given zone - indicatorList = repository.getPopulationIndicators(); - } - - if (indicatorList != null) { - result = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); - } - } - return result; - } - - @Override - public FileResult produceResult(ExtractRequest r) { - - Locale locale = r.getLocale(); - List<String> zoneList = r.getZoneList(); - List<DataType> extractTypeList = r.getExtractTypeList(); - List<String> speciesList = r.getSpeciesList(); - List<String> communityIndicatorList = r.getCommunityIndicatorList(); - List<String> populationIndicatorList = r.getPopulationIndicatorList(); - - File resultZip = null; - File tempDir = null; - try { - tempDir = FileUtil.createTempDirectory("coser-extract-", "-tmp"); - - File subDir = new File(tempDir, "Indicateurs_Ifremer"); - FileUtils.forceMkdir(subDir); - - // les sources se retrouve dans le zip a cote du pdf - if (extractTypeList.contains(DataType.SOURCE)) { - if (log.isDebugEnabled()) { - log.debug("Extracting sources"); - } - File srcDir = new File(subDir, "sources"); - extractSource(srcDir); - } - - // les cartes doivent se retrouver dans le pdf - MultiKeyMap pdfMaps = null; - if (extractTypeList.contains(DataType.MAP)) { - if (log.isDebugEnabled()) { - log.debug("Extracting maps"); - } - SpeciesMap speciesMap = repository.getSpeciesMap(); - String zone = path.getRsufiResult().getZone(); - for (String species : speciesList) { - File mapFile = repository.getMapSpeciesFile(species); - pdfMaps.put(zone, speciesMap.getSpeciesName(species), mapFile); - } - } - - // les graphiques sont également dans le pdf - MultiKeyMap pdfCharts = null; - if (CollectionUtils.isNotEmpty(communityIndicatorList) || - CollectionUtils.isNotEmpty(populationIndicatorList)) { - if (log.isDebugEnabled()) { - log.debug("Extracting charts"); - } - pdfCharts = extractCharts(speciesList, - communityIndicatorList, - populationIndicatorList, - locale); - } - - // generate pdf if necessary - if (MapUtils.isNotEmpty(pdfMaps) || MapUtils.isNotEmpty(pdfCharts)) { - if (log.isDebugEnabled()) { - log.debug("Generated Extract PDF"); - } - reports.generateExtractPDF(subDir, - zoneList, - pdfMaps, - pdfCharts, - repository.getZonesMap(), - locale); - } - - // fichier de décharge en pdf - if (log.isDebugEnabled()) { - log.debug("Generated decharge PDF"); - } - String filename = reports.getDechargeFilename(locale); - File dechargePDF = new File(subDir, filename); - reports.generateDechargePDF(dechargePDF, locale, null, null); - - // make zip - if (log.isDebugEnabled()) { - log.debug("Make final archive"); - } - resultZip = File.createTempFile("coser-extract-", ".zip"); - resultZip.deleteOnExit(); - ZipUtil.compress(resultZip, subDir); - - // clean directory - FileUtils.deleteDirectory(tempDir); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't create zip file", ex); - } finally { - // clean directory - FileUtils.deleteQuietly(tempDir); - } - - FileResult result = new FileResult(repository.getId(), resultZip); - return result; - } - - /** - * Generate raw data after selection in a sub directory (named of the zone) of the given directory. - * - * @param directory where to generate file - */ - protected void extractSource(File directory) { - - // load project (with data to get original file names) - Project project = path.getProject(); - - // load selection data (to do data export rsufi) - Selection selection = path.getSelection(); - - try { - // be sure that data are available for this project - // or it will fail - - projectService.loadSelectionData(basedir.getParentFile(), project, selection); - } catch (CoserBusinessException e) { - throw new CoserTechnicalException("Could not load project selection", e); - } - - // il ne faut pas les fichiers de selection, mais leurs - // export rsufi (sans les lignes, et les quotes) - File zoneDirectory = new File(directory, path.getRsufiResult().getZone()); - - try { - FileUtils.forceMkdir(zoneDirectory); - } catch (IOException e) { - throw new CoserTechnicalException("Could not create directory: " + zoneDirectory, e); - } - - try { - projectService.extractRSUfiData(project, selection, zoneDirectory, true); - } catch (CoserBusinessException e) { - throw new CoserTechnicalException("Could not extract raw data", e); - } - } - - /** - * Retourne les indicateurs calculés avec leurs traductions scientifique - * pour la zone et l'especes souhaitées. - * - * @param species especes (if {@code null} look for com indicators - * @param comIndicators comIndicator - * @param popIndicators popIndicators - * @param locale locale - * @return la liste des indicateurs (zone, speciesname, [graphfile, graphdata]) - */ - protected MultiKeyMap extractCharts(Collection<String> species, - Collection<String> comIndicators, - Collection<String> popIndicators, - Locale locale) { - - MultiKeyMap chartFileAndDatas = new MultiKeyMap(); - - Project project = path.getProject(); - RSufiResult rsufiResult = path.getRsufiResult(); - String zone = rsufiResult.getZone(); - String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); - - if (CollectionUtils.isNotEmpty(comIndicators)) { - Map<String, Pair<File, String>> chartFileAndDataCom = getRsufiResultComCharts(comIndicators, - zoneDisplayName, - repository.getIndicatorsMap(), - locale, - 650, - 430); - // put in multimap as zone,speciesname, data - for (Map.Entry<String, Pair<File, String>> entry : chartFileAndDataCom.entrySet()) { - chartFileAndDatas.put(zone, entry.getKey(), entry.getValue()); - } - } - - if (CollectionUtils.isNotEmpty(popIndicators)) { - Map<String, Pair<File, String>> chartFileAndDataPop = getRsufiResultPopCharts(species, - popIndicators, - zoneDisplayName, - repository.getIndicatorsMap(), - locale, - 650, - 430); - // put in multimap as zone,speciesname, data - for (Map.Entry<String, Pair<File, String>> entry : chartFileAndDataPop.entrySet()) { - chartFileAndDatas.put(zone, entry.getKey(), entry.getValue()); - } - } - - return chartFileAndDatas; - } - - /** - * Generate community graph for selected indicators. - * Used by web ui extraction. - * - * @param indicators indicators to extract - * @param zoneDisplayName zone full name - * @param indicatorMap indicator localized map - * @param locale locale - * @param width graph width - * @param height graph height - * @return maps of generated graph image (temp file) and data indexed by natural key (indicator - species) - */ - public Map<String, Pair<File, String>> getRsufiResultComCharts(Collection<String> indicators, - String zoneDisplayName, - IndicatorMap indicatorMap, - Locale locale, - int width, int height) { - - Map<String, Pair<File, String>> result = Maps.newHashMap(); - - int multiplicator = 1; - int minYear = Integer.MAX_VALUE; - int maxYear = Integer.MIN_VALUE; - - Map<String, Map<Integer, Double[]>> indicatorGraphData = new HashMap<String, Map<Integer, Double[]>>(); - Map<String, String> indicatorLists = new HashMap<String, String>(); - Map<String, DataStorage> indicatorStorages = new HashMap<String, DataStorage>(); - - // Campagne Indicateur Liste Strate Annee Estimation EcartType CV - Iterator<String[]> estComIndIterator = repository.loadCommunityIndicatorStorage(true); - while (estComIndIterator.hasNext()) { - // Campagne Indicateur Liste Strate Annee Estimation EcartType CV - String[] tuple = estComIndIterator.next(); - String indicatorCode = tuple[1]; - String indicatorList = tuple[2]; - - if (indicators.contains(indicatorCode)) { - - // si pas de list selectionnée, on prend la premiere - String localList = indicatorLists.get(indicatorCode); - if (StringUtils.isBlank(localList)) { - localList = indicatorList; - indicatorLists.put(indicatorCode, localList); - } - - if (indicatorList.equals(localList)) { - Double estimation = Double.parseDouble(tuple[5]); - Double ecart = Double.parseDouble(tuple[6]); - int year = Integer.parseInt(tuple[4]); - - if (year < minYear) { - minYear = year; - } - if (year > maxYear) { - maxYear = year; - } - Map<Integer, Double[]> graphData = indicatorGraphData.get(indicatorCode); - if (graphData == null) { - graphData = new HashMap<Integer, Double[]>(); - indicatorGraphData.put(indicatorCode, graphData); - } - graphData.put(year, new Double[]{estimation, ecart}); - - // si les données sont énormes, on affiche les données - // / multiplicator et on le mentionne dans la légende - if (estimation > 1e9) { - multiplicator = 1000000; - } - if (estimation > 1e6 && multiplicator < 1000000) { - multiplicator = 1000; - } - - // for data part - DataStorage subDataStorage = indicatorStorages.get(indicatorCode); - if (subDataStorage == null) { - subDataStorage = new MemoryDataStorage(); - if ("fr".equals(locale.getLanguage())) { - subDataStorage.add(new String[]{"Campagne", "Indice", "Liste", "Strate", "Année", "Estimation", "EcartType", "CV"}); - } else { - subDataStorage.add(new String[]{"Survey", "Index", "List", "Stratum", "Year", "Estimate", "StandardDeviation", "CV"}); - } - indicatorStorages.put(indicatorCode, subDataStorage); - } - subDataStorage.add(tuple); - } - } - } - - // avec l'extraction des données, on peut demander a générer un graphique - // sur un indicateur qui n'est pas présent dans le projet courant, - // dans ce cas, on retourne null - for (String indicator : indicatorGraphData.keySet()) { - // get graph title - String chartTitle = zoneDisplayName; - String indicatorName = indicatorMap.getIndicatorValue(indicator, locale); - String unit = indicatorMap.getIndicatorUnit(indicator); - chartTitle += " - " + indicatorName; - - // ajout de la traduction de la liste d'indicateur - // les liste sont a1, T1, T2 ... - String localList = indicatorLists.get(indicator); - String speciesListName = repository.getSpeciesListMap().getSpeciesListName(locale, localList); - chartTitle += " - " + speciesListName; -// String listLetter = String.valueOf(localList.charAt(0)); -// Iterator<String[]> typeIterator = repository.getSpeciesListMap().iterator(true); -// while (typeIterator.hasNext()) { -// // "Types";"Commentaire";"NumSys min";"NumSys max";"Code" -// String[] tuple = typeIterator.next(); -// if (tuple[4].equals(listLetter)) { -// /// gestion du groupe "Tous" -// // cas special, c'est la seule valeur du fichier -// // code type espece qui a besoin d'une traduction -// if (tuple[4].equalsIgnoreCase("T")) { -// if ("fr".equals(locale.getLanguage())) { -// chartTitle += " - " + "Tous Liste " + localList.charAt(1); -// } else if ("es".equals(locale.getLanguage())) { -// chartTitle += " - " + "Todo Lista " + localList.charAt(1); -// } else { -// chartTitle += " - " + "All List " + localList.charAt(1); -// } -// } else { -// // ajout de la traduction du nom de liste plus le numéro -// if ("fr".equals(locale.getLanguage())) { -// chartTitle += " - " + tuple[0] + " Liste " + localList.charAt(1); -// } else if ("es".equals(locale.getLanguage())) { -// chartTitle += " - " + tuple[0] + " Lista " + localList.charAt(1); -// } else { -// chartTitle += " - " + tuple[0] + " List " + localList.charAt(1); -// } -// } -// break; -// } -// } - - // generate dataset with sorted data - Map<Integer, Double[]> graphData = indicatorGraphData.get(indicator); - DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); - for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { - Double[] entry = graphData.get(indexYear); - if (entry != null) { - Double estimation = entry[0] / multiplicator; - Double ecart = entry[1] / multiplicator; - statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); - } else { - statisticalDataset.add(null, null, "Serie1", indexYear); - } - } - - // configure chart - //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); - String yearAxis = reports.getYearChartTitle(locale); - CategoryAxis categoryAxis = new CategoryAxis(yearAxis); - categoryAxis.setCategoryMargin(0); - categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); - // label horizontaux - String legendY = indicatorName; - if (multiplicator != 1) { - // affiche par exemple : cm * 1000 - legendY += " (" + unit + "*" + multiplicator + ")"; - } else if (StringUtils.isNotEmpty(unit)) { - legendY += " (" + unit + ")"; - } - ValueAxis valueAxis = new NumberAxis(legendY); - valueAxis.setUpperMargin(0.1); - - CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); - - // n'affiche pas les nombre sur le graphique - //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); - //renderer.setBaseItemLabelGenerator(itemLabelGenerator); - //renderer.setBaseItemLabelsVisible(true); - - CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); - plot.setOrientation(PlotOrientation.VERTICAL); - JFreeChart chart = new JFreeChart(chartTitle, - JFreeChart.DEFAULT_TITLE_FONT, plot, true); - - // remove series legend - chart.removeLegend(); - // white background - chart.setBackgroundPaint(Color.WHITE); - - try { - File chartFile = File.createTempFile("coser-community-chart-", ".png"); - chartFile.deleteOnExit(); - ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); - //ByteArrayOutputStream out = new ByteArrayOutputStream(); - //ChartUtilities.writeChartAsPNG(out, chart, width, height); - - // data extraction - DataStorage subDataStorage = indicatorStorages.get(indicator); - StringWriter writer = new StringWriter(); - DataStorages.save(subDataStorage, writer); - - // add chart file dans chart data in result - result.put(indicator, Pair.of(chartFile, writer.toString())); - writer.close(); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't save chart", ex); - } - } - - return result; - } - - /** - * Generate population graph for selected species and indicator. - * - * @param species species to extract - * @param indicators indicators to extract - * @param zoneDisplayName zone full name - * @param indicatorMap indicator localized map - * @param locale locale - * @param width graph width - * @param height graph height - * @return maps of generated graph image (temp file) and data indexed by natural key (indicator - species) - */ - public Map<String, Pair<File, String>> getRsufiResultPopCharts(Collection<String> species, - Collection<String> indicators, - String zoneDisplayName, - IndicatorMap indicatorMap, - Locale locale, - int width, - int height) { - - Map<String, Pair<File, String>> result = Maps.newHashMap(); - - int multiplicator = 1; - int minYear = Integer.MAX_VALUE; - int maxYear = Integer.MIN_VALUE; - - MultiKeyMap indicatorGraphData = new MultiKeyMap(); - MultiKeyMap indicatorStorages = new MultiKeyMap(); - - // Campagne Indicateur Liste Species Strate Annee Estimation EcartType CV - Iterator<String[]> estPopIndIterator = repository.loadPopulationIndicatorStorage(true); - while (estPopIndIterator.hasNext()) { - String[] tuple = estPopIndIterator.next(); - - String speciesCode = tuple[3]; - String indicatorCode = tuple[1]; - if (species.contains(speciesCode) && indicators.contains(indicatorCode)) { - - // XXX echatellier, maybe take care of list here ? - - Double estimation = Double.parseDouble(tuple[6]); - Double ecart = Double.parseDouble(tuple[7]); - int year = Integer.parseInt(tuple[5]); - - if (year < minYear) { - minYear = year; - } - if (year > maxYear) { - maxYear = year; - } - Map<Integer, Double[]> graphData = (Map<Integer, Double[]>) indicatorGraphData.get(indicatorCode, speciesCode); - if (graphData == null) { - graphData = new HashMap<Integer, Double[]>(); - indicatorGraphData.put(indicatorCode, speciesCode, graphData); - } - graphData.put(year, new Double[]{estimation, ecart}); - - // si les données sont énormes, on affiche les données - // / multiplicator et on le mentionne dans la légende - if (estimation > 1e9) { - multiplicator = 1000000; - } - if (estimation > 1e6 && multiplicator < 1000000) { - multiplicator = 1000; - } - - // for data part - DataStorage subDataStorage = (DataStorage) indicatorStorages.get(indicatorCode, speciesCode); - if (subDataStorage == null) { - subDataStorage = new MemoryDataStorage(); - if ("fr".equals(locale.getLanguage())) { - subDataStorage.add(new String[]{"Campagne", "Indice", "Liste", "Espèce", "Strate", "Annee", "Estimation", "EcartType", "CV"}); - } else { - subDataStorage.add(new String[]{"Survey", "Index", "List", "Species", "Stratum", "Year", "Estimate", "StandardDeviation", "CV"}); - } - indicatorStorages.put(indicatorCode, speciesCode, subDataStorage); - } - subDataStorage.add(tuple); - } - } - - SpeciesMap speciesMap = repository.getSpeciesMap(); - - // avec l'extraction des données, on peut demander a générer un graphique - // sur un indicateur qui n'est pas présent dans le projet courant, - // dans ce cas, on retourne null - for (MultiKey indicatorSpecies : (Set<MultiKey>) indicatorGraphData.keySet()) { - String indicator = (String) indicatorSpecies.getKey(0); - String aSpecies = (String) indicatorSpecies.getKey(1); - // get graph title - String title = zoneDisplayName; - String indicatorName = indicatorMap.getIndicatorValue(indicator, locale); - String unit = indicatorMap.getIndicatorUnit(indicator); - title += " - " + indicatorName; - title += " - " + speciesMap.getReportDisplayName(aSpecies); - - // generate dataset with sorted data - DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); - Map<Integer, Double[]> graphData = (Map<Integer, Double[]>) indicatorGraphData.get(indicator, aSpecies); - for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { - Double[] entry = graphData.get(indexYear); - if (entry != null) { - Double estimation = entry[0] / multiplicator; - Double ecart = entry[1] / multiplicator; - statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); - } else { - statisticalDataset.add(null, null, "Serie1", indexYear); - } - } - - - // configure chart - //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); - String yearAxis = reports.getYearChartTitle(locale); - CategoryAxis categoryAxis = new CategoryAxis(yearAxis); - categoryAxis.setCategoryMargin(0); - categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); - // label horizontaux - String legendY = indicatorName; - if (multiplicator != 1) { - // affiche par exemple : cm * 1000 - legendY += " (" + unit + "*" + multiplicator + ")"; - } else if (StringUtils.isNotEmpty(unit)) { - legendY += " (" + unit + ")"; - } - ValueAxis valueAxis = new NumberAxis(legendY); - valueAxis.setUpperMargin(0.1); - - CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); - - // n'affiche pas les nombre sur le graphique - //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); - //renderer.setBaseItemLabelGenerator(itemLabelGenerator); - //renderer.setBaseItemLabelsVisible(true); - - CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); - plot.setOrientation(PlotOrientation.VERTICAL); - JFreeChart chart = new JFreeChart(title, - JFreeChart.DEFAULT_TITLE_FONT, plot, true); - - // remove series legend - chart.removeLegend(); - // white background - chart.setBackgroundPaint(Color.WHITE); - - try { - File chartFile = File.createTempFile("coser-population-chart-", ".png"); - chartFile.deleteOnExit(); - ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); - //ByteArrayOutputStream out = new ByteArrayOutputStream(); - //ChartUtilities.writeChartAsPNG(out, chart, width, height); - - // data extraction - DataStorage subDataStorage = (DataStorage) indicatorStorages.get(indicator, aSpecies); - StringWriter writer = new StringWriter(); - DataStorages.save(subDataStorage, writer); - - // add chart file dans chart data in result - result.put(indicator + "-" + aSpecies, Pair.of(chartFile, writer.toString())); - writer.close(); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't save chart", ex); - } - } - - return result; - } - - // --------------------------------------------------------------------- // - // --- Matchers ------------------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchExtractTypeSet(ExtractRequest request) { - boolean result = false; - if (repository.mapsResult) { - result = request.getExtractTypeList().contains(DataType.SOURCE); - } - if (repository.indicatorsResult) { - result = request.getExtractTypeList().contains(DataType.POPULATION) || - request.getExtractTypeList().contains(DataType.COMMUNITY); - } - if (repository.dataResult) { - result = request.getExtractTypeList().contains(DataType.SOURCE); - } - return result; - } - - protected boolean matchZoneList(ExtractRequest request) { - return request.getZoneList().contains(path.getRsufiResult().getZone()); - } - - protected boolean matchCommunityIndicatorList(ExtractRequest request) { - Preconditions.checkNotNull(request.getCommunityIndicatorList()); - - List<String> indicatorList = request.getCommunityIndicatorList(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorList(tuple, indicatorList)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchPopulationIndicatorList(ExtractRequest request) { - Preconditions.checkNotNull(request.getPopulationIndicatorList()); - - List<String> indicatorList = request.getPopulationIndicatorList(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorList(tuple, indicatorList)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchPopulationIndicatorListAndSpeciesList(ExtractRequest request) { - Preconditions.checkNotNull(request.getPopulationIndicatorList()); - - List<String> indicatorList = request.getPopulationIndicatorList(); - List<String> speciesList = request.getSpeciesList(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchCommunityIndicatorListAndSpeciesList(ExtractRequest request) { - Preconditions.checkNotNull(request.getCommunityIndicatorList()); - - List<String> indicatorList = request.getCommunityIndicatorList(); - List<String> speciesList = request.getSpeciesList(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { - result = true; - break; - } - } - return result; - } -} Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepository.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepository.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepository.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -27,26 +27,20 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import fr.ifremer.coser.CoserBusinessConfig; +import fr.ifremer.coser.CoserBusinessException; import fr.ifremer.coser.CoserConstants; import fr.ifremer.coser.CoserServiceContext; +import fr.ifremer.coser.CoserTechnicalException; import fr.ifremer.coser.bean.EchoBaseProject; import fr.ifremer.coser.bean.IndicatorMap; import fr.ifremer.coser.bean.RSufiResultPath; import fr.ifremer.coser.bean.SpeciesListMap; import fr.ifremer.coser.bean.SpeciesMap; import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.CoserRequest; -import fr.ifremer.coser.result.CoserResult; import fr.ifremer.coser.result.Reports; -import fr.ifremer.coser.result.repository.ResultProducer; import fr.ifremer.coser.result.repository.ResultRepository; -import fr.ifremer.coser.result.request.CommunityIndicatorRequest; import fr.ifremer.coser.result.request.CoserRequestFacadeAware; import fr.ifremer.coser.result.request.CoserRequestZoneAware; -import fr.ifremer.coser.result.request.ExtractRequest; -import fr.ifremer.coser.result.request.MapRequest; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; -import fr.ifremer.coser.result.request.RawDataRequest; import fr.ifremer.coser.services.ProjectService; import fr.ifremer.coser.storage.DataStorage; import fr.ifremer.coser.storage.DataStorages; @@ -76,11 +70,6 @@ private static final Log log = LogFactory.getLog(LegacyResultRepository.class); /** - * Id of result source. - */ - public static final String ID = "rsufi"; - - /** * Project basedir. */ protected final File basedir; @@ -95,7 +84,6 @@ */ protected final File mapsDirectory; - /** * Project definition. */ @@ -137,27 +125,11 @@ protected SpeciesListMap speciesListMap; /** - * Is the result contains maps ? - */ - protected final boolean mapsResult; - - /** - * Is the result contains indicators ? - */ - protected final boolean indicatorsResult; - - /** - * Is the results contains raw data ? - */ - protected final boolean dataResult; - - /** * Report helper. */ protected final Reports reports; - protected final Map<String, ResultProducer<?>> resultProducers; - + //FIXME Remove this protected final ProjectService projectService; public LegacyResultRepository(CoserServiceContext serviceContext, @@ -179,21 +151,12 @@ path.getRsufiResult().getName()); this.mapsDirectory = new File(resultDirectory, CoserConstants.STORAGE_MAPS_DIRECTORY); this.path = path; - this.mapsResult = path.getRsufiResult().isMapsResult(); - this.indicatorsResult = path.getRsufiResult().isIndicatorsResult(); - this.dataResult = path.getRsufiResult().isDataAllowed(); this.reports = new Reports(); this.mapFileToSpeciesCode = EchoBaseProject.newMapFileToSpeciesCode(surveyName); this.speciesCodeToMapFile = EchoBaseProject.newSpeciesCodeToMapFileName(surveyName); this.mapSpeciesFilenameFilter = EchoBaseProject.newMapSpeciesFilenameFilter(surveyName); this.projectService = new ProjectService(serviceContext.getConfig()); - this.resultProducers = Maps.newHashMap(); - this.resultProducers.put(MapRequest.class.getName(), new MapResultProducer(this)); - this.resultProducers.put(CommunityIndicatorRequest.class.getName(), new CommunityIndicatorResultProducer(this)); - this.resultProducers.put(PopulationIndicatorRequest.class.getName(), new PopulationIndicatorResultProducer(this)); - this.resultProducers.put(RawDataRequest.class.getName(), new RawDataResultProducer(this)); - this.resultProducers.put(ExtractRequest.class.getName(), new ExtractResultProducer(this)); if (log.isInfoEnabled()) { log.info("New result repository: " + getId()); @@ -207,112 +170,139 @@ @Override public String getId() { return String.format("%s::%s::%s", - ID, + LegacyResultRepositoryType.ID, resultDirectory, path.getRsufiResult().isMapsResult() ? "Map" : "Indicator" ); } @Override - public <R extends CoserRequest> Map<String, String> getAvailableZones(R request) { - Preconditions.checkNotNull(request); - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); + public LegacyResultRepositoryType getResultRepositoryType() { + return LegacyResultRepositoryType.INSTANCE; + } - Map<String, String> result = resultProducer.getAvailableZones(request); - return result; + public File getResultDirectory() { + return resultDirectory; } - @Override - public <R extends CoserRequest> Map<String, String> getAvailableSpecies(R request) { - Preconditions.checkNotNull(request); - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); + public RSufiResultPath getPath() { + return path; + } - Map<String, String> result = resultProducer.getAvailableSpecies(request); - return result; + public String getSurveyName() { + return surveyName; } - @Override - public <R extends CoserRequest> Map<String, String> getAvailableIndicators(R request) { - Preconditions.checkNotNull(request); - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); + public Reports getReports() { + return reports; + } - Map<String, String> result = resultProducer.getAvailableIndicators(request); - return result; + public File getBasedir() { + return basedir; } - @Override - public <R extends CoserRequest> boolean acceptResult(R request) { - Preconditions.checkNotNull(request); - Preconditions.checkArgument(request.isFilled()); + public String getProjectName() { + return path.getProject().getName(); + } - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); - boolean result = resultProducer.acceptResult(request); - return result; + public String getSelectionName() { + return path.getSelection().getName(); } - @Override - public <R extends CoserRequest> CoserResult getResult(R request) { - Preconditions.checkNotNull(request); - Preconditions.checkArgument(request.isFilled()); - Preconditions.checkArgument(acceptResult(request)); + public String getZone() { + return path.getRsufiResult().getZone(); + } - ResultProducer<R> resultProducer = getProducer(request); - Preconditions.checkNotNull(resultProducer); + public String getResultName() { + return path.getRsufiResult().getName(); + } - CoserResult result = resultProducer.produceResult(request); - return result; + public boolean isMapsResult() { + return path.getRsufiResult().isMapsResult(); } + public boolean isIndicatorsResult() { + return path.getRsufiResult().isIndicatorsResult(); + } + + public boolean isPubliableResult() { + return path.getRsufiResult().isPubliableResult(); + } + + public boolean isDataResult() { + return path.getRsufiResult().isDataAllowed(); + } + + //FIXME Remove this + public ProjectService getProjectService() { + return projectService; + } + + public void loadSelectionData() { + try { + // be sure that data are available for this project + // or it will fail + + getProjectService().loadSelectionData(getBasedir().getParentFile(), path.getProject(), path.getSelection()); + } catch (CoserBusinessException e) { + throw new CoserTechnicalException("Could not load project selection", e); + } + } + + public File extractRSUfiData(File zoneDirectory) { + try { + return getProjectService().extractRSUfiData(path.getProject(), path.getSelection(), zoneDirectory, true); + } catch (CoserBusinessException e) { + throw new CoserTechnicalException("Could not extract raw data", e); + } + } + // --------------------------------------------------------------------- // // --- Matchers -------------------------------------------------------- // // --------------------------------------------------------------------- // - protected boolean matchFacade(CoserRequestFacadeAware request) { + public boolean matchFacade(CoserRequestFacadeAware request) { return true; } - protected boolean matchZone(CoserRequestZoneAware request) { + public boolean matchZone(CoserRequestZoneAware request) { return path.getRsufiResult().getZone().equals(request.getZone()); } - protected boolean matchPopulationSpecies(String[] tuple, String species) { + public boolean matchPopulationSpecies(String[] tuple, String species) { String speciesCode = tuple[3]; boolean result = species.equals(speciesCode); return result; } - protected boolean matchPopulationSpeciesAndIndicator(String[] tuple, String species, String indicator) { + public boolean matchPopulationSpeciesAndIndicator(String[] tuple, String species, String indicator) { String indicatorCode = tuple[1]; boolean result = matchPopulationSpecies(tuple, species) && indicator.equals(indicatorCode); return result; } - protected boolean matchCommunityIndicator(String[] tuple, String indicator) { + public boolean matchCommunityIndicator(String[] tuple, String indicator) { String indicatorCode = tuple[1]; boolean result = indicator.equals(indicatorCode); return result; } - protected boolean matchCommunityIndicatorAndSpeciesList(String[] tuple, String indicator, String speciesList) { + public boolean matchCommunityIndicatorAndSpeciesList(String[] tuple, String indicator, String speciesList) { String indicatorCode = tuple[1]; String speciesListCode = tuple[2]; boolean result = indicator.equals(indicatorCode) && speciesList.equals(speciesListCode); return result; } - protected boolean matchIndicatorList(String[] tuple, List<String> indicatorList) { + public boolean matchIndicatorList(String[] tuple, List<String> indicatorList) { String indicatorCode = tuple[1]; boolean result = indicatorList.contains(indicatorCode); return result; } - protected boolean matchIndicatorListAndSpeciesList(String[] tuple, - List<String> indicatorList, - List<String> speciesList) { + public boolean matchIndicatorListAndSpeciesList(String[] tuple, + List<String> indicatorList, + List<String> speciesList) { String indicatorCode = tuple[1]; String speciesCode = tuple[3]; boolean result = indicatorList.contains(indicatorCode) && @@ -324,7 +314,7 @@ // --- Get Map result -------------------------------------------------- // // --------------------------------------------------------------------- // - protected File getMapSpeciesFile(String species) { + public File getMapSpeciesFile(String species) { String fileName = speciesCodeToMapFile.apply(species); File file = fileName == null ? null : new File(mapsDirectory, fileName); return file; @@ -334,7 +324,7 @@ // --- Get species lists ----------------------------------------------- // // --------------------------------------------------------------------- // - protected Map<String, String> getPopulationIndicatorSpecies() { + public Map<String, String> getPopulationIndicatorSpecies() { Map<String, String> result = Maps.newHashMap(); SpeciesMap speciesNames = getSpeciesMap(); @@ -353,7 +343,7 @@ return result; } - protected Map<String, String> getCommunityIndicatorSpecies() { + public Map<String, String> getCommunityIndicatorSpecies() { Map<String, String> result = Maps.newHashMap(); SpeciesMap speciesNames = getSpeciesMap(); @@ -372,7 +362,7 @@ return result; } - protected Map<String, String> getCommunityIndicatorSpecies(Locale locale, String indicator) { + public Map<String, String> getCommunityIndicatorSpecies(Locale locale, String indicator) { // linked hash map (doit respecter l'ordre d'insertion) Map<String, String> result = new LinkedHashMap<String, String>(); @@ -395,7 +385,7 @@ // --- Get indicator lists --------------------------------------------- // // --------------------------------------------------------------------- // - protected Set<String> getCommunityIndicators() { + public Set<String> getCommunityIndicators() { Iterator<String[]> iterator = loadCommunityIndicatorStorage(true); Set<String> result = Sets.newHashSet(); while (iterator.hasNext()) { @@ -406,7 +396,7 @@ return result; } - protected Set<String> getPopulationIndicators() { + public Set<String> getPopulationIndicators() { Iterator<String[]> iterator = loadPopulationIndicatorStorage(true); Set<String> result = Sets.newHashSet(); while (iterator.hasNext()) { @@ -417,7 +407,7 @@ return result; } - protected Set<String> getPopulationIndicators(String species) { + public Set<String> getPopulationIndicators(String species) { Iterator<String[]> iterator = loadPopulationIndicatorStorage(true); Set<String> result = Sets.newHashSet(); while (iterator.hasNext()) { @@ -442,7 +432,7 @@ return speciesListMap; } - protected SpeciesMap getSpeciesMap() { + public SpeciesMap getSpeciesMap() { if (speciesMap == null) { File file = new File(basedir, CoserConstants.Category.REFTAX_SPECIES.getStorageFileName()); @@ -451,7 +441,7 @@ return speciesMap; } - protected IndicatorMap getIndicatorsMap() { + public IndicatorMap getIndicatorsMap() { return serviceContext.getIndicatorsMap(); } @@ -463,7 +453,7 @@ // --- storage util methods -------------------------------------------- // // --------------------------------------------------------------------- // - protected Iterator<String[]> loadPopulationIndicatorStorage(boolean skipFirstLine) { + public Iterator<String[]> loadPopulationIndicatorStorage(boolean skipFirstLine) { File file = new File(resultDirectory, path.getRsufiResult().getEstPopIndName()); // Campagne Indicateur Liste Espece Strate Annee Estimation EcartType CV DataStorage dataStorage = DataStorages.load(file, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); @@ -471,7 +461,7 @@ return iterator; } - protected Iterator<String[]> loadCommunityIndicatorStorage(boolean skipFirstLine) { + public Iterator<String[]> loadCommunityIndicatorStorage(boolean skipFirstLine) { File file = new File(resultDirectory, path.getRsufiResult().getEstComIndName()); // Campagne Indicateur Liste Espece Strate Annee Estimation EcartType CV DataStorage dataStorage = DataStorages.load(file, CoserConstants.CSV_RESULT_SEPARATOR_CHAR); @@ -479,12 +469,15 @@ return iterator; } - protected <R extends CoserRequest> ResultProducer<R> getProducer(R request) { - String requestTypeName = request.getClass().getName(); - return (ResultProducer<R>) resultProducers.get(requestTypeName); - } +// protected <R extends CoserRequest> ResultRepositoryCommand<R> getProducer(R request) { +// Preconditions.checkNotNull(request); +// String requestTypeName = request.getClass().getName(); +// ResultRepositoryCommand<?> resultRepositoryCommand = resultProducers.get(requestTypeName); +// Preconditions.checkNotNull(resultRepositoryCommand); +// return (ResultRepositoryCommand<R>) resultRepositoryCommand; +// } - protected CoserBusinessConfig getConfig() { + public CoserBusinessConfig getConfig() { return serviceContext.getConfig(); } } Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryCommandEngine.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryCommandEngine.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryCommandEngine.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,134 @@ +package fr.ifremer.coser.result.repository.legacy; + +/* + * #%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 com.google.common.collect.Maps; +import fr.ifremer.coser.result.CoserRequest; +import fr.ifremer.coser.result.CoserResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.ResultRepositoryCommandEngine; +import fr.ifremer.coser.result.repository.legacy.command.DeleteResultsCommand; +import fr.ifremer.coser.result.repository.legacy.command.ExtractRawDataAndResultsCommand; +import fr.ifremer.coser.result.repository.legacy.command.ExtractRawDataCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetAllResultsCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetCommunityIndicatorResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetIndicatorsForCommunityIndicatorResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetIndicatorsForExtractRawDataAndResultsCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetIndicatorsForPopulationIndicatorResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetMapResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetPopulationIndicatorResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetSpeciesForMapResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetSpeciesForPopulationIndicatorResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetSpeciesListForCommunityIndicatorResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetSpeciesListForExtractRawDataAndResultsCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetZonesForCommunityIndicatorResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetZonesForExtractRawDataCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetZonesForMapResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetZonesForPopulationIndicatorResultCommand; +import fr.ifremer.coser.result.repository.legacy.command.GetZonesListForExtractRawDataAndResultsCommand; + +import java.util.Map; + +/** + * Created on 3/12/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class LegacyResultRepositoryCommandEngine implements ResultRepositoryCommandEngine { + + protected final LegacyResultRepository resultRepository; + + protected final Map<String, ResultRepositoryCommand<LegacyResultRepository, ?>> commands; + + public LegacyResultRepositoryCommandEngine(LegacyResultRepository resultRepository) { + this.resultRepository = resultRepository; + this.commands = Maps.newHashMap(); + + // get map result + loadCommand(new GetZonesForMapResultCommand()); + loadCommand(new GetSpeciesForMapResultCommand()); + loadCommand(new GetMapResultCommand()); + + // get community indicator result + loadCommand(new GetZonesForCommunityIndicatorResultCommand()); + loadCommand(new GetIndicatorsForCommunityIndicatorResultCommand()); + loadCommand(new GetSpeciesListForCommunityIndicatorResultCommand()); + loadCommand(new GetCommunityIndicatorResultCommand()); + + // get population indicator result + loadCommand(new GetZonesForPopulationIndicatorResultCommand()); + loadCommand(new GetSpeciesForPopulationIndicatorResultCommand()); + loadCommand(new GetIndicatorsForPopulationIndicatorResultCommand()); + loadCommand(new GetPopulationIndicatorResultCommand()); + + // get all results + loadCommand(new GetAllResultsCommand()); + + // extract raw data + loadCommand(new GetZonesForExtractRawDataCommand()); + loadCommand(new ExtractRawDataCommand()); + + // extract raw data and results + loadCommand(new GetZonesListForExtractRawDataAndResultsCommand()); + loadCommand(new GetSpeciesListForExtractRawDataAndResultsCommand()); + loadCommand(new GetIndicatorsForExtractRawDataAndResultsCommand()); + loadCommand(new ExtractRawDataAndResultsCommand()); + + // delete results + loadCommand(new DeleteResultsCommand()); + } + + @Override + public LegacyResultRepository getResultRepository() { + return resultRepository; + } + + @Override + public <R extends CoserRequest> boolean acceptRequest(R request) { + ResultRepositoryCommand<LegacyResultRepository, R> command = getCommand(request); + boolean result = command.accept(resultRepository, request); + return result; + } + + @Override + public <R extends CoserRequest> CoserResult executeRequest(R request) { + ResultRepositoryCommand<LegacyResultRepository, R> command = getCommand(request); + CoserResult result = command.execute(resultRepository, request); + return result; + } + + protected <R extends CoserRequest> ResultRepositoryCommand<LegacyResultRepository, R> getCommand(R request) { + Preconditions.checkNotNull(request); + String requestTypeName = request.getClass().getName(); + ResultRepositoryCommand<LegacyResultRepository, ?> resultRepositoryCommand = commands.get(requestTypeName); + Preconditions.checkNotNull(resultRepositoryCommand); + return (ResultRepositoryCommand<LegacyResultRepository, R>) resultRepositoryCommand; + } + + protected void loadCommand(ResultRepositoryCommand<LegacyResultRepository, ?> command) { + String name = command.getRequestType().getName(); + commands.put(name, command); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryCommandEngine.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/LegacyResultRepositoryProvider.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryProvider.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryProvider.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -32,6 +32,7 @@ import fr.ifremer.coser.bean.RSufiResultPath; import fr.ifremer.coser.bean.Selection; import fr.ifremer.coser.result.ResultRepositoryInitializationException; +import fr.ifremer.coser.result.repository.ResultRepositoryCommandEngine; import fr.ifremer.coser.result.repository.ResultRepositoryProvider; import fr.ifremer.coser.services.ProjectService; import org.apache.commons.logging.Log; @@ -80,6 +81,11 @@ return result; } + @Override + public ResultRepositoryCommandEngine newEngine(LegacyResultRepository repository) { + return new LegacyResultRepositoryCommandEngine(repository); + } + /** * Retourne tous les projets qui ont des résultats. * <p/> @@ -90,7 +96,7 @@ * @return results paths * @throws CoserBusinessException */ - public Set<LegacyResultRepository> findAllProjectWithResult(CoserServiceContext serviceContext) throws CoserBusinessException { + protected Set<LegacyResultRepository> findAllProjectWithResult(CoserServiceContext serviceContext) throws CoserBusinessException { ProjectService projectService = new ProjectService(serviceContext.getConfig()); Added: 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 (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryType.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,68 @@ +package fr.ifremer.coser.result.repository.legacy; + +/* + * #%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.collect.Sets; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.repository.ResultRepositoryType; + +import java.util.Set; + +import static org.nuiton.i18n.I18n.n; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class LegacyResultRepositoryType implements ResultRepositoryType { + + /** + * Id of result source. + */ + public static final String ID = "rsufi"; + + /** + * Public shared instance of type. + */ + public static final LegacyResultRepositoryType INSTANCE = new LegacyResultRepositoryType(); + + private static final long serialVersionUID = 1L; + + @Override + public String getId() { + return ID; + } + + @Override + public String getLabelKey() { + return n("coser.business.result.repository.type.legacy"); + } + + @Override + public Set<ResultType> getResultTypes() { + return Sets.immutableEnumSet(ResultType.MAP, ResultType.INDICATOR); + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryType.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/MapResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/MapResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/MapResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,123 +0,0 @@ -package fr.ifremer.coser.result.repository.legacy; - -/* - * #%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.bean.RSufiResultPath; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.repository.RequestUnavailableForProducerException; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.MapRequest; - -import java.io.File; -import java.util.List; -import java.util.Map; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class MapResultProducer implements ResultProducer<MapRequest> { - - protected final LegacyResultRepository repository; - - protected final RSufiResultPath path; - - public MapResultProducer(LegacyResultRepository repository) { - this.repository = repository; - this.path = repository.path; - } - - @Override - public LegacyResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(MapRequest request) { - return repository.mapsResult && - repository.matchFacade(request) && - repository.matchZone(request) && - matchSpecies(request); - } - - @Override - public Map<String, String> getAvailableZones(MapRequest request) { - Preconditions.checkNotNull(request.getFacade()); - - boolean match = repository.matchFacade(request); - - Map<String, String> result = null; - if (match) { - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); - result = zonesMap.getSubZonesMap(path.getRsufiResult().getZone(), allowedZones); - } - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(MapRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - - Map<String, String> result = null; - - boolean match = repository.mapsResult && - repository.matchFacade(request) && - repository.matchZone(request); - if (match) { - - // get all map species for given facade + zone - result = repository.getPopulationIndicatorSpecies(); - } - return result; - } - - @Override - public Map<String, String> getAvailableIndicators(MapRequest request) { - throw RequestUnavailableForProducerException.newException("getAvailableIndicators", this); - } - - @Override - public FileResult produceResult(MapRequest r) { - - File resultZip = repository.getMapSpeciesFile(r.getSpecies()); - - FileResult result = new FileResult(repository.getId(), resultZip); - return result; - } - - // --------------------------------------------------------------------- // - // --- Matchers ------------------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchSpecies(MapRequest request) { - String species = request.getSpecies(); - File file = repository.getMapSpeciesFile(species); - return file != null; - } -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/PopulationIndicatorResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/PopulationIndicatorResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/PopulationIndicatorResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,356 +0,0 @@ -package fr.ifremer.coser.result.repository.legacy; - -/* - * #%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.CoserTechnicalException; -import fr.ifremer.coser.bean.RSufiResultPath; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.Reports; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; -import fr.ifremer.coser.storage.DataStorage; -import fr.ifremer.coser.storage.DataStorages; -import fr.ifremer.coser.storage.MemoryDataStorage; -import org.apache.commons.lang3.StringUtils; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.CategoryAxis; -import org.jfree.chart.axis.CategoryLabelPositions; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.axis.ValueAxis; -import org.jfree.chart.plot.CategoryPlot; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.chart.renderer.category.CategoryItemRenderer; -import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; -import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; - -import java.awt.Color; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class PopulationIndicatorResultProducer implements ResultProducer<PopulationIndicatorRequest> { - - protected final LegacyResultRepository repository; - - protected final Reports reports; - - protected final RSufiResultPath path; - - protected final File basedir; - - protected final String surveyName; - - public PopulationIndicatorResultProducer(LegacyResultRepository repository) { - this.repository = repository; - this.path = repository.path; - this.reports = repository.reports; - this.basedir = repository.basedir; - this.surveyName = repository.surveyName; - } - - @Override - public LegacyResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(PopulationIndicatorRequest request) { - return repository.indicatorsResult && - repository.matchFacade(request) && - repository.matchZone(request) && - matchSpeciesAndIndicator(request); - } - - @Override - public Map<String, String> getAvailableZones(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - - boolean match = repository.matchFacade(request); - - Map<String, String> result = null; - if (match) { - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); - result = zonesMap.getSubZonesMap(path.getRsufiResult().getZone(), allowedZones); - } - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - - Map<String, String> result = null; - - boolean match = repository.indicatorsResult && - repository.matchFacade(request) && - repository.matchZone(request); - - if (match) { - // get all population indicator species for given facade + zone - result = repository.getPopulationIndicatorSpecies(); - } - return result; - } - - @Override - public Map<String, String> getAvailableIndicators(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getFacade()); - Preconditions.checkNotNull(request.getZone()); - Preconditions.checkNotNull(request.getSpecies()); - - Map<String, String> result = null; - - boolean match = repository.indicatorsResult && - repository.matchFacade(request) && - repository.matchZone(request) && - matchSpecies(request); - - if (match) { - - // get all indicators for given facade + zone + species - Set<String> indicatorList = repository.getPopulationIndicators(request.getSpecies()); - result = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); - } - - return result; - } - - @Override - public FileResult produceResult(PopulationIndicatorRequest request) { - - File file = null; - switch (request.getResultType()) { - case DATA: - file = getPopulationIndicatorDataFile(request.getIndicator(), - request.getSpecies()); - break; - - case GRAPH: - file = getPopulationIndicatorGraphFile(request.getLocale(), - request.getZone(), - request.getIndicator(), - request.getSpecies()); - break; - } - - - FileResult result = new FileResult(repository.getId(), file); - return result; - } - - protected File getPopulationIndicatorDataFile(String species, String indicator) { - - DataStorage dataStorage = new MemoryDataStorage(); - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(false); - - // add header - dataStorage.add(iterator.next()); - - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchPopulationSpeciesAndIndicator(tuple, species, indicator)) { - dataStorage.add(tuple); - } - } - File result = DataStorages.save(dataStorage, "coser-chart-population-indicator", - ".csv" - ); - return result; - } - - protected File getPopulationIndicatorGraphFile(Locale locale, - String zone, - String species, - String indicator) { - - int multiplicator = 1; - int minYear = Integer.MAX_VALUE; - int maxYear = Integer.MIN_VALUE; - boolean indicatorFound = false; - Map<Integer, Double[]> graphData = new HashMap<Integer, Double[]>(); - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - - if (repository.matchPopulationSpeciesAndIndicator(tuple, species, indicator)) { - indicatorFound = true; - - // XXX echatellier, maybe take care of list here ? - - Double estimation = Double.parseDouble(tuple[6]); - Double ecart = Double.parseDouble(tuple[7]); - int year = Integer.parseInt(tuple[5]); - - if (year < minYear) { - minYear = year; - } - if (year > maxYear) { - maxYear = year; - } - graphData.put(year, new Double[]{estimation, ecart}); - - // si les données sont énormes, on affiche les données - // / multiplicator et on le mentionne dans la légende - if (estimation > 1e9) { - multiplicator = 1000000; - } - if (estimation > 1e6 && multiplicator < 1000000) { - multiplicator = 1000; - } - } - } - - File result = null; - - // avec l'extraction des données, on peut demander a générer un graphique - // sur un indicateur qui n'est pas présent dans le projet courant, - // dans ce cas, on retourne null - if (indicatorFound) { - - String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); - String indicatorName = repository.getIndicatorsMap().getIndicatorValue(indicator, locale); - String unit = repository.getIndicatorsMap().getIndicatorUnit(indicator); - - // get graph title - String title = zoneDisplayName; - title += " - " + indicatorName; - title += " - " + repository.getSpeciesMap().getReportDisplayName(species); - - // generate dataset with sorted data - DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); - for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { - Double[] entry = graphData.get(indexYear); - if (entry != null) { - Double estimation = entry[0] / multiplicator; - Double ecart = entry[1] / multiplicator; - statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); - } else { - statisticalDataset.add(null, null, "Serie1", indexYear); - } - } - - // configure chart - //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); - String yearAxis = reports.getYearChartTitle(locale); - CategoryAxis categoryAxis = new CategoryAxis(yearAxis); - categoryAxis.setCategoryMargin(0); - categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); - // label horizontaux - String legendY = indicatorName; - if (multiplicator != 1) { - // affiche par exemple : cm * 1000 - legendY += " (" + unit + "*" + multiplicator + ")"; - } else if (StringUtils.isNotEmpty(unit)) { - legendY += " (" + unit + ")"; - } - ValueAxis valueAxis = new NumberAxis(legendY); - valueAxis.setUpperMargin(0.1); - - CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); - - // n'affiche pas les nombre sur le graphique - //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); - //renderer.setBaseItemLabelGenerator(itemLabelGenerator); - //renderer.setBaseItemLabelsVisible(true); - - CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); - plot.setOrientation(PlotOrientation.VERTICAL); - JFreeChart chart = new JFreeChart(title, - JFreeChart.DEFAULT_TITLE_FONT, plot, true); - - // remove series legend - chart.removeLegend(); - // white background - chart.setBackgroundPaint(Color.WHITE); - - try { - result = File.createTempFile("coser-chart-population-indicator-", ".png"); - result.deleteOnExit(); - ChartUtilities.saveChartAsPNG(result, chart, 800, 400); - } catch (IOException ex) { - throw new CoserTechnicalException("Can't save chart", ex); - } - } - - return result; - } - - // --------------------------------------------------------------------- // - // --- Matchers -------------------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchSpecies(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getSpecies()); - - String species = request.getSpecies(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchPopulationSpecies(tuple, species)) { - result = true; - break; - } - } - return result; - } - - protected boolean matchSpeciesAndIndicator(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getSpecies()); - Preconditions.checkNotNull(request.getIndicator()); - - String species = request.getSpecies(); - String indicator = request.getIndicator(); - - boolean result = false; - - Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (repository.matchPopulationSpeciesAndIndicator(tuple, species, indicator)) { - result = true; - break; - } - } - return result; - } -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/RawDataResultProducer.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/RawDataResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/RawDataResultProducer.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,178 +0,0 @@ -package fr.ifremer.coser.result.repository.legacy; - -/* - * #%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.CoserBusinessConfig; -import fr.ifremer.coser.CoserBusinessException; -import fr.ifremer.coser.CoserConstants; -import fr.ifremer.coser.CoserTechnicalException; -import fr.ifremer.coser.bean.Project; -import fr.ifremer.coser.bean.RSufiResultPath; -import fr.ifremer.coser.bean.Selection; -import fr.ifremer.coser.bean.ZoneMap; -import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.Reports; -import fr.ifremer.coser.result.repository.RequestUnavailableForProducerException; -import fr.ifremer.coser.result.repository.ResultProducer; -import fr.ifremer.coser.result.request.RawDataRequest; -import fr.ifremer.coser.services.ProjectService; -import org.apache.commons.io.FileUtils; -import org.nuiton.util.FileUtil; -import org.nuiton.util.ZipUtil; - -import java.io.File; -import java.io.IOException; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class RawDataResultProducer implements ResultProducer<RawDataRequest> { - - protected final LegacyResultRepository repository; - - protected final Reports reports; - - protected final RSufiResultPath path; - - protected final File basedir; - - protected final ProjectService projectService; - - private CoserBusinessConfig config; - - private String surveyName; - - public RawDataResultProducer(LegacyResultRepository repository) { - this.repository = repository; - this.path = repository.path; - this.reports = repository.reports; - this.projectService = repository.projectService; - this.basedir = repository.basedir; - this.config = repository.getConfig(); - this.surveyName = repository.surveyName; - } - - @Override - public LegacyResultRepository getRepository() { - return repository; - } - - @Override - public boolean acceptResult(RawDataRequest request) { - return repository.dataResult && - repository.matchFacade(request) && - matchZone(request); - } - - @Override - public Map<String, String> getAvailableZones(RawDataRequest request) { - boolean match = repository.matchFacade(request); - - Map<String, String> result = null; - if (match) { - ZoneMap zonesMap = repository.getZonesMap(); - List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); - result = zonesMap.getSubZonesMap(path.getRsufiResult().getZone(), allowedZones); - } - return result; - } - - @Override - public Map<String, String> getAvailableSpecies(RawDataRequest request) { - throw RequestUnavailableForProducerException.newException("getAvailableSpecies", this); - } - - @Override - public Map<String, String> getAvailableIndicators(RawDataRequest request) { - throw RequestUnavailableForProducerException.newException("getAvailableIndicators", this); - } - - @Override - public FileResult produceResult(RawDataRequest r) { - - Locale locale = r.getLocale(); - - Project project = path.getProject(); - Selection selection = path.getSelection(); - try { - // be sure that data are available for this project - // or it will fail - projectService.loadSelectionData(basedir.getParentFile(), project, selection); - } catch (CoserBusinessException e) { - throw new CoserTechnicalException("Could not load project selection", e); - } - - File resultZip; - - try { - File tempDir = FileUtil.createTempDirectory("coser-source-", "-tmp"); - - // il ne faut pas les fichiers de selection, mais leurs - // export rsufi (sans les lignes, et les quotes) - File archiveDir = projectService.extractRSUfiData(project, selection, tempDir, true); - - // add decharge file - String filename = reports.getDechargeFilename(locale); - File dechargePDF = new File(archiveDir, filename); - - Date lastDataUpdateDate = config.getLastDataUpdateDate(); - - reports.generateDechargePDF(dechargePDF, locale, lastDataUpdateDate, surveyName); - - // ajout du reftax dans le zip - File reftaxFile = new File(basedir, CoserConstants.Category.REFTAX_SPECIES.getStorageFileName()); - FileUtils.copyFileToDirectory(reftaxFile, archiveDir); - - // make zip - resultZip = File.createTempFile("coser-source-", ".zip"); - resultZip.deleteOnExit(); - ZipUtil.compress(resultZip, archiveDir); - - // clean directory - FileUtils.deleteDirectory(tempDir); - } catch (IOException e) { - throw new CoserTechnicalException("Can't create zip file", e); - } catch (CoserBusinessException e) { - throw new CoserTechnicalException("Can't create zip file", e); - } - - FileResult result = new FileResult(repository.getId(), resultZip); - return result; - } - - // --------------------------------------------------------------------- // - // --- Matchers ------------------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchZone(RawDataRequest request) { - return path.getRsufiResult().getZone().equals(request.getZone()); - } - -} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/DeleteResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/DeleteResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/DeleteResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,133 @@ +package fr.ifremer.coser.result.repository.legacy.command; + +/* + * #%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 fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.result.CoserResult; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.VoidResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepositoryType; +import fr.ifremer.coser.result.request.DeleteResultsRequest; +import org.apache.commons.io.FileUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class DeleteResultsCommand implements ResultRepositoryCommand<LegacyResultRepository, DeleteResultsRequest> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(DeleteResultsCommand.class); +// +// protected final LegacyResultRepository repository; +// +// protected final RSufiResult rsufiResult; +// +// public DeleteResultsCommand(LegacyResultRepository repository) { +// this.repository = repository; +// this.rsufiResult = repository.path.getRsufiResult(); +// } +// +// @Override +// public LegacyResultRepository getRepository() { +// return repository; +// } + + + @Override + public Class<DeleteResultsRequest> getRequestType() { + return DeleteResultsRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, DeleteResultsRequest request) { + boolean result = matchRepositoryType(request) && + matchResultType(repository, request) && + matchPublish(repository) && + matchZone(repository, request); + return result; + } + + @Override + public CoserResult execute(LegacyResultRepository repository, DeleteResultsRequest request) { + File basedir = repository.getBasedir(); + if (log.isInfoEnabled()) { + log.info("Will delete project at: " + basedir); + } + try { + FileUtils.deleteDirectory(basedir); + } catch (IOException e) { + throw new CoserTechnicalException("Could not delete project at: " + basedir, e); + } + return new VoidResult(repository.getId()); + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchRepositoryType(DeleteResultsRequest request) { + boolean result = request.getResultRepositoryType().equals(LegacyResultRepositoryType.ID); + return result; + } + + protected boolean matchResultType(LegacyResultRepository repository, DeleteResultsRequest request) { + boolean result; + ResultType resultType = request.getResultType(); + switch (resultType) { + + case MAP: + result = repository.isMapsResult(); + break; + case INDICATOR: + result = repository.isIndicatorsResult(); + break; + default: + result = false; + break; + } + return result; + } + + protected boolean matchPublish(LegacyResultRepository repository) { + boolean result = repository.isPubliableResult(); + return result; + } + + protected boolean matchZone(LegacyResultRepository repository, DeleteResultsRequest request) { + List<String> zoneList = request.getZoneList(); + boolean result = zoneList.contains(repository.getZone()); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/DeleteResultsCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/ExtractRawDataAndResultsCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/ExtractResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/ExtractRawDataAndResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/ExtractRawDataAndResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,753 @@ +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.base.Preconditions; +import com.google.common.collect.Maps; +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.bean.IndicatorMap; +import fr.ifremer.coser.bean.SpeciesMap; +import fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.Reports; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.ExtractRawDataAndResultsRequest; +import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.storage.DataStorages; +import fr.ifremer.coser.storage.MemoryDataStorage; +import fr.ifremer.coser.util.DataType; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.collections4.keyvalue.MultiKey; +import org.apache.commons.collections4.map.MultiKeyMap; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.CategoryLabelPositions; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; +import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; +import org.nuiton.util.FileUtil; +import org.nuiton.util.ZipUtil; + +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class ExtractRawDataAndResultsCommand implements ResultRepositoryCommand<LegacyResultRepository, ExtractRawDataAndResultsRequest> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ExtractRawDataAndResultsCommand.class); + + @Override + public Class<ExtractRawDataAndResultsRequest> getRequestType() { + return ExtractRawDataAndResultsRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + ExtractRawDataAndResultsRequest request) { + return matchExtractTypeSet(repository, request) && + matchZoneList(repository, request) && + (matchPopulationIndicatorListAndSpeciesList(repository, request) || + matchCommunityIndicatorListAndSpeciesList(repository, request)); + } + + @Override + public FileResult execute(LegacyResultRepository repository, + ExtractRawDataAndResultsRequest r) { + + Locale locale = r.getLocale(); + List<String> zoneList = r.getZoneList(); + List<DataType> extractTypeList = r.getExtractTypeList(); + List<String> speciesList = r.getSpeciesList(); + List<String> communityIndicatorList = r.getCommunityIndicatorList(); + List<String> populationIndicatorList = r.getPopulationIndicatorList(); + + File resultZip = null; + File tempDir = null; + try { + tempDir = FileUtil.createTempDirectory("coser-extract-", "-tmp"); + + File subDir = new File(tempDir, "Indicateurs_Ifremer"); + FileUtils.forceMkdir(subDir); + + // les sources se retrouve dans le zip a cote du pdf + if (extractTypeList.contains(DataType.SOURCE)) { + if (log.isDebugEnabled()) { + log.debug("Extracting sources"); + } + File srcDir = new File(subDir, "sources"); + extractSource(repository, srcDir); + } + + // les cartes doivent se retrouver dans le pdf + MultiKeyMap pdfMaps = null; + if (extractTypeList.contains(DataType.MAP)) { + if (log.isDebugEnabled()) { + log.debug("Extracting maps"); + } + SpeciesMap speciesMap = repository.getSpeciesMap(); + String zone = repository.getZone(); + for (String species : speciesList) { + File mapFile = repository.getMapSpeciesFile(species); + pdfMaps.put(zone, speciesMap.getSpeciesName(species), mapFile); + } + } + + // les graphiques sont également dans le pdf + MultiKeyMap pdfCharts = null; + if (CollectionUtils.isNotEmpty(communityIndicatorList) || + CollectionUtils.isNotEmpty(populationIndicatorList)) { + if (log.isDebugEnabled()) { + log.debug("Extracting charts"); + } + pdfCharts = extractCharts(repository, + speciesList, + communityIndicatorList, + populationIndicatorList, + locale); + } + + Reports reports = repository.getReports(); + + // generate pdf if necessary + if (MapUtils.isNotEmpty(pdfMaps) || MapUtils.isNotEmpty(pdfCharts)) { + if (log.isDebugEnabled()) { + log.debug("Generated Extract PDF"); + } + reports.generateExtractPDF(subDir, + zoneList, + pdfMaps, + pdfCharts, + repository.getZonesMap(), + locale); + } + + // fichier de décharge en pdf + if (log.isDebugEnabled()) { + log.debug("Generated decharge PDF"); + } + String filename = reports.getDechargeFilename(locale); + File dechargePDF = new File(subDir, filename); + reports.generateDechargePDF(dechargePDF, locale, null, null); + + // make zip + if (log.isDebugEnabled()) { + log.debug("Make final archive"); + } + resultZip = File.createTempFile("coser-extract-", ".zip"); + resultZip.deleteOnExit(); + ZipUtil.compress(resultZip, subDir); + + // clean directory + FileUtils.deleteDirectory(tempDir); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't create zip file", ex); + } finally { + // clean directory + FileUtils.deleteQuietly(tempDir); + } + + FileResult result = new FileResult(repository.getId(), resultZip); + return result; + } + + /** + * Generate raw data after selection in a sub directory (named of the zone) of the given directory. + * + * @param directory where to generate file + */ + protected void extractSource(LegacyResultRepository repository, File directory) { + + repository.loadSelectionData(); + + // il ne faut pas les fichiers de selection, mais leurs + // export rsufi (sans les lignes, et les quotes) + File zoneDirectory = new File(directory, repository.getZone()); + + try { + FileUtils.forceMkdir(zoneDirectory); + } catch (IOException e) { + throw new CoserTechnicalException("Could not create directory: " + zoneDirectory, e); + } + + repository.extractRSUfiData(zoneDirectory); + } + + /** + * Retourne les indicateurs calculés avec leurs traductions scientifique + * pour la zone et l'especes souhaitées. + * + * @param species especes (if {@code null} look for com indicators + * @param comIndicators comIndicator + * @param popIndicators popIndicators + * @param locale locale + * @return la liste des indicateurs (zone, speciesname, [graphfile, graphdata]) + */ + protected MultiKeyMap extractCharts(LegacyResultRepository repository, + Collection<String> species, + Collection<String> comIndicators, + Collection<String> popIndicators, + Locale locale) { + + MultiKeyMap chartFileAndDatas = new MultiKeyMap(); + + String zone = repository.getZone(); + String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); + + if (CollectionUtils.isNotEmpty(comIndicators)) { + Map<String, Pair<File, String>> chartFileAndDataCom = getRsufiResultComCharts(repository, + comIndicators, + zoneDisplayName, + repository.getIndicatorsMap(), + locale, + 650, + 430); + // put in multimap as zone,speciesname, data + for (Map.Entry<String, Pair<File, String>> entry : chartFileAndDataCom.entrySet()) { + chartFileAndDatas.put(zone, entry.getKey(), entry.getValue()); + } + } + + if (CollectionUtils.isNotEmpty(popIndicators)) { + Map<String, Pair<File, String>> chartFileAndDataPop = getRsufiResultPopCharts(repository, + species, + popIndicators, + zoneDisplayName, + repository.getIndicatorsMap(), + locale, + 650, + 430); + // put in multimap as zone,speciesname, data + for (Map.Entry<String, Pair<File, String>> entry : chartFileAndDataPop.entrySet()) { + chartFileAndDatas.put(zone, entry.getKey(), entry.getValue()); + } + } + + return chartFileAndDatas; + } + + /** + * Generate community graph for selected indicators. + * Used by web ui extraction. + * + * @param indicators indicators to extract + * @param zoneDisplayName zone full name + * @param indicatorMap indicator localized map + * @param locale locale + * @param width graph width + * @param height graph height + * @return maps of generated graph image (temp file) and data indexed by natural key (indicator - species) + */ + public Map<String, Pair<File, String>> getRsufiResultComCharts(LegacyResultRepository repository, + Collection<String> indicators, + String zoneDisplayName, + IndicatorMap indicatorMap, + Locale locale, + int width, int height) { + + Map<String, Pair<File, String>> result = Maps.newHashMap(); + + int multiplicator = 1; + int minYear = Integer.MAX_VALUE; + int maxYear = Integer.MIN_VALUE; + + Map<String, Map<Integer, Double[]>> indicatorGraphData = new HashMap<String, Map<Integer, Double[]>>(); + Map<String, String> indicatorLists = new HashMap<String, String>(); + Map<String, DataStorage> indicatorStorages = new HashMap<String, DataStorage>(); + + // Campagne Indicateur Liste Strate Annee Estimation EcartType CV + Iterator<String[]> estComIndIterator = repository.loadCommunityIndicatorStorage(true); + while (estComIndIterator.hasNext()) { + // Campagne Indicateur Liste Strate Annee Estimation EcartType CV + String[] tuple = estComIndIterator.next(); + String indicatorCode = tuple[1]; + String indicatorList = tuple[2]; + + if (indicators.contains(indicatorCode)) { + + // si pas de list selectionnée, on prend la premiere + String localList = indicatorLists.get(indicatorCode); + if (StringUtils.isBlank(localList)) { + localList = indicatorList; + indicatorLists.put(indicatorCode, localList); + } + + if (indicatorList.equals(localList)) { + Double estimation = Double.parseDouble(tuple[5]); + Double ecart = Double.parseDouble(tuple[6]); + int year = Integer.parseInt(tuple[4]); + + if (year < minYear) { + minYear = year; + } + if (year > maxYear) { + maxYear = year; + } + Map<Integer, Double[]> graphData = indicatorGraphData.get(indicatorCode); + if (graphData == null) { + graphData = new HashMap<Integer, Double[]>(); + indicatorGraphData.put(indicatorCode, graphData); + } + graphData.put(year, new Double[]{estimation, ecart}); + + // si les données sont énormes, on affiche les données + // / multiplicator et on le mentionne dans la légende + if (estimation > 1e9) { + multiplicator = 1000000; + } + if (estimation > 1e6 && multiplicator < 1000000) { + multiplicator = 1000; + } + + // for data part + DataStorage subDataStorage = indicatorStorages.get(indicatorCode); + if (subDataStorage == null) { + subDataStorage = new MemoryDataStorage(); + if ("fr".equals(locale.getLanguage())) { + subDataStorage.add(new String[]{"Campagne", "Indice", "Liste", "Strate", "Année", "Estimation", "EcartType", "CV"}); + } else { + subDataStorage.add(new String[]{"Survey", "Index", "List", "Stratum", "Year", "Estimate", "StandardDeviation", "CV"}); + } + indicatorStorages.put(indicatorCode, subDataStorage); + } + subDataStorage.add(tuple); + } + } + } + + // avec l'extraction des données, on peut demander a générer un graphique + // sur un indicateur qui n'est pas présent dans le projet courant, + // dans ce cas, on retourne null + for (String indicator : indicatorGraphData.keySet()) { + // get graph title + String chartTitle = zoneDisplayName; + String indicatorName = indicatorMap.getIndicatorValue(indicator, locale); + String unit = indicatorMap.getIndicatorUnit(indicator); + chartTitle += " - " + indicatorName; + + // ajout de la traduction de la liste d'indicateur + // les liste sont a1, T1, T2 ... + String localList = indicatorLists.get(indicator); + String speciesListName = repository.getSpeciesListMap().getSpeciesListName(locale, localList); + chartTitle += " - " + speciesListName; +// String listLetter = String.valueOf(localList.charAt(0)); +// Iterator<String[]> typeIterator = repository.getSpeciesListMap().iterator(true); +// while (typeIterator.hasNext()) { +// // "Types";"Commentaire";"NumSys min";"NumSys max";"Code" +// String[] tuple = typeIterator.next(); +// if (tuple[4].equals(listLetter)) { +// /// gestion du groupe "Tous" +// // cas special, c'est la seule valeur du fichier +// // code type espece qui a besoin d'une traduction +// if (tuple[4].equalsIgnoreCase("T")) { +// if ("fr".equals(locale.getLanguage())) { +// chartTitle += " - " + "Tous Liste " + localList.charAt(1); +// } else if ("es".equals(locale.getLanguage())) { +// chartTitle += " - " + "Todo Lista " + localList.charAt(1); +// } else { +// chartTitle += " - " + "All List " + localList.charAt(1); +// } +// } else { +// // ajout de la traduction du nom de liste plus le numéro +// if ("fr".equals(locale.getLanguage())) { +// chartTitle += " - " + tuple[0] + " Liste " + localList.charAt(1); +// } else if ("es".equals(locale.getLanguage())) { +// chartTitle += " - " + tuple[0] + " Lista " + localList.charAt(1); +// } else { +// chartTitle += " - " + tuple[0] + " List " + localList.charAt(1); +// } +// } +// break; +// } +// } + + // generate dataset with sorted data + Map<Integer, Double[]> graphData = indicatorGraphData.get(indicator); + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { + Double[] entry = graphData.get(indexYear); + if (entry != null) { + Double estimation = entry[0] / multiplicator; + Double ecart = entry[1] / multiplicator; + statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); + } else { + statisticalDataset.add(null, null, "Serie1", indexYear); + } + } + + // configure chart + //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); + String yearAxis = repository.getReports().getYearChartTitle(locale); + CategoryAxis categoryAxis = new CategoryAxis(yearAxis); + categoryAxis.setCategoryMargin(0); + categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + // label horizontaux + String legendY = indicatorName; + if (multiplicator != 1) { + // affiche par exemple : cm * 1000 + legendY += " (" + unit + "*" + multiplicator + ")"; + } else if (StringUtils.isNotEmpty(unit)) { + legendY += " (" + unit + ")"; + } + ValueAxis valueAxis = new NumberAxis(legendY); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart(chartTitle, + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + // remove series legend + chart.removeLegend(); + // white background + chart.setBackgroundPaint(Color.WHITE); + + try { + File chartFile = File.createTempFile("coser-community-chart-", ".png"); + chartFile.deleteOnExit(); + ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); + //ByteArrayOutputStream out = new ByteArrayOutputStream(); + //ChartUtilities.writeChartAsPNG(out, chart, width, height); + + // data extraction + DataStorage subDataStorage = indicatorStorages.get(indicator); + StringWriter writer = new StringWriter(); + DataStorages.save(subDataStorage, writer); + + // add chart file dans chart data in result + result.put(indicator, Pair.of(chartFile, writer.toString())); + writer.close(); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't save chart", ex); + } + } + + return result; + } + + /** + * Generate population graph for selected species and indicator. + * + * @param species species to extract + * @param indicators indicators to extract + * @param zoneDisplayName zone full name + * @param indicatorMap indicator localized map + * @param locale locale + * @param width graph width + * @param height graph height + * @return maps of generated graph image (temp file) and data indexed by natural key (indicator - species) + */ + public Map<String, Pair<File, String>> getRsufiResultPopCharts(LegacyResultRepository repository, + Collection<String> species, + Collection<String> indicators, + String zoneDisplayName, + IndicatorMap indicatorMap, + Locale locale, + int width, + int height) { + + Map<String, Pair<File, String>> result = Maps.newHashMap(); + + int multiplicator = 1; + int minYear = Integer.MAX_VALUE; + int maxYear = Integer.MIN_VALUE; + + MultiKeyMap indicatorGraphData = new MultiKeyMap(); + MultiKeyMap indicatorStorages = new MultiKeyMap(); + + // Campagne Indicateur Liste Species Strate Annee Estimation EcartType CV + Iterator<String[]> estPopIndIterator = repository.loadPopulationIndicatorStorage(true); + while (estPopIndIterator.hasNext()) { + String[] tuple = estPopIndIterator.next(); + + String speciesCode = tuple[3]; + String indicatorCode = tuple[1]; + if (species.contains(speciesCode) && indicators.contains(indicatorCode)) { + + // XXX echatellier, maybe take care of list here ? + + Double estimation = Double.parseDouble(tuple[6]); + Double ecart = Double.parseDouble(tuple[7]); + int year = Integer.parseInt(tuple[5]); + + if (year < minYear) { + minYear = year; + } + if (year > maxYear) { + maxYear = year; + } + Map<Integer, Double[]> graphData = (Map<Integer, Double[]>) indicatorGraphData.get(indicatorCode, speciesCode); + if (graphData == null) { + graphData = new HashMap<Integer, Double[]>(); + indicatorGraphData.put(indicatorCode, speciesCode, graphData); + } + graphData.put(year, new Double[]{estimation, ecart}); + + // si les données sont énormes, on affiche les données + // / multiplicator et on le mentionne dans la légende + if (estimation > 1e9) { + multiplicator = 1000000; + } + if (estimation > 1e6 && multiplicator < 1000000) { + multiplicator = 1000; + } + + // for data part + DataStorage subDataStorage = (DataStorage) indicatorStorages.get(indicatorCode, speciesCode); + if (subDataStorage == null) { + subDataStorage = new MemoryDataStorage(); + if ("fr".equals(locale.getLanguage())) { + subDataStorage.add(new String[]{"Campagne", "Indice", "Liste", "Espèce", "Strate", "Annee", "Estimation", "EcartType", "CV"}); + } else { + subDataStorage.add(new String[]{"Survey", "Index", "List", "Species", "Stratum", "Year", "Estimate", "StandardDeviation", "CV"}); + } + indicatorStorages.put(indicatorCode, speciesCode, subDataStorage); + } + subDataStorage.add(tuple); + } + } + + SpeciesMap speciesMap = repository.getSpeciesMap(); + + // avec l'extraction des données, on peut demander a générer un graphique + // sur un indicateur qui n'est pas présent dans le projet courant, + // dans ce cas, on retourne null + for (MultiKey indicatorSpecies : (Set<MultiKey>) indicatorGraphData.keySet()) { + String indicator = (String) indicatorSpecies.getKey(0); + String aSpecies = (String) indicatorSpecies.getKey(1); + // get graph title + String title = zoneDisplayName; + String indicatorName = indicatorMap.getIndicatorValue(indicator, locale); + String unit = indicatorMap.getIndicatorUnit(indicator); + title += " - " + indicatorName; + title += " - " + speciesMap.getReportDisplayName(aSpecies); + + // generate dataset with sorted data + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + Map<Integer, Double[]> graphData = (Map<Integer, Double[]>) indicatorGraphData.get(indicator, aSpecies); + for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { + Double[] entry = graphData.get(indexYear); + if (entry != null) { + Double estimation = entry[0] / multiplicator; + Double ecart = entry[1] / multiplicator; + statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); + } else { + statisticalDataset.add(null, null, "Serie1", indexYear); + } + } + + Reports reports = repository.getReports(); + + // configure chart + //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); + String yearAxis = reports.getYearChartTitle(locale); + CategoryAxis categoryAxis = new CategoryAxis(yearAxis); + categoryAxis.setCategoryMargin(0); + categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + // label horizontaux + String legendY = indicatorName; + if (multiplicator != 1) { + // affiche par exemple : cm * 1000 + legendY += " (" + unit + "*" + multiplicator + ")"; + } else if (StringUtils.isNotEmpty(unit)) { + legendY += " (" + unit + ")"; + } + ValueAxis valueAxis = new NumberAxis(legendY); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart(title, + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + // remove series legend + chart.removeLegend(); + // white background + chart.setBackgroundPaint(Color.WHITE); + + try { + File chartFile = File.createTempFile("coser-population-chart-", ".png"); + chartFile.deleteOnExit(); + ChartUtilities.saveChartAsPNG(chartFile, chart, width, height); + //ByteArrayOutputStream out = new ByteArrayOutputStream(); + //ChartUtilities.writeChartAsPNG(out, chart, width, height); + + // data extraction + DataStorage subDataStorage = (DataStorage) indicatorStorages.get(indicator, aSpecies); + StringWriter writer = new StringWriter(); + DataStorages.save(subDataStorage, writer); + + // add chart file dans chart data in result + result.put(indicator + "-" + aSpecies, Pair.of(chartFile, writer.toString())); + writer.close(); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't save chart", ex); + } + } + + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers ------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchExtractTypeSet(LegacyResultRepository repository, + ExtractRawDataAndResultsRequest request) { + boolean result = false; + if (repository.isMapsResult()) { + result = request.getExtractTypeList().contains(DataType.SOURCE); + } + if (repository.isIndicatorsResult()) { + result = request.getExtractTypeList().contains(DataType.POPULATION) || + request.getExtractTypeList().contains(DataType.COMMUNITY); + } + if (repository.isDataResult()) { + result = request.getExtractTypeList().contains(DataType.SOURCE); + } + return result; + } + + protected boolean matchZoneList(LegacyResultRepository repository, + ExtractRawDataAndResultsRequest request) { + return request.getZoneList().contains(repository.getZone()); + } + + protected boolean matchCommunityIndicatorList(LegacyResultRepository repository, + ExtractRawDataAndResultsRequest request) { + Preconditions.checkNotNull(request.getCommunityIndicatorList()); + + List<String> indicatorList = request.getCommunityIndicatorList(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorList(tuple, indicatorList)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchPopulationIndicatorList(LegacyResultRepository repository, + ExtractRawDataAndResultsRequest request) { + Preconditions.checkNotNull(request.getPopulationIndicatorList()); + + List<String> indicatorList = request.getPopulationIndicatorList(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorList(tuple, indicatorList)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchPopulationIndicatorListAndSpeciesList(LegacyResultRepository repository, + ExtractRawDataAndResultsRequest request) { + Preconditions.checkNotNull(request.getPopulationIndicatorList()); + + List<String> indicatorList = request.getPopulationIndicatorList(); + List<String> speciesList = request.getSpeciesList(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchCommunityIndicatorListAndSpeciesList(LegacyResultRepository repository, + ExtractRawDataAndResultsRequest request) { + Preconditions.checkNotNull(request.getCommunityIndicatorList()); + + List<String> indicatorList = request.getCommunityIndicatorList(); + List<String> speciesList = request.getSpeciesList(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { + result = true; + break; + } + } + return result; + } + +} Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/ExtractRawDataCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/RawDataResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/ExtractRawDataCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/ExtractRawDataCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,107 @@ +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 fr.ifremer.coser.CoserConstants; +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.Reports; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.ExtractRawDataRequest; +import org.apache.commons.io.FileUtils; +import org.nuiton.util.FileUtil; +import org.nuiton.util.ZipUtil; + +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.Locale; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class ExtractRawDataCommand implements ResultRepositoryCommand<LegacyResultRepository, ExtractRawDataRequest> { + + @Override + public Class<ExtractRawDataRequest> getRequestType() { + return ExtractRawDataRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + ExtractRawDataRequest request) { + return repository.isDataResult() && + repository.matchFacade(request) && + repository.matchZone(request); + } + + @Override + public FileResult execute(LegacyResultRepository repository, + ExtractRawDataRequest r) { + + Locale locale = r.getLocale(); + + repository.loadSelectionData(); + + File resultZip; + + try { + File tempDir = FileUtil.createTempDirectory("coser-source-", "-tmp"); + + // il ne faut pas les fichiers de selection, mais leurs + // export rsufi (sans les lignes, et les quotes) + File archiveDir = repository.extractRSUfiData(tempDir); + + // add decharge file + Reports reports = repository.getReports(); + String filename = reports.getDechargeFilename(locale); + File dechargePDF = new File(archiveDir, filename); + + Date lastDataUpdateDate = repository.getConfig().getLastDataUpdateDate(); + + reports.generateDechargePDF(dechargePDF, locale, lastDataUpdateDate, repository.getSurveyName()); + + // ajout du reftax dans le zip + File reftaxFile = new File(repository.getBasedir(), CoserConstants.Category.REFTAX_SPECIES.getStorageFileName()); + FileUtils.copyFileToDirectory(reftaxFile, archiveDir); + + // make zip + resultZip = File.createTempFile("coser-source-", ".zip"); + resultZip.deleteOnExit(); + ZipUtil.compress(resultZip, archiveDir); + + // clean directory + FileUtils.deleteDirectory(tempDir); + } catch (IOException e) { + throw new CoserTechnicalException("Can't create zip file", e); + } + + FileResult result = new FileResult(repository.getId(), resultZip); + return result; + } + +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetAllResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetAllResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetAllResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,103 @@ +package fr.ifremer.coser.result.repository.legacy.command; + +/* + * #%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.collect.Maps; +import fr.ifremer.coser.result.CoserResult; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepositoryType; +import fr.ifremer.coser.result.request.GetAllResultsRequest; + +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetAllResultsCommand implements ResultRepositoryCommand<LegacyResultRepository, GetAllResultsRequest> { + + @Override + public Class<GetAllResultsRequest> getRequestType() { + return GetAllResultsRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetAllResultsRequest request) { + boolean result = matchRepositoryType(request) && + matchResultType(repository, request) && + matchPublish(repository); + return result; + } + + @Override + public CoserResult execute(LegacyResultRepository repository, + GetAllResultsRequest request) { + Map<String, String> map = Maps.newHashMap(); + String resultResultId = repository.getZone(); + String name = repository.getProjectName() + "/" + repository.getSelectionName() + + "/" + repository.getResultName(); + map.put(resultResultId, name); + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchRepositoryType(GetAllResultsRequest request) { + boolean result = request.getResultRepositoryType().equals(LegacyResultRepositoryType.ID); + return result; + } + + protected boolean matchResultType(LegacyResultRepository repository, + GetAllResultsRequest request) { + boolean result; + ResultType resultType = request.getResultType(); + switch (resultType) { + + case MAP: + result = repository.isMapsResult(); + break; + case INDICATOR: + result = repository.isIndicatorsResult(); + break; + default: + result = false; + break; + } + return result; + } + + protected boolean matchPublish(LegacyResultRepository repository) { + boolean result = repository.isPubliableResult(); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetAllResultsCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetCommunityIndicatorResultCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/CommunityIndicatorResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetCommunityIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetCommunityIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,380 @@ +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.base.Preconditions; +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetCommunityIndicatorResultRequest; +import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.storage.DataStorages; +import fr.ifremer.coser.storage.MemoryDataStorage; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.CategoryLabelPositions; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; +import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; +import org.nuiton.util.FileUtil; +import org.nuiton.util.ZipUtil; + +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetCommunityIndicatorResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetCommunityIndicatorResultRequest> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(GetCommunityIndicatorResultCommand.class); + + @Override + public Class<GetCommunityIndicatorResultRequest> getRequestType() { + return GetCommunityIndicatorResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetCommunityIndicatorResultRequest request) { + return repository.isIndicatorsResult() && + repository.matchFacade(request) && + repository.matchZone(request) && + matchIndicatorAndSpeciesList(repository, request); + } + + @Override + public FileResult execute(LegacyResultRepository repository, + GetCommunityIndicatorResultRequest request) { + + File file = null; + switch (request.getIndicatorResultType()) { + case DATA: + file = getCommunityIndicatorDataFile(repository, + request.getLocale(), + request.getIndicator(), + request.getSpecies()); + break; + + case GRAPH: + file = getCommunityIndicatorGraphFile(repository, + request.getLocale(), + request.getZone(), + request.getIndicator(), + request.getSpecies()); + break; + } + FileResult result = new FileResult(repository.getId(), file); + return result; + } + + protected File getCommunityIndicatorDataFile(LegacyResultRepository repository, + Locale locale, + String indicator, + String speciesList) { + + try { + + File tempDir = FileUtil.createTempDirectory("coser-chart-population-indicator", "-tmp"); + + File baseDir = new File(tempDir, repository.getSurveyName()); + FileUtils.forceMkdir(baseDir); + + // ajout du fichier csv avec les indicateurs + DataStorage dataStorage = new MemoryDataStorage(); + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(false); + + // add header + dataStorage.add(iterator.next()); + + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { + dataStorage.add(tuple); + } + } + File csvFile = DataStorages.save(dataStorage, "coser-chart-community-indicator", + ".csv" + ); + + File csvFileCopied = new File(baseDir, indicator + ".csv"); + FileUtils.copyFile(csvFile, csvFileCopied); + FileUtils.forceDelete(csvFile); + + // ajout du fichier d'information sur les espèces incluses dans + // les calculs des indicateurs de communautés + // load project (without data to get reftax data) + File metaFile = repository.getReports().generateMetaFilePDF(repository.getPath(), + repository.getResultDirectory(), + locale, + repository.getIndicatorsMap() + ); + File metaFileCopied = new File(baseDir, "Information.pdf"); + FileUtils.copyFile(metaFile, metaFileCopied); + + // make zip + File result = File.createTempFile("coser-chart-community-indicator", ".zip"); + result.deleteOnExit(); + ZipUtil.compress(result, baseDir); + + // clean directory + FileUtils.deleteDirectory(tempDir); + return result; + } catch (Exception e) { + throw new CoserTechnicalException("Can't create zip file", e); + } + } + + protected File getCommunityIndicatorGraphFile(LegacyResultRepository repository, + Locale locale, + String zone, + String indicator, + String speciesList) { + + // indicator list to take care + // pour avoir une valeur non nulle si list est null + // on prend dans ce cas la premiere valeur trouvée + String localList = speciesList; + + if (log.isDebugEnabled()) { + log.debug("Searching list for indicator : " + indicator); + } + + int multiplicator = 1; + int minYear = Integer.MAX_VALUE; + int maxYear = Integer.MIN_VALUE; + boolean indicatorFound = false; + Map<Integer, Double[]> graphData = new HashMap<Integer, Double[]>(); + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + // Campagne Indicateur Liste Strate Annee Estimation EcartType CV + String[] tuple = iterator.next(); + String indicatorList = tuple[2]; + + if (repository.matchCommunityIndicator(tuple, indicator)) { + indicatorFound = true; + + // si pas de list selectionnée, on prend la premiere + if (StringUtils.isBlank(localList)) { + localList = indicatorList; + } + + if (indicatorList.equals(localList)) { + Double estimation = Double.parseDouble(tuple[5]); + Double ecart = Double.parseDouble(tuple[6]); + int year = Integer.parseInt(tuple[4]); + + if (year < minYear) { + minYear = year; + } + if (year > maxYear) { + maxYear = year; + } + graphData.put(year, new Double[]{estimation, ecart}); + + // si les données sont énormes, on affiche les données + // / multiplicator et on le mentionne dans la légende + if (estimation > 1e9) { + multiplicator = 1000000; + } + if (estimation > 1e6 && multiplicator < 1000000) { + multiplicator = 1000; + } + } + } + } + + File result = null; + + // avec l'extraction des données, on peut demander a générer un graphique + // sur un indicateur qui n'est pas présent dans le projet courant, + // dans ce cas, on retourne null + if (indicatorFound) { + + String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); + String indicatorName = repository.getIndicatorsMap().getIndicatorValue(indicator, locale); + String unit = repository.getIndicatorsMap().getIndicatorUnit(indicator); + + // get graph title + String chartTitle = zoneDisplayName; + chartTitle += " - " + indicatorName; + + String speciesListName = repository.getSpeciesListMap().getSpeciesListName(locale, localList); + chartTitle += " - " + speciesListName; +// // ajout de la traduction de la liste d'indicateur +// // les liste sont a1, T1, T2 ... +// String listLetter = String.valueOf(localList.charAt(0)); +// Iterator<String[]> typeIterator = repository.getSpeciesListMap().iterator(true); +// while (typeIterator.hasNext()) { +// // "Types";"Commentaire";"NumSys min";"NumSys max";"Code" +// String[] tuple = typeIterator.next(); +// if (tuple[4].equals(listLetter)) { +// /// gestion du groupe "Tous" +// // cas special, c'est la seule valeur du fichier +// // code type espece qui a besoin d'une traduction +// if (tuple[4].equalsIgnoreCase("T")) { +// if ("fr".equals(locale.getLanguage())) { +// chartTitle += " - " + "Tous Liste " + localList.charAt(1); +// } else if ("es".equals(locale.getLanguage())) { +// chartTitle += " - " + "Todo Lista " + localList.charAt(1); +// } else { +// chartTitle += " - " + "All List " + localList.charAt(1); +// } +// } else { +// // ajout de la traduction du nom de liste plus le numéro +// if ("fr".equals(locale.getLanguage())) { +// chartTitle += " - " + tuple[0] + " Liste " + localList.charAt(1); +// } else if ("es".equals(locale.getLanguage())) { +// chartTitle += " - " + tuple[0] + " Lista " + localList.charAt(1); +// } else { +// chartTitle += " - " + tuple[0] + " List " + localList.charAt(1); +// } +// } +// break; +// } +// } + + // generate dataset with sorted data + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { + Double[] entry = graphData.get(indexYear); + if (entry != null) { + Double estimation = entry[0] / multiplicator; + Double ecart = entry[1] / multiplicator; + statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); + } else { + statisticalDataset.add(null, null, "Serie1", indexYear); + } + } + + // configure chart + //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); + String yearAxis = repository.getReports().getYearChartTitle(locale); + + CategoryAxis categoryAxis = new CategoryAxis(yearAxis); + categoryAxis.setCategoryMargin(0); + categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + // label horizontaux + String legendY = indicatorName; + if (multiplicator != 1) { + // affiche par exemple : cm * 1000 + legendY += " (" + unit + "*" + multiplicator + ")"; + } else if (StringUtils.isNotEmpty(unit)) { + legendY += " (" + unit + ")"; + } + ValueAxis valueAxis = new NumberAxis(legendY); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart(chartTitle, + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + // remove series legend + chart.removeLegend(); + // white background + chart.setBackgroundPaint(Color.WHITE); + + try { + result = File.createTempFile("coser-chart-community-indicator-", ".png"); + result.deleteOnExit(); + ChartUtilities.saveChartAsPNG(result, chart, 800, 400); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't save chart", ex); + } + } + + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers ------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchIndicator(LegacyResultRepository repository, + GetCommunityIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getIndicator()); + + String indicator = request.getIndicator(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchCommunityIndicator(tuple, indicator)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchIndicatorAndSpeciesList(LegacyResultRepository repository, + GetCommunityIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getIndicator()); + Preconditions.checkNotNull(request.getSpecies()); + + String indicator = request.getIndicator(); + String speciesList = request.getSpecies(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { + result = true; + break; + } + } + return result; + } +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForCommunityIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForCommunityIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForCommunityIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,64 @@ +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 fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetIndicatorsForCommunityIndicatorResultRequest; + +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetIndicatorsForCommunityIndicatorResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetIndicatorsForCommunityIndicatorResultRequest> { + + @Override + public Class<GetIndicatorsForCommunityIndicatorResultRequest> getRequestType() { + return GetIndicatorsForCommunityIndicatorResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetIndicatorsForCommunityIndicatorResultRequest request) { + return repository.isIndicatorsResult() && + repository.matchFacade(request) && + repository.matchZone(request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetIndicatorsForCommunityIndicatorResultRequest request) { + + Set<String> indicatorList = repository.getCommunityIndicators(); + Map<String, String> map = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForCommunityIndicatorResultCommand.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/legacy/command/GetIndicatorsForExtractRawDataAndResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForExtractRawDataAndResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForExtractRawDataAndResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,105 @@ +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 fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetIndicatorsForExtractRawDataAndResultsRequest; +import fr.ifremer.coser.util.DataType; + +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetIndicatorsForExtractRawDataAndResultsCommand implements ResultRepositoryCommand<LegacyResultRepository, GetIndicatorsForExtractRawDataAndResultsRequest> { + + @Override + public Class<GetIndicatorsForExtractRawDataAndResultsRequest> getRequestType() { + return GetIndicatorsForExtractRawDataAndResultsRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetIndicatorsForExtractRawDataAndResultsRequest request) { + return matchExtractTypeSet(repository, request) && + matchZoneList(repository, request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetIndicatorsForExtractRawDataAndResultsRequest request) { + + + Set<String> indicatorList = null; + + if (request.getExtractTypeList().contains(DataType.COMMUNITY)) { + + // get all community indicators for given zone + indicatorList = repository.getCommunityIndicators(); + } else if (request.getExtractTypeList().contains(DataType.POPULATION)) { + + // get all population indicators for given zone + indicatorList = repository.getPopulationIndicators(); + } + + Map<String, String> map = null; + if (indicatorList != null) { + map = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); + } + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers ------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchExtractTypeSet(LegacyResultRepository repository, + GetIndicatorsForExtractRawDataAndResultsRequest request) { + boolean result = false; + if (repository.isMapsResult()) { + result = request.getExtractTypeList().contains(DataType.SOURCE); + } + if (repository.isIndicatorsResult()) { + result = request.getExtractTypeList().contains(DataType.POPULATION) || + request.getExtractTypeList().contains(DataType.COMMUNITY); + } + if (repository.isDataResult()) { + result = request.getExtractTypeList().contains(DataType.SOURCE); + } + return result; + } + + protected boolean matchZoneList(LegacyResultRepository repository, + GetIndicatorsForExtractRawDataAndResultsRequest request) { + return request.getZoneList().contains(repository.getZone()); + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForExtractRawDataAndResultsCommand.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/legacy/command/GetIndicatorsForPopulationIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForPopulationIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForPopulationIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,91 @@ +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.base.Preconditions; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetIndicatorsForPopulationIndicatorResultRequest; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetIndicatorsForPopulationIndicatorResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetIndicatorsForPopulationIndicatorResultRequest> { + + @Override + public Class<GetIndicatorsForPopulationIndicatorResultRequest> getRequestType() { + return GetIndicatorsForPopulationIndicatorResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetIndicatorsForPopulationIndicatorResultRequest request) { + return repository.isIndicatorsResult() && + repository.matchFacade(request) && + repository.matchZone(request) && + matchSpecies(repository, request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetIndicatorsForPopulationIndicatorResultRequest request) { + + Set<String> indicatorList = repository.getPopulationIndicators(request.getSpecies()); + Map<String, String> map = repository.getIndicatorsMap().getIndicatorsValues(indicatorList, request.getLocale()); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchSpecies(LegacyResultRepository repository, + GetIndicatorsForPopulationIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getSpecies()); + + String species = request.getSpecies(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchPopulationSpecies(tuple, species)) { + result = true; + break; + } + } + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetIndicatorsForPopulationIndicatorResultCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetMapResultCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/MapResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetMapResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetMapResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,75 @@ +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 fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetMapResultRequest; + +import java.io.File; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetMapResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetMapResultRequest> { + + @Override + public Class<GetMapResultRequest> getRequestType() { + return GetMapResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetMapResultRequest request) { + return repository.isMapsResult() && + repository.matchFacade(request) && + repository.matchZone(request) && + matchSpecies(repository, request); + } + + @Override + public FileResult execute(LegacyResultRepository repository, + GetMapResultRequest r) { + + File resultZip = repository.getMapSpeciesFile(r.getSpecies()); + + FileResult result = new FileResult(repository.getId(), resultZip); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers ------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchSpecies(LegacyResultRepository repository, + GetMapResultRequest request) { + String species = request.getSpecies(); + File file = repository.getMapSpeciesFile(species); + return file != null; + } + +} Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetPopulationIndicatorResultCommand.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/PopulationIndicatorResultProducer.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetPopulationIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetPopulationIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,288 @@ +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.base.Preconditions; +import fr.ifremer.coser.CoserTechnicalException; +import fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetPopulationIndicatorResultRequest; +import fr.ifremer.coser.storage.DataStorage; +import fr.ifremer.coser.storage.DataStorages; +import fr.ifremer.coser.storage.MemoryDataStorage; +import org.apache.commons.lang3.StringUtils; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.axis.CategoryAxis; +import org.jfree.chart.axis.CategoryLabelPositions; +import org.jfree.chart.axis.NumberAxis; +import org.jfree.chart.axis.ValueAxis; +import org.jfree.chart.plot.CategoryPlot; +import org.jfree.chart.plot.PlotOrientation; +import org.jfree.chart.renderer.category.CategoryItemRenderer; +import org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer; +import org.jfree.data.statistics.DefaultStatisticalCategoryDataset; + +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetPopulationIndicatorResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetPopulationIndicatorResultRequest> { + + @Override + public Class<GetPopulationIndicatorResultRequest> getRequestType() { + return GetPopulationIndicatorResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetPopulationIndicatorResultRequest request) { + return repository.isIndicatorsResult() && + repository.matchFacade(request) && + repository.matchZone(request) && + matchSpeciesAndIndicator(repository, request); + } + + @Override + public FileResult execute(LegacyResultRepository repository, + GetPopulationIndicatorResultRequest request) { + + File file = null; + switch (request.getIndicatorResultType()) { + case DATA: + file = getPopulationIndicatorDataFile(repository, + request.getIndicator(), + request.getSpecies()); + break; + + case GRAPH: + file = getPopulationIndicatorGraphFile(repository, + request.getLocale(), + request.getZone(), + request.getIndicator(), + request.getSpecies()); + break; + } + + + FileResult result = new FileResult(repository.getId(), file); + return result; + } + + protected File getPopulationIndicatorDataFile(LegacyResultRepository repository, + String species, + String indicator) { + + DataStorage dataStorage = new MemoryDataStorage(); + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(false); + + // add header + dataStorage.add(iterator.next()); + + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchPopulationSpeciesAndIndicator(tuple, species, indicator)) { + dataStorage.add(tuple); + } + } + File result = DataStorages.save(dataStorage, "coser-chart-population-indicator", + ".csv" + ); + return result; + } + + protected File getPopulationIndicatorGraphFile(LegacyResultRepository repository, + Locale locale, + String zone, + String species, + String indicator) { + + int multiplicator = 1; + int minYear = Integer.MAX_VALUE; + int maxYear = Integer.MIN_VALUE; + boolean indicatorFound = false; + Map<Integer, Double[]> graphData = new HashMap<Integer, Double[]>(); + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + + if (repository.matchPopulationSpeciesAndIndicator(tuple, species, indicator)) { + indicatorFound = true; + + // XXX echatellier, maybe take care of list here ? + + Double estimation = Double.parseDouble(tuple[6]); + Double ecart = Double.parseDouble(tuple[7]); + int year = Integer.parseInt(tuple[5]); + + if (year < minYear) { + minYear = year; + } + if (year > maxYear) { + maxYear = year; + } + graphData.put(year, new Double[]{estimation, ecart}); + + // si les données sont énormes, on affiche les données + // / multiplicator et on le mentionne dans la légende + if (estimation > 1e9) { + multiplicator = 1000000; + } + if (estimation > 1e6 && multiplicator < 1000000) { + multiplicator = 1000; + } + } + } + + File result = null; + + // avec l'extraction des données, on peut demander a générer un graphique + // sur un indicateur qui n'est pas présent dans le projet courant, + // dans ce cas, on retourne null + if (indicatorFound) { + + String zoneDisplayName = repository.getZonesMap().getZoneFullName(zone); + String indicatorName = repository.getIndicatorsMap().getIndicatorValue(indicator, locale); + String unit = repository.getIndicatorsMap().getIndicatorUnit(indicator); + + // get graph title + String title = zoneDisplayName; + title += " - " + indicatorName; + title += " - " + repository.getSpeciesMap().getReportDisplayName(species); + + // generate dataset with sorted data + DefaultStatisticalCategoryDataset statisticalDataset = new DefaultStatisticalCategoryDataset(); + for (int indexYear = minYear; indexYear <= maxYear; ++indexYear) { + Double[] entry = graphData.get(indexYear); + if (entry != null) { + Double estimation = entry[0] / multiplicator; + Double ecart = entry[1] / multiplicator; + statisticalDataset.add(estimation, ecart, "Serie1", (Comparable) indexYear); + } else { + statisticalDataset.add(null, null, "Serie1", indexYear); + } + } + + // configure chart + //CategoryAxis categoryAxis = new CategoryAxis(t("coser.business.common.year")); + String yearAxis = repository.getReports().getYearChartTitle(locale); + CategoryAxis categoryAxis = new CategoryAxis(yearAxis); + categoryAxis.setCategoryMargin(0); + categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); + // label horizontaux + String legendY = indicatorName; + if (multiplicator != 1) { + // affiche par exemple : cm * 1000 + legendY += " (" + unit + "*" + multiplicator + ")"; + } else if (StringUtils.isNotEmpty(unit)) { + legendY += " (" + unit + ")"; + } + ValueAxis valueAxis = new NumberAxis(legendY); + valueAxis.setUpperMargin(0.1); + + CategoryItemRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); + + // n'affiche pas les nombre sur le graphique + //StandardCategoryItemLabelGenerator itemLabelGenerator = new StandardCategoryItemLabelGenerator(); + //renderer.setBaseItemLabelGenerator(itemLabelGenerator); + //renderer.setBaseItemLabelsVisible(true); + + CategoryPlot plot = new CategoryPlot(statisticalDataset, categoryAxis, valueAxis, renderer); + plot.setOrientation(PlotOrientation.VERTICAL); + JFreeChart chart = new JFreeChart(title, + JFreeChart.DEFAULT_TITLE_FONT, plot, true); + + // remove series legend + chart.removeLegend(); + // white background + chart.setBackgroundPaint(Color.WHITE); + + try { + result = File.createTempFile("coser-chart-population-indicator-", ".png"); + result.deleteOnExit(); + ChartUtilities.saveChartAsPNG(result, chart, 800, 400); + } catch (IOException ex) { + throw new CoserTechnicalException("Can't save chart", ex); + } + } + + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchSpecies(LegacyResultRepository repository, + GetPopulationIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getSpecies()); + + String species = request.getSpecies(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchPopulationSpecies(tuple, species)) { + result = true; + break; + } + } + return result; + } + + protected boolean matchSpeciesAndIndicator(LegacyResultRepository repository, + GetPopulationIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getSpecies()); + Preconditions.checkNotNull(request.getIndicator()); + + String species = request.getSpecies(); + String indicator = request.getIndicator(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadPopulationIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchPopulationSpeciesAndIndicator(tuple, species, indicator)) { + result = true; + break; + } + } + return result; + } + +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesForMapResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesForMapResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesForMapResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,61 @@ +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 fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetSpeciesForMapResultRequest; + +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesForMapResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetSpeciesForMapResultRequest> { + + @Override + public Class<GetSpeciesForMapResultRequest> getRequestType() { + return GetSpeciesForMapResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, GetSpeciesForMapResultRequest request) { + return repository.isMapsResult() && + repository.matchFacade(request) && + repository.matchZone(request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, GetSpeciesForMapResultRequest request) { + + Map<String, String> map = repository.getPopulationIndicatorSpecies(); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesForMapResultCommand.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/legacy/command/GetSpeciesForPopulationIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesForPopulationIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesForPopulationIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,63 @@ +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 fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetSpeciesForPopulationIndicatorResultRequest; + +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesForPopulationIndicatorResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetSpeciesForPopulationIndicatorResultRequest> { + + @Override + public Class<GetSpeciesForPopulationIndicatorResultRequest> getRequestType() { + return GetSpeciesForPopulationIndicatorResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetSpeciesForPopulationIndicatorResultRequest request) { + return repository.isIndicatorsResult() && + repository.matchFacade(request) && + repository.matchZone(request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetSpeciesForPopulationIndicatorResultRequest request) { + + Map<String, String> map = repository.getPopulationIndicatorSpecies(); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesForPopulationIndicatorResultCommand.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/legacy/command/GetSpeciesListForCommunityIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesListForCommunityIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesListForCommunityIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,90 @@ +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.base.Preconditions; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetSpeciesListForCommunityIndicatorResultRequest; + +import java.util.Iterator; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesListForCommunityIndicatorResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetSpeciesListForCommunityIndicatorResultRequest> { + + @Override + public Class<GetSpeciesListForCommunityIndicatorResultRequest> getRequestType() { + return GetSpeciesListForCommunityIndicatorResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetSpeciesListForCommunityIndicatorResultRequest request) { + return repository.isIndicatorsResult() && + repository.matchFacade(request) && + repository.matchZone(request) && + matchIndicator(repository, request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetSpeciesListForCommunityIndicatorResultRequest request) { + + Map<String, String> map = repository.getCommunityIndicatorSpecies(request.getLocale(), + request.getIndicator()); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers ------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchIndicator(LegacyResultRepository repository, + GetSpeciesListForCommunityIndicatorResultRequest request) { + Preconditions.checkNotNull(request.getIndicator()); + + String indicator = request.getIndicator(); + + boolean result = false; + + Iterator<String[]> iterator = repository.loadCommunityIndicatorStorage(true); + while (iterator.hasNext()) { + String[] tuple = iterator.next(); + if (repository.matchCommunityIndicator(tuple, indicator)) { + result = true; + break; + } + } + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesListForCommunityIndicatorResultCommand.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/legacy/command/GetSpeciesListForExtractRawDataAndResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesListForExtractRawDataAndResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesListForExtractRawDataAndResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,93 @@ +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.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetSpeciesListForExtractRawDataAndResultsRequest; +import fr.ifremer.coser.util.DataType; + +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesListForExtractRawDataAndResultsCommand implements ResultRepositoryCommand<LegacyResultRepository, GetSpeciesListForExtractRawDataAndResultsRequest> { + + @Override + public Class<GetSpeciesListForExtractRawDataAndResultsRequest> getRequestType() { + return GetSpeciesListForExtractRawDataAndResultsRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetSpeciesListForExtractRawDataAndResultsRequest request) { + return matchExtractTypeSet(repository, request) && + matchZoneList(repository, request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetSpeciesListForExtractRawDataAndResultsRequest request) { + + Map<String, String> map = Maps.newHashMap(); + + // get all species for population indicators + map.putAll(repository.getPopulationIndicatorSpecies()); + // get all species for community indicators + map.putAll(repository.getCommunityIndicatorSpecies()); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + // --------------------------------------------------------------------- // + // --- Matchers ------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchExtractTypeSet(LegacyResultRepository repository, + GetSpeciesListForExtractRawDataAndResultsRequest request) { + boolean result = false; + if (repository.isMapsResult()) { + result = request.getExtractTypeList().contains(DataType.SOURCE); + } + if (repository.isIndicatorsResult()) { + result = request.getExtractTypeList().contains(DataType.POPULATION) || + request.getExtractTypeList().contains(DataType.COMMUNITY); + } + if (repository.isDataResult()) { + result = request.getExtractTypeList().contains(DataType.SOURCE); + } + return result; + } + + protected boolean matchZoneList(LegacyResultRepository repository, + GetSpeciesListForExtractRawDataAndResultsRequest request) { + return request.getZoneList().contains(repository.getZone()); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetSpeciesListForExtractRawDataAndResultsCommand.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/legacy/command/GetZonesForCommunityIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForCommunityIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForCommunityIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,64 @@ +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 fr.ifremer.coser.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetZonesForCommunityIndicatorResultRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForCommunityIndicatorResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetZonesForCommunityIndicatorResultRequest> { + + @Override + public Class<GetZonesForCommunityIndicatorResultRequest> getRequestType() { + return GetZonesForCommunityIndicatorResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, GetZonesForCommunityIndicatorResultRequest request) { + return repository.isIndicatorsResult() && repository.matchFacade(request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, GetZonesForCommunityIndicatorResultRequest request) { + + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForCommunityIndicatorResultCommand.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/legacy/command/GetZonesForExtractRawDataCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForExtractRawDataCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForExtractRawDataCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,66 @@ +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 fr.ifremer.coser.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetZonesForExtractRawDataRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForExtractRawDataCommand implements ResultRepositoryCommand<LegacyResultRepository, GetZonesForExtractRawDataRequest> { + + @Override + public Class<GetZonesForExtractRawDataRequest> getRequestType() { + return GetZonesForExtractRawDataRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetZonesForExtractRawDataRequest request) { + return repository.isDataResult() && + repository.matchFacade(request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetZonesForExtractRawDataRequest request) { + + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForExtractRawDataCommand.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/legacy/command/GetZonesForMapResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForMapResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForMapResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,66 @@ +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 fr.ifremer.coser.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetZonesForMapResultRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForMapResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetZonesForMapResultRequest> { + + @Override + public Class<GetZonesForMapResultRequest> getRequestType() { + return GetZonesForMapResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetZonesForMapResultRequest request) { + return repository.isMapsResult() && + repository.matchFacade(request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetZonesForMapResultRequest request) { + + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForMapResultCommand.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/legacy/command/GetZonesForPopulationIndicatorResultCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForPopulationIndicatorResultCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForPopulationIndicatorResultCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,66 @@ +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 fr.ifremer.coser.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetZonesForPopulationIndicatorResultRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForPopulationIndicatorResultCommand implements ResultRepositoryCommand<LegacyResultRepository, GetZonesForPopulationIndicatorResultRequest> { + + @Override + public Class<GetZonesForPopulationIndicatorResultRequest> getRequestType() { + return GetZonesForPopulationIndicatorResultRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetZonesForPopulationIndicatorResultRequest request) { + return repository.isIndicatorsResult() && + repository.matchFacade(request); + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetZonesForPopulationIndicatorResultRequest request) { + + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(request.getFacade()); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesForPopulationIndicatorResultCommand.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/legacy/command/GetZonesListForExtractRawDataAndResultsCommand.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesListForExtractRawDataAndResultsCommand.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesListForExtractRawDataAndResultsCommand.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,63 @@ +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 fr.ifremer.coser.bean.ZoneMap; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryCommand; +import fr.ifremer.coser.result.repository.legacy.LegacyResultRepository; +import fr.ifremer.coser.result.request.GetZonesForExtractRawDataAndResultsRequest; + +import java.util.List; +import java.util.Map; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesListForExtractRawDataAndResultsCommand implements ResultRepositoryCommand<LegacyResultRepository, GetZonesForExtractRawDataAndResultsRequest> { + + @Override + public Class<GetZonesForExtractRawDataAndResultsRequest> getRequestType() { + return GetZonesForExtractRawDataAndResultsRequest.class; + } + + @Override + public boolean accept(LegacyResultRepository repository, + GetZonesForExtractRawDataAndResultsRequest request) { + return true; + } + + @Override + public MapResult execute(LegacyResultRepository repository, + GetZonesForExtractRawDataAndResultsRequest request) { + ZoneMap zonesMap = repository.getZonesMap(); + List<String> allowedZones = zonesMap.getZonesForFacade(null); + Map<String, String> map = zonesMap.getSubZonesMap(repository.getZone(), allowedZones); + MapResult result = new MapResult(repository.getId(), map); + return result; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/command/GetZonesListForExtractRawDataAndResultsCommand.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/AbstractGetIndicatorResultRequest.java (from rev 1141, trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/IndicatorRequest.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/AbstractGetIndicatorResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/AbstractGetIndicatorResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,122 @@ +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 java.util.Locale; + +/** + * Request to obtain indicator results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public abstract class AbstractGetIndicatorResultRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware, CoserRequestSpeciesAware, CoserRequestIndicatorAware { + + private static final long serialVersionUID = 1L; + + /** + * Type of result. + */ + public enum IndicatorResultType { + DATA, + GRAPH + } + + protected Locale locale; + + protected String facade; + + protected String zone; + + protected String indicator; + + protected IndicatorResultType indicatorResultType; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || + facade == null || + zone == null || + indicatorResultType == null || + indicator == null); + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } + + @Override + public String getZone() { + return zone; + } + + @Override + public void setZone(String zone) { + Preconditions.checkNotNull(zone); + this.zone = zone; + } + + public IndicatorResultType getIndicatorResultType() { + return indicatorResultType; + } + + public void setIndicatorResultType(IndicatorResultType indicatorResultType) { + Preconditions.checkNotNull(indicatorResultType); + this.indicatorResultType = indicatorResultType; + } + + @Override + public String getIndicator() { + return indicator; + } + + @Override + public void setIndicator(String indicator) { + Preconditions.checkNotNull(indicator); + this.indicator = indicator; + } + +} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CommunityIndicatorRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CommunityIndicatorRequest.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CommunityIndicatorRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,56 +0,0 @@ -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; - -/** - * Request to obtain community indicator results. - * <p/> - * Created on 3/4/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class CommunityIndicatorRequest extends IndicatorRequest { - - private static final long serialVersionUID = 1L; - - protected String species; - - @Override - public String getSpecies() { - return species; - } - - @Override - public void setSpecies(String species) { - Preconditions.checkNotNull(facade); - this.species = species; - } - - @Override - public boolean isFilled() { - return super.isFilled() && species != null; - } -} Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestBuilder.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestBuilder.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestBuilder.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,7 +22,10 @@ * #L% */ +import com.google.common.base.Preconditions; +import fr.ifremer.coser.CoserTechnicalException; import fr.ifremer.coser.result.CoserRequest; +import fr.ifremer.coser.result.ResultType; import fr.ifremer.coser.util.DataType; import org.apache.commons.collections4.CollectionUtils; @@ -37,7 +40,7 @@ * @author Tony Chemit <chemit@codelutin.com> * @since 1.5 */ -public class CoserRequestBuilder { +public class CoserRequestBuilder<R extends CoserRequest> { protected final Locale locale; @@ -49,7 +52,7 @@ protected String indicator; - protected IndicatorRequest.ResultType resultType; + protected AbstractGetIndicatorResultRequest.IndicatorResultType indicatorResultType; protected List<DataType> extractTypeList; @@ -61,91 +64,92 @@ protected List<String> communityIndicatorList; - public CoserRequestBuilder(Locale locale) { + protected String resultRepositoryType; + + protected ResultType resultType; + + protected final Class<R> requestType; + + public CoserRequestBuilder(Locale locale, Class<R> requestType) { + Preconditions.checkNotNull(locale); + Preconditions.checkNotNull(requestType); this.locale = locale; + this.requestType = requestType; } - public CoserRequestBuilder addFacade(String facade) { + public CoserRequestBuilder<R> addFacade(String facade) { this.facade = facade; return this; } - public CoserRequestBuilder addZone(String zone) { + public CoserRequestBuilder<R> addZone(String zone) { this.zone = zone; return this; } - public CoserRequestBuilder addSpecies(String species) { + public CoserRequestBuilder<R> addSpecies(String species) { this.species = species; return this; } - public CoserRequestBuilder addIndicator(String indicator) { + public CoserRequestBuilder<R> addIndicator(String indicator) { this.indicator = indicator; return this; } - public CoserRequestBuilder addResultType(IndicatorRequest.ResultType resultType) { - this.resultType = resultType; + public CoserRequestBuilder<R> addIndicatorResultType(AbstractGetIndicatorResultRequest.IndicatorResultType indicatorResultType) { + this.indicatorResultType = indicatorResultType; return this; } - public CoserRequestBuilder addExtractTypeList(List<DataType> extractTypeSet) { + public CoserRequestBuilder<R> addExtractTypeList(List<DataType> extractTypeSet) { this.extractTypeList = extractTypeSet; return this; } - public CoserRequestBuilder addZoneList(List<String> zoneList) { + public CoserRequestBuilder<R> addZoneList(List<String> zoneList) { this.zoneList = zoneList; return this; } - public CoserRequestBuilder addSpeciesList(List<String> speciesList) { + public CoserRequestBuilder<R> addSpeciesList(List<String> speciesList) { this.speciesList = speciesList; return this; } - public CoserRequestBuilder addPopulationIndicatorList(List<String> populationIndicatorList) { + public CoserRequestBuilder<R> addPopulationIndicatorList(List<String> populationIndicatorList) { this.populationIndicatorList = populationIndicatorList; return this; } - public CoserRequestBuilder addCommunityIndicatorList(List<String> communityIndicatorList) { + public CoserRequestBuilder<R> addCommunityIndicatorList(List<String> communityIndicatorList) { this.communityIndicatorList = communityIndicatorList; return this; } - public MapRequest toMapRequest() { - MapRequest request = new MapRequest(); - flush(request); - return request; + public CoserRequestBuilder<R> addResultRepositoryType(String resultRepositoryType) { + this.resultRepositoryType = resultRepositoryType; + return this; } - public RawDataRequest toRawDataRequest() { - RawDataRequest request = new RawDataRequest(); - flush(request); - return request; + public CoserRequestBuilder<R> addResultType(ResultType resultType) { + this.resultType = resultType; + return this; } - public PopulationIndicatorRequest toPopulationIndicatorRequest() { - PopulationIndicatorRequest request = new PopulationIndicatorRequest(); - flush(request); - return request; + public R toRequest() { + try { + R request = requestType.newInstance(); + flush(request); + return request; + } catch (InstantiationException e) { + throw new CoserTechnicalException(e); + } catch (IllegalAccessException e) { + throw new CoserTechnicalException(e); + } } - public CommunityIndicatorRequest toCommunityIndicatorRequest() { - CommunityIndicatorRequest request = new CommunityIndicatorRequest(); - flush(request); - return request; - } - - public ExtractRequest toExtractRequest() { - ExtractRequest request = new ExtractRequest(); - flush(request); - return request; - } - - protected <R extends CoserRequest> void flush(R request) { + protected void flush(R request) { request.setLocale(locale); if (request instanceof CoserRequestFacadeAware) { if (facade != null) { @@ -162,34 +166,56 @@ ((CoserRequestSpeciesAware) request).setSpecies(species); } } - - if (request instanceof IndicatorRequest) { + if (request instanceof CoserRequestZoneListAware) { + if (CollectionUtils.isNotEmpty(zoneList)) { + ((CoserRequestZoneListAware) request).setZoneList(zoneList); + } + } + if (request instanceof CoserRequestIndicatorAware) { if (indicator != null) { - ((IndicatorRequest) request).setIndicator(indicator); + ((CoserRequestIndicatorAware) request).setIndicator(indicator); } - if (resultType != null) { - ((IndicatorRequest) request).setResultType(resultType); + } + + if (request instanceof AbstractGetIndicatorResultRequest) { + if (indicatorResultType != null) { + ((AbstractGetIndicatorResultRequest) request).setIndicatorResultType(indicatorResultType); } } - if (request instanceof ExtractRequest) { + if (request instanceof ExtractRawDataAndResultsRequest) { if (CollectionUtils.isNotEmpty(extractTypeList)) { - ((ExtractRequest) request).setExtractTypeList(extractTypeList); + ((ExtractRawDataAndResultsRequest) request).setExtractTypeList(extractTypeList); } - if (CollectionUtils.isNotEmpty(zoneList)) { - ((ExtractRequest) request).setZoneList(zoneList); - } if (CollectionUtils.isNotEmpty(populationIndicatorList)) { - ((ExtractRequest) request).setPopulationIndicatorList(populationIndicatorList); + ((ExtractRawDataAndResultsRequest) request).setPopulationIndicatorList(populationIndicatorList); } if (CollectionUtils.isNotEmpty(communityIndicatorList)) { - ((ExtractRequest) request).setCommunityIndicatorList(communityIndicatorList); + ((ExtractRawDataAndResultsRequest) request).setCommunityIndicatorList(communityIndicatorList); } if (CollectionUtils.isNotEmpty(speciesList)) { - ((ExtractRequest) request).setSpeciesList(speciesList); + ((ExtractRawDataAndResultsRequest) request).setSpeciesList(speciesList); } } + + if (request instanceof DeleteResultsRequest) { + if (resultRepositoryType != null) { + ((DeleteResultsRequest) request).setResultRepositoryType(resultRepositoryType); + } + if (resultType != null) { + ((DeleteResultsRequest) request).setResultType(resultType); + } + } + + if (request instanceof GetAllResultsRequest) { + if (resultRepositoryType != null) { + ((GetAllResultsRequest) request).setResultRepositoryType(resultRepositoryType); + } + if (resultType != null) { + ((GetAllResultsRequest) request).setResultType(resultType); + } + } } } Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestIndicatorAware.java (from rev 1134, trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneAware.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestIndicatorAware.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestIndicatorAware.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,40 @@ +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 fr.ifremer.coser.result.CoserRequest; + +/** + * Place this on any request which involve a {@code indicator}. + * <p/> + * Created on 3/7/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public interface CoserRequestIndicatorAware extends CoserRequest { + + String getIndicator(); + + void setIndicator(String indicator); +} Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneAware.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneAware.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneAware.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -30,7 +30,7 @@ * Created on 3/7/14. * * @author Tony Chemit <chemit@codelutin.com> - * @since XXX + * @since 1.5 */ public interface CoserRequestZoneAware extends CoserRequest { Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneListAware.java (from rev 1134, trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneAware.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneListAware.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CoserRequestZoneListAware.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,42 @@ +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 fr.ifremer.coser.result.CoserRequest; + +import java.util.List; + +/** + * Place this on any request which involve a {@code zone}. + * <p/> + * Created on 3/7/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public interface CoserRequestZoneListAware extends CoserRequest { + + List<String> getZoneList(); + + void setZoneList(List<String> zoneList); +} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteRequest.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,74 +0,0 @@ -package fr.ifremer.coser.result.request; - -/* - * #%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 fr.ifremer.coser.result.CoserRequest; -import fr.ifremer.coser.util.DataType; -import org.apache.commons.collections4.CollectionUtils; - -import java.util.List; -import java.util.Locale; - -/** - * To delete some results. - * Created on 3/11/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class DeleteRequest implements CoserRequest { - - private static final long serialVersionUID = 1L; - - protected Locale locale; - - protected List<String> zoneList; - - protected List<String> populationIndicatorList; - - protected List<String> communityIndicatorList; - - protected List<String> speciesList; - - protected List<DataType> extractTypeList; - - @Override - public Locale getLocale() { - return locale; - } - - @Override - public void setLocale(Locale locale) { - this.locale = locale; - } - - @Override - public boolean isFilled() { - return !(locale == null || - CollectionUtils.isEmpty(extractTypeList) || - CollectionUtils.isEmpty(zoneList) || - CollectionUtils.isEmpty(populationIndicatorList) || - CollectionUtils.isEmpty(communityIndicatorList) || - CollectionUtils.isEmpty(speciesList)); - } -} Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteResultsRequest.java (from rev 1144, trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteRequest.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteResultsRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteResultsRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,110 @@ +package fr.ifremer.coser.result.request; + +/* + * #%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 fr.ifremer.coser.result.CoserRequest; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.repository.ResultRepositoryType; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.List; +import java.util.Locale; + +/** + * To delete some results. + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class DeleteResultsRequest implements CoserRequest, CoserRequestZoneListAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + /** + * Id of matching result repository type. + * + * @see ResultRepositoryType#getId() + */ + protected String resultRepositoryType; + + /** + * Type of matching result. + */ + protected ResultType resultType; + + /** + * Ids of matching zone to delete. + */ + protected List<String> zoneList; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || + resultRepositoryType == null || + resultType == null || + CollectionUtils.isEmpty(zoneList)); + } + + public String getResultRepositoryType() { + return resultRepositoryType; + } + + public void setResultRepositoryType(String resultRepositoryType) { + Preconditions.checkNotNull(resultRepositoryType); + this.resultRepositoryType = resultRepositoryType; + } + + public ResultType getResultType() { + return resultType; + } + + public void setResultType(ResultType resultType) { + Preconditions.checkNotNull(resultType); + this.resultType = resultType; + } + + @Override + public List<String> getZoneList() { + return zoneList; + } + + @Override + public void setZoneList(List<String> zoneList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(zoneList)); + this.zoneList = zoneList; + } +} Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRawDataAndResultsRequest.java (from rev 1141, trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRequest.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRawDataAndResultsRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRawDataAndResultsRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,124 @@ +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; +import java.util.Locale; + +/** + * Request to extract data. + * <p/> + * Created on 3/9/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class ExtractRawDataAndResultsRequest implements CoserRequest, CoserRequestZoneListAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected List<String> zoneList; + + protected List<String> populationIndicatorList; + + protected List<String> communityIndicatorList; + + protected List<String> speciesList; + + protected List<DataType> extractTypeList; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || + CollectionUtils.isEmpty(extractTypeList) || + CollectionUtils.isEmpty(zoneList) || + CollectionUtils.isEmpty(populationIndicatorList) || + CollectionUtils.isEmpty(communityIndicatorList) || + CollectionUtils.isEmpty(speciesList)); + } + + public List<DataType> getExtractTypeList() { + return extractTypeList; + } + + public void setExtractTypeList(List<DataType> extractTypeSet) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(extractTypeSet)); + this.extractTypeList = extractTypeSet; + } + + @Override + public List<String> getZoneList() { + return zoneList; + } + + @Override + public void setZoneList(List<String> zoneList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(zoneList)); + this.zoneList = zoneList; + } + + public List<String> getPopulationIndicatorList() { + return populationIndicatorList; + } + + public void setPopulationIndicatorList(List<String> populationIndicatorList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(populationIndicatorList)); + this.populationIndicatorList = populationIndicatorList; + } + + public List<String> getCommunityIndicatorList() { + return communityIndicatorList; + } + + public void setCommunityIndicatorList(List<String> communityIndicatorList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(communityIndicatorList)); + this.communityIndicatorList = communityIndicatorList; + } + + public List<String> getSpeciesList() { + return speciesList; + } + + public void setSpeciesList(List<String> speciesList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(speciesList)); + this.speciesList = speciesList; + } +} Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRawDataRequest.java (from rev 1134, trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/RawDataRequest.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRawDataRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRawDataRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,85 @@ +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 java.util.Locale; + +/** + * Request to obtain raw data results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class ExtractRawDataRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + protected String zone; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || facade == null || zone == null); + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } + + @Override + public String getZone() { + return zone; + } + + @Override + public void setZone(String zone) { + Preconditions.checkNotNull(zone); + this.zone = zone; + } +} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRequest.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/ExtractRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,122 +0,0 @@ -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; -import java.util.Locale; - -/** - * Request to extract data. - * <p/> - * Created on 3/9/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class ExtractRequest implements CoserRequest { - - private static final long serialVersionUID = 1L; - - protected Locale locale; - - protected List<String> zoneList; - - protected List<String> populationIndicatorList; - - protected List<String> communityIndicatorList; - - protected List<String> speciesList; - - protected List<DataType> extractTypeList; - - @Override - public Locale getLocale() { - return locale; - } - - @Override - public void setLocale(Locale locale) { - Preconditions.checkNotNull(locale); - this.locale = locale; - } - - @Override - public boolean isFilled() { - return !(locale == null || - CollectionUtils.isEmpty(extractTypeList) || - CollectionUtils.isEmpty(zoneList) || - CollectionUtils.isEmpty(populationIndicatorList) || - CollectionUtils.isEmpty(communityIndicatorList) || - CollectionUtils.isEmpty(speciesList)); - } - - public List<DataType> getExtractTypeList() { - return extractTypeList; - } - - public void setExtractTypeList(List<DataType> extractTypeSet) { - Preconditions.checkArgument(CollectionUtils.isNotEmpty(extractTypeSet)); - this.extractTypeList = extractTypeSet; - } - - public List<String> getZoneList() { - return zoneList; - } - - public void setZoneList(List<String> zoneList) { - Preconditions.checkArgument(CollectionUtils.isNotEmpty(zoneList)); - this.zoneList = zoneList; - } - - public List<String> getPopulationIndicatorList() { - return populationIndicatorList; - } - - public void setPopulationIndicatorList(List<String> populationIndicatorList) { - Preconditions.checkArgument(CollectionUtils.isNotEmpty(populationIndicatorList)); - this.populationIndicatorList = populationIndicatorList; - } - - public List<String> getCommunityIndicatorList() { - return communityIndicatorList; - } - - public void setCommunityIndicatorList(List<String> communityIndicatorList) { - Preconditions.checkArgument(CollectionUtils.isNotEmpty(communityIndicatorList)); - this.communityIndicatorList = communityIndicatorList; - } - - public List<String> getSpeciesList() { - return speciesList; - } - - public void setSpeciesList(List<String> speciesList) { - Preconditions.checkArgument(CollectionUtils.isNotEmpty(speciesList)); - this.speciesList = speciesList; - } -} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetAllResultsRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetAllResultsRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetAllResultsRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,90 @@ +package fr.ifremer.coser.result.request; + +/* + * #%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 fr.ifremer.coser.result.CoserRequest; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.repository.ResultRepositoryType; + +import java.util.Locale; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetAllResultsRequest implements CoserRequest { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + /** + * Id of matching result repository type. + * + * @see ResultRepositoryType#getId() + */ + protected String resultRepositoryType; + + /** + * Type of matching result. + */ + protected ResultType resultType; + + @Override + public boolean isFilled() { + return !(locale == null || resultRepositoryType == null || resultType == null); + } + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + public String getResultRepositoryType() { + return resultRepositoryType; + } + + public void setResultRepositoryType(String resultRepositoryType) { + Preconditions.checkNotNull(resultRepositoryType); + this.resultRepositoryType = resultRepositoryType; + } + + public ResultType getResultType() { + return resultType; + } + + public void setResultType(ResultType resultType) { + Preconditions.checkNotNull(resultType); + this.resultType = resultType; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetAllResultsRequest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetCommunityIndicatorResultRequest.java (from rev 1134, trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/CommunityIndicatorRequest.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetCommunityIndicatorResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetCommunityIndicatorResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,56 @@ +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; + +/** + * Request to obtain community indicator results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetCommunityIndicatorResultRequest extends AbstractGetIndicatorResultRequest { + + private static final long serialVersionUID = 1L; + + protected String species; + + @Override + public String getSpecies() { + return species; + } + + @Override + public void setSpecies(String species) { + Preconditions.checkNotNull(facade); + this.species = species; + } + + @Override + public boolean isFilled() { + return super.isFilled() && species != null; + } +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForCommunityIndicatorResultRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForCommunityIndicatorResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForCommunityIndicatorResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,88 @@ +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 java.util.Locale; + +/** + * Request to obtain community indicator results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetIndicatorsForCommunityIndicatorResultRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + protected String zone; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || + facade == null || + zone == null); + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } + + @Override + public String getZone() { + return zone; + } + + @Override + public void setZone(String zone) { + Preconditions.checkNotNull(zone); + this.zone = zone; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForCommunityIndicatorResultRequest.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/GetIndicatorsForExtractRawDataAndResultsRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForExtractRawDataAndResultsRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForExtractRawDataAndResultsRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,110 @@ +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; +import java.util.Locale; + +/** + * Request to extract data. + * <p/> + * Created on 3/9/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetIndicatorsForExtractRawDataAndResultsRequest implements CoserRequest { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected List<String> zoneList; + + protected List<String> populationIndicatorList; + + protected List<String> communityIndicatorList; + + protected List<DataType> extractTypeList; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || + CollectionUtils.isEmpty(extractTypeList) || + CollectionUtils.isEmpty(zoneList) || + CollectionUtils.isEmpty(populationIndicatorList) || + CollectionUtils.isEmpty(communityIndicatorList)); + } + + public List<DataType> getExtractTypeList() { + return extractTypeList; + } + + public void setExtractTypeList(List<DataType> extractTypeSet) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(extractTypeSet)); + this.extractTypeList = extractTypeSet; + } + + public List<String> getZoneList() { + return zoneList; + } + + public void setZoneList(List<String> zoneList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(zoneList)); + this.zoneList = zoneList; + } + + public List<String> getPopulationIndicatorList() { + return populationIndicatorList; + } + + public void setPopulationIndicatorList(List<String> populationIndicatorList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(populationIndicatorList)); + this.populationIndicatorList = populationIndicatorList; + } + + public List<String> getCommunityIndicatorList() { + return communityIndicatorList; + } + + public void setCommunityIndicatorList(List<String> communityIndicatorList) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(communityIndicatorList)); + this.communityIndicatorList = communityIndicatorList; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForExtractRawDataAndResultsRequest.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/GetIndicatorsForPopulationIndicatorResultRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForPopulationIndicatorResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForPopulationIndicatorResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,100 @@ +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 java.util.Locale; + +/** + * Request to obtain community indicator results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetIndicatorsForPopulationIndicatorResultRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware , CoserRequestSpeciesAware{ + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + protected String zone; + protected String species; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || + facade == null || + zone == null || + species==null); + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } + + @Override + public String getZone() { + return zone; + } + + @Override + public void setZone(String zone) { + Preconditions.checkNotNull(zone); + this.zone = zone; + } + + @Override + public String getSpecies() { + return species; + } + + @Override + public void setSpecies(String species) { + Preconditions.checkNotNull(species); + this.species = species; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetIndicatorsForPopulationIndicatorResultRequest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetMapResultRequest.java (from rev 1134, trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/MapRequest.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetMapResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetMapResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,105 @@ +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 java.util.Locale; + +/** + * Request to obtain map results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetMapResultRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware, CoserRequestSpeciesAware { + + private static final long serialVersionUID = 1L; + + /** + * Used to have map with no species, we prefer to keep a not null value + * to still make request consistent. + */ + public static final String NULL_SPECIES = "Repartition-stations"; + + protected Locale locale; + + protected String facade; + + protected String zone; + + protected String species; + + @Override + public boolean isFilled() { + return !(locale == null || facade == null || zone == null && species == null); + } + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } + + @Override + public String getZone() { + return zone; + } + + @Override + public void setZone(String zone) { + Preconditions.checkNotNull(zone); + this.zone = zone; + } + + @Override + public String getSpecies() { + return species; + } + + @Override + public void setSpecies(String species) { + Preconditions.checkNotNull(species); + this.species = species; + } + +} Copied: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetPopulationIndicatorResultRequest.java (from rev 1134, trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/PopulationIndicatorRequest.java) =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetPopulationIndicatorResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetPopulationIndicatorResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,56 @@ +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; + +/** + * Request to obtain population indicator results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetPopulationIndicatorResultRequest extends AbstractGetIndicatorResultRequest { + + private static final long serialVersionUID = 1L; + + protected String species; + + @Override + public String getSpecies() { + return species; + } + + @Override + public void setSpecies(String species) { + Preconditions.checkNotNull(species); + this.species = species; + } + + @Override + public boolean isFilled() { + return super.isFilled() && species != null; + } +} Added: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesForMapResultRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesForMapResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesForMapResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,86 @@ +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 java.util.Locale; + +/** + * Request to obtain available species for map results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesForMapResultRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + protected String zone; + + @Override + public boolean isFilled() { + return !(locale == null || facade == null || zone == null); + } + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } + + @Override + public String getZone() { + return zone; + } + + @Override + public void setZone(String zone) { + Preconditions.checkNotNull(zone); + this.zone = zone; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesForMapResultRequest.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/GetSpeciesForPopulationIndicatorResultRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesForPopulationIndicatorResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesForPopulationIndicatorResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,88 @@ +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 java.util.Locale; + +/** + * Request to obtain community indicator results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesForPopulationIndicatorResultRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + protected String zone; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || + facade == null || + zone == null); + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } + + @Override + public String getZone() { + return zone; + } + + @Override + public void setZone(String zone) { + Preconditions.checkNotNull(zone); + this.zone = zone; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesForPopulationIndicatorResultRequest.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/GetSpeciesListForCommunityIndicatorResultRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesListForCommunityIndicatorResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesListForCommunityIndicatorResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,102 @@ +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 java.util.Locale; + +/** + * Request to obtain community indicator results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesListForCommunityIndicatorResultRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware, CoserRequestIndicatorAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + protected String zone; + + protected String indicator; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || + facade == null || + zone == null || + indicator == null); + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } + + @Override + public String getZone() { + return zone; + } + + @Override + public void setZone(String zone) { + Preconditions.checkNotNull(zone); + this.zone = zone; + } + + @Override + public String getIndicator() { + return indicator; + } + + @Override + public void setIndicator(String indicator) { + Preconditions.checkNotNull(indicator); + this.indicator = indicator; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesListForCommunityIndicatorResultRequest.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/GetSpeciesListForExtractRawDataAndResultsRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesListForExtractRawDataAndResultsRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetSpeciesListForExtractRawDataAndResultsRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,86 @@ +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; +import java.util.Locale; + +/** + * Request to extract data. + * <p/> + * Created on 3/9/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetSpeciesListForExtractRawDataAndResultsRequest implements CoserRequest { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected List<String> zoneList; + + protected List<DataType> extractTypeList; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || + CollectionUtils.isEmpty(extractTypeList) || + CollectionUtils.isEmpty(zoneList)); + } + + public List<DataType> getExtractTypeList() { + return extractTypeList; + } + + public void setExtractTypeList(List<DataType> extractTypeSet) { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(extractTypeSet)); + this.extractTypeList = extractTypeSet; + } + + public List<String> getZoneList() { + return zoneList; + } + + 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/GetSpeciesListForExtractRawDataAndResultsRequest.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/GetZonesForCommunityIndicatorResultRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForCommunityIndicatorResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForCommunityIndicatorResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,72 @@ +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 java.util.Locale; + +/** + * Request to obtain available zones for community indicator results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForCommunityIndicatorResultRequest implements CoserRequest, CoserRequestFacadeAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + @Override + public boolean isFilled() { + return !(locale == null || facade == null); + } + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForCommunityIndicatorResultRequest.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/GetZonesForExtractRawDataAndResultsRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForExtractRawDataAndResultsRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForExtractRawDataAndResultsRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,73 @@ +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.util.List; +import java.util.Locale; + +/** + * Request to extract data. + * <p/> + * Created on 3/9/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForExtractRawDataAndResultsRequest implements CoserRequest { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected List<String> zoneList; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || CollectionUtils.isEmpty(zoneList)); + } + + public List<String> getZoneList() { + return zoneList; + } + + 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/GetZonesForExtractRawDataAndResultsRequest.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/GetZonesForExtractRawDataRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForExtractRawDataRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForExtractRawDataRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,72 @@ +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 java.util.Locale; + +/** + * Request to obtain raw data results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForExtractRawDataRequest implements CoserRequest, CoserRequestFacadeAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public boolean isFilled() { + return !(locale == null || facade == null); + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForExtractRawDataRequest.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/GetZonesForMapResultRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForMapResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForMapResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,73 @@ +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 java.util.Locale; + +/** + * Request to obtain available zones for map results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForMapResultRequest implements CoserRequest, CoserRequestFacadeAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + @Override + public boolean isFilled() { + return !(locale == null || facade == null); + } + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForMapResultRequest.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/GetZonesForPopulationIndicatorResultRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForPopulationIndicatorResultRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForPopulationIndicatorResultRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,72 @@ +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 java.util.Locale; + +/** + * Request to obtain available zones for community indicator results. + * <p/> + * Created on 3/4/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class GetZonesForPopulationIndicatorResultRequest implements CoserRequest, CoserRequestFacadeAware { + + private static final long serialVersionUID = 1L; + + protected Locale locale; + + protected String facade; + + @Override + public boolean isFilled() { + return !(locale == null || facade == null); + } + + @Override + public Locale getLocale() { + return locale; + } + + @Override + public void setLocale(Locale locale) { + Preconditions.checkNotNull(locale); + this.locale = locale; + } + + @Override + public String getFacade() { + return facade; + } + + @Override + public void setFacade(String facade) { + Preconditions.checkNotNull(facade); + this.facade = facade; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/GetZonesForPopulationIndicatorResultRequest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/IndicatorRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/IndicatorRequest.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/IndicatorRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,116 +0,0 @@ -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 java.util.Locale; - -/** - * Request to obtain indicator results. - * <p/> - * Created on 3/4/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public abstract class IndicatorRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware, CoserRequestSpeciesAware { - - private static final long serialVersionUID = 1L; - - /** - * Type of result. - */ - public enum ResultType { - DATA, - GRAPH - } - - protected Locale locale; - - protected String facade; - - protected String zone; - - protected String indicator; - - protected ResultType resultType; - - @Override - public Locale getLocale() { - return locale; - } - - @Override - public void setLocale(Locale locale) { - Preconditions.checkNotNull(locale); - this.locale = locale; - } - - @Override - public boolean isFilled() { - return !(locale == null || facade == null || zone == null || resultType == null || indicator == null); - } - - @Override - public String getFacade() { - return facade; - } - - @Override - public void setFacade(String facade) { - Preconditions.checkNotNull(facade); - this.facade = facade; - } - - @Override - public String getZone() { - return zone; - } - - @Override - public void setZone(String zone) { - Preconditions.checkNotNull(zone); - this.zone = zone; - } - - public ResultType getResultType() { - return resultType; - } - - public void setResultType(ResultType resultType) { - Preconditions.checkNotNull(resultType); - this.resultType = resultType; - } - - public String getIndicator() { - return indicator; - } - - public void setIndicator(String indicator) { - Preconditions.checkNotNull(indicator); - this.indicator = indicator; - } - -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/MapRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/MapRequest.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/MapRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,105 +0,0 @@ -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 java.util.Locale; - -/** - * Request to obtain map results. - * <p/> - * Created on 3/4/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class MapRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware, CoserRequestSpeciesAware { - - private static final long serialVersionUID = 1L; - - /** - * Used to have map with no species, we prefer to keep a not null value - * to still make request consistent. - */ - public static final String NULL_SPECIES = "Repartition-stations"; - - protected Locale locale; - - protected String facade; - - protected String zone; - - protected String species; - - @Override - public boolean isFilled() { - return !(locale == null || facade == null || zone == null && species == null); - } - - @Override - public Locale getLocale() { - return locale; - } - - @Override - public void setLocale(Locale locale) { - Preconditions.checkNotNull(locale); - this.locale = locale; - } - - @Override - public String getFacade() { - return facade; - } - - @Override - public void setFacade(String facade) { - Preconditions.checkNotNull(facade); - this.facade = facade; - } - - @Override - public String getZone() { - return zone; - } - - @Override - public void setZone(String zone) { - Preconditions.checkNotNull(zone); - this.zone = zone; - } - - @Override - public String getSpecies() { - return species; - } - - @Override - public void setSpecies(String species) { - Preconditions.checkNotNull(species); - this.species = species; - } - -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/PopulationIndicatorRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/PopulationIndicatorRequest.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/PopulationIndicatorRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,56 +0,0 @@ -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; - -/** - * Request to obtain population indicator results. - * <p/> - * Created on 3/4/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class PopulationIndicatorRequest extends IndicatorRequest { - - private static final long serialVersionUID = 1L; - - protected String species; - - @Override - public String getSpecies() { - return species; - } - - @Override - public void setSpecies(String species) { - Preconditions.checkNotNull(facade); - this.species = species; - } - - @Override - public boolean isFilled() { - return super.isFilled() && species != null; - } -} Deleted: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/RawDataRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/RawDataRequest.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/RawDataRequest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -1,85 +0,0 @@ -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 java.util.Locale; - -/** - * Request to obtain raw data results. - * <p/> - * Created on 3/4/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 1.5 - */ -public class RawDataRequest implements CoserRequest, CoserRequestFacadeAware, CoserRequestZoneAware { - - private static final long serialVersionUID = 1L; - - protected Locale locale; - - protected String facade; - - protected String zone; - - @Override - public Locale getLocale() { - return locale; - } - - @Override - public void setLocale(Locale locale) { - Preconditions.checkNotNull(locale); - this.locale = locale; - } - - @Override - public boolean isFilled() { - return !(locale == null || facade == null || zone == null); - } - - @Override - public String getFacade() { - return facade; - } - - @Override - public void setFacade(String facade) { - Preconditions.checkNotNull(facade); - this.facade = facade; - } - - @Override - public String getZone() { - return zone; - } - - @Override - public void setZone(String zone) { - Preconditions.checkNotNull(zone); - this.zone = zone; - } -} Added: trunk/coser-business/src/main/resources/META-INF/services/fr.ifremer.coser.result.repository.ResultRepositoryType =================================================================== --- trunk/coser-business/src/main/resources/META-INF/services/fr.ifremer.coser.result.repository.ResultRepositoryType (rev 0) +++ trunk/coser-business/src/main/resources/META-INF/services/fr.ifremer.coser.result.repository.ResultRepositoryType 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,2 @@ +fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepositoryType +fr.ifremer.coser.result.repository.legacy.LegacyResultRepositoryType \ No newline at end of file Modified: trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/resources/i18n/coser-business_en_GB.properties 2014-03-12 17:35:43 UTC (rev 1145) @@ -143,6 +143,8 @@ coser.business.publication.selectionchoices=Selection choices coser.business.publication.selectionlogexporttitle=Selection report for %s (project %s) coser.business.publication.stratafilename=Strata file name +coser.business.result.repository.type.echobase=EchoBase results +coser.business.result.repository.type.legacy=RSufi results coser.business.result.rsufiResultAlreadyExists=Result %s already exists \! coser.business.resultupload.duplicatedresult=Result %s/%s/%s duplicate another result for zone %s \! coser.business.selection.notValidatedControl=Not validated control \! Modified: trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties =================================================================== --- trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/main/resources/i18n/coser-business_fr_FR.properties 2014-03-12 17:35:43 UTC (rev 1145) @@ -143,6 +143,8 @@ coser.business.publication.selectionchoices=Choix de sélections coser.business.publication.selectionlogexporttitle=Rapport de la sélection %s (projet %s) coser.business.publication.stratafilename=Nom du fichier strates +coser.business.result.repository.type.echobase=Résultats EchoBase +coser.business.result.repository.type.legacy=Résultats RSufi coser.business.result.rsufiResultAlreadyExists=Le résultat %s existe déjà \! coser.business.resultupload.duplicatedresult=Le résultat %s/%s/%s duplique un autre résultat pour la zone %s \! coser.business.selection.notValidatedControl=Contrôle non validé \! Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryTest.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryTest.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,9 +22,10 @@ * #L% */ -import fr.ifremer.coser.result.request.CommunityIndicatorRequest; -import fr.ifremer.coser.result.request.MapRequest; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; +import fr.ifremer.coser.result.repository.ResultRepositoryCommandEngine; +import fr.ifremer.coser.result.request.GetZonesForCommunityIndicatorResultRequest; +import fr.ifremer.coser.result.request.GetZonesForMapResultRequest; +import fr.ifremer.coser.result.request.GetZonesForPopulationIndicatorResultRequest; import fr.ifremer.coser.services.CoserTestAbstract; import org.junit.Assert; import org.junit.Assume; @@ -44,9 +45,9 @@ */ public class EchoBaseResultRepositoryTest extends CoserTestAbstract { - protected EchoBaseResultRepository repository1; + protected ResultRepositoryCommandEngine repository1; - protected EchoBaseResultRepository repository2; + protected ResultRepositoryCommandEngine repository2; @Override public void initProjectDatabase() throws IOException { @@ -60,9 +61,9 @@ for (EchoBaseResultRepository repository : repositories) { String projectName = repository.project.getName(); if ("project1".equals(projectName)) { - repository1 = repository; + repository1 = repositoryProvider.newEngine(repository); } else if ("project2".equals(projectName)) { - repository2 = repository; + repository2 = repositoryProvider.newEngine(repository); } } Assume.assumeTrue("Could not find repository named *project1*", repository1 != null); @@ -74,13 +75,14 @@ // Map request - MapRequest mapRequest = new MapRequest(); + GetZonesForMapResultRequest mapRequest = new GetZonesForMapResultRequest(); mapRequest.setLocale(Locale.FRANCE); mapRequest.setFacade("atlantique"); Map<String, String> availableZones; - availableZones = repository1.getAvailableZones(mapRequest); + Assert.assertTrue(repository1.acceptRequest(mapRequest)); + availableZones = (Map<String, String>) repository1.executeRequest(mapRequest).getResult(); Assert.assertNotNull(availableZones); Assert.assertEquals(1, availableZones.size()); Assert.assertTrue(availableZones.containsKey("gdgciem8")); @@ -88,21 +90,24 @@ // pas de zones pour la facade mapRequest.setFacade("mediteranee"); - availableZones = repository1.getAvailableZones(mapRequest); - Assert.assertNull(availableZones); + Assert.assertFalse(repository1.acceptRequest(mapRequest)); +// availableZones = (Map<String, String>) repository1.executeRequest(mapRequest).getResult(); +// Assert.assertNull(availableZones); // facade inconnue mapRequest.setFacade("mediteranee2"); - availableZones = repository1.getAvailableZones(mapRequest); - Assert.assertNull(availableZones); + Assert.assertFalse(repository1.acceptRequest(mapRequest)); +// availableZones = (Map<String, String>) repository1.executeRequest(mapRequest).getResult(); +// Assert.assertNull(availableZones); // Population request - PopulationIndicatorRequest popRequest = new PopulationIndicatorRequest(); + GetZonesForPopulationIndicatorResultRequest popRequest = new GetZonesForPopulationIndicatorResultRequest(); popRequest.setLocale(Locale.FRANCE); popRequest.setFacade("atlantique"); - availableZones = repository1.getAvailableZones(popRequest); + Assert.assertTrue(repository1.acceptRequest(popRequest)); + availableZones = (Map<String, String>) repository1.executeRequest(popRequest).getResult(); Assert.assertNotNull(availableZones); Assert.assertEquals(1, availableZones.size()); Assert.assertTrue(availableZones.containsKey("gdgciem8")); @@ -110,21 +115,24 @@ // pas de zones pour la facade popRequest.setFacade("mediteranee"); - availableZones = repository1.getAvailableZones(popRequest); - Assert.assertNull(availableZones); + Assert.assertFalse(repository1.acceptRequest(popRequest)); +// availableZones = (Map<String, String>) repository1.executeRequest(popRequest).getResult(); +// Assert.assertNull(availableZones); // facade inconnue popRequest.setFacade("mediteranee2"); - availableZones = repository1.getAvailableZones(popRequest); - Assert.assertNull(availableZones); + Assert.assertFalse(repository1.acceptRequest(popRequest)); +// availableZones = (Map<String, String>) repository1.executeRequest(popRequest).getResult(); +// Assert.assertNull(availableZones); // Community request - CommunityIndicatorRequest comRequest = new CommunityIndicatorRequest(); + GetZonesForCommunityIndicatorResultRequest comRequest = new GetZonesForCommunityIndicatorResultRequest(); comRequest.setLocale(Locale.FRANCE); comRequest.setFacade("atlantique"); - availableZones = repository1.getAvailableZones(comRequest); + Assert.assertTrue(repository1.acceptRequest(comRequest)); + availableZones = (Map<String, String>) repository1.executeRequest(comRequest).getResult(); Assert.assertNotNull(availableZones); Assert.assertEquals(1, availableZones.size()); Assert.assertTrue(availableZones.containsKey("gdgciem8")); @@ -132,13 +140,15 @@ // pas de zones pour la facade comRequest.setFacade("mediteranee"); - availableZones = repository1.getAvailableZones(comRequest); - Assert.assertNull(availableZones); + Assert.assertFalse(repository1.acceptRequest(comRequest)); +// availableZones = (Map<String, String>) repository1.executeRequest(comRequest).getResult(); +// Assert.assertNull(availableZones); // facade inconnue comRequest.setFacade("mediteranee2"); - availableZones = repository1.getAvailableZones(comRequest); - Assert.assertNull(availableZones); + Assert.assertFalse(repository1.acceptRequest(comRequest)); +// availableZones = (Map<String, String>) repository1.executeRequest(comRequest).getResult(); +// Assert.assertNull(availableZones); } } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationContext.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationContext.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationContext.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -24,6 +24,8 @@ import com.google.common.base.Preconditions; import fr.ifremer.coser.CoserServiceContext; import fr.ifremer.coser.DefaultCoserServiceContext; +import fr.ifremer.coser.bean.IndicatorMap; +import fr.ifremer.coser.bean.ZoneMap; import fr.ifremer.coser.result.CoserResultEngine; import fr.ifremer.coser.services.WebService; import org.nuiton.config.ArgumentsParserException; @@ -59,7 +61,7 @@ /** * Business layer context. */ - protected CoserServiceContext businessContext; + protected CoserServiceContext serviceContext; /** * Web config. @@ -73,7 +75,10 @@ public CoserApplicationContext() { - I18n.init(new DefaultI18nInitializer("coser-i18n"), null); + DefaultI18nInitializer i18nInitializer = new DefaultI18nInitializer("coser-i18n"); + // To see on screen none translated sentences + i18nInitializer.setMissingKeyReturnNull(true); + I18n.init(i18nInitializer, null); config = new CoserWebConfig(); @@ -83,10 +88,10 @@ throw new CoserWebException("Can't read configuration", ex); } - businessContext = new DefaultCoserServiceContext(config); + serviceContext = new DefaultCoserServiceContext(config); webService = new WebService(config); - resultService = new CoserResultEngine(businessContext); + resultService = new CoserResultEngine(serviceContext); } public WebService getWebService() { @@ -100,4 +105,13 @@ public CoserWebConfig getConfig() { return config; } + + public IndicatorMap getIndicatorsMap() { + return serviceContext.getIndicatorsMap(); + } + + public ZoneMap getZonesMap() { + return serviceContext.getZonesMap(); + } + } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceHelper.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceHelper.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceHelper.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,16 +22,19 @@ */ import com.google.common.base.Preconditions; +import com.google.common.collect.Maps; import fr.ifremer.coser.CoserBusinessException; import fr.ifremer.coser.result.CoserRequest; import fr.ifremer.coser.result.CoserResult; import fr.ifremer.coser.result.CoserResultEngine; import fr.ifremer.coser.result.FileResult; +import fr.ifremer.coser.result.MapResult; +import fr.ifremer.coser.result.repository.ResultRepositoryType; +import fr.ifremer.coser.result.request.AbstractGetIndicatorResultRequest; import fr.ifremer.coser.result.request.CoserRequestSpeciesAware; import fr.ifremer.coser.result.request.CoserRequestZoneAware; -import fr.ifremer.coser.result.request.IndicatorRequest; +import fr.ifremer.coser.result.request.DeleteResultsRequest; import fr.ifremer.coser.services.WebService; -import fr.ifremer.coser.util.DataType; import fr.ifremer.coser.web.actions.common.CoserAction; import java.io.File; @@ -60,25 +63,27 @@ protected final CoserWebConfig config; + protected final CoserApplicationContext applicationContext; + public ServiceHelper(CoserAction action) { Preconditions.checkNotNull(action); - CoserApplicationContext applicationContext = CoserApplicationContext.get(); + this.applicationContext = CoserApplicationContext.get(); this.action = action; this.webService = applicationContext.getWebService(); this.resultService = applicationContext.getResultService(); this.config = applicationContext.getConfig(); } + public Map<String, ResultRepositoryType> getRepositoryTypes() { + return resultService.getRepositoryTypes(); + } + // --------------------------------------------------------------------- // // --- Facade methods -------------------------------------------------- // // --------------------------------------------------------------------- // public Map<String, String> getFacades() { - try { - return webService.getFacades(); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not obtain facades", e); - } + return applicationContext.getZonesMap().getFacades(); } public String getFacadeDisplayName(String facade) { @@ -91,47 +96,32 @@ // --------------------------------------------------------------------- // public Map<String, List<String>> getZoneByFacade() { - try { - return webService.getZoneByFacade(); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not obtain zone by facade", e); - } + return applicationContext.getZonesMap().getZoneByFacade(); } public Map<String, String> getZonePictures() { - try { - return webService.getZonePictures(); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not obtain zone pictures", e); - } + return applicationContext.getZonesMap().getZonePictures(); } public Map<String, String> getZoneMetaInfo(Locale locale) { - try { - return webService.getZoneMetaInfo(locale); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not obtain zone meta infos", e); - } + return applicationContext.getZonesMap().getZoneMetaInfo(locale); } + //FIXME Remove this public Map<String, String> getAvailableZones(CoserRequest request) { - return resultService.getAvailableZones(request); + return getMultipleResultAsMap(request); } - public Map<String, String> getZoneForFacade() { - try { - return webService.getZoneForFacade(null, false, false); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not obtain zone for facades", e); - } - } +// public Map<String, String> getZoneForFacade() { +// try { +// return webService.getZoneForFacade(null, false, false); +// } catch (CoserBusinessException e) { +// throw new CoserWebException("Could not obtain zone for facades", e); +// } +// } public String getZoneFullName(String zoneId) { - try { - return webService.getZoneFullName(zoneId); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not obtain zone full name", e); - } + return applicationContext.getZonesMap().getZoneFullName(zoneId); } public String getZoneDisplayName(CoserRequestZoneAware request) { @@ -144,6 +134,7 @@ // --- Species methods ------------------------------------------------- // // --------------------------------------------------------------------- // + //FIXME Remove this public Map<String, String> getAvailableSpecies(CoserRequest request) { return resultService.getAvailableSpecies(request); } @@ -158,27 +149,28 @@ // --- Indicator methods ----------------------------------------------- // // --------------------------------------------------------------------- // + //FIXME Remove this public Map<String, String> getAvailableIndicators(CoserRequest request) { return resultService.getAvailableIndicators(request); } - public Map<String, String> getIndicators(List<String> selectZones, DataType dataType) { - try { - return webService.getIndicators(selectZones, dataType, action.getLocale()); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not obtain indicators", e); - } - } +// public Map<String, String> getIndicators(List<String> selectZones, DataType dataType) { +// try { +// return webService.getIndicators(selectZones, dataType, action.getLocale()); +// } catch (CoserBusinessException e) { +// throw new CoserWebException("Could not obtain indicators", e); +// } +// } - public Map<String, String> getSpecies(List<String> selectZones) { - try { - return webService.getSpecies(selectZones, false); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not obtain species", e); - } - } +// public Map<String, String> getSpecies(List<String> selectZones) { +// try { +// return webService.getSpecies(selectZones, false); +// } catch (CoserBusinessException e) { +// throw new CoserWebException("Could not obtain species", e); +// } +// } - public String getIndicatorDisplayName(IndicatorRequest request) { + public String getIndicatorDisplayName(AbstractGetIndicatorResultRequest request) { Map<String, String> availableIndicators = getAvailableIndicators(request); String displayName = availableIndicators.get(request.getIndicator()); return displayName; @@ -188,25 +180,25 @@ // --- Result methods -------------------------------------------------- // // --------------------------------------------------------------------- // - public Map<String, String> getIndicatorsResultsPerZone() { - try { - return webService.getIndicatorsResultsPerZone(); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not get indicators results per zone", e); - } - } +// public Map<String, String> getIndicatorsResultsPerZone() { +// try { +// return webService.getIndicatorsResultsPerZone(); +// } catch (CoserBusinessException e) { +// throw new CoserWebException("Could not get indicators results per zone", e); +// } +// } - public Map<String, String> getMapsResultsPerZone() { - try { - return webService.getMapsResultsPerZone(); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not get map results per zone", e); - } - } +// public Map<String, String> getMapsResultsPerZone() { +// try { +// return webService.getMapsResultsPerZone(); +// } catch (CoserBusinessException e) { +// throw new CoserWebException("Could not get map results per zone", e); +// } +// } public FileResult getFileResult(CoserRequest request) { - CoserResult result = resultService.getResult(request); + CoserResult result = resultService.getUniqueResult(request); if (!(result instanceof FileResult)) { throw new CoserWebException( @@ -216,22 +208,59 @@ return fileResult; } - public void deleteIndicatorsResult(List<String> indicatorsZonesId) { - try { - webService.deleteIndicatorsResult(indicatorsZonesId); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not delete indicator results", e); + public MapResult getMapResult(CoserRequest request) { + + CoserResult result = resultService.getUniqueResult(request); + + if (!(result instanceof MapResult)) { + throw new CoserWebException( + "Result should a MapResult, but was: " + result); } + MapResult fileResult = (MapResult) result; + return fileResult; } - public void deleteMapsResult(List<String> mapsZonesId) { - try { - webService.deleteMapsResult(mapsZonesId); - } catch (CoserBusinessException e) { - throw new CoserWebException("Could not delete map results", e); + public Map<String, String> getMultipleResultAsMap(CoserRequest request) { + + List<CoserResult> result = resultService.getMultipleResult(request); + + Map<String, String> resultAsMap = Maps.newHashMap(); + for (CoserResult coserResult : result) { + if (!(coserResult instanceof MapResult)) { + throw new CoserWebException( + "Result should a MapResult, but was: " + result); + } + Map<String, String> map = ((MapResult) coserResult).getResult(); + resultAsMap.putAll(map); } + return resultAsMap; } + public void deleteResults(DeleteResultsRequest request) { + + // do delete results (don't care about result) + resultService.getMultipleResult(request); + + // reload projects + resultService.resetRepositories(); + } + +// public void deleteIndicatorsResult(List<String> indicatorsZonesId) { +// try { +// webService.deleteIndicatorsResult(indicatorsZonesId); +// } catch (CoserBusinessException e) { +// throw new CoserWebException("Could not delete indicator results", e); +// } +// } +// +// public void deleteMapsResult(List<String> mapsZonesId) { +// try { +// webService.deleteMapsResult(mapsZonesId); +// } catch (CoserBusinessException e) { +// throw new CoserWebException("Could not delete map results", e); +// } +// } + public void registerNewUploadedResults(String login, File resultFile) { try { webService.registerNewUploadedResults(login, resultFile); @@ -247,4 +276,8 @@ public CoserWebConfig getConfig() { return config; } + + public void reloadProjects() { + resultService.resetRepositories(); + } } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/DeleteProjectsAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/DeleteProjectsAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/DeleteProjectsAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,8 +21,9 @@ package fr.ifremer.coser.web.actions.admin; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.request.DeleteResultsRequest; import fr.ifremer.coser.web.actions.common.CoserAction; -import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.convention.annotation.InterceptorRef; @@ -55,44 +56,73 @@ private static final Log log = LogFactory.getLog(DeleteProjectsAction.class); /** - * Contient les identifiants des zones dont on souhaites supprimer le - * resultat conrespondant dans le stockage indicateur. + * Type of result repository. */ - protected List<String> indicatorsZonesId; + protected String repositoryType; /** - * Contient les identifiants des zones dont on souhaites supprimer le - * resultat conrespondant dans le stockage cartes. + * Type of result to delete. */ - protected List<String> mapsZonesId; + protected ResultType resultType; - public void setIndicatorsZonesId(List<String> indicatorsZonesId) { - this.indicatorsZonesId = indicatorsZonesId; + /** + * List of result id to delete. + */ + protected List<String> zonesId; + + public void setRepositoryType(String repositoryType) { + this.repositoryType = repositoryType; } - public void setMapsZonesId(List<String> mapsZonesId) { - this.mapsZonesId = mapsZonesId; + public void setResultType(ResultType resultType) { + this.resultType = resultType; } + public void setZonesId(List<String> zonesId) { + this.zonesId = zonesId; + } + + @Override public String execute() { - if (log.isDebugEnabled()) { - log.debug("Delete indicators zone : " + indicatorsZonesId); + if (log.isInfoEnabled()) { + log.info(String.format("Delete zone (type %s) (repository type %s) : %s", + resultType, + repositoryType, + zonesId)); } - if (CollectionUtils.isNotEmpty(indicatorsZonesId)) { - getService().deleteIndicatorsResult(indicatorsZonesId); - } - if (log.isDebugEnabled()) { - log.debug("Delete maps zone : " + mapsZonesId); - } - if (CollectionUtils.isNotEmpty(mapsZonesId)) { - getService().deleteMapsResult(mapsZonesId); - } + DeleteResultsRequest request = requestBuilder(). + addResultRepositoryType(repositoryType). + addResultType(resultType). + addZoneList(zonesId). + toDeleteResultsRequest(); + getService().deleteResults(request); + return SUCCESS; } +// /** +// * Contient les identifiants des zones dont on souhaite supprimer le +// * resultat conrespondant dans le stockage indicateur. +// */ +// protected List<String> indicatorsZonesId; +// +// /** +// * Contient les identifiants des zones dont on souhaites supprimer le +// * resultat conrespondant dans le stockage cartes. +// */ +// protected List<String> mapsZonesId; +// +// public void setIndicatorsZonesId(List<String> indicatorsZonesId) { +// this.indicatorsZonesId = indicatorsZonesId; +// } +// +// public void setMapsZonesId(List<String> mapsZonesId) { +// this.mapsZonesId = mapsZonesId; +// } +// // public String execute() { // WebService webService = ServiceFactory.getWebService(); // Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/ListProjectsAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/ListProjectsAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/ListProjectsAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,13 +21,21 @@ package fr.ifremer.coser.web.actions.admin; +import com.google.common.collect.Maps; +import fr.ifremer.coser.result.ResultType; +import fr.ifremer.coser.result.repository.ResultRepositoryType; +import fr.ifremer.coser.result.request.GetAllResultsRequest; +import fr.ifremer.coser.web.CoserWebException; import fr.ifremer.coser.web.actions.common.CoserAction; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.struts2.convention.annotation.InterceptorRef; import org.apache.struts2.convention.annotation.InterceptorRefs; import org.apache.struts2.convention.annotation.ParentPackage; import java.util.List; import java.util.Map; +import java.util.Set; /** * Project list action. @@ -48,12 +56,34 @@ /** serialVersionUID. */ private static final long serialVersionUID = 6024588562104111883L; + // All types of result repository + protected Map<String, ResultRepositoryType> repositoryTypes; + + // Selected result repository type + protected String selectedRepositoryType; + protected Map<String, String> facades; + protected Map<String, List<String>> zonesByFacades; + protected Map<ResultType, Map<String, String>> results; + protected Map<String, String> indicatorsResults; + protected Map<String, String> mapsResults; + public Map<String, ResultRepositoryType> getRepositoryTypes() { + return repositoryTypes; + } + + public String getSelectedRepositoryType() { + return selectedRepositoryType; + } + + public void setSelectedRepositoryType(String selectedRepositoryType) { + this.selectedRepositoryType = selectedRepositoryType; + } + public Map<String, String> getFacades() { return facades; } @@ -62,28 +92,60 @@ return zonesByFacades; } - public Map<String, String> getIndicatorsResults() { - return indicatorsResults; + public Map<String, String> getResults(ResultType resultType) { + return results.get(resultType); } - public Map<String, String> getMapsResults() { - return mapsResults; - } - public String getZoneDisplayName(String zoneId) { return getService().getZoneFullName(zoneId); } + @Override public String execute() { + repositoryTypes = getService().getRepositoryTypes(); + if (MapUtils.isEmpty(repositoryTypes)) { + throw new CoserWebException("No result repository type defined!"); + } + + if (StringUtils.isEmpty(selectedRepositoryType)) { + + // use first value + ResultRepositoryType repositoryType = repositoryTypes.values().iterator().next(); + selectedRepositoryType = repositoryType.getId(); + } + facades = getService().getFacades(); zonesByFacades = getService().getZoneByFacade(); - indicatorsResults = getService().getIndicatorsResultsPerZone(); - mapsResults = getService().getMapsResultsPerZone(); + GetAllResultsRequest request = requestBuilder(). + addResultRepositoryType(getSelectedRepositoryType()). + toGetAllResultsRequest(); + + results = Maps.newEnumMap(ResultType.class); + if (selectedRepositoryType != null) { + ResultRepositoryType repositoryType = repositoryTypes.get(selectedRepositoryType); + Set<ResultType> resultTypes = repositoryType.getResultTypes(); + for (ResultType resultType : resultTypes) { + + // get projects for this type + request.setResultType(resultType); + Map<String, String> resultsForType = getService().getMultipleResultAsMap(request); + results.put(resultType, resultsForType); + } + } + return SUCCESS; } +// public Map<String, String> getIndicatorsResults() { +// return indicatorsResults; +// } +// +// public Map<String, String> getMapsResults() { +// return mapsResults; +// } +// // public String getZoneDisplayName(String zoneId) { // WebService webService = ServiceFactory.getWebService(); // String zoneDisplayName = null; Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/PerformLoginAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/PerformLoginAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/PerformLoginAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,7 +22,6 @@ package fr.ifremer.coser.web.actions.admin; import fr.ifremer.coser.web.CoserWebConfig; -import fr.ifremer.coser.web.ServiceFactory; import fr.ifremer.coser.web.actions.common.CoserAction; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.interceptor.SessionAware; @@ -59,9 +58,6 @@ this.password = password; } - /* - * @see org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map) - */ @Override public void setSession(Map<String, Object> session) { this.session = session; Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/ReloadProjectsAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/ReloadProjectsAction.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/ReloadProjectsAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -0,0 +1,53 @@ +package fr.ifremer.coser.web.actions.admin; + +/* + * #%L + * Coser :: Web + * %% + * 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 Affero 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 Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.coser.web.actions.common.CoserAction; +import org.apache.struts2.convention.annotation.InterceptorRef; +import org.apache.struts2.convention.annotation.InterceptorRefs; +import org.apache.struts2.convention.annotation.ParentPackage; +import org.apache.struts2.convention.annotation.Result; + +/** + * To reload all projects from disk configuration. + * <p/> + * Created on 3/12/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +@ParentPackage("admin") +@InterceptorRefs({ + @InterceptorRef("loginInterceptor"), + @InterceptorRef("defaultStack") + }) +@Result(name = "success", type = "redirect", location = "list-projects") +public class ReloadProjectsAction extends CoserAction { + + private static final long serialVersionUID = 1L; + + @Override + public String execute() throws Exception { + getService().reloadProjects(); + return SUCCESS; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/admin/ReloadProjectsAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,8 @@ package fr.ifremer.coser.web.actions.com; -import fr.ifremer.coser.result.request.IndicatorRequest; +import fr.ifremer.coser.result.request.AbstractGetIndicatorResultRequest; +import fr.ifremer.coser.result.request.GetCommunityIndicatorResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; import java.util.Map; @@ -54,7 +55,7 @@ /** La liste actuellement selectionnée (cas null géré). */ protected String list; - protected IndicatorRequest request; + protected AbstractGetIndicatorResultRequest request; public String getFacade() { return facade; @@ -107,12 +108,12 @@ @Override public String execute() { - request = requestBuilder(). + request = requestBuilder(GetCommunityIndicatorResultRequest.class). addFacade(facade). addZone(zone). addIndicator(indicator). addSpecies(list). - toCommunityIndicatorRequest(); + toRequest(); lists = getService().getAvailableSpecies(request); return SUCCESS; } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDataAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDataAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDataAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,7 +22,7 @@ package fr.ifremer.coser.web.actions.com; import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.request.IndicatorRequest; +import fr.ifremer.coser.result.request.AbstractGetIndicatorResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Result; @@ -92,13 +92,13 @@ // @Action(results = {@Result(type = "stream", params = {"contentType", "image/png", "inputName", "inputStream"})}) @Action(results = {@Result(type = "stream", params = {"contentType", "image/png"})}) public String execute() { - IndicatorRequest request = requestBuilder(). + AbstractGetIndicatorResultRequest request = requestBuilder(). addFacade(facade). addZone(zone). addIndicator(indicator). - addResultType(IndicatorRequest.ResultType.GRAPH). + addIndicatorResultType(AbstractGetIndicatorResultRequest.IndicatorResultType.GRAPH). addSpecies(list). - toCommunityIndicatorRequest(); + toGetCommunityIndicatorResultRequest(); if (list == null) { Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDownloadAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDownloadAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/GraphDownloadAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,7 +22,7 @@ package fr.ifremer.coser.web.actions.com; import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.request.IndicatorRequest; +import fr.ifremer.coser.result.request.AbstractGetIndicatorResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Result; @@ -93,13 +93,13 @@ @Action(results = {@Result(type = "stream", params = {"contentType", "application/zip", "contentDisposition", "attachment; filename=\"${filename}\""})}) public String execute() { - IndicatorRequest request = requestBuilder(). + AbstractGetIndicatorResultRequest request = requestBuilder(). addFacade(facade). addZone(zone). addIndicator(indicator). - addResultType(IndicatorRequest.ResultType.DATA). + addIndicatorResultType(AbstractGetIndicatorResultRequest.IndicatorResultType.DATA). addSpecies(list). - toCommunityIndicatorRequest(); + toGetCommunityIndicatorResultRequest(); if (list == null) { Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/IndicatorAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/IndicatorAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/IndicatorAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.com; -import fr.ifremer.coser.result.request.CommunityIndicatorRequest; +import fr.ifremer.coser.result.request.GetCommunityIndicatorResultRequest; import fr.ifremer.coser.web.actions.common.CommonIndicator; /** @@ -39,10 +39,10 @@ private static final long serialVersionUID = 1663244944108703571L; @Override - protected CommunityIndicatorRequest createRequest() { - return requestBuilder(). + protected GetCommunityIndicatorResultRequest createRequest() { + return requestBuilder(GetCommunityIndicatorResultRequest.class). addFacade(facade). addZone(zone). - toCommunityIndicatorRequest(); + toRequest(); } } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/ZoneAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/ZoneAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/com/ZoneAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -42,6 +42,6 @@ protected CoserRequest createRequest() { return requestBuilder(). addFacade(facade). - toCommunityIndicatorRequest(); + toGetCommunityIndicatorResultRequest(); } } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/common/CommonIndicator.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/common/CommonIndicator.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/common/CommonIndicator.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.common; -import fr.ifremer.coser.result.request.IndicatorRequest; +import fr.ifremer.coser.result.request.AbstractGetIndicatorResultRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -54,9 +54,9 @@ protected Map<String, String> indicators; - protected IndicatorRequest request; + protected AbstractGetIndicatorResultRequest request; - protected abstract IndicatorRequest createRequest(); + protected abstract AbstractGetIndicatorResultRequest createRequest(); public String getFacade() { return facade; Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/common/CoserAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/common/CoserAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/common/CoserAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,6 +21,7 @@ package fr.ifremer.coser.web.actions.common; +import fr.ifremer.coser.result.CoserRequest; import fr.ifremer.coser.result.request.CoserRequestBuilder; import fr.ifremer.coser.web.CoserWebConfig; import fr.ifremer.coser.web.ServiceHelper; @@ -88,17 +89,18 @@ * @return a new request builder. * @since 1.5 */ - protected CoserRequestBuilder requestBuilder() { - return requestBuilder(getLocale()); + protected <R extends CoserRequest> CoserRequestBuilder<R> requestBuilder(Class<R> requestType) { + return requestBuilder(getLocale(), requestType); } /** - * @param locale locale to use (while using execute and wait action we keep the locale in session...) + * @param locale locale to use (while using execute and wait action we keep the locale in session...) + * @param requestType type of request to build * @return a new request builder. * @since 1.5 */ - protected CoserRequestBuilder requestBuilder(Locale locale) { - return new CoserRequestBuilder(locale); + protected <R extends CoserRequest> CoserRequestBuilder<R> requestBuilder(Locale locale, Class<R> requestType) { + return new CoserRequestBuilder<R>(locale, requestType); } /** Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.map; -import fr.ifremer.coser.result.request.MapRequest; +import fr.ifremer.coser.result.request.GetMapResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; /** @@ -44,7 +44,7 @@ protected String species; - protected MapRequest request; + protected GetMapResultRequest request; public void setFacade(String facade) { this.facade = facade; @@ -85,11 +85,11 @@ @Override public String execute() throws Exception { - request = requestBuilder(). + request = requestBuilder(GetMapResultRequest.class). addFacade(facade). addZone(zone). addSpecies(species). - toMapRequest(); + toRequest(); return SUCCESS; } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapDataAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapDataAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/MapDataAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,7 +22,7 @@ package fr.ifremer.coser.web.actions.map; import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.request.MapRequest; +import fr.ifremer.coser.result.request.GetMapResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -84,11 +84,11 @@ @Action(results = {@Result(type = "stream", params = {"contentType", "image/png"})}) public String execute() { // work with null species (get Repartition-stations map) - MapRequest request = requestBuilder(). + GetMapResultRequest request = requestBuilder(). addFacade(facade). addZone(zone). - addSpecies(species == null ? MapRequest.NULL_SPECIES : species). - toMapRequest(); + addSpecies(species == null ? GetMapResultRequest.NULL_SPECIES : species). + toGetMapResultRequest(); if (log.isInfoEnabled()) { log.info("Looking for map of species: " + request.getSpecies()); Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SpeciesAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SpeciesAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/SpeciesAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.map; -import fr.ifremer.coser.result.request.MapRequest; +import fr.ifremer.coser.result.request.GetMapResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -50,7 +50,7 @@ protected Map<String, String> species; - protected MapRequest request; + protected GetMapResultRequest request; public String getFacade() { return facade; @@ -86,7 +86,7 @@ request = requestBuilder(). addFacade(facade). addZone(zone). - toMapRequest(); + toGetMapResultRequest(); if (log.isInfoEnabled()) { log.info("Looking for species for zone " + zone); Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ZoneAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ZoneAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/map/ZoneAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.map; -import fr.ifremer.coser.result.request.MapRequest; +import fr.ifremer.coser.result.request.GetMapResultRequest; import fr.ifremer.coser.web.actions.common.CommonZone; /** @@ -39,8 +39,8 @@ private static final long serialVersionUID = 3385467755357775199L; @Override - protected MapRequest createRequest() { - return requestBuilder().addFacade(facade).toMapRequest(); + protected GetMapResultRequest createRequest() { + return requestBuilder().addFacade(facade).toGetMapResultRequest(); } // @Override Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.pop; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; +import fr.ifremer.coser.result.request.GetPopulationIndicatorResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; /** @@ -48,7 +48,7 @@ protected String indicator; - protected PopulationIndicatorRequest request; + protected GetPopulationIndicatorResultRequest request; public String getFacade() { return facade; @@ -106,7 +106,7 @@ addZone(zone). addSpecies(species). addIndicator(indicator). - toPopulationIndicatorRequest(); + toGetPopulationIndicatorResultRequest(); return SUCCESS; } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDataAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDataAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDataAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,8 +22,8 @@ package fr.ifremer.coser.web.actions.pop; import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.request.IndicatorRequest; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; +import fr.ifremer.coser.result.request.AbstractGetIndicatorResultRequest; +import fr.ifremer.coser.result.request.GetPopulationIndicatorResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Result; @@ -93,13 +93,13 @@ // @Action(results = {@Result(type = "stream", params = {"contentType", "image/png", "inputName", "inputStream"})}) @Action(results = {@Result(type = "stream", params = {"contentType", "image/png"})}) public String execute() { - PopulationIndicatorRequest request = requestBuilder(). + GetPopulationIndicatorResultRequest request = requestBuilder(). addFacade(facade). addZone(zone). addSpecies(species). addIndicator(indicator). - addResultType(IndicatorRequest.ResultType.GRAPH). - toPopulationIndicatorRequest(); + addIndicatorResultType(AbstractGetIndicatorResultRequest.IndicatorResultType.GRAPH). + toGetPopulationIndicatorResultRequest(); result = getService().getFileResult(request); return SUCCESS; } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDownloadAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDownloadAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/GraphDownloadAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -22,8 +22,8 @@ package fr.ifremer.coser.web.actions.pop; import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.request.IndicatorRequest; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; +import fr.ifremer.coser.result.request.AbstractGetIndicatorResultRequest; +import fr.ifremer.coser.result.request.GetPopulationIndicatorResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Result; @@ -91,13 +91,13 @@ // @Action(results = {@Result(type = "stream", params = {"contentType", "text/csv", "inputName", "inputStream", "contentDisposition", "attachment; filename=\"${filename}\""})}) @Action(results = {@Result(type = "stream", params = {"contentType", "text/csv", "contentDisposition", "attachment; filename=\"${filename}\""})}) public String execute() { - PopulationIndicatorRequest request = requestBuilder(). + GetPopulationIndicatorResultRequest request = requestBuilder(). addFacade(facade). addZone(zone). addSpecies(species). addIndicator(indicator). - addResultType( IndicatorRequest.ResultType.DATA). - toPopulationIndicatorRequest(); + addIndicatorResultType(AbstractGetIndicatorResultRequest.IndicatorResultType.DATA). + toGetPopulationIndicatorResultRequest(); result = getService().getFileResult(request); return SUCCESS; } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/IndicatorAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/IndicatorAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/IndicatorAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.pop; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; +import fr.ifremer.coser.result.request.GetPopulationIndicatorResultRequest; import fr.ifremer.coser.web.actions.common.CommonIndicator; /** @@ -39,11 +39,11 @@ private static final long serialVersionUID = 1663244944108703571L; @Override - protected PopulationIndicatorRequest createRequest() { - return requestBuilder(). + protected GetPopulationIndicatorResultRequest createRequest() { + return requestBuilder(GetPopulationIndicatorResultRequest.class). addFacade(facade). addZone(zone). addSpecies(species). - toPopulationIndicatorRequest(); + toRequest(); } } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/SpeciesAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/SpeciesAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/SpeciesAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.pop; -import fr.ifremer.coser.result.request.PopulationIndicatorRequest; +import fr.ifremer.coser.result.request.GetPopulationIndicatorResultRequest; import fr.ifremer.coser.web.actions.common.CoserAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -52,7 +52,7 @@ protected String zonePicture; - protected PopulationIndicatorRequest request; + protected GetPopulationIndicatorResultRequest request; public String getFacade() { return facade; @@ -96,7 +96,7 @@ request = requestBuilder(). addFacade(facade). addZone(zone). - toPopulationIndicatorRequest(); + toGetPopulationIndicatorResultRequest(); species = getService().getAvailableSpecies(request); if (log.isDebugEnabled()) { Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/ZoneAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/ZoneAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/pop/ZoneAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -42,6 +42,6 @@ protected CoserRequest createRequest() { return requestBuilder(). addFacade(facade). - toPopulationIndicatorRequest(); + toGetPopulationIndicatorResultRequest(); } } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/search/ExtractAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/search/ExtractAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/search/ExtractAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -23,7 +23,7 @@ import com.google.common.collect.Lists; import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.request.ExtractRequest; +import fr.ifremer.coser.result.request.ExtractRawDataAndResultsRequest; import fr.ifremer.coser.util.DataType; import fr.ifremer.coser.web.actions.common.CoserAction; import org.apache.commons.collections4.CollectionUtils; @@ -183,28 +183,28 @@ result = INPUT; types = DataType.getExtractTypes(getLocale()); + + ExtractRawDataAndResultsRequest extractRawDataAndResultsRequest = requestBuilder().toExtractRawDataAndResultsRequest(); // renvoi la liste des id subzone-survey et leurs label associé - zones = getService().getZoneForFacade(); + zones = getService().getAvailableZones(extractRawDataAndResultsRequest); if (CollectionUtils.isNotEmpty(selectZones)) { - ExtractRequest extractRequest = requestBuilder(). - addZoneList(selectZones). - toExtractRequest(); + extractRawDataAndResultsRequest.setZoneList(selectZones); - species = getService().getAvailableSpecies(extractRequest); + species = getService().getAvailableSpecies(extractRawDataAndResultsRequest); if (selectTypes != null) { if (selectTypes.contains(DataType.COMMUNITY)) { - extractRequest.setExtractTypeList(Lists.newArrayList(DataType.COMMUNITY)); - comIndicators = getService().getAvailableIndicators(extractRequest); + extractRawDataAndResultsRequest.setExtractTypeList(Lists.newArrayList(DataType.COMMUNITY)); + comIndicators = getService().getAvailableIndicators(extractRawDataAndResultsRequest); } if (selectTypes.contains(DataType.POPULATION)) { - extractRequest.setExtractTypeList(Lists.newArrayList(DataType.POPULATION)); - popIndicators = getService().getAvailableIndicators(extractRequest); + extractRawDataAndResultsRequest.setExtractTypeList(Lists.newArrayList(DataType.POPULATION)); + popIndicators = getService().getAvailableIndicators(extractRawDataAndResultsRequest); } } } @@ -270,15 +270,15 @@ Locale locale = (Locale) request.getSession().getAttribute(LOCALE_ATTRIBUTE); - ExtractRequest extractRequest = requestBuilder(locale). + ExtractRawDataAndResultsRequest extractRawDataAndResultsRequest = requestBuilder(locale). addZoneList(selectZones). addExtractTypeList(selectTypes). addSpeciesList(selectSpecies). addCommunityIndicatorList(selectComIndicators). addPopulationIndicatorList(selectPopIndicators). - toExtractRequest(); + toExtractRawDataAndResultsRequest(); - resultFile = getService().getFileResult(extractRequest); + resultFile = getService().getFileResult(extractRawDataAndResultsRequest); return SUCCESS; } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/source/SourceAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/source/SourceAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/source/SourceAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.source; -import fr.ifremer.coser.result.request.RawDataRequest; +import fr.ifremer.coser.result.request.ExtractRawDataRequest; import fr.ifremer.coser.web.actions.common.CoserAction; import java.util.Map; @@ -46,7 +46,7 @@ protected String zonePicture; - protected RawDataRequest request; + protected ExtractRawDataRequest request; public String getFacade() { return facade; @@ -83,12 +83,12 @@ return SUCCESS; } - protected RawDataRequest getRequest() { + protected ExtractRawDataRequest getRequest() { if (request == null) { request = requestBuilder(). addFacade(facade). addZone(zone). - toRawDataRequest(); + toExtractRawDataRequest(); } return request; } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/source/ZoneAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/source/ZoneAction.java 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/source/ZoneAction.java 2014-03-12 17:35:43 UTC (rev 1145) @@ -21,7 +21,7 @@ package fr.ifremer.coser.web.actions.source; -import fr.ifremer.coser.result.request.RawDataRequest; +import fr.ifremer.coser.result.request.ExtractRawDataRequest; import fr.ifremer.coser.web.actions.common.CommonZone; /** @@ -39,10 +39,10 @@ private static final long serialVersionUID = 3385467755357775199L; @Override - protected RawDataRequest createRequest() { + protected ExtractRawDataRequest createRequest() { return requestBuilder(). addFacade(facade). - toRawDataRequest(); + toExtractRawDataRequest(); } // @Override Modified: trunk/coser-web/src/main/resources/i18n/coser-web_en_GB.properties =================================================================== --- trunk/coser-web/src/main/resources/i18n/coser-web_en_GB.properties 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/resources/i18n/coser-web_en_GB.properties 2014-03-12 17:35:43 UTC (rev 1145) @@ -9,6 +9,9 @@ message.admin.listprojects.indicatorsprojects=Indicators projects by zones message.admin.listprojects.indicatorsprojects.comment=Removing an indicator project will also delete projet data source. message.admin.listprojects.mapsprojects=Maps projects by zones +message.admin.listprojects.projects=Projects by zones +message.admin.listprojects.projects.comment=Removing a project will also delete projet data source. +message.admin.listprojects.select.resultType=Select type of project message.admin.listprojects.title=Projects management message.admin.login=Login message.admin.loginrequiered=Authentication required Modified: trunk/coser-web/src/main/resources/i18n/coser-web_fr_FR.properties =================================================================== --- trunk/coser-web/src/main/resources/i18n/coser-web_fr_FR.properties 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/resources/i18n/coser-web_fr_FR.properties 2014-03-12 17:35:43 UTC (rev 1145) @@ -6,9 +6,12 @@ coser.config.coserWeb.configuration.description=Configuration du site des indicateurs message.admin.indexaction=Actions d'administration message.admin.listprojects.deleteselected=Supprimer les projets sélectionnés -message.admin.listprojects.indicatorsprojects=Projects d'indicateur par zones -message.admin.listprojects.indicatorsprojects.comment=La suppression d'un projets d'indicateur supprimera également la possibilité de télécharger les données sources du projet concerné. +message.admin.listprojects.indicatorsprojects=Projets d'indicateur par zones +message.admin.listprojects.indicatorsprojects.comment=La suppression d'un projet d'indicateur supprimera également la possibilité de télécharger les données sources du projet concerné. message.admin.listprojects.mapsprojects=Projects de cartes par zones +message.admin.listprojects.projects=Projects par zones +message.admin.listprojects.projects.comment=La suppression d'un projet supprimera également la possibilité de télécharger les données sources du projet concerné. +message.admin.listprojects.select.resultType=Sélectionner le type de projet message.admin.listprojects.title=Gestion des projets message.admin.login=Identifiant message.admin.loginrequiered=Autentification requise Modified: trunk/coser-web/src/main/resources/log4j.properties =================================================================== --- trunk/coser-web/src/main/resources/log4j.properties 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/resources/log4j.properties 2014-03-12 17:35:43 UTC (rev 1145) @@ -29,3 +29,4 @@ # Categories log4j.category.fr.ifremer.coser=INFO +log4j.category.org.nuiton=INFO Modified: trunk/coser-web/src/main/webapp/WEB-INF/content/admin/list-projects.jsp =================================================================== --- trunk/coser-web/src/main/webapp/WEB-INF/content/admin/list-projects.jsp 2014-03-11 16:45:58 UTC (rev 1144) +++ trunk/coser-web/src/main/webapp/WEB-INF/content/admin/list-projects.jsp 2014-03-12 17:35:43 UTC (rev 1145) @@ -29,56 +29,112 @@ <h2><s:text name="message.admin.listprojects.title" /></h2> - <h3><s:text name="message.admin.listprojects.indicatorsprojects" /></h3> + <h3><s:text name="message.admin.listprojects.select.resultType" /></h3> - <p><s:text name="message.admin.listprojects.indicatorsprojects.comment" /></p> - - <form action="delete-projects" class="listprojects" method="post"> - <s:iterator value="facades"> - <div class="listprojects-facade"> - <span class="title"><s:text name="message.common.facade" /> : <s:property value='value' /></span> - <s:iterator value="%{getZonesByFacades().get(key)}" var="zone"> - <div class="listprojects-zone"> - <span class="title"><s:text name="message.common.zone" /> : <s:property value="getZoneDisplayName(#zone)"/></span> - <div class="listprojects-result"> - <s:if test="%{indicatorsResults.get(#zone) == null}"> - Aucun projet trouvé - </s:if> - <s:else> - <input type="checkbox" name="indicatorsZonesId" value="<s:property value="zone" />" /> - <s:property value="%{indicatorsResults.get(#zone)}" /> - </s:else> + <s:form action="list-projects" method="get"> + <select name="selectedRepositoryType" id="selectedRepositoryType"> + <s:iterator value="repositoryTypes" var="repositoryType"> + <option value="<s:property value="key" />" + <s:if test="#repositoryType.key.equals(selectedRepositoryType)"> + selected="selected" + </s:if>> + <s:property value="%{getText(#repositoryType.value.labelKey)}" /></option> + </s:iterator> + </select> + <s:submit value="%{getText('message.common.validform')}"/> + </s:form> + + <s:if test="selectedRepositoryType == @fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepositoryType@ID"> + <h3><s:text name="message.admin.listprojects.projects" /></h3> + <p><s:text name="message.admin.listprojects.projects.comment" /></p> + + <form action="delete-projects" class="listprojects" method="post"> + <s:hidden name="repositoryType" value="%{selectedRepositoryType}"/> + <s:hidden name="resultType" value="%{@fr.ifremer.coser.result.ResultType@MAP_AND_INDICATOR}"/> + <s:set name="results" value="%{getResults(@fr.ifremer.coser.result.ResultType@MAP_AND_INDICATOR)}"/> + <s:iterator value="facades"> + <div class="listprojects-facade"> + <span class="title"><s:text name="message.common.facade" /> : <s:property value='value' /></span> + <s:iterator value="%{getZonesByFacades().get(key)}" var="zone"> + <div class="listprojects-zone"> + <span class="title"><s:text name="message.common.zone" /> : <s:property value="getZoneDisplayName(#zone)"/></span> + <div class="listprojects-result"> + <s:if test="%{#results.get(#zone) == null}"> + Aucun projet trouvé + </s:if> + <s:else> + <input type="checkbox" name="zonesId" value="<s:property value="zone" />" /> + <s:property value="%{#results.get(#zone)}" /> + </s:else> + </div> </div> - </div> - </s:iterator> - </div> - </s:iterator> - <s:submit value='%{getText("message.admin.listprojects.deleteselected")}'/> - </form> - - <h3><s:text name="message.admin.listprojects.mapsprojects" /></h3> - - <form action="delete-projects" class="listprojects" method="post"> - <s:iterator value="facades"> - <div class="listprojects-facade"> - <span class="title"><s:text name="message.common.facade" /> : <s:property value='value' /></span> - <s:iterator value="%{getZonesByFacades().get(key)}" var="zone"> - <div class="listprojects-zone"> - <span class="title"><s:text name="message.common.zone" /> : <s:property value="getZoneDisplayName(#zone)"/></span> - <div class="listprojects-result"> - <s:if test="%{mapsResults.get(#zone) == null}"> - Aucun projet trouvé - </s:if> - <s:else> - <input type="checkbox" name="mapsZonesId" value="<s:property value="zone" />" /> - <s:property value="%{mapsResults.get(#zone)}" /> - </s:else> + </s:iterator> + </div> + </s:iterator> + <s:submit value='%{getText("message.admin.listprojects.deleteselected")}'/> + </form> + </s:if> + <s:elseif test="selectedRepositoryType == @fr.ifremer.coser.result.repository.legacy.LegacyResultRepositoryType@ID"> + + <h3><s:text name="message.admin.listprojects.indicatorsprojects" /></h3> + <p><s:text name="message.admin.listprojects.indicatorsprojects.comment" /></p> + + <form action="delete-projects" class="listprojects" method="post"> + <s:hidden name="repositoryType" value="%{selectedRepositoryType}"/> + <s:hidden name="resultType" value="%{@fr.ifremer.coser.result.ResultType@INDICATOR}"/> + <s:set name="results" value="%{getResults(@fr.ifremer.coser.result.ResultType@INDICATOR)}"/> + <s:iterator value="facades"> + <div class="listprojects-facade"> + <span class="title"><s:text name="message.common.facade" /> : <s:property value='value' /></span> + <s:iterator value="%{getZonesByFacades().get(key)}" var="zone"> + <div class="listprojects-zone"> + <span class="title"><s:text name="message.common.zone" /> : <s:property value="getZoneDisplayName(#zone)"/></span> + <div class="listprojects-result"> + <s:if test="%{#results.get(#zone) == null}"> + Aucun projet trouvé + </s:if> + <s:else> + <input type="checkbox" name="zonesId" value="<s:property value="zone" />" /> + <s:property value="%{#results.get(#zone)}" /> + </s:else> + </div> </div> - </div> - </s:iterator> - </div> - </s:iterator> - <s:submit value='%{getText("message.admin.listprojects.deleteselected")}'/> - </form> + </s:iterator> + </div> + </s:iterator> + <s:submit value='%{getText("message.admin.listprojects.deleteselected")}'/> + </form> + + <h3><s:text name="message.admin.listprojects.mapsprojects" /></h3> + + <form action="delete-projects" class="listprojects" method="post"> + <s:hidden name="repositoryType" value="%{selectedRepositoryType}"/> + <s:hidden name="resultType" value="%{@fr.ifremer.coser.result.ResultType@MAP}"/> + <s:set name="results" value="%{getResults(@fr.ifremer.coser.result.ResultType@MAP)}"/> + <s:iterator value="facades"> + <div class="listprojects-facade"> + <span class="title"><s:text name="message.common.facade" /> : <s:property value='value' /></span> + <s:iterator value="%{getZonesByFacades().get(key)}" var="zone"> + <div class="listprojects-zone"> + <span class="title"><s:text name="message.common.zone" /> : <s:property value="getZoneDisplayName(#zone)"/></span> + <div class="listprojects-result"> + <s:if test="%{#results.get(#zone) == null}"> + Aucun projet trouvé + </s:if> + <s:else> + <input type="checkbox" name="zonesId" value="<s:property value="zone" />" /> + <s:property value="%{#results.get(#zone)}" /> + </s:else> + </div> + </div> + </s:iterator> + </div> + </s:iterator> + <s:submit value='%{getText("message.admin.listprojects.deleteselected")}'/> + </form> + </s:elseif> + <s:else> + TODO + </s:else> </body> </html>
participants (1)
-
tchemit@users.forge.codelutin.com