Author: tchemit Date: 2014-03-11 17:45:58 +0100 (Tue, 11 Mar 2014) New Revision: 1144 Url: http://forge.codelutin.com/projects/coser/repository/revisions/1144 Log: refs #4664 (nearly done...) Added: 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/result/request/DeleteRequest.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationContext.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserRequest.java trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserResultEngine.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/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/CommunityIndicatorResultProducer.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/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/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/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/test/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryProviderTest.java 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/legacy/LegacyResultRepositoryProviderTest.java trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationListener.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceHelper.java trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/IndexAction.java Added: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserServiceContext.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/CoserServiceContext.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/CoserServiceContext.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -0,0 +1,46 @@ +package fr.ifremer.coser; + +/* + * #%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.bean.IndicatorMap; +import fr.ifremer.coser.bean.ZoneMap; +import fr.ifremer.coser.result.repository.ResultRepositoryProvider; + +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public interface CoserServiceContext { + + CoserBusinessConfig getConfig(); + + Set<ResultRepositoryProvider<?>> getProviders(); + + IndicatorMap getIndicatorsMap(); + + ZoneMap getZonesMap(); +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/CoserServiceContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/coser-business/src/main/java/fr/ifremer/coser/DefaultCoserServiceContext.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/DefaultCoserServiceContext.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/DefaultCoserServiceContext.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -0,0 +1,93 @@ +package fr.ifremer.coser; + +/* + * #%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.bean.IndicatorMap; +import fr.ifremer.coser.bean.ZoneMap; +import fr.ifremer.coser.result.CoserResultEngine; +import fr.ifremer.coser.result.repository.ResultRepositoryProvider; + +import java.util.Set; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class DefaultCoserServiceContext implements CoserServiceContext { + + /** + * Application configuration. + */ + protected CoserBusinessConfig config; + + /** + * Result repositories providers. + */ + protected Set<ResultRepositoryProvider<?>> providers; + + /** + * Cache of indicator definition. + */ + protected IndicatorMap indicatorsMap; + + /** + * Cache of zone definition. + */ + protected ZoneMap zonesMap; + + public DefaultCoserServiceContext(CoserBusinessConfig config) { + this.config = config; + } + + @Override + public CoserBusinessConfig getConfig() { + return config; + } + + @Override + public Set<ResultRepositoryProvider<?>> getProviders() { + if (providers == null) { + providers = CoserResultEngine.createDefaultRepositoryProviders(config); + } + return providers; + } + + @Override + public IndicatorMap getIndicatorsMap() { + if (indicatorsMap == null) { + indicatorsMap = new IndicatorMap(config.getWebIndicatorsFile()); + } + return indicatorsMap; + } + + @Override + public ZoneMap getZonesMap() { + if (zonesMap == null) { + zonesMap = new ZoneMap(config.getWebZonesFile()); + } + return zonesMap; + } + +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/DefaultCoserServiceContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserRequest.java 2014-03-11 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserRequest.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -33,7 +33,7 @@ * @author Tony Chemit <chemit@codelutin.com> * @since 1.5 */ -public interface CoserRequest extends Serializable{ +public interface CoserRequest extends Serializable { Locale getLocale(); 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/CoserResultEngine.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -27,6 +27,7 @@ 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.ResultRepositoryProvider; import fr.ifremer.coser.result.repository.echobase.EchoBaseResultRepositoryProvider; @@ -57,39 +58,36 @@ /** Logger. */ private static final Log log = LogFactory.getLog(CoserResultEngine.class); - /** - * List of result repository providers. - */ - protected final Set<ResultRepositoryProvider<?>> repositoryProviders; - - /** - * Result repositories loaded lazy from their provider. - * - * @see #getRepositories() - */ - protected Set<ResultRepository> repositories; - 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, config.getWebMapsProjectsDirectory())); + result.add(new LegacyResultRepositoryProvider(config.getWebMapsProjectsDirectory())); // add legacy indicators repository Preconditions.checkNotNull(config.getWebIndicatorsProjectsDirectory()); - result.add(new LegacyResultRepositoryProvider(config, config.getWebIndicatorsProjectsDirectory())); + result.add(new LegacyResultRepositoryProvider(config.getWebIndicatorsProjectsDirectory())); // add EchoBase repository Preconditions.checkNotNull(config.getWebEchobaseProjectsDirectory()); - result.add(new EchoBaseResultRepositoryProvider(config, config.getWebEchobaseProjectsDirectory())); + result.add(new EchoBaseResultRepositoryProvider(config.getWebEchobaseProjectsDirectory())); return result; } - public CoserResultEngine(Set<ResultRepositoryProvider<?>> repositoryProviders) { - Preconditions.checkNotNull(repositoryProviders); - this.repositoryProviders = repositoryProviders; + /** + * Result repositories loaded lazy from their provider. + * + * @see #getRepositories() + */ + protected Set<ResultRepository> repositories; + + protected final CoserServiceContext serviceContext; + + public CoserResultEngine(CoserServiceContext serviceContext) { + Preconditions.checkNotNull(serviceContext); + this.serviceContext = serviceContext; } public void resetRepositories() { @@ -154,8 +152,8 @@ if (repositories == null) { Set<String> ids = Sets.newHashSet(); repositories = Sets.newHashSet(); - for (ResultRepositoryProvider repositoryProvider : repositoryProviders) { - Set<ResultRepository> resultRepositories = repositoryProvider.loadRepositories(); + for (ResultRepositoryProvider repositoryProvider : serviceContext.getProviders()) { + Set<ResultRepository> resultRepositories = repositoryProvider.loadRepositories(serviceContext); // check all repository use a unique id for (ResultRepository resultRepository : resultRepositories) { Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -39,6 +39,8 @@ ResultRepository getRepository(); + boolean acceptResult(R request); + Map<String, String> getAvailableZones(R request); Map<String, String> getAvailableSpecies(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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepository.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -48,7 +48,7 @@ * @param request request * @return all available zones for the given request */ - Map<String, String> getAvailableZones(CoserRequest request); + <R extends CoserRequest> Map<String, String> getAvailableZones(R request); /** * Get all available species (or speciesList) for the given request. @@ -56,7 +56,7 @@ * @param request request * @return all available species for the given request. */ - Map<String, String> getAvailableSpecies(CoserRequest request); + <R extends CoserRequest> Map<String, String> getAvailableSpecies(R request); /** * Get all available indicators for the given request. @@ -64,14 +64,14 @@ * @param request request * @return all available indicators for the given request. */ - Map<String, String> getAvailableIndicators(CoserRequest 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 */ - boolean acceptResult(CoserRequest request); + <R extends CoserRequest> boolean acceptResult(R request); /** * Get result for the given request. @@ -81,5 +81,5 @@ * @param request request to obtain result * @return the result for the given request */ - CoserResult getResult(CoserRequest request); + <R extends CoserRequest> CoserResult getResult(R request); } 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/ResultRepositoryProvider.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -22,6 +22,7 @@ * #L% */ +import fr.ifremer.coser.CoserServiceContext; import fr.ifremer.coser.result.ResultRepositoryInitializationException; import java.util.Set; @@ -37,7 +38,8 @@ public interface ResultRepositoryProvider<R extends ResultRepository> { /** + * @param serviceContext service context * @return the set of provided result repositories. */ - Set<R> loadRepositories() throws ResultRepositoryInitializationException; + Set<R> loadRepositories(CoserServiceContext serviceContext) throws ResultRepositoryInitializationException; } Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/CommunityIndicatorResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -90,6 +90,13 @@ } @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()); @@ -112,7 +119,7 @@ boolean match = repository.matchFacade(request) && repository.matchZone(request) && - repository.matchIndicator(request); + matchIndicator(request); Map<String, String> result = null; @@ -389,4 +396,46 @@ 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepository.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -27,7 +27,7 @@ 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.bean.EchoBaseProject; import fr.ifremer.coser.bean.IndicatorMap; import fr.ifremer.coser.bean.SpeciesMap; @@ -46,7 +46,6 @@ import fr.ifremer.coser.result.request.RawDataRequest; import fr.ifremer.coser.storage.DataStorage; import fr.ifremer.coser.storage.DataStorages; -import fr.ifremer.coser.util.DataType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -84,11 +83,6 @@ protected final File mapsDirectory; /** - * Application config. - */ - protected final CoserBusinessConfig config; - - /** * Transform a map result species file to the species code. */ protected final Function<File, String> mapFileToSpeciesCode; @@ -104,36 +98,26 @@ protected final FilenameFilter mapSpeciesFilenameFilter; /** - * Cache of species definition. + * Service context. */ - protected SpeciesMap speciesMap; + protected final CoserServiceContext serviceContext; /** - * Cache of indicator definition. - */ - protected IndicatorMap indicatorsMap; - - /** - * Cache of zone definition. - */ - protected ZoneMap zonesMap; - - /** * Cache of species definition. */ - protected DataStorage speciesDefinition; + protected SpeciesMap speciesMap; /** * Report helper. */ protected final Reports reports; - protected final Map<Class<?>, ResultProducer<?>> resultProducers; + protected final Map<String, ResultProducer<?>> resultProducers; - public EchoBaseResultRepository(CoserBusinessConfig config, EchoBaseProject project) { - Preconditions.checkNotNull(config); + public EchoBaseResultRepository(CoserServiceContext serviceContext, EchoBaseProject project) { + this.serviceContext = serviceContext; + Preconditions.checkNotNull(serviceContext); Preconditions.checkNotNull(project); - this.config = config; this.project = project; this.mapsDirectory = project.getMapsDirectory(); this.reports = new Reports(); @@ -144,11 +128,11 @@ this.mapSpeciesFilenameFilter = EchoBaseProject.newMapSpeciesFilenameFilter(surveyName); this.resultProducers = Maps.newHashMap(); - this.resultProducers.put(MapRequest.class, new MapResultProducer(this)); - this.resultProducers.put(CommunityIndicatorRequest.class, new CommunityIndicatorResultProducer(this)); - this.resultProducers.put(PopulationIndicatorRequest.class, new PopulationIndicatorResultProducer(this)); - this.resultProducers.put(RawDataRequest.class, new RawDataResultProducer(this)); - this.resultProducers.put(ExtractRequest.class, new ExtractResultProducer(this)); + 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()); @@ -165,9 +149,9 @@ } @Override - public Map<String, String> getAvailableZones(CoserRequest request) { - - ResultProducer resultProducer = getProducer(request.getClass()); + public <R extends CoserRequest> Map<String, String> getAvailableZones(R request) { + Preconditions.checkNotNull(request); + ResultProducer<R> resultProducer = getProducer(request); Preconditions.checkNotNull(resultProducer); Map<String, String> result = resultProducer.getAvailableZones(request); @@ -175,9 +159,9 @@ } @Override - public Map<String, String> getAvailableSpecies(CoserRequest request) { - - ResultProducer resultProducer = getProducer(request.getClass()); + public <R extends CoserRequest> Map<String, String> getAvailableSpecies(R request) { + Preconditions.checkNotNull(request); + ResultProducer<R> resultProducer = getProducer(request); Preconditions.checkNotNull(resultProducer); Map<String, String> result = resultProducer.getAvailableSpecies(request); @@ -185,9 +169,9 @@ } @Override - public Map<String, String> getAvailableIndicators(CoserRequest request) { - - ResultProducer resultProducer = getProducer(request.getClass()); + public <R extends CoserRequest> Map<String, String> getAvailableIndicators(R request) { + Preconditions.checkNotNull(request); + ResultProducer<R> resultProducer = getProducer(request); Preconditions.checkNotNull(resultProducer); Map<String, String> result = resultProducer.getAvailableIndicators(request); @@ -195,74 +179,36 @@ } @Override - public boolean acceptResult(CoserRequest request) { - + public <R extends CoserRequest> boolean acceptResult(R request) { + Preconditions.checkNotNull(request); Preconditions.checkArgument(request.isFilled()); - boolean result = false; - - if (request instanceof MapRequest) { - - // must match facade + zone + species - MapRequest r = (MapRequest) request; - - result = matchFacade(r) && - matchZone(r) && - matchSpecies(r); - } else if (request instanceof RawDataRequest) { - - // must match facade + zone - RawDataRequest r = (RawDataRequest) request; - result = matchFacade(r) && matchZone(r); - - } else if (request instanceof CommunityIndicatorRequest) { - - // must match facade + zone + (indicator + speciesList) - CommunityIndicatorRequest r = (CommunityIndicatorRequest) request; - - result = matchFacade(r) && - matchZone(r) && - matchIndicatorAndSpeciesList(r); - } else if (request instanceof PopulationIndicatorRequest) { - - // must match facade + zone + (species + indicator) - PopulationIndicatorRequest r = (PopulationIndicatorRequest) request; - - result = matchFacade(r) && - matchZone(r) && - matchSpeciesAndIndicator(r); - } else if (request instanceof ExtractRequest) { - - // must match extract type + zone + (species + indicator) - ExtractRequest r = (ExtractRequest) request; - - result = matchExtractTypeSet(r) && - matchZoneList(r) && - (matchPopulationIndicatorListAndSpeciesList(r) || - matchCommunityIndicatorListAndSpeciesList(r)); - } + ResultProducer<R> resultProducer = getProducer(request); + Preconditions.checkNotNull(resultProducer); + boolean result = resultProducer.acceptResult(request); return result; } @Override - public CoserResult getResult(CoserRequest request) { - + public <R extends CoserRequest> CoserResult getResult(R request) { + Preconditions.checkNotNull(request); Preconditions.checkArgument(request.isFilled()); Preconditions.checkArgument(acceptResult(request)); - ResultProducer resultProducer = getProducer(request.getClass()); + ResultProducer<R> resultProducer = getProducer(request); Preconditions.checkNotNull(resultProducer); CoserResult result = resultProducer.produceResult(request); return result; } - protected <R extends CoserRequest> ResultProducer<R> getProducer(Class<R> requestType) { - return (ResultProducer<R>) resultProducers.get(requestType); + protected <R extends CoserRequest> ResultProducer<R> getProducer(R request) { + String requestTypeName = request.getClass().getName(); + return (ResultProducer<R>) resultProducers.get(requestTypeName); } // --------------------------------------------------------------------- // - // --- Common matchers ------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // // --------------------------------------------------------------------- // protected boolean matchFacade(CoserRequestFacadeAware request) { @@ -273,26 +219,6 @@ return project.getZoneName().equals(request.getZone()); } - // --------------------------------------------------------------------- // - // --- MapRequest matchers --------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchSpecies(MapRequest request) { - String species = request.getSpecies(); - File file = getMapSpeciesFile(species); - return file != null && file.exists(); - } - - // --------------------------------------------------------------------- // - // --- RawDataRequest matchers ----------------------------------------- // - // --------------------------------------------------------------------- // - - // None - - // --------------------------------------------------------------------- // - // --- IndicatorRequest matchers --------------------------------------- // - // --------------------------------------------------------------------- // - protected boolean matchIndicatorSpecies(String[] tuple, String species) { String speciesCode = tuple[3]; boolean result = species.equals(speciesCode); @@ -310,190 +236,21 @@ String indicator) { String speciesCode = tuple[3]; String indicatorCode = tuple[1]; - boolean result = species.equals(speciesCode) && indicator.equals(indicatorCode); + boolean result = species.equals(speciesCode) && + indicator.equals(indicatorCode); return result; } - // --------------------------------------------------------------------- // - // --- PopulationIndicatorRequest matchers ----------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchSpecies(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getSpecies()); - - String species = request.getSpecies(); - - boolean result = false; - - Iterator<String[]> iterator = loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (matchIndicatorSpeciesAndIndicator(tuple, species, indicator)) { - result = true; - break; - } - } - return result; - } - - // --------------------------------------------------------------------- // - // --- CommunityIndicatorRequest matchers ------------------------------ // - // --------------------------------------------------------------------- // - - protected boolean matchIndicator(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getIndicator()); - - String indicator = request.getIndicator(); - - boolean result = false; - - Iterator<String[]> iterator = loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { - result = true; - break; - } - } - return result; - } - protected boolean matchCommunityIndicatorAndSpeciesList(String[] tuple, String indicator, String speciesList) { String indicatorCode = tuple[1]; String speciesListCode = tuple[2]; - boolean result = indicator.equals(indicatorCode) && speciesList.equals(speciesListCode); + boolean result = indicator.equals(indicatorCode) && + speciesList.equals(speciesListCode); return result; } - // --------------------------------------------------------------------- // - // --- ExtractRequest 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 = loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { - result = true; - break; - } - } - return result; - } - protected boolean matchIndicatorList(String[] tuple, List<String> indicatorList) { String indicatorCode = tuple[1]; boolean result = indicatorList.contains(indicatorCode); @@ -505,7 +262,8 @@ List<String> speciesList) { String indicatorCode = tuple[1]; String speciesCode = tuple[3]; - boolean result = indicatorList.contains(indicatorCode) && speciesList.contains(speciesCode); + boolean result = indicatorList.contains(indicatorCode) && + speciesList.contains(speciesCode); return result; } @@ -613,26 +371,18 @@ protected SpeciesMap getSpeciesMap() { if (speciesMap == null) { - File file = project.getSpeciesDefinitionFile(); - speciesMap = new SpeciesMap(file); } return speciesMap; } protected IndicatorMap getIndicatorsMap() { - if (indicatorsMap == null) { - indicatorsMap = new IndicatorMap(config.getWebIndicatorsFile()); - } - return indicatorsMap; + return serviceContext.getIndicatorsMap(); } public ZoneMap getZonesMap() { - if (zonesMap == null) { - zonesMap = new ZoneMap(config.getWebZonesFile()); - } - return zonesMap; + return serviceContext.getZonesMap(); } // --------------------------------------------------------------------- // 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryProvider.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -24,7 +24,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Sets; -import fr.ifremer.coser.CoserBusinessConfig; +import fr.ifremer.coser.CoserServiceContext; import fr.ifremer.coser.bean.EchoBaseProject; import fr.ifremer.coser.result.ResultRepositoryInitializationException; import fr.ifremer.coser.result.repository.ResultRepositoryProvider; @@ -55,17 +55,13 @@ */ protected final File basedir; - protected final CoserBusinessConfig config; - - public EchoBaseResultRepositoryProvider(CoserBusinessConfig config, File basedir) { - this.config = config; - Preconditions.checkNotNull(config); + public EchoBaseResultRepositoryProvider(File basedir) { Preconditions.checkNotNull(basedir); this.basedir = basedir; } @Override - public Set<EchoBaseResultRepository> loadRepositories() { + public Set<EchoBaseResultRepository> loadRepositories(CoserServiceContext serviceContext) { if (log.isInfoEnabled()) { log.info(String.format("Scan for projects from basedir: %s", basedir)); @@ -96,7 +92,7 @@ } catch (IOException e) { throw new ResultRepositoryInitializationException(this, "Could not load project file", e); } - result.add(new EchoBaseResultRepository(config, project)); + result.add(new EchoBaseResultRepository(serviceContext, project)); } } if (log.isInfoEnabled()) { Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/ExtractResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -102,6 +102,14 @@ } @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(); @@ -114,7 +122,7 @@ public Map<String, String> getAvailableSpecies(ExtractRequest request) { Preconditions.checkNotNull(request.getZoneList()); - boolean match = repository.matchZoneList(request); + boolean match = matchZoneList(request); Map<String, String> result = null; if (match) { @@ -136,7 +144,7 @@ Map<String, String> result = null; - boolean match = repository.matchZoneList(request); + boolean match = matchZoneList(request); if (match) { Set<String> indicatorList = null; @@ -682,4 +690,91 @@ 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; + } } Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/MapResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -58,6 +58,13 @@ } @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()); @@ -105,4 +112,13 @@ return result; } + // --------------------------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchSpecies(MapRequest request) { + String species = request.getSpecies(); + File file = repository.getMapSpeciesFile(species); + return file != null && file.exists(); + } } Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/PopulationIndicatorResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -82,6 +82,13 @@ } @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); @@ -289,4 +296,46 @@ 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; + } + } Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/echobase/RawDataResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -57,6 +57,12 @@ } @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()); @@ -88,4 +94,10 @@ throw RequestUnavailableForProducerException.newException("produceResult", this); } + + // --------------------------------------------------------------------- // + // --- Matchers ------------------------------------------------------- // + // --------------------------------------------------------------------- // + + //TODO } Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/CommunityIndicatorResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -100,6 +100,14 @@ } @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()); @@ -125,7 +133,7 @@ boolean match = repository.indicatorsResult && repository.matchFacade(request) && repository.matchZone(request) && - repository.matchIndicator(request); + matchIndicator(request); if (match) { // get all map species for given facade + zone @@ -402,4 +410,46 @@ 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; + } } Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/ExtractResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -112,6 +112,14 @@ } @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(); @@ -126,7 +134,7 @@ Map<String, String> result = null; - boolean match = repository.matchZoneList(request); + boolean match = matchZoneList(request); if (match) { result = Maps.newHashMap(); @@ -146,7 +154,7 @@ Map<String, String> result = null; - boolean match = repository.matchZoneList(request); + boolean match = matchZoneList(request); if (match) { Set<String> indicatorList = null; @@ -727,4 +735,101 @@ 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepository.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -28,6 +28,7 @@ import com.google.common.collect.Sets; import fr.ifremer.coser.CoserBusinessConfig; import fr.ifremer.coser.CoserConstants; +import fr.ifremer.coser.CoserServiceContext; import fr.ifremer.coser.bean.EchoBaseProject; import fr.ifremer.coser.bean.IndicatorMap; import fr.ifremer.coser.bean.RSufiResultPath; @@ -49,7 +50,6 @@ import fr.ifremer.coser.services.ProjectService; import fr.ifremer.coser.storage.DataStorage; import fr.ifremer.coser.storage.DataStorages; -import fr.ifremer.coser.util.DataType; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; @@ -117,9 +117,9 @@ protected final FilenameFilter mapSpeciesFilenameFilter; /** - * Application config. + * Service context. */ - protected final CoserBusinessConfig config; + protected final CoserServiceContext serviceContext; /** * Survey name (used to get maps). @@ -137,16 +137,6 @@ protected SpeciesListMap speciesListMap; /** - * Cache of indicator definition. - */ - protected IndicatorMap indicatorsMap; - - /** - * Cache of zone definition. - */ - protected ZoneMap zonesMap; - - /** * Is the result contains maps ? */ protected final boolean mapsResult; @@ -166,19 +156,19 @@ */ protected final Reports reports; - protected final Map<Class<?>, ResultProducer<?>> resultProducers; + protected final Map<String, ResultProducer<?>> resultProducers; protected final ProjectService projectService; - public LegacyResultRepository(CoserBusinessConfig config, + public LegacyResultRepository(CoserServiceContext serviceContext, File basedir, RSufiResultPath path, String surveyName) { - Preconditions.checkNotNull(config); + Preconditions.checkNotNull(serviceContext); Preconditions.checkNotNull(basedir); Preconditions.checkNotNull(path); Preconditions.checkNotNull(surveyName); - this.config = config; + this.serviceContext = serviceContext; this.basedir = basedir; this.surveyName = surveyName; this.resultDirectory = FileUtils.getFile( @@ -197,13 +187,13 @@ this.mapFileToSpeciesCode = EchoBaseProject.newMapFileToSpeciesCode(surveyName); this.speciesCodeToMapFile = EchoBaseProject.newSpeciesCodeToMapFileName(surveyName); this.mapSpeciesFilenameFilter = EchoBaseProject.newMapSpeciesFilenameFilter(surveyName); - this.projectService = new ProjectService(config); + this.projectService = new ProjectService(serviceContext.getConfig()); this.resultProducers = Maps.newHashMap(); - this.resultProducers.put(MapRequest.class, new MapResultProducer(this)); - this.resultProducers.put(CommunityIndicatorRequest.class, new CommunityIndicatorResultProducer(this)); - this.resultProducers.put(PopulationIndicatorRequest.class, new PopulationIndicatorResultProducer(this)); - this.resultProducers.put(RawDataRequest.class, new RawDataResultProducer(this)); - this.resultProducers.put(ExtractRequest.class, new ExtractResultProducer(this)); + 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()); @@ -224,19 +214,19 @@ } @Override - public Map<String, String> getAvailableZones(CoserRequest request) { - - ResultProducer resultProducer = getProducer(request.getClass()); + public <R extends CoserRequest> Map<String, String> getAvailableZones(R request) { + Preconditions.checkNotNull(request); + ResultProducer<R> resultProducer = getProducer(request); Preconditions.checkNotNull(resultProducer); - Map result = resultProducer.getAvailableZones(request); + Map<String, String> result = resultProducer.getAvailableZones(request); return result; } @Override - public Map<String, String> getAvailableSpecies(CoserRequest request) { - - ResultProducer resultProducer = getProducer(request.getClass()); + public <R extends CoserRequest> Map<String, String> getAvailableSpecies(R request) { + Preconditions.checkNotNull(request); + ResultProducer<R> resultProducer = getProducer(request); Preconditions.checkNotNull(resultProducer); Map<String, String> result = resultProducer.getAvailableSpecies(request); @@ -244,9 +234,9 @@ } @Override - public Map<String, String> getAvailableIndicators(CoserRequest request) { - - ResultProducer resultProducer = getProducer(request.getClass()); + public <R extends CoserRequest> Map<String, String> getAvailableIndicators(R request) { + Preconditions.checkNotNull(request); + ResultProducer<R> resultProducer = getProducer(request); Preconditions.checkNotNull(resultProducer); Map<String, String> result = resultProducer.getAvailableIndicators(request); @@ -254,76 +244,31 @@ } @Override - public boolean acceptResult(CoserRequest request) { - + public <R extends CoserRequest> boolean acceptResult(R request) { + Preconditions.checkNotNull(request); Preconditions.checkArgument(request.isFilled()); - boolean result = false; - - if (request instanceof MapRequest) { - - // must match facade + zone + species - MapRequest r = (MapRequest) request; - - result = mapsResult && - matchFacade(r) && - matchZone(r) && - matchSpecies(r); - } else if (request instanceof RawDataRequest) { - - // must match facade + zone - RawDataRequest r = (RawDataRequest) request; - result = dataResult && matchFacade(r) && matchZone(r); - - } else if (request instanceof CommunityIndicatorRequest) { - - // must match facade + zone + (indicator + speciesList) - CommunityIndicatorRequest r = (CommunityIndicatorRequest) request; - - result = indicatorsResult && - matchFacade(r) && - matchZone(r) && - matchIndicatorAndSpeciesList(r); - } else if (request instanceof PopulationIndicatorRequest) { - - // must match facade + zone + (species + indicator) - PopulationIndicatorRequest r = (PopulationIndicatorRequest) request; - - result = indicatorsResult && - matchFacade(r) && - matchZone(r) && - matchSpeciesAndIndicator(r); - } else if (request instanceof ExtractRequest) { - - // must match extract type + zone + (species + indicator) - ExtractRequest r = (ExtractRequest) request; - - result = matchExtractTypeSet(r) && - matchZoneList(r) && - (matchPopulationIndicatorListAndSpeciesList(r) || - matchCommunityIndicatorListAndSpeciesList(r)); - } + ResultProducer<R> resultProducer = getProducer(request); + Preconditions.checkNotNull(resultProducer); + boolean result = resultProducer.acceptResult(request); return result; } @Override - public CoserResult getResult(CoserRequest request) { + public <R extends CoserRequest> CoserResult getResult(R request) { + Preconditions.checkNotNull(request); Preconditions.checkArgument(request.isFilled()); Preconditions.checkArgument(acceptResult(request)); - ResultProducer resultProducer = getProducer(request.getClass()); + ResultProducer<R> resultProducer = getProducer(request); Preconditions.checkNotNull(resultProducer); CoserResult result = resultProducer.produceResult(request); return result; } - protected <R extends CoserRequest> ResultProducer<R> getProducer(Class<R> requestType) { - return (ResultProducer<R>) resultProducers.get(requestType); - } - // --------------------------------------------------------------------- // - // --- Common matchers ------------------------------------------------- // + // --- Matchers -------------------------------------------------------- // // --------------------------------------------------------------------- // protected boolean matchFacade(CoserRequestFacadeAware request) { @@ -334,66 +279,6 @@ return path.getRsufiResult().getZone().equals(request.getZone()); } - // --------------------------------------------------------------------- // - // --- MapRequest matchers --------------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchSpecies(MapRequest request) { - String species = request.getSpecies(); - File file = getMapSpeciesFile(species); - return file != null; - } - - // --------------------------------------------------------------------- // - // --- RawDataRequest matchers ----------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchZone(RawDataRequest request) { - return path.getRsufiResult().getZone().equals(request.getZone()); - } - - // --------------------------------------------------------------------- // - // --- PopulationIndicatorRequest matchers ----------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchSpecies(PopulationIndicatorRequest request) { - Preconditions.checkNotNull(request.getSpecies()); - - String species = request.getSpecies(); - - boolean result = false; - - Iterator<String[]> iterator = loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (matchPopulationSpeciesAndIndicator(tuple, species, indicator)) { - result = true; - break; - } - } - return result; - } - protected boolean matchPopulationSpecies(String[] tuple, String species) { String speciesCode = tuple[3]; boolean result = species.equals(speciesCode); @@ -406,48 +291,6 @@ return result; } - // --------------------------------------------------------------------- // - // --- CommunityIndicatorRequest matchers ------------------------------ // - // --------------------------------------------------------------------- // - - protected boolean matchIndicator(CommunityIndicatorRequest request) { - Preconditions.checkNotNull(request.getIndicator()); - - String indicator = request.getIndicator(); - - boolean result = false; - - Iterator<String[]> iterator = loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (matchCommunityIndicatorAndSpeciesList(tuple, indicator, speciesList)) { - result = true; - break; - } - } - return result; - } - protected boolean matchCommunityIndicator(String[] tuple, String indicator) { String indicatorCode = tuple[1]; boolean result = indicator.equals(indicatorCode); @@ -461,103 +304,6 @@ return result; } - // --------------------------------------------------------------------- // - // --- ExtractRequest matchers ----------------------------------------- // - // --------------------------------------------------------------------- // - - protected boolean matchExtractTypeSet(ExtractRequest request) { - boolean result = false; - if (mapsResult) { - result = request.getExtractTypeList().contains(DataType.SOURCE); - } - if (indicatorsResult) { - result = request.getExtractTypeList().contains(DataType.POPULATION) || - request.getExtractTypeList().contains(DataType.COMMUNITY); - } - if (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 = loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadPopulationIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (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 = loadCommunityIndicatorStorage(true); - while (iterator.hasNext()) { - String[] tuple = iterator.next(); - if (matchIndicatorListAndSpeciesList(tuple, indicatorList, speciesList)) { - result = true; - break; - } - } - return result; - } - protected boolean matchIndicatorList(String[] tuple, List<String> indicatorList) { String indicatorCode = tuple[1]; boolean result = indicatorList.contains(indicatorCode); @@ -706,17 +452,11 @@ } protected IndicatorMap getIndicatorsMap() { - if (indicatorsMap == null) { - indicatorsMap = new IndicatorMap(config.getWebIndicatorsFile()); - } - return indicatorsMap; + return serviceContext.getIndicatorsMap(); } public ZoneMap getZonesMap() { - if (zonesMap == null) { - zonesMap = new ZoneMap(config.getWebZonesFile()); - } - return zonesMap; + return serviceContext.getZonesMap(); } // --------------------------------------------------------------------- // @@ -739,4 +479,12 @@ return iterator; } + protected <R extends CoserRequest> ResultProducer<R> getProducer(R request) { + String requestTypeName = request.getClass().getName(); + return (ResultProducer<R>) resultProducers.get(requestTypeName); + } + + protected CoserBusinessConfig getConfig() { + return serviceContext.getConfig(); + } } 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryProvider.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -24,9 +24,9 @@ import com.google.common.base.Preconditions; 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.bean.Project; import fr.ifremer.coser.bean.RSufiResult; import fr.ifremer.coser.bean.RSufiResultPath; @@ -56,27 +56,20 @@ */ protected final File basedir; - protected final ProjectService projectService; - - protected final CoserBusinessConfig config; - - public LegacyResultRepositoryProvider(CoserBusinessConfig config, File basedir) { - this.config = config; - Preconditions.checkNotNull(config); + public LegacyResultRepositoryProvider(File basedir) { Preconditions.checkNotNull(basedir); - this.projectService = new ProjectService(config); this.basedir = basedir; } @Override - public Set<LegacyResultRepository> loadRepositories() { + public Set<LegacyResultRepository> loadRepositories(CoserServiceContext serviceContext) { if (log.isInfoEnabled()) { log.info(String.format("Scan for projects from basedir: %s", basedir)); } Set<LegacyResultRepository> result; try { - result = findAllProjectWithResult(); + result = findAllProjectWithResult(serviceContext); } catch (CoserBusinessException e) { throw new ResultRepositoryInitializationException(this, "Could not find projects", e); } @@ -93,10 +86,14 @@ * De la forme d'une liste de de path (à la tree path) : * ProjetName/SelectionName/ResultName * + * @param serviceContext service context * @return results paths * @throws CoserBusinessException */ - public Set<LegacyResultRepository> findAllProjectWithResult() throws CoserBusinessException { + public Set<LegacyResultRepository> findAllProjectWithResult(CoserServiceContext serviceContext) throws CoserBusinessException { + + ProjectService projectService = new ProjectService(serviceContext.getConfig()); + Set<LegacyResultRepository> result = Sets.newHashSet(); // loop on projets File[] projects = basedir.listFiles(); @@ -131,7 +128,7 @@ } String surveyName = projectService.getProjectSurveyName(rSufiResult, r); - LegacyResultRepository repository = new LegacyResultRepository(config, existingProject, path, surveyName); + LegacyResultRepository repository = new LegacyResultRepository(serviceContext, existingProject, path, surveyName); if (log.isInfoEnabled()) { Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/MapResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -57,6 +57,14 @@ } @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()); @@ -103,4 +111,13 @@ return result; } + // --------------------------------------------------------------------- // + // --- Matchers ------------------------------------------------------- // + // --------------------------------------------------------------------- // + + protected boolean matchSpecies(MapRequest request) { + String species = request.getSpecies(); + File file = repository.getMapSpeciesFile(species); + return file != null; + } } Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/PopulationIndicatorResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -88,6 +88,14 @@ } @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()); @@ -131,7 +139,7 @@ boolean match = repository.indicatorsResult && repository.matchFacade(request) && repository.matchZone(request) && - repository.matchSpecies(request); + matchSpecies(request); if (match) { @@ -192,7 +200,6 @@ String species, String indicator) { - int multiplicator = 1; int minYear = Integer.MAX_VALUE; int maxYear = Integer.MIN_VALUE; @@ -305,4 +312,45 @@ 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; + } } Modified: 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/repository/legacy/RawDataResultProducer.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -75,7 +75,7 @@ this.reports = repository.reports; this.projectService = repository.projectService; this.basedir = repository.basedir; - this.config = repository.config; + this.config = repository.getConfig(); this.surveyName = repository.surveyName; } @@ -85,6 +85,13 @@ } @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); @@ -160,4 +167,12 @@ 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/request/DeleteRequest.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteRequest.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteRequest.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -0,0 +1,74 @@ +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)); + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/result/request/DeleteRequest.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryProviderTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryProviderTest.java 2014-03-11 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryProviderTest.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -48,9 +48,9 @@ File basedir = config.getWebEchobaseProjectsDirectory(); - EchoBaseResultRepositoryProvider provider = new EchoBaseResultRepositoryProvider(config, basedir); + EchoBaseResultRepositoryProvider provider = new EchoBaseResultRepositoryProvider(basedir); - Set<EchoBaseResultRepository> resultRepositories = provider.loadRepositories(); + Set<EchoBaseResultRepository> resultRepositories = provider.loadRepositories(serviceContext); Assert.assertNotNull(resultRepositories); Assert.assertEquals(2, resultRepositories.size()); } 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 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/echobase/EchoBaseResultRepositoryTest.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -53,9 +53,9 @@ File projectsDirectory = config.getWebEchobaseProjectsDirectory(); copyDirectoryContent("src.test.resources.web.echobaseprojects", projectsDirectory); - EchoBaseResultRepositoryProvider repositoryProvider = new EchoBaseResultRepositoryProvider(config, projectsDirectory); + EchoBaseResultRepositoryProvider repositoryProvider = new EchoBaseResultRepositoryProvider(projectsDirectory); - Set<EchoBaseResultRepository> repositories = repositoryProvider.loadRepositories(); + Set<EchoBaseResultRepository> repositories = repositoryProvider.loadRepositories(serviceContext); for (EchoBaseResultRepository repository : repositories) { String projectName = repository.project.getName(); Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryProviderTest.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryProviderTest.java 2014-03-11 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/result/repository/legacy/LegacyResultRepositoryProviderTest.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -49,9 +49,9 @@ File basedir = config.getWebIndicatorsProjectsDirectory(); - LegacyResultRepositoryProvider provider = new LegacyResultRepositoryProvider(config, basedir); + LegacyResultRepositoryProvider provider = new LegacyResultRepositoryProvider(basedir); - Set<LegacyResultRepository> resultRepositories = provider.loadRepositories(); + Set<LegacyResultRepository> resultRepositories = provider.loadRepositories(serviceContext); Assert.assertNotNull(resultRepositories); Assert.assertEquals(2, resultRepositories.size()); } Modified: trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java =================================================================== --- trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java 2014-03-11 14:45:05 UTC (rev 1143) +++ trunk/coser-business/src/test/java/fr/ifremer/coser/services/CoserTestAbstract.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -30,6 +30,8 @@ import java.util.Locale; import java.util.Map; +import fr.ifremer.coser.CoserServiceContext; +import fr.ifremer.coser.DefaultCoserServiceContext; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -59,6 +61,7 @@ private static final Log log = LogFactory.getLog(CoserTestAbstract.class); protected static CoserBusinessConfig config; + protected static CoserServiceContext serviceContext; protected static File testDirectory; @@ -83,6 +86,7 @@ config.setWebIndicatorsFile(CoserTestAbstract.class.getResource("/webindicators.csv").getFile()); config.setWebZonesFile(CoserTestAbstract.class.getResource("/webzones.csv").getFile()); + serviceContext = new DefaultCoserServiceContext(config); } @AfterClass Added: trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationContext.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationContext.java (rev 0) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationContext.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -0,0 +1,103 @@ +package fr.ifremer.coser.web; + +/* + * #%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 com.google.common.base.Preconditions; +import fr.ifremer.coser.CoserServiceContext; +import fr.ifremer.coser.DefaultCoserServiceContext; +import fr.ifremer.coser.result.CoserResultEngine; +import fr.ifremer.coser.services.WebService; +import org.nuiton.config.ArgumentsParserException; +import org.nuiton.i18n.I18n; +import org.nuiton.i18n.init.DefaultI18nInitializer; + +/** + * Created on 3/11/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 1.5 + */ +public class CoserApplicationContext { + + /** + * Shared application context. + */ + protected static CoserApplicationContext context; + + public static CoserApplicationContext get() { + Preconditions.checkState(context != null, "Application was not initialized!"); + return context; + } + + public static void init() { + context = new CoserApplicationContext(); + } + + public static void close() { + context = null; + } + + /** + * Business layer context. + */ + protected CoserServiceContext businessContext; + + /** + * Web config. + */ + protected CoserWebConfig config; + + //TODO Remove this soon + protected WebService webService; + + protected CoserResultEngine resultService; + + public CoserApplicationContext() { + + I18n.init(new DefaultI18nInitializer("coser-i18n"), null); + + config = new CoserWebConfig(); + + try { + config.parse(); + } catch (ArgumentsParserException ex) { + throw new CoserWebException("Can't read configuration", ex); + } + + businessContext = new DefaultCoserServiceContext(config); + + webService = new WebService(config); + resultService = new CoserResultEngine(businessContext); + } + + public WebService getWebService() { + return webService; + } + + public CoserResultEngine getResultService() { + return resultService; + } + + public CoserWebConfig getConfig() { + return config; + } +} Property changes on: trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationContext.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationListener.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationListener.java 2014-03-11 14:45:05 UTC (rev 1143) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/CoserApplicationListener.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -31,9 +31,9 @@ /** * To listen start and end of the application. * <p/> - * On start we will init the service helper ({@link ServiceHelper#init()}). + * On start we will init the application context ({@link CoserApplicationContext#init()}). * <p/> - * On stop, just release close the service helper ({@link ServiceHelper#close()}). + * On stop, just release close the application context ({@link CoserApplicationContext#close()}). * * @author tchemit <chemit@codelutin.com> * @since 1.5 @@ -50,9 +50,7 @@ if (log.isInfoEnabled()) { log.info("Application starting at " + new Date() + "..."); } - - ServiceHelper.init(); - + CoserApplicationContext.init(); } @Override @@ -60,8 +58,6 @@ if (log.isInfoEnabled()) { log.info("Application is ending at " + new Date() + "..."); } - - ServiceHelper.close(); - + CoserApplicationContext.close(); } } 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 14:45:05 UTC (rev 1143) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/ServiceHelper.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -27,23 +27,17 @@ import fr.ifremer.coser.result.CoserResult; import fr.ifremer.coser.result.CoserResultEngine; import fr.ifremer.coser.result.FileResult; -import fr.ifremer.coser.result.repository.ResultRepositoryProvider; 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.services.WebService; import fr.ifremer.coser.util.DataType; import fr.ifremer.coser.web.actions.common.CoserAction; -import org.nuiton.config.ArgumentsParserException; -import org.nuiton.i18n.I18n; -import org.nuiton.i18n.init.DefaultI18nInitializer; import java.io.File; -import java.util.Date; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Set; /** * Wrap any call to business layer. @@ -58,50 +52,21 @@ */ public class ServiceHelper { - private static WebService webService; + protected final CoserAction action; - private static CoserResultEngine resultService; + protected final WebService webService; - private static CoserWebConfig config; + protected final CoserResultEngine resultService; + protected final CoserWebConfig config; - // --------------------------------------------------------------------- // - // --- Application context methods ------------------------------------- // - // --------------------------------------------------------------------- // - - public static void init() { - - // on a pas trop de locale là :( - I18n.init(new DefaultI18nInitializer("coser-i18n"), null); - - config = new CoserWebConfig(); - try { - config.parse(); - } catch (ArgumentsParserException ex) { - throw new CoserWebException("Can't read configuration", ex); - } - - webService = new WebService(config); - - Set<ResultRepositoryProvider<?>> providers = - CoserResultEngine.createDefaultRepositoryProviders(config); - resultService = new CoserResultEngine(providers); - } - - public static void close() { - webService = null; - resultService = null; - config = null; - } - - private final CoserAction action; - public ServiceHelper(CoserAction action) { - Preconditions.checkNotNull(config); - Preconditions.checkNotNull(webService); - Preconditions.checkNotNull(resultService); Preconditions.checkNotNull(action); + CoserApplicationContext applicationContext = CoserApplicationContext.get(); this.action = action; + this.webService = applicationContext.getWebService(); + this.resultService = applicationContext.getResultService(); + this.config = applicationContext.getConfig(); } // --------------------------------------------------------------------- // @@ -279,12 +244,7 @@ // --- Misc methods ---------------------------------------------------- // // --------------------------------------------------------------------- // - public Date getLastDataUpdateDate() { - return getConfig().getLastDataUpdateDate(); - } - public CoserWebConfig getConfig() { return config; } - } Modified: trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/IndexAction.java =================================================================== --- trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/IndexAction.java 2014-03-11 14:45:05 UTC (rev 1143) +++ trunk/coser-web/src/main/java/fr/ifremer/coser/web/actions/IndexAction.java 2014-03-11 16:45:58 UTC (rev 1144) @@ -67,7 +67,7 @@ @Override public String execute() { - dataUpdateDate = getService().getLastDataUpdateDate(); + dataUpdateDate = getService().getConfig().getLastDataUpdateDate(); return SUCCESS; }