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 919e40dca28cb7d5459796b347174dbd14ea3ed1 Author: HERBRETEAU Killian <Killian_H@localhost.localdomain> Date: Tue Jul 30 16:35:53 2019 +0200 adding request for get poll --- .../persistence/Dao/PollenPollSpgeedDao.java | 30 ++++- .../org/chorem/pollen/persistence/entity/Poll.java | 144 +++++++++++++++++++++ .../service/security/SpgeedDummyService.java | 65 +++++----- .../org/chorem/pollen/services}/SpgeedTest.java | 21 ++- 4 files changed, 220 insertions(+), 40 deletions(-) diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/Dao/PollenPollSpgeedDao.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/Dao/PollenPollSpgeedDao.java index 9a4ad560..16338bc2 100644 --- a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/Dao/PollenPollSpgeedDao.java +++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/Dao/PollenPollSpgeedDao.java @@ -1,9 +1,33 @@ package org.chorem.pollen.persistence.Dao; -import org.chorem.pollen.persistence.entity.PollenUser; -import org.chorem.pollen.persistence.entity.PollenUserEmailAddress; +import org.chorem.pollen.persistence.entity.Poll; import org.nuiton.spgeed.annotations.Select; +import org.nuiton.spgeed.annotations.Update; + +import java.sql.Date; public interface PollenPollSpgeedDao { - + + @Select(sql = "with pollenpo as " + + "(select title, description, begindate, enddate, anonymousvoteallowed, " + + "continuousresults, notifymehoursbeforepollends, pollendremindersent, " + + "notificationlocale, votenotification, feedcontent, commentnotification, " + + "newchoicenotification, gtuvalidationdate, premium, notificationmaxvotersend, " + + "emailaddresssuffixes from poll) " + + "select json_agg(po) from pollenpo po") + Poll[] getallpoll(); + + @Update(sql = "insert into poll (title, description, begindate, enddate, anonymousvoteallowed, " + + "continuousresults, notifymehoursbeforepollends, pollendremindersent, " + + "notificationlocale, votenotification, feedcontent, commentnotification, " + + "newchoicenotification, gtuvalidationdate, premium, notificationmaxvotersend, " + + "emailaddresssuffixes) values ($(title), $(description), $(begindate), $(enddate), $(anonymousvoteallowed), " + + "$(continuousresults), $(notifymehoursbeforepollends), $(pollendremindersent), " + + "$(notificationlocale), $(votenotification), $(feedcontent), $(commentnotification), " + + "$(newchoicenotification), $(gtuvalidationdate), $(premium), $(notificationmaxvotersend), " + + "$(emailaddresssuffixes)))") + int new_poll(String title, String description, Date begindate, Date enddate, boolean anonymousvoteallowed, boolean continuousresults, + int notifymehoursbeforepollends, boolean pollendremindersent, String notificationlocale, boolean votenotification, + String feedcontent, boolean commentnotification, boolean newchoicenotification, Date gtuvalidationdate, boolean premium, + boolean notificationmaxvotersend, String emailaddresssuffixes); } \ No newline at end of file diff --git a/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java new file mode 100644 index 00000000..2574253f --- /dev/null +++ b/pollen-persistence/src/main/java/org/chorem/pollen/persistence/entity/Poll.java @@ -0,0 +1,144 @@ +package org.chorem.pollen.persistence.entity; + +import java.util.Date; +import javax.annotation.Generated; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.nuiton.topia.persistence.TopiaEntity; + +@JsonDeserialize(as = PollImpl.class) +public interface Poll extends TopiaEntity { + + String PROPERTY_TITLE = "title"; + + String PROPERTY_DESCRIPTION = "description"; + + String PROPERTY_BEGIN_DATE = "beginDate"; + + String PROPERTY_END_DATE = "endDate"; + + String PROPERTY_ANONYMOUS_VOTE_ALLOWED = "anonymousVoteAllowed"; + + String PROPERTY_CONTINUOUS_RESULTS = "continuousResults"; + + String PROPERTY_NOTIFY_ME_HOURS_BEFORE_POLL_ENDS = "notifyMeHoursBeforePollEnds"; + + String PROPERTY_POLL_END_REMINDER_SENT = "pollEndReminderSent"; + + String PROPERTY_NOTIFICATION_LOCALE = "notificationLocale"; + + String PROPERTY_VOTE_NOTIFICATION = "voteNotification"; + + String PROPERTY_FEED_CONTENT = "feedContent"; + + String PROPERTY_COMMENT_NOTIFICATION = "commentNotification"; + + String PROPERTY_NEW_CHOICE_NOTIFICATION = "newChoiceNotification"; + + String PROPERTY_GTU_VALIDATION_DATE = "gtuValidationDate"; + + String PROPERTY_PREMIUM = "premium"; + + String PROPERTY_NOTIFICATION_MAX_VOTER_SEND = "notificationMaxVoterSend"; + + String PROPERTY_EMAIL_ADDRESS_SUFFIXES = "emailAddressSuffixes"; + + String PROPERTY_POLL_TYPE = "pollType"; + + String PROPERTY_VOTE_VISIBILITY = "voteVisibility"; + + String PROPERTY_COMMENT_VISIBILITY = "commentVisibility"; + + String PROPERTY_RESULT_VISIBILITY = "resultVisibility"; + + String PROPERTY_CREATOR = "creator"; + + void setTitle(String title); + + String getTitle(); + + void setDescription(String description); + + String getDescription(); + + void setBeginDate(Date beginDate); + + Date getBeginDate(); + + void setEndDate(Date endDate); + + Date getEndDate(); + + void setAnonymousVoteAllowed(boolean anonymousVoteAllowed); + + boolean isAnonymousVoteAllowed(); + + void setContinuousResults(boolean continuousResults); + + boolean isContinuousResults(); + + void setNotifyMeHoursBeforePollEnds(int notifyMeHoursBeforePollEnds); + + int getNotifyMeHoursBeforePollEnds(); + + void setPollEndReminderSent(boolean pollEndReminderSent); + + boolean isPollEndReminderSent(); + + void setNotificationLocale(String notificationLocale); + + String getNotificationLocale(); + + void setVoteNotification(boolean voteNotification); + + boolean isVoteNotification(); + + void setFeedContent(String feedContent); + + String getFeedContent(); + + void setCommentNotification(boolean commentNotification); + + boolean isCommentNotification(); + + void setNewChoiceNotification(boolean newChoiceNotification); + + boolean isNewChoiceNotification(); + + void setGtuValidationDate(Date gtuValidationDate); + + Date getGtuValidationDate(); + + void setPremium(boolean premium); + + boolean isPremium(); + + void setNotificationMaxVoterSend(boolean notificationMaxVoterSend); + + boolean isNotificationMaxVoterSend(); + + void setEmailAddressSuffixes(String emailAddressSuffixes); + + String getEmailAddressSuffixes(); + + void setPollType(PollType pollType); + + PollType getPollType(); + + void setVoteVisibility(VoteVisibility voteVisibility); + + VoteVisibility getVoteVisibility(); + + void setCommentVisibility(CommentVisibility commentVisibility); + + CommentVisibility getCommentVisibility(); + + void setResultVisibility(ResultVisibility resultVisibility); + + ResultVisibility getResultVisibility(); + + void setCreator(PollenPrincipal creator); + + PollenPrincipal getCreator(); + +} //Poll 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 index de7ec0c9..ca901ed2 100644 --- 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 @@ -2,8 +2,12 @@ package org.chorem.pollen.services.service.security; import org.chorem.pollen.persistence.PollenSpgeedApplicationContext; import org.chorem.pollen.persistence.Dao.PollenUserSpgeedDao; +import org.chorem.pollen.persistence.Dao.PollenPollSpgeedDao; +import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.persistence.entity.PollenUser; import org.chorem.pollen.persistence.entity.PollenUserEmailAddress; +import org.chorem.pollen.persistence.entity.Polls; +import org.chorem.pollen.services.PollenServiceContext; import org.chorem.pollen.services.PollenTechnicalException; import org.chorem.pollen.services.config.PollenServicesConfig; import org.nuiton.spgeed.SqlSession; @@ -13,44 +17,55 @@ import java.sql.SQLException; public class SpgeedDummyService { - public PollenUser getPollenUser() { + DataSource dataSource = null; + + public DataSource getdb() { - PollenSpgeedApplicationContext pollenSpgeedApplicationContext = new PollenSpgeedApplicationContext(); + if (dataSource == null) { + PollenSpgeedApplicationContext pollenSpgeedApplicationContext = new PollenSpgeedApplicationContext(); - PollenServicesConfig pollenServicesConfig = new PollenServicesConfig("pollen-rest-api.properties"); + PollenServicesConfig pollenServicesConfig = new PollenServicesConfig("pollen-rest-api.properties"); - String dburl = pollenServicesConfig.getDataSourceUrl(); - String dbpassword = pollenServicesConfig.getDataSourcePassword(); - String dbuser = pollenServicesConfig.getDataSourceUser(); + String dburl = pollenServicesConfig.getDataSourceUrl(); + String dbpassword = pollenServicesConfig.getDataSourcePassword(); + String dbuser = pollenServicesConfig.getDataSourceUser(); - pollenSpgeedApplicationContext.setDataSource(dburl, dbuser, dbpassword); + pollenSpgeedApplicationContext.setDataSource(dburl, dbuser, dbpassword); + this.dataSource = pollenSpgeedApplicationContext.getDataSource(); + } + return (dataSource); + } - DataSource ds = pollenSpgeedApplicationContext.getDataSource(); + public Poll[] getallPoll() { + DataSource ds = getdb(); try (SqlSession session = new SqlSession(ds)) { - PollenUserSpgeedDao dao = session.getDao(PollenUserSpgeedDao.class); + PollenPollSpgeedDao dao = session.getDao(PollenPollSpgeedDao.class); - return (dao.getUser()); + return (dao.getallpoll()); } catch(SQLException e) { throw new PollenTechnicalException("erreur lors du chargement d'un utilisateur", e); } - } + public PollenUser getPollenUser() { - public PollenUserEmailAddress getPollenUserEmailaddress() { + DataSource ds = getdb(); + + try (SqlSession session = new SqlSession(ds)) { - PollenSpgeedApplicationContext pollenSpgeedApplicationContext = new PollenSpgeedApplicationContext(); + PollenUserSpgeedDao dao = session.getDao(PollenUserSpgeedDao.class); - PollenServicesConfig pollenServicesConfig = new PollenServicesConfig("pollen-rest-api.properties"); + return (dao.getUser()); + } catch(SQLException e) { + throw new PollenTechnicalException("erreur lors du chargement d'un utilisateur", e); + } - String dburl = pollenServicesConfig.getDataSourceUrl(); - String dbpassword = pollenServicesConfig.getDataSourcePassword(); - String dbuser = pollenServicesConfig.getDataSourceUser(); + } - pollenSpgeedApplicationContext.setDataSource(dburl, dbuser, dbpassword); + public PollenUserEmailAddress getPollenUserEmailaddress() { - DataSource ds = pollenSpgeedApplicationContext.getDataSource(); + DataSource ds = getdb(); try (SqlSession session = new SqlSession(ds)) { @@ -65,17 +80,7 @@ public class SpgeedDummyService { 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(); + DataSource ds = getdb(); try (SqlSession session = new SqlSession(ds)) { diff --git a/pollen-persistence/src/test/java/org/chorem/pollen/persistence/SpgeedTest.java b/pollen-services/src/test/java/org/chorem/pollen/services/SpgeedTest.java similarity index 89% rename from pollen-persistence/src/test/java/org/chorem/pollen/persistence/SpgeedTest.java rename to pollen-services/src/test/java/org/chorem/pollen/services/SpgeedTest.java index 68696375..f11d99c5 100644 --- a/pollen-persistence/src/test/java/org/chorem/pollen/persistence/SpgeedTest.java +++ b/pollen-services/src/test/java/org/chorem/pollen/services/SpgeedTest.java @@ -1,20 +1,15 @@ -package org.chorem.pollen.persistence; +package org.chorem.pollen.services; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.tomcat.jni.Poll; +import org.chorem.pollen.persistence.entity.Poll; import org.chorem.pollen.persistence.entity.PollenUser; import org.chorem.pollen.persistence.entity.PollenUserEmailAddress; -import org.chorem.pollen.services.PollenTechnicalException; -import org.chorem.pollen.services.service.PollenUserService; import org.chorem.pollen.services.service.security.SpgeedDummyService; import org.junit.Assert; import org.junit.Test; -import javax.sql.DataSource; -import java.io.IOException; - /** * @author ymartel (martel@codelutin.com) */ @@ -103,4 +98,16 @@ public class SpgeedTest { Assert.assertTrue(pollenUser.isAdministrator()); } + @Test + public void testPoll() { + SpgeedDummyService spgeedDummyService = new SpgeedDummyService(); + Poll[] polls = spgeedDummyService.getallPoll(); + + Assert.assertNotNull(polls); + Poll first = polls[0]; + Assert.assertEquals(polls.length, 1); + Assert.assertEquals(first.getTitle(), "Sondage"); + Assert.assertEquals(first.getDescription(), "cc"); + } + } \ No newline at end of file -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.