This is an automated email from the git hooks/post-receive script. New commit to branch feature/spgeed in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit 9b7a621c5926f58b8f2dbd6846bef97311836b1a Author: HERBRETEAU Killian <Killian_H@localhost.localdomain> Date: Mon Jul 22 14:34:12 2019 +0200 Creating PollenSpgeedUserDAO + @Path -> Spgeed --- pollen-persistence/pom.xml | 16 +++++ .../chorem/pollen/persistence/PollenConfig.java | 72 ++++++++++++++++++++++ .../PollenSpgeedApplicationContext.java | 59 ++++++++++++++++++ .../pollen/persistence/PollenUserSpgeedDao.java | 13 ++++ pollen-rest-api/pom.xml | 1 - .../rest/api/PollenRestApiApplicationContext.java | 34 ++++++++-- .../rest/api/PollenRestApiRequestFilter.java | 2 +- .../chorem/pollen/rest/api/v1/TransverseApi.java | 9 +++ .../pollen/services/PollenApplicationContext.java | 3 + .../services/config/PollenServicesConfig.java | 11 ++++ .../pollen/services/service/TransverseService.java | 12 ++++ .../service/security/SpgeedDummyService.java | 65 +++++++++++++++++++ .../test/FakePollenApplicationContext.java | 6 ++ pom.xml | 16 +++++ 14 files changed, 313 insertions(+), 6 deletions(-) diff --git a/pollen-persistence/pom.xml b/pollen-persistence/pom.xml index c13d3b37..de373136 100644 --- a/pollen-persistence/pom.xml +++ b/pollen-persistence/pom.xml @@ -38,6 +38,17 @@ <dependencies> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-config</artifactId> + <version>3.3</version> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>spgeed</artifactId> + </dependency> + <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> @@ -73,6 +84,11 @@ <artifactId>hibernate-core</artifactId> </dependency> + <dependency> + <groupId>org.postgresql</groupId> + <artifactId>postgresql</artifactId> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenConfig.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenConfig.java new file mode 100644 index 00000000..73e91e54 --- /dev/null +++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenConfig.java @@ -0,0 +1,72 @@ +package org.chorem.pollen.persistence; + +/* + * #%L + * Pollen :: Persistence + * %% + * Copyright (C) 2009 - 2017 Code Lutin, Tony Chemit + * %% + * 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.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.config.ApplicationConfig; +import org.nuiton.config.ArgumentsParserException; + +/** + * Created by couteau on 27/01/17. + */ +public class PollenConfig { + + final static private Log log = LogFactory.getLog(PollenConfig.class); + + protected static PollenConfig instance = new PollenConfig(); + + public static PollenConfig get() { + return instance; + } + + protected ApplicationConfig config; + + protected PollenConfig() { + ApplicationConfig configDefault = new ApplicationConfig("pollen.properties"); + try { + configDefault.parse(); + } catch (ArgumentsParserException e) { + log.error("Parse config error", e); + } + + this.config = new ApplicationConfig(configDefault.getFlatOptions(), "pollen-test.properties"); + try { + this.config.parse(); + } catch (ArgumentsParserException e) { + log.error("Parse config error", e); + } + } + + public String getDataSourceUrl() { + return this.config.getOption("pollen.datasource.url"); + } + + public String getDataSourceUser() { + return this.config.getOption("pollen.datasource.user"); + } + + public String getDataSourcePassword() { + return this.config.getOption("pollen.datasource.password"); + } + +} diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenSpgeedApplicationContext.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenSpgeedApplicationContext.java new file mode 100644 index 00000000..7d61e2f2 --- /dev/null +++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenSpgeedApplicationContext.java @@ -0,0 +1,59 @@ +package org.chorem.pollen.persistence; + +/* + * #%L + * Pollen :: Persistence + * %% + * Copyright (C) 2009 - 2017 Code Lutin, Tony Chemit + * %% + * 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 javax.sql.DataSource; +import org.postgresql.ds.PGSimpleDataSource; + +public class PollenSpgeedApplicationContext { + + protected DataSource dataSource; + + protected PGSimpleDataSource ds; + + public DataSource getDataSource() { + if (this.dataSource == null) { + PollenConfig Config = PollenConfig.get(); + PGSimpleDataSource ds = new PGSimpleDataSource(); + + ds.setUrl(Config.getDataSourceUrl()); + ds.setUser(Config.getDataSourceUser()); + ds.setPassword(Config.getDataSourcePassword()); + this.dataSource = ds; + } + return (dataSource); + } + + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } + + public void setDataSource(String url, String password, String user) { + if (this.ds == null) { + this.ds = new PGSimpleDataSource(); + } + this.ds.setUser(user); + this.ds.setPassword(password); + this.ds.setUrl(url); + this.dataSource = this.ds; + } +} \ No newline at end of file diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenUserSpgeedDao.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenUserSpgeedDao.java new file mode 100644 index 00000000..691de8d8 --- /dev/null +++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/PollenUserSpgeedDao.java @@ -0,0 +1,13 @@ +package org.chorem.pollen.persistence; + +import org.chorem.pollen.persistence.entity.PollenUserImpl; +import org.nuiton.spgeed.annotations.Select; + +public interface PollenUserSpgeedDao { + + @Select(sql = "SELECT json_agg(pollenuser.*) FROM PollenUser JOIN pollenuseremailaddress ON (PollenUser.topiaId = pollenuseremailaddress.pollenuser)") + PollenUserImpl getUser(); + + @Select(sql = "SELECT count(*) FROM PollenUser") + int getUserCount(); +} \ No newline at end of file diff --git a/pollen-rest-api/pom.xml b/pollen-rest-api/pom.xml index 75c62f34..f1929532 100644 --- a/pollen-rest-api/pom.xml +++ b/pollen-rest-api/pom.xml @@ -241,7 +241,6 @@ <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> - <scope>runtime</scope> </dependency> <dependency> diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java index 3d07f18f..4671d566 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiApplicationContext.java @@ -26,9 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.LogManager; import org.apache.log4j.PropertyConfigurator; -import org.chorem.pollen.persistence.PollenPersistenceContext; -import org.chorem.pollen.persistence.PollenTopiaApplicationContext; -import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; +import org.chorem.pollen.persistence.*; import org.chorem.pollen.persistence.entity.PollenPrincipal; import org.chorem.pollen.persistence.entity.PollenUser; import org.chorem.pollen.services.DefaultPollenServiceContext; @@ -72,12 +70,18 @@ public class PollenRestApiApplicationContext implements PollenApplicationContext PollenServicesConfig applicationConfig = new PollenServicesConfig("pollen-rest-api.properties"); + PollenSpgeedApplicationContext pollenSpgeedApplicationContext = new PollenSpgeedApplicationContext(); + Map<String, String> topiaProperties = applicationConfig.getTopiaProperties(); BeanTopiaConfiguration topiaConfiguration = new TopiaConfigurationBuilder().readMap(topiaProperties); + PollenTopiaApplicationContext pollenTopiaApplicationContext = new PollenTopiaApplicationContext(topiaConfiguration); - applicationContext = new PollenRestApiApplicationContext(applicationConfig, pollenTopiaApplicationContext); + applicationContext = new PollenRestApiApplicationContext( + applicationConfig, + pollenTopiaApplicationContext, + pollenSpgeedApplicationContext); applicationContext.init(); } @@ -104,6 +108,8 @@ public class PollenRestApiApplicationContext implements PollenApplicationContext protected final PollenTopiaApplicationContext topiaApplicationContext; + protected PollenSpgeedApplicationContext spgeedApplicationContext; + protected final PollenServicesConfig applicationConfig; protected VoteCountingFactory voteCountingFactory; @@ -119,6 +125,21 @@ public class PollenRestApiApplicationContext implements PollenApplicationContext this.closed = new AtomicBoolean(false); } + protected PollenRestApiApplicationContext(PollenServicesConfig applicationConfig, + PollenTopiaApplicationContext topiaApplicationContext, + PollenSpgeedApplicationContext spgeedApplicationContext) { + + Preconditions.checkNotNull(applicationConfig, "Configuration can not be null!"); + Preconditions.checkNotNull(topiaApplicationContext, "topiaApplicationContext can not be null!"); + Preconditions.checkNotNull(spgeedApplicationContext, "spgeedApplicationContext can not be null!"); + + this.applicationConfig = applicationConfig; + this.topiaApplicationContext = topiaApplicationContext; + this.spgeedApplicationContext = spgeedApplicationContext; + this.started = new AtomicBoolean(false); + this.closed = new AtomicBoolean(false); + } + @Override public PollenTopiaApplicationContext getTopiaApplicationContext() { return topiaApplicationContext; @@ -129,6 +150,11 @@ public class PollenRestApiApplicationContext implements PollenApplicationContext return applicationConfig; } + @Override + public PollenSpgeedApplicationContext getSpgeedDataSource() { + return spgeedApplicationContext; + } + @Override public VoteCountingFactory getVoteCountingFactory() { diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java index ce6e30b6..1804c4e4 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/PollenRestApiRequestFilter.java @@ -62,6 +62,7 @@ import org.chorem.pollen.services.service.security.SecurityService; import org.jboss.resteasy.spi.ResteasyProviderFactory; import javax.servlet.http.HttpServletRequest; +import javax.sql.DataSource; import javax.ws.rs.HttpMethod; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; @@ -233,7 +234,6 @@ public class PollenRestApiRequestFilter implements ContainerRequestFilter, Conta ResteasyProviderFactory.pushContext(PollenServiceContext.class, serviceContext); - PollenSecurityContext securityContext = createSecurityContext(context, applicationContext, serviceContext); serviceContext.setSecurityContext(securityContext); ResteasyProviderFactory.pushContext(PollenSecurityContext.class, securityContext); diff --git a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/TransverseApi.java b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/TransverseApi.java index 470fa9f3..5682a86c 100644 --- a/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/TransverseApi.java +++ b/pollen-rest-api/src/main/java/org/chorem/pollen/rest/api/v1/TransverseApi.java @@ -23,6 +23,7 @@ package org.chorem.pollen.rest.api.v1; import org.chorem.pollen.services.bean.ConfigurationBean; import org.chorem.pollen.services.bean.PollenStatus; +import org.chorem.pollen.services.bean.PollenUserBean; import org.chorem.pollen.services.service.TransverseService; import javax.ws.rs.Consumes; @@ -56,5 +57,13 @@ public class TransverseApi { } + @Path("/spgeed") + @GET + public PollenUserBean getSpgeed(@Context TransverseService transverseService) { + + return transverseService.getSpgeed(); + + } + } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/PollenApplicationContext.java b/pollen-services/src/main/java/org/chorem/pollen/services/PollenApplicationContext.java index 0cde7f7a..db7ad59e 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/PollenApplicationContext.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/PollenApplicationContext.java @@ -22,6 +22,7 @@ package org.chorem.pollen.services; */ import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.PollenSpgeedApplicationContext; import org.chorem.pollen.persistence.PollenTopiaApplicationContext; import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.persistence.entity.PollenPrincipal; @@ -45,6 +46,8 @@ public interface PollenApplicationContext extends Closeable { PollenServicesConfig getApplicationConfig(); + PollenSpgeedApplicationContext getSpgeedDataSource(); + VoteCountingFactory getVoteCountingFactory(); PollenTopiaPersistenceContext newPersistenceContext(); diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServicesConfig.java b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServicesConfig.java index b19988dc..0e991fa2 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServicesConfig.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/config/PollenServicesConfig.java @@ -179,4 +179,15 @@ public class PollenServicesConfig extends GeneratedPollenServicesConfig { return Base64.getDecoder().decode(secret); } + public String getDataSourceUrl() { + return get().getOption("hibernate.connection.url"); + } + + public String getDataSourcePassword() { + return get().getOption("hibernate.connection.password"); + } + + public String getDataSourceUser() { + return get().getOption("hibernate.connection.username"); + } } diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/TransverseService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/TransverseService.java index d2bd4ba9..f78594f6 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/TransverseService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/TransverseService.java @@ -24,9 +24,12 @@ package org.chorem.pollen.services.service; import com.google.common.collect.Lists; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.pollen.persistence.entity.PollenUser; import org.chorem.pollen.services.UnitHuman; import org.chorem.pollen.services.bean.ConfigurationBean; import org.chorem.pollen.services.bean.PollenStatus; +import org.chorem.pollen.services.bean.PollenUserBean; +import org.chorem.pollen.services.service.security.SpgeedDummyService; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; @@ -47,6 +50,15 @@ public class TransverseService extends PollenServiceSupport { return bean; } + public PollenUserBean getSpgeed() { + + SpgeedDummyService spgeedDummyService = new SpgeedDummyService(); + PollenUser user = spgeedDummyService.getPollenUser(); + PollenUserService pollenUserService = newService(PollenUserService.class); + + return pollenUserService.toPollenUserBean(user); + } + public PollenStatus getStatus() { long statusStart = System.currentTimeMillis(); List<String> errors = Lists.newArrayList(); diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SpgeedDummyService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SpgeedDummyService.java new file mode 100644 index 00000000..f4c43df5 --- /dev/null +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/security/SpgeedDummyService.java @@ -0,0 +1,65 @@ +package org.chorem.pollen.services.service.security; + +import org.chorem.pollen.persistence.PollenSpgeedApplicationContext; +import org.chorem.pollen.persistence.PollenUserSpgeedDao; +import org.chorem.pollen.persistence.entity.PollenUserImpl; +import org.chorem.pollen.services.config.PollenServicesConfig; +import org.nuiton.spgeed.SqlSession; +import org.chorem.pollen.persistence.entity.PollenUser; + +import javax.sql.DataSource; +import java.sql.SQLException; + +public class SpgeedDummyService { + + public PollenUser getPollenUser() { + + PollenSpgeedApplicationContext pollenSpgeedApplicationContext = new PollenSpgeedApplicationContext(); + + PollenServicesConfig pollenServicesConfig = new PollenServicesConfig("pollen-rest-api.properties"); + + String dburl = pollenServicesConfig.getDataSourceUrl(); + String dbpassword = pollenServicesConfig.getDataSourcePassword(); + String dbuser = pollenServicesConfig.getDataSourceUser(); + + pollenSpgeedApplicationContext.setDataSource(dburl, dbuser, dbpassword); + + DataSource ds = pollenSpgeedApplicationContext.getDataSource(); + + try (SqlSession session = new SqlSession(ds)) { + + PollenUserSpgeedDao dao = session.getDao(PollenUserSpgeedDao.class); + + return dao.getUser(); + } catch(SQLException e) { + } + return (null); + + } + + public int getPollenUsercount() { + + PollenSpgeedApplicationContext pollenSpgeedApplicationContext = new PollenSpgeedApplicationContext(); + + PollenServicesConfig pollenServicesConfig = new PollenServicesConfig("pollen-rest-api.properties"); + + String dburl = pollenServicesConfig.getDataSourceUrl(); + String dbpassword = pollenServicesConfig.getDataSourcePassword(); + String dbuser = pollenServicesConfig.getDataSourceUser(); + + pollenSpgeedApplicationContext.setDataSource(dburl, dbuser, dbpassword); + + DataSource ds = pollenSpgeedApplicationContext.getDataSource(); + + try (SqlSession session = new SqlSession(ds)) { + + PollenUserSpgeedDao dao = session.getDao(PollenUserSpgeedDao.class); + + return (dao.getUserCount()); + } catch(SQLException e) { + } + return (0); + + } +} + diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenApplicationContext.java b/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenApplicationContext.java index bf39e898..da5b5284 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenApplicationContext.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/test/FakePollenApplicationContext.java @@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.persistence.PollenPersistenceContext; +import org.chorem.pollen.persistence.PollenSpgeedApplicationContext; import org.chorem.pollen.persistence.PollenTopiaApplicationContext; import org.chorem.pollen.persistence.PollenTopiaPersistenceContext; import org.chorem.pollen.persistence.entity.PollenPrincipal; @@ -188,6 +189,11 @@ public class FakePollenApplicationContext extends TestWatcher implements PollenA return configuration; } + @Override + public PollenSpgeedApplicationContext getSpgeedDataSource() { + return null; + } + @Override public VoteCountingFactory getVoteCountingFactory() { diff --git a/pom.xml b/pom.xml index 0186c9f4..3a505c38 100644 --- a/pom.xml +++ b/pom.xml @@ -180,6 +180,8 @@ <nuitonI18nVersion>3.7</nuitonI18nVersion> <eugenePluginVersion>3.0-alpha-10</eugenePluginVersion> <topiaVersion>3.5</topiaVersion> + <spgeedVersion>1.0.6</spgeedVersion> + <flywayVersion>5.0.0</flywayVersion> <nuitonWebVersion>1.20</nuitonWebVersion> @@ -299,6 +301,11 @@ <!-- persistence module dependencies --> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>spgeed</artifactId> + <version>${spgeedVersion}</version> + </dependency> <dependency> <groupId>org.nuiton.topia</groupId> <artifactId>topia-persistence</artifactId> @@ -630,6 +637,15 @@ <pluginManagement> <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <compilerArgs> + <arg>-parameters</arg> + </compilerArgs> + </configuration> + </plugin> <plugin> <artifactId>maven-site-plugin</artifactId> <dependencies> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.