branch develop updated (b6e205a -> 2ec3a0b)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository observe. See http://git.codelutin.com/observe.git from b6e205a Allez! tout sur develop! Merge branch 'feature/7463' into develop new ea3b474 Corrige le build (scopes et noms des modules changés) new 1391c81 Debut de travail sur la partie serveur new 2ec3a0b Ajout Service pour gérer une data source The 3 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 2ec3a0b9194fb1890cda1fb278de9ba1689b6c0b Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 21 10:51:11 2015 +0200 Ajout Service pour gérer une data source commit 1391c8136e6c7267f2451ac77b346f1ed29c3ef8 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 21 10:50:28 2015 +0200 Debut de travail sur la partie serveur commit ea3b47410e0171d09a220467689df7f7df6dce51 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Aug 21 10:50:06 2015 +0200 Corrige le build (scopes et noms des modules changés) Summary of changes: .../application/web/ObserveServiceInjector.java | 55 ++++++++++++++++ .../web/ObserveWebApplicationContext.java | 12 +++- .../web/ObserveWebApplicationListener.java | 24 +++---- .../application/web/ObserveWebMotionFilter.java | 33 +++------- .../application/web/ObserveWebMotionRender.java | 5 +- .../application/web/ObserveWebRequestContext.java | 77 ++++++++++++++++++++++ .../{ => v1}/ReferentialServiceController.java | 3 +- observe-application-web/src/main/resources/mapping | 7 +- .../services/service/DataSourceService.java | 24 +++++++ .../services/dto/gson/ObserveDtoGsonSupplier.java | 53 ++++++++------- observe-services-runner/pom.xml | 8 +-- 11 files changed, 232 insertions(+), 69 deletions(-) create mode 100644 observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveServiceInjector.java create mode 100644 observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebRequestContext.java rename observe-application-web/src/main/java/fr/ird/observe/application/web/controller/{ => v1}/ReferentialServiceController.java (94%) create mode 100644 observe-services-api/src/main/java/fr/ird/observe/services/service/DataSourceService.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 develop in repository observe. See http://git.codelutin.com/observe.git commit ea3b47410e0171d09a220467689df7f7df6dce51 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Aug 21 10:50:06 2015 +0200 Corrige le build (scopes et noms des modules changés) --- observe-services-runner/pom.xml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/observe-services-runner/pom.xml b/observe-services-runner/pom.xml index 354853d..a110705 100644 --- a/observe-services-runner/pom.xml +++ b/observe-services-runner/pom.xml @@ -35,19 +35,17 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>observe-services-configuration-rest-client</artifactId> + <artifactId>observe-services-configuration-rest</artifactId> <version>${project.version}</version> - <scope>runtime</scope> </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>observe-services-rest-client</artifactId> + <artifactId>observe-services-configuration-topia</artifactId> <version>${project.version}</version> - <scope>runtime</scope> </dependency> <dependency> <groupId>${project.groupId}</groupId> - <artifactId>observe-services-configuration-topia</artifactId> + <artifactId>observe-services-rest</artifactId> <version>${project.version}</version> <scope>runtime</scope> </dependency> -- 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 develop in repository observe. See http://git.codelutin.com/observe.git commit 1391c8136e6c7267f2451ac77b346f1ed29c3ef8 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 21 10:50:28 2015 +0200 Debut de travail sur la partie serveur --- .../application/web/ObserveServiceInjector.java | 55 ++++++++++++++++ .../web/ObserveWebApplicationContext.java | 12 +++- .../web/ObserveWebApplicationListener.java | 24 +++---- .../application/web/ObserveWebMotionFilter.java | 33 +++------- .../application/web/ObserveWebMotionRender.java | 5 +- .../application/web/ObserveWebRequestContext.java | 77 ++++++++++++++++++++++ .../{ => v1}/ReferentialServiceController.java | 3 +- observe-application-web/src/main/resources/mapping | 7 +- .../services/dto/gson/ObserveDtoGsonSupplier.java | 53 ++++++++------- 9 files changed, 205 insertions(+), 64 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 new file mode 100644 index 0000000..63de3be --- /dev/null +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveServiceInjector.java @@ -0,0 +1,55 @@ +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 4feff7c..cd39ff0 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 @@ -1,8 +1,10 @@ package fr.ird.observe.application.web; import com.google.common.base.Preconditions; +import fr.ird.observe.services.ObserveServiceApplicationContext; import fr.ird.observe.services.ObserveServiceFactory; import fr.ird.observe.services.ObserveServiceMainFactory; +import fr.ird.observe.services.dto.gson.ObserveDtoGsonSupplier; import org.debux.webmotion.server.call.HttpContext; import javax.servlet.ServletContext; @@ -10,7 +12,7 @@ import javax.servlet.ServletContext; /** * @author Tony Chemit : chemit@codelutin.com */ -public class ObserveWebApplicationContext { +public class ObserveWebApplicationContext extends ObserveServiceApplicationContext { public static final String APPLICATION_CONTEXT_PARAMETER = ObserveWebApplicationContext.class.getName(); @@ -18,6 +20,8 @@ public class ObserveWebApplicationContext { ObserveWebApplicationContext.class.getSimpleName() + " not found. You probably forgot to" + " register " + ObserveWebApplicationListener.class.getName() + " in your web.xml"; + protected ObserveDtoGsonSupplier gsonSupplier; + protected ObserveServiceFactory serviceFactory; protected static ObserveWebApplicationContext getApplicationContext(HttpContext context) { @@ -39,6 +43,8 @@ public class ObserveWebApplicationContext { public void init() { + gsonSupplier = new ObserveDtoGsonSupplier(); + //FIXME Demander a la main factory directement la factory de topia serviceFactory = ObserveServiceMainFactory.get(); @@ -72,4 +78,8 @@ public class ObserveWebApplicationContext { public ObserveServiceFactory getServiceFactory() { return serviceFactory; } + + public ObserveDtoGsonSupplier getGsonSupplier() { + return gsonSupplier; + } } 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 c1dd564..52f984d 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 @@ -2,41 +2,43 @@ package fr.ird.observe.application.web; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; +import org.debux.webmotion.server.WebMotionServerListener; +import org.debux.webmotion.server.call.ServerContext; +import org.debux.webmotion.server.mapping.Mapping; /** * @author Tony Chemit : chemit@codelutin.com */ -public class ObserveWebApplicationListener implements ServletContextListener { +public class ObserveWebApplicationListener implements WebMotionServerListener { private static final Log log = LogFactory.getLog(ObserveWebApplicationListener.class); - protected ObserveWebApplicationContext context; + protected ObserveWebApplicationContext applicationContext; @Override - public void contextInitialized(ServletContextEvent sce) { + public void onStart(Mapping mapping, ServerContext context) { + if (log.isInfoEnabled()) { log.info("Initializing " + ObserveWebApplicationListener.class.getName()); } - context = new ObserveWebApplicationContext(); - context.init(); + applicationContext = new ObserveWebApplicationContext(); + applicationContext.init(); - sce.getServletContext().setAttribute(ObserveWebApplicationContext.APPLICATION_CONTEXT_PARAMETER, context); + context.addInjector(new ObserveServiceInjector()); } @Override - public void contextDestroyed(ServletContextEvent sce) { + public void onStop(ServerContext context) { if (log.isInfoEnabled()) { log.info("Destroying " + ObserveWebApplicationListener.class.getName()); } - context.close(); + applicationContext.close(); + } } 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 4ed6d67..1b308ec 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 @@ -1,5 +1,6 @@ package fr.ird.observe.application.web; +import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; import org.debux.webmotion.server.WebMotionFilter; import org.debux.webmotion.server.call.HttpContext; @@ -10,21 +11,8 @@ import javax.servlet.http.HttpServletRequest; */ public class ObserveWebMotionFilter extends WebMotionFilter { -// protected ObserveTopiaPersistenceContext getTopiaContext(HttpContext context) { -// HttpServletRequest servletRequest = context.getRequest(); -// ObserveTopiaPersistenceContext result = (ObserveTopiaPersistenceContext) -// servletRequest -// .getAttribute(TopiaTransactionFilter.TOPIA_TRANSACTION_REQUEST_ATTRIBUTE); -// -// Preconditions.checkState(result != null, "TopiaContext not available"); -// -// return result; -// } - public void inject(HttpContext context) { -// final ObserveTopiaPersistenceContext persistenceContext = getTopiaContext(context); - ObserveWebApplicationContext applicationContext = ObserveWebApplicationContext.getApplicationContext(context); @@ -32,22 +20,17 @@ public class ObserveWebMotionFilter extends WebMotionFilter { String authenticationToken = request.getHeader("authenticationToken"); - //TODO Recuperation de la configuration de la base à partir du token + //TODO Recuperation de la configuration de la data source de la base à partir du token + ObserveDataSourceConfiguration dataSourceConfiguration = null; - //TODO En déduire la ser + ObserveWebRequestContext requestContext = new ObserveWebRequestContext(); + requestContext.setWebApplicationContext(applicationContext); + requestContext.setDataSourceConfiguration(dataSourceConfiguration); -// DefaultServiceContext serviceContext = new DefaultServiceContext(applicationContext.getServiceConfig(), new Supplier<ObserveTopiaPersistenceContext>() { -// @Override -// public ObserveTopiaPersistenceContext get() { -// return persistenceContext; -// } -// }, authenticationToken); -// -// ServiceFactory serviceFactory = serviceContext.getServiceFactory(); -// request.setAttribute("serviceFactory", serviceFactory); + ObserveWebRequestContext.setRequestContext(context, requestContext); doProcess(); - } + } } diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebMotionRender.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebMotionRender.java index 8c54993..f50f873 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebMotionRender.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebMotionRender.java @@ -1,5 +1,6 @@ package fr.ird.observe.application.web; +import com.google.gson.Gson; import org.debux.webmotion.server.call.Call; import org.debux.webmotion.server.call.HttpContext; import org.debux.webmotion.server.mapping.Mapping; @@ -41,7 +42,9 @@ public class ObserveWebMotionRender<T> extends Render { boolean devMode = applicationContext.isDevMode(); - ObserveWebMotionJsonHelper gson = new ObserveWebMotionJsonHelper(devMode); + applicationContext.getGsonSupplier(); + + Gson gson = applicationContext.getGsonSupplier().get(); String json = gson.toJson(model); PrintWriter out = context.getOut(); 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 new file mode 100644 index 0000000..5418c73 --- /dev/null +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/ObserveWebRequestContext.java @@ -0,0 +1,77 @@ +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 fr.ird.observe.services.ObserveServiceFactory; +import fr.ird.observe.services.configuration.ObserveDataSourceConfiguration; +import org.debux.webmotion.server.call.HttpContext; + +/** + * Created on 4/25/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 2.0 + */ +public class ObserveWebRequestContext { + + protected static final String REQUEST_POLLEN_REQUEST_CONTEXT = ObserveWebRequestContext.class.getName(); + + public static ObserveWebRequestContext getRequestContext(HttpContext httpContext) { + + ObserveWebRequestContext result = (ObserveWebRequestContext) + httpContext.getRequest().getAttribute(REQUEST_POLLEN_REQUEST_CONTEXT); + return result; + } + + public static void setRequestContext(HttpContext httpContext, + ObserveWebRequestContext serviceContext) { + httpContext.getRequest().setAttribute(REQUEST_POLLEN_REQUEST_CONTEXT, serviceContext); + } + + protected ObserveWebApplicationContext webApplicationContext; + + protected ObserveDataSourceConfiguration dataSourceConfiguration; + + public ObserveWebApplicationContext getWebApplicationContext() { + return webApplicationContext; + } + + public ObserveDataSourceConfiguration getDataSourceConfiguration() { + return dataSourceConfiguration; + } + + public void setWebApplicationContext(ObserveWebApplicationContext webApplicationContext) { + 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); + return service; + } + +} diff --git a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/ReferentialServiceController.java b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java similarity index 94% rename from observe-application-web/src/main/java/fr/ird/observe/application/web/controller/ReferentialServiceController.java rename to observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java index ab9b4c8..df59b76 100644 --- a/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/ReferentialServiceController.java +++ b/observe-application-web/src/main/java/fr/ird/observe/application/web/controller/v1/ReferentialServiceController.java @@ -1,5 +1,6 @@ -package fr.ird.observe.application.web.controller; +package fr.ird.observe.application.web.controller.v1; +import fr.ird.observe.application.web.controller.ObserveWebMotionController; import fr.ird.observe.services.ObserveServiceContext; import fr.ird.observe.services.dto.FormDto; import fr.ird.observe.services.dto.ReferenceSetDto; diff --git a/observe-application-web/src/main/resources/mapping b/observe-application-web/src/main/resources/mapping index 03d0384..0aa5db6 100644 --- a/observe-application-web/src/main/resources/mapping +++ b/observe-application-web/src/main/resources/mapping @@ -1,11 +1,14 @@ [config] package.base=fr.ird.observe.application.web.controller -default.render=fr.ird.observe.application.web.ObserveWebMotionRender +package.actions=fr.ird.observe.application.web.controller.v1 +package.errors=fr.ird.observe.application.web.controller.v1 + server.controller.scope=request server.listener.class=fr.ird.observe.services.rest.wm.ObserveServerListener +default.render=fr.ird.observe.application.web.ObserveWebMotionRender [filters] -* /* fr.ird.observe.application.web.ObserveWebMotionFilter.inject +* /* ObserveWebMotionFilter.inject [actions] GET,POST /api/v1/referential/{method} action:ReferentialServiceController.{method} diff --git a/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ObserveDtoGsonSupplier.java b/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ObserveDtoGsonSupplier.java index 453f6db..0904065 100644 --- a/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ObserveDtoGsonSupplier.java +++ b/observe-services-model/src/main/java/fr/ird/observe/services/dto/gson/ObserveDtoGsonSupplier.java @@ -13,40 +13,47 @@ import java.util.Date; */ public class ObserveDtoGsonSupplier implements Supplier<Gson> { - public static final Supplier<GsonBuilder> GSON_BUILDER_SUPPLIER = new Supplier<GsonBuilder>() { + protected GsonBuilder gsonBuilder; - @Override - public GsonBuilder get() { - GsonBuilder result = new GsonBuilder(); - - // Type adapters : base types - result.registerTypeAdapter(Integer.class, new IntegerAdapter()); - result.registerTypeAdapter(Date.class, new DateAdapter()); - result.registerTypeAdapter(Timestamp.class, new DateAdapter()); - result.registerTypeAdapter(java.sql.Date.class, new DateAdapter()); - - return result; - } - }; - - protected static GsonBuilder gsonBuilder; + protected final boolean prettyPrint; protected Gson gson; - protected static GsonBuilder getGsonBuilder() { - if (gsonBuilder == null) { - // Assign only when initialization is finished to be thread-safe - gsonBuilder = GSON_BUILDER_SUPPLIER.get(); - } - return gsonBuilder; + public ObserveDtoGsonSupplier() { + this(false); + } + + public ObserveDtoGsonSupplier(boolean prettyPrint) { + this.prettyPrint = prettyPrint; } @Override public Gson get() { if (gson == null) { - gson = getGsonBuilder().create(); + gson = getGsonBuilder(prettyPrint).create(); } return gson; } + protected GsonBuilder getGsonBuilder(boolean prettyPrint) { + + if (gsonBuilder == null) { + + // Assign only when initialization is finished to be thread-safe + gsonBuilder = new GsonBuilder(); + + if (prettyPrint) { + gsonBuilder.setPrettyPrinting(); + } + // Type adapters : base types + gsonBuilder.registerTypeAdapter(Integer.class, new IntegerAdapter()); + gsonBuilder.registerTypeAdapter(Date.class, new DateAdapter()); + gsonBuilder.registerTypeAdapter(Timestamp.class, new DateAdapter()); + gsonBuilder.registerTypeAdapter(java.sql.Date.class, new DateAdapter()); + + } + return gsonBuilder; + + } + } -- 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 develop in repository observe. See http://git.codelutin.com/observe.git commit 2ec3a0b9194fb1890cda1fb278de9ba1689b6c0b Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Aug 21 10:51:11 2015 +0200 Ajout Service pour gérer une data source --- .../services/service/DataSourceService.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/observe-services-api/src/main/java/fr/ird/observe/services/service/DataSourceService.java b/observe-services-api/src/main/java/fr/ird/observe/services/service/DataSourceService.java new file mode 100644 index 0000000..dac2dc6 --- /dev/null +++ b/observe-services-api/src/main/java/fr/ird/observe/services/service/DataSourceService.java @@ -0,0 +1,24 @@ +package fr.ird.observe.services.service; + +import fr.ird.observe.services.ObserveService; + +/** + * Created on 21/08/15. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public interface DataSourceService extends ObserveService { + + boolean exist(); + + void create(); + + void open(); + + void close(); + + boolean canConnect(); + + void destroy(); + +} -- 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