branch feature/7494 updated (b65d39b -> ea81a8f)
This is an automated email from the git hooks/post-receive script. New change to branch feature/7494 in repository observe. See http://git.codelutin.com/observe.git from b65d39b Mise en place du boot de l'application web (configuration, mapping, ...) (See 7494) new ea81a8f Suppresion des injectors, mise en place des controlleurs The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit ea81a8f26ca2bf01cf7a49f4bb9caf65774e1dae Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Aug 30 10:17:12 2015 +0200 Suppresion des injectors, mise en place des controlleurs Summary of changes: .../application/web/ObserveServiceInjector.java | 55 ---------------------- .../web/ObserveWebApplicationContext.java | 38 ++++++++++----- .../web/ObserveWebApplicationContextInjector.java | 53 --------------------- .../web/ObserveWebApplicationListener.java | 3 -- .../application/web/ObserveWebMotionFilter.java | 4 +- .../application/web/ObserveWebRequestContext.java | 28 ++++------- .../web/controller/ObserveWebMotionController.java | 18 ++++++- .../web/controller/v1/DocController.java | 9 ++-- .../v1/ReferentialServiceController.java | 10 +++- observe-application-web/src/main/resources/mapping | 8 ++-- .../services/ObserveServiceApplicationContext.java | 17 +++++-- 11 files changed, 81 insertions(+), 162 deletions(-) delete mode 100644 observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveServiceInjector.java delete mode 100644 observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationContextInjector.java -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/7494 in repository observe. See http://git.codelutin.com/observe.git commit ea81a8f26ca2bf01cf7a49f4bb9caf65774e1dae Author: Tony CHEMIT <chemit@codelutin.com> Date: Sun Aug 30 10:17:12 2015 +0200 Suppresion des injectors, mise en place des controlleurs --- .../application/web/ObserveServiceInjector.java | 55 ---------------------- .../web/ObserveWebApplicationContext.java | 38 ++++++++++----- .../web/ObserveWebApplicationContextInjector.java | 53 --------------------- .../web/ObserveWebApplicationListener.java | 3 -- .../application/web/ObserveWebMotionFilter.java | 4 +- .../application/web/ObserveWebRequestContext.java | 28 ++++------- .../web/controller/ObserveWebMotionController.java | 18 ++++++- .../web/controller/v1/DocController.java | 9 ++-- .../v1/ReferentialServiceController.java | 10 +++- observe-application-web/src/main/resources/mapping | 8 ++-- .../services/ObserveServiceApplicationContext.java | 17 +++++-- 11 files changed, 81 insertions(+), 162 deletions(-) diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveServiceInjector.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveServiceInjector.java deleted file mode 100644 index 63de3be..0000000 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveServiceInjector.java +++ /dev/null @@ -1,55 +0,0 @@ -package fr.ird.observe.application.web; - -/* - * #%L - * Pollen :: Rest Api - * %% - * Copyright (C) 2009 - 2014 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.ird.observe.services.ObserveService; -import org.debux.webmotion.server.call.Call; -import org.debux.webmotion.server.call.HttpContext; -import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler; -import org.debux.webmotion.server.mapping.Mapping; - -import java.lang.reflect.Type; - -/** - * Created on 5/23/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 2.0 - */ -public class ObserveServiceInjector implements ExecutorParametersInjectorHandler.Injector { - - @Override - public ObserveService getValue(Mapping m, Call call, String name, Class type, Type generic) { - - ObserveService result = null; - if (ObserveService.class.isAssignableFrom(type)) { - - HttpContext httpContext = call.getContext(); - ObserveWebRequestContext requestContext = ObserveWebRequestContext.getRequestContext(httpContext); - result = requestContext.newService(type); - - } - - return result; - - } -} diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationContext.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationContext.java index 1e8dbab..f6fd20c 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationContext.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationContext.java @@ -2,9 +2,11 @@ package fr.ird.observe.application.web; import com.google.common.base.Preconditions; import fr.ird.observe.application.web.configuration.ObserveWebApplicationConfiguration; +import fr.ird.observe.services.ObserveService; import fr.ird.observe.services.ObserveServiceApplicationContext; import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.ObserveServiceMainFactory; +import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; import fr.ird.observe.services.dto.gson.ObserveDtoGsonSupplier; import org.debux.webmotion.server.call.HttpContext; @@ -12,9 +14,9 @@ import javax.servlet.ServletContext; import java.io.Closeable; /** - * @author Tony Chemit : chemit@codelutin.com + * @author Tony Chemit - chemit@codelutin.com */ -public class ObserveWebApplicationContext extends ObserveServiceApplicationContext implements Closeable { +public class ObserveWebApplicationContext implements Closeable { public static final String APPLICATION_CONTEXT_PARAMETER = ObserveWebApplicationContext.class.getName(); @@ -24,11 +26,11 @@ public class ObserveWebApplicationContext extends ObserveServiceApplicationConte protected ObserveDtoGsonSupplier gsonSupplier; - protected ObserveServiceFactory serviceFactory; - protected ObserveWebApplicationConfiguration applicationConfiguration; - protected static ObserveWebApplicationContext getApplicationContext(HttpContext context) { + protected ObserveServiceApplicationContext serviceApplicationContext; + + public static ObserveWebApplicationContext getApplicationContext(HttpContext context) { ServletContext servletContext = context.getServletContext(); ObserveWebApplicationContext result = @@ -47,12 +49,21 @@ public class ObserveWebApplicationContext extends ObserveServiceApplicationConte applicationConfiguration = new ObserveWebApplicationConfiguration(); applicationConfiguration.init(); + // init databases + //TODO + + // init users + //TODO + + // init service application context + serviceApplicationContext = new ObserveServiceApplicationContext(); + serviceApplicationContext.setTemporaryDirectoryRoot(applicationConfiguration.getTemporaryDirectory().toPath()); + serviceApplicationContext.setMainServiceFactory(ObserveServiceMainFactory.get()); + + // init gson supplier boolean devMode = applicationConfiguration.isDevMode(); gsonSupplier = new ObserveDtoGsonSupplier(devMode); - //FIXME Demander a la main factory directement la factory de topia - serviceFactory = ObserveServiceMainFactory.get(); - } @Override @@ -62,12 +73,8 @@ public class ObserveWebApplicationContext extends ObserveServiceApplicationConte //TODO // Fermer l'usine de services - serviceFactory.close(); - - } + serviceApplicationContext.close(); - public ObserveServiceFactory getServiceFactory() { - return serviceFactory; } public ObserveDtoGsonSupplier getGsonSupplier() { @@ -78,4 +85,9 @@ public class ObserveWebApplicationContext extends ObserveServiceApplicationConte return applicationConfiguration; } + public <S extends ObserveService> S newService(ObserveDataSourceConfiguration dataSourceConfiguration, Class<S> serviceType) { + ObserveServiceFactory mainServiceFactory = serviceApplicationContext.getMainServiceFactory(); + return mainServiceFactory.newService(serviceApplicationContext, dataSourceConfiguration, serviceType); + } + } diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationContextInjector.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationContextInjector.java deleted file mode 100644 index f585e23..0000000 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationContextInjector.java +++ /dev/null @@ -1,53 +0,0 @@ -package fr.ird.observe.application.web; - -/* - * #%L - * Pollen :: Rest Api - * %% - * Copyright (C) 2009 - 2014 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 org.debux.webmotion.server.call.Call; -import org.debux.webmotion.server.call.HttpContext; -import org.debux.webmotion.server.handler.ExecutorParametersInjectorHandler; -import org.debux.webmotion.server.mapping.Mapping; - -import java.lang.reflect.Type; - -/** - * Created on 5/23/14. - * - * @author Tony Chemit <chemit@codelutin.com> - * @since 2.0 - */ -public class ObserveWebApplicationContextInjector implements ExecutorParametersInjectorHandler.Injector { - - @Override - public ObserveWebApplicationContext getValue(Mapping m, Call call, String name, Class type, Type generic) { - - ObserveWebApplicationContext result = null; - if (ObserveWebApplicationContext.class.isAssignableFrom(type)) { - - HttpContext httpContext = call.getContext(); - result = ObserveWebApplicationContext.getApplicationContext(httpContext); - - } - - return result; - - } -} diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationListener.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationListener.java index b304cee..10b1c3a 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationListener.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebApplicationListener.java @@ -22,9 +22,6 @@ public class ObserveWebApplicationListener implements WebMotionServerListener { log.info("Initializing " + ObserveWebApplicationListener.class.getName()); } - context.addInjector(new ObserveWebApplicationContextInjector()); - context.addInjector(new ObserveServiceInjector()); - applicationContext = new ObserveWebApplicationContext(); applicationContext.init(); diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebMotionFilter.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebMotionFilter.java index 1b308ec..07d7abe 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebMotionFilter.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebMotionFilter.java @@ -23,9 +23,7 @@ public class ObserveWebMotionFilter extends WebMotionFilter { //TODO Recuperation de la configuration de la data source de la base à partir du token ObserveDataSourceConfiguration dataSourceConfiguration = null; - ObserveWebRequestContext requestContext = new ObserveWebRequestContext(); - requestContext.setWebApplicationContext(applicationContext); - requestContext.setDataSourceConfiguration(dataSourceConfiguration); + ObserveWebRequestContext requestContext = new ObserveWebRequestContext(applicationContext, dataSourceConfiguration); ObserveWebRequestContext.setRequestContext(context, requestContext); diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebRequestContext.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebRequestContext.java index 5418c73..9846742 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebRequestContext.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebRequestContext.java @@ -22,7 +22,6 @@ package fr.ird.observe.application.web; */ import fr.ird.observe.services.ObserveService; -import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; import org.debux.webmotion.server.call.HttpContext; @@ -34,43 +33,32 @@ import org.debux.webmotion.server.call.HttpContext; */ public class ObserveWebRequestContext { - protected static final String REQUEST_POLLEN_REQUEST_CONTEXT = ObserveWebRequestContext.class.getName(); + protected static final String REQUEST_OBSERVE_WEB_REQUEST_CONTEXT = ObserveWebRequestContext.class.getName(); public static ObserveWebRequestContext getRequestContext(HttpContext httpContext) { ObserveWebRequestContext result = (ObserveWebRequestContext) - httpContext.getRequest().getAttribute(REQUEST_POLLEN_REQUEST_CONTEXT); + httpContext.getRequest().getAttribute(REQUEST_OBSERVE_WEB_REQUEST_CONTEXT); return result; } public static void setRequestContext(HttpContext httpContext, ObserveWebRequestContext serviceContext) { - httpContext.getRequest().setAttribute(REQUEST_POLLEN_REQUEST_CONTEXT, serviceContext); + httpContext.getRequest().setAttribute(REQUEST_OBSERVE_WEB_REQUEST_CONTEXT, serviceContext); } - protected ObserveWebApplicationContext webApplicationContext; + protected final ObserveWebApplicationContext webApplicationContext; - protected ObserveDataSourceConfiguration dataSourceConfiguration; + protected final ObserveDataSourceConfiguration dataSourceConfiguration; - public ObserveWebApplicationContext getWebApplicationContext() { - return webApplicationContext; - } - - public ObserveDataSourceConfiguration getDataSourceConfiguration() { - return dataSourceConfiguration; - } - - public void setWebApplicationContext(ObserveWebApplicationContext webApplicationContext) { + public ObserveWebRequestContext(ObserveWebApplicationContext webApplicationContext, + ObserveDataSourceConfiguration dataSourceConfiguration) { this.webApplicationContext = webApplicationContext; - } - - public void setDataSourceConfiguration(ObserveDataSourceConfiguration dataSourceConfiguration) { this.dataSourceConfiguration = dataSourceConfiguration; } public <S extends ObserveService> S newService(Class<S> serviceType) { - ObserveServiceFactory serviceFactory = webApplicationContext.getServiceFactory(); - S service = serviceFactory.newService(webApplicationContext, dataSourceConfiguration, serviceType); + S service = webApplicationContext.newService(dataSourceConfiguration, serviceType); return service; } diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/ObserveWebMotionController.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/ObserveWebMotionController.java index 7e31748..1844495 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/ObserveWebMotionController.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/ObserveWebMotionController.java @@ -1,11 +1,27 @@ package fr.ird.observe.application.web.controller; +import fr.ird.observe.application.web.ObserveWebApplicationContext; +import fr.ird.observe.application.web.ObserveWebRequestContext; +import fr.ird.observe.application.web.configuration.ObserveWebApplicationConfiguration; import fr.ird.observe.services.ObserveService; import org.debux.webmotion.server.WebMotionController; /** * @author Tony Chemit : chemit@codelutin.com */ -public abstract class ObserveWebMotionController extends WebMotionController implements ObserveService { +public abstract class ObserveWebMotionController extends WebMotionController { + public ObserveWebApplicationContext getObserveWebApplicationContext() { + return ObserveWebApplicationContext.getApplicationContext(getContext()); + } + + public ObserveWebApplicationConfiguration getObserveWebApplicationConfiguration() { + return getObserveWebApplicationContext().getApplicationConfiguration(); + } + + public <S extends ObserveService> S newService(Class<S> serviceType) { + ObserveWebRequestContext requestContext = ObserveWebRequestContext.getRequestContext(getContext()); + S service = requestContext.newService(serviceType); + return service; + } } diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/DocController.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/DocController.java index 821819b..168d6f2 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/DocController.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/DocController.java @@ -1,8 +1,7 @@ package fr.ird.observe.application.web.controller.v1; -import fr.ird.observe.application.web.ObserveWebApplicationContext; +import fr.ird.observe.application.web.controller.ObserveWebMotionController; import org.apache.commons.io.IOUtils; -import org.debux.webmotion.server.WebMotionController; import org.debux.webmotion.server.render.Render; import java.io.IOException; @@ -13,7 +12,7 @@ import java.io.InputStream; * * @author Tony Chemit - chemit@codelutin.com */ -public class DocController extends WebMotionController { +public class DocController extends ObserveWebMotionController { public Render mapping() { @@ -32,9 +31,9 @@ public class DocController extends WebMotionController { } - public Render configuration(ObserveWebApplicationContext applicationContext) { + public Render configuration() { - String content = applicationContext.getApplicationConfiguration().getConfigurationDescription(); + String content = getObserveWebApplicationConfiguration().getConfigurationDescription(); return renderContent(content, "text/plain"); } diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java index df59b76..35c8541 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java @@ -8,6 +8,7 @@ import fr.ird.observe.services.dto.referential.ReferentialDto; import fr.ird.observe.services.service.DataNotFoundException; import fr.ird.observe.services.service.ReferentialService; import fr.ird.observe.services.spi.Write; +import org.debux.webmotion.server.WebMotionContextable; import java.util.Collection; @@ -18,9 +19,14 @@ import java.util.Collection; */ public class ReferentialServiceController extends ObserveWebMotionController implements ReferentialService { - //TODO A injecter protected ReferentialService referentialService; - + + @Override + public void setContextable(WebMotionContextable contextable) { + super.setContextable(contextable); + referentialService = newService(ReferentialService.class); + } + @Override public <R extends ReferentialDto> ReferenceSetDto<R> getReferentialReferenceSet(Class<R> type) { return referentialService.getReferentialReferenceSet(type); diff --git a/observe-application-web/src/main/resources/mapping b/observe-application-web/src/main/resources/mapping index 51e97da..860c553 100644 --- a/observe-application-web/src/main/resources/mapping +++ b/observe-application-web/src/main/resources/mapping @@ -2,7 +2,7 @@ # #%L # ObServe :: Web Application # %% -# Copyright (C) 2008 - 2010 IRD, Codelutin, Tony Chemit +# Copyright (C) 2015 IRD, Codelutin, Tony Chemit # %% # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as @@ -21,9 +21,9 @@ ### # -# Application Version ${project.version} -# Build Date ${buildDate} -# Build Number ${buildNumber} +# Build version ${project.version} +# Build date ${buildDate} +# Build number ${buildNumber} # [config] diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceApplicationContext.java b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceApplicationContext.java index a25b1e7..791dbc4 100644 --- a/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceApplicationContext.java +++ b/observe-services-api/src/main/java/fr/ird/observe/services/ObserveServiceApplicationContext.java @@ -2,6 +2,7 @@ package fr.ird.observe.services; import fr.ird.observe.services.dto.constants.ReferentialLocale; +import java.io.Closeable; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -17,7 +18,7 @@ import java.util.Set; * * @author Tony Chemit - chemit@codelutin.com */ -public class ObserveServiceApplicationContext { +public class ObserveServiceApplicationContext implements Closeable { /** * FIXME peut-être pas le bon endroit, car la locale est en scope request. @@ -25,6 +26,7 @@ public class ObserveServiceApplicationContext { * La locale de l'application. */ protected Locale applicationLocale; + /** * La locale du référentiel. */ @@ -68,14 +70,23 @@ public class ObserveServiceApplicationContext { this.temporaryDirectoryRoot = temporaryDirectoryRoot; } - public File createTemporaryDirectory(String prefix) { + public File createTemporaryDirectory(String prefix) { Set<PosixFilePermission> posixFilePermissions = PosixFilePermissions.fromString("rwxr-x---"); FileAttribute<Set<PosixFilePermission>> fileAttribute = PosixFilePermissions.asFileAttribute(posixFilePermissions); try { return Files.createTempDirectory(temporaryDirectoryRoot, prefix, fileAttribute).toFile(); } catch (IOException e) { //TODO Avoir une exception plus concrete - throw new RuntimeException("Could not create temporary directory with preifx: "+prefix,e); + throw new RuntimeException("Could not create temporary directory with preifx: " + prefix, e); + } + } + + @Override + public void close() { + + if (mainServiceFactory != null) { + mainServiceFactory.close(); } + } } -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@list.forge.codelutin.com>.
participants (1)
-
codelutin.com scm